ui: fix library updates in ui
Fix issues where the UI failed to update with library changes in the search/home view.
This commit is contained in:
parent
df435a12b8
commit
60e54abfe9
5 changed files with 14 additions and 7 deletions
|
@ -124,7 +124,3 @@ spotless {
|
||||||
licenseHeaderFile("NOTICE")
|
licenseHeaderFile("NOTICE")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
|
||||||
preDebugBuild.dependsOn spotlessApply
|
|
||||||
}
|
|
|
@ -138,6 +138,7 @@ class HomeViewModel(application: Application) :
|
||||||
|
|
||||||
override fun onLibraryChanged(library: MusicStore.Library?) {
|
override fun onLibraryChanged(library: MusicStore.Library?) {
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
logD("Library changed, refreshing library")
|
||||||
_songs.value = settings.libSongSort.songs(library.songs)
|
_songs.value = settings.libSongSort.songs(library.songs)
|
||||||
_albums.value = settings.libAlbumSort.albums(library.albums)
|
_albums.value = settings.libAlbumSort.albums(library.albums)
|
||||||
_artists.value = settings.libArtistSort.artists(library.artists)
|
_artists.value = settings.libArtistSort.artists(library.artists)
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.oxycblt.auxio.music.storage.albumCoverUri
|
||||||
import org.oxycblt.auxio.music.storage.audioUri
|
import org.oxycblt.auxio.music.storage.audioUri
|
||||||
import org.oxycblt.auxio.settings.Settings
|
import org.oxycblt.auxio.settings.Settings
|
||||||
import org.oxycblt.auxio.ui.recycler.Item
|
import org.oxycblt.auxio.ui.recycler.Item
|
||||||
import org.oxycblt.auxio.util.logD
|
|
||||||
import org.oxycblt.auxio.util.nonZeroOrNull
|
import org.oxycblt.auxio.util.nonZeroOrNull
|
||||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
@ -204,6 +203,11 @@ sealed class Music : Item {
|
||||||
sealed class MusicParent : Music() {
|
sealed class MusicParent : Music() {
|
||||||
/** The songs that this parent owns. */
|
/** The songs that this parent owns. */
|
||||||
abstract val songs: List<Song>
|
abstract val songs: List<Song>
|
||||||
|
|
||||||
|
override fun hashCode() = 31 * uid.hashCode() + songs.hashCode()
|
||||||
|
|
||||||
|
override fun equals(other: Any?) =
|
||||||
|
other is MusicParent && javaClass == other.javaClass && uid == other.uid && songs == other.songs
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -511,8 +515,6 @@ class Album constructor(raw: Raw, override val songs: List<Song>) : MusicParent(
|
||||||
totalDuration += song.durationMs
|
totalDuration += song.durationMs
|
||||||
}
|
}
|
||||||
|
|
||||||
logD(earliestDateAdded)
|
|
||||||
|
|
||||||
date = earliestDate
|
date = earliestDate
|
||||||
durationMs = totalDuration
|
durationMs = totalDuration
|
||||||
dateAdded = earliestDateAdded
|
dateAdded = earliestDateAdded
|
||||||
|
|
|
@ -24,6 +24,7 @@ import android.os.Build
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.oxycblt.auxio.BuildConfig
|
import org.oxycblt.auxio.BuildConfig
|
||||||
|
@ -135,6 +136,8 @@ class Indexer {
|
||||||
* complete, a new completion state will be pushed to each callback.
|
* complete, a new completion state will be pushed to each callback.
|
||||||
*/
|
*/
|
||||||
suspend fun index(context: Context) {
|
suspend fun index(context: Context) {
|
||||||
|
delay(2000)
|
||||||
|
|
||||||
val notGranted =
|
val notGranted =
|
||||||
ContextCompat.checkSelfPermission(context, PERMISSION_READ_AUDIO) ==
|
ContextCompat.checkSelfPermission(context, PERMISSION_READ_AUDIO) ==
|
||||||
PackageManager.PERMISSION_DENIED
|
PackageManager.PERMISSION_DENIED
|
||||||
|
|
|
@ -65,6 +65,10 @@ class SearchViewModel(application: Application) :
|
||||||
private var lastQuery: String? = null
|
private var lastQuery: String? = null
|
||||||
private var currentSearchJob: Job? = null
|
private var currentSearchJob: Job? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
musicStore.addCallback(this)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use [query] to perform a search of the music library. Will push results to [searchResults].
|
* Use [query] to perform a search of the music library. Will push results to [searchResults].
|
||||||
*/
|
*/
|
||||||
|
@ -175,6 +179,7 @@ class SearchViewModel(application: Application) :
|
||||||
|
|
||||||
override fun onLibraryChanged(library: MusicStore.Library?) {
|
override fun onLibraryChanged(library: MusicStore.Library?) {
|
||||||
if (library != null) {
|
if (library != null) {
|
||||||
|
logD("Library changed, re-searching")
|
||||||
// Make sure our query is up to date with the music library.
|
// Make sure our query is up to date with the music library.
|
||||||
search(lastQuery)
|
search(lastQuery)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue