Skip to content

Commit

Permalink
add isDownloading
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Dec 12, 2024
1 parent 63ed48c commit d017482
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions app/src/main/java/com/nextcloud/client/jobs/sync/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.nextcloud.client.account.User
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.operations.DownloadFileOperation
Expand All @@ -31,13 +30,11 @@ class SyncWorker(

const val FILE_PATHS = "FILE_PATHS"

// FIXME it's not synchronous
fun isDownloading(fileId: Long): Boolean {
return downloadFileIds.contains(fileId) || currentDownloadFolderId == fileId
}
private var downloadingFilePaths = ArrayList<String>()

private var currentDownloadFolderId: Long? = null
private var downloadFileIds = ArrayList<Long>()
fun isDownloading(path: String): Boolean {
return downloadingFilePaths.contains(path)
}
}

private val notificationManager = SyncWorkerNotificationManager(context)
Expand All @@ -56,6 +53,9 @@ class SyncWorker(
return@withContext Result.failure()
}

// TODO
// downloadingFilePaths = filePaths

val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)

val account = user.toOwnCloudAccount()
Expand All @@ -76,8 +76,6 @@ class SyncWorker(
delay(1000)

val operation = DownloadFileOperation(user, file, context).execute(client)
setCurrentDownloadFileIds(fileDataStorageManager, file)

Log_OC.d(TAG, "Syncing file: " + file.decryptedRemotePath)
if (!operation.isSuccess) {
result = false
Expand All @@ -87,8 +85,6 @@ class SyncWorker(

// TODO add isDownloading
// TODO add cancel only one file download

downloadFileIds.clear()
withContext(Dispatchers.Main) {
notificationManager.showCompletionMessage(result)
}
Expand All @@ -102,12 +98,4 @@ class SyncWorker(
}
}
}

private fun setCurrentDownloadFileIds(fileDataStorageManager: FileDataStorageManager, file: OCFile) {
if (currentDownloadFolderId == null) {
currentDownloadFolderId = fileDataStorageManager.getTopParentId(file)
}

downloadFileIds.add(file.fileId)
}
}

0 comments on commit d017482

Please sign in to comment.