mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 07:52:18 +03:00
add getAvailableSpaceOnDevice
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
b3e83474f1
commit
7f22ad68cc
3 changed files with 21 additions and 0 deletions
|
@ -17,6 +17,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager
|
|||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
|
||||
import com.owncloud.android.lib.common.utils.Log_OC
|
||||
import com.owncloud.android.operations.DownloadFileOperation
|
||||
import com.owncloud.android.ui.helpers.FileOperationsHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withContext
|
||||
|
@ -81,6 +82,15 @@ class SyncWorker(
|
|||
}
|
||||
|
||||
fileDataStorageManager.getFileByDecryptedRemotePath(path)?.let { file ->
|
||||
val fileSizeInByte = file.fileLength
|
||||
val availableDiskSpace = FileOperationsHelper.getAvailableSpaceOnDevice()
|
||||
|
||||
// TODO check
|
||||
if (availableDiskSpace < fileSizeInByte) {
|
||||
notificationManager.showNotAvailableDiskSpace()
|
||||
return@withContext Result.failure()
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
notificationManager.showProgressNotification(file.fileName, index, filePaths.size)
|
||||
}
|
||||
|
|
|
@ -101,6 +101,15 @@ class SyncWorkerNotificationManager(private val context: Context) {
|
|||
dismiss()
|
||||
}
|
||||
|
||||
suspend fun showNotAvailableDiskSpace() {
|
||||
val notification =
|
||||
getNotification(context.getString(R.string.sync_worker_insufficient_disk_space_notification_title))
|
||||
notificationManager.notify(notificationId, notification)
|
||||
|
||||
delay(1000)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
private fun showNotification(titleId: Int, descriptionId: Int) {
|
||||
val notification = getNotification(
|
||||
context.getString(titleId),
|
||||
|
|
|
@ -240,6 +240,8 @@
|
|||
<string name="sync_worker_error_notification_title">Download Failed</string>
|
||||
<string name="sync_worker_error_notification_description">An error occurred during folder synchronization</string>
|
||||
|
||||
<string name="sync_worker_insufficient_disk_space_notification_title">Insufficient disk space, sync operation canceled</string>
|
||||
|
||||
<string name="uploader_upload_in_progress_ticker">Uploading…</string>
|
||||
<string name="uploader_upload_in_progress_content">%1$d%% Uploading %2$s</string>
|
||||
<string name="uploader_upload_succeeded_content_single">%1$s uploaded</string>
|
||||
|
|
Loading…
Reference in a new issue