Skip to content

Commit

Permalink
add getAvailableSpaceOnDevice
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 18, 2024
1 parent a0799b9 commit 7439bc3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 7439bc3

Please sign in to comment.