From 7039216eaee0135fb21af5bda869b7a7ab6bb611 Mon Sep 17 00:00:00 2001 From: len Date: Mon, 6 Jun 2016 16:14:56 +0200 Subject: [PATCH] Manual mappings. Code generation on java classes (better compilation times) --- app/build.gradle | 5 - app/src/main/java/eu/kanade/tachiyomi/App.kt | 10 +- .../tachiyomi/data/database/DatabaseHelper.kt | 13 +-- .../database/mappers/CategoryTypeMapping.kt | 62 ++++++++++++ .../database/mappers/ChapterTypeMapping.kt | 81 ++++++++++++++++ .../database/mappers/HistoryTypeMapping.kt | 62 ++++++++++++ .../mappers/MangaCategoryTypeMapping.kt | 59 ++++++++++++ .../database/mappers/MangaSyncTypeMapping.kt | 77 +++++++++++++++ .../data/database/mappers/MangaTypeMapping.kt | 95 +++++++++++++++++++ .../resolvers/LibraryMangaGetResolver.kt | 5 +- .../resolvers/MangaChapterGetResolver.kt | 8 +- .../MangaChapterHistoryGetResolver.kt | 12 ++- .../injection/AppComponentFactory.java | 16 ++++ .../test/java/eu/kanade/tachiyomi/TestApp.kt | 4 +- 14 files changed, 480 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/HistoryTypeMapping.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaCategoryTypeMapping.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaSyncTypeMapping.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt create mode 100644 app/src/main/java/eu/kanade/tachiyomi/injection/AppComponentFactory.java diff --git a/app/build.gradle b/app/build.gradle index 3b83767cbe..4b885faf47 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -84,10 +84,6 @@ android { } -kapt { - generateStubs = true -} - dependencies { final SUPPORT_LIBRARY_VERSION = '23.4.0' final DAGGER_VERSION = '2.4' @@ -148,7 +144,6 @@ dependencies { // Database compile "com.pushtorefresh.storio:sqlite:$STORIO_VERSION" compile "com.pushtorefresh.storio:sqlite-annotations:$STORIO_VERSION" - kapt "com.pushtorefresh.storio:sqlite-annotations-processor:$STORIO_VERSION" // Model View Presenter compile "info.android15.nucleus:nucleus:$NUCLEUS_VERSION" diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 98be1f295e..8cff1ff345 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -3,10 +3,9 @@ package eu.kanade.tachiyomi import android.app.Application import android.content.Context import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.injection.AppComponentFactory import eu.kanade.tachiyomi.injection.ComponentReflectionInjector import eu.kanade.tachiyomi.injection.component.AppComponent -import eu.kanade.tachiyomi.injection.component.DaggerAppComponent -import eu.kanade.tachiyomi.injection.module.AppModule import org.acra.ACRA import org.acra.annotation.ReportsCrashes import timber.log.Timber @@ -32,7 +31,7 @@ open class App : Application() { super.onCreate() if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) - component = prepareAppComponent().build() + component = createAppComponent() componentReflection = ComponentReflectionInjector(AppComponent::class.java, component) @@ -44,9 +43,8 @@ open class App : Application() { appTheme = PreferencesHelper.getTheme(this) } - protected open fun prepareAppComponent(): DaggerAppComponent.Builder { - return DaggerAppComponent.builder() - .appModule(AppModule(this)) + protected open fun createAppComponent(): AppComponent { + return AppComponentFactory.create(this) } protected open fun setupAcra() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt index 778376f5be..343479cc0f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database import android.content.Context import com.pushtorefresh.storio.sqlite.impl.DefaultStorIOSQLite +import eu.kanade.tachiyomi.data.database.mappers.* import eu.kanade.tachiyomi.data.database.models.* import eu.kanade.tachiyomi.data.database.queries.* @@ -13,12 +14,12 @@ open class DatabaseHelper(context: Context) override val db = DefaultStorIOSQLite.builder() .sqliteOpenHelper(DbOpenHelper(context)) - .addTypeMapping(Manga::class.java, MangaSQLiteTypeMapping()) - .addTypeMapping(Chapter::class.java, ChapterSQLiteTypeMapping()) - .addTypeMapping(MangaSync::class.java, MangaSyncSQLiteTypeMapping()) - .addTypeMapping(Category::class.java, CategorySQLiteTypeMapping()) - .addTypeMapping(MangaCategory::class.java, MangaCategorySQLiteTypeMapping()) - .addTypeMapping(History::class.java, HistorySQLiteTypeMapping()) + .addTypeMapping(Manga::class.java, MangaTypeMapping()) + .addTypeMapping(Chapter::class.java, ChapterTypeMapping()) + .addTypeMapping(MangaSync::class.java, MangaSyncTypeMapping()) + .addTypeMapping(Category::class.java, CategoryTypeMapping()) + .addTypeMapping(MangaCategory::class.java, MangaCategoryTypeMapping()) + .addTypeMapping(History::class.java, HistoryTypeMapping()) .build() inline fun inTransaction(block: () -> Unit) = db.inTransaction(block) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt new file mode 100644 index 0000000000..b1bd29fc46 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/CategoryTypeMapping.kt @@ -0,0 +1,62 @@ +package eu.kanade.tachiyomi.data.database.mappers + +import android.content.ContentValues +import android.database.Cursor +import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping +import com.pushtorefresh.storio.sqlite.operations.delete.DefaultDeleteResolver +import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver +import com.pushtorefresh.storio.sqlite.operations.put.DefaultPutResolver +import com.pushtorefresh.storio.sqlite.queries.DeleteQuery +import com.pushtorefresh.storio.sqlite.queries.InsertQuery +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.models.Category +import eu.kanade.tachiyomi.data.database.tables.CategoryTable.COL_FLAGS +import eu.kanade.tachiyomi.data.database.tables.CategoryTable.COL_ID +import eu.kanade.tachiyomi.data.database.tables.CategoryTable.COL_NAME +import eu.kanade.tachiyomi.data.database.tables.CategoryTable.COL_ORDER +import eu.kanade.tachiyomi.data.database.tables.CategoryTable.TABLE + +class CategoryTypeMapping : SQLiteTypeMapping( + CategoryPutResolver(), + CategoryGetResolver(), + CategoryDeleteResolver() +) + +class CategoryPutResolver : DefaultPutResolver() { + + override fun mapToInsertQuery(obj: Category) = InsertQuery.builder() + .table(TABLE) + .build() + + override fun mapToUpdateQuery(obj: Category) = UpdateQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() + + override fun mapToContentValues(obj: Category) = ContentValues(4).apply { + put(COL_ID, obj.id) + put(COL_NAME, obj.name) + put(COL_ORDER, obj.order) + put(COL_FLAGS, obj.flags) + } +} + +class CategoryGetResolver : DefaultGetResolver() { + + override fun mapFromCursor(cursor: Cursor) = Category().apply { + id = cursor.getInt(cursor.getColumnIndex(COL_ID)) + name = cursor.getString(cursor.getColumnIndex(COL_NAME)) + order = cursor.getInt(cursor.getColumnIndex(COL_ORDER)) + flags = cursor.getInt(cursor.getColumnIndex(COL_FLAGS)) + } +} + +class CategoryDeleteResolver : DefaultDeleteResolver() { + + override fun mapToDeleteQuery(obj: Category) = DeleteQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt new file mode 100644 index 0000000000..bdc2e51d45 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/ChapterTypeMapping.kt @@ -0,0 +1,81 @@ +package eu.kanade.tachiyomi.data.database.mappers + +import android.content.ContentValues +import android.database.Cursor +import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping +import com.pushtorefresh.storio.sqlite.operations.delete.DefaultDeleteResolver +import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver +import com.pushtorefresh.storio.sqlite.operations.put.DefaultPutResolver +import com.pushtorefresh.storio.sqlite.queries.DeleteQuery +import com.pushtorefresh.storio.sqlite.queries.InsertQuery +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.models.Chapter +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_CHAPTER_NUMBER +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_DATE_FETCH +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_DATE_UPLOAD +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_ID +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_LAST_PAGE_READ +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_MANGA_ID +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_NAME +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_READ +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_SOURCE_ORDER +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.COL_URL +import eu.kanade.tachiyomi.data.database.tables.ChapterTable.TABLE + +class ChapterTypeMapping : SQLiteTypeMapping( + ChapterPutResolver(), + ChapterGetResolver(), + ChapterDeleteResolver() +) + +class ChapterPutResolver : DefaultPutResolver() { + + override fun mapToInsertQuery(obj: Chapter) = InsertQuery.builder() + .table(TABLE) + .build() + + override fun mapToUpdateQuery(obj: Chapter) = UpdateQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() + + override fun mapToContentValues(obj: Chapter) = ContentValues(10).apply { + put(COL_ID, obj.id) + put(COL_MANGA_ID, obj.manga_id) + put(COL_URL, obj.url) + put(COL_NAME, obj.name) + put(COL_READ, obj.read) + put(COL_DATE_FETCH, obj.date_fetch) + put(COL_DATE_UPLOAD, obj.date_upload) + put(COL_LAST_PAGE_READ, obj.last_page_read) + put(COL_CHAPTER_NUMBER, obj.chapter_number) + put(COL_SOURCE_ORDER, obj.source_order) + } +} + +class ChapterGetResolver : DefaultGetResolver() { + + override fun mapFromCursor(cursor: Cursor) = Chapter().apply { + id = cursor.getLong(cursor.getColumnIndex(COL_ID)) + manga_id = cursor.getLong(cursor.getColumnIndex(COL_MANGA_ID)) + url = cursor.getString(cursor.getColumnIndex(COL_URL)) + name = cursor.getString(cursor.getColumnIndex(COL_NAME)) + read = cursor.getInt(cursor.getColumnIndex(COL_READ)) == 1 + date_fetch = cursor.getLong(cursor.getColumnIndex(COL_DATE_FETCH)) + date_upload = cursor.getLong(cursor.getColumnIndex(COL_DATE_UPLOAD)) + last_page_read = cursor.getInt(cursor.getColumnIndex(COL_LAST_PAGE_READ)) + chapter_number = cursor.getFloat(cursor.getColumnIndex(COL_CHAPTER_NUMBER)) + source_order = cursor.getInt(cursor.getColumnIndex(COL_SOURCE_ORDER)) + } +} + +class ChapterDeleteResolver : DefaultDeleteResolver() { + + override fun mapToDeleteQuery(obj: Chapter) = DeleteQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() +} + diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/HistoryTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/HistoryTypeMapping.kt new file mode 100644 index 0000000000..2997f8db1e --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/HistoryTypeMapping.kt @@ -0,0 +1,62 @@ +package eu.kanade.tachiyomi.data.database.mappers + +import android.content.ContentValues +import android.database.Cursor +import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping +import com.pushtorefresh.storio.sqlite.operations.delete.DefaultDeleteResolver +import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver +import com.pushtorefresh.storio.sqlite.operations.put.DefaultPutResolver +import com.pushtorefresh.storio.sqlite.queries.DeleteQuery +import com.pushtorefresh.storio.sqlite.queries.InsertQuery +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.models.History +import eu.kanade.tachiyomi.data.database.tables.HistoryTable.COL_CHAPTER_ID +import eu.kanade.tachiyomi.data.database.tables.HistoryTable.COL_ID +import eu.kanade.tachiyomi.data.database.tables.HistoryTable.COL_LAST_READ +import eu.kanade.tachiyomi.data.database.tables.HistoryTable.COL_TIME_READ +import eu.kanade.tachiyomi.data.database.tables.HistoryTable.TABLE + +class HistoryTypeMapping : SQLiteTypeMapping( + HistoryPutResolver(), + HistoryGetResolver(), + HistoryDeleteResolver() +) + +class HistoryPutResolver : DefaultPutResolver() { + + override fun mapToInsertQuery(obj: History) = InsertQuery.builder() + .table(TABLE) + .build() + + override fun mapToUpdateQuery(obj: History) = UpdateQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() + + override fun mapToContentValues(obj: History) = ContentValues(4).apply { + put(COL_ID, obj.id) + put(COL_CHAPTER_ID, obj.chapter_id) + put(COL_LAST_READ, obj.last_read) + put(COL_TIME_READ, obj.time_read) + } +} + +class HistoryGetResolver : DefaultGetResolver() { + + override fun mapFromCursor(cursor: Cursor) = History().apply { + id = cursor.getLong(cursor.getColumnIndex(COL_ID)) + chapter_id = cursor.getLong(cursor.getColumnIndex(COL_CHAPTER_ID)) + last_read = cursor.getLong(cursor.getColumnIndex(COL_LAST_READ)) + time_read = cursor.getLong(cursor.getColumnIndex(COL_TIME_READ)) + } +} + +class HistoryDeleteResolver : DefaultDeleteResolver() { + + override fun mapToDeleteQuery(obj: History) = DeleteQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaCategoryTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaCategoryTypeMapping.kt new file mode 100644 index 0000000000..b0b11e2fb5 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaCategoryTypeMapping.kt @@ -0,0 +1,59 @@ +package eu.kanade.tachiyomi.data.database.mappers + +import android.content.ContentValues +import android.database.Cursor +import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping +import com.pushtorefresh.storio.sqlite.operations.delete.DefaultDeleteResolver +import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver +import com.pushtorefresh.storio.sqlite.operations.put.DefaultPutResolver +import com.pushtorefresh.storio.sqlite.queries.DeleteQuery +import com.pushtorefresh.storio.sqlite.queries.InsertQuery +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.models.MangaCategory +import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable.COL_CATEGORY_ID +import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable.COL_ID +import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable.COL_MANGA_ID +import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable.TABLE + +class MangaCategoryTypeMapping : SQLiteTypeMapping( + MangaCategoryPutResolver(), + MangaCategoryGetResolver(), + MangaCategoryDeleteResolver() +) + +class MangaCategoryPutResolver : DefaultPutResolver() { + + override fun mapToInsertQuery(obj: MangaCategory) = InsertQuery.builder() + .table(TABLE) + .build() + + override fun mapToUpdateQuery(obj: MangaCategory) = UpdateQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() + + override fun mapToContentValues(obj: MangaCategory) = ContentValues(3).apply { + put(COL_ID, obj.id) + put(COL_MANGA_ID, obj.manga_id) + put(COL_CATEGORY_ID, obj.category_id) + } +} + +class MangaCategoryGetResolver : DefaultGetResolver() { + + override fun mapFromCursor(cursor: Cursor) = MangaCategory().apply { + id = cursor.getLong(cursor.getColumnIndex(COL_ID)) + manga_id = cursor.getLong(cursor.getColumnIndex(COL_MANGA_ID)) + category_id = cursor.getInt(cursor.getColumnIndex(COL_CATEGORY_ID)) + } +} + +class MangaCategoryDeleteResolver : DefaultDeleteResolver() { + + override fun mapToDeleteQuery(obj: MangaCategory) = DeleteQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaSyncTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaSyncTypeMapping.kt new file mode 100644 index 0000000000..b3c7cc92bd --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaSyncTypeMapping.kt @@ -0,0 +1,77 @@ +package eu.kanade.tachiyomi.data.database.mappers + +import android.content.ContentValues +import android.database.Cursor +import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping +import com.pushtorefresh.storio.sqlite.operations.delete.DefaultDeleteResolver +import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver +import com.pushtorefresh.storio.sqlite.operations.put.DefaultPutResolver +import com.pushtorefresh.storio.sqlite.queries.DeleteQuery +import com.pushtorefresh.storio.sqlite.queries.InsertQuery +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.models.MangaSync +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_ID +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_LAST_CHAPTER_READ +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_MANGA_ID +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_REMOTE_ID +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_SCORE +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_STATUS +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_SYNC_ID +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_TITLE +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.COL_TOTAL_CHAPTERS +import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable.TABLE + +class MangaSyncTypeMapping : SQLiteTypeMapping( + MangaSyncPutResolver(), + MangaSyncGetResolver(), + MangaSyncDeleteResolver() +) + +class MangaSyncPutResolver : DefaultPutResolver() { + + override fun mapToInsertQuery(obj: MangaSync) = InsertQuery.builder() + .table(TABLE) + .build() + + override fun mapToUpdateQuery(obj: MangaSync) = UpdateQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() + + override fun mapToContentValues(obj: MangaSync) = ContentValues(9).apply { + put(COL_ID, obj.id) + put(COL_MANGA_ID, obj.manga_id) + put(COL_SYNC_ID, obj.sync_id) + put(COL_REMOTE_ID, obj.remote_id) + put(COL_TITLE, obj.title) + put(COL_LAST_CHAPTER_READ, obj.last_chapter_read) + put(COL_TOTAL_CHAPTERS, obj.total_chapters) + put(COL_STATUS, obj.status) + put(COL_SCORE, obj.score) + } +} + +class MangaSyncGetResolver : DefaultGetResolver() { + + override fun mapFromCursor(cursor: Cursor) = MangaSync().apply { + id = cursor.getLong(cursor.getColumnIndex(COL_ID)) + manga_id = cursor.getLong(cursor.getColumnIndex(COL_MANGA_ID)) + sync_id = cursor.getInt(cursor.getColumnIndex(COL_SYNC_ID)) + remote_id = cursor.getInt(cursor.getColumnIndex(COL_REMOTE_ID)) + title = cursor.getString(cursor.getColumnIndex(COL_TITLE)) + last_chapter_read = cursor.getInt(cursor.getColumnIndex(COL_LAST_CHAPTER_READ)) + total_chapters = cursor.getInt(cursor.getColumnIndex(COL_TOTAL_CHAPTERS)) + status = cursor.getInt(cursor.getColumnIndex(COL_STATUS)) + score = cursor.getFloat(cursor.getColumnIndex(COL_SCORE)) + } +} + +class MangaSyncDeleteResolver : DefaultDeleteResolver() { + + override fun mapToDeleteQuery(obj: MangaSync) = DeleteQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt new file mode 100644 index 0000000000..e98fa6da8a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt @@ -0,0 +1,95 @@ +package eu.kanade.tachiyomi.data.database.mappers + +import android.content.ContentValues +import android.database.Cursor +import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping +import com.pushtorefresh.storio.sqlite.operations.delete.DefaultDeleteResolver +import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver +import com.pushtorefresh.storio.sqlite.operations.put.DefaultPutResolver +import com.pushtorefresh.storio.sqlite.queries.DeleteQuery +import com.pushtorefresh.storio.sqlite.queries.InsertQuery +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_ARTIST +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_AUTHOR +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_CHAPTER_FLAGS +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_DESCRIPTION +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_FAVORITE +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_GENRE +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_ID +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_INITIALIZED +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_LAST_UPDATE +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_SOURCE +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_STATUS +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_THUMBNAIL_URL +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_TITLE +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_URL +import eu.kanade.tachiyomi.data.database.tables.MangaTable.COL_VIEWER +import eu.kanade.tachiyomi.data.database.tables.MangaTable.TABLE + +class MangaTypeMapping : SQLiteTypeMapping( + MangaPutResolver(), + MangaGetResolver(), + MangaDeleteResolver() +) + +class MangaPutResolver : DefaultPutResolver() { + + override fun mapToInsertQuery(obj: Manga) = InsertQuery.builder() + .table(TABLE) + .build() + + override fun mapToUpdateQuery(obj: Manga) = UpdateQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() + + override fun mapToContentValues(obj: Manga) = ContentValues(15).apply { + put(COL_ID, obj.id) + put(COL_SOURCE, obj.source) + put(COL_URL, obj.url) + put(COL_ARTIST, obj.artist) + put(COL_AUTHOR, obj.author) + put(COL_DESCRIPTION, obj.description) + put(COL_GENRE, obj.genre) + put(COL_TITLE, obj.title) + put(COL_STATUS, obj.status) + put(COL_THUMBNAIL_URL, obj.thumbnail_url) + put(COL_FAVORITE, obj.favorite) + put(COL_LAST_UPDATE, obj.last_update) + put(COL_INITIALIZED, obj.initialized) + put(COL_VIEWER, obj.viewer) + put(COL_CHAPTER_FLAGS, obj.chapter_flags) + } +} + +open class MangaGetResolver : DefaultGetResolver() { + + override fun mapFromCursor(cursor: Cursor) = Manga().apply { + id = cursor.getLong(cursor.getColumnIndex(COL_ID)) + source = cursor.getInt(cursor.getColumnIndex(COL_SOURCE)) + url = cursor.getString(cursor.getColumnIndex(COL_URL)) + artist = cursor.getString(cursor.getColumnIndex(COL_ARTIST)) + author = cursor.getString(cursor.getColumnIndex(COL_AUTHOR)) + description = cursor.getString(cursor.getColumnIndex(COL_DESCRIPTION)) + genre = cursor.getString(cursor.getColumnIndex(COL_GENRE)) + title = cursor.getString(cursor.getColumnIndex(COL_TITLE)) + status = cursor.getInt(cursor.getColumnIndex(COL_STATUS)) + thumbnail_url = cursor.getString(cursor.getColumnIndex(COL_THUMBNAIL_URL)) + favorite = cursor.getInt(cursor.getColumnIndex(COL_FAVORITE)) == 1 + last_update = cursor.getLong(cursor.getColumnIndex(COL_LAST_UPDATE)) + initialized = cursor.getInt(cursor.getColumnIndex(COL_INITIALIZED)) == 1 + viewer = cursor.getInt(cursor.getColumnIndex(COL_VIEWER)) + chapter_flags = cursor.getInt(cursor.getColumnIndex(COL_CHAPTER_FLAGS)) + } +} + +class MangaDeleteResolver : DefaultDeleteResolver() { + + override fun mapToDeleteQuery(obj: Manga) = DeleteQuery.builder() + .table(TABLE) + .where("$COL_ID = ?") + .whereArgs(obj.id) + .build() +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt index 70f43c4a8e..4be02fecef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/LibraryMangaGetResolver.kt @@ -1,12 +1,11 @@ package eu.kanade.tachiyomi.data.database.resolvers import android.database.Cursor - +import eu.kanade.tachiyomi.data.database.mappers.MangaGetResolver import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.models.MangaStorIOSQLiteGetResolver import eu.kanade.tachiyomi.data.database.tables.MangaTable -class LibraryMangaGetResolver : MangaStorIOSQLiteGetResolver() { +class LibraryMangaGetResolver : MangaGetResolver() { companion object { val INSTANCE = LibraryMangaGetResolver() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterGetResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterGetResolver.kt index 8745fb398c..4f9ce536fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterGetResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterGetResolver.kt @@ -2,9 +2,9 @@ package eu.kanade.tachiyomi.data.database.resolvers import android.database.Cursor import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver -import eu.kanade.tachiyomi.data.database.models.ChapterStorIOSQLiteGetResolver +import eu.kanade.tachiyomi.data.database.mappers.ChapterGetResolver +import eu.kanade.tachiyomi.data.database.mappers.MangaGetResolver import eu.kanade.tachiyomi.data.database.models.MangaChapter -import eu.kanade.tachiyomi.data.database.models.MangaStorIOSQLiteGetResolver class MangaChapterGetResolver : DefaultGetResolver() { @@ -12,9 +12,9 @@ class MangaChapterGetResolver : DefaultGetResolver() { val INSTANCE = MangaChapterGetResolver() } - private val mangaGetResolver = MangaStorIOSQLiteGetResolver() + private val mangaGetResolver = MangaGetResolver() - private val chapterGetResolver = ChapterStorIOSQLiteGetResolver() + private val chapterGetResolver = ChapterGetResolver() override fun mapFromCursor(cursor: Cursor): MangaChapter { val manga = mangaGetResolver.mapFromCursor(cursor) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt index c5cb48f672..6eecaf273d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaChapterHistoryGetResolver.kt @@ -2,7 +2,11 @@ package eu.kanade.tachiyomi.data.database.resolvers import android.database.Cursor import com.pushtorefresh.storio.sqlite.operations.get.DefaultGetResolver -import eu.kanade.tachiyomi.data.database.models.* +import eu.kanade.tachiyomi.data.database.mappers.ChapterGetResolver +import eu.kanade.tachiyomi.data.database.mappers.HistoryGetResolver +import eu.kanade.tachiyomi.data.database.mappers.MangaGetResolver +import eu.kanade.tachiyomi.data.database.models.MangaChapter +import eu.kanade.tachiyomi.data.database.models.MangaChapterHistory class MangaChapterHistoryGetResolver : DefaultGetResolver() { companion object { @@ -12,17 +16,17 @@ class MangaChapterHistoryGetResolver : DefaultGetResolver() /** * Manga get resolver */ - private val mangaGetResolver = MangaStorIOSQLiteGetResolver() + private val mangaGetResolver = MangaGetResolver() /** * Chapter get resolver */ - private val chapterResolver = ChapterStorIOSQLiteGetResolver() + private val chapterResolver = ChapterGetResolver() /** * History get resolver */ - private val historyGetResolver = HistoryStorIOSQLiteGetResolver() + private val historyGetResolver = HistoryGetResolver() /** * Map correct objects from cursor result diff --git a/app/src/main/java/eu/kanade/tachiyomi/injection/AppComponentFactory.java b/app/src/main/java/eu/kanade/tachiyomi/injection/AppComponentFactory.java new file mode 100644 index 0000000000..6bcb6a3de3 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/injection/AppComponentFactory.java @@ -0,0 +1,16 @@ +package eu.kanade.tachiyomi.injection; + +import eu.kanade.tachiyomi.App; +import eu.kanade.tachiyomi.injection.component.AppComponent; +import eu.kanade.tachiyomi.injection.component.DaggerAppComponent; +import eu.kanade.tachiyomi.injection.module.AppModule; + + +public class AppComponentFactory { + + public static AppComponent create(App app) { + return DaggerAppComponent.builder().appModule(new AppModule(app)).build(); + } +} + + diff --git a/app/src/test/java/eu/kanade/tachiyomi/TestApp.kt b/app/src/test/java/eu/kanade/tachiyomi/TestApp.kt index 0685aced35..ac710e95d0 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/TestApp.kt +++ b/app/src/test/java/eu/kanade/tachiyomi/TestApp.kt @@ -1,15 +1,17 @@ package eu.kanade.tachiyomi +import eu.kanade.tachiyomi.injection.component.AppComponent import eu.kanade.tachiyomi.injection.component.DaggerAppComponent import eu.kanade.tachiyomi.injection.module.AppModule import eu.kanade.tachiyomi.injection.module.TestDataModule open class TestApp : App() { - override fun prepareAppComponent(): DaggerAppComponent.Builder { + override fun createAppComponent(): AppComponent { return DaggerAppComponent.builder() .appModule(AppModule(this)) .dataModule(TestDataModule()) + .build() } override fun setupAcra() {