mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Add single item insertion methods.
This commit is contained in:
parent
5838e2bd4f
commit
58f1871abd
@ -30,7 +30,7 @@ object SubscriptionHelper {
|
|||||||
Log.e(TAG(), e.toString())
|
Log.e(TAG(), e.toString())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Database.localSubscriptionDao().insertAll(listOf(LocalSubscription(channelId)))
|
Database.localSubscriptionDao().insert(LocalSubscription(channelId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ object DatabaseHelper {
|
|||||||
streams.thumbnailUrl,
|
streams.thumbnailUrl,
|
||||||
streams.duration
|
streams.duration
|
||||||
)
|
)
|
||||||
Database.watchHistoryDao().insertAll(listOf(watchHistoryItem))
|
Database.watchHistoryDao().insert(watchHistoryItem)
|
||||||
val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "100")
|
val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "100")
|
||||||
if (maxHistorySize == "unlimited") {
|
if (maxHistorySize == "unlimited") {
|
||||||
return@withContext
|
return@withContext
|
||||||
@ -38,7 +38,7 @@ object DatabaseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addToSearchHistory(searchHistoryItem: SearchHistoryItem) {
|
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
|
// delete the first watch history entry if the limit is reached
|
||||||
val searchHistory = Database.searchHistoryDao().getAll()
|
val searchHistory = Database.searchHistoryDao().getAll()
|
||||||
|
@ -11,6 +11,9 @@ interface CustomInstanceDao {
|
|||||||
@Query("SELECT * FROM customInstance")
|
@Query("SELECT * FROM customInstance")
|
||||||
suspend fun getAll(): List<CustomInstance>
|
suspend fun getAll(): List<CustomInstance>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(customInstance: CustomInstance)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(customInstances: List<CustomInstance>)
|
suspend fun insertAll(customInstances: List<CustomInstance>)
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ interface LocalSubscriptionDao {
|
|||||||
@Query("SELECT * FROM localSubscription")
|
@Query("SELECT * FROM localSubscription")
|
||||||
suspend fun getAll(): List<LocalSubscription>
|
suspend fun getAll(): List<LocalSubscription>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(localSubscription: LocalSubscription)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(localSubscriptions: List<LocalSubscription>)
|
suspend fun insertAll(localSubscriptions: List<LocalSubscription>)
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ interface PlaylistBookmarkDao {
|
|||||||
@Query("SELECT * FROM playlistBookmark")
|
@Query("SELECT * FROM playlistBookmark")
|
||||||
suspend fun getAll(): List<PlaylistBookmark>
|
suspend fun getAll(): List<PlaylistBookmark>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(bookmark: PlaylistBookmark)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(bookmarks: List<PlaylistBookmark>)
|
suspend fun insertAll(bookmarks: List<PlaylistBookmark>)
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ interface SearchHistoryDao {
|
|||||||
@Query("SELECT * FROM searchHistoryItem")
|
@Query("SELECT * FROM searchHistoryItem")
|
||||||
suspend fun getAll(): List<SearchHistoryItem>
|
suspend fun getAll(): List<SearchHistoryItem>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(searchHistoryItem: SearchHistoryItem)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(searchHistoryItems: List<SearchHistoryItem>)
|
suspend fun insertAll(searchHistoryItems: List<SearchHistoryItem>)
|
||||||
|
|
||||||
|
@ -12,6 +12,9 @@ interface WatchHistoryDao {
|
|||||||
@Query("SELECT * FROM watchHistoryItem")
|
@Query("SELECT * FROM watchHistoryItem")
|
||||||
suspend fun getAll(): List<WatchHistoryItem>
|
suspend fun getAll(): List<WatchHistoryItem>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(watchHistoryItem: WatchHistoryItem)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(watchHistoryItems: List<WatchHistoryItem>)
|
suspend fun insertAll(watchHistoryItems: List<WatchHistoryItem>)
|
||||||
|
|
||||||
|
@ -14,6 +14,9 @@ interface WatchPositionDao {
|
|||||||
@Query("SELECT * FROM watchPosition WHERE videoId LIKE :videoId LIMIT 1")
|
@Query("SELECT * FROM watchPosition WHERE videoId LIKE :videoId LIMIT 1")
|
||||||
suspend fun findById(videoId: String): WatchPosition?
|
suspend fun findById(videoId: String): WatchPosition?
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insert(watchPosition: WatchPosition)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAll(watchPositions: List<WatchPosition>)
|
suspend fun insertAll(watchPositions: List<WatchPosition>)
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class BackgroundMode : LifecycleService() {
|
|||||||
this.streams ?: return@let
|
this.streams ?: return@let
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
Database.watchPositionDao().insertAll(listOf(watchPosition))
|
Database.watchPositionDao().insert(watchPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handler.postDelayed(this::updateWatchPosition, 500)
|
handler.postDelayed(this::updateWatchPosition, 500)
|
||||||
|
@ -86,7 +86,7 @@ class PlaylistBookmarkAdapter(
|
|||||||
DatabaseHolder.Database.playlistBookmarkDao()
|
DatabaseHolder.Database.playlistBookmarkDao()
|
||||||
.deleteById(bookmark.playlistId)
|
.deleteById(bookmark.playlistId)
|
||||||
} else {
|
} 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) {
|
if (apiUrl.toHttpUrlOrNull() != null && frontendUrl.toHttpUrlOrNull() != null) {
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
Database.customInstanceDao()
|
Database.customInstanceDao()
|
||||||
.insertAll(listOf(CustomInstance(instanceName, apiUrl, frontendUrl)))
|
.insert(CustomInstance(instanceName, apiUrl, frontendUrl))
|
||||||
ActivityCompat.recreate(requireActivity())
|
ActivityCompat.recreate(requireActivity())
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
@ -644,7 +644,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
|||||||
if (!PlayerHelper.watchPositionsVideo) return
|
if (!PlayerHelper.watchPositionsVideo) return
|
||||||
val watchPosition = WatchPosition(videoId!!, exoPlayer.currentPosition)
|
val watchPosition = WatchPosition(videoId!!, exoPlayer.currentPosition)
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
Database.watchPositionDao().insertAll(listOf(watchPosition))
|
Database.watchPositionDao().insert(watchPosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ class PlaylistFragment : Fragment() {
|
|||||||
.deleteById(playlistId!!)
|
.deleteById(playlistId!!)
|
||||||
} else {
|
} else {
|
||||||
DatabaseHolder.Database.playlistBookmarkDao()
|
DatabaseHolder.Database.playlistBookmarkDao()
|
||||||
.insertAll(listOf(response.toPlaylistBookmark(playlistId!!)))
|
.insert(response.toPlaylistBookmark(playlistId!!))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,7 @@ class PlaylistOptionsBottomSheet(
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
return@withContext
|
return@withContext
|
||||||
}.toPlaylistBookmark(playlistId)
|
}.toPlaylistBookmark(playlistId)
|
||||||
DatabaseHolder.Database.playlistBookmarkDao()
|
DatabaseHolder.Database.playlistBookmarkDao().insert(bookmark)
|
||||||
.insertAll(listOf(bookmark))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,8 @@ class VideoOptionsBottomSheet(
|
|||||||
}
|
}
|
||||||
getString(R.string.mark_as_watched) -> {
|
getString(R.string.mark_as_watched) -> {
|
||||||
val watchPosition = WatchPosition(videoId, Long.MAX_VALUE)
|
val watchPosition = WatchPosition(videoId, Long.MAX_VALUE)
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
withContext(Dispatchers.IO) {
|
||||||
DatabaseHolder.Database.watchPositionDao().insertAll(listOf(watchPosition))
|
DatabaseHolder.Database.watchPositionDao().insert(watchPosition)
|
||||||
}
|
}
|
||||||
if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
|
if (PreferenceHelper.getBoolean(PreferenceKeys.HIDE_WATCHED_FROM_FEED, false)) {
|
||||||
// get the host fragment containing the current fragment
|
// get the host fragment containing the current fragment
|
||||||
|
Loading…
Reference in New Issue
Block a user