mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Show 'mark as unwatched' in video options sheet if already watched
This commit is contained in:
parent
5dcafdaaf9
commit
2573c37322
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user