Smooth Automatic Scrolling for Webtoon (#777)

(cherry picked from commit 82f0e5bc01e93baa1cd81f9c898d15d51e3faa1b)
This commit is contained in:
Daniel 2023-03-16 08:42:25 +11:00 committed by Jobobby04
parent c7433287c6
commit 43b3abf43b
6 changed files with 37 additions and 5 deletions

View File

@ -807,12 +807,22 @@ class ReaderActivity : BaseActivity() {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
val interval = parsed.seconds val interval = parsed.seconds
while (true) { while (true) {
delay(interval) if (!binding.readerMenu.isVisible) {
viewer.let { v -> viewer.let { v ->
when (v) { when (v) {
is PagerViewer -> v.moveToNext() is PagerViewer -> v.moveToNext()
is WebtoonViewer -> v.scrollDown() is WebtoonViewer -> {
if (readerPreferences.smoothAutoScroll().get()) {
v.linearScroll(interval)
} else {
v.scrollDown()
}
}
}
} }
delay(interval)
} else {
delay(100)
} }
} }
} }

View File

@ -133,6 +133,8 @@ class ReaderPreferences(
fun autoscrollInterval() = preferenceStore.getFloat("eh_util_autoscroll_interval", 3f) fun autoscrollInterval() = preferenceStore.getFloat("eh_util_autoscroll_interval", 3f)
fun smoothAutoScroll() = preferenceStore.getBoolean("smooth_auto_scroll", true)
fun preserveReadingPosition() = preferenceStore.getBoolean("eh_preserve_reading_position", false) fun preserveReadingPosition() = preferenceStore.getBoolean("eh_preserve_reading_position", false)
fun preloadSize() = preferenceStore.getInt("eh_preload_size", 10) fun preloadSize() = preferenceStore.getInt("eh_preload_size", 10)

View File

@ -134,6 +134,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr
// SY --> // SY -->
binding.webtoonPrefsGroup.zoomOutWebtoon.bindToPreference(readerPreferences.webtoonEnableZoomOut()) binding.webtoonPrefsGroup.zoomOutWebtoon.bindToPreference(readerPreferences.webtoonEnableZoomOut())
binding.webtoonPrefsGroup.cropBordersContinuousVertical.bindToPreference(readerPreferences.cropBordersContinuousVertical()) binding.webtoonPrefsGroup.cropBordersContinuousVertical.bindToPreference(readerPreferences.cropBordersContinuousVertical())
binding.webtoonPrefsGroup.smoothScrollWebtoon.bindToPreference(readerPreferences.smoothAutoScroll())
binding.webtoonPrefsGroup.pageTransitionsWebtoon.bindToPreference(readerPreferences.pageTransitionsWebtoon()) binding.webtoonPrefsGroup.pageTransitionsWebtoon.bindToPreference(readerPreferences.pageTransitionsWebtoon())
// SY <-- // SY <--
} }

View File

@ -6,6 +6,7 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.animation.LinearInterpolator
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -29,6 +30,7 @@ import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.time.Duration
/** /**
* Implementation of a [BaseViewer] to display pages with a [RecyclerView]. * Implementation of a [BaseViewer] to display pages with a [RecyclerView].
@ -300,6 +302,13 @@ class WebtoonViewer(val activity: ReaderActivity, val isContinuous: Boolean = tr
} }
} }
/**
* Scrolls one screen over a period of time
*/
fun linearScroll(duration: Duration) {
recycler.smoothScrollBy(0, activity.resources.displayMetrics.heightPixels, LinearInterpolator(), duration.inWholeMilliseconds.toInt())
}
/** /**
* Scrolls down by [scrollDistance]. * Scrolls down by [scrollDistance].
*/ */

View File

@ -46,6 +46,15 @@
android:text="@string/pref_crop_borders" android:text="@string/pref_crop_borders"
android:textColor="?android:attr/textColorSecondary" /> android:textColor="?android:attr/textColorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/smooth_scroll_webtoon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
android:paddingVertical="16dp"
android:textColor="?android:attr/textColorSecondary"
android:text="@string/pref_smooth_scroll"/>
<com.google.android.material.materialswitch.MaterialSwitch <com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/page_transitions_webtoon" android:id="@+id/page_transitions_webtoon"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -253,6 +253,7 @@
<string name="pref_left_handed_vertical_seekbar_summary">Switches which side the seekbar is on</string> <string name="pref_left_handed_vertical_seekbar_summary">Switches which side the seekbar is on</string>
<string name="pref_force_horz_seekbar">Force horizontal seekbar</string> <string name="pref_force_horz_seekbar">Force horizontal seekbar</string>
<string name="pref_force_horz_seekbar_summary">Removes vertical seekbar entirely in favour of horizontal</string> <string name="pref_force_horz_seekbar_summary">Removes vertical seekbar entirely in favour of horizontal</string>
<string name="pref_smooth_scroll">Smooth Auto Scroll</string>
<!-- Reader --> <!-- Reader -->
<!-- Reader Actions --> <!-- Reader Actions -->