Skip to content

Commit

Permalink
Fix bug: Back navigation resets scroll state in note list -> https://…
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancoltech committed Sep 26, 2024
1 parent 6366e44 commit 9a5fd37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NotesFragment: Fragment() {
private var showingFloatingButtons = false
private var playingAudioPath: String? = null
private var playingAudioPosition = -1
private var lastNoteItemPosition = 0

private val newTextNoteClickListener = View.OnClickListener {
onFloatingActionButtonClicked()
Expand Down Expand Up @@ -202,13 +203,11 @@ class NotesFragment: Fragment() {
binding.groupEmptyState.gone()
binding.rvPinnedNotes.visible()
binding.edtSearch.visible()
binding.scrollViewNotes.visible()
} else {
binding.layoutBottomControl.gone()
binding.groupEmptyState.visible()
binding.rvPinnedNotes.gone()
binding.edtSearch.gone()
binding.scrollViewNotes.gone()
}
}

Expand Down Expand Up @@ -250,10 +249,17 @@ class NotesFragment: Fragment() {
}
}

override fun onPause() {
super.onPause()
val layoutMgr = (binding.rvPinnedNotes.layoutManager as? LinearLayoutManager)
lastNoteItemPosition = layoutMgr?.findFirstCompletelyVisibleItemPosition() ?: 0
}

override fun onResume() {
super.onResume()
activity.fragment = this
observeClipboardContent()
binding.rvPinnedNotes.layoutManager?.scrollToPosition(lastNoteItemPosition)
}

private fun createTextNote() {
Expand Down
54 changes: 3 additions & 51 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,64 +182,16 @@
android:layout_marginBottom="16dp"
app:icon="@drawable/add"/>

<androidx.core.widget.NestedScrollView
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@+id/view_bottom_panel"
android:paddingHorizontal="@dimen/home_horizontal_margin"
android:id="@+id/scroll_view_notes"
app:layout_constraintTop_toBottomOf="@+id/edt_search">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextSmall"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/tv_header_pinned"
android:text="@string/ark_memo_notes_title_pinned"
android:visibility="gone"/>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/rv_pinned_notes"
android:layout_marginTop="12dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextSmall"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rv_pinned_notes"
android:id="@+id/tv_header_recent"
android:layout_marginTop="24dp"
android:visibility="gone"
android:text="@string/ark_memo_notes_title_recent"/>

<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/rv_recent_notes"
app:layout_constraintTop_toBottomOf="@+id/tv_header_recent"
android:layout_marginTop="12dp"
android:visibility="gone"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>
android:id="@+id/rv_pinned_notes"
app:layout_constraintTop_toBottomOf="@+id/edt_search"/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab_draw"
Expand Down

0 comments on commit 9a5fd37

Please sign in to comment.