Cubic reader scroll speed
This commit is contained in:
@@ -48,8 +48,8 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
if (!catchingWebViewUnavailability {
|
if (!catchingWebViewUnavailability {
|
||||||
setContentView(
|
setContentView(
|
||||||
ActivityBrowserBinding.inflate(
|
ActivityBrowserBinding.inflate(
|
||||||
layoutInflater
|
layoutInflater,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}) {
|
}) {
|
||||||
return
|
return
|
||||||
@@ -82,9 +82,11 @@ class CloudFlareActivity : BaseActivity<ActivityBrowserBinding>(), CloudFlareCal
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
viewBinding.webView.run {
|
runCatching {
|
||||||
stopLoading()
|
viewBinding.webView
|
||||||
destroy()
|
}.onSuccess {
|
||||||
|
it.stopLoading()
|
||||||
|
it.destroy()
|
||||||
}
|
}
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package org.koitharu.kotatsu.core.ui.widgets
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.ArrayMap
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.google.android.material.slider.Slider
|
||||||
|
import kotlin.math.cbrt
|
||||||
|
import kotlin.math.pow
|
||||||
|
|
||||||
|
class CubicSlider @JvmOverloads constructor(
|
||||||
|
context: Context,
|
||||||
|
attrs: AttributeSet? = null,
|
||||||
|
) : Slider(context, attrs) {
|
||||||
|
|
||||||
|
private val changeListeners = ArrayMap<OnChangeListener, OnChangeListenerMapper>(1)
|
||||||
|
|
||||||
|
override fun setValue(value: Float) {
|
||||||
|
super.setValue(value.unmap())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getValue(): Float {
|
||||||
|
return super.getValue().map()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getValueFrom(): Float {
|
||||||
|
return super.getValueFrom().map()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValueFrom(valueFrom: Float) {
|
||||||
|
super.setValueFrom(valueFrom.unmap())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getValueTo(): Float {
|
||||||
|
return super.getValueTo().map()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValueTo(valueTo: Float) {
|
||||||
|
super.setValueTo(valueTo.unmap())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addOnChangeListener(listener: OnChangeListener) {
|
||||||
|
val mapper = OnChangeListenerMapper(listener)
|
||||||
|
super.addOnChangeListener(mapper)
|
||||||
|
changeListeners[listener] = mapper
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun removeOnChangeListener(listener: OnChangeListener) {
|
||||||
|
changeListeners.remove(listener)?.let {
|
||||||
|
super.removeOnChangeListener(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun clearOnChangeListeners() {
|
||||||
|
super.clearOnChangeListeners()
|
||||||
|
changeListeners.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Float.map(): Float {
|
||||||
|
return this.pow(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Float.unmap(): Float {
|
||||||
|
return cbrt(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private inner class OnChangeListenerMapper(
|
||||||
|
private val delegate: OnChangeListener,
|
||||||
|
) : OnChangeListener {
|
||||||
|
|
||||||
|
override fun onValueChange(slider: Slider, value: Float, fromUser: Boolean) {
|
||||||
|
delegate.onValueChange(slider, value.map(), fromUser)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -128,7 +128,7 @@ class ReaderConfigSheet :
|
|||||||
when (buttonView.id) {
|
when (buttonView.id) {
|
||||||
R.id.switch_scroll_timer -> {
|
R.id.switch_scroll_timer -> {
|
||||||
findCallback()?.isAutoScrollEnabled = isChecked
|
findCallback()?.isAutoScrollEnabled = isChecked
|
||||||
requireViewBinding().labelTimer.isVisible = isChecked
|
requireViewBinding().layoutTimer.isVisible = isChecked
|
||||||
requireViewBinding().sliderTimer.isVisible = isChecked
|
requireViewBinding().sliderTimer.isVisible = isChecked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,6 +159,7 @@ class ReaderConfigSheet :
|
|||||||
if (fromUser) {
|
if (fromUser) {
|
||||||
settings.readerAutoscrollSpeed = value
|
settings.readerAutoscrollSpeed = value
|
||||||
}
|
}
|
||||||
|
(viewBinding ?: return).labelTimerValue.text = getString(R.string.speed_value, value * 10f)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityResult(result: Uri?) {
|
override fun onActivityResult(result: Uri?) {
|
||||||
|
|||||||
@@ -119,18 +119,35 @@
|
|||||||
android:textColor="?colorOnSurfaceVariant"
|
android:textColor="?colorOnSurfaceVariant"
|
||||||
app:drawableStartCompat="@drawable/ic_timer" />
|
app:drawableStartCompat="@drawable/ic_timer" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/label_timer"
|
android:id="@+id/layout_timer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="@dimen/margin_normal"
|
android:layout_marginHorizontal="@dimen/margin_normal"
|
||||||
android:layout_marginTop="@dimen/margin_small"
|
android:layout_marginTop="@dimen/margin_normal"
|
||||||
android:text="@string/speed"
|
android:textAppearance="?textAppearanceTitleSmall"
|
||||||
android:textAppearance="?attr/textAppearanceBodySmall"
|
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible">
|
||||||
|
|
||||||
<com.google.android.material.slider.Slider
|
<TextView
|
||||||
|
android:id="@+id/label_timer"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/speed"
|
||||||
|
android:textAppearance="?attr/textAppearanceTitleSmall" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/label_timer_value"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="@dimen/margin_small"
|
||||||
|
android:textAppearance="?attr/textAppearanceBodySmall"
|
||||||
|
tools:text="x0.5" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<org.koitharu.kotatsu.core.ui.widgets.CubicSlider
|
||||||
android:id="@+id/slider_timer"
|
android:id="@+id/slider_timer"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -510,4 +510,5 @@
|
|||||||
<string name="periodic_backups_enable">Enable periodic backups</string>
|
<string name="periodic_backups_enable">Enable periodic backups</string>
|
||||||
<string name="backups_output_directory">Backups output directory</string>
|
<string name="backups_output_directory">Backups output directory</string>
|
||||||
<string name="last_successful_backup">Last successful backup: %s</string>
|
<string name="last_successful_backup">Last successful backup: %s</string>
|
||||||
|
<string name="speed_value">x%.1f</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user