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
*/
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
}

View File

@ -101,10 +101,11 @@ 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
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
val navHostFragment = (context as MainActivity).supportFragmentManager
@ -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
}
}