From 33a02b47d5e54b207fe2d50cfe0b754db22a6c4b Mon Sep 17 00:00:00 2001 From: Riztard Lanthorn Date: Sat, 30 Oct 2021 23:19:15 +0700 Subject: [PATCH] Hide cutout toggle button if fullscreen is off (#6150) --- .../ui/reader/setting/ReaderGeneralSettings.kt | 17 +++++++++++------ .../ui/setting/SettingsReaderController.kt | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt index 96c66b76b9..263c460590 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt @@ -5,11 +5,14 @@ import android.util.AttributeSet import android.view.LayoutInflater import androidx.core.view.isVisible import androidx.core.widget.NestedScrollView +import androidx.lifecycle.lifecycleScope import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.databinding.ReaderGeneralSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.preference.bindToPreference +import kotlinx.coroutines.flow.launchIn import uy.kohesive.injekt.injectLazy /** @@ -35,15 +38,17 @@ class ReaderGeneralSettings @JvmOverloads constructor(context: Context, attrs: A binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values) binding.showPageNumber.bindToPreference(preferences.showPageNumber()) binding.fullscreen.bindToPreference(preferences.fullscreen()) + preferences.fullscreen() + .asImmediateFlow { + // If the preference is explicitly disabled, that means the setting was configured since there is a cutout + binding.cutoutShort.isVisible = it && ((context as ReaderActivity).hasCutout || !preferences.cutoutShort().get()) + binding.cutoutShort.bindToPreference(preferences.cutoutShort()) + } + .launchIn((context as ReaderActivity).lifecycleScope) + binding.keepscreen.bindToPreference(preferences.keepScreenOn()) binding.longTap.bindToPreference(preferences.readWithLongTap()) binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition()) binding.pageTransitions.bindToPreference(preferences.pageTransitions()) - - // If the preference is explicitly disabled, that means the setting was configured since there is a cutout - if ((context as ReaderActivity).hasCutout || !preferences.cutoutShort().get()) { - binding.cutoutShort.isVisible = true - binding.cutoutShort.bindToPreference(preferences.cutoutShort()) - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index de2191a9a7..cadeb403d5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -111,6 +111,7 @@ class SettingsReaderController : SettingsController() { key = Keys.cutoutShort titleRes = R.string.pref_cutout_short defaultValue = true + preferences.fullscreen().asImmediateFlow { isVisible = it }.launchIn(viewScope) } }