From 6687c80b2d086bc400b45f1ebb48ec7fcaf89efa Mon Sep 17 00:00:00 2001 From: len Date: Sun, 5 Jun 2016 11:14:40 +0200 Subject: [PATCH] Minor changes --- .../data/database/queries/MangaQueries.kt | 6 ++++ .../resolvers/MangaFlagsPutResolver.kt | 33 +++++++++++++++++++ .../data/source/online/english/Mangahere.kt | 2 +- .../ui/manga/chapter/ChaptersPresenter.kt | 10 +++--- 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt index cd66c0a9d2..1b058ac3fc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt @@ -6,6 +6,7 @@ import com.pushtorefresh.storio.sqlite.queries.RawQuery import eu.kanade.tachiyomi.data.database.DbProvider import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.resolvers.LibraryMangaGetResolver +import eu.kanade.tachiyomi.data.database.resolvers.MangaFlagsPutResolver import eu.kanade.tachiyomi.data.database.tables.ChapterTable import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable import eu.kanade.tachiyomi.data.database.tables.MangaTable @@ -60,6 +61,11 @@ interface MangaQueries : DbProvider { fun insertMangas(mangas: List) = db.put().objects(mangas).prepare() + fun updateFlags(manga: Manga) = db.put() + .`object`(manga) + .withPutResolver(MangaFlagsPutResolver()) + .prepare() + fun deleteManga(manga: Manga) = db.delete().`object`(manga).prepare() fun deleteMangas(mangas: List) = db.delete().objects(mangas).prepare() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt new file mode 100644 index 0000000000..f9cc403ea2 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaFlagsPutResolver.kt @@ -0,0 +1,33 @@ +package eu.kanade.tachiyomi.data.database.resolvers + +import android.content.ContentValues +import com.pushtorefresh.storio.sqlite.StorIOSQLite +import com.pushtorefresh.storio.sqlite.operations.put.PutResolver +import com.pushtorefresh.storio.sqlite.operations.put.PutResult +import com.pushtorefresh.storio.sqlite.queries.UpdateQuery +import eu.kanade.tachiyomi.data.database.inTransactionReturn +import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.tables.MangaTable + +class MangaFlagsPutResolver : PutResolver() { + + override fun performPut(db: StorIOSQLite, manga: Manga) = db.inTransactionReturn { + val updateQuery = mapToUpdateQuery(manga) + val contentValues = mapToContentValues(manga) + + val numberOfRowsUpdated = db.internal().update(updateQuery, contentValues) + PutResult.newUpdateResult(numberOfRowsUpdated, updateQuery.table()) + } + + fun mapToUpdateQuery(manga: Manga) = UpdateQuery.builder() + .table(MangaTable.TABLE) + .where("${MangaTable.COL_ID} = ?") + .whereArgs(manga.id) + .build() + + fun mapToContentValues(manga: Manga) = ContentValues(1).apply { + put(MangaTable.COL_CHAPTER_FLAGS, manga.chapter_flags) + } + +} + diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt index b98252633f..1abd0498ee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Mangahere.kt @@ -37,7 +37,7 @@ class Mangahere(context: Context, override val id: Int) : ParsedOnlineSource(con override fun searchMangaInitialUrl(query: String) = "$baseUrl/search.php?name=$query&page=1&sort=views&order=za" - override fun searchMangaSelector() = "div.result_search > dl" + override fun searchMangaSelector() = "div.result_search > dl:has(dt)" override fun searchMangaFromElement(element: Element, manga: Manga) { element.select("a.manga_info").first().let { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt index d6b71aa032..dce4621452 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.kt @@ -224,30 +224,30 @@ class ChaptersPresenter : BasePresenter() { fun revertSortOrder() { manga.setChapterOrder(if (sortDescending()) Manga.SORT_ASC else Manga.SORT_DESC) - db.insertManga(manga).executeAsBlocking() + db.updateFlags(manga).executeAsBlocking() refreshChapters() } fun setReadFilter(onlyUnread: Boolean) { manga.readFilter = if (onlyUnread) Manga.SHOW_UNREAD else Manga.SHOW_ALL - db.insertManga(manga).executeAsBlocking() + db.updateFlags(manga).executeAsBlocking() refreshChapters() } fun setDownloadedFilter(onlyDownloaded: Boolean) { manga.downloadedFilter = if (onlyDownloaded) Manga.SHOW_DOWNLOADED else Manga.SHOW_ALL - db.insertManga(manga).executeAsBlocking() + db.updateFlags(manga).executeAsBlocking() refreshChapters() } fun setDisplayMode(mode: Int) { manga.displayMode = mode - db.insertManga(manga).executeAsBlocking() + db.updateFlags(manga).executeAsBlocking() } fun setSorting(mode: Int) { manga.sorting = mode - db.insertManga(manga).executeAsBlocking() + db.updateFlags(manga).executeAsBlocking() refreshChapters() }