mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Removing progress dialog in reader
still needs some adjustments
This commit is contained in:
parent
241280ed02
commit
214a4d2e5a
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<ReaderChapterItem>(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<Any>) {
|
||||
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<String>()
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ReaderChapterItem>() {
|
||||
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<ReaderChapterItem>,
|
||||
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()
|
||||
|
@ -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" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chapter_scanlator"
|
||||
android:id="@+id/chapter_subtitle"
|
||||
style="@style/TextAppearance.MaterialComponents.Caption"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
@ -35,13 +35,13 @@
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
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_constraintTop_toBottomOf="@+id/chapter_title"
|
||||
tools:text="3 days ago • On page 45 • Scanlator" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/bookmark_layout"
|
||||
android:id="@+id/bookmark_button"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
@ -59,6 +59,15 @@
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="center"
|
||||
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>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -16,12 +16,22 @@
|
||||
android:gravity="center"
|
||||
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
|
||||
android:id="@+id/left_chapter"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="60dp"
|
||||
android:layout_marginStart="56dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:contentDescription="@string/previous_chapter"
|
||||
@ -32,9 +42,7 @@
|
||||
<LinearLayout
|
||||
android:id="@+id/reader_seekbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/left_page_text"
|
||||
@ -70,11 +78,21 @@
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="60dp"
|
||||
android:layout_marginEnd="56dp"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/next_chapter"
|
||||
android:padding="@dimen/material_layout_keylines_screen_edge_margin"
|
||||
app:tint="@color/textColorPrimary"
|
||||
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>
|
Loading…
Reference in New Issue
Block a user