Zoom control buttons in reader
This commit is contained in:
@@ -120,6 +120,12 @@ class ReaderViewModel @Inject constructor(
|
||||
valueProducer = { isWebtoonZoomEnable },
|
||||
)
|
||||
|
||||
val isZoomControlEnabled = settings.observeAsStateFlow(
|
||||
scope = viewModelScope + Dispatchers.Default,
|
||||
key = AppSettings.KEY_READER_ZOOM_BUTTONS,
|
||||
valueProducer = { isReaderZoomButtonsEnabled },
|
||||
)
|
||||
|
||||
val readerSettings = ReaderSettings(
|
||||
parentScope = viewModelScope,
|
||||
settings = settings,
|
||||
|
||||
@@ -32,6 +32,9 @@ class ReaderSettings(
|
||||
val isPagesNumbersEnabled: Boolean
|
||||
get() = settings.isPagesNumbersEnabled
|
||||
|
||||
val isZoomControlsEnabled: Boolean
|
||||
get() = settings.isReaderZoomButtonsEnabled
|
||||
|
||||
fun applyBackground(view: View) {
|
||||
val bg = settings.readerBackground
|
||||
view.background = bg.resolve(view.context)
|
||||
@@ -74,6 +77,7 @@ class ReaderSettings(
|
||||
key == AppSettings.KEY_ZOOM_MODE ||
|
||||
key == AppSettings.KEY_PAGES_NUMBERS ||
|
||||
key == AppSettings.KEY_WEBTOON_ZOOM ||
|
||||
key == AppSettings.KEY_READER_ZOOM_BUTTONS ||
|
||||
key == AppSettings.KEY_READER_BACKGROUND
|
||||
) {
|
||||
notifyChanged()
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.koitharu.kotatsu.reader.ui.config.ReaderSettings
|
||||
abstract class BasePageHolder<B : ViewBinding>(
|
||||
protected val binding: B,
|
||||
loader: PageLoader,
|
||||
private val settings: ReaderSettings,
|
||||
protected val settings: ReaderSettings,
|
||||
networkState: NetworkState,
|
||||
exceptionResolver: ExceptionResolver,
|
||||
) : RecyclerView.ViewHolder(binding.root), PageHolderDelegate.Callback {
|
||||
|
||||
@@ -40,6 +40,12 @@ open class PageHolder(
|
||||
@Suppress("LeakingThis")
|
||||
bindingInfo.buttonErrorDetails.setOnClickListener(this)
|
||||
binding.textViewNumber.isVisible = settings.isPagesNumbersEnabled
|
||||
binding.zoomControl.listener = SsivZoomListener(binding.ssiv)
|
||||
}
|
||||
|
||||
override fun onConfigChanged() {
|
||||
super.onConfigChanged()
|
||||
binding.zoomControl.isVisible = settings.isZoomControlsEnabled
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.koitharu.kotatsu.reader.ui.pager.standard
|
||||
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
|
||||
class SsivZoomListener(
|
||||
private val ssiv: SubsamplingScaleImageView,
|
||||
) : ZoomControl.ZoomControlListener {
|
||||
|
||||
override fun onZoomIn() {
|
||||
scaleBy(1.2f)
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
scaleBy(0.8f)
|
||||
}
|
||||
|
||||
private fun scaleBy(factor: Float) {
|
||||
val center = ssiv.getCenter() ?: return
|
||||
val newScale = ssiv.scale * factor
|
||||
ssiv.animateScaleAndCenter(newScale, center)?.apply {
|
||||
withDuration(ssiv.resources.getInteger(android.R.integer.config_shortAnimTime).toLong())
|
||||
withInterpolator(DecelerateInterpolator())
|
||||
start()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.async
|
||||
@@ -45,10 +46,14 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
||||
adapter = readerAdapter
|
||||
addOnPageScrollListener(PageScrollListener())
|
||||
}
|
||||
binding.zoomControl.listener = binding.frame
|
||||
|
||||
viewModel.isWebtoonZoomEnabled.observe(viewLifecycleOwner) {
|
||||
binding.frame.isZoomEnable = it
|
||||
}
|
||||
viewModel.isZoomControlEnabled.observe(viewLifecycleOwner) {
|
||||
binding.zoomControl.isVisible = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.widget.FrameLayout
|
||||
import android.widget.OverScroller
|
||||
import androidx.core.view.GestureDetectorCompat
|
||||
import androidx.core.view.ViewConfigurationCompat
|
||||
import org.koitharu.kotatsu.core.ui.widgets.ZoomControl
|
||||
import org.koitharu.kotatsu.core.util.ext.getAnimationDuration
|
||||
|
||||
private const val MAX_SCALE = 2.5f
|
||||
@@ -27,7 +28,9 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyles: Int = 0,
|
||||
) : FrameLayout(context, attrs, defStyles), ScaleGestureDetector.OnScaleGestureListener {
|
||||
) : FrameLayout(context, attrs, defStyles),
|
||||
ScaleGestureDetector.OnScaleGestureListener,
|
||||
ZoomControl.ZoomControlListener {
|
||||
|
||||
private val targetChild by lazy(LazyThreadSafetyMode.NONE) { getChildAt(0) as WebtoonRecyclerView }
|
||||
|
||||
@@ -110,14 +113,14 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
||||
KeyEvent.KEYCODE_ZOOM_IN,
|
||||
KeyEvent.KEYCODE_NUMPAD_ADD,
|
||||
KeyEvent.KEYCODE_PLUS -> {
|
||||
smoothScaleTo(scale * 1.1f)
|
||||
onZoomIn()
|
||||
true
|
||||
}
|
||||
|
||||
KeyEvent.KEYCODE_ZOOM_OUT,
|
||||
KeyEvent.KEYCODE_NUMPAD_SUBTRACT,
|
||||
KeyEvent.KEYCODE_MINUS -> {
|
||||
smoothScaleTo(scale * 0.9f)
|
||||
onZoomOut()
|
||||
true
|
||||
}
|
||||
|
||||
@@ -151,6 +154,14 @@ class WebtoonScalingFrame @JvmOverloads constructor(
|
||||
halfHeight = h / 2f
|
||||
}
|
||||
|
||||
override fun onZoomIn() {
|
||||
smoothScaleTo(scale * 1.1f)
|
||||
}
|
||||
|
||||
override fun onZoomOut() {
|
||||
smoothScaleTo(scale * 0.9f)
|
||||
}
|
||||
|
||||
private fun invalidateTarget() {
|
||||
adjustBounds()
|
||||
targetChild.run {
|
||||
|
||||
Reference in New Issue
Block a user