Add single item insertion methods.

This commit is contained in:
Isira Seneviratne 2023-04-02 08:49:57 +05:30
parent 5838e2bd4f
commit 58f1871abd
15 changed files with 29 additions and 12 deletions

View File

@ -30,7 +30,7 @@ object SubscriptionHelper {
Log.e(TAG(), e.toString())
}
} else {
Database.localSubscriptionDao().insertAll(listOf(LocalSubscription(channelId)))
Database.localSubscriptionDao().insert(LocalSubscription(channelId))
}
}

View File

@ -24,7 +24,7 @@ object DatabaseHelper {
streams.thumbnailUrl,
streams.duration
)
Database.watchHistoryDao().insertAll(listOf(watchHistoryItem))
Database.watchHistoryDao().insert(watchHistoryItem)
val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "100")
if (maxHistorySize == "unlimited") {
return@withContext
@ -38,7 +38,7 @@ object DatabaseHelper {
}
suspend fun addToSearchHistory(searchHistoryItem: SearchHistoryItem) {
Database.searchHistoryDao().insertAll(listOf(searchHistoryItem))
Database.searchHistoryDao().insert(searchHistoryItem)
// delete the first watch history entry if the limit is reached
val searchHistory = Database.searchHistoryDao().getAll()

View File

@ -11,6 +11,9 @@ interface CustomInstanceDao {
@Query("SELECT * FROM customInstance")
suspend fun getAll(): List<CustomInstance>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(customInstance: CustomInstance)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(customInstances: List<CustomInstance>)

View File

@ -12,6 +12,9 @@ interface LocalSubscriptionDao {
@Query("SELECT * FROM localSubscription")
suspend fun getAll(): List<LocalSubscription>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(localSubscription: LocalSubscription)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(localSubscriptions: List<LocalSubscription>)

View File

@ -12,6 +12,9 @@ interface PlaylistBookmarkDao {
@Query("SELECT * FROM playlistBookmark")
suspend fun getAll(): List<PlaylistBookmark>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(bookmark: PlaylistBookmark)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(bookmarks: List<PlaylistBookmark>)

View File

@ -12,6 +12,9 @@ interface SearchHistoryDao {
@Query("SELECT * FROM searchHistoryItem")
suspend fun getAll(): List<SearchHistoryItem>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(searchHistoryItem: SearchHistoryItem)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(searchHistoryItems: List<SearchHistoryItem>)

View File

@ -12,6 +12,9 @@ interface WatchHistoryDao {
@Query("SELECT * FROM watchHistoryItem")
suspend fun getAll(): List<WatchHistoryItem>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(watchHistoryItem: WatchHistoryItem)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(watchHistoryItems: List<WatchHistoryItem>)

View File

@ -14,6 +14,9 @@ interface WatchPositionDao {
@Query("SELECT * FROM watchPosition WHERE videoId LIKE :videoId LIMIT 1")
suspend fun findById(videoId: String): WatchPosition?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(watchPosition: WatchPosition)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(watchPositions: List<WatchPosition>)

View File

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

View File

@ -86,7 +86,7 @@ class PlaylistBookmarkAdapter(
DatabaseHolder.Database.playlistBookmarkDao()
.deleteById(bookmark.playlistId)
} else {
DatabaseHolder.Database.playlistBookmarkDao().insertAll(listOf(bookmark))
DatabaseHolder.Database.playlistBookmarkDao().insert(bookmark)
}
}
}

View File

@ -31,7 +31,7 @@ class CustomInstanceDialog : DialogFragment() {
if (apiUrl.toHttpUrlOrNull() != null && frontendUrl.toHttpUrlOrNull() != null) {
lifecycleScope.launch {
Database.customInstanceDao()
.insertAll(listOf(CustomInstance(instanceName, apiUrl, frontendUrl)))
.insert(CustomInstance(instanceName, apiUrl, frontendUrl))
ActivityCompat.recreate(requireActivity())
dismiss()
}

View File

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

View File

@ -166,7 +166,7 @@ class PlaylistFragment : Fragment() {
.deleteById(playlistId!!)
} else {
DatabaseHolder.Database.playlistBookmarkDao()
.insertAll(listOf(response.toPlaylistBookmark(playlistId!!)))
.insert(response.toPlaylistBookmark(playlistId!!))
}
}
}

View File

@ -102,8 +102,7 @@ class PlaylistOptionsBottomSheet(
} catch (e: Exception) {
return@withContext
}.toPlaylistBookmark(playlistId)
DatabaseHolder.Database.playlistBookmarkDao()
.insertAll(listOf(bookmark))
DatabaseHolder.Database.playlistBookmarkDao().insert(bookmark)
}
}
}

View File

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