mirror of
https://github.com/nextcloud/android.git
synced 2024-12-18 15:01:57 +03:00
use IO thread
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
a8bff664bb
commit
2b576a052b
1 changed files with 30 additions and 26 deletions
|
@ -15,6 +15,8 @@ import com.owncloud.android.datamodel.FileDataStorageManager
|
||||||
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
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class SyncWorker(
|
class SyncWorker(
|
||||||
private val user: User,
|
private val user: User,
|
||||||
|
@ -29,40 +31,42 @@ class SyncWorker(
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
// TODO add notifications
|
return withContext(Dispatchers.IO) {
|
||||||
Log_OC.d(TAG, "SyncWorker started")
|
// TODO add notifications
|
||||||
val filePaths = inputData.getStringArray(FILE_PATHS)
|
Log_OC.d(TAG, "SyncWorker started")
|
||||||
|
val filePaths = inputData.getStringArray(FILE_PATHS)
|
||||||
|
|
||||||
if (filePaths.isNullOrEmpty()) {
|
if (filePaths.isNullOrEmpty()) {
|
||||||
return Result.failure()
|
return@withContext Result.failure()
|
||||||
}
|
}
|
||||||
|
|
||||||
val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
|
val fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
|
||||||
|
|
||||||
val account = user.toOwnCloudAccount()
|
val account = user.toOwnCloudAccount()
|
||||||
val client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(account, context)
|
val client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(account, context)
|
||||||
|
|
||||||
var result = true
|
var result = true
|
||||||
filePaths.forEach { path ->
|
filePaths.forEach { path ->
|
||||||
fileDataStorageManager.getFileByDecryptedRemotePath(path)?.let { file ->
|
fileDataStorageManager.getFileByDecryptedRemotePath(path)?.let { file ->
|
||||||
// TODO dont download downloaded files??
|
// TODO dont download downloaded files??
|
||||||
val operation = DownloadFileOperation(user, file, context).execute(client)
|
val operation = DownloadFileOperation(user, file, context).execute(client)
|
||||||
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO add isDownloading
|
// TODO add isDownloading
|
||||||
// TODO add cancel only one file download
|
// TODO add cancel only one file download
|
||||||
|
|
||||||
return if (result) {
|
if (result) {
|
||||||
Log_OC.d(TAG, "SyncWorker completed")
|
Log_OC.d(TAG, "SyncWorker completed")
|
||||||
Result.success()
|
Result.success()
|
||||||
} else {
|
} else {
|
||||||
Log_OC.d(TAG, "SyncWorker failed")
|
Log_OC.d(TAG, "SyncWorker failed")
|
||||||
Result.failure()
|
Result.failure()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue