-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from musicorum-app/dev
new feat: offline caching
- Loading branch information
Showing
33 changed files
with
640 additions
and
200 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
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
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
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
29 changes: 29 additions & 0 deletions
29
app/src/main/java/io/musicorum/mobile/database/CachedScrobblesDb.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,29 @@ | ||
package io.musicorum.mobile.database | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import io.musicorum.mobile.database.daos.CachedScrobblesDao | ||
import io.musicorum.mobile.models.CachedScrobble | ||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import kotlinx.coroutines.internal.synchronized | ||
|
||
@Database(entities = [CachedScrobble::class], version = 2, exportSchema = false) | ||
abstract class CachedScrobblesDb : RoomDatabase() { | ||
abstract fun cachedScrobblesDao(): CachedScrobblesDao | ||
|
||
companion object { | ||
@Volatile | ||
private var Instance: CachedScrobblesDb? = null | ||
|
||
@OptIn(InternalCoroutinesApi::class) | ||
fun getDatabase(context: Context): CachedScrobblesDb { | ||
return Instance ?: synchronized(this) { | ||
Room.databaseBuilder(context, CachedScrobblesDb::class.java, "cachedScrobbles") | ||
.fallbackToDestructiveMigration() | ||
.build() | ||
}.also { Instance = it } | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/io/musicorum/mobile/database/PendingScrobblesDb.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,29 @@ | ||
package io.musicorum.mobile.database | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import io.musicorum.mobile.database.daos.PendingScrobblesDao | ||
import io.musicorum.mobile.models.PendingScrobble | ||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import kotlinx.coroutines.internal.synchronized | ||
|
||
@Database(entities = [PendingScrobble::class], version = 2, exportSchema = false) | ||
abstract class PendingScrobblesDb : RoomDatabase() { | ||
abstract fun pendingScrobblesDao(): PendingScrobblesDao | ||
|
||
companion object { | ||
@Volatile | ||
private var Instance: PendingScrobblesDb? = null | ||
|
||
@OptIn(InternalCoroutinesApi::class) | ||
fun getDatabase(context: Context): PendingScrobblesDb { | ||
return Instance ?: synchronized(this) { | ||
Room.databaseBuilder(context, PendingScrobblesDb::class.java, "pendingScrobbles") | ||
.fallbackToDestructiveMigration() | ||
.build() | ||
}.also { Instance = it } | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/io/musicorum/mobile/database/daos/CachedScrobblesDao.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,24 @@ | ||
package io.musicorum.mobile.database.daos | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import io.musicorum.mobile.models.CachedScrobble | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface CachedScrobblesDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(data: CachedScrobble) | ||
|
||
@Delete | ||
suspend fun delete(data: CachedScrobble) | ||
|
||
@Query("SELECT * FROM cachedScrobbles") | ||
fun getAll(): Flow<List<CachedScrobble>> | ||
|
||
@Query("DELETE FROM cachedScrobbles") | ||
suspend fun clearAll() | ||
} |
Oops, something went wrong.