Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show total playlist duration #6240

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -40,7 +40,7 @@ import kotlinx.coroutines.withContext
* playlists
*/
class PlaylistAdapter(
private val originalFeed: MutableList<StreamItem>,
val originalFeed: MutableList<StreamItem>,
private val sortedFeed: MutableList<StreamItem>,
private val playlistId: String,
private val playlistType: PlaylistType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -385,6 +386,8 @@ class PlaylistFragment : DynamicLayoutManagerFragment() {
val itemTouchHelper = ItemTouchHelper(itemTouchCallback)
itemTouchHelper.attachToRecyclerView(binding.playlistRecView)
}

updatePlaylistDuration()
}

@SuppressLint("StringFormatInvalid", "StringFormatMatches")
Expand Down Expand Up @@ -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
Expand Down
51 changes: 40 additions & 11 deletions app/src/main/res/layout/fragment_playlist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/playlist_recView"
Expand All @@ -25,7 +25,8 @@
android:id="@+id/playlist_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
android:visibility="gone"
tools:visibility="visible">

<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/playlist_collapsing_tb"
Expand All @@ -39,16 +40,44 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/thumbnail"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginVertical="10dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Small"
tools:src="@tools:sample/backgrounds/scenic" />
android:layout_marginHorizontal="14dp"
android:layout_marginVertical="10dp">

<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
app:shapeAppearanceOverlay="@style/ShapeAppearance.Material3.Corner.Small"
tools:src="@tools:sample/backgrounds/scenic" />

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp"
app:cardElevation="0dp">

<TextView
android:id="@+id/playlist_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="2dp"
android:textColor="@color/duration_text_color"
android:textSize="12sp"
tools:text="05:36" />

</androidx.cardview.widget.CardView>

</FrameLayout>

<LinearLayout
android:layout_width="match_parent"
Expand Down
Loading