diff --git a/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt b/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt index 770667532..a6620c9c8 100644 --- a/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/ChannelAdapter.kt @@ -11,6 +11,7 @@ import com.github.libretube.obj.StreamItem import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.NavigationHelper import com.github.libretube.util.formatShort +import com.github.libretube.util.setWatchProgressLength class ChannelAdapter( private val videoFeed: MutableList, @@ -46,12 +47,13 @@ class ChannelAdapter( root.setOnClickListener { NavigationHelper.navigateVideo(root.context, trending.url) } + val videoId = trending.url!!.replace("/watch?v=", "") root.setOnLongClickListener { - val videoId = trending.url!!.replace("/watch?v=", "") VideoOptionsDialog(videoId, root.context) .show(childFragmentManager, "VideoOptionsDialog") true } + watchProgress.setWatchProgressLength(videoId, trending.duration!!) } } } diff --git a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt index c2802a865..d88934757 100644 --- a/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/SearchAdapter.kt @@ -19,6 +19,7 @@ import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.NavigationHelper import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.formatShort +import com.github.libretube.util.setWatchProgressLength import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -101,8 +102,8 @@ class SearchAdapter( root.setOnClickListener { NavigationHelper.navigateVideo(root.context, item.url) } + val videoId = item.url!!.replace("/watch?v=", "") root.setOnLongClickListener { - val videoId = item.url!!.replace("/watch?v=", "") VideoOptionsDialog(videoId, root.context) .show(childFragmentManager, "VideoOptionsDialog") true @@ -110,6 +111,7 @@ class SearchAdapter( channelImage.setOnClickListener { NavigationHelper.navigateChannel(root.context, item.uploaderUrl) } + watchProgress.setWatchProgressLength(videoId, item.duration!!) } } diff --git a/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt b/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt index 3d6e7b48c..4c4b4f30e 100644 --- a/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/TrendingAdapter.kt @@ -12,6 +12,7 @@ import com.github.libretube.obj.StreamItem import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.NavigationHelper import com.github.libretube.util.formatShort +import com.github.libretube.util.setWatchProgressLength class TrendingAdapter( private val streamItems: List, @@ -51,12 +52,13 @@ class TrendingAdapter( root.setOnClickListener { NavigationHelper.navigateVideo(root.context, trending.url) } + val videoId = trending.url!!.replace("/watch?v=", "") root.setOnLongClickListener { - val videoId = trending.url!!.replace("/watch?v=", "") VideoOptionsDialog(videoId, root.context) .show(childFragmentManager, "VideoOptionsDialog") true } + watchProgress.setWatchProgressLength(videoId, trending.duration!!) } } } diff --git a/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt index afee515ca..32f0a5062 100644 --- a/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/WatchHistoryAdapter.kt @@ -1,15 +1,20 @@ package com.github.libretube.adapters import android.text.format.DateUtils +import android.util.Log import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup +import android.view.ViewTreeObserver.OnGlobalLayoutListener import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.dialogs.VideoOptionsDialog import com.github.libretube.obj.WatchHistoryItem +import com.github.libretube.preferences.PreferenceHelper import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.NavigationHelper +import com.github.libretube.util.setWatchProgressLength class WatchHistoryAdapter( private val watchHistory: MutableList, @@ -52,6 +57,8 @@ class WatchHistoryAdapter( .show(childFragmentManager, "VideoOptionsDialog") true } + + watchProgress.setWatchProgressLength(video.videoId!!, video.duration.toLong()) } } diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index b0cffc28f..f9499d3c8 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -853,6 +853,7 @@ class PlayerFragment : Fragment() { private fun playNextVideo() { // check whether there is a new video in the queue // by making sure that the next and the current video aren't the same + saveWatchPosition() if (videoId != nextStreamId) { // save the id of the next stream as videoId and load the next video videoId = nextStreamId diff --git a/app/src/main/java/com/github/libretube/util/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/util/SetWatchProgressLength.kt new file mode 100644 index 000000000..0fd79d838 --- /dev/null +++ b/app/src/main/java/com/github/libretube/util/SetWatchProgressLength.kt @@ -0,0 +1,35 @@ +package com.github.libretube.util + +import android.view.View +import android.view.ViewTreeObserver +import com.github.libretube.preferences.PreferenceHelper + +/** + * shows the already watched time under the video + */ +fun View?.setWatchProgressLength(videoId: String, duration: Long) { + val view = this!! + val positions = PreferenceHelper.getWatchPositions() + var newWidth: Long? = null + view.getViewTreeObserver() + .addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { + override fun onGlobalLayout() { + this@setWatchProgressLength.getViewTreeObserver().removeOnGlobalLayoutListener(this) + positions.forEach { + if (it.videoId == videoId) { + newWidth = (width * (it.position / (duration))) / 1000 + return@forEach + } + } + if (newWidth != null) { + val lp = view.layoutParams + lp.apply { + width = newWidth!!.toInt() + } + view.layoutParams = lp + } else { + view.visibility = View.GONE + } + } + }) +} diff --git a/app/src/main/res/layout/trending_row.xml b/app/src/main/res/layout/trending_row.xml index 1a05a5db5..94f137ed6 100644 --- a/app/src/main/res/layout/trending_row.xml +++ b/app/src/main/res/layout/trending_row.xml @@ -25,27 +25,42 @@ android:layout_width="match_parent" android:layout_height="match_parent" /> - + android:layout_gravity="bottom" + android:orientation="vertical"> - + android:layout_gravity="end" + android:layout_marginEnd="5dp" + android:layout_marginBottom="5dp" + app:cardBackgroundColor="@color/duration_background_color" + app:cardCornerRadius="8dp" + app:cardElevation="0dp"> - + + + + + + + diff --git a/app/src/main/res/layout/video_row.xml b/app/src/main/res/layout/video_row.xml index afde087e5..b1756ea61 100644 --- a/app/src/main/res/layout/video_row.xml +++ b/app/src/main/res/layout/video_row.xml @@ -35,29 +35,42 @@ android:layout_height="match_parent" tools:srcCompat="@tools:sample/backgrounds/scenic" /> - + android:layout_gravity="bottom" + android:orientation="vertical"> - + android:layout_gravity="end" + android:layout_marginEnd="5dp" + android:layout_marginBottom="5dp" + app:cardBackgroundColor="@color/duration_background_color" + app:cardCornerRadius="8dp" + app:cardElevation="0dp"> - + + + + + + +