Option to disable pages animation #406

This commit is contained in:
Koitharu
2023-08-09 14:50:52 +03:00
parent 4b9f4f9af2
commit edb91c46d4
13 changed files with 71 additions and 21 deletions

View File

@@ -166,9 +166,6 @@
<activity
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
android:label="@string/color_correction" />
<activity
android:name="org.koitharu.kotatsu.shelf.ui.config.ShelfSettingsActivity"
android:label="@string/settings" />
<activity
android:name="org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity"
android:exported="true"

View File

@@ -101,8 +101,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
val notificationLight: Boolean
get() = prefs.getBoolean(KEY_NOTIFICATIONS_LIGHT, true)
val readerAnimation: Boolean
get() = prefs.getBoolean(KEY_READER_ANIMATION, false)
val readerAnimation: ReaderAnimation
get() = prefs.getEnumValue(KEY_READER_ANIMATION, ReaderAnimation.DEFAULT)
val readerBackground: ReaderBackground
get() = prefs.getEnumValue(KEY_READER_BACKGROUND, ReaderBackground.DEFAULT)
@@ -384,7 +384,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
const val KEY_NOTIFICATIONS_VIBRATE = "notifications_vibrate"
const val KEY_NOTIFICATIONS_LIGHT = "notifications_light"
const val KEY_NOTIFICATIONS_INFO = "tracker_notifications_info"
const val KEY_READER_ANIMATION = "reader_animation"
const val KEY_READER_ANIMATION = "reader_animation2"
const val KEY_READER_MODE = "reader_mode"
const val KEY_READER_MODE_DETECT = "reader_mode_detect"
const val KEY_APP_PASSWORD = "app_password"

View File

@@ -0,0 +1,7 @@
package org.koitharu.kotatsu.core.prefs
enum class ReaderAnimation {
// Do not rename this
NONE, DEFAULT, ADVANCED;
}

View File

@@ -8,6 +8,6 @@ enum class ReaderMode(val id: Int) {
companion object {
fun valueOf(id: Int) = values().firstOrNull { it.id == id }
fun valueOf(id: Int) = entries.firstOrNull { it.id == id }
}
}
}

View File

@@ -101,7 +101,7 @@ class ReaderViewModel @Inject constructor(
val manga: DoubleManga?
get() = mangaData.value
val readerAnimation = settings.observeAsStateFlow(
val pageAnimation = settings.observeAsStateFlow(
scope = viewModelScope + Dispatchers.Default,
key = AppSettings.KEY_READER_ANIMATION,
valueProducer = { readerAnimation },

View File

@@ -4,8 +4,10 @@ import android.os.Bundle
import androidx.core.graphics.Insets
import androidx.fragment.app.activityViewModels
import androidx.viewbinding.ViewBinding
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
import org.koitharu.kotatsu.core.ui.BaseFragment
import org.koitharu.kotatsu.core.util.ext.getParcelableCompat
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.reader.ui.ReaderState
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
@@ -54,6 +56,10 @@ abstract class BaseReaderFragment<B : ViewBinding> : BaseFragment<B>() {
"Adapter was not created or already destroyed"
}
protected fun isAnimationEnabled(): Boolean {
return context?.isAnimationsEnabled == true && viewModel.pageAnimation.value != ReaderAnimation.NONE
}
override fun onWindowInsetsChanged(insets: Insets) = Unit
abstract fun switchPageBy(delta: Int)

View File

@@ -11,8 +11,8 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.yield
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.os.NetworkState
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.core.util.ext.recyclerView
import org.koitharu.kotatsu.core.util.ext.resetTransformations
@@ -22,6 +22,7 @@ import org.koitharu.kotatsu.reader.ui.ReaderState
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderAdapter
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
import org.koitharu.kotatsu.reader.ui.pager.standard.NoAnimPageTransformer
import org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
import javax.inject.Inject
import kotlin.math.absoluteValue
@@ -48,8 +49,12 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
doOnPageChanged(::notifyPageChanged)
}
viewModel.readerAnimation.observe(viewLifecycleOwner) {
val transformer = if (it) ReversedPageAnimTransformer() else null
viewModel.pageAnimation.observe(viewLifecycleOwner) {
val transformer = when (it) {
ReaderAnimation.NONE -> NoAnimPageTransformer()
ReaderAnimation.DEFAULT -> null
ReaderAnimation.ADVANCED -> ReversedPageAnimTransformer()
}
binding.pager.setPageTransformer(transformer)
if (transformer == null) {
binding.pager.recyclerView?.children?.forEach { v ->
@@ -74,7 +79,7 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
override fun switchPageBy(delta: Int) {
with(requireViewBinding().pager) {
setCurrentItem(currentItem - delta, context.isAnimationsEnabled)
setCurrentItem(currentItem - delta, isAnimationEnabled())
}
}
@@ -82,7 +87,7 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
with(requireViewBinding().pager) {
setCurrentItem(
reversed(position),
smooth && context.isAnimationsEnabled && (currentItem - position).absoluteValue < PagerReaderFragment.SMOOTH_SCROLL_LIMIT,
smooth && isAnimationEnabled() && (currentItem - position).absoluteValue < PagerReaderFragment.SMOOTH_SCROLL_LIMIT,
)
}
}

View File

@@ -0,0 +1,15 @@
package org.koitharu.kotatsu.reader.ui.pager.standard
import android.view.View
import androidx.viewpager2.widget.ViewPager2
class NoAnimPageTransformer : ViewPager2.PageTransformer {
override fun transformPage(page: View, position: Float) {
page.translationX = when {
position in -0.5f..0.5f -> -position * page.width.toFloat()
position > 0 -> page.width.toFloat()
else -> -page.width.toFloat()
}
}
}

View File

@@ -11,8 +11,8 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.yield
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.os.NetworkState
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
import org.koitharu.kotatsu.core.util.ext.doOnPageChanged
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.core.util.ext.recyclerView
import org.koitharu.kotatsu.core.util.ext.resetTransformations
@@ -47,8 +47,12 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
doOnPageChanged(::notifyPageChanged)
}
viewModel.readerAnimation.observe(viewLifecycleOwner) {
val transformer = if (it) PageAnimTransformer() else null
viewModel.pageAnimation.observe(viewLifecycleOwner) {
val transformer = when (it) {
ReaderAnimation.NONE -> NoAnimPageTransformer()
ReaderAnimation.DEFAULT -> null
ReaderAnimation.ADVANCED -> PageAnimTransformer()
}
binding.pager.setPageTransformer(transformer)
if (transformer == null) {
binding.pager.recyclerView?.children?.forEach { view ->
@@ -95,7 +99,7 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
override fun switchPageBy(delta: Int) {
with(requireViewBinding().pager) {
setCurrentItem(currentItem + delta, context.isAnimationsEnabled)
setCurrentItem(currentItem + delta, isAnimationEnabled())
}
}
@@ -103,7 +107,7 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
with(requireViewBinding().pager) {
setCurrentItem(
position,
smooth && context.isAnimationsEnabled && (currentItem - position).absoluteValue < SMOOTH_SCROLL_LIMIT,
smooth && isAnimationEnabled() && (currentItem - position).absoluteValue < SMOOTH_SCROLL_LIMIT,
)
}
}

View File

@@ -13,7 +13,6 @@ import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.os.NetworkState
import org.koitharu.kotatsu.core.util.ext.findCenterViewPosition
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
import org.koitharu.kotatsu.core.util.ext.observe
import org.koitharu.kotatsu.databinding.FragmentReaderWebtoonBinding
import org.koitharu.kotatsu.reader.domain.PageLoader
@@ -111,7 +110,7 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
override fun switchPageBy(delta: Int) {
with(requireViewBinding().recyclerView) {
if (context.isAnimationsEnabled) {
if (isAnimationEnabled()) {
smoothScrollBy(0, (height * 0.9).toInt() * delta, scrollInterpolator)
} else {
nestedScrollBy(0, (height * 0.9).toInt() * delta)

View File

@@ -10,6 +10,7 @@ import dagger.hilt.android.AndroidEntryPoint
import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.core.model.ZoomMode
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
import org.koitharu.kotatsu.core.prefs.ReaderBackground
import org.koitharu.kotatsu.core.prefs.ReaderMode
import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
@@ -32,6 +33,10 @@ class ReaderSettingsFragment :
entryValues = ReaderBackground.entries.names()
setDefaultValueCompat(ReaderBackground.DEFAULT.name)
}
findPreference<ListPreference>(AppSettings.KEY_READER_ANIMATION)?.run {
entryValues = ReaderAnimation.entries.names()
setDefaultValueCompat(ReaderAnimation.DEFAULT.name)
}
findPreference<MultiSelectListPreference>(AppSettings.KEY_READER_SWITCHERS)?.run {
summaryProvider = MultiSummaryProvider(R.string.gestures_only)
}

View File

@@ -65,4 +65,10 @@
<item>@string/color_white</item>
<item>@string/color_black</item>
</string-array>
<string-array name="reader_animation">
<item>@string/disabled</item>
<item>@string/system_default</item>
<item>@string/advanced</item>
</string-array>
<string name="advanced">Advanced</string>
</resources>

View File

@@ -42,6 +42,12 @@
android:summary="@string/reader_control_ltr_summary"
android:title="@string/reader_control_ltr" />
<ListPreference
android:entries="@array/reader_animation"
android:key="reader_animation2"
android:title="@string/pages_animation"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="reader_animation"