From d542fa6bb6583b513f95438d17d3c3b15ec0acd7 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 15 Apr 2025 19:48:22 +0300 Subject: [PATCH] Update database structure and migrate from kapt to ksp --- app/build.gradle | 7 +++---- .../kotatsu/core/backup/JsonDeserializer.kt | 4 ++++ .../kotatsu/core/backup/JsonSerializer.kt | 3 +++ .../koitharu/kotatsu/core/db/MangaDatabase.kt | 4 +++- .../kotatsu/core/db/dao/MangaSourcesDao.kt | 2 ++ .../kotatsu/core/db/entity/EntityMapping.kt | 1 + .../kotatsu/core/db/entity/MangaPrefsEntity.kt | 3 +++ .../kotatsu/core/db/entity/MangaSourceEntity.kt | 1 + .../koitharu/kotatsu/core/db/entity/TagEntity.kt | 1 + .../core/db/migrations/Migration25To26.kt | 16 ++++++++++++++++ .../kotatsu/core/parser/MangaDataRepository.kt | 3 +++ .../explore/data/MangaSourcesRepository.kt | 2 ++ .../kotatsu/favourites/data/FavouriteEntity.kt | 1 + .../favourites/domain/FavouritesRepository.kt | 1 + gradle.properties | 1 - gradle/libs.versions.toml | 6 +++--- 16 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/db/migrations/Migration25To26.kt diff --git a/app/build.gradle b/app/build.gradle index 5c14ce619..326beccdd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonDeserializer.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonDeserializer.kt index 8ecc60e98..97d0ea712 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonDeserializer.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonDeserializer.kt @@ -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 { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonSerializer.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonSerializer.kt index 16c3af122..e54309d1d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonSerializer.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/backup/JsonSerializer.kt @@ -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) }, ) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/MangaDatabase.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/MangaDatabase.kt index 52579ee8f..e2fbd6108 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/MangaDatabase.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/MangaDatabase.kt @@ -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 = arrayOf( Migration23To24(), Migration24To23(), Migration24To25(), + Migration25To26(), ) fun MangaDatabase(context: Context): MangaDatabase = Room diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/dao/MangaSourcesDao.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/dao/MangaSourcesDao.kt index 3e11fda1c..bc61aba4c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/dao/MangaSourcesDao.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/dao/MangaSourcesDao.kt @@ -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) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt index 508b25f22..1747b0934 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt @@ -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.toEntities() = map(MangaTag::toEntity) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaPrefsEntity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaPrefsEntity.kt index 18fe1db04..167f64e3c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaPrefsEntity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaPrefsEntity.kt @@ -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?, ) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaSourceEntity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaSourceEntity.kt index 849cfcd61..e49bb007f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaSourceEntity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaSourceEntity.kt @@ -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, ) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/TagEntity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/TagEntity.kt index 6c7907da6..e84cf963b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/TagEntity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/TagEntity.kt @@ -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, ) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/migrations/Migration25To26.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/migrations/Migration25To26.kt new file mode 100644 index 000000000..9504fb68f --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/migrations/Migration25To26.kt @@ -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") + } +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/MangaDataRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/MangaDataRepository.kt index 521b2536f..74a49bf57 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/MangaDataRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/MangaDataRepository.kt @@ -161,5 +161,8 @@ class MangaDataRepository @Inject constructor( cfContrast = 0f, cfInvert = false, cfGrayscale = false, + titleOverride = null, + coverUrlOverride = null, + contentRatingOverride = null, ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt index 24726e457..9f59ed56e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt @@ -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) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouriteEntity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouriteEntity.kt index 87f8afa55..6cfc09079 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouriteEntity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/data/FavouriteEntity.kt @@ -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, ) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt index f81b1aa50..be4c9efb5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/FavouritesRepository.kt @@ -237,6 +237,7 @@ class FavouritesRepository @Inject constructor( createdAt = System.currentTimeMillis(), sortKey = 0, deletedAt = 0L, + isPinned = false, ) db.getFavouritesDao().insert(entity) } diff --git a/gradle.properties b/gradle.properties index 682e3e860..0c9e2bae4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4c3301bb9..f2a09e7ad 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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"