show watched time under the video

This commit is contained in:
Bnyro 2022-07-28 09:18:32 +02:00
parent 7b58bc81ba
commit 9fefb0fc32
8 changed files with 114 additions and 37 deletions

View File

@ -11,6 +11,7 @@ import com.github.libretube.obj.StreamItem
import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort import com.github.libretube.util.formatShort
import com.github.libretube.util.setWatchProgressLength
class ChannelAdapter( class ChannelAdapter(
private val videoFeed: MutableList<StreamItem>, private val videoFeed: MutableList<StreamItem>,
@ -46,12 +47,13 @@ class ChannelAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url) NavigationHelper.navigateVideo(root.context, trending.url)
} }
root.setOnLongClickListener {
val videoId = trending.url!!.replace("/watch?v=", "") val videoId = trending.url!!.replace("/watch?v=", "")
root.setOnLongClickListener {
VideoOptionsDialog(videoId, root.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, "VideoOptionsDialog") .show(childFragmentManager, "VideoOptionsDialog")
true true
} }
watchProgress.setWatchProgressLength(videoId, trending.duration!!)
} }
} }
} }

View File

@ -19,6 +19,7 @@ import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.RetrofitInstance import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.formatShort import com.github.libretube.util.formatShort
import com.github.libretube.util.setWatchProgressLength
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -101,8 +102,8 @@ class SearchAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, item.url) NavigationHelper.navigateVideo(root.context, item.url)
} }
root.setOnLongClickListener {
val videoId = item.url!!.replace("/watch?v=", "") val videoId = item.url!!.replace("/watch?v=", "")
root.setOnLongClickListener {
VideoOptionsDialog(videoId, root.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, "VideoOptionsDialog") .show(childFragmentManager, "VideoOptionsDialog")
true true
@ -110,6 +111,7 @@ class SearchAdapter(
channelImage.setOnClickListener { channelImage.setOnClickListener {
NavigationHelper.navigateChannel(root.context, item.uploaderUrl) NavigationHelper.navigateChannel(root.context, item.uploaderUrl)
} }
watchProgress.setWatchProgressLength(videoId, item.duration!!)
} }
} }

View File

@ -12,6 +12,7 @@ import com.github.libretube.obj.StreamItem
import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.formatShort import com.github.libretube.util.formatShort
import com.github.libretube.util.setWatchProgressLength
class TrendingAdapter( class TrendingAdapter(
private val streamItems: List<StreamItem>, private val streamItems: List<StreamItem>,
@ -51,12 +52,13 @@ class TrendingAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url) NavigationHelper.navigateVideo(root.context, trending.url)
} }
root.setOnLongClickListener {
val videoId = trending.url!!.replace("/watch?v=", "") val videoId = trending.url!!.replace("/watch?v=", "")
root.setOnLongClickListener {
VideoOptionsDialog(videoId, root.context) VideoOptionsDialog(videoId, root.context)
.show(childFragmentManager, "VideoOptionsDialog") .show(childFragmentManager, "VideoOptionsDialog")
true true
} }
watchProgress.setWatchProgressLength(videoId, trending.duration!!)
} }
} }
} }

View File

@ -1,15 +1,20 @@
package com.github.libretube.adapters package com.github.libretube.adapters
import android.text.format.DateUtils import android.text.format.DateUtils
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.dialogs.VideoOptionsDialog import com.github.libretube.dialogs.VideoOptionsDialog
import com.github.libretube.obj.WatchHistoryItem import com.github.libretube.obj.WatchHistoryItem
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.util.ConnectionHelper import com.github.libretube.util.ConnectionHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.setWatchProgressLength
class WatchHistoryAdapter( class WatchHistoryAdapter(
private val watchHistory: MutableList<WatchHistoryItem>, private val watchHistory: MutableList<WatchHistoryItem>,
@ -52,6 +57,8 @@ class WatchHistoryAdapter(
.show(childFragmentManager, "VideoOptionsDialog") .show(childFragmentManager, "VideoOptionsDialog")
true true
} }
watchProgress.setWatchProgressLength(video.videoId!!, video.duration.toLong())
} }
} }

View File

@ -853,6 +853,7 @@ class PlayerFragment : Fragment() {
private fun playNextVideo() { private fun playNextVideo() {
// check whether there is a new video in the queue // check whether there is a new video in the queue
// by making sure that the next and the current video aren't the same // by making sure that the next and the current video aren't the same
saveWatchPosition()
if (videoId != nextStreamId) { if (videoId != nextStreamId) {
// save the id of the next stream as videoId and load the next video // save the id of the next stream as videoId and load the next video
videoId = nextStreamId videoId = nextStreamId

View File

@ -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
}
}
})
}

View File

@ -25,11 +25,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="end"
android:layout_margin="5dp" android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
app:cardBackgroundColor="@color/duration_background_color" app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="0dp"> app:cardElevation="0dp">
@ -38,15 +45,23 @@
android:id="@+id/thumbnail_duration" android:id="@+id/thumbnail_duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="6dp" android:paddingHorizontal="6dp"
android:paddingTop="2dp" android:paddingVertical="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:textColor="@color/duration_text_color" android:textColor="@color/duration_text_color"
android:textSize="11sp"
tools:text="05:36" /> tools:text="05:36" />
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<View
android:id="@+id/watch_progress"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_gravity="bottom"
android:background="@android:color/holo_red_dark" />
</LinearLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>

View File

@ -35,12 +35,18 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:srcCompat="@tools:sample/backgrounds/scenic" /> tools:srcCompat="@tools:sample/backgrounds/scenic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="end"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_marginBottom="3dp" android:layout_marginBottom="5dp"
app:cardBackgroundColor="@color/duration_background_color" app:cardBackgroundColor="@color/duration_background_color"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="0dp"> app:cardElevation="0dp">
@ -49,16 +55,23 @@
android:id="@+id/thumbnail_duration" android:id="@+id/thumbnail_duration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="6dp" android:paddingHorizontal="6dp"
android:paddingTop="2dp" android:paddingVertical="2dp"
android:paddingEnd="6dp"
android:paddingBottom="2dp"
android:textColor="@color/duration_text_color" android:textColor="@color/duration_text_color"
android:textSize="11sp" android:textSize="11sp"
tools:text="05:36" /> tools:text="05:36" />
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<View
android:id="@+id/watch_progress"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_gravity="bottom"
android:background="@android:color/holo_red_dark" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
<TextView <TextView