Removing progress dialog in reader

still needs some adjustments
This commit is contained in:
Jays2Kings 2021-03-31 16:31:07 -04:00
parent 241280ed02
commit 214a4d2e5a
7 changed files with 124 additions and 76 deletions

View File

@ -65,7 +65,7 @@ class ExtensionBottomSheet @JvmOverloads constructor(context: Context, attrs: At
lateinit var controller: BrowseController lateinit var controller: BrowseController
var boundViews = arrayListOf<RecyclerWithScrollerView>() var boundViews = arrayListOf<RecyclerWithScrollerView>()
val extensionFrameLayout: RecyclerWithScrollerView? val extensionFrameLayout: RecyclerWithScrollerView?
get() = binding.pager.findViewWithTag("TabbedRecycler0") as? RecyclerWithScrollerView get() = binding.pager.findViewWithTag("TabbedRecycler0") as? RecyclerWithScrollerView
val migrationFrameLayout: RecyclerWithScrollerView? val migrationFrameLayout: RecyclerWithScrollerView?
get() = binding.pager.findViewWithTag("TabbedRecycler1") as? RecyclerWithScrollerView get() = binding.pager.findViewWithTag("TabbedRecycler1") as? RecyclerWithScrollerView

View File

@ -1,7 +1,6 @@
package eu.kanade.tachiyomi.ui.reader package eu.kanade.tachiyomi.ui.reader
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.ProgressDialog
import android.content.ClipData import android.content.ClipData
import android.content.Context import android.content.Context
import android.content.Intent 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.getResourceColor
import eu.kanade.tachiyomi.util.system.hasSideNavBar import eu.kanade.tachiyomi.util.system.hasSideNavBar
import eu.kanade.tachiyomi.util.system.isBottomTappable 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.launchUI
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
@ -154,16 +154,12 @@ class ReaderActivity :
var lightStatusBar = false 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 private var snackbar: Snackbar? = null
var intentPageNumber: Int? = null var intentPageNumber: Int? = null
var isLoading = false
companion object { companion object {
@Suppress("unused") @Suppress("unused")
const val LEFT_TO_RIGHT = 1 const val LEFT_TO_RIGHT = 1
@ -245,8 +241,6 @@ class ReaderActivity :
config = null config = null
bottomSheet?.dismiss() bottomSheet?.dismiss()
bottomSheet = null bottomSheet = null
progressDialog?.dismiss()
progressDialog = null
snackbar?.dismiss() snackbar?.dismiss()
snackbar = null snackbar = null
} }
@ -365,19 +359,33 @@ class ReaderActivity :
} }
binding.readerNav.leftChapter.setOnClickListener { binding.readerNav.leftChapter.setOnClickListener {
if (viewer is R2LPagerViewer) { if (isLoading) {
return@setOnClickListener
}
val result = if (viewer is R2LPagerViewer) {
presenter.loadNextChapter() presenter.loadNextChapter()
} else { } else {
presenter.loadPreviousChapter() presenter.loadPreviousChapter()
} }
if (result) {
binding.readerNav.leftChapter.gone()
binding.readerNav.leftProgress.visible()
}
} }
binding.readerNav.rightChapter.setOnClickListener { binding.readerNav.rightChapter.setOnClickListener {
if (viewer !is R2LPagerViewer) { if (isLoading) {
return@setOnClickListener
}
val result = if (viewer !is R2LPagerViewer) {
presenter.loadNextChapter() presenter.loadNextChapter()
} else { } else {
presenter.loadPreviousChapter() presenter.loadPreviousChapter()
} }
if (result) {
binding.readerNav.rightChapter.gone()
binding.readerNav.rightProgress.visible()
}
} }
val readerNavGestureDetector = ReaderNavGestureDetector(this) val readerNavGestureDetector = ReaderNavGestureDetector(this)
@ -607,6 +615,13 @@ class ReaderActivity :
intentPageNumber?.let { moveToPageIndex(it) } intentPageNumber?.let { moveToPageIndex(it) }
intentPageNumber = null intentPageNumber = null
binding.toolbar.subtitle = viewerChapters.currChapter.chapter.name 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 * [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. * other cases are handled with chapter transitions on the viewers and chapter preloading.
*/ */
@Suppress("DEPRECATION")
fun setProgressDialog(show: Boolean) { fun setProgressDialog(show: Boolean) {
progressDialog?.dismiss() if (!show) {
progressDialog = if (show) { binding.readerNav.leftChapter.visible()
ProgressDialog.show(this, null, getString(R.string.loading), true) binding.readerNav.rightChapter.visible()
binding.readerNav.leftProgress.gone()
binding.readerNav.rightProgress.gone()
binding.chaptersSheet.root.resetChapter()
}
if (show) {
isLoading = show
} else { } else {
null scope.launchIO {
delay(100)
isLoading = show
}
} }
} }

View File

@ -438,34 +438,19 @@ class ReaderPresenter(
/** /**
* Called from the activity to load and set the next chapter as active. * Called from the activity to load and set the next chapter as active.
*/ */
fun loadNextChapter() { fun loadNextChapter(): Boolean {
val nextChapter = viewerChaptersRelay.value?.nextChapter ?: return val nextChapter = viewerChaptersRelay.value?.nextChapter ?: return false
loadAdjacent(nextChapter) loadChapter(nextChapter.chapter)
return true
} }
/** /**
* Called from the activity to load and set the previous chapter as active. * Called from the activity to load and set the previous chapter as active.
*/ */
fun loadPreviousChapter() { fun loadPreviousChapter(): Boolean {
val prevChapter = viewerChaptersRelay.value?.prevChapter ?: return val prevChapter = viewerChaptersRelay.value?.prevChapter ?: return false
loadAdjacent(prevChapter) loadChapter(prevChapter.chapter)
} return true
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
}
)
} }
/** /**

View File

@ -2,15 +2,13 @@ package eu.kanade.tachiyomi.ui.reader.chapter
import android.graphics.Typeface import android.graphics.Typeface
import android.view.View import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.FastAdapter
import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.fastadapter.items.AbstractItem
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.databinding.ReaderChapterItemBinding
import eu.kanade.tachiyomi.util.chapter.ChapterUtil import eu.kanade.tachiyomi.util.chapter.ChapterUtil
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.DecimalFormatSymbols 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<ReaderChapterItem>(view) { class ViewHolder(view: View) : FastAdapter.ViewHolder<ReaderChapterItem>(view) {
private var chapterTitle: TextView = view.findViewById(R.id.chapter_title) val binding = ReaderChapterItemBinding.bind(view)
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)
override fun bindView(item: ReaderChapterItem, payloads: List<Any>) { override fun bindView(item: ReaderChapterItem, payloads: List<Any>) {
val manga = item.manga val manga = item.manga
val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter) val chapterColor = ChapterUtil.chapterColor(itemView.context, item.chapter)
chapterTitle.text = when (manga.displayMode) { binding.chapterTitle.text = when (manga.displayMode) {
Manga.DISPLAY_NUMBER -> { Manga.DISPLAY_NUMBER -> {
val number = item.decimalFormat.format(item.chapter_number.toDouble()) val number = item.decimalFormat.format(item.chapter_number.toDouble())
itemView.context.getString(R.string.chapter_, number) 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<String>() val statuses = mutableListOf<String>()
ChapterUtil.relativeDate(item)?.let { statuses.add(it) } 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) { if (item.isCurrent) {
chapterTitle.setTypeface(null, Typeface.BOLD_ITALIC) binding.chapterTitle.setTypeface(null, Typeface.BOLD_ITALIC)
chapterSubtitle.setTypeface(null, Typeface.BOLD_ITALIC) binding.chapterSubtitle.setTypeface(null, Typeface.BOLD_ITALIC)
} else { } else {
chapterTitle.setTypeface(null, Typeface.NORMAL) binding.chapterTitle.setTypeface(null, Typeface.NORMAL)
chapterSubtitle.setTypeface(null, Typeface.NORMAL) binding.chapterSubtitle.setTypeface(null, Typeface.NORMAL)
} }
// match color of the chapter title // match color of the chapter title
chapterTitle.setTextColor(chapterColor) binding.chapterTitle.setTextColor(chapterColor)
chapterSubtitle.setTextColor(chapterColor) binding.chapterSubtitle.setTextColor(chapterColor)
bookmarkImage.setImageResource( binding.bookmarkImage.setImageResource(
if (item.bookmark) R.drawable.ic_bookmark_24dp if (item.bookmark) R.drawable.ic_bookmark_24dp
else R.drawable.ic_bookmark_border_24dp else R.drawable.ic_bookmark_border_24dp
) )
val drawableColor = ChapterUtil.bookmarkColor(itemView.context, item) 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) { override fun unbindView(item: ReaderChapterItem) {
chapterTitle.text = null binding.chapterTitle.text = null
chapterSubtitle.text = null binding.chapterSubtitle.text = null
} }
} }
} }

View File

@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.collapse
import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.expand
import eu.kanade.tachiyomi.util.view.gone 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.isCollapsed
import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.isExpanded
import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.util.view.visible
@ -43,6 +44,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
var shouldCollapse = true var shouldCollapse = true
var selectedChapterId = -1L var selectedChapterId = -1L
var loadingPos = 0
lateinit var binding: ReaderChaptersSheetBinding lateinit var binding: ReaderChaptersSheetBinding
override fun onFinishInflate() { override fun onFinishInflate() {
@ -126,13 +128,20 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
adapter = FastAdapter.with(itemAdapter) adapter = FastAdapter.with(itemAdapter)
binding.chapterRecycler.adapter = adapter binding.chapterRecycler.adapter = adapter
adapter?.onClickListener = { _, _, item, _ -> adapter?.onClickListener = { _, _, item, position ->
if (!sheetBehavior.isExpanded()) { if (!sheetBehavior.isExpanded() || activity.isLoading) {
false false
} else { } else {
if (item.chapter.id != presenter.getCurrentChapter()?.chapter?.id) { if (item.chapter.id != presenter.getCurrentChapter()?.chapter?.id) {
activity.binding.readerNav.leftChapter.invisible()
activity.binding.readerNav.rightChapter.invisible()
shouldCollapse = false shouldCollapse = false
presenter.loadChapter(item.chapter) presenter.loadChapter(item.chapter)
loadingPos = position
val itemView = (binding.chapterRecycler.findViewHolderForAdapterPosition(position) as? ReaderChapterItem.ViewHolder)?.binding
itemView?.bookmarkImage?.gone()
itemView?.progress?.visible()
} }
true true
} }
@ -141,7 +150,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
object : ClickEventHook<ReaderChapterItem>() { object : ClickEventHook<ReaderChapterItem>() {
override fun onBind(viewHolder: RecyclerView.ViewHolder): View? { override fun onBind(viewHolder: RecyclerView.ViewHolder): View? {
return if (viewHolder is ReaderChapterItem.ViewHolder) { return if (viewHolder is ReaderChapterItem.ViewHolder) {
viewHolder.bookmarkButton viewHolder.binding.bookmarkButton
} else { } else {
null null
} }
@ -153,8 +162,10 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
fastAdapter: FastAdapter<ReaderChapterItem>, fastAdapter: FastAdapter<ReaderChapterItem>,
item: ReaderChapterItem item: ReaderChapterItem
) { ) {
presenter.toggleBookmark(item.chapter) if (!activity.isLoading) {
refreshList() presenter.toggleBookmark(item.chapter)
refreshList()
}
} }
} }
) )
@ -168,6 +179,12 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr
refreshList() refreshList()
} }
fun resetChapter() {
val itemView = (binding.chapterRecycler.findViewHolderForAdapterPosition(loadingPos) as? ReaderChapterItem.ViewHolder)?.binding
itemView?.bookmarkImage?.visible()
itemView?.progress?.gone()
}
fun refreshList() { fun refreshList() {
launchUI { launchUI {
val chapters = presenter.getChapters() val chapters = presenter.getChapters()

View File

@ -19,14 +19,14 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
app:layout_constraintBottom_toTopOf="@id/chapter_scanlator" app:layout_constraintBottom_toTopOf="@id/chapter_subtitle"
app:layout_constraintEnd_toStartOf="@id/bookmark_layout" app:layout_constraintEnd_toStartOf="@id/bookmark_button"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="Chapter 123 - The Real One" /> tools:text="Chapter 123 - The Real One" />
<TextView <TextView
android:id="@+id/chapter_scanlator" android:id="@+id/chapter_subtitle"
style="@style/TextAppearance.MaterialComponents.Caption" style="@style/TextAppearance.MaterialComponents.Caption"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -35,13 +35,13 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/bookmark_layout" app:layout_constraintEnd_toStartOf="@id/bookmark_button"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chapter_title" app:layout_constraintTop_toBottomOf="@+id/chapter_title"
tools:text="3 days ago • On page 45 • Scanlator" /> tools:text="3 days ago • On page 45 • Scanlator" />
<FrameLayout <FrameLayout
android:id="@+id/bookmark_layout" android:id="@+id/bookmark_button"
android:layout_width="50dp" android:layout_width="50dp"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
@ -59,6 +59,15 @@
android:layout_height="30dp" android:layout_height="30dp"
android:layout_gravity="center" android:layout_gravity="center"
android:src="@drawable/ic_bookmark_border_24dp" android:src="@drawable/ic_bookmark_border_24dp"
android:tint="?android:attr/textColorHint" /> app:tint="?android:attr/textColorHint" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:visibility="gone"
tools:visibility="visible"/>
</FrameLayout> </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -16,12 +16,22 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<ProgressBar
android:id="@+id/left_progress"
style="?android:attr/progressBarStyleSmall"
android:visibility="gone"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:layout_gravity="center"
android:layout_marginStart="56dp" />
<ImageButton <ImageButton
android:id="@+id/left_chapter" android:id="@+id/left_chapter"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginStart="60dp" android:layout_marginStart="56dp"
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:contentDescription="@string/previous_chapter" android:contentDescription="@string/previous_chapter"
@ -32,9 +42,7 @@
<LinearLayout <LinearLayout
android:id="@+id/reader_seekbar" android:id="@+id/reader_seekbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:paddingStart="10dp"
android:paddingEnd="10dp">
<TextView <TextView
android:id="@+id/left_page_text" android:id="@+id/left_page_text"
@ -70,11 +78,21 @@
android:layout_height="40dp" android:layout_height="40dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="60dp" android:layout_marginEnd="56dp"
android:background="?selectableItemBackgroundBorderless" android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/next_chapter" android:contentDescription="@string/next_chapter"
android:padding="@dimen/material_layout_keylines_screen_edge_margin" android:padding="@dimen/material_layout_keylines_screen_edge_margin"
app:tint="@color/textColorPrimary" app:tint="@color/textColorPrimary"
app:srcCompat="@drawable/ic_skip_next_24" /> app:srcCompat="@drawable/ic_skip_next_24" />
<ProgressBar
android:id="@+id/right_progress"
style="?android:attr/progressBarStyleSmall"
android:visibility="gone"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginEnd="56dp" />
</LinearLayout> </LinearLayout>