Skip to content

fix(shared-items): keep scroll position and avoid duplicates when paging - #7049

Merged
mahibi merged 9 commits into
masterfrom
fixSharedItemsScreen
Nov 17, 2026
Merged

mahibi merged 9 commits into
masterfrom
fixSharedItemsScreen

Conversation

@mahibi

@mahibi mahibi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

🖼️ Screenvideos

🏚️ Before

sharedItemsScreenOldWithBugs.mp4

🏡 After

sharedItemsScreenNew.mp4

pictures are just shown duplicated here because i actually uploaded the same multiple times.

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@mahibi mahibi added this to the 26.0.0 milestone Nov 16, 2026
@mahibi mahibi self-assigned this Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

📱 QA build

Download app-qa-debug.apk
QR code Open the QR code for this download
Commit afdd5fc
Version 7049
Available until 7 days after this build

The QA build installs alongside a released Nextcloud app, so you can keep
using your existing install while testing.

Downloading the file requires a GitHub account, so open this link on the
device you want to test on, or transfer the APK to it.

The list jumped to the top on every loaded page because a new adapter and
layout manager were created for each state update. The adapter is now a
ListAdapter that is kept while the selected type stays the same, and new
pages are submitted to it.

Items were shown multiple times because several next-page requests with the
same cursor could run at once, and pages of a previously selected tab could
still be appended after switching tabs. The ViewModel now runs at most one
items request at a time, cancels it on tab change and only appends a page to
the list it was requested for. Unpinned items are removed from the
ViewModel state so they do not reappear with the next page.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
The shared items endpoints move from NcApi to NcApiCoroutines, and
SharedItemsRepository exposes suspend functions instead of Observables.
SharedItemsViewModel exposes a StateFlow and runs its requests in
viewModelScope, keeping a single items job that is cancelled on tab change.
MediaViewerViewModel calls the repository directly instead of bridging the
Observable.

As a StateFlow can skip intermediate states, the activity sets up the tabs
from the first state that carries the available types instead of relying on
TypesLoadedState being delivered.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
…ecreated

SharedItemsViewModel.initialize() now only starts loading while the state is
still InitialState, so a recreated activity keeps the loaded pages and the
selected type instead of reloading the first page of the initial type.

The tabs highlight the tab of the selected type, and rebuilding them replaces
the tab listener instead of adding another one, which caused duplicate
requests per tab tap.

MediaViewerViewModel rethrows CancellationException instead of treating a
cancelled request as a failed load.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
…e messages

SharedItemsViewModel.initialize() now resumes whatever has not finished
instead of doing nothing after InitialState: a first page that failed to
load is requested again, and a types request that is still running is not
started a second time when the activity is recreated.

moreItemsExisting is derived from the number of messages the server
returned rather than the number of mapped items, so a full page containing a
message that cannot be mapped no longer stops paging.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
The next page was only requested when fewer than 8 items were left, which is
two rows in the media grid, so a fling reached the end of the list before the
page arrived and scrolling stopped. The next page is now requested once a
full page of items is left below the visible area.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
A page whose messages could all not be shown left the list unchanged, so no
scroll event requested the next page and paging stopped, or the tab stayed
blank when it was the first page. SharedItemsViewModel now requests the
following page itself while a page adds no items and the server reports more.

The media viewer had the same problem with pages without images or videos.
It now pages by the cursor the server returns instead of the oldest shown
item and skips such pages as well.

Rebuilding the tabs only replaces the activity's own tab listener instead of
clearing all listeners of the TabLayout.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
The loading text was drawn below the list and centred over the whole screen,
so it overlapped the toolbar text or was hidden under the items of the
previously selected tab.

The first page of a type now shows a centred circular progress indicator in
the content area, and further pages show one as a footer row at the end of
the list, spanning the full width of the media grid. Selecting another type
replaces the list right away with that type's empty adapter, and the empty
view is placed below the app bar.

The next-page request is posted from onScrolled, as showing the footer must
not change the adapter during a layout or scroll pass.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi
mahibi force-pushed the fixSharedItemsScreen branch from 304d1b3 to 3fd8fdc Compare November 16, 2026 18:22
@mahibi
mahibi marked this pull request as ready for review November 16, 2026 18:27
…ever

A failed types request or first page now shows an error with a Retry
button instead of an endless spinner. A failed next page shows the error
and Retry in the list footer and is no longer requested again on every
scroll, which retried it in a tight loop.

The overview request throws on a server error, so it is reported as an
error instead of "No shared items". The list only posts a next page
request from onScrolled when one can be loaded.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi
mahibi force-pushed the fixSharedItemsScreen branch from 3fd8fdc to 31de1ec Compare November 16, 2026 18:28
@mahibi
mahibi marked this pull request as draft November 16, 2026 18:30
@mahibi
mahibi marked this pull request as ready for review November 16, 2026 18:31
@mahibi

mahibi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

I was tempted to continue migrating it to Compose, but I'm stopping here since the bugs have been fixed. Migration can be a followup

The DiffUtil callback compares shared items with equals. All
implementations are data classes, but lint only saw the plain interface
and reported a suspicious equality check. Sealing the interface lets
lint check every implementation.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi
mahibi requested a review from rapterjet2004 November 16, 2026 18:34
@github-actions

Copy link
Copy Markdown
Contributor

Codacy

Lint

TypemasterPR
Warnings1716
Errors00

SpotBugs

CategoryBaseNew
Bad practice77
Correctness88
Dodgy code4040
Internationalization33
Malicious code vulnerability33
Performance77
Security1111
Total7979

@mahibi
mahibi merged commit 31323b8 into master Nov 17, 2026
20 checks passed
@mahibi
mahibi deleted the fixSharedItemsScreen branch November 17, 2026 09:20
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.

Scrolling through "Shared Items" keeps jumping back to top duplicated items in SharedItemsActivity

2 participants