Option to disable pages animation #406
This commit is contained in:
@@ -166,9 +166,6 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
|
android:name="org.koitharu.kotatsu.reader.ui.colorfilter.ColorFilterConfigActivity"
|
||||||
android:label="@string/color_correction" />
|
android:label="@string/color_correction" />
|
||||||
<activity
|
|
||||||
android:name="org.koitharu.kotatsu.shelf.ui.config.ShelfSettingsActivity"
|
|
||||||
android:label="@string/settings" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity"
|
android:name="org.koitharu.kotatsu.scrobbling.common.ui.config.ScrobblerConfigActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) {
|
|||||||
val notificationLight: Boolean
|
val notificationLight: Boolean
|
||||||
get() = prefs.getBoolean(KEY_NOTIFICATIONS_LIGHT, true)
|
get() = prefs.getBoolean(KEY_NOTIFICATIONS_LIGHT, true)
|
||||||
|
|
||||||
val readerAnimation: Boolean
|
val readerAnimation: ReaderAnimation
|
||||||
get() = prefs.getBoolean(KEY_READER_ANIMATION, false)
|
get() = prefs.getEnumValue(KEY_READER_ANIMATION, ReaderAnimation.DEFAULT)
|
||||||
|
|
||||||
val readerBackground: ReaderBackground
|
val readerBackground: ReaderBackground
|
||||||
get() = prefs.getEnumValue(KEY_READER_BACKGROUND, ReaderBackground.DEFAULT)
|
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_VIBRATE = "notifications_vibrate"
|
||||||
const val KEY_NOTIFICATIONS_LIGHT = "notifications_light"
|
const val KEY_NOTIFICATIONS_LIGHT = "notifications_light"
|
||||||
const val KEY_NOTIFICATIONS_INFO = "tracker_notifications_info"
|
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 = "reader_mode"
|
||||||
const val KEY_READER_MODE_DETECT = "reader_mode_detect"
|
const val KEY_READER_MODE_DETECT = "reader_mode_detect"
|
||||||
const val KEY_APP_PASSWORD = "app_password"
|
const val KEY_APP_PASSWORD = "app_password"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package org.koitharu.kotatsu.core.prefs
|
||||||
|
|
||||||
|
enum class ReaderAnimation {
|
||||||
|
|
||||||
|
// Do not rename this
|
||||||
|
NONE, DEFAULT, ADVANCED;
|
||||||
|
}
|
||||||
@@ -8,6 +8,6 @@ enum class ReaderMode(val id: Int) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun valueOf(id: Int) = values().firstOrNull { it.id == id }
|
fun valueOf(id: Int) = entries.firstOrNull { it.id == id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ class ReaderViewModel @Inject constructor(
|
|||||||
val manga: DoubleManga?
|
val manga: DoubleManga?
|
||||||
get() = mangaData.value
|
get() = mangaData.value
|
||||||
|
|
||||||
val readerAnimation = settings.observeAsStateFlow(
|
val pageAnimation = settings.observeAsStateFlow(
|
||||||
scope = viewModelScope + Dispatchers.Default,
|
scope = viewModelScope + Dispatchers.Default,
|
||||||
key = AppSettings.KEY_READER_ANIMATION,
|
key = AppSettings.KEY_READER_ANIMATION,
|
||||||
valueProducer = { readerAnimation },
|
valueProducer = { readerAnimation },
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import android.os.Bundle
|
|||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
|
import org.koitharu.kotatsu.core.prefs.ReaderAnimation
|
||||||
import org.koitharu.kotatsu.core.ui.BaseFragment
|
import org.koitharu.kotatsu.core.ui.BaseFragment
|
||||||
import org.koitharu.kotatsu.core.util.ext.getParcelableCompat
|
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.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderState
|
import org.koitharu.kotatsu.reader.ui.ReaderState
|
||||||
import org.koitharu.kotatsu.reader.ui.ReaderViewModel
|
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"
|
"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
|
override fun onWindowInsetsChanged(insets: Insets) = Unit
|
||||||
|
|
||||||
abstract fun switchPageBy(delta: Int)
|
abstract fun switchPageBy(delta: Int)
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import kotlinx.coroutines.coroutineScope
|
|||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
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.doOnPageChanged
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
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.BaseReaderAdapter
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
import org.koitharu.kotatsu.reader.ui.pager.BaseReaderFragment
|
||||||
import org.koitharu.kotatsu.reader.ui.pager.ReaderPage
|
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 org.koitharu.kotatsu.reader.ui.pager.standard.PagerReaderFragment
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
@@ -48,8 +49,12 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
|||||||
doOnPageChanged(::notifyPageChanged)
|
doOnPageChanged(::notifyPageChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.readerAnimation.observe(viewLifecycleOwner) {
|
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
||||||
val transformer = if (it) ReversedPageAnimTransformer() else null
|
val transformer = when (it) {
|
||||||
|
ReaderAnimation.NONE -> NoAnimPageTransformer()
|
||||||
|
ReaderAnimation.DEFAULT -> null
|
||||||
|
ReaderAnimation.ADVANCED -> ReversedPageAnimTransformer()
|
||||||
|
}
|
||||||
binding.pager.setPageTransformer(transformer)
|
binding.pager.setPageTransformer(transformer)
|
||||||
if (transformer == null) {
|
if (transformer == null) {
|
||||||
binding.pager.recyclerView?.children?.forEach { v ->
|
binding.pager.recyclerView?.children?.forEach { v ->
|
||||||
@@ -74,7 +79,7 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
|||||||
|
|
||||||
override fun switchPageBy(delta: Int) {
|
override fun switchPageBy(delta: Int) {
|
||||||
with(requireViewBinding().pager) {
|
with(requireViewBinding().pager) {
|
||||||
setCurrentItem(currentItem - delta, context.isAnimationsEnabled)
|
setCurrentItem(currentItem - delta, isAnimationEnabled())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +87,7 @@ class ReversedReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>
|
|||||||
with(requireViewBinding().pager) {
|
with(requireViewBinding().pager) {
|
||||||
setCurrentItem(
|
setCurrentItem(
|
||||||
reversed(position),
|
reversed(position),
|
||||||
smooth && context.isAnimationsEnabled && (currentItem - position).absoluteValue < PagerReaderFragment.SMOOTH_SCROLL_LIMIT,
|
smooth && isAnimationEnabled() && (currentItem - position).absoluteValue < PagerReaderFragment.SMOOTH_SCROLL_LIMIT,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,8 @@ import kotlinx.coroutines.coroutineScope
|
|||||||
import kotlinx.coroutines.yield
|
import kotlinx.coroutines.yield
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
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.doOnPageChanged
|
||||||
import org.koitharu.kotatsu.core.util.ext.isAnimationsEnabled
|
|
||||||
import org.koitharu.kotatsu.core.util.ext.observe
|
import org.koitharu.kotatsu.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
import org.koitharu.kotatsu.core.util.ext.recyclerView
|
||||||
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
import org.koitharu.kotatsu.core.util.ext.resetTransformations
|
||||||
@@ -47,8 +47,12 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
|
|||||||
doOnPageChanged(::notifyPageChanged)
|
doOnPageChanged(::notifyPageChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.readerAnimation.observe(viewLifecycleOwner) {
|
viewModel.pageAnimation.observe(viewLifecycleOwner) {
|
||||||
val transformer = if (it) PageAnimTransformer() else null
|
val transformer = when (it) {
|
||||||
|
ReaderAnimation.NONE -> NoAnimPageTransformer()
|
||||||
|
ReaderAnimation.DEFAULT -> null
|
||||||
|
ReaderAnimation.ADVANCED -> PageAnimTransformer()
|
||||||
|
}
|
||||||
binding.pager.setPageTransformer(transformer)
|
binding.pager.setPageTransformer(transformer)
|
||||||
if (transformer == null) {
|
if (transformer == null) {
|
||||||
binding.pager.recyclerView?.children?.forEach { view ->
|
binding.pager.recyclerView?.children?.forEach { view ->
|
||||||
@@ -95,7 +99,7 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
|
|||||||
|
|
||||||
override fun switchPageBy(delta: Int) {
|
override fun switchPageBy(delta: Int) {
|
||||||
with(requireViewBinding().pager) {
|
with(requireViewBinding().pager) {
|
||||||
setCurrentItem(currentItem + delta, context.isAnimationsEnabled)
|
setCurrentItem(currentItem + delta, isAnimationEnabled())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +107,7 @@ class PagerReaderFragment : BaseReaderFragment<FragmentReaderStandardBinding>()
|
|||||||
with(requireViewBinding().pager) {
|
with(requireViewBinding().pager) {
|
||||||
setCurrentItem(
|
setCurrentItem(
|
||||||
position,
|
position,
|
||||||
smooth && context.isAnimationsEnabled && (currentItem - position).absoluteValue < SMOOTH_SCROLL_LIMIT,
|
smooth && isAnimationEnabled() && (currentItem - position).absoluteValue < SMOOTH_SCROLL_LIMIT,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.core.os.NetworkState
|
import org.koitharu.kotatsu.core.os.NetworkState
|
||||||
import org.koitharu.kotatsu.core.util.ext.findCenterViewPosition
|
import org.koitharu.kotatsu.core.util.ext.findCenterViewPosition
|
||||||
import org.koitharu.kotatsu.core.util.ext.firstVisibleItemPosition
|
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.core.util.ext.observe
|
||||||
import org.koitharu.kotatsu.databinding.FragmentReaderWebtoonBinding
|
import org.koitharu.kotatsu.databinding.FragmentReaderWebtoonBinding
|
||||||
import org.koitharu.kotatsu.reader.domain.PageLoader
|
import org.koitharu.kotatsu.reader.domain.PageLoader
|
||||||
@@ -111,7 +110,7 @@ class WebtoonReaderFragment : BaseReaderFragment<FragmentReaderWebtoonBinding>()
|
|||||||
|
|
||||||
override fun switchPageBy(delta: Int) {
|
override fun switchPageBy(delta: Int) {
|
||||||
with(requireViewBinding().recyclerView) {
|
with(requireViewBinding().recyclerView) {
|
||||||
if (context.isAnimationsEnabled) {
|
if (isAnimationEnabled()) {
|
||||||
smoothScrollBy(0, (height * 0.9).toInt() * delta, scrollInterpolator)
|
smoothScrollBy(0, (height * 0.9).toInt() * delta, scrollInterpolator)
|
||||||
} else {
|
} else {
|
||||||
nestedScrollBy(0, (height * 0.9).toInt() * delta)
|
nestedScrollBy(0, (height * 0.9).toInt() * delta)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.core.model.ZoomMode
|
import org.koitharu.kotatsu.core.model.ZoomMode
|
||||||
import org.koitharu.kotatsu.core.prefs.AppSettings
|
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.ReaderBackground
|
||||||
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
import org.koitharu.kotatsu.core.prefs.ReaderMode
|
||||||
import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
import org.koitharu.kotatsu.core.ui.BasePreferenceFragment
|
||||||
@@ -32,6 +33,10 @@ class ReaderSettingsFragment :
|
|||||||
entryValues = ReaderBackground.entries.names()
|
entryValues = ReaderBackground.entries.names()
|
||||||
setDefaultValueCompat(ReaderBackground.DEFAULT.name)
|
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 {
|
findPreference<MultiSelectListPreference>(AppSettings.KEY_READER_SWITCHERS)?.run {
|
||||||
summaryProvider = MultiSummaryProvider(R.string.gestures_only)
|
summaryProvider = MultiSummaryProvider(R.string.gestures_only)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,4 +65,10 @@
|
|||||||
<item>@string/color_white</item>
|
<item>@string/color_white</item>
|
||||||
<item>@string/color_black</item>
|
<item>@string/color_black</item>
|
||||||
</string-array>
|
</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>
|
</resources>
|
||||||
|
|||||||
@@ -42,6 +42,12 @@
|
|||||||
android:summary="@string/reader_control_ltr_summary"
|
android:summary="@string/reader_control_ltr_summary"
|
||||||
android:title="@string/reader_control_ltr" />
|
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
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="reader_animation"
|
android:key="reader_animation"
|
||||||
|
|||||||
Reference in New Issue
Block a user