From 214a4d2e5a672f0d35a085381557df47d3a0a063 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Wed, 31 Mar 2021 16:31:07 -0400 Subject: [PATCH] Removing progress dialog in reader still needs some adjustments --- .../ui/extension/ExtensionBottomSheet.kt | 2 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 56 +++++++++++++------ .../tachiyomi/ui/reader/ReaderPresenter.kt | 31 +++------- .../ui/reader/chapter/ReaderChapterItem.kt | 35 +++++------- .../ui/reader/chapter/ReaderChapterSheet.kt | 27 +++++++-- .../main/res/layout/reader_chapter_item.xml | 21 +++++-- app/src/main/res/layout/reader_nav.xml | 28 ++++++++-- 7 files changed, 124 insertions(+), 76 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt index 89c5372326..444eefa2fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt @@ -65,7 +65,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At lateinit var controller: BrowseController var boundViews = arrayListOf() - val extensionFrameLayout: RecyclerWithScrollerView? + val extensionFrameLayout: RecyclerWithScrollerView? get() = binding.pager.findViewWithTag("TabbedRecycler0") as? RecyclerWithScrollerView val migrationFrameLayout: RecyclerWithScrollerView? get() = binding.pager.findViewWithTag("TabbedRecycler1") as? RecyclerWithScrollerView 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 259a38972e..795deb5f66 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 @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.ui.reader import android.annotation.SuppressLint -import android.app.ProgressDialog import android.content.ClipData import android.content.Context import android.content.Intent @@ -58,6 +57,7 @@ import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.hasSideNavBar import eu.kanade.tachiyomi.util.system.isBottomTappable +import eu.kanade.tachiyomi.util.system.launchIO import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toast @@ -154,16 +154,12 @@ class ReaderActivity : var lightStatusBar = false - /** - * Progress dialog used when switching chapters from the menu buttons. - */ - @Suppress("DEPRECATION") - private var progressDialog: ProgressDialog? = null - private var snackbar: Snackbar? = null var intentPageNumber: Int? = null + var isLoading = false + companion object { @Suppress("unused") const val LEFT_TO_RIGHT = 1 @@ -245,8 +241,6 @@ class ReaderActivity : config = null bottomSheet?.dismiss() bottomSheet = null - progressDialog?.dismiss() - progressDialog = null snackbar?.dismiss() snackbar = null } @@ -365,19 +359,33 @@ class ReaderActivity : } binding.readerNav.leftChapter.setOnClickListener { - if (viewer is R2LPagerViewer) { + if (isLoading) { + return@setOnClickListener + } + val result = if (viewer is R2LPagerViewer) { presenter.loadNextChapter() } else { presenter.loadPreviousChapter() } + if (result) { + binding.readerNav.leftChapter.gone() + binding.readerNav.leftProgress.visible() + } } binding.readerNav.rightChapter.setOnClickListener { - if (viewer !is R2LPagerViewer) { + if (isLoading) { + return@setOnClickListener + } + val result = if (viewer !is R2LPagerViewer) { presenter.loadNextChapter() } else { presenter.loadPreviousChapter() } + if (result) { + binding.readerNav.rightChapter.gone() + binding.readerNav.rightProgress.visible() + } } val readerNavGestureDetector = ReaderNavGestureDetector(this) @@ -607,6 +615,13 @@ class ReaderActivity : intentPageNumber?.let { moveToPageIndex(it) } intentPageNumber = null binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name + if (viewer is R2LPagerViewer) { + binding.readerNav.leftChapter.alpha = if (viewerChapters.nextChapter != null) 1f else 0.5f + binding.readerNav.rightChapter.alpha = if (viewerChapters.prevChapter != null) 1f else 0.5f + } else { + binding.readerNav.rightChapter.alpha = if (viewerChapters.nextChapter != null) 1f else 0.5f + binding.readerNav.leftChapter.alpha = if (viewerChapters.prevChapter != null) 1f else 0.5f + } } /** @@ -625,13 +640,22 @@ class ReaderActivity : * [show]. This is only used when the next/previous buttons on the binding.toolbar are clicked; the * other cases are handled with chapter transitions on the viewers and chapter preloading. */ - @Suppress("DEPRECATION") fun setProgressDialog(show: Boolean) { - progressDialog?.dismiss() - progressDialog = if (show) { - ProgressDialog.show(this, null, getString(R.string.loading), true) + if (!show) { + binding.readerNav.leftChapter.visible() + binding.readerNav.rightChapter.visible() + + binding.readerNav.leftProgress.gone() + binding.readerNav.rightProgress.gone() + binding.chaptersSheet.root.resetChapter() + } + if (show) { + isLoading = show } else { - null + scope.launchIO { + delay(100) + isLoading = show + } } } 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 a5b29abdb5..9d9697d8dc 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 @@ -438,34 +438,19 @@ class ReaderPresenter( /** * Called from the activity to load and set the next chapter as active. */ - fun loadNextChapter() { - val nextChapter = viewerChaptersRelay.value?.nextChapter ?: return - loadAdjacent(nextChapter) + fun loadNextChapter(): Boolean { + val nextChapter = viewerChaptersRelay.value?.nextChapter ?: return false + loadChapter(nextChapter.chapter) + return true } /** * Called from the activity to load and set the previous chapter as active. */ - fun loadPreviousChapter() { - val prevChapter = viewerChaptersRelay.value?.prevChapter ?: return - loadAdjacent(prevChapter) - } - - private fun loadAdjacent(chapter: ReaderChapter) { - val loader = loader ?: return - - activeChapterSubscription?.unsubscribe() - activeChapterSubscription = getLoadObservable(loader, chapter) - .doOnSubscribe { isLoadingAdjacentChapterRelay.call(true) } - .doOnUnsubscribe { isLoadingAdjacentChapterRelay.call(false) } - .subscribeFirst( - { view, _ -> - view.moveToPageIndex(0) - }, - { _, _ -> - // Ignore onError event, viewers handle that state - } - ) + fun loadPreviousChapter(): Boolean { + val prevChapter = viewerChaptersRelay.value?.prevChapter ?: return false + loadChapter(prevChapter.chapter) + return true } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt index 32ab9e4ca5..c16e9d7465 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterItem.kt @@ -2,15 +2,13 @@ package eu.kanade.tachiyomi.ui.reader.chapter import android.graphics.Typeface import android.view.View -import android.widget.FrameLayout -import android.widget.ImageView -import android.widget.TextView import androidx.core.graphics.drawable.DrawableCompat import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.items.AbstractItem import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.databinding.ReaderChapterItemBinding import eu.kanade.tachiyomi.util.chapter.ChapterUtil import java.text.DecimalFormat import java.text.DecimalFormatSymbols @@ -35,17 +33,14 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B } class ViewHolder(view: View) : FastAdapter.ViewHolder(view) { - private var chapterTitle: TextView = view.findViewById(R.id.chapter_title) - private var chapterSubtitle: TextView = view.findViewById(R.id.chapter_scanlator) - var bookmarkButton: FrameLayout = view.findViewById(R.id.bookmark_layout) - private var bookmarkImage: ImageView = view.findViewById(R.id.bookmark_image) + val binding = ReaderChapterItemBinding.bind(view) override fun bindView(item: ReaderChapterItem, payloads: List) { val manga = item.manga val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter) - chapterTitle.text = when (manga.displayMode) { + binding.chapterTitle.text = when (manga.displayMode) { Manga.DISPLAY_NUMBER -> { val number = item.decimalFormat.format(item.chapter_number.toDouble()) itemView.context.getString(R.string.chapter_, number) @@ -55,35 +50,35 @@ class ReaderChapterItem(val chapter: Chapter, val manga: Manga, val isCurrent: B val statuses = mutableListOf() ChapterUtil.relativeDate(item)?.let { statuses.add(it) } - item.scanlator?.isNotBlank()?.let { statuses.add(item.scanlator!!) } + item.scanlator?.isNotBlank()?.let { statuses.add(item.scanlator ?: "") } if (item.isCurrent) { - chapterTitle.setTypeface(null, Typeface.BOLD_ITALIC) - chapterSubtitle.setTypeface(null, Typeface.BOLD_ITALIC) + binding.chapterTitle.setTypeface(null, Typeface.BOLD_ITALIC) + binding.chapterSubtitle.setTypeface(null, Typeface.BOLD_ITALIC) } else { - chapterTitle.setTypeface(null, Typeface.NORMAL) - chapterSubtitle.setTypeface(null, Typeface.NORMAL) + binding.chapterTitle.setTypeface(null, Typeface.NORMAL) + binding.chapterSubtitle.setTypeface(null, Typeface.NORMAL) } // match color of the chapter title - chapterTitle.setTextColor(chapterColor) - chapterSubtitle.setTextColor(chapterColor) + binding.chapterTitle.setTextColor(chapterColor) + binding.chapterSubtitle.setTextColor(chapterColor) - bookmarkImage.setImageResource( + binding.bookmarkImage.setImageResource( if (item.bookmark) R.drawable.ic_bookmark_24dp else R.drawable.ic_bookmark_border_24dp ) val drawableColor = ChapterUtil.bookmarkColor(itemView.context, item) - DrawableCompat.setTint(bookmarkImage.drawable, drawableColor) + DrawableCompat.setTint(binding.bookmarkImage.drawable, drawableColor) - chapterSubtitle.text = statuses.joinToString(" • ") + binding.chapterSubtitle.text = statuses.joinToString(" • ") } override fun unbindView(item: ReaderChapterItem) { - chapterTitle.text = null - chapterSubtitle.text = null + binding.chapterTitle.text = null + binding.chapterSubtitle.text = null } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt index 90c2eadcf2..8a03812cb4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/chapter/ReaderChapterSheet.kt @@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.invisible import eu.kanade.tachiyomi.util.view.isCollapsed import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.visible @@ -43,6 +44,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr var shouldCollapse = true var selectedChapterId = -1L + var loadingPos = 0 lateinit var binding: ReaderChaptersSheetBinding override fun onFinishInflate() { @@ -126,13 +128,20 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr adapter = FastAdapter.with(itemAdapter) binding.chapterRecycler.adapter = adapter - adapter?.onClickListener = { _, _, item, _ -> - if (!sheetBehavior.isExpanded()) { + adapter?.onClickListener = { _, _, item, position -> + if (!sheetBehavior.isExpanded() || activity.isLoading) { false } else { if (item.chapter.id != presenter.getCurrentChapter()?.chapter?.id) { + activity.binding.readerNav.leftChapter.invisible() + activity.binding.readerNav.rightChapter.invisible() + shouldCollapse = false presenter.loadChapter(item.chapter) + loadingPos = position + val itemView = (binding.chapterRecycler.findViewHolderForAdapterPosition(position) as? ReaderChapterItem.ViewHolder)?.binding + itemView?.bookmarkImage?.gone() + itemView?.progress?.visible() } true } @@ -141,7 +150,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr object : ClickEventHook() { override fun onBind(viewHolder: RecyclerView.ViewHolder): View? { return if (viewHolder is ReaderChapterItem.ViewHolder) { - viewHolder.bookmarkButton + viewHolder.binding.bookmarkButton } else { null } @@ -153,8 +162,10 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr fastAdapter: FastAdapter, item: ReaderChapterItem ) { - presenter.toggleBookmark(item.chapter) - refreshList() + if (!activity.isLoading) { + presenter.toggleBookmark(item.chapter) + refreshList() + } } } ) @@ -168,6 +179,12 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr refreshList() } + fun resetChapter() { + val itemView = (binding.chapterRecycler.findViewHolderForAdapterPosition(loadingPos) as? ReaderChapterItem.ViewHolder)?.binding + itemView?.bookmarkImage?.visible() + itemView?.progress?.gone() + } + fun refreshList() { launchUI { val chapters = presenter.getChapters() diff --git a/app/src/main/res/layout/reader_chapter_item.xml b/app/src/main/res/layout/reader_chapter_item.xml index 8956dfd6e0..f648779ce3 100644 --- a/app/src/main/res/layout/reader_chapter_item.xml +++ b/app/src/main/res/layout/reader_chapter_item.xml @@ -19,14 +19,14 @@ android:layout_marginTop="12dp" android:ellipsize="end" android:maxLines="1" - app:layout_constraintBottom_toTopOf="@id/chapter_scanlator" - app:layout_constraintEnd_toStartOf="@id/bookmark_layout" + app:layout_constraintBottom_toTopOf="@id/chapter_subtitle" + app:layout_constraintEnd_toStartOf="@id/bookmark_button" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="Chapter 123 - The Real One" /> + app:tint="?android:attr/textColorHint" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/reader_nav.xml b/app/src/main/res/layout/reader_nav.xml index 63259a1ff9..da0adae427 100644 --- a/app/src/main/res/layout/reader_nav.xml +++ b/app/src/main/res/layout/reader_nav.xml @@ -16,12 +16,22 @@ android:gravity="center" android:orientation="horizontal"> + + + android:layout_height="match_parent"> + + \ No newline at end of file