From bd556baa769c7a4bd64aafaeb459e5c9470acf22 Mon Sep 17 00:00:00 2001 From: faisalcodes Date: Tue, 31 Jan 2023 11:11:00 +0530 Subject: [PATCH 1/3] Fixes #2815 --- .../libretube/ui/adapters/PlaylistAdapter.kt | 12 ++++---- .../ui/extensions/SetWatchProgressLength.kt | 29 +++++++++---------- app/src/main/res/layout/trending_row.xml | 26 +++++++++-------- app/src/main/res/layout/video_row.xml | 27 ++++++++--------- app/src/main/res/values/style.xml | 3 +- 5 files changed, 48 insertions(+), 49 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 5fba1f429..e7a58beca 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 @@ -26,9 +26,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class PlaylistAdapter( - private val videoFeed: MutableList, - private val playlistId: String, - private val playlistType: PlaylistType + private val videoFeed: MutableList, + private val playlistId: String, + private val playlistType: PlaylistType ) : RecyclerView.Adapter() { var visibleCount = minOf(20, videoFeed.size) @@ -84,9 +84,7 @@ class PlaylistAdapter( if (!streamItem.uploaderUrl.isNullOrBlank()) { channelContainer.setOnClickListener { - streamItem.uploaderUrl?.toID()?.let { - NavigationHelper.navigateChannel(root.context, it) - } + NavigationHelper.navigateChannel(root.context, streamItem.uploaderUrl.toID()) } } @@ -96,7 +94,7 @@ class PlaylistAdapter( removeFromPlaylist(root.context, position) } } - watchProgress.setWatchProgressLength(videoId, streamItem.duration!!) + watchProgress.setWatchProgressLength(videoId, streamItem.duration) } } diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt index d11f979ed..333975bb4 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt @@ -1,8 +1,7 @@ package com.github.libretube.ui.extensions import android.view.View -import android.view.ViewTreeObserver -import android.widget.LinearLayout +import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.updateLayoutParams import com.github.libretube.db.DatabaseHolder.Companion.Database import com.github.libretube.extensions.awaitQuery @@ -16,6 +15,13 @@ import com.github.libretube.extensions.awaitQuery fun View?.setWatchProgressLength(videoId: String, duration: Long): Boolean { val view = this!! + view.apply { + updateLayoutParams { + matchConstraintPercentWidth = 0f + } + visibility = View.GONE + } + val progress = try { awaitQuery { Database.watchPositionDao().findById(videoId)?.position @@ -26,22 +32,15 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long): Boolean { ?.toFloat()?.div(1000) if (progress == null || duration == 0L) { - view.visibility = View.GONE return false } - view.viewTreeObserver - .addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { - override fun onGlobalLayout() { - this@setWatchProgressLength.viewTreeObserver.removeOnGlobalLayoutListener(this) - val fullWidth = (parent as LinearLayout).width - val newWidth = fullWidth * (progress / duration.toFloat()) - view.updateLayoutParams { - width = newWidth.toInt() - } - view.visibility = View.VISIBLE - } - }) + view.apply { + updateLayoutParams { + matchConstraintPercentWidth = (progress / duration.toFloat()) + } + visibility = View.VISIBLE + } return progress / duration.toFloat() > 0.9 } diff --git a/app/src/main/res/layout/trending_row.xml b/app/src/main/res/layout/trending_row.xml index 7ebb58466..f965f2a3d 100644 --- a/app/src/main/res/layout/trending_row.xml +++ b/app/src/main/res/layout/trending_row.xml @@ -20,16 +20,15 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - - + android:layout_height="match_parent"> + + + app:cardElevation="0dp" + app:layout_constraintBottom_toTopOf="@id/watch_progress" + app:layout_constraintEnd_toEndOf="parent"> - - + android:layout_height="5dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + diff --git a/app/src/main/res/layout/video_row.xml b/app/src/main/res/layout/video_row.xml index 165098b27..02a33a4f7 100644 --- a/app/src/main/res/layout/video_row.xml +++ b/app/src/main/res/layout/video_row.xml @@ -25,17 +25,15 @@ app:layout_constraintVertical_bias="0.0" app:strokeWidth="0dp"> - + android:layout_height="match_parent"> - + + app:cardElevation="0dp" + app:layout_constraintBottom_toTopOf="@id/watch_progress" + app:layout_constraintEnd_toEndOf="parent"> - - + style="@style/WatchProgress" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" /> + diff --git a/app/src/main/res/values/style.xml b/app/src/main/res/values/style.xml index 043068972..5518e107e 100644 --- a/app/src/main/res/values/style.xml +++ b/app/src/main/res/values/style.xml @@ -137,9 +137,8 @@