Skip to content

Commit

Permalink
Merge pull request #7002 from Bnyro/master
Browse files Browse the repository at this point in the history
fix: mark as (un)watched button
  • Loading branch information
Bnyro authored Jan 22, 2025
2 parents b9123f7 + c674f61 commit d7dd246
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
val progress = DatabaseHelper.getWatchPositionBlocking(videoId)?.div(1000)
if (progress == null || progress == 0L) {
isGone = true
return
}

updateLayoutParams<ConstraintLayout.LayoutParams> {
matchConstraintPercentWidth = 0f
matchConstraintPercentWidth = progress.toFloat()/ duration.toFloat()
}

var backgroundColor = ThemeHelper.getThemeColor(
context,
com.google.android.material.R.attr.colorPrimaryDark
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit d7dd246

Please sign in to comment.