Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class ListsTabFragment : UnchainedFragment() {
findNavController().navigate(action)
}

binding.fabScrollToTop.setOnClickListener {
viewModel.postScrollToTop(binding.tabs.selectedTabPosition)
}

// an external link has been shared with the app
activityViewModel.externalLinkLiveData.observe(
viewLifecycleOwner,
Expand Down Expand Up @@ -624,6 +628,15 @@ class DownloadsListFragment : UnchainedFragment(), DownloadListListener {
},
)

// scroll the list to the top when the parent fragment fab is clicked on this tab
viewModel.scrollToTopLiveData.observe(viewLifecycleOwner) { event ->
if (event?.peekContent() == DOWNLOADS_TAB) {
event.getContentIfNotHandled()?.let {
if (_binding != null) binding.rvDownloadList.layoutManager?.scrollToPosition(0)
}
}
}

// starts the Transformations.switchMap(queryLiveData) which otherwise won't trigger the
// Paging
// request
Expand Down Expand Up @@ -835,6 +848,15 @@ class TorrentsListFragment : UnchainedFragment(), TorrentListListener {
},
)

// scroll the list to the top when the parent fragment fab is clicked on this tab
viewModel.scrollToTopLiveData.observe(viewLifecycleOwner) { event ->
if (event?.peekContent() == TORRENTS_TAB) {
event.getContentIfNotHandled()?.let {
if (_binding != null) binding.rvTorrentList.layoutManager?.scrollToPosition(0)
}
}
}

return binding.root
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ constructor(

val eventLiveData = MutableLiveData<Event<ListEvent>>()

// tab index of the list to be scrolled to the top, see ListsTabFragment fabScrollToTop
val scrollToTopLiveData = MutableLiveData<Event<Int>>()

/**
* Un restrict a torrent and move it to the download section
*
Expand Down Expand Up @@ -178,6 +181,10 @@ constructor(
eventLiveData.postEvent(event)
}

fun postScrollToTop(tab: Int) {
scrollToTopLiveData.postEvent(tab)
}

companion object {
const val KEY_SELECTED_TAB = "selected_tab_key"
const val TORRENT_DELETED = -1
Expand Down
10 changes: 10 additions & 0 deletions app/app/src/main/res/drawable/icon_arrow_upward.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8L4,12z"/>
</vector>
12 changes: 12 additions & 0 deletions app/app/src/main/res/layout/fragment_tab_lists.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tabs" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
Comment thread
ElCruncharino marked this conversation as resolved.
android:id="@+id/fabScrollToTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:contentDescription="@string/scroll_to_top"
app:fabSize="mini"
app:layout_constraintBottom_toTopOf="@id/fabNewDownload"
app:layout_constraintEnd_toEndOf="@id/fabNewDownload"
app:layout_constraintStart_toStartOf="@id/fabNewDownload"
app:srcCompat="@drawable/icon_arrow_upward" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabNewDownload"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="premium_days_format">Remaining days: %1$d</string>
<string name="user">User</string>
<string name="new_download">New Download</string>
<string name="scroll_to_top">Scroll to the top</string>
Comment thread
ElCruncharino marked this conversation as resolved.
<string name="remote_traffic">Remote Traffic</string>
<string name="password_optional">Password [Optional]</string>
<string name="yes">Yes</string>
Expand Down
Loading