Skip to content

Commit b833d4f

Browse files
committed
fix(file-list): sync icon disappearance
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 1958a74 commit b833d4f

5 files changed

Lines changed: 54 additions & 28 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
8+
package com.nextcloud.client.jobs.folderDownload
9+
10+
sealed class FolderDownloadState(open val id: Long) {
11+
data class Downloading(override val id: Long) : FolderDownloadState(id)
12+
data class Removed(override val id: Long) : FolderDownloadState(id)
13+
}

app/src/main/java/com/nextcloud/client/jobs/folderDownload/FolderDownloadWorker.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class FolderDownloadWorker(
4141
const val FOLDER_ID = "FOLDER_ID"
4242
const val ACCOUNT_NAME = "ACCOUNT_NAME"
4343

44-
private val _activeFolders = MutableStateFlow<Set<Long>>(emptySet())
45-
val activeFolders: StateFlow<Set<Long>> = _activeFolders
44+
private val _activeFolders = MutableStateFlow<Set<FolderDownloadState>>(emptySet())
45+
val activeFolders: StateFlow<Set<FolderDownloadState>> = _activeFolders
4646
}
4747

4848
private val notificationManager = FolderDownloadWorkerNotificationManager(context, viewThemeUtils)
@@ -79,7 +79,7 @@ class FolderDownloadWorker(
7979

8080
trySetForeground(folder)
8181

82-
_activeFolders.value += folderID
82+
_activeFolders.value += FolderDownloadState.Downloading(folderID)
8383

8484
val downloadHelper = FileDownloadHelper.instance()
8585

@@ -137,7 +137,7 @@ class FolderDownloadWorker(
137137
Result.failure()
138138
} finally {
139139
WorkerStateObserver.send(WorkerState.FolderDownloadCompleted(folder))
140-
_activeFolders.value -= folderID
140+
_activeFolders.value -= FolderDownloadState.Downloading(folderID)
141141
notificationManager.dismiss()
142142
}
143143
}

app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import com.nextcloud.client.jobs.download.FileDownloadHelper
6767
import com.nextcloud.client.jobs.download.FileDownloadWorker
6868
import com.nextcloud.client.jobs.download.FileDownloadWorker.Companion.getDownloadAddedMessage
6969
import com.nextcloud.client.jobs.download.FileDownloadWorker.Companion.getDownloadFinishMessage
70+
import com.nextcloud.client.jobs.folderDownload.FolderDownloadState
7071
import com.nextcloud.client.jobs.folderDownload.FolderDownloadWorker
7172
import com.nextcloud.client.jobs.upload.FileUploadBroadcastManager
7273
import com.nextcloud.client.jobs.upload.FileUploadHelper
@@ -79,7 +80,6 @@ import com.nextcloud.model.WorkerState
7980
import com.nextcloud.model.WorkerState.FileDownloadCompleted
8081
import com.nextcloud.model.WorkerState.FileDownloadStarted
8182
import com.nextcloud.model.WorkerState.OfflineOperationsCompleted
82-
import com.nextcloud.model.WorkerStateObserver
8383
import com.nextcloud.utils.extensions.getParcelableArgument
8484
import com.nextcloud.utils.extensions.isActive
8585
import com.nextcloud.utils.extensions.lastFragment
@@ -2135,6 +2135,11 @@ class FileDisplayActivity :
21352135
}
21362136
supportInvalidateOptionsMenu()
21372137
fetchRecommendedFilesIfNeeded(ignoreETag = true, currentDir)
2138+
2139+
if (removedFile.isFolder) {
2140+
val deletedFolderDownloadState = FolderDownloadState.Removed(removedFile.fileId)
2141+
listOfFilesFragment?.adapter?.notifyFolderDownloadStates(setOf(deletedFolderDownloadState))
2142+
}
21382143
} else {
21392144
if (result.isSslRecoverableException) {
21402145
mLastSslUntrustedServerResult = result
@@ -2434,9 +2439,9 @@ class FileDisplayActivity :
24342439
private fun observeFolderDownloadWorker() {
24352440
lifecycleScope.launch {
24362441
repeatOnLifecycle(Lifecycle.State.STARTED) {
2437-
FolderDownloadWorker.activeFolders.collect { activeIds ->
2438-
Log_OC.d(TAG, "currently downloading: $activeIds")
2439-
listOfFilesFragment?.adapter?.notifyDownloadingFolderIds(activeIds)
2442+
FolderDownloadWorker.activeFolders.collect { workerStates ->
2443+
Log_OC.d(TAG, "currently downloading: ${workerStates.size}")
2444+
listOfFilesFragment?.adapter?.notifyFolderDownloadStates(workerStates)
24402445
}
24412446
}
24422447
}

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
3131
import com.nextcloud.client.account.User;
3232
import com.nextcloud.client.database.entity.OfflineOperationEntity;
33+
import com.nextcloud.client.jobs.folderDownload.FolderDownloadState;
3334
import com.nextcloud.client.jobs.upload.FileUploadHelper;
3435
import com.nextcloud.client.preferences.AppPreferences;
3536
import com.nextcloud.model.OfflineOperationType;
@@ -1063,19 +1064,20 @@ public void removeAllFiles() {
10631064
notifyDataSetChanged();
10641065
}
10651066

1066-
public void notifyDownloadingFolderIds(Set<Long> ids) {
1067-
Set<Long> previousIds = new HashSet<>(ocFileListDelegate.getDownloadingFolderIds());
1067+
public void notifyFolderDownloadStates(Set<FolderDownloadState> states) {
1068+
Set<FolderDownloadState> previousStates = new HashSet<>(ocFileListDelegate.getFolderDownloadStates());
10681069

1069-
ocFileListDelegate.notifyDownloadingFolderIds(ids);
1070+
ocFileListDelegate.addFolderDownloadStates(states);
10701071

1071-
Set<Long> allChangedIds = new HashSet<>();
1072-
allChangedIds.addAll(ids);
1073-
allChangedIds.addAll(previousIds);
1072+
Set<Long> changedFileIds = new HashSet<>();
1073+
states.forEach(state -> changedFileIds.add(state.getId()));
1074+
previousStates.forEach(state -> changedFileIds.add(state.getId()));
10741075

1075-
allChangedIds.forEach(id -> {
1076-
OCFile file = findOCFile(id);
1076+
1077+
changedFileIds.forEach(fileId -> {
1078+
OCFile file = findOCFile(fileId);
10771079
if (file != null) {
1078-
int position = mFiles.indexOf(file);
1080+
int position = getItemPosition(file);
10791081
if (position != -1) {
10801082
notifyItemChanged(position);
10811083
}

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.elyeproj.loaderviewlibrary.LoaderImageView
1515
import com.nextcloud.android.common.ui.theme.utils.ColorRole
1616
import com.nextcloud.client.account.User
1717
import com.nextcloud.client.jobs.download.FileDownloadHelper
18+
import com.nextcloud.client.jobs.folderDownload.FolderDownloadState
1819
import com.nextcloud.client.jobs.gallery.GalleryImageGenerationJob
1920
import com.nextcloud.client.jobs.gallery.GalleryImageGenerationListener
2021
import com.nextcloud.client.jobs.upload.FileUploadHelper
@@ -67,7 +68,7 @@ class OCFileListDelegate(
6768
private val asyncTasks: MutableList<ThumbnailsCacheManager.ThumbnailGenerationTask> = ArrayList()
6869
private val ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
6970
private val galleryImageGenerationJob = GalleryImageGenerationJob(user, storageManager)
70-
private val downloadingFolderIds = mutableSetOf<Long>()
71+
private val folderDownloadStates = mutableSetOf<FolderDownloadState>()
7172

7273
fun setHighlightedItem(highlightedItem: OCFile?) {
7374
this.highlightedItem = highlightedItem
@@ -323,12 +324,13 @@ class OCFileListDelegate(
323324
private fun isSynchronizing(file: OCFile): Boolean {
324325
val operationsServiceBinder = transferServiceGetter.operationsServiceBinder
325326
val fileDownloadHelper = FileDownloadHelper.instance()
327+
val isDownloadingFolder =
328+
folderDownloadStates.any { it is FolderDownloadState.Downloading && it.id == file.fileId }
326329

327-
Log_OC.d(TAG, "size of downloading folder: " + downloadingFolderIds.size)
328-
330+
Log_OC.d(TAG, "size of downloading folder: " + folderDownloadStates.size)
329331
return operationsServiceBinder?.isSynchronizing(user, file) == true ||
330332
fileDownloadHelper.isDownloading(user, file) ||
331-
downloadingFolderIds.contains(file.fileId) ||
333+
isDownloadingFolder ||
332334
fileUploadHelper.isUploading(file.remotePath, user.accountName)
333335
}
334336

@@ -337,11 +339,15 @@ class OCFileListDelegate(
337339
val isSyncing = isSynchronizing(file)
338340
val hasConflict = (file.etagInConflict != null)
339341
val isDown = file.isDown
342+
val isRemoved = folderDownloadStates.any {
343+
it is FolderDownloadState.Removed && it.id == file.fileId
344+
}
340345

341346
val icon = when {
342347
isSyncing -> R.drawable.ic_synchronizing
343348
hasConflict -> R.drawable.ic_synchronizing_error
344349
isDown || isFullyDownloaded -> R.drawable.ic_synced
350+
isRemoved -> null
345351
else -> null
346352
}
347353

@@ -406,17 +412,17 @@ class OCFileListDelegate(
406412
showShareAvatar = bool
407413
}
408414

409-
fun notifyDownloadingFolderIds(ids: Set<Long>) {
410-
val removed = downloadingFolderIds - ids
411-
val added = ids - downloadingFolderIds
415+
fun addFolderDownloadStates(ids: Set<FolderDownloadState>) {
416+
val removed = folderDownloadStates - ids
417+
val added = ids - folderDownloadStates
412418

413-
downloadingFolderIds.clear()
414-
downloadingFolderIds.addAll(ids)
419+
folderDownloadStates.clear()
420+
folderDownloadStates.addAll(ids)
415421

416-
Log_OC.d(TAG, "downloading folders - added: $added, removed: $removed, current: $downloadingFolderIds")
422+
Log_OC.d(TAG, "downloading folders - added: $added, removed: $removed, current: $folderDownloadStates")
417423
}
418424

419-
fun getDownloadingFolderIds(): List<Long> = downloadingFolderIds.toList()
425+
fun getFolderDownloadStates(): List<FolderDownloadState> = folderDownloadStates.toList()
420426

421427
fun cleanup() {
422428
ioScope.cancel()

0 commit comments

Comments
 (0)