-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: better persistent & cache database
- Loading branch information
Showing
67 changed files
with
776 additions
and
768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ app/src/main/assets/i18n | |
dist | ||
secrets | ||
.kotlin | ||
app/room-schemas/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/io/github/zyrouge/symphony/services/database/CacheDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.zyrouge.symphony.services.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.room.TypeConverters | ||
import io.github.zyrouge.symphony.Symphony | ||
import io.github.zyrouge.symphony.services.database.store.SongCacheStore | ||
import io.github.zyrouge.symphony.services.groove.Song | ||
import io.github.zyrouge.symphony.utils.RoomConvertors | ||
|
||
@Database(entities = [Song::class], version = 1) | ||
@TypeConverters(RoomConvertors::class) | ||
abstract class CacheDatabase : RoomDatabase() { | ||
abstract fun songs(): SongCacheStore | ||
|
||
companion object { | ||
fun create(symphony: Symphony) = Room | ||
.databaseBuilder( | ||
symphony.applicationContext, | ||
CacheDatabase::class.java, | ||
"cache" | ||
) | ||
.build() | ||
} | ||
} |
13 changes: 9 additions & 4 deletions
13
app/src/main/java/io/github/zyrouge/symphony/services/database/Database.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package io.github.zyrouge.symphony.services.database | ||
|
||
import io.github.zyrouge.symphony.Symphony | ||
import io.github.zyrouge.symphony.services.database.store.ArtworkCacheStore | ||
import io.github.zyrouge.symphony.services.database.store.LyricsCacheStore | ||
|
||
class Database(symphony: Symphony) { | ||
val songCache = SongCache(symphony) | ||
val artworkCache = ArtworkCache(symphony) | ||
val lyricsCache = LyricsCache(symphony) | ||
val playlists = PlaylistBox(symphony) | ||
private val cache = CacheDatabase.create(symphony) | ||
private val persistent = PersistentDatabase.create(symphony) | ||
|
||
val artworkCache = ArtworkCacheStore(symphony) | ||
val lyricsCache = LyricsCacheStore(symphony) | ||
val songCache get() = cache.songs() | ||
val playlists get() = persistent.playlists() | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/io/github/zyrouge/symphony/services/database/PersistentDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.zyrouge.symphony.services.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.room.TypeConverters | ||
import io.github.zyrouge.symphony.Symphony | ||
import io.github.zyrouge.symphony.services.database.store.PlaylistStore | ||
import io.github.zyrouge.symphony.services.groove.Playlist | ||
import io.github.zyrouge.symphony.utils.RoomConvertors | ||
|
||
@Database(entities = [Playlist::class], version = 1) | ||
@TypeConverters(RoomConvertors::class) | ||
abstract class PersistentDatabase : RoomDatabase() { | ||
abstract fun playlists(): PlaylistStore | ||
|
||
companion object { | ||
fun create(symphony: Symphony) = Room | ||
.databaseBuilder( | ||
symphony.applicationContext, | ||
PersistentDatabase::class.java, | ||
"persistent" | ||
) | ||
.build() | ||
} | ||
} |
25 changes: 0 additions & 25 deletions
25
app/src/main/java/io/github/zyrouge/symphony/services/database/PlaylistBox.kt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
app/src/main/java/io/github/zyrouge/symphony/services/database/SongCache.kt
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...ymphony/services/database/ArtworkCache.kt → ...vices/database/store/ArtworkCacheStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...symphony/services/database/LyricsCache.kt → ...rvices/database/store/LyricsCacheStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/io/github/zyrouge/symphony/services/database/store/PlaylistStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.github.zyrouge.symphony.services.database.store | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.MapColumn | ||
import androidx.room.Query | ||
import androidx.room.Update | ||
import io.github.zyrouge.symphony.services.groove.Playlist | ||
|
||
@Dao | ||
interface PlaylistStore { | ||
@Insert | ||
suspend fun insert(vararg playlist: Playlist) | ||
|
||
@Update | ||
suspend fun update(vararg playlist: Playlist) | ||
|
||
@Query("DELETE FROM playlists WHERE id IN (:playlistIds)") | ||
suspend fun delete(playlistIds: Collection<String>) | ||
|
||
@Query("SELECT * FROM playlists") | ||
suspend fun entries(): Map<@MapColumn("id") String, Playlist> | ||
} |
Oops, something went wrong.