Hide cutout option when appropriate in reader settings sheet (closes #2982)

(cherry picked from commit b9488645d4de4d5a844426d7503b13f5675bc3a2)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderSettingsSheet.kt
This commit is contained in:
arkon 2020-07-30 22:38:10 -04:00 committed by Jobobby04
parent 00701aeda1
commit 3920a5a73b
3 changed files with 22 additions and 7 deletions

View File

@ -54,6 +54,7 @@ import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.lang.plusAssign
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.GLUtil 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.system.toast
import eu.kanade.tachiyomi.util.view.defaultBar import eu.kanade.tachiyomi.util.view.defaultBar
import eu.kanade.tachiyomi.util.view.hideBar import eu.kanade.tachiyomi.util.view.hideBar
@ -67,6 +68,7 @@ import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.roundToLong import kotlin.math.roundToLong
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
@ -98,6 +100,8 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
*/ */
val maxBitmapSize by lazy { GLUtil.maxTextureSize } val maxBitmapSize by lazy { GLUtil.maxTextureSize }
val hasCutout by lazy { hasDisplayCutout() }
/** /**
* Viewer used to display the pages (pager, webtoon, ...). * Viewer used to display the pages (pager, webtoon, ...).
*/ */
@ -881,6 +885,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
/** /**
* Class that handles the user preferences of the reader. * Class that handles the user preferences of the reader.
*/ */
@FlowPreview
private inner class ReaderConfig { private inner class ReaderConfig {
/** /**
@ -908,11 +913,9 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
.onEach { setTrueColor(it) } .onEach { setTrueColor(it) }
.launchIn(scope) .launchIn(scope)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { preferences.cutoutShort().asFlow()
preferences.cutoutShort().asFlow() .onEach { setCutoutShort(it) }
.onEach { setCutoutShort(it) } .launchIn(scope)
.launchIn(scope)
}
preferences.keepScreenOn().asFlow() preferences.keepScreenOn().asFlow()
.onEach { setKeepScreenOn(it) } .onEach { setKeepScreenOn(it) }
@ -982,6 +985,9 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
true -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES true -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
false -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER false -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER
} }
// Trigger relayout
setMenuVisibility(menuVisible)
} }
/** /**
@ -998,6 +1004,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
/** /**
* Sets the custom brightness overlay according to [enabled]. * Sets the custom brightness overlay according to [enabled].
*/ */
@FlowPreview
private fun setCustomBrightness(enabled: Boolean) { private fun setCustomBrightness(enabled: Boolean) {
if (enabled) { if (enabled) {
preferences.customBrightnessValue().asFlow() preferences.customBrightnessValue().asFlow()
@ -1012,6 +1019,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
/** /**
* Sets the color filter overlay according to [enabled]. * Sets the color filter overlay according to [enabled].
*/ */
@FlowPreview
private fun setColorFilter(enabled: Boolean) { private fun setColorFilter(enabled: Boolean) {
if (enabled) { if (enabled) {
preferences.colorFilterValue().asFlow() preferences.colorFilterValue().asFlow()

View File

@ -67,7 +67,6 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values) binding.backgroundColor.bindToIntPreference(preferences.readerTheme(), R.array.reader_themes_values)
binding.showPageNumber.bindToPreference(preferences.showPageNumber()) binding.showPageNumber.bindToPreference(preferences.showPageNumber())
binding.fullscreen.bindToPreference(preferences.fullscreen()) binding.fullscreen.bindToPreference(preferences.fullscreen())
binding.cutoutShort.bindToPreference(preferences.cutoutShort())
binding.keepscreen.bindToPreference(preferences.keepScreenOn()) binding.keepscreen.bindToPreference(preferences.keepScreenOn())
binding.longTap.bindToPreference(preferences.readWithLongTap()) binding.longTap.bindToPreference(preferences.readWithLongTap())
binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition()) binding.alwaysShowChapterTransition.bindToPreference(preferences.alwaysShowChapterTransition())
@ -76,6 +75,12 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia
// SY --> // SY -->
binding.autoWebtoonMode.bindToPreference(preferences.eh_useAutoWebtoon()) binding.autoWebtoonMode.bindToPreference(preferences.eh_useAutoWebtoon())
// SY <-- // SY <--
// 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())
}
} }
/** /**

View File

@ -164,7 +164,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/pref_cutout_short" android:text="@string/pref_cutout_short"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
app:layout_constraintTop_toBottomOf="@id/fullscreen" /> android:visibility="gone"
app:layout_constraintTop_toBottomOf="@id/fullscreen"
tools:visibility="visible" />
<com.google.android.material.switchmaterial.SwitchMaterial <com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/keepscreen" android:id="@+id/keepscreen"