mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
show watched time under the video
This commit is contained in:
parent
7b58bc81ba
commit
9fefb0fc32
@ -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<StreamItem>,
|
||||
@ -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!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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!!)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<StreamItem>,
|
||||
@ -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!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<WatchHistoryItem>,
|
||||
@ -52,6 +57,8 @@ class WatchHistoryAdapter(
|
||||
.show(childFragmentManager, "VideoOptionsDialog")
|
||||
true
|
||||
}
|
||||
|
||||
watchProgress.setWatchProgressLength(video.videoId!!, video.duration.toLong())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@ -25,27 +25,42 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="5dp"
|
||||
app:cardBackgroundColor="@color/duration_background_color"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp">
|
||||
android:layout_gravity="bottom"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/thumbnail_duration"
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:textColor="@color/duration_text_color"
|
||||
tools:text="05:36" />
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
app:cardBackgroundColor="@color/duration_background_color"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
<TextView
|
||||
android:id="@+id/thumbnail_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="11sp"
|
||||
tools:text="05:36" />
|
||||
|
||||
</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>
|
||||
|
||||
|
@ -35,29 +35,42 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:srcCompat="@tools:sample/backgrounds/scenic" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="3dp"
|
||||
app:cardBackgroundColor="@color/duration_background_color"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp">
|
||||
android:layout_gravity="bottom"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/thumbnail_duration"
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="6dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingEnd="6dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:textColor="@color/duration_text_color"
|
||||
android:textSize="11sp"
|
||||
tools:text="05:36" />
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
app:cardBackgroundColor="@color/duration_background_color"
|
||||
app:cardCornerRadius="8dp"
|
||||
app:cardElevation="0dp">
|
||||
|
||||
</androidx.cardview.widget.CardView>
|
||||
<TextView
|
||||
android:id="@+id/thumbnail_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="11sp"
|
||||
tools:text="05:36" />
|
||||
|
||||
</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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user