-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
548 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "34c8cb053819dc69522ce96641158208", | ||
"entities": [ | ||
{ | ||
"tableName": "favorite_anime", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `name` TEXT NOT NULL, `cover` TEXT NOT NULL, `update_at` INTEGER NOT NULL DEFAULT (CURRENT_TIMESTAMP), PRIMARY KEY(`id`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "name", | ||
"columnName": "name", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "cover", | ||
"columnName": "cover", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "updateAt", | ||
"columnName": "update_at", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "(CURRENT_TIMESTAMP)" | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"id" | ||
] | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "index_favorite_anime_update_at", | ||
"unique": false, | ||
"columnNames": [ | ||
"update_at" | ||
], | ||
"orders": [], | ||
"createSql": "CREATE INDEX IF NOT EXISTS `index_favorite_anime_update_at` ON `${TABLE_NAME}` (`update_at`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
}, | ||
{ | ||
"tableName": "episode_progress", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`aid` INTEGER NOT NULL, `title_hash` INTEGER NOT NULL, `title` TEXT NOT NULL, `progress` INTEGER NOT NULL DEFAULT 0, `duration` INTEGER NOT NULL DEFAULT 0, `update_at` INTEGER NOT NULL DEFAULT (CURRENT_TIMESTAMP), PRIMARY KEY(`aid`, `title_hash`))", | ||
"fields": [ | ||
{ | ||
"fieldPath": "aid", | ||
"columnName": "aid", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "titleHash", | ||
"columnName": "title_hash", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "progress", | ||
"columnName": "progress", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "duration", | ||
"columnName": "duration", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "0" | ||
}, | ||
{ | ||
"fieldPath": "updateAt", | ||
"columnName": "update_at", | ||
"affinity": "INTEGER", | ||
"notNull": true, | ||
"defaultValue": "(CURRENT_TIMESTAMP)" | ||
} | ||
], | ||
"primaryKey": { | ||
"autoGenerate": false, | ||
"columnNames": [ | ||
"aid", | ||
"title_hash" | ||
] | ||
}, | ||
"indices": [ | ||
{ | ||
"name": "index_episode_progress_update_at", | ||
"unique": false, | ||
"columnNames": [ | ||
"update_at" | ||
], | ||
"orders": [], | ||
"createSql": "CREATE INDEX IF NOT EXISTS `index_episode_progress_update_at` ON `${TABLE_NAME}` (`update_at`)" | ||
} | ||
], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '34c8cb053819dc69522ce96641158208')" | ||
] | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.muedsa.agetv | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import com.muedsa.agetv.room.AppDatabase | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object DatabaseModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideAppDatabase(@ApplicationContext appContext: Context): AppDatabase { | ||
return Room.databaseBuilder( | ||
appContext, | ||
AppDatabase::class.java, | ||
"AGETV" | ||
).build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideFavoriteAnimeDao(appDatabase: AppDatabase) = appDatabase.favoriteAnimeDao() | ||
|
||
@Provides | ||
@Singleton | ||
fun provideEpisodeProgressDao(appDatabase: AppDatabase) = appDatabase.episodeProgressDao() | ||
} |
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,19 @@ | ||
package com.muedsa.agetv | ||
|
||
import android.content.Context | ||
import com.muedsa.agetv.repository.DataStoreRepo | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
internal object DateStoreModule { | ||
|
||
@Singleton | ||
@Provides | ||
fun provideDataStoreRepository(@ApplicationContext app: Context) = DataStoreRepo(app) | ||
} |
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,15 @@ | ||
package com.muedsa.agetv.room | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.muedsa.agetv.room.dao.EpisodeProgressDao | ||
import com.muedsa.agetv.room.dao.FavoriteAnimeDao | ||
import com.muedsa.agetv.room.model.EpisodeProgressModel | ||
import com.muedsa.agetv.room.model.FavoriteAnimeModel | ||
|
||
@Database(entities = [FavoriteAnimeModel::class, EpisodeProgressModel::class], version = 1) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract fun favoriteAnimeDao(): FavoriteAnimeDao | ||
|
||
abstract fun episodeProgressDao(): EpisodeProgressDao | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/kotlin/com/muedsa/agetv/room/dao/EpisodeProgressDao.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,19 @@ | ||
package com.muedsa.agetv.room.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Query | ||
import androidx.room.Upsert | ||
import com.muedsa.agetv.room.model.EpisodeProgressModel | ||
|
||
@Dao | ||
interface EpisodeProgressDao { | ||
|
||
@Query("SELECT * FROM episode_progress WHERE aid = :aid") | ||
suspend fun getListByAid(aid: Int): List<EpisodeProgressModel> | ||
|
||
@Upsert | ||
suspend fun upsert(model: EpisodeProgressModel) | ||
|
||
@Query("DELETE FROM episode_progress WHERE aid = :aid") | ||
suspend fun deleteByAid(aid: Int) | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/kotlin/com/muedsa/agetv/room/dao/FavoriteAnimeDao.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,28 @@ | ||
package com.muedsa.agetv.room.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import com.muedsa.agetv.room.model.FavoriteAnimeModel | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface FavoriteAnimeDao { | ||
|
||
// @Query("SELECT * FROM favorite_anime ORDER BY update_at DESC") | ||
// suspend fun getAll(): List<FavoriteAnimeModel> | ||
|
||
@Query("SELECT * FROM favorite_anime ORDER BY update_at DESC") | ||
fun flowAll(): Flow<List<FavoriteAnimeModel>> | ||
|
||
@Query("SELECT * FROM favorite_anime WHERE id = :id") | ||
suspend fun getById(id: Int): FavoriteAnimeModel? | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertAll(vararg models: FavoriteAnimeModel) | ||
|
||
@Delete | ||
suspend fun delete(model: FavoriteAnimeModel) | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/kotlin/com/muedsa/agetv/room/model/EpisodeProgressModel.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,18 @@ | ||
package com.muedsa.agetv.room.model | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
|
||
@Entity(tableName = "episode_progress", primaryKeys = ["aid", "title_hash"]) | ||
data class EpisodeProgressModel( | ||
@ColumnInfo(name = "aid") val aid: Int, | ||
@ColumnInfo(name = "title_hash") val titleHash: Int, | ||
@ColumnInfo(name = "title") val title: String, | ||
@ColumnInfo(name = "progress", defaultValue = "0") var progress: Long, | ||
@ColumnInfo(name = "duration", defaultValue = "0") var duration: Long, | ||
@ColumnInfo( | ||
name = "update_at", | ||
defaultValue = "(CURRENT_TIMESTAMP)", | ||
index = true | ||
) var updateAt: Long = 0 | ||
) |
17 changes: 17 additions & 0 deletions
17
app/src/main/kotlin/com/muedsa/agetv/room/model/FavoriteAnimeModel.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,17 @@ | ||
package com.muedsa.agetv.room.model | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "favorite_anime") | ||
data class FavoriteAnimeModel( | ||
@PrimaryKey @ColumnInfo(name = "id") val id: Int, | ||
@ColumnInfo(name = "name") val name: String, | ||
@ColumnInfo(name = "cover") val cover: String, | ||
@ColumnInfo( | ||
name = "update_at", | ||
defaultValue = "(CURRENT_TIMESTAMP)", | ||
index = true | ||
) var updateAt: Long = 0 | ||
) |
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
Oops, something went wrong.