add isDownloading

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-12-02 12:13:00 +01:00 committed by Alper Öztürk
parent 80e874a7a7
commit 0a0405f913

View file

@ -12,7 +12,6 @@ import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.nextcloud.client.account.User import com.nextcloud.client.account.User
import com.owncloud.android.datamodel.FileDataStorageManager 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.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.operations.DownloadFileOperation import com.owncloud.android.operations.DownloadFileOperation
@ -31,13 +30,11 @@ class SyncWorker(
const val FILE_PATHS = "FILE_PATHS" const val FILE_PATHS = "FILE_PATHS"
// FIXME it's not synchronous private var downloadingFilePaths = ArrayList<String>()
fun isDownloading(fileId: Long): Boolean {
return downloadFileIds.contains(fileId) || currentDownloadFolderId == fileId
}
private var currentDownloadFolderId: Long? = null fun isDownloading(path: String): Boolean {
private var downloadFileIds = ArrayList<Long>() return downloadingFilePaths.contains(path)
}
} }
private val notificationManager = SyncWorkerNotificationManager(context) private val notificationManager = SyncWorkerNotificationManager(context)
@ -56,6 +53,9 @@ class SyncWorker(
return@withContext Result.failure() return@withContext Result.failure()
} }
// TODO
// downloadingFilePaths = filePaths
val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver) val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
val account = user.toOwnCloudAccount() val account = user.toOwnCloudAccount()
@ -76,8 +76,6 @@ class SyncWorker(
delay(1000) delay(1000)
val operation = DownloadFileOperation(user, file, context).execute(client) val operation = DownloadFileOperation(user, file, context).execute(client)
setCurrentDownloadFileIds(fileDataStorageManager, file)
Log_OC.d(TAG, "Syncing file: " + file.decryptedRemotePath) Log_OC.d(TAG, "Syncing file: " + file.decryptedRemotePath)
if (!operation.isSuccess) { if (!operation.isSuccess) {
result = false result = false
@ -87,8 +85,6 @@ class SyncWorker(
// TODO add isDownloading // TODO add isDownloading
// TODO add cancel only one file download // TODO add cancel only one file download
downloadFileIds.clear()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
notificationManager.showCompletionMessage(result) notificationManager.showCompletionMessage(result)
} }
@ -102,12 +98,4 @@ class SyncWorker(
} }
} }
} }
private fun setCurrentDownloadFileIds(fileDataStorageManager: FileDataStorageManager, file: OCFile) {
if (currentDownloadFolderId == null) {
currentDownloadFolderId = fileDataStorageManager.getTopParentId(file)
}
downloadFileIds.add(file.fileId)
}
} }