diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index 29132e098..37ad743be 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -141,6 +141,11 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { val isReaderOptimizationEnabled: Boolean get() = prefs.getBoolean(KEY_READER_OPTIMIZE, false) + val readerControls: Set + get() = prefs.getStringSet(KEY_READER_CONTROLS, null)?.mapNotNullTo(EnumSet.noneOf(ReaderControl::class.java)) { + ReaderControl.entries.find(it) + } ?: EnumSet.allOf(ReaderControl::class.java) + val isOfflineCheckDisabled: Boolean get() = prefs.getBoolean(KEY_OFFLINE_DISABLED, false) @@ -631,6 +636,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { const val KEY_NOTIFICATIONS_LIGHT = "notifications_light" const val KEY_NOTIFICATIONS_INFO = "tracker_notifications_info" const val KEY_READER_ANIMATION = "reader_animation2" + const val KEY_READER_CONTROLS = "reader_controls" const val KEY_READER_MODE = "reader_mode" const val KEY_READER_MODE_DETECT = "reader_mode_detect" const val KEY_READER_CROP = "reader_crop" diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/ReaderControl.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/ReaderControl.kt new file mode 100644 index 000000000..b7de928da --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/ReaderControl.kt @@ -0,0 +1,6 @@ +package org.koitharu.kotatsu.core.prefs + +enum class ReaderControl { + + PREV_CHAPTER, NEXT_CHAPTER, SLIDER, PAGES_SHEET +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Preferences.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Preferences.kt index 72b7fc3bd..e2e915619 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Preferences.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Preferences.kt @@ -2,6 +2,7 @@ package org.koitharu.kotatsu.core.util.ext import android.content.SharedPreferences import androidx.preference.ListPreference +import androidx.preference.MultiSelectListPreference fun ListPreference.setDefaultValueCompat(defaultValue: String) { if (value == null) { @@ -9,6 +10,10 @@ fun ListPreference.setDefaultValueCompat(defaultValue: String) { } } +fun MultiSelectListPreference.setDefaultValueCompat(defaultValue: Set) { + setDefaultValue(defaultValue) +} + fun > SharedPreferences.getEnumValue(key: String, enumClass: Class): E? { val stringValue = getString(key, null) ?: return null return enumClass.enumConstants?.find { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt index 84ca4593c..a3f6af05f 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt @@ -33,6 +33,7 @@ import org.koitharu.kotatsu.core.exceptions.resolve.DialogErrorObserver import org.koitharu.kotatsu.core.nav.AppRouter import org.koitharu.kotatsu.core.nav.router import org.koitharu.kotatsu.core.prefs.AppSettings +import org.koitharu.kotatsu.core.prefs.ReaderControl import org.koitharu.kotatsu.core.prefs.ReaderMode import org.koitharu.kotatsu.core.ui.BaseFullscreenActivity import org.koitharu.kotatsu.core.ui.util.MenuInvalidator @@ -145,6 +146,7 @@ class ReaderActivity : viewModel.content.observe(this) { onLoadingStateChanged(viewModel.isLoading.value) } + viewModel.readerControls.observe(this, ::onReaderControlsChanged) viewModel.isKeepScreenOnEnabled.observe(this, this::setKeepScreenOn) viewModel.isInfoBarTransparent.observe(this) { viewBinding.infoBar.drawBackground = !it } viewModel.isInfoBarEnabled.observe(this, ::onReaderBarChanged) @@ -297,6 +299,13 @@ class ReaderActivity : } } + private fun onReaderControlsChanged(controls: Set) = with(viewBinding) { + buttonPrev.isVisible = ReaderControl.PREV_CHAPTER in controls + buttonNext.isVisible = ReaderControl.NEXT_CHAPTER in controls + slider.isVisible = ReaderControl.SLIDER in controls + toolbarBottom.invalidateMenu() + } + private fun setUiIsVisible(isUiVisible: Boolean) { if (viewBinding.appbarTop.isVisible != isUiVisible) { if (isAnimationsEnabled) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderMenuBottomProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderMenuBottomProvider.kt index c938b91bf..0decec25b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderMenuBottomProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderMenuBottomProvider.kt @@ -7,6 +7,7 @@ import androidx.core.view.MenuProvider import androidx.fragment.app.FragmentActivity import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.nav.router +import org.koitharu.kotatsu.core.prefs.ReaderControl class ReaderMenuBottomProvider( private val activity: FragmentActivity, @@ -20,10 +21,11 @@ class ReaderMenuBottomProvider( } override fun onPrepareMenu(menu: Menu) { - val hasPages = viewModel.content.value.pages.isNotEmpty() + val isPagesSheetEnabled = viewModel.content.value.pages.isNotEmpty() && + ReaderControl.PAGES_SHEET in viewModel.readerControls.value menu.findItem(R.id.action_pages_thumbs).run { - isVisible = hasPages - if (hasPages) { + isVisible = isPagesSheetEnabled + if (isPagesSheetEnabled) { setIcon(if (viewModel.isPagesSheetEnabled.value) R.drawable.ic_grid else R.drawable.ic_list) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index f05dc0703..bdce762ed 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -136,6 +136,12 @@ class ReaderViewModel @Inject constructor( valueProducer = { isReaderBarEnabled }, ) + val readerControls = settings.observeAsStateFlow( + scope = viewModelScope + Dispatchers.Default, + key = AppSettings.KEY_READER_CONTROLS, + valueProducer = { readerControls }, + ) + val isInfoBarTransparent = settings.observeAsStateFlow( scope = viewModelScope + Dispatchers.Default, key = AppSettings.KEY_READER_BAR_TRANSPARENT, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ReaderSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ReaderSettingsFragment.kt index c71ca7ab8..0a77c28b4 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/ReaderSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/ReaderSettingsFragment.kt @@ -14,6 +14,7 @@ import org.koitharu.kotatsu.core.nav.router 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.ReaderControl import org.koitharu.kotatsu.core.prefs.ReaderMode import org.koitharu.kotatsu.core.ui.BasePreferenceFragment import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat @@ -30,12 +31,7 @@ class ReaderSettingsFragment : override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_reader) findPreference(AppSettings.KEY_READER_MODE)?.run { - entryValues = arrayOf( - ReaderMode.STANDARD.name, - ReaderMode.REVERSED.name, - ReaderMode.VERTICAL.name, - ReaderMode.WEBTOON.name, - ) + entryValues = ReaderMode.entries.names() setDefaultValueCompat(ReaderMode.STANDARD.name) } findPreference(AppSettings.KEY_READER_ORIENTATION)?.run { @@ -47,6 +43,11 @@ class ReaderSettingsFragment : ) setDefaultValueCompat(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED.toString()) } + findPreference(AppSettings.KEY_READER_CONTROLS)?.run { + entryValues = ReaderControl.entries.names() + setDefaultValueCompat(ReaderControl.entries.names().toSet()) + summaryProvider = MultiSummaryProvider(R.string.none) + } findPreference(AppSettings.KEY_READER_BACKGROUND)?.run { entryValues = ReaderBackground.entries.names() setDefaultValueCompat(ReaderBackground.DEFAULT.name) diff --git a/app/src/main/res/layout/activity_reader.xml b/app/src/main/res/layout/activity_reader.xml index 79dba1369..0a8fdf3da 100644 --- a/app/src/main/res/layout/activity_reader.xml +++ b/app/src/main/res/layout/activity_reader.xml @@ -69,20 +69,19 @@ android:layout_height="wrap_content" tools:menu="@menu/opt_reader_bottom"> - + android:layout_marginEnd="2dp" + android:gravity="center_vertical|end"> @@ -91,9 +90,7 @@ android:id="@+id/slider" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_centerVertical="true" - android:layout_toStartOf="@id/button_next" - android:layout_toEndOf="@id/button_prev" + android:layout_weight="1" android:stepSize="1.0" android:valueFrom="0" app:labelBehavior="floating" @@ -105,13 +102,11 @@ style="?actionButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_alignParentEnd="true" - android:layout_centerVertical="true" android:contentDescription="@string/next_chapter" android:src="@drawable/ic_next" android:tooltipText="@string/next_chapter" /> - + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index fa5ea6aa5..154376802 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -124,4 +124,10 @@ @string/portrait @string/landscape + + @string/prev_chapter + @string/next_chapter + @string/pages_slider + @string/chapters_and_pages + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5b4e9b05..6045b9c7f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -795,4 +795,7 @@ Transparent reader information bar The backup will be restored in the background Restoring backup + Reader controls in bottom bar + Chapters and pages + Page switch slider diff --git a/app/src/main/res/xml/pref_reader.xml b/app/src/main/res/xml/pref_reader.xml index fcbbee104..9228b787b 100644 --- a/app/src/main/res/xml/pref_reader.xml +++ b/app/src/main/res/xml/pref_reader.xml @@ -138,7 +138,12 @@ android:defaultValue="false" android:key="pages_numbers" android:summary="@string/show_pages_numbers_summary" - android:title="@string/show_pages_numbers" />x + android:title="@string/show_pages_numbers" /> + +