Skip to content

fix: observe worker state#15923

Merged
alperozturk96 merged 9 commits intomasterfrom
fix/observe-worker-state
Dec 4, 2025
Merged

fix: observe worker state#15923
alperozturk96 merged 9 commits intomasterfrom
fix/observe-worker-state

Conversation

@alperozturk96
Copy link
Copy Markdown
Collaborator

@alperozturk96 alperozturk96 commented Nov 7, 2025

  • Tests written, or not not needed

Issue

Local file indicator icons were not updating correctly when files or folders finished downloading, and switching between list and grid layouts caused icons to disappear.

Fixes

Fix observation of multiple workers across all relevant screens to ensure each worker completion is reflected in the UI.

Preserves local file indicator state during layout switches (list ↔ grid).

Fix logic for both folder and file downloads to display local file indicator icons consistently.

@alperozturk96 alperozturk96 force-pushed the fix/observe-worker-state branch 2 times, most recently from e7f430c to 1b4292e Compare November 11, 2025 17:14
@tobiasKaminsky tobiasKaminsky marked this pull request as draft November 14, 2025 09:14
@alperozturk96 alperozturk96 force-pushed the fix/observe-worker-state branch from 1b4292e to 797b231 Compare November 14, 2025 13:43
@alperozturk96
Copy link
Copy Markdown
Collaborator Author

alperozturk96 commented Nov 14, 2025

@tobiasKaminsky

Note:

Events are delivered only to the currently active activity.

For example, this means that when the user is in FileDisplayActivity. ManageAccountsActivity, cannot receive an event.


FolderDownloadCompleted is used:

  • In FileDisplayActivity to mark the green tick for a single OCFile item via notifyItemChanged, indicating that the folder has been downloaded.

FileDownloadStarted is used:

  • In FileDisplayActivity, if mWaitingToPreview is not null, to request the download again if it has not already started.
  • In ManageAccountsActivity, when the user logs out, to cancel all current downloads for the active account.
  • In PreviewImageActivity, if the screen state is PreviewImageActivityState.WaitingForBinder, to select the appropriate page in the ViewPager.

FileDownloadCompleted is used:

  • In FileDisplayActivity to preview an image immediately after the download completes, but only if fileIDForImmediatePreview is valid.
  • In PreviewImageActivity, if the screen state is PreviewImageActivityState.Edit, to start the image editing activity; otherwise, it reinitializes the ViewPager for the newly downloaded file.

FileUploadStarted is used:

  • In UploadListActivity (the Upload screen) to refresh the items in the list.
  • In FileDetailFragment to update the text view and inform the user that the file is uploading.

FileUploadCompleted is used:

  • In UploadListActivity (the Upload screen) to refresh the items in the list.
  • In FileDisplayActivity to insert the related item via notifyItemInserted.

OfflineOperationsCompleted is used:

  • In FileDisplayActivity to refresh the current directory and reload the OCFile list adapter.

@alperozturk96
Copy link
Copy Markdown
Collaborator Author

alperozturk96 commented Nov 14, 2025

@tobiasKaminsky

How to Test the Green Tick for a Folder & Slow Grid View

  1. Ensure the folder contains at least a few files.

  2. Open the three-dot menu for that folder.

  3. Tap "Sync".

  4. The folder will be downloaded via FolderDownloadWorker.

  5. The green tick icon is then displayed through OCFileListDelegate.showLocalFileIndicator.

    • This method uses a Coroutine IO scope to call isFolderFullyDownloaded, which queries the database asynchronously.
    • Other icon checks (e.g., cancel, syncing states) can be handled synchronously, but the folder-completion check cannot because it is suspended.

Why Some Approaches Do Not Work

  1. Setting synchronous icons first, then calling the async check. This shows the quick icons immediately, but the green tick never appears afterward because the adapter is not notified when the async result returns.

  2. Calling isFolderFullyDownloaded asynchronously from OCFileListFragment or FileDisplayActivity, then using notifyItemChanged

  3. Running the check on an ExecutorService or a Thread. This does not change the behavior, since the core issue is the async nature of the database call and the lack of a proper UI update mechanism tied to it.

  4. Switching from setAdapter to swapAdapter in the switchLayoutManager function. While this make UI faster but changing the adapter-swap logic breaks item alignment, styles, and layout behaviors.

@alperozturk96 alperozturk96 force-pushed the fix/observe-worker-state branch 2 times, most recently from 5ba3d67 to 8ba9015 Compare November 19, 2025 07:30
@tobiasKaminsky
Copy link
Copy Markdown
Member

To reproduce:

  • go into a folder wtih downloaded files

@tobiasKaminsky

This comment was marked as resolved.

@alperozturk96 alperozturk96 force-pushed the fix/observe-worker-state branch from 8ba9015 to 4c6d370 Compare December 1, 2025 10:50
@alperozturk96
Copy link
Copy Markdown
Collaborator Author

I debugged it and I see that we set visibility of the "container" "@+id/file_features_layout" only after setting the sync state. This is very specific to the grid view:

checkVisibilityOfFileFeaturesLayout(gridViewHolder);

If I always set this "container" to be visible, then there is no delay.

Thank you awesome 👍

@alperozturk96 alperozturk96 marked this pull request as ready for review December 1, 2025 12:48
@nextcloud nextcloud deleted a comment from github-actions Bot Dec 1, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 1, 2025

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/15923.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

Signed-off-by: alperozturk <alper_ozturk@proton.me>

# Conflicts:
#	app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
@alperozturk96 alperozturk96 force-pushed the fix/observe-worker-state branch from a66a4d8 to b46969d Compare December 4, 2025 09:08
Signed-off-by: alperozturk <alper_ozturk@proton.me>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 4, 2025

blue-Light-Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@alperozturk96 alperozturk96 merged commit b0656a6 into master Dec 4, 2025
12 of 21 checks passed
@alperozturk96 alperozturk96 deleted the fix/observe-worker-state branch December 4, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants