Skip to content

Commit

Permalink
Fix file sync icon
Browse files Browse the repository at this point in the history
Signed-off-by: alperozturk <[email protected]>
  • Loading branch information
alperozturk96 committed Jan 5, 2024
1 parent bebe98b commit 0039a23
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ class FileDownloadHelper {

return backgroundJobManager.isStartFileDownloadJobScheduled(
user,
file.remotePath
file
)
}

fun cancelPendingOrCurrentDownloads(user: User?, file: OCFile?) {
if (user == null || file == null) return
backgroundJobManager.cancelFilesDownloadJob(user, file.remotePath)
backgroundJobManager.cancelFilesDownloadJob(user, file)
}

fun cancelAllDownloadsForAccount(accountName: String?, currentDownload: DownloadFileOperation) {
if (currentDownload.user.nameEquals(accountName)) {
currentDownload.file?.let { file ->
backgroundJobManager.cancelFilesDownloadJob(currentDownload.user, file.remotePath)
backgroundJobManager.cancelFilesDownloadJob(currentDownload.user, file)
}

currentDownload.cancel()
Expand Down Expand Up @@ -123,7 +123,7 @@ class FileDownloadHelper {

fun downloadFolder(folder: OCFile, user: User, files: List<OCFile>) {
val filesPath = files.map { it.remotePath }
backgroundJobManager.startFolderDownloadJob(folder.remotePath, user, filesPath)
backgroundJobManager.startFolderDownloadJob(folder, user, filesPath)
}

fun downloadFile(user: User, file: OCFile) {
Expand All @@ -142,7 +142,7 @@ class FileDownloadHelper {
) {
backgroundJobManager.startFileDownloadJob(
user,
ocFile.remotePath,
ocFile,
behaviour,
downloadType,
activityName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ interface BackgroundJobManager {
fun getFileUploads(user: User): LiveData<List<JobInfo>>
fun cancelFilesUploadJob(user: User)

fun cancelFilesDownloadJob(user: User, path: String)
fun cancelFilesDownloadJob(user: User, ocFile: OCFile)

fun isStartFileDownloadJobScheduled(user: User, path: String): Boolean
fun isStartFileDownloadJobScheduled(user: User, ocFile: OCFile): Boolean

@Suppress("LongParameterList")
fun startFileDownloadJob(
user: User,
filePath: String,
file: OCFile,
behaviour: String,
downloadType: DownloadType?,
activityName: String,
Expand All @@ -161,7 +161,7 @@ interface BackgroundJobManager {
)

fun startFolderDownloadJob(
folderPath: String,
folder: OCFile,
user: User,
filesPath: List<String>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
import com.nextcloud.client.files.downloader.FileDownloadWorker
import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.utils.extensions.isWorkScheduled
import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.operations.DownloadType
import java.util.Date
Expand Down Expand Up @@ -108,7 +109,6 @@ internal class BackgroundJobManagerImpl(
const val PERIODIC_BACKUP_INTERVAL_MINUTES = 24 * 60L
const val DEFAULT_PERIODIC_JOB_INTERVAL_MINUTES = 15L
const val DEFAULT_IMMEDIATE_JOB_DELAY_SEC = 3L
private val gson = Gson()

private const val KEEP_LOG_MILLIS = 1000 * 60 * 60 * 24 * 3L

Expand Down Expand Up @@ -500,7 +500,6 @@ internal class BackgroundJobManagerImpl(

workManager.enqueue(request)
}

override fun startFilesUploadJob(user: User) {
val data = workDataOf(FilesUploadWorker.ACCOUNT to user.accountName)

Expand All @@ -511,23 +510,23 @@ internal class BackgroundJobManagerImpl(
workManager.enqueueUniqueWork(JOB_FILES_UPLOAD + user.accountName, ExistingWorkPolicy.KEEP, request)
}

private fun startFileDownloadJobTag(user: User, path: String): String {
return JOB_FILES_DOWNLOAD + user.accountName + path
private fun startFileDownloadJobTag(user: User, ocFile: OCFile): String {
return JOB_FILES_DOWNLOAD + user.accountName + ocFile.fileId
}

override fun isStartFileDownloadJobScheduled(user: User, path: String): Boolean {
return workManager.isWorkScheduled(startFileDownloadJobTag(user, path))
override fun isStartFileDownloadJobScheduled(user: User, ocFile: OCFile): Boolean {
return workManager.isWorkScheduled(startFileDownloadJobTag(user, ocFile))
}

override fun startFolderDownloadJob(folderPath: String, user: User, filesPath: List<String>) {
override fun startFolderDownloadJob(folder: OCFile, user: User, filesPath: List<String>) {
val data = workDataOf(
FileDownloadWorker.USER_NAME to user.accountName,
FileDownloadWorker.FOLDER_PATH to folderPath,
FileDownloadWorker.FOLDER_PATH to folder.remotePath,
FileDownloadWorker.FILES_PATH to filesPath.joinToString(FileDownloadWorker.FILES_SEPARATOR),
FileDownloadWorker.DOWNLOAD_TYPE to DownloadType.DOWNLOAD.toString()
)

val tag = startFileDownloadJobTag(user, folderPath)
val tag = startFileDownloadJobTag(user, folder)

val request = oneTimeRequestBuilder(FileDownloadWorker::class, JOB_FILES_DOWNLOAD, user)
.addTag(tag)
Expand All @@ -540,19 +539,19 @@ internal class BackgroundJobManagerImpl(

override fun startFileDownloadJob(
user: User,
filePath: String,
file: OCFile,
behaviour: String,
downloadType: DownloadType?,
activityName: String,
packageName: String,
conflictUploadId: Long?
) {
val tag = startFileDownloadJobTag(user, filePath)
val tag = startFileDownloadJobTag(user, file)

val data = workDataOf(
FileDownloadWorker.WORKER_TAG to tag,
FileDownloadWorker.USER_NAME to user.accountName,
FileDownloadWorker.FILE_PATH to filePath,
FileDownloadWorker.FILE_PATH to file.remotePath,
FileDownloadWorker.BEHAVIOUR to behaviour,
FileDownloadWorker.DOWNLOAD_TYPE to downloadType.toString(),
FileDownloadWorker.ACTIVITY_NAME to activityName,
Expand All @@ -577,8 +576,8 @@ internal class BackgroundJobManagerImpl(
workManager.cancelJob(JOB_FILES_UPLOAD, user)
}

override fun cancelFilesDownloadJob(user: User, path: String) {
workManager.cancelAllWorkByTag(startFileDownloadJobTag(user, path))
override fun cancelFilesDownloadJob(user: User, ocFile: OCFile) {
workManager.cancelAllWorkByTag(startFileDownloadJobTag(user, ocFile))
}

override fun startPdfGenerateAndUploadWork(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.lifecycle.LiveData
import com.nextcloud.client.account.User
import com.owncloud.android.datamodel.OCFile

class DownloadWorkerStateLiveData private constructor() : LiveData<ArrayList<DownloadWorkerState>>() {
class DownloadWorkerStateLiveData private constructor(): LiveData<ArrayList<DownloadWorkerState>>() {

private var workers: ArrayList<DownloadWorkerState> = arrayListOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,15 @@ class OCFileListDelegate(
val operationsServiceBinder = transferServiceGetter.operationsServiceBinder
val fileUploaderBinder = transferServiceGetter.fileUploaderBinder

val isDownloading = if (file.isFolder) {
FileDownloadHelper.instance().isDownloading(user, file)
} else {
DownloadWorkerStateLiveData.instance().isDownloading(user, file)
}

val icon: Int? = when {
operationsServiceBinder?.isSynchronizing(user, file) == true ||
DownloadWorkerStateLiveData.instance().isDownloading(user, file) ||
isDownloading ||
fileUploaderBinder?.isUploading(user, file) == true -> {
// synchronizing, downloading or uploading
R.drawable.ic_synchronizing
Expand Down

0 comments on commit 0039a23

Please sign in to comment.