diff --git a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt index 9074ada26..eb723e9d0 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/SetWatchProgressLength.kt @@ -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 { - matchConstraintPercentWidth = 0f + val progress = DatabaseHelper.getWatchPositionBlocking(videoId)?.div(1000) + if (progress == null || progress == 0L) { + isGone = true + return } + + updateLayoutParams { + 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 { - matchConstraintPercentWidth = progress / duration.toFloat() - } isVisible = true } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt index 327eecdca..65eeaceef 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt @@ -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 } }