Skip to content

Commit

Permalink
update: favorite anime
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Nov 9, 2023
1 parent 3ed35a1 commit 4155623
Show file tree
Hide file tree
Showing 19 changed files with 548 additions and 15 deletions.
27 changes: 24 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.incremental.createDirectory
import java.io.FileInputStream
import java.util.Properties

Expand All @@ -17,6 +18,22 @@ if (keystorePropertiesFile.exists() && keystorePropertiesFile.canRead()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}

val schemasDir: File = project.file("schemas")
if (!schemasDir.exists()) {
schemasDir.createDirectory()
}

class RoomSchemaArgProvider(
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
val schemaDir: File
) : CommandLineArgumentProvider {

override fun asArguments(): Iterable<String> {
return listOf("room.schemaLocation=${schemaDir.path}")
}
}

android {
namespace = "com.muedsa.agetv"
compileSdk = 34
Expand Down Expand Up @@ -91,9 +108,9 @@ android {
}
}

testOptions {
unitTests.isReturnDefaultValues = true
}
// testOptions {
// unitTests.isReturnDefaultValues = true
// }
}

dependencies {
Expand Down Expand Up @@ -156,4 +173,8 @@ dependencies {
implementation(libs.firebase.crashlytics)

//implementation(libs.material.icons.extended)
}

ksp {
arg(RoomSchemaArgProvider(File(projectDir, "schemas")))
}
127 changes: 127 additions & 0 deletions app/schemas/com.muedsa.agetv.room.AppDatabase/1.json
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')"
]
}
}
7 changes: 0 additions & 7 deletions app/src/main/kotlin/com/muedsa/agetv/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.muedsa.agetv

import android.content.Context
import com.google.common.net.HttpHeaders
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.muedsa.agetv.repository.AppRepository
import com.muedsa.agetv.repository.DataStoreRepo
import com.muedsa.agetv.service.AgeApiService
import com.muedsa.agetv.service.AgePlayerService
import com.muedsa.agetv.service.DanDanPlayApiService
Expand All @@ -13,7 +11,6 @@ import com.muedsa.uitl.LenientJson
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -91,8 +88,4 @@ internal object AppModule {
playerService = playerService,
danDanPlayApiService = danDanPlayApiService
)

@Singleton
@Provides
fun provideDataStoreRepository(@ApplicationContext app: Context) = DataStoreRepo(app)
}
34 changes: 34 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/DatabaseModule.kt
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()
}
19 changes: 19 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/DateStoreModule.kt
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)
}
15 changes: 15 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/room/AppDatabase.kt
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
}
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 app/src/main/kotlin/com/muedsa/agetv/room/dao/FavoriteAnimeDao.kt
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)
}
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
)
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
)
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/muedsa/agetv/ui/Colors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ val WeekCardColorList = listOf(
Color(0xff784213)
)
val RankIconColor = Color(0xffff6347)
val RankFontColor = Color(0xffffc857)
val RankFontColor = Color(0xffffc857)
val FavoriteIconColor = Color(0xfff98787)
Loading

0 comments on commit 4155623

Please sign in to comment.