mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Merge pull request #3487 from Isira-Seneviratne/Insert
Add single item insertion methods.
This commit is contained in:
commit
0d12ea062c
@ -30,7 +30,7 @@ object SubscriptionHelper {
|
||||
Log.e(TAG(), e.toString())
|
||||
}
|
||||
} else {
|
||||
Database.localSubscriptionDao().insertAll(listOf(LocalSubscription(channelId)))
|
||||
Database.localSubscriptionDao().insert(LocalSubscription(channelId))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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>)
|
||||
|
||||
|
@ -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>)
|
||||
|
||||
|
@ -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>)
|
||||
|
||||
|
@ -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>)
|
||||
|
||||
|
@ -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>)
|
||||
|
||||
|
@ -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>)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -86,7 +86,7 @@ class PlaylistBookmarkAdapter(
|
||||
DatabaseHolder.Database.playlistBookmarkDao()
|
||||
.deleteById(bookmark.playlistId)
|
||||
} else {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().insertAll(listOf(bookmark))
|
||||
DatabaseHolder.Database.playlistBookmarkDao().insert(bookmark)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ class PlaylistFragment : Fragment() {
|
||||
.deleteById(playlistId!!)
|
||||
} else {
|
||||
DatabaseHolder.Database.playlistBookmarkDao()
|
||||
.insertAll(listOf(response.toPlaylistBookmark(playlistId!!)))
|
||||
.insert(response.toPlaylistBookmark(playlistId!!))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,8 +102,7 @@ class PlaylistOptionsBottomSheet(
|
||||
} catch (e: Exception) {
|
||||
return@withContext
|
||||
}.toPlaylistBookmark(playlistId)
|
||||
DatabaseHolder.Database.playlistBookmarkDao()
|
||||
.insertAll(listOf(bookmark))
|
||||
DatabaseHolder.Database.playlistBookmarkDao().insert(bookmark)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user