Removed Blacklist and Lyrics Room tables
This commit is contained in:
parent
08df1b2958
commit
aa96993584
4 changed files with 4 additions and 60 deletions
|
@ -1,12 +1,8 @@
|
||||||
package code.name.monkey.retromusic
|
package code.name.monkey.retromusic
|
||||||
|
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
|
||||||
import code.name.monkey.retromusic.auto.AutoMusicProvider
|
import code.name.monkey.retromusic.auto.AutoMusicProvider
|
||||||
import code.name.monkey.retromusic.cast.RetroWebServer
|
import code.name.monkey.retromusic.cast.RetroWebServer
|
||||||
import code.name.monkey.retromusic.db.BlackListStoreDao
|
|
||||||
import code.name.monkey.retromusic.db.BlackListStoreEntity
|
|
||||||
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
import code.name.monkey.retromusic.db.PlaylistWithSongs
|
||||||
import code.name.monkey.retromusic.db.RetroDatabase
|
import code.name.monkey.retromusic.db.RetroDatabase
|
||||||
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
import code.name.monkey.retromusic.fragments.LibraryViewModel
|
||||||
|
@ -20,10 +16,6 @@ import code.name.monkey.retromusic.network.provideLastFmRest
|
||||||
import code.name.monkey.retromusic.network.provideLastFmRetrofit
|
import code.name.monkey.retromusic.network.provideLastFmRetrofit
|
||||||
import code.name.monkey.retromusic.network.provideOkHttp
|
import code.name.monkey.retromusic.network.provideOkHttp
|
||||||
import code.name.monkey.retromusic.repository.*
|
import code.name.monkey.retromusic.repository.*
|
||||||
import code.name.monkey.retromusic.util.FilePathUtil
|
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import org.koin.android.ext.koin.androidContext
|
import org.koin.android.ext.koin.androidContext
|
||||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||||
import org.koin.dsl.bind
|
import org.koin.dsl.bind
|
||||||
|
@ -50,31 +42,14 @@ private val roomModule = module {
|
||||||
single {
|
single {
|
||||||
Room.databaseBuilder(androidContext(), RetroDatabase::class.java, "playlist.db")
|
Room.databaseBuilder(androidContext(), RetroDatabase::class.java, "playlist.db")
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
.addCallback(object : RoomDatabase.Callback() {
|
|
||||||
override fun onOpen(db: SupportSQLiteDatabase) {
|
|
||||||
super.onOpen(db)
|
|
||||||
GlobalScope.launch(IO) {
|
|
||||||
FilePathUtil.blacklistFilePaths().map {
|
|
||||||
get<BlackListStoreDao>().insertBlacklistPath(BlackListStoreEntity(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.fallbackToDestructiveMigration()
|
.fallbackToDestructiveMigration()
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
factory {
|
|
||||||
get<RetroDatabase>().lyricsDao()
|
|
||||||
}
|
|
||||||
|
|
||||||
factory {
|
factory {
|
||||||
get<RetroDatabase>().playlistDao()
|
get<RetroDatabase>().playlistDao()
|
||||||
}
|
}
|
||||||
|
|
||||||
factory {
|
|
||||||
get<RetroDatabase>().blackListStore()
|
|
||||||
}
|
|
||||||
|
|
||||||
factory {
|
factory {
|
||||||
get<RetroDatabase>().playCountDao()
|
get<RetroDatabase>().playCountDao()
|
||||||
}
|
}
|
||||||
|
@ -84,7 +59,7 @@ private val roomModule = module {
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single {
|
||||||
RealRoomRepository(get(), get(), get(), get(), get())
|
RealRoomRepository(get(), get(), get())
|
||||||
} bind RoomRepository::class
|
} bind RoomRepository::class
|
||||||
}
|
}
|
||||||
private val autoModule = module {
|
private val autoModule = module {
|
||||||
|
|
|
@ -18,14 +18,12 @@ import androidx.room.Database
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class, BlackListStoreEntity::class, LyricsEntity::class],
|
entities = [PlaylistEntity::class, SongEntity::class, HistoryEntity::class, PlayCountEntity::class],
|
||||||
version = 23,
|
version = 24,
|
||||||
exportSchema = false
|
exportSchema = false
|
||||||
)
|
)
|
||||||
abstract class RetroDatabase : RoomDatabase() {
|
abstract class RetroDatabase : RoomDatabase() {
|
||||||
abstract fun playlistDao(): PlaylistDao
|
abstract fun playlistDao(): PlaylistDao
|
||||||
abstract fun blackListStore(): BlackListStoreDao
|
|
||||||
abstract fun playCountDao(): PlayCountDao
|
abstract fun playCountDao(): PlayCountDao
|
||||||
abstract fun historyDao(): HistoryDao
|
abstract fun historyDao(): HistoryDao
|
||||||
abstract fun lyricsDao(): LyricsDao
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,6 @@ interface Repository {
|
||||||
suspend fun clearSongHistory()
|
suspend fun clearSongHistory()
|
||||||
suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
||||||
suspend fun playCountSongs(): List<PlayCountEntity>
|
suspend fun playCountSongs(): List<PlayCountEntity>
|
||||||
suspend fun blackListPaths(): List<BlackListStoreEntity>
|
|
||||||
suspend fun deleteSongs(songs: List<Song>)
|
suspend fun deleteSongs(songs: List<Song>)
|
||||||
suspend fun contributor(): List<Contributor>
|
suspend fun contributor(): List<Contributor>
|
||||||
suspend fun searchArtists(query: String): List<Artist>
|
suspend fun searchArtists(query: String): List<Artist>
|
||||||
|
@ -345,9 +344,6 @@ class RealRepository(
|
||||||
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
||||||
roomRepository.playCountSongs()
|
roomRepository.playCountSongs()
|
||||||
|
|
||||||
override suspend fun blackListPaths(): List<BlackListStoreEntity> =
|
|
||||||
roomRepository.blackListPaths()
|
|
||||||
|
|
||||||
override fun observableHistorySongs(): LiveData<List<Song>> =
|
override fun observableHistorySongs(): LiveData<List<Song>> =
|
||||||
Transformations.map(roomRepository.observableHistorySongs()) {
|
Transformations.map(roomRepository.observableHistorySongs()) {
|
||||||
it.fromHistoryToSongs()
|
it.fromHistoryToSongs()
|
||||||
|
|
|
@ -16,7 +16,6 @@ import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
interface RoomRepository {
|
interface RoomRepository {
|
||||||
fun historySongs(): List<HistoryEntity>
|
fun historySongs(): List<HistoryEntity>
|
||||||
fun favoritePlaylistLiveData(favorite: String): LiveData<List<SongEntity>>
|
fun favoritePlaylistLiveData(favorite: String): LiveData<List<SongEntity>>
|
||||||
fun insertBlacklistPath(blackListStoreEntity: BlackListStoreEntity)
|
|
||||||
fun observableHistorySongs(): LiveData<List<HistoryEntity>>
|
fun observableHistorySongs(): LiveData<List<HistoryEntity>>
|
||||||
fun getSongs(playListId: Long): LiveData<List<SongEntity>>
|
fun getSongs(playListId: Long): LiveData<List<SongEntity>>
|
||||||
suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long
|
suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long
|
||||||
|
@ -42,11 +41,6 @@ interface RoomRepository {
|
||||||
suspend fun clearSongHistory()
|
suspend fun clearSongHistory()
|
||||||
suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
suspend fun checkSongExistInPlayCount(songId: Long): List<PlayCountEntity>
|
||||||
suspend fun playCountSongs(): List<PlayCountEntity>
|
suspend fun playCountSongs(): List<PlayCountEntity>
|
||||||
suspend fun insertBlacklistPath(blackListStoreEntities: List<BlackListStoreEntity>)
|
|
||||||
suspend fun deleteBlacklistPath(blackListStoreEntity: BlackListStoreEntity)
|
|
||||||
suspend fun clearBlacklist()
|
|
||||||
suspend fun insertBlacklistPathAsync(blackListStoreEntity: BlackListStoreEntity)
|
|
||||||
suspend fun blackListPaths(): List<BlackListStoreEntity>
|
|
||||||
suspend fun deleteSongs(songs: List<Song>)
|
suspend fun deleteSongs(songs: List<Song>)
|
||||||
suspend fun isSongFavorite(context: Context, songId: Long): Boolean
|
suspend fun isSongFavorite(context: Context, songId: Long): Boolean
|
||||||
fun checkPlaylistExists(playListId: Long): LiveData<Boolean>
|
fun checkPlaylistExists(playListId: Long): LiveData<Boolean>
|
||||||
|
@ -54,10 +48,8 @@ interface RoomRepository {
|
||||||
|
|
||||||
class RealRoomRepository(
|
class RealRoomRepository(
|
||||||
private val playlistDao: PlaylistDao,
|
private val playlistDao: PlaylistDao,
|
||||||
private val blackListStoreDao: BlackListStoreDao,
|
|
||||||
private val playCountDao: PlayCountDao,
|
private val playCountDao: PlayCountDao,
|
||||||
private val historyDao: HistoryDao,
|
private val historyDao: HistoryDao
|
||||||
private val lyricsDao: LyricsDao
|
|
||||||
) : RoomRepository {
|
) : RoomRepository {
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
override suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long =
|
override suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long =
|
||||||
|
@ -185,27 +177,10 @@ class RealRoomRepository(
|
||||||
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
override suspend fun playCountSongs(): List<PlayCountEntity> =
|
||||||
playCountDao.playCountSongs()
|
playCountDao.playCountSongs()
|
||||||
|
|
||||||
override fun insertBlacklistPath(blackListStoreEntity: BlackListStoreEntity) =
|
|
||||||
blackListStoreDao.insertBlacklistPath(blackListStoreEntity)
|
|
||||||
|
|
||||||
override suspend fun insertBlacklistPath(blackListStoreEntities: List<BlackListStoreEntity>) =
|
|
||||||
blackListStoreDao.insertBlacklistPath(blackListStoreEntities)
|
|
||||||
|
|
||||||
override suspend fun insertBlacklistPathAsync(blackListStoreEntity: BlackListStoreEntity) =
|
|
||||||
blackListStoreDao.insertBlacklistPath(blackListStoreEntity)
|
|
||||||
|
|
||||||
override suspend fun blackListPaths(): List<BlackListStoreEntity> =
|
|
||||||
blackListStoreDao.blackListPaths()
|
|
||||||
|
|
||||||
override suspend fun deleteSongs(songs: List<Song>) = songs.forEach {
|
override suspend fun deleteSongs(songs: List<Song>) = songs.forEach {
|
||||||
playCountDao.deleteSong(it.id)
|
playCountDao.deleteSong(it.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun deleteBlacklistPath(blackListStoreEntity: BlackListStoreEntity) =
|
|
||||||
blackListStoreDao.deleteBlacklistPath(blackListStoreEntity)
|
|
||||||
|
|
||||||
override suspend fun clearBlacklist() = blackListStoreDao.clearBlacklist()
|
|
||||||
|
|
||||||
override suspend fun isSongFavorite(context: Context, songId: Long): Boolean {
|
override suspend fun isSongFavorite(context: Context, songId: Long): Boolean {
|
||||||
return playlistDao.isSongExistsInPlaylist(
|
return playlistDao.isSongExistsInPlaylist(
|
||||||
playlistDao.playlist(context.getString(R.string.favorites)).firstOrNull()?.playListId
|
playlistDao.playlist(context.getString(R.string.favorites)).firstOrNull()?.playListId
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue