music: refactor library usage
Refactor the disjoint Library and Playlist setup into two new DeviceLibrary and UserLibrary implementations. This makes the API surface a bit less disjoint than prior.
This commit is contained in:
@@ -20,12 +20,11 @@ package org.oxycblt.auxio.music
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import org.oxycblt.auxio.music.*
|
||||
import org.oxycblt.auxio.music.fs.MimeType
|
||||
import org.oxycblt.auxio.music.fs.Path
|
||||
import org.oxycblt.auxio.music.metadata.Date
|
||||
import org.oxycblt.auxio.music.metadata.Disc
|
||||
import org.oxycblt.auxio.music.metadata.ReleaseType
|
||||
import org.oxycblt.auxio.music.storage.MimeType
|
||||
import org.oxycblt.auxio.music.storage.Path
|
||||
|
||||
open class FakeSong : Song {
|
||||
override val rawName: String?
|
||||
|
||||
@@ -19,24 +19,16 @@
|
||||
package org.oxycblt.auxio.music
|
||||
|
||||
import kotlinx.coroutines.Job
|
||||
import org.oxycblt.auxio.music.library.Library
|
||||
import org.oxycblt.auxio.music.device.DeviceLibrary
|
||||
import org.oxycblt.auxio.music.user.UserLibrary
|
||||
|
||||
open class FakeMusicRepository : MusicRepository {
|
||||
override var indexingState: IndexingState?
|
||||
override val indexingState: IndexingState?
|
||||
get() = throw NotImplementedError()
|
||||
set(_) {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
override var library: Library?
|
||||
override val deviceLibrary: DeviceLibrary?
|
||||
get() = throw NotImplementedError()
|
||||
set(_) {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
override var playlists: List<Playlist>?
|
||||
override val userLibrary: UserLibrary?
|
||||
get() = throw NotImplementedError()
|
||||
set(_) {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun addUpdateListener(listener: MusicRepository.UpdateListener) {
|
||||
throw NotImplementedError()
|
||||
@@ -62,6 +54,10 @@ open class FakeMusicRepository : MusicRepository {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun find(uid: Music.UID): Music? {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun requestIndex(withCache: Boolean) {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package org.oxycblt.auxio.music
|
||||
|
||||
import org.oxycblt.auxio.list.Sort
|
||||
import org.oxycblt.auxio.music.storage.MusicDirectories
|
||||
import org.oxycblt.auxio.music.fs.MusicDirectories
|
||||
|
||||
open class FakeMusicSettings : MusicSettings {
|
||||
override fun registerListener(listener: MusicSettings.Listener) = throw NotImplementedError()
|
||||
|
||||
@@ -21,8 +21,8 @@ package org.oxycblt.auxio.music
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.oxycblt.auxio.music.library.FakeLibrary
|
||||
import org.oxycblt.auxio.music.library.Library
|
||||
import org.oxycblt.auxio.music.device.DeviceLibrary
|
||||
import org.oxycblt.auxio.music.device.FakeDeviceLibrary
|
||||
import org.oxycblt.auxio.util.forceClear
|
||||
|
||||
class MusicViewModelTest {
|
||||
@@ -49,7 +49,7 @@ class MusicViewModelTest {
|
||||
val musicRepository = TestMusicRepository()
|
||||
val musicViewModel = MusicViewModel(musicRepository)
|
||||
assertEquals(null, musicViewModel.statistics.value)
|
||||
musicRepository.library = TestLibrary()
|
||||
musicRepository.deviceLibrary = TestDeviceLibrary()
|
||||
assertEquals(
|
||||
MusicViewModel.Statistics(
|
||||
2,
|
||||
@@ -71,11 +71,11 @@ class MusicViewModelTest {
|
||||
}
|
||||
|
||||
private class TestMusicRepository : FakeMusicRepository() {
|
||||
override var library: Library? = null
|
||||
override var deviceLibrary: DeviceLibrary? = null
|
||||
set(value) {
|
||||
field = value
|
||||
updateListener?.onMusicChanges(
|
||||
MusicRepository.Changes(library = true, playlists = false))
|
||||
MusicRepository.Changes(deviceLibrary = true, userLibrary = false))
|
||||
}
|
||||
override var indexingState: IndexingState? = null
|
||||
set(value) {
|
||||
@@ -88,7 +88,8 @@ class MusicViewModelTest {
|
||||
val requests = mutableListOf<Boolean>()
|
||||
|
||||
override fun addUpdateListener(listener: MusicRepository.UpdateListener) {
|
||||
listener.onMusicChanges(MusicRepository.Changes(library = true, playlists = false))
|
||||
listener.onMusicChanges(
|
||||
MusicRepository.Changes(deviceLibrary = true, userLibrary = false))
|
||||
this.updateListener = listener
|
||||
}
|
||||
|
||||
@@ -110,7 +111,7 @@ class MusicViewModelTest {
|
||||
}
|
||||
}
|
||||
|
||||
private class TestLibrary : FakeLibrary() {
|
||||
private class TestDeviceLibrary : FakeDeviceLibrary() {
|
||||
override val songs: List<Song>
|
||||
get() = listOf(TestSong(), TestSong())
|
||||
override val albums: List<Album>
|
||||
|
||||
+10
-6
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Auxio Project
|
||||
* FakeLibrary.kt is part of Auxio.
|
||||
* FakeDeviceLibrary.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -16,13 +16,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.music.library
|
||||
package org.oxycblt.auxio.music.device
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import org.oxycblt.auxio.music.*
|
||||
|
||||
open class FakeLibrary : Library {
|
||||
open class FakeDeviceLibrary : DeviceLibrary {
|
||||
override val songs: List<Song>
|
||||
get() = throw NotImplementedError()
|
||||
override val albums: List<Album>
|
||||
@@ -32,7 +32,7 @@ open class FakeLibrary : Library {
|
||||
override val genres: List<Genre>
|
||||
get() = throw NotImplementedError()
|
||||
|
||||
override fun <T : Music> find(uid: Music.UID): T? {
|
||||
override fun findSong(uid: Music.UID): Song? {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
@@ -40,11 +40,15 @@ open class FakeLibrary : Library {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun <T : MusicParent> sanitize(parent: T): T? {
|
||||
override fun findAlbum(uid: Music.UID): Album? {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun sanitize(song: Song): Song? {
|
||||
override fun findArtist(uid: Music.UID): Artist? {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
|
||||
override fun findGenre(uid: Music.UID): Genre? {
|
||||
throw NotImplementedError()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.music.library
|
||||
package org.oxycblt.auxio.music.device
|
||||
|
||||
import java.util.*
|
||||
import org.junit.Assert.assertEquals
|
||||
Reference in New Issue
Block a user