Merge pull request #3925 from Bnyro/master

Show 'mark as unwatched' in video options sheet if already watched
This commit is contained in:
Bnyro 2023-06-04 16:59:14 +02:00 committed by GitHub
commit 25dd630cfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -6,12 +6,16 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.db.obj.WatchPosition
@Dao
interface WatchHistoryDao {
@Query("SELECT * FROM watchHistoryItem")
suspend fun getAll(): List<WatchHistoryItem>
@Query("SELECT * FROM watchHistoryItem WHERE videoId LIKE :videoId LIMIT 1")
suspend fun findById(videoId: String): WatchHistoryItem?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(watchHistoryItem: WatchHistoryItem)
@ -21,6 +25,9 @@ interface WatchHistoryDao {
@Delete
suspend fun delete(watchHistoryItem: WatchHistoryItem)
@Query("DELETE FROM watchHistoryItem WHERE videoId = :id")
fun deleteByVideoId(id: String)
@Query("DELETE FROM watchHistoryItem")
suspend fun deleteAll()
}

View File

@ -20,6 +20,9 @@ interface WatchPositionDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(watchPositions: List<WatchPosition>)
@Query("DELETE FROM watchPosition WHERE videoId = :id")
fun deleteByVideoId(id: String)
@Query("DELETE FROM watchPosition")
suspend fun deleteAll()
}

View File

@ -20,6 +20,7 @@ import com.github.libretube.ui.dialogs.ShareDialog
import com.github.libretube.ui.fragments.SubscriptionsFragment
import com.github.libretube.util.PlayingQueue
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
/**
@ -47,9 +48,17 @@ class VideoOptionsBottomSheet(
optionsList += getString(R.string.add_to_queue)
}
// show the mark as watched option if watch positions are enabled
if (PlayerHelper.watchPositionsVideo) {
optionsList += getString(R.string.mark_as_watched)
// show the mark as watched or unwatched option if watch positions are enabled
if (PlayerHelper.watchPositionsVideo || PlayerHelper.watchHistoryEnabled) {
val watchPositionEntry = runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.watchPositionDao().findById(videoId)
}
val watchHistoryEntry = runBlocking(Dispatchers.IO) {
DatabaseHolder.Database.watchHistoryDao().findById(videoId)
}
optionsList += if (watchHistoryEntry != null || watchPositionEntry != null) {
getString(R.string.mark_as_unwatched)
} else getString(R.string.mark_as_watched)
}
setSimpleItems(optionsList) { which ->
@ -116,6 +125,12 @@ class VideoOptionsBottomSheet(
)
}
}
getString(R.string.mark_as_unwatched) -> {
withContext(Dispatchers.IO) {
DatabaseHolder.Database.watchPositionDao().deleteByVideoId(videoId)
DatabaseHolder.Database.watchHistoryDao().deleteByVideoId(videoId)
}
}
}
}

View File

@ -412,6 +412,7 @@
<string name="creation_date_reversed">Creation date (reversed)</string>
<string name="alphabetic">Alphabetic</string>
<string name="alphabetic_reversed">Alphabetic (reversed)</string>
<string name="mark_as_unwatched">Mark as unwatched</string>
<!-- Backup & Restore Settings -->
<string name="import_subscriptions_from">Import subscriptions from</string>