diff --git a/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt index 55139e2f3..7eeb64804 100644 --- a/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -65,6 +65,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { val readerPageSwitch: Set get() = prefs.getStringSet(KEY_READER_SWITCHERS, null) ?: setOf(PAGE_SWITCH_TAPS) + val isReaderTapsAdaptive: Boolean + get() = !prefs.getBoolean(KEY_READER_TAPS_LTR, false) + var isTrafficWarningEnabled: Boolean get() = prefs.getBoolean(KEY_TRAFFIC_WARNING, true) set(value) = prefs.edit { putBoolean(KEY_TRAFFIC_WARNING, value) } @@ -321,6 +324,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { const val KEY_SYNC = "sync" const val KEY_READER_BAR = "reader_bar" const val KEY_SHORTCUTS = "dynamic_shortcuts" + const val KEY_READER_TAPS_LTR = "reader_taps_ltr" // About const val KEY_APP_UPDATE = "app_update" diff --git a/app/src/main/java/org/koitharu/kotatsu/main/ui/protect/AppProtectHelper.kt b/app/src/main/java/org/koitharu/kotatsu/main/ui/protect/AppProtectHelper.kt index a3b4bcbbd..c94cdd153 100644 --- a/app/src/main/java/org/koitharu/kotatsu/main/ui/protect/AppProtectHelper.kt +++ b/app/src/main/java/org/koitharu/kotatsu/main/ui/protect/AppProtectHelper.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Bundle import javax.inject.Inject import javax.inject.Singleton +import org.acra.dialog.CrashReportDialog import org.koitharu.kotatsu.core.prefs.AppSettings @Singleton @@ -14,7 +15,7 @@ class AppProtectHelper @Inject constructor(private val settings: AppSettings) : private var isUnlocked = settings.appPassword.isNullOrEmpty() override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { - if (activity !is ProtectActivity && !isUnlocked) { + if (!isUnlocked && activity !is ProtectActivity && activity !is CrashReportDialog) { val sourceIntent = Intent(activity, activity.javaClass) activity.intent?.let { sourceIntent.putExtras(it) diff --git a/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt b/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt index e958796b1..cb9a0f13c 100644 --- a/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt +++ b/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt @@ -74,6 +74,9 @@ class ReaderActivity : pageSwitchTimer.delaySec = value } + override val readerMode: ReaderMode? + get() = readerManager.currentMode + private lateinit var pageSwitchTimer: PageSwitchTimer private lateinit var touchHelper: GridTouchHelper private lateinit var controlDelegate: ReaderControlDelegate @@ -88,7 +91,7 @@ class ReaderActivity : supportActionBar?.setDisplayHomeAsUpEnabled(true) touchHelper = GridTouchHelper(this, this) pageSwitchTimer = PageSwitchTimer(this, this) - controlDelegate = ReaderControlDelegate(lifecycleScope, settings, this) + controlDelegate = ReaderControlDelegate(settings, this, this) binding.toolbarBottom.setOnMenuItemClickListener(::onOptionsItemSelected) binding.slider.setLabelFormatter(PageLabelFormatter()) ReaderSliderListener(this, viewModel).attachToSlider(binding.slider) diff --git a/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderControlDelegate.kt b/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderControlDelegate.kt index 98c14c98c..3da6ed8d1 100644 --- a/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderControlDelegate.kt +++ b/app/src/main/java/org/koitharu/kotatsu/reader/ui/ReaderControlDelegate.kt @@ -1,33 +1,39 @@ package org.koitharu.kotatsu.reader.ui +import android.content.SharedPreferences import android.view.KeyEvent import android.view.SoundEffectConstants import android.view.View -import androidx.lifecycle.LifecycleCoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner import org.koitharu.kotatsu.core.prefs.AppSettings -import org.koitharu.kotatsu.core.prefs.observeAsFlow +import org.koitharu.kotatsu.core.prefs.ReaderMode import org.koitharu.kotatsu.utils.GridTouchHelper class ReaderControlDelegate( - scope: LifecycleCoroutineScope, - settings: AppSettings, + private val settings: AppSettings, private val listener: OnInteractionListener, -) { + owner: LifecycleOwner, +) : DefaultLifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener { private var isTapSwitchEnabled: Boolean = true private var isVolumeKeysSwitchEnabled: Boolean = false + private var isReaderTapsAdaptive: Boolean = true init { - settings.observeAsFlow(AppSettings.KEY_READER_SWITCHERS) { readerPageSwitch } - .flowOn(Dispatchers.Default) - .onEach { - isTapSwitchEnabled = AppSettings.PAGE_SWITCH_TAPS in it - isVolumeKeysSwitchEnabled = AppSettings.PAGE_SWITCH_VOLUME_KEYS in it - }.launchIn(scope) + owner.lifecycle.addObserver(this) + settings.subscribe(this) + updateSettings() + } + + override fun onDestroy(owner: LifecycleOwner) { + settings.unsubscribe(this) + owner.lifecycle.removeObserver(this) + super.onDestroy(owner) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + updateSettings() } fun onGridTouch(area: Int, view: View) { @@ -41,7 +47,7 @@ class ReaderControlDelegate( view.playSoundEffect(SoundEffectConstants.NAVIGATION_UP) } GridTouchHelper.AREA_LEFT -> if (isTapSwitchEnabled) { - listener.switchPageBy(-1) + listener.switchPageBy(if (isReaderTapsReversed()) 1 else -1) view.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT) } GridTouchHelper.AREA_BOTTOM -> if (isTapSwitchEnabled) { @@ -49,7 +55,7 @@ class ReaderControlDelegate( view.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN) } GridTouchHelper.AREA_RIGHT -> if (isTapSwitchEnabled) { - listener.switchPageBy(1) + listener.switchPageBy(if (isReaderTapsReversed()) -1 else 1) view.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT) } } @@ -72,19 +78,25 @@ class ReaderControlDelegate( KeyEvent.KEYCODE_PAGE_DOWN, KeyEvent.KEYCODE_SYSTEM_NAVIGATION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, - KeyEvent.KEYCODE_DPAD_RIGHT, -> { listener.switchPageBy(1) true } + KeyEvent.KEYCODE_DPAD_RIGHT -> { + listener.switchPageBy(if (isReaderTapsReversed()) -1 else 1) + true + } KeyEvent.KEYCODE_PAGE_UP, KeyEvent.KEYCODE_SYSTEM_NAVIGATION_UP, KeyEvent.KEYCODE_DPAD_UP, - KeyEvent.KEYCODE_DPAD_LEFT, -> { listener.switchPageBy(-1) true } + KeyEvent.KEYCODE_DPAD_LEFT -> { + listener.switchPageBy(if (isReaderTapsReversed()) 1 else -1) + true + } KeyEvent.KEYCODE_DPAD_CENTER -> { listener.toggleUiVisibility() true @@ -99,8 +111,21 @@ class ReaderControlDelegate( ) } + private fun updateSettings() { + val switch = settings.readerPageSwitch + isTapSwitchEnabled = AppSettings.PAGE_SWITCH_TAPS in switch + isVolumeKeysSwitchEnabled = AppSettings.PAGE_SWITCH_VOLUME_KEYS in switch + isReaderTapsAdaptive = settings.isReaderTapsAdaptive + } + + private fun isReaderTapsReversed(): Boolean { + return isReaderTapsAdaptive && listener.readerMode == ReaderMode.REVERSED + } + interface OnInteractionListener { + val readerMode: ReaderMode? + fun switchPageBy(delta: Int) fun toggleUiVisibility() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 105caaee3..b903e1234 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -379,4 +379,6 @@ Error details:<br><tt>%1$s</tt><br><br>1. Try to <a href="%2$s">open manga in a web browser</a> to ensure it is available on its source<br>2. If it is available, send an error report to the developers. Show recent manga shortcuts Make recent manga available by long pressing on application icon + Tap on the right edge or pressing the right key always switches to the next page + Ergonomic reader control diff --git a/app/src/main/res/xml/pref_reader.xml b/app/src/main/res/xml/pref_reader.xml index 9d82c1cf3..dbbe245e0 100644 --- a/app/src/main/res/xml/pref_reader.xml +++ b/app/src/main/res/xml/pref_reader.xml @@ -29,6 +29,12 @@ android:title="@string/switch_pages" app:allowDividerAbove="true" /> + +