From dace5b4de7bed5af02533057a16a68fe67fd7155 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 3 Mar 2020 12:37:28 -0800 Subject: [PATCH] Added Reader type for manga to seperate manga type Using manhwa wording again Fixes for swipe refresh in manga page Fixed layout when expaning detials in manga info --- .../tachiyomi/data/database/models/Manga.kt | 42 +++++++--- .../tachiyomi/ui/library/LibraryPresenter.kt | 2 +- .../library/filter/SortFilterBottomSheet.kt | 2 +- .../ui/manga/MangaChaptersController.kt | 8 +- .../tachiyomi/ui/manga/MangaHeaderHolder.kt | 15 +++- .../tachiyomi/ui/manga/MangaPresenter.kt | 21 +++-- .../tachiyomi/ui/reader/ReaderActivity.kt | 31 +++++++- .../tachiyomi/ui/reader/ReaderPresenter.kt | 7 +- .../tachiyomi/util/view/ViewExtensions.kt | 2 +- app/src/main/res/layout/manga_header_item.xml | 77 ++++++------------- app/src/main/res/layout/reader_activity.xml | 1 + app/src/main/res/menu/chapters_mat_single.xml | 16 ++-- app/src/main/res/values/strings.xml | 3 + 13 files changed, 132 insertions(+), 95 deletions(-) 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 fe019fdf69..a5cba0d785 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 @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database.models import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SManga +import eu.kanade.tachiyomi.ui.reader.ReaderActivity import uy.kohesive.injekt.injectLazy import java.util.Locale @@ -38,11 +39,9 @@ interface Manga : SManga { val currentTags = currentGenres()?.split(",")?.map { it.trim().toLowerCase(Locale.US) } return if (currentTags?.any { tag -> - tag == "long strip" || tag == "manhwa" || - tag.contains("webtoon") - } == true || - sourceManager.getOrStub(source).name.contains("webtoon", true)) - TYPE_WEBTOON + tag.startsWith("english") || tag == "comic" + } == true) + TYPE_COMIC else if (currentTags?.any { tag -> tag.startsWith("chinese") || tag == "manhua" @@ -50,12 +49,33 @@ interface Manga : SManga { TYPE_MANHUA else if (currentTags?.any { tag -> - tag.startsWith("english") || tag == "comic" - } == true) - TYPE_COMIC + tag == "long strip" || tag == "manhwa" || + tag.contains("webtoon") + } == true || + sourceManager.getOrStub(source).name.contains("webtoon", true)) + TYPE_MANHWA else TYPE_MANGA } + fun defaultReaderType(): Int { + val sourceManager: SourceManager by injectLazy() + val currentTags = currentGenres()?.split(",")?.map { it.trim().toLowerCase(Locale.US) } + return if (currentTags?.any + { tag -> + tag == "long strip" || tag == "manhwa" || + tag.contains("webtoon") + } == true || + sourceManager.getOrStub(source).name.contains("webtoon", true)) + ReaderActivity.WEBTOON + else if (currentTags?.any + { tag -> + tag.startsWith("chinese") || tag == "manhua" || + tag.startsWith("english") || tag == "comic" + } == true) + ReaderActivity.LEFT_TO_RIGHT + else 0 + } + // Used to display the chapter's title one way or another var displayMode: Int get() = chapter_flags and DISPLAY_MASK @@ -106,8 +126,12 @@ interface Manga : SManga { const val DISPLAY_NUMBER = 0x00100000 const val DISPLAY_MASK = 0x00100000 + const val READ_WEBTOON = 0 + const val READ_LTR = 1 + const val READ_RTL = 2 + const val TYPE_MANGA = 0 - const val TYPE_WEBTOON = 1 + const val TYPE_MANHWA = 1 const val TYPE_MANHUA = 2 const val TYPE_COMIC = 3 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 d303501a74..39b33e6dbd 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 @@ -174,7 +174,7 @@ class LibraryPresenter( if ((filterMangaType == Manga.TYPE_MANHUA) && mangaType != Manga.TYPE_MANHUA) return@f false if ((filterMangaType == Manga.TYPE_COMIC) && mangaType != Manga.TYPE_COMIC) return@f false - if ((filterMangaType == Manga.TYPE_WEBTOON) && mangaType != Manga.TYPE_WEBTOON) return@f false + if ((filterMangaType == Manga.TYPE_MANHWA) && mangaType != Manga.TYPE_MANHWA) return@f false } 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 900b327cbe..ad28922777 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 @@ -215,7 +215,7 @@ class SortFilterBottomSheet @JvmOverloads constructor(context: Context, attrs: A } val librryManga = db.getLibraryMangas().executeAsBlocking() val types = mutableListOf() - if (librryManga.any { it.mangaType() == Manga.TYPE_WEBTOON }) types.add(R.string.webtoon_viewer) + if (librryManga.any { it.mangaType() == Manga.TYPE_MANHWA }) types.add(R.string.manhwa) if (librryManga.any { it.mangaType() == Manga.TYPE_MANHUA }) types.add(R.string.manhua) if (librryManga.any { it.mangaType() == Manga.TYPE_COMIC }) types.add(R.string.comic) if (types.isNotEmpty()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaChaptersController.kt index 82a873565d..487bd9d14f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaChaptersController.kt @@ -57,6 +57,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.getText import eu.kanade.tachiyomi.util.view.snack @@ -235,7 +236,7 @@ class MangaChaptersController : BaseController, } fun showError(message: String) { - swipe_refresh.isRefreshing = false + swipe_refresh?.isRefreshing = false view?.snack(message) } @@ -277,7 +278,7 @@ class MangaChaptersController : BaseController, adapter?.updateDataSet(listOf(ChapterItem(Chapter.createH(), presenter.manga))) } else { - swipe_refresh.isRefreshing = false + swipe_refresh?.isRefreshing = false adapter?.updateDataSet( listOf(ChapterItem(Chapter.createH(), presenter.manga)) + presenter.chapters ) @@ -286,8 +287,9 @@ class MangaChaptersController : BaseController, fun updateChapters(chapters: List) { - swipe_refresh.isRefreshing = false + swipe_refresh?.isRefreshing = false if (presenter.chapters.isEmpty() && fromCatalogue && !presenter.hasRequested) { + launchUI { swipe_refresh?.isRefreshing = true } presenter.fetchChaptersFromSource() } adapter?.updateDataSet(listOf(ChapterItem(Chapter.createH(), presenter.manga)) + chapters) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 65ffea4d0f..8ce651bf47 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -31,7 +31,7 @@ class MangaHeaderHolder( init { start_reading_button.setOnClickListener { adapter.coverListener?.readNextChapter() } top_view.updateLayoutParams { - topMargin = adapter.coverListener?.topCoverHeight() ?: 0 + height = adapter.coverListener?.topCoverHeight() ?: 0 } more_button.setOnClickListener { expandDesc() } manga_summary.setOnClickListener { expandDesc() } @@ -86,11 +86,13 @@ class MangaHeaderHolder( if (manga_summary.lineCount < 3 && manga.currentGenres().isNullOrBlank()) { more_button_group.gone() } + else + more_button_group.visible() } manga_summary_label.text = itemView.context.getString(R.string.about_this, itemView.context.getString( when { - manga.mangaType() == Manga.TYPE_WEBTOON -> R.string.webtoon_viewer + manga.mangaType() == Manga.TYPE_MANHWA -> R.string.manhwa manga.mangaType() == Manga.TYPE_MANHUA -> R.string.manhua manga.mangaType() == Manga.TYPE_COMIC -> R.string.comic else -> R.string.manga @@ -149,7 +151,7 @@ class MangaHeaderHolder( chapters_title.text = itemView.resources.getQuantityString(R.plurals.chapters, count, count) top_view.updateLayoutParams { - topMargin = adapter.coverListener?.topCoverHeight() ?: 0 + height = adapter.coverListener?.topCoverHeight() ?: 0 } manga_status.text = (itemView.context.getString( when (manga.status) { @@ -173,11 +175,16 @@ class MangaHeaderHolder( fun setTopHeight(newHeight: Int) { top_view.updateLayoutParams { - topMargin = newHeight + height = newHeight } } fun setBackDrop(color: Int) { true_backdrop.setBackgroundColor(color) } + + override fun onLongClick(view: View?): Boolean { + super.onLongClick(view) + return false + } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index 72250e4533..da7fbb1157 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.manga +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category @@ -17,6 +18,7 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource +import eu.kanade.tachiyomi.util.system.launchUI import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -50,10 +52,17 @@ class MangaPresenter(private val controller: MangaChaptersController, fun onCreate() { isLockedFromSearch = SecureActivityDelegate.shouldBeLocked() downloadManager.addListener(this) - if (!manga.initialized) - fetchMangaFromSource() - updateChapters() - controller.updateChapters(this.chapters) + if (!manga.initialized) { + controller.updateHeader() + launchUI { + controller.setRefresh(true) + } + refreshAll() + } + else { + updateChapters() + controller.updateChapters(this.chapters) + } } fun onDestroy() { @@ -363,7 +372,9 @@ class MangaPresenter(private val controller: MangaChaptersController, } private fun trimException(e: java.lang.Exception): String { - return e.message?.split(": ")?.drop(1)?.joinToString(": ") ?: "Error" + return (if (e.message?.contains(": ") == true) + e.message?.split(": ")?.drop(1)?.joinToString(": ") + else e.message) ?: preferences.context.getString(R.string.unknown_error) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index ae594f5d32..ca467108d4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -23,6 +23,7 @@ import android.widget.SeekBar import androidx.appcompat.app.AppCompatDelegate import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.snackbar.Snackbar import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga @@ -49,6 +50,7 @@ import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.SimpleAnimationListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener @@ -64,6 +66,7 @@ import rx.subscriptions.CompositeSubscription import timber.log.Timber import uy.kohesive.injekt.injectLazy import java.io.File +import java.util.Locale import java.util.concurrent.TimeUnit import kotlin.math.abs @@ -125,6 +128,8 @@ class ReaderActivity : BaseRxActivity(), @Suppress("DEPRECATION") private var progressDialog: ProgressDialog? = null + private var snackbar:Snackbar? = null + companion object { @Suppress("unused") const val LEFT_TO_RIGHT = 1 @@ -196,6 +201,8 @@ class ReaderActivity : BaseRxActivity(), bottomSheet = null progressDialog?.dismiss() progressDialog = null + snackbar?.dismiss() + snackbar = null } /** @@ -323,6 +330,7 @@ class ReaderActivity : BaseRxActivity(), menuVisible = visible if (visible) coroutine?.cancel() if (visible) { + snackbar?.dismiss() systemUi?.show() reader_menu.visibility = View.VISIBLE reader_menu_bottom.visibility = View.VISIBLE @@ -370,13 +378,34 @@ class ReaderActivity : BaseRxActivity(), */ fun setManga(manga: Manga) { val prevViewer = viewer - val newViewer = when (presenter.getMangaViewer()) { + val noDefault = manga.viewer == -1 + val mangaViewer = presenter.getMangaViewer() + val newViewer = when (mangaViewer) { RIGHT_TO_LEFT -> R2LPagerViewer(this) VERTICAL -> VerticalPagerViewer(this) WEBTOON -> WebtoonViewer(this) else -> L2RPagerViewer(this) } + if (noDefault && presenter.manga?.viewer!! > 0) { + snackbar = reader_layout.snack( + getString( + R.string.reading_mode, getString( + when (mangaViewer) { + RIGHT_TO_LEFT -> R.string.right_to_left_viewer + VERTICAL -> R.string.vertical_viewer + WEBTOON -> R.string.webtoon_style + else -> R.string.left_to_right_viewer + } + ).toLowerCase(Locale.getDefault()) + ), 8000 + ) { + setAction(R.string.action_use_default) { + presenter.setMangaViewer(0) + } + } + } + // Destroy previous viewer if there was one if (prevViewer != null) { prevViewer.destroy() 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 7a55057fbf..2708ccb7d5 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 @@ -397,12 +397,7 @@ class ReaderPresenter( fun getMangaViewer(): Int { val manga = manga ?: return preferences.defaultViewer() if (manga.viewer == -1) { - val type = when(manga.mangaType()) { - Manga.TYPE_WEBTOON -> ReaderActivity.WEBTOON - Manga.TYPE_COMIC, Manga.TYPE_MANHUA -> ReaderActivity.LEFT_TO_RIGHT - else -> 0 - } - manga.viewer = type + manga.viewer = manga.defaultReaderType() db.updateMangaViewer(manga).asRxObservable().subscribe() } return if (manga.viewer == 0) preferences.defaultViewer() else manga.viewer diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index b217449724..f8aea5c918 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -65,7 +65,7 @@ Unit)? = null): Snackbar { snack.f() } val theme = Injekt.get().theme() - if (theme == 3 || theme == 6) { + if (theme == 3) { val textView: TextView = snack.view.findViewById(com.google.android.material.R.id.snackbar_text) val button: Button? = diff --git a/app/src/main/res/layout/manga_header_item.xml b/app/src/main/res/layout/manga_header_item.xml index dcac380bb7..54335c9438 100644 --- a/app/src/main/res/layout/manga_header_item.xml +++ b/app/src/main/res/layout/manga_header_item.xml @@ -6,30 +6,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - - - - @@ -56,46 +41,22 @@ - - - - - - + app:layout_constraintTop_toTopOf="parent" /> + app:constraint_referenced_ids="manga_source,cover_card" /> @@ -301,6 +265,8 @@ android:layout_marginTop="8dp" android:layout_marginEnd="16dp" android:visibility="gone" + tools:visibility="visible" + tools:layout_height="100dp" app:atg_backgroundColor="@android:color/transparent" app:atg_borderColor="@color/md_blue_A400" app:atg_borderStrokeWidth="1dp" @@ -314,12 +280,15 @@ + + + + @@ -9,14 +15,4 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 39ae67d696..420fc249a9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -114,6 +114,7 @@ Save Reset Undo + Use Default Create Restore Back @@ -610,6 +611,8 @@ Loading pages… Failed to load pages: %1$s Pull up for more options + Reading %1$s + webtoon style %1$s - Ch.%2$s