Merge pull request #3154 from Isira-Seneviratne/Improve_WatchPositionDao

Improve WatchPositionDao.
This commit is contained in:
Bnyro 2023-02-22 10:11:46 +01:00 committed by GitHub
commit d2e2d806b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 14 deletions

View File

@ -1,7 +1,6 @@
package com.github.libretube.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
@ -16,13 +15,7 @@ interface WatchPositionDao {
suspend fun findById(videoId: String): WatchPosition?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(vararg watchPositions: WatchPosition)
@Delete
suspend fun delete(watchPosition: WatchPosition)
@Query("DELETE FROM watchHistoryItem WHERE videoId = :videoId")
suspend fun deleteById(videoId: String)
suspend fun insertAll(watchPositions: List<WatchPosition>)
@Query("DELETE FROM watchPosition")
suspend fun deleteAll()

View File

@ -48,9 +48,7 @@ object BackupHelper {
Database.watchHistoryDao().insertAll(backupFile.watchHistory.orEmpty())
Database.searchHistoryDao().insertAll(backupFile.searchHistory.orEmpty())
Database.watchPositionDao().insertAll(
*backupFile.watchPositions.orEmpty().toTypedArray()
)
Database.watchPositionDao().insertAll(backupFile.watchPositions.orEmpty())
Database.localSubscriptionDao().insertAll(backupFile.localSubscriptions.orEmpty())
Database.customInstanceDao().insertAll(backupFile.customInstances.orEmpty())
Database.playlistBookmarkDao().insertAll(

View File

@ -155,7 +155,7 @@ class BackgroundMode : LifecycleService() {
this.streams ?: return@let
CoroutineScope(Dispatchers.IO).launch {
Database.watchPositionDao().insertAll(watchPosition)
Database.watchPositionDao().insertAll(listOf(watchPosition))
}
}
handler.postDelayed(this::updateWatchPosition, 500)

View File

@ -609,7 +609,7 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
if (!PlayerHelper.watchPositionsVideo) return
val watchPosition = WatchPosition(videoId!!, exoPlayer.currentPosition)
CoroutineScope(Dispatchers.IO).launch {
Database.watchPositionDao().insertAll(watchPosition)
Database.watchPositionDao().insertAll(listOf(watchPosition))
}
}

View File

@ -101,7 +101,7 @@ class VideoOptionsBottomSheet(
getString(R.string.mark_as_watched) -> {
val watchPosition = WatchPosition(videoId, Long.MAX_VALUE)
CoroutineScope(Dispatchers.IO).launch {
DatabaseHolder.Database.watchPositionDao().insertAll(watchPosition)
DatabaseHolder.Database.watchPositionDao().insertAll(listOf(watchPosition))
}
if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
// get the host fragment containing the current fragment