From 10674890a714a3f8b90778e717d0f41e77529ab1 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 23 Feb 2020 00:32:30 -0800 Subject: [PATCH] Reader now defaults to webtoon style for webtoons --- .../backup/serializer/MangaTypeAdapter.kt | 3 ++- .../data/database/models/LibraryManga.kt | 21 ------------------- .../tachiyomi/data/database/models/Manga.kt | 19 +++++++++++++++++ .../data/database/models/MangaImpl.kt | 4 +--- .../tachiyomi/ui/library/LibraryPresenter.kt | 8 +++---- .../library/filter/SortFilterBottomSheet.kt | 4 ++-- .../tachiyomi/ui/reader/ReaderPresenter.kt | 8 ++++++- 7 files changed, 35 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/MangaTypeAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/MangaTypeAdapter.kt index e1f7634916..d63a040e14 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/MangaTypeAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/MangaTypeAdapter.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.data.backup.serializer import com.github.salomonbrys.kotson.typeAdapter import com.google.gson.TypeAdapter import eu.kanade.tachiyomi.data.database.models.MangaImpl +import kotlin.math.max /** * JSON Serializer used to write / read [MangaImpl] to / from json @@ -16,7 +17,7 @@ object MangaTypeAdapter { value(it.url) value(it.originalTitle()) value(it.source) - value(it.viewer) + value(max(0, it.viewer)) value(it.chapter_flags) endArray() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt index 0eb74c4a83..b9a7d94286 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/LibraryManga.kt @@ -1,30 +1,9 @@ package eu.kanade.tachiyomi.data.database.models -import eu.kanade.tachiyomi.source.SourceManager -import uy.kohesive.injekt.injectLazy -import java.util.Locale - class LibraryManga : MangaImpl() { var unread: Int = 0 var category: Int = 0 - fun mangaType(): Int { - val sourceManager:SourceManager by injectLazy() - return if (currentGenres()?.split(",")?.any - { tag -> - val trimmedTag = tag.trim().toLowerCase(Locale.getDefault()) - trimmedTag == "long strip" || trimmedTag == "manwha" - } == true || - sourceManager.getOrStub(source).name.contains("webtoon", true)) - MANWHA - else MANGA - } - - companion object { - const val MANGA = 1 - const val MANWHA = 2 - } - } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt index c7dff69dfa..68cdd1650f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Manga.kt @@ -1,6 +1,9 @@ package eu.kanade.tachiyomi.data.database.models +import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga +import uy.kohesive.injekt.injectLazy +import java.util.Locale interface Manga : SManga { @@ -30,6 +33,19 @@ interface Manga : SManga { return chapter_flags and SORT_MASK == SORT_DESC } + fun mangaType(): Int { + val sourceManager: SourceManager by injectLazy() + return if (currentGenres()?.split(",")?.any + { tag -> + val trimmedTag = tag.trim().toLowerCase(Locale.US) + trimmedTag == "long strip" || trimmedTag == "manwha" || + trimmedTag.contains("webtoon") + } == true || + sourceManager.getOrStub(source).name.contains("webtoon", true)) + TYPE_MANWHA + else TYPE_MANGA + } + // Used to display the chapter's title one way or another var displayMode: Int get() = chapter_flags and DISPLAY_MASK @@ -80,6 +96,9 @@ interface Manga : SManga { const val DISPLAY_NUMBER = 0x00100000 const val DISPLAY_MASK = 0x00100000 + const val TYPE_MANGA = 1 + const val TYPE_MANWHA = 2 + fun create(source: Long): Manga = MangaImpl().apply { this.source = source } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index 8f5313a42a..032cd25f24 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -4,8 +4,6 @@ import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.source.model.SManga import uy.kohesive.injekt.injectLazy -import kotlin.collections.MutableMap -import kotlin.collections.mutableMapOf import kotlin.collections.set open class MangaImpl : Manga { @@ -36,7 +34,7 @@ open class MangaImpl : Manga { override var initialized: Boolean = false - override var viewer: Int = 0 + override var viewer: Int = -1 override var chapter_flags: Int = 0 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 720e58c258..6d8e9ddf8c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -169,11 +169,11 @@ class LibraryPresenter( return@f false if (filterUnread == STATE_REALLY_EXCLUDE && item.manga.unread > 0) return@f false - if (filterMangaType == LibraryManga.MANGA && - item.manga.mangaType() == LibraryManga.MANWHA) + if (filterMangaType == Manga.TYPE_MANGA && + item.manga.mangaType() == Manga.TYPE_MANWHA) return@f false - if ((filterMangaType == LibraryManga.MANWHA) && - item.manga.mangaType() == LibraryManga.MANGA) return@f false + if ((filterMangaType == Manga.TYPE_MANWHA) && + item.manga.mangaType() == Manga.TYPE_MANGA) return@f false if (filterCompleted == STATE_INCLUDE && item.manga.status != SManga.COMPLETED) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt index f1c9b08704..6e5c22c57f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/SortFilterBottomSheet.kt @@ -20,7 +20,7 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category -import eu.kanade.tachiyomi.data.database.models.LibraryManga +import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.track.TrackManager @@ -372,7 +372,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) { val db:DatabaseHelper by injectLazy() val librryManga = db.getLibraryMangas().executeAsBlocking() - if (librryManga.any { it.mangaType() == LibraryManga.MANWHA }) { + if (librryManga.any { it.mangaType() == Manga.TYPE_MANWHA }) { launchUI { val mangaType = inflate(R.layout.filter_buttons) as FilterTagGroup mangaType.setup( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index a696b0d9e0..d6c4ea630e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -33,7 +33,7 @@ import timber.log.Timber import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File -import java.util.* +import java.util.Date import java.util.concurrent.TimeUnit /** @@ -394,6 +394,12 @@ class ReaderPresenter( */ fun getMangaViewer(): Int { val manga = manga ?: return preferences.defaultViewer() + if (manga.viewer == -1) { + val type = + if (manga.mangaType() == Manga.TYPE_MANWHA) ReaderActivity.WEBTOON + else 0 + setMangaViewer(type) + } return if (manga.viewer == 0) preferences.defaultViewer() else manga.viewer }