mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Using Slider for reader pages now
so we can use the label popup and ticks (I can predict how these are gonna be taken already)
This commit is contained in:
parent
bf64d0f12a
commit
471fddeee4
7 changed files with 110 additions and 79 deletions
|
@ -22,7 +22,6 @@ import android.view.ViewGroup
|
|||
import android.view.WindowManager
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
import android.widget.SeekBar
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.view.GestureDetectorCompat
|
||||
|
@ -36,6 +35,7 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.slider.Slider
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
|
@ -95,7 +95,6 @@ import eu.kanade.tachiyomi.util.view.popupMenu
|
|||
import eu.kanade.tachiyomi.util.view.snack
|
||||
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
|
||||
import eu.kanade.tachiyomi.widget.SimpleAnimationListener
|
||||
import eu.kanade.tachiyomi.widget.SimpleSeekBarListener
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
|
@ -114,6 +113,7 @@ import java.text.DecimalFormat
|
|||
import java.text.DecimalFormatSymbols
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Activity containing the reader of Tachiyomi. This activity is mostly a container of the
|
||||
|
@ -639,7 +639,7 @@ class ReaderActivity :
|
|||
presenter.loadPreviousChapter()
|
||||
}
|
||||
if (result) {
|
||||
binding.readerNav.leftChapter.isVisible = false
|
||||
binding.readerNav.leftChapter.isInvisible = true
|
||||
binding.readerNav.leftProgress.isVisible = true
|
||||
} else {
|
||||
toast(
|
||||
|
@ -662,7 +662,7 @@ class ReaderActivity :
|
|||
presenter.loadPreviousChapter()
|
||||
}
|
||||
if (result) {
|
||||
binding.readerNav.rightChapter.isVisible = false
|
||||
binding.readerNav.rightChapter.isInvisible = true
|
||||
binding.readerNav.rightProgress.isVisible = true
|
||||
} else {
|
||||
toast(
|
||||
|
@ -686,13 +686,21 @@ class ReaderActivity :
|
|||
val readerNavGestureDetector = ReaderNavGestureDetector(this)
|
||||
val gestureDetector = GestureDetectorCompat(this, readerNavGestureDetector)
|
||||
with(binding.readerNav) {
|
||||
binding.readerNav.pageSeekbar.addOnSliderTouchListener(object : Slider.OnSliderTouchListener {
|
||||
override fun onStartTrackingTouch(slider: Slider) {
|
||||
readerNavGestureDetector.lockVertical = false
|
||||
readerNavGestureDetector.hasScrollHorizontal = true
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(slider: Slider) {
|
||||
}
|
||||
})
|
||||
listOf(root, leftChapter, rightChapter, pageSeekbar).forEach {
|
||||
it.setOnTouchListener { _, event ->
|
||||
val result = gestureDetector.onTouchEvent(event)
|
||||
if (event?.action == MotionEvent.ACTION_UP) {
|
||||
if (!result) {
|
||||
val sheetBehavior = binding.chaptersSheet.root.sheetBehavior
|
||||
binding.chaptersSheet.root.dispatchTouchEvent(event)
|
||||
if (sheetBehavior?.state != BottomSheetBehavior.STATE_SETTLING && !sheetBehavior.isCollapsed()) {
|
||||
sheetBehavior?.collapse()
|
||||
}
|
||||
|
@ -706,7 +714,7 @@ class ReaderActivity :
|
|||
return@setOnTouchListener false
|
||||
}
|
||||
if (it == pageSeekbar) {
|
||||
readerNavGestureDetector.lockVertical || (!readerNavGestureDetector.hasScrollHorizontal && event?.action != MotionEvent.ACTION_UP)
|
||||
readerNavGestureDetector.lockVertical
|
||||
} else {
|
||||
result
|
||||
}
|
||||
|
@ -715,15 +723,27 @@ class ReaderActivity :
|
|||
}
|
||||
|
||||
// Init listeners on bottom menu
|
||||
binding.readerNav.pageSeekbar.setOnSeekBarChangeListener(
|
||||
object : SimpleSeekBarListener() {
|
||||
override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) {
|
||||
if (viewer != null && fromUser) {
|
||||
moveToPageIndex(value)
|
||||
binding.readerNav.pageSeekbar.addOnChangeListener { _, value, fromUser ->
|
||||
if (viewer != null && fromUser) {
|
||||
moveToPageIndex(value.roundToInt())
|
||||
}
|
||||
}
|
||||
|
||||
binding.readerNav.pageSeekbar.setLabelFormatter { value ->
|
||||
val pageNumber = (value + 1).roundToInt()
|
||||
(viewer as? PagerViewer)?.let {
|
||||
if (it.config.doublePages || it.config.splitPages) {
|
||||
if (it.hasExtraPage(value.roundToInt(), presenter.getCurrentChapter())) {
|
||||
return@setLabelFormatter if (resources.isLTR) {
|
||||
"$pageNumber-${pageNumber + 1}"
|
||||
} else {
|
||||
"${pageNumber + 1}-$pageNumber"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
pageNumber.toString()
|
||||
}
|
||||
|
||||
// Set initial visibility
|
||||
setMenuVisibility(menuVisible)
|
||||
|
@ -966,9 +986,9 @@ class ReaderActivity :
|
|||
if (doublePages) {
|
||||
// If we're moving from singe to double, we want the current page to be the first page
|
||||
pViewer.config.shiftDoublePage = (
|
||||
binding.readerNav.pageSeekbar.progress +
|
||||
binding.readerNav.pageSeekbar.value.roundToInt() +
|
||||
(
|
||||
currentChapter?.pages?.take(binding.readerNav.pageSeekbar.progress)
|
||||
currentChapter?.pages?.take(binding.readerNav.pageSeekbar.value.roundToInt())
|
||||
?.count { it.fullPage == true || it.isolatedPage } ?: 0
|
||||
)
|
||||
) % 2 != 0
|
||||
|
@ -1102,10 +1122,10 @@ class ReaderActivity :
|
|||
binding.chaptersSheet.chaptersBottomSheet.refreshList()
|
||||
}
|
||||
// Set seekbar progress
|
||||
binding.readerNav.pageSeekbar.max = pages.lastIndex
|
||||
binding.readerNav.pageSeekbar.valueTo = pages.lastIndex.toFloat()
|
||||
val progress = page.index + if (hasExtraPage) 1 else 0
|
||||
// For a double page, show the last 2 pages as if it was the final part of the seekbar
|
||||
binding.readerNav.pageSeekbar.progress = if (progress == pages.lastIndex) progress else page.index
|
||||
binding.readerNav.pageSeekbar.value = (if (progress == pages.lastIndex) progress else page.index).toFloat()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,9 +10,7 @@ class ReaderNavGestureDetector(private val activity: ReaderActivity) : GestureDe
|
|||
.SimpleOnGestureListener() {
|
||||
|
||||
var hasScrollHorizontal = false
|
||||
private set
|
||||
var lockVertical = false
|
||||
private set
|
||||
|
||||
override fun onDown(e: MotionEvent): Boolean {
|
||||
lockVertical = false
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package eu.kanade.tachiyomi.ui.reader
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
class ReaderNavView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||
ConstraintLayout(context, attrs) {
|
||||
override fun canScrollVertically(direction: Int): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun shouldDelayChildPressedState(): Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package eu.kanade.tachiyomi.ui.reader
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.appcompat.widget.AppCompatSeekBar
|
||||
|
||||
/**
|
||||
* Seekbar to show current chapter progress.
|
||||
*/
|
||||
class ReaderSeekBar @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null
|
||||
) : AppCompatSeekBar(context, attrs) {
|
||||
|
||||
/**
|
||||
* Whether the seekbar should draw from right to left.
|
||||
*/
|
||||
var isRTL = false
|
||||
private val boundingBox: Rect = Rect()
|
||||
private val exclusions = listOf(boundingBox)
|
||||
|
||||
/**
|
||||
* Draws the seekbar, translating the canvas if using a right to left reader.
|
||||
*/
|
||||
override fun draw(canvas: Canvas) {
|
||||
if (isRTL) {
|
||||
val px = width / 2f
|
||||
val py = height / 2f
|
||||
|
||||
canvas.scale(-1f, 1f, px, py)
|
||||
}
|
||||
super.draw(canvas)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles touch events, translating coordinates if using a right to left reader.
|
||||
*/
|
||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||
if (isRTL) {
|
||||
event.setLocation(width - event.x, event.y)
|
||||
}
|
||||
return super.onTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
super.onLayout(changed, left, top, right, bottom)
|
||||
if (Build.VERSION.SDK_INT >= 29 && changed) {
|
||||
boundingBox.set(left, top, right, bottom)
|
||||
systemGestureExclusionRects = exclusions
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package eu.kanade.tachiyomi.ui.reader
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.slider.Slider
|
||||
|
||||
/**
|
||||
* Seekbar to show current chapter progress.
|
||||
*/
|
||||
class ReaderSlider @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null
|
||||
) : Slider(context, attrs) {
|
||||
|
||||
/**
|
||||
* Whether the seekbar should draw from right to left.
|
||||
*/
|
||||
var isRTL: Boolean
|
||||
set(value) {
|
||||
layoutDirection = if (value) LAYOUT_DIRECTION_RTL else LAYOUT_DIRECTION_LTR
|
||||
}
|
||||
get() = layoutDirection == LAYOUT_DIRECTION_RTL
|
||||
private val boundingBox: Rect = Rect()
|
||||
private val exclusions = listOf(boundingBox)
|
||||
|
||||
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
||||
super.onLayout(changed, left, top, right, bottom)
|
||||
if (Build.VERSION.SDK_INT >= 29 && changed) {
|
||||
boundingBox.set(left, top, right, bottom)
|
||||
systemGestureExclusionRects = exclusions
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import androidx.viewpager.widget.ViewPager
|
|||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.BaseViewer
|
||||
|
@ -225,6 +226,18 @@ abstract class PagerViewer(val activity: ReaderActivity) : BaseViewer {
|
|||
}
|
||||
}
|
||||
|
||||
private fun getItem(position: Int, currentChapter: ReaderChapter?): Pair<Any, Any?>? {
|
||||
return adapter.joinedItems.firstOrNull {
|
||||
val readerPage = it.first as? ReaderPage ?: return@firstOrNull false
|
||||
readerPage.index == position && readerPage.chapter.chapter.id == currentChapter?.chapter?.id
|
||||
}
|
||||
}
|
||||
|
||||
fun hasExtraPage(position: Int, currentChapter: ReaderChapter?): Boolean {
|
||||
val item = getItem(position, currentChapter) ?: return false
|
||||
return item.second is ReaderPage
|
||||
}
|
||||
|
||||
fun setChaptersDoubleShift(chapters: ViewerChapters) {
|
||||
// Remove Listener since we're about to change the size of the items
|
||||
// If we don't the size change could put us on a new chapter
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<eu.kanade.tachiyomi.ui.reader.ReaderNavView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/reader_nav"
|
||||
|
@ -63,14 +63,19 @@
|
|||
android:textSize="15sp"
|
||||
tools:text="1-2" />
|
||||
|
||||
<eu.kanade.tachiyomi.ui.reader.ReaderSeekBar
|
||||
<eu.kanade.tachiyomi.ui.reader.ReaderSlider
|
||||
android:id="@+id/page_seekbar"
|
||||
style="@style/Theme.Widget.Slider"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="1"
|
||||
android:progressBackgroundTint="@color/tint_color_secondary"
|
||||
android:maxHeight="?attr/actionBarSize"
|
||||
android:minHeight="?attr/actionBarSize" />
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:progressBackgroundTint="@color/tint_color_secondary"
|
||||
android:stepSize="1"
|
||||
tools:value="4"
|
||||
tools:valueTo="10"
|
||||
tools:ignore="SpeakableTextPresentCheck" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/right_page_text"
|
||||
|
@ -111,4 +116,4 @@
|
|||
android:layout_height="40dp"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.kanade.tachiyomi.ui.reader.ReaderNavView>
|
Loading…
Add table
Add a link
Reference in a new issue