Update database structure and migrate from kapt to ksp
This commit is contained in:
@@ -3,7 +3,6 @@ import java.time.LocalDateTime
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-kapt'
|
||||
id 'com.google.devtools.ksp'
|
||||
id 'kotlin-parcelize'
|
||||
id 'dagger.hilt.android.plugin'
|
||||
@@ -162,9 +161,9 @@ dependencies {
|
||||
implementation libs.adapterdelegates.viewbinding
|
||||
|
||||
implementation libs.hilt.android
|
||||
kapt libs.hilt.compiler
|
||||
ksp libs.hilt.compiler
|
||||
implementation libs.androidx.hilt.work
|
||||
kapt libs.androidx.hilt.compiler
|
||||
ksp libs.androidx.hilt.compiler
|
||||
|
||||
implementation libs.coil.core
|
||||
implementation libs.coil.network
|
||||
@@ -198,5 +197,5 @@ dependencies {
|
||||
androidTestImplementation libs.moshi.kotlin
|
||||
|
||||
androidTestImplementation libs.hilt.android.testing
|
||||
kaptAndroidTest libs.hilt.android.compiler
|
||||
kspAndroidTest libs.hilt.android.compiler
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.koitharu.kotatsu.favourites.data.FavouriteCategoryEntity
|
||||
import org.koitharu.kotatsu.favourites.data.FavouriteEntity
|
||||
import org.koitharu.kotatsu.history.data.HistoryEntity
|
||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||
import org.koitharu.kotatsu.parsers.network.CloudFlareHelper
|
||||
import org.koitharu.kotatsu.parsers.util.json.getBooleanOrDefault
|
||||
import org.koitharu.kotatsu.parsers.util.json.getFloatOrDefault
|
||||
import org.koitharu.kotatsu.parsers.util.json.getIntOrDefault
|
||||
@@ -23,6 +24,7 @@ class JsonDeserializer(private val json: JSONObject) {
|
||||
sortKey = json.getIntOrDefault("sort_key", 0),
|
||||
createdAt = json.getLong("created_at"),
|
||||
deletedAt = 0L,
|
||||
isPinned = json.getBooleanOrDefault("pinned", false),
|
||||
)
|
||||
|
||||
fun toMangaEntity() = MangaEntity(
|
||||
@@ -46,6 +48,7 @@ class JsonDeserializer(private val json: JSONObject) {
|
||||
title = json.getString("title"),
|
||||
key = json.getString("key"),
|
||||
source = json.getString("source"),
|
||||
isPinned = json.getBooleanOrDefault("pinned", false),
|
||||
)
|
||||
|
||||
fun toHistoryEntity() = HistoryEntity(
|
||||
@@ -89,6 +92,7 @@ class JsonDeserializer(private val json: JSONObject) {
|
||||
addedIn = json.getIntOrDefault("added_in", 0),
|
||||
lastUsedAt = json.getLongOrDefault("used_at", 0L),
|
||||
isPinned = json.getBooleanOrDefault("pinned", false),
|
||||
cfState = json.getIntOrDefault("cf_state", CloudFlareHelper.PROTECTION_NOT_DETECTED),
|
||||
)
|
||||
|
||||
fun toMap(): Map<String, Any?> {
|
||||
|
||||
@@ -17,6 +17,7 @@ class JsonSerializer private constructor(private val json: JSONObject) {
|
||||
put("category_id", e.categoryId)
|
||||
put("sort_key", e.sortKey)
|
||||
put("created_at", e.createdAt)
|
||||
put("pinned", e.isPinned)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -51,6 +52,7 @@ class JsonSerializer private constructor(private val json: JSONObject) {
|
||||
put("title", e.title)
|
||||
put("key", e.key)
|
||||
put("source", e.source)
|
||||
put("pinned", e.isPinned)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -93,6 +95,7 @@ class JsonSerializer private constructor(private val json: JSONObject) {
|
||||
put("added_in", e.addedIn)
|
||||
put("used_at", e.lastUsedAt)
|
||||
put("pinned", e.isPinned)
|
||||
put("cf_state", e.cfState)
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.koitharu.kotatsu.core.db.migrations.Migration22To23
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration23To24
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration24To23
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration24To25
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration25To26
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration2To3
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration3To4
|
||||
import org.koitharu.kotatsu.core.db.migrations.Migration4To5
|
||||
@@ -68,7 +69,7 @@ import org.koitharu.kotatsu.tracker.data.TrackEntity
|
||||
import org.koitharu.kotatsu.tracker.data.TrackLogEntity
|
||||
import org.koitharu.kotatsu.tracker.data.TracksDao
|
||||
|
||||
const val DATABASE_VERSION = 25
|
||||
const val DATABASE_VERSION = 26
|
||||
|
||||
@Database(
|
||||
entities = [
|
||||
@@ -138,6 +139,7 @@ fun getDatabaseMigrations(context: Context): Array<Migration> = arrayOf(
|
||||
Migration23To24(),
|
||||
Migration24To23(),
|
||||
Migration24To25(),
|
||||
Migration25To26(),
|
||||
)
|
||||
|
||||
fun MangaDatabase(context: Context): MangaDatabase = Room
|
||||
|
||||
@@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.core.db.entity.MangaSourceEntity
|
||||
import org.koitharu.kotatsu.explore.data.SourcesSortOrder
|
||||
import org.koitharu.kotatsu.parsers.network.CloudFlareHelper
|
||||
|
||||
@Dao
|
||||
abstract class MangaSourcesDao {
|
||||
@@ -76,6 +77,7 @@ abstract class MangaSourcesDao {
|
||||
addedIn = BuildConfig.VERSION_CODE,
|
||||
lastUsedAt = 0,
|
||||
isPinned = false,
|
||||
cfState = CloudFlareHelper.PROTECTION_NOT_DETECTED,
|
||||
)
|
||||
upsert(entity)
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ fun MangaTag.toEntity() = TagEntity(
|
||||
key = key,
|
||||
source = source.name,
|
||||
id = "${key}_${source.name}".longHashCode(),
|
||||
isPinned = false, // for future use
|
||||
)
|
||||
|
||||
fun Collection<MangaTag>.toEntities() = map(MangaTag::toEntity)
|
||||
|
||||
@@ -25,4 +25,7 @@ data class MangaPrefsEntity(
|
||||
@ColumnInfo(name = "cf_contrast") val cfContrast: Float,
|
||||
@ColumnInfo(name = "cf_invert") val cfInvert: Boolean,
|
||||
@ColumnInfo(name = "cf_grayscale") val cfGrayscale: Boolean,
|
||||
@ColumnInfo(name = "title_override") val titleOverride: String?,
|
||||
@ColumnInfo(name = "cover_override") val coverUrlOverride: String?,
|
||||
@ColumnInfo(name = "content_rating_override") val contentRatingOverride: String?,
|
||||
)
|
||||
|
||||
@@ -17,4 +17,5 @@ data class MangaSourceEntity(
|
||||
@ColumnInfo(name = "added_in") val addedIn: Int,
|
||||
@ColumnInfo(name = "used_at") val lastUsedAt: Long,
|
||||
@ColumnInfo(name = "pinned") val isPinned: Boolean,
|
||||
@ColumnInfo(name = "cf_state") val cfState: Int,
|
||||
)
|
||||
|
||||
@@ -12,4 +12,5 @@ data class TagEntity(
|
||||
@ColumnInfo(name = "title") val title: String,
|
||||
@ColumnInfo(name = "key") val key: String,
|
||||
@ColumnInfo(name = "source") val source: String,
|
||||
@ColumnInfo(name = "pinned") val isPinned: Boolean,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.koitharu.kotatsu.core.db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
class Migration25To26 : Migration(25, 26) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE sources ADD COLUMN cf_state INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE preferences ADD COLUMN title_override TEXT DEFAULT NULL")
|
||||
db.execSQL("ALTER TABLE preferences ADD COLUMN cover_override TEXT DEFAULT NULL")
|
||||
db.execSQL("ALTER TABLE preferences ADD COLUMN content_rating_override TEXT DEFAULT NULL")
|
||||
db.execSQL("ALTER TABLE favourites ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0")
|
||||
db.execSQL("ALTER TABLE tags ADD COLUMN pinned INTEGER NOT NULL DEFAULT 0")
|
||||
}
|
||||
}
|
||||
@@ -161,5 +161,8 @@ class MangaDataRepository @Inject constructor(
|
||||
cfContrast = 0f,
|
||||
cfInvert = false,
|
||||
cfGrayscale = false,
|
||||
titleOverride = null,
|
||||
coverUrlOverride = null,
|
||||
contentRatingOverride = null,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.koitharu.kotatsu.core.util.ext.flattenLatest
|
||||
import org.koitharu.kotatsu.parsers.model.ContentType
|
||||
import org.koitharu.kotatsu.parsers.model.MangaParserSource
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.network.CloudFlareHelper
|
||||
import org.koitharu.kotatsu.parsers.util.mapNotNullToSet
|
||||
import org.koitharu.kotatsu.parsers.util.mapToSet
|
||||
import java.util.Collections
|
||||
@@ -268,6 +269,7 @@ class MangaSourcesRepository @Inject constructor(
|
||||
addedIn = BuildConfig.VERSION_CODE,
|
||||
lastUsedAt = 0,
|
||||
isPinned = false,
|
||||
cfState = CloudFlareHelper.PROTECTION_NOT_DETECTED,
|
||||
)
|
||||
}
|
||||
dao.insertIfAbsent(entities)
|
||||
|
||||
@@ -28,6 +28,7 @@ data class FavouriteEntity(
|
||||
@ColumnInfo(name = "manga_id", index = true) val mangaId: Long,
|
||||
@ColumnInfo(name = "category_id", index = true) val categoryId: Long,
|
||||
@ColumnInfo(name = "sort_key") val sortKey: Int,
|
||||
@ColumnInfo(name = "pinned") val isPinned: Boolean,
|
||||
@ColumnInfo(name = "created_at") val createdAt: Long,
|
||||
@ColumnInfo(name = "deleted_at") val deletedAt: Long,
|
||||
)
|
||||
|
||||
@@ -237,6 +237,7 @@ class FavouritesRepository @Inject constructor(
|
||||
createdAt = System.currentTimeMillis(),
|
||||
sortKey = 0,
|
||||
deletedAt = 0L,
|
||||
isPinned = false,
|
||||
)
|
||||
db.getFavouritesDao().insert(entity)
|
||||
}
|
||||
|
||||
@@ -18,4 +18,3 @@ kotlin.code.style=official
|
||||
org.gradle.jvmargs=-Xmx1536M -Dkotlin.daemon.jvm.options\="-Xmx1536M"
|
||||
android.enableR8.fullMode=true
|
||||
android.nonFinalResIds=false
|
||||
kapt.use.k2=false
|
||||
|
||||
@@ -16,14 +16,14 @@ desugar = "2.1.5"
|
||||
diskLruCache = "1.5"
|
||||
fragment = "1.8.6"
|
||||
gradle = "8.9.1"
|
||||
guava = "33.4.6-android"
|
||||
guava = "33.4.8-android"
|
||||
dagger = "2.56.1"
|
||||
hilt = "1.2.0"
|
||||
json = "20250107"
|
||||
junit = "4.13.2"
|
||||
junitKtx = "1.2.1"
|
||||
kotlin = "2.1.20"
|
||||
ksp = "2.1.20-1.0.31"
|
||||
ksp = "2.1.20-2.0.0"
|
||||
leakcanary = "3.0-alpha-8"
|
||||
lifecycle = "2.8.7"
|
||||
markwon = "4.6.2"
|
||||
@@ -34,7 +34,7 @@ okio = "3.11.0"
|
||||
parsers = "e874837efb"
|
||||
preference = "1.2.1"
|
||||
recyclerview = "1.4.0"
|
||||
room = "2.6.1"
|
||||
room = "2.7.0"
|
||||
ssiv = "9a67b6a7c9"
|
||||
swiperefreshlayout = "1.1.0"
|
||||
testRules = "1.6.1"
|
||||
|
||||
Reference in New Issue
Block a user