From 97c2f4378735e88612df56f1d9408be9357ca3ac Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 15 Jul 2024 14:50:04 +0200 Subject: [PATCH] feat: show total playlist duration --- .../libretube/ui/adapters/PlaylistAdapter.kt | 2 +- .../ui/fragments/PlaylistFragment.kt | 11 ++++ app/src/main/res/layout/fragment_playlist.xml | 51 +++++++++++++++---- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index f95fb73cf0..769647cf6a 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -40,7 +40,7 @@ import kotlinx.coroutines.withContext * playlists */ class PlaylistAdapter( - private val originalFeed: MutableList, + val originalFeed: MutableList, private val sortedFeed: MutableList, private val playlistId: String, private val playlistType: PlaylistType diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index e44568b0e7..6b1382b8fe 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.content.res.Configuration import android.os.Bundle import android.os.Parcelable +import android.text.format.DateUtils import android.util.Log import android.view.LayoutInflater import android.view.View @@ -385,6 +386,8 @@ class PlaylistFragment : DynamicLayoutManagerFragment() { val itemTouchHelper = ItemTouchHelper(itemTouchCallback) itemTouchHelper.attachToRecyclerView(binding.playlistRecView) } + + updatePlaylistDuration() } @SuppressLint("StringFormatInvalid", "StringFormatMatches") @@ -416,10 +419,18 @@ class PlaylistFragment : DynamicLayoutManagerFragment() { nextPage = response.nextpage playlistAdapter?.updateItems(response.relatedStreams) + updatePlaylistDuration() isLoading = false } } + @SuppressLint("SetTextI18n") + private fun updatePlaylistDuration() { + val totalDuration = playlistAdapter?.originalFeed?.sumOf { it.duration ?: 0 } ?: return + binding.playlistDuration.text = DateUtils.formatElapsedTime(totalDuration) + + if (nextPage != null) "+" else "" + } + override fun onConfigurationChanged(newConfig: Configuration) { super.onConfigurationChanged(newConfig) // manually restore the recyclerview state due to https://github.com/material-components/material-components-android/issues/3473 diff --git a/app/src/main/res/layout/fragment_playlist.xml b/app/src/main/res/layout/fragment_playlist.xml index 97d3596dd3..0cc587c318 100644 --- a/app/src/main/res/layout/fragment_playlist.xml +++ b/app/src/main/res/layout/fragment_playlist.xml @@ -10,8 +10,8 @@ android:id="@+id/playlist_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:visibility="gone" - android:layout_gravity="center" /> + android:layout_gravity="center" + android:visibility="gone" /> + android:visibility="gone" + tools:visibility="visible"> - + android:layout_marginHorizontal="14dp" + android:layout_marginVertical="10dp"> + + + + + + + + + +