mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Merge pull request #7002 from Bnyro/master
fix: mark as (un)watched button
This commit is contained in:
commit
d7dd246ff2
@ -16,9 +16,16 @@ import com.github.libretube.helpers.ThemeHelper
|
||||
* @param duration The duration of the video in seconds
|
||||
*/
|
||||
fun View.setWatchProgressLength(videoId: String, duration: Long) {
|
||||
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
matchConstraintPercentWidth = 0f
|
||||
val progress = DatabaseHelper.getWatchPositionBlocking(videoId)?.div(1000)
|
||||
if (progress == null || progress == 0L) {
|
||||
isGone = true
|
||||
return
|
||||
}
|
||||
|
||||
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
matchConstraintPercentWidth = progress.toFloat()/ duration.toFloat()
|
||||
}
|
||||
|
||||
var backgroundColor = ThemeHelper.getThemeColor(
|
||||
context,
|
||||
com.google.android.material.R.attr.colorPrimaryDark
|
||||
@ -28,17 +35,6 @@ fun View.setWatchProgressLength(videoId: String, duration: Long) {
|
||||
backgroundColor = ColorUtils.blendARGB(backgroundColor, Color.WHITE, 0.4f)
|
||||
}
|
||||
setBackgroundColor(backgroundColor)
|
||||
isGone = true
|
||||
|
||||
if (duration == 0L) {
|
||||
return
|
||||
}
|
||||
|
||||
val progress = DatabaseHelper.getWatchPositionBlocking(videoId)?.div(1000)?.toFloat() ?: 0f
|
||||
|
||||
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
matchConstraintPercentWidth = progress / duration.toFloat()
|
||||
}
|
||||
|
||||
isVisible = true
|
||||
}
|
||||
|
@ -101,9 +101,10 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
val watchPosition = WatchPosition(videoId, Long.MAX_VALUE)
|
||||
withContext(Dispatchers.IO) {
|
||||
DatabaseHolder.Database.watchPositionDao().insert(watchPosition)
|
||||
if (!PlayerHelper.watchHistoryEnabled) return@withContext
|
||||
// add video to watch history
|
||||
DatabaseHelper.addToWatchHistory(streamItem.toWatchHistoryItem(videoId))
|
||||
|
||||
if (PlayerHelper.watchHistoryEnabled) {
|
||||
DatabaseHelper.addToWatchHistory(streamItem.toWatchHistoryItem(videoId))
|
||||
}
|
||||
}
|
||||
if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
|
||||
// get the host fragment containing the current fragment
|
||||
@ -146,13 +147,14 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
|
||||
DatabaseHolder.Database.watchHistoryDao().findById(videoId)
|
||||
}
|
||||
|
||||
val isWatched = DatabaseHelper.isVideoWatchedBlocking(videoId, streamItem.duration ?: 0)
|
||||
if (isWatched || watchHistoryEntry != null) {
|
||||
val position = DatabaseHelper.getWatchPositionBlocking(videoId) ?: 0
|
||||
val isCompleted = DatabaseHelper.isVideoWatched(position, streamItem.duration ?: 0)
|
||||
if (position != 0L || watchHistoryEntry != null) {
|
||||
optionsList += R.string.mark_as_unwatched
|
||||
}
|
||||
|
||||
if (!isWatched || watchHistoryEntry == null) {
|
||||
R.string.mark_as_watched
|
||||
if (!isCompleted || watchHistoryEntry == null) {
|
||||
optionsList += R.string.mark_as_watched
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user