From b9488645d4de4d5a844426d7503b13f5675bc3a2 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 30 Jul 2020 22:38:10 -0400 Subject: [PATCH] Hide cutout option when appropriate in reader settings sheet (closes #2982) --- .../tachiyomi/ui/reader/ReaderActivity.kt | 18 +++++++++++++----- .../tachiyomi/ui/reader/ReaderSettingsSheet.kt | 7 ++++++- .../main/res/layout/reader_settings_sheet.xml | 4 +++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index dc3b61f906..4823283215 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -46,6 +46,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.GLUtil +import eu.kanade.tachiyomi.util.system.hasDisplayCutout import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.defaultBar import eu.kanade.tachiyomi.util.view.hideBar @@ -56,6 +57,7 @@ import eu.kanade.tachiyomi.widget.SimpleAnimationListener import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import java.io.File import kotlin.math.abs +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.delay import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.launchIn @@ -79,6 +81,8 @@ class ReaderActivity : BaseRxActivity() */ val maxBitmapSize by lazy { GLUtil.maxTextureSize } + val hasCutout by lazy { hasDisplayCutout() } + /** * Viewer used to display the pages (pager, webtoon, ...). */ @@ -625,6 +629,7 @@ class ReaderActivity : BaseRxActivity() /** * Class that handles the user preferences of the reader. */ + @FlowPreview private inner class ReaderConfig { /** @@ -652,11 +657,9 @@ class ReaderActivity : BaseRxActivity() .onEach { setTrueColor(it) } .launchIn(scope) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - preferences.cutoutShort().asFlow() - .onEach { setCutoutShort(it) } - .launchIn(scope) - } + preferences.cutoutShort().asFlow() + .onEach { setCutoutShort(it) } + .launchIn(scope) preferences.keepScreenOn().asFlow() .onEach { setKeepScreenOn(it) } @@ -726,6 +729,9 @@ class ReaderActivity : BaseRxActivity() true -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES false -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER } + + // Trigger relayout + setMenuVisibility(menuVisible) } /** @@ -742,6 +748,7 @@ class ReaderActivity : BaseRxActivity() /** * Sets the custom brightness overlay according to [enabled]. */ + @FlowPreview private fun setCustomBrightness(enabled: Boolean) { if (enabled) { preferences.customBrightnessValue().asFlow() @@ -756,6 +763,7 @@ class ReaderActivity : BaseRxActivity() /** * Sets the color filter overlay according to [enabled]. */ + @FlowPreview private fun setColorFilter(enabled: Boolean) { if (enabled) { preferences.colorFilterValue().asFlow() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt index f7f4c116f5..59a99a7fc8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt @@ -67,12 +67,17 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values) binding.showPageNumber.bindToPreference(preferences.showPageNumber()) binding.fullscreen.bindToPreference(preferences.fullscreen()) - binding.cutoutShort.bindToPreference(preferences.cutoutShort()) binding.keepscreen.bindToPreference(preferences.keepScreenOn()) binding.longTap.bindToPreference(preferences.readWithLongTap()) binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition()) binding.cropBorders.bindToPreference(preferences.cropBorders()) binding.pageTransitions.bindToPreference(preferences.pageTransitions()) + + // If the preference is explicitly disabled, that means the setting was configured since there is a cutout + if (activity.hasCutout || !preferences.cutoutShort().get()) { + binding.cutoutShort.isVisible = true + binding.cutoutShort.bindToPreference(preferences.cutoutShort()) + } } /** diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index bf667d23a2..e6712e46ff 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -164,7 +164,9 @@ android:layout_height="wrap_content" android:text="@string/pref_cutout_short" android:textColor="?android:attr/textColorSecondary" - app:layout_constraintTop_toBottomOf="@id/fullscreen" /> + android:visibility="gone" + app:layout_constraintTop_toBottomOf="@id/fullscreen" + tools:visibility="visible" />