Update room to v2.5.0

This commit is contained in:
Renovate Bot 2023-01-20 13:14:47 +00:00 committed by birdbird
parent 3be49689e6
commit e5f1454675
4 changed files with 25 additions and 75 deletions
gradle
ultrasonic/src/main/kotlin/org/moire/ultrasonic

@ -15,7 +15,7 @@ androidSupport = "1.5.0"
materialDesign = "1.6.1"
constraintLayout = "2.1.4"
multidex = "2.0.1"
room = "2.4.3"
room = "2.5.0"
kotlin = "1.7.22"
kotlinxCoroutines = "1.6.4-native-mt"
kotlinxGuava = "1.6.4"

@ -2,7 +2,6 @@ package org.moire.ultrasonic.data
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Transaction
import org.moire.ultrasonic.domain.Album
@Dao
@ -66,39 +65,4 @@ interface AlbumDao : GenericDao<Album> {
*/
@Query("DELETE FROM albums WHERE id LIKE :id")
fun delete(id: String)
/**
* TODO: Make generic
* Upserts (insert or update) an object to the database
*
* @param obj the object to upsert
*/
@Transaction
@JvmSuppressWildcards
fun upsert(obj: Album) {
val id = insertIgnoring(obj)
if (id == -1L) {
update(obj)
}
}
/**
* Upserts (insert or update) a list of objects
*
* @param objList the object to be upserted
*/
@Transaction
@JvmSuppressWildcards
fun upsert(objList: List<Album>) {
val insertResult = insertIgnoring(objList)
val updateList: MutableList<Album> = ArrayList()
for (i in insertResult.indices) {
if (insertResult[i] == -1L) {
updateList.add(objList[i])
}
}
if (updateList.isNotEmpty()) {
update(updateList)
}
}
}

@ -5,8 +5,8 @@ import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import androidx.room.Upsert
import org.moire.ultrasonic.domain.Index
import org.moire.ultrasonic.domain.MusicFolder
@ -51,41 +51,6 @@ interface IndexDao : GenericDao<Index> {
*/
@Query("SELECT * FROM indexes where musicFolderId LIKE :musicFolderId")
fun get(musicFolderId: String): List<Index>
/**
* TODO: Make generic
* Upserts (insert or update) an object to the database
*
* @param obj the object to upsert
*/
@Transaction
@JvmSuppressWildcards
fun upsert(obj: Index) {
val id = insertIgnoring(obj)
if (id == -1L) {
update(obj)
}
}
/**
* Upserts (insert or update) a list of objects
*
* @param objList the object to be upserted
*/
@Transaction
@JvmSuppressWildcards
fun upsert(objList: List<Index>) {
val insertResult = insertIgnoring(objList)
val updateList: MutableList<Index> = ArrayList()
for (i in insertResult.indices) {
if (insertResult[i] == -1L) {
updateList.add(objList[i])
}
}
if (updateList.isNotEmpty()) {
update(updateList)
}
}
}
interface GenericDao<T> {
@ -154,4 +119,20 @@ interface GenericDao<T> {
@Delete
@JvmSuppressWildcards
fun delete(obj: T)
/**
* Upserts (insert or update) an object to the database
*
* @param obj the object to upsert
*/
@Upsert
fun upsert(obj: T)
/**
* Upserts (insert or update) a list of objects
*
* @param objList the object to be upserted
*/
@Upsert
fun upsert(objList: List<T>)
}

@ -76,14 +76,13 @@ class AlbumListFragment(
}
private fun fetchAlbums(refresh: Boolean = navArgs.refresh, append: Boolean = navArgs.append) {
val refresh = navArgs.refresh || refresh
listModel.viewModelScope.launch(handler) {
refreshListView?.isRefreshing = true
if (navArgs.byArtist) {
listModel.getAlbumsOfArtist(
refresh = navArgs.refresh,
refresh = refresh,
id = navArgs.id!!,
name = navArgs.title
)
@ -185,6 +184,12 @@ class AlbumListFragment(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Setup refresh handler
refreshListView = view.findViewById(refreshListId)
refreshListView?.setOnRefreshListener {
fetchAlbums(refresh = true)
}
// In most cases this fragment will be hosted by a ViewPager2 in the MainFragment,
// which provides its own FilterBar.
// But when we are looking at the Albums of a specific Artist this Fragment is standalone,