From 12aa04be93032575d23fd8ebc483fd0903af1612 Mon Sep 17 00:00:00 2001 From: onlymash Date: Mon, 17 Feb 2020 23:40:49 +0800 Subject: [PATCH] Fix fullscreen reader for notch device (#2595) * Fix fullscreen reader for notch device * Make cutout mode configurable * Rename cutout option --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../data/preference/PreferencesHelper.kt | 2 ++ .../kanade/tachiyomi/ui/reader/ReaderActivity.kt | 15 +++++++++++++++ .../tachiyomi/ui/reader/ReaderSettingsSheet.kt | 6 ++++++ .../ui/setting/SettingsReaderController.kt | 7 +++++++ app/src/main/res/layout/reader_settings_sheet.xml | 12 +++++++++++- app/src/main/res/values/strings.xml | 1 + 7 files changed, 44 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 070739b92..865ae6ba1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -19,6 +19,8 @@ object PreferenceKeys { const val fullscreen = "fullscreen" + const val cutoutShort = "cutout_short" + const val keepScreenOn = "pref_keep_screen_on_key" const val customBrightness = "pref_custom_brightness_key" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 3c9e8b3de..162313a18 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -67,6 +67,8 @@ class PreferencesHelper(val context: Context) { fun fullscreen() = rxPrefs.getBoolean(Keys.fullscreen, true) + fun cutoutShort() = rxPrefs.getBoolean(Keys.cutoutShort, true) + fun keepScreenOn() = rxPrefs.getBoolean(Keys.keepScreenOn, true) fun customBrightness() = rxPrefs.getBoolean(Keys.customBrightness, false) 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 54d1cd342..2171a4395 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.reader import android.annotation.SuppressLint +import android.annotation.TargetApi import android.app.ProgressDialog import android.content.Context import android.content.Intent @@ -8,6 +9,7 @@ import android.content.pm.ActivityInfo import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.Color +import android.os.Build import android.os.Bundle import android.view.* import android.view.animation.Animation @@ -565,6 +567,11 @@ class ReaderActivity : BaseRxActivity() { subscriptions += preferences.fullscreen().asObservable() .subscribe { setFullscreen(it) } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + subscriptions += preferences.cutoutShort().asObservable() + .subscribe { setCutoutShort(it)} + } + subscriptions += preferences.keepScreenOn().asObservable() .subscribe { setKeepScreenOn(it) } @@ -646,6 +653,14 @@ class ReaderActivity : BaseRxActivity() { } } + @TargetApi(Build.VERSION_CODES.P) + private fun setCutoutShort(enabled: Boolean) { + window.attributes.layoutInDisplayCutoutMode = when (enabled) { + true -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + false -> WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER + } + } + /** * Sets the keep screen on mode according to [enabled]. */ 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 9540da3b1..d66982af3 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 @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.ui.reader +import android.os.Build import android.os.Bundle +import android.view.View import android.widget.CompoundButton import android.widget.Spinner import androidx.core.widget.NestedScrollView @@ -61,6 +63,10 @@ class ReaderSettingsSheet(private val activity: ReaderActivity) : BottomSheetDia background_color.bindToPreference(preferences.readerTheme()) show_page_number.bindToPreference(preferences.showPageNumber()) fullscreen.bindToPreference(preferences.fullscreen()) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + cutout_short.visibility = View.VISIBLE + cutout_short.bindToPreference(preferences.cutoutShort()) + } keepscreen.bindToPreference(preferences.keepScreenOn()) long_tap.bindToPreference(preferences.readWithLongTap()) } 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 db0c2a3d0..fc6c234c4 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 @@ -74,6 +74,13 @@ class SettingsReaderController : SettingsController() { titleRes = R.string.pref_fullscreen defaultValue = true } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + switchPreference { + key = Keys.cutoutShort + titleRes = R.string.pref_cutout_short + defaultValue = true + } + } switchPreference { key = Keys.keepScreenOn titleRes = R.string.pref_keep_screen_on diff --git a/app/src/main/res/layout/reader_settings_sheet.xml b/app/src/main/res/layout/reader_settings_sheet.xml index 20e9d3286..987968167 100644 --- a/app/src/main/res/layout/reader_settings_sheet.xml +++ b/app/src/main/res/layout/reader_settings_sheet.xml @@ -125,6 +125,16 @@ android:textColor="?android:attr/textColorSecondary" app:layout_constraintTop_toBottomOf="@id/true_color" /> + + + app:layout_constraintTop_toBottomOf="@id/cutout_short" /> Fullscreen + Show content in cutout area Lock orientation Page transitions Double tap animation speed