Merge pull request #7002 from Bnyro/master

fix: mark as (un)watched button
This commit is contained in:
Bnyro 2025-01-22 18:18:26 +01:00 committed by GitHub
commit d7dd246ff2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 20 deletions

View File

@ -16,9 +16,16 @@ import com.github.libretube.helpers.ThemeHelper
* @param duration The duration of the video in seconds * @param duration The duration of the video in seconds
*/ */
fun View.setWatchProgressLength(videoId: String, duration: Long) { fun View.setWatchProgressLength(videoId: String, duration: Long) {
updateLayoutParams<ConstraintLayout.LayoutParams> { val progress = DatabaseHelper.getWatchPositionBlocking(videoId)?.div(1000)
matchConstraintPercentWidth = 0f if (progress == null || progress == 0L) {
isGone = true
return
} }
updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = progress.toFloat()/ duration.toFloat()
}
var backgroundColor = ThemeHelper.getThemeColor( var backgroundColor = ThemeHelper.getThemeColor(
context, context,
com.google.android.material.R.attr.colorPrimaryDark 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) backgroundColor = ColorUtils.blendARGB(backgroundColor, Color.WHITE, 0.4f)
} }
setBackgroundColor(backgroundColor) 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 isVisible = true
} }

View File

@ -101,9 +101,10 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
val watchPosition = WatchPosition(videoId, Long.MAX_VALUE) val watchPosition = WatchPosition(videoId, Long.MAX_VALUE)
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
DatabaseHolder.Database.watchPositionDao().insert(watchPosition) DatabaseHolder.Database.watchPositionDao().insert(watchPosition)
if (!PlayerHelper.watchHistoryEnabled) return@withContext
// add video to watch history if (PlayerHelper.watchHistoryEnabled) {
DatabaseHelper.addToWatchHistory(streamItem.toWatchHistoryItem(videoId)) DatabaseHelper.addToWatchHistory(streamItem.toWatchHistoryItem(videoId))
}
} }
if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) { if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
// get the host fragment containing the current fragment // get the host fragment containing the current fragment
@ -146,13 +147,14 @@ class VideoOptionsBottomSheet : BaseBottomSheet() {
DatabaseHolder.Database.watchHistoryDao().findById(videoId) DatabaseHolder.Database.watchHistoryDao().findById(videoId)
} }
val isWatched = DatabaseHelper.isVideoWatchedBlocking(videoId, streamItem.duration ?: 0) val position = DatabaseHelper.getWatchPositionBlocking(videoId) ?: 0
if (isWatched || watchHistoryEntry != null) { val isCompleted = DatabaseHelper.isVideoWatched(position, streamItem.duration ?: 0)
if (position != 0L || watchHistoryEntry != null) {
optionsList += R.string.mark_as_unwatched optionsList += R.string.mark_as_unwatched
} }
if (!isWatched || watchHistoryEntry == null) { if (!isCompleted || watchHistoryEntry == null) {
R.string.mark_as_watched optionsList += R.string.mark_as_watched
} }
} }