Repository navigation
fix(shared-items): keep scroll position and avoid duplicates when paging - #7049
Merged
Merged
Conversation
Contributor
📱 QA build
The QA build installs alongside a released Nextcloud app, so you can keep Downloading the file requires a GitHub account, so open this link on the |
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
force-pushed
the
fixSharedItemsScreen
branch
from
November 16, 2026 18:22
304d1b3 to
3fd8fdc
Compare
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
force-pushed
the
fixSharedItemsScreen
branch
from
November 16, 2026 18:28
3fd8fdc to
31de1ec
Compare
mahibi
marked this pull request as draft
November 16, 2026 18:30
mahibi
marked this pull request as ready for review
November 16, 2026 18:31
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>
Contributor
rapterjet2004
approved these changes
Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🖼️ Screenvideos
🏚️ Before
sharedItemsScreenOldWithBugs.mp4
🏡 After
sharedItemsScreenNew.mp4
pictures are just shown duplicated here because i actually uploaded the same multiple times.
🏁 Checklist
/backport to stable-xx.x🤖 AI (if applicable)