Skip to content

Conversation

rapterjet2004
Copy link
Contributor

@rapterjet2004 rapterjet2004 commented Jun 9, 2025

Conversation List jumps to position of clicked conversation item when back pressed

ToDO

  • get/store position in shared preferences, not sure why I sent this by intent. Maybe I need some coffee.
  • Reevaluate scroll logic.

I couldn't find a reliable way to save/restore the vertical offset from the calculateVerticalOffset() method. The units don't translate reliably to the ones needed for scrollY and the method to scrollVerticallyBy() requires RecyclerView.State which is internal. Restoring the recycler view state from layoutManager.onSaveInstanceState() also doesn't work.

Current Implementation is quite simple though, requires keeping a reference to the item's viewHolder in ConversationItem. It's then gets the position of the first visible item and calculates the non visible offset to scroll by. The result is the exact position the user left off. Restored/Retrieved from AppPreferences.

🖼️ Screenshots

Screen_recording_20250609_124059.webm

🏁 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?)

@rapterjet2004 rapterjet2004 self-assigned this Jun 9, 2025
@rapterjet2004 rapterjet2004 changed the title Conversation List jumps to position of clicked conversation item when… Preserve Conversation List position Jun 9, 2025
@rapterjet2004 rapterjet2004 requested a review from mahibi June 10, 2025 17:00
@rapterjet2004 rapterjet2004 added the 3. to review Waiting for reviews label Jun 10, 2025
Copy link
Collaborator

@mahibi mahibi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always place the last opened conversation at the top when coming back. This is not expected but people expect the exact scroll position as when the chat was opened.

It should be solved with
scrollToPositionWithOffset
which gets the scroll position and the offset from when the chat was opened.

@rapterjet2004 rapterjet2004 force-pushed the issue-5041-jump-to-coversation branch from 6278b2f to 4792f17 Compare June 16, 2025 15:00
@rapterjet2004 rapterjet2004 requested a review from mahibi June 16, 2025 15:29
Copy link
Collaborator

@mahibi mahibi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the feeling this can be solved in a simpler way.

Right now the position is passed to ChatActivity and back to ConversationList. This should not be necessary at all but ConversationList should handle this itself.
For example this does not work when the app just goes to background and coming back.

Also, i guess that findFirstVisibleItemPosition is something that should not be necessary. It will "just" scroll to an item instead to the exact position.

Can you have a look if there are simpler ways to achieve this?
Like just using the scroll position on the recyclerview itself and just using lifecycle methods to save/restore the scroll postion, eg. from the viewmodel..?

@mahibi mahibi added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jun 24, 2025
@mahibi
Copy link
Collaborator

mahibi commented Jul 11, 2025

@rapterjet2004 whats the state for this PR? should it be "to review"?

@rapterjet2004 rapterjet2004 requested a review from mahibi July 15, 2025 15:05
@rapterjet2004 rapterjet2004 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 15, 2025
rapterjet2004 and others added 4 commits July 16, 2025 15:36
Signed-off-by: rapterjet2004 <[email protected]>
otherwise, it's would not work when just reopening the app from background

Signed-off-by: Marcel Hibbe <[email protected]>
@mahibi mahibi force-pushed the issue-5041-jump-to-coversation branch from 34e1919 to 38b5098 Compare July 16, 2025 14:00
@mahibi mahibi self-requested a review July 16, 2025 14:02
private const val SIXTEEN_HOURS_IN_SECONDS: Long = 57600
const val LONG_1000: Long = 1000
private const val NOTE_TO_SELF_SHORTCUT_ID = "NOTE_TO_SELF_SHORTCUT_ID"
private const val CONVERSATION_ITEM_HEIGHT = 44
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the nicest solution but fine for me as the handling will be replaced with Compose anyway

@mahibi mahibi enabled auto-merge July 16, 2025 14:16
Copy link
Contributor

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/5049-talk.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 Talk app.

Copy link
Contributor

Codacy

Lint

TypemasterPR
Warnings9796
Errors00

SpotBugs

CategoryBaseNew
Bad practice66
Correctness1616
Dodgy code6161
Internationalization33
Malicious code vulnerability33
Performance44
Security11
Total9494

@mahibi mahibi merged commit 1b2d419 into master Jul 16, 2025
15 of 16 checks passed
@mahibi mahibi deleted the issue-5041-jump-to-coversation branch July 16, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Jump to the top after press back button
2 participants