From bcec01c48b49d92df1ccbe5e5162372485a05586 Mon Sep 17 00:00:00 2001 From: Jan Grabowski Date: Sun, 8 Mar 2020 14:04:52 +0100 Subject: [PATCH 1/3] Added an option to change the notch mode Option is enabled (not greyed out) in Reader settings only when a mobile supports notch. Default option is to NOT use the notch area on horizontal view. Also added polish translation to already fixed polish translation file. --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../tachiyomi/ui/reader/ReaderActivity.kt | 39 +++++++++++++------ .../ui/setting/SettingsReaderController.kt | 13 +++++++ app/src/main/res/values-pl/strings.xml | 2 + app/src/main/res/values/strings.xml | 2 + 6 files changed, 49 insertions(+), 11 deletions(-) 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 ea3d9eb08a..3fbc2c90f8 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 isDefaultNotchMode = "pref_notch_mode" + 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 ab2c49be7a..0b589b33fe 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 @@ -72,6 +72,8 @@ class PreferencesHelper(val context: Context) { fun fullscreen() = rxPrefs.getBoolean(Keys.fullscreen, true) + fun notchDefaultCutoutMode() = rxPrefs.getBoolean(Keys.isDefaultNotchMode, false) + 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 43e749fef4..106a241e27 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 @@ -11,12 +11,7 @@ import android.graphics.Bitmap import android.graphics.Color import android.os.Build import android.os.Bundle -import android.view.KeyEvent -import android.view.Menu -import android.view.MenuItem -import android.view.MotionEvent -import android.view.View -import android.view.WindowManager +import android.view.* import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.SeekBar @@ -34,9 +29,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.main.BiometricActivity import eu.kanade.tachiyomi.ui.main.MainActivity -import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.AddToLibraryFirst -import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Error -import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.Success +import eu.kanade.tachiyomi.ui.reader.ReaderPresenter.SetAsCoverResult.* import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter import eu.kanade.tachiyomi.ui.reader.model.ReaderPage import eu.kanade.tachiyomi.ui.reader.model.ViewerChapters @@ -45,11 +38,11 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer -import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.system.GLUtil import eu.kanade.tachiyomi.util.system.getResourceColor +import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visible @@ -67,7 +60,7 @@ import rx.subscriptions.CompositeSubscription import timber.log.Timber import uy.kohesive.injekt.injectLazy import java.io.File -import java.util.Date +import java.util.* import java.util.concurrent.TimeUnit import kotlin.math.abs @@ -692,6 +685,10 @@ class ReaderActivity : BaseRxActivity(), subscriptions += preferences.colorFilterMode().asObservable() .subscribe { setColorFilter(preferences.colorFilter().getOrDefault()) } + + subscriptions += preferences.notchDefaultCutoutMode().asObservable() + .subscribe { setNotchCutoutMode(preferences.notchDefaultCutoutMode().getOrDefault()) } + } /** @@ -804,6 +801,26 @@ class ReaderActivity : BaseRxActivity(), } } + + /** + * Sets notch cutout mode to "DEFAULT" mode if true and "NEVER" mode if false. + * In "NEVER" mode the space next to the notch won't be used and filled with a black background. + */ + private fun setNotchCutoutMode(isDefault: Boolean) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + if (!isDefault) { + val currentOrientation = resources.configuration.orientation + + if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { + val params = window.attributes + params.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER + } + + } + } + } + /** * Sets the brightness of the screen. Range is [-75, 100]. * From -75 to -1 a semi-transparent black view is overlaid with the minimum brightness. 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 dc9861234b..24eccef800 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 @@ -87,6 +87,19 @@ class SettingsReaderController : SettingsController() { defaultValue = false } } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val cutout = activity?.window?.decorView?.rootWindowInsets?.displayCutout + + switchPreference { + key = Keys.isDefaultNotchMode + titleRes = R.string.pref_notch_display + summaryRes = R.string.pref_notch_display_summary + defaultValue = false + isEnabled = cutout != null // display option only when a mobile has a notch + } + } + preferenceCategory { titleRes = R.string.pager_viewer diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index b731bea572..0e8563d6b0 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -215,6 +215,8 @@ Szybkość podwójnego stuknięcia Pokazuj numer strony Kolor 32 bitowy + Użyj przestrzeni sąsiadującej z notchem + Działa tylko w widoku horyzontalnym, tak by notch nachodził na wyświetlaną stronę Przycinaj krawędzie Niestandardowa jasność Niestandardowy filtr kolorów diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e84d5bf8f2..0248cb2ca3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -216,6 +216,8 @@ Double tap animation speed Show page number 32-bit color + Use space next to the notch + Works only for the landscape view for the notch to overlap the displayed page Crop borders Use custom brightness Use custom color filter From 3b7be37268d7f706ff85139d6cc8f01a937f311c Mon Sep 17 00:00:00 2001 From: Jan Grabowski Date: Sun, 8 Mar 2020 21:34:34 +0100 Subject: [PATCH 2/3] Made feature persistent, removed option from settings --- .../tachiyomi/data/preference/PreferencesHelper.kt | 2 -- .../eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt | 12 ++++-------- .../tachiyomi/ui/setting/SettingsReaderController.kt | 12 ------------ app/src/main/res/values-pl/strings.xml | 2 -- app/src/main/res/values/strings.xml | 2 -- 5 files changed, 4 insertions(+), 26 deletions(-) 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 0b589b33fe..ab2c49be7a 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 @@ -72,8 +72,6 @@ class PreferencesHelper(val context: Context) { fun fullscreen() = rxPrefs.getBoolean(Keys.fullscreen, true) - fun notchDefaultCutoutMode() = rxPrefs.getBoolean(Keys.isDefaultNotchMode, false) - 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 106a241e27..1bbfb659b2 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 @@ -686,9 +686,7 @@ class ReaderActivity : BaseRxActivity(), subscriptions += preferences.colorFilterMode().asObservable() .subscribe { setColorFilter(preferences.colorFilter().getOrDefault()) } - subscriptions += preferences.notchDefaultCutoutMode().asObservable() - .subscribe { setNotchCutoutMode(preferences.notchDefaultCutoutMode().getOrDefault()) } - + this.setNotchCutoutMode() } /** @@ -803,12 +801,11 @@ class ReaderActivity : BaseRxActivity(), /** - * Sets notch cutout mode to "DEFAULT" mode if true and "NEVER" mode if false. - * In "NEVER" mode the space next to the notch won't be used and filled with a black background. + * Sets notch cutout mode to "NEVER", if mobile is in a landscape view */ - private fun setNotchCutoutMode(isDefault: Boolean) { + private fun setNotchCutoutMode() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - if (!isDefault) { + val currentOrientation = resources.configuration.orientation if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { @@ -817,7 +814,6 @@ class ReaderActivity : BaseRxActivity(), WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER } - } } } 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 24eccef800..0e23b82aae 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 @@ -88,18 +88,6 @@ class SettingsReaderController : SettingsController() { } } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - val cutout = activity?.window?.decorView?.rootWindowInsets?.displayCutout - - switchPreference { - key = Keys.isDefaultNotchMode - titleRes = R.string.pref_notch_display - summaryRes = R.string.pref_notch_display_summary - defaultValue = false - isEnabled = cutout != null // display option only when a mobile has a notch - } - } - preferenceCategory { titleRes = R.string.pager_viewer diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 0e8563d6b0..b731bea572 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -215,8 +215,6 @@ Szybkość podwójnego stuknięcia Pokazuj numer strony Kolor 32 bitowy - Użyj przestrzeni sąsiadującej z notchem - Działa tylko w widoku horyzontalnym, tak by notch nachodził na wyświetlaną stronę Przycinaj krawędzie Niestandardowa jasność Niestandardowy filtr kolorów diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0248cb2ca3..e84d5bf8f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -216,8 +216,6 @@ Double tap animation speed Show page number 32-bit color - Use space next to the notch - Works only for the landscape view for the notch to overlap the displayed page Crop borders Use custom brightness Use custom color filter From 543cb0a0470fe5991ff131fe1851bf72243c6954 Mon Sep 17 00:00:00 2001 From: Jan Grabowski Date: Mon, 9 Mar 2020 17:38:46 +0100 Subject: [PATCH 3/3] Moved function, removed pref. --- .../data/preference/PreferenceKeys.kt | 2 - .../tachiyomi/ui/reader/ReaderActivity.kt | 39 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) 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 3fbc2c90f8..ea3d9eb08a 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,8 +19,6 @@ object PreferenceKeys { const val fullscreen = "fullscreen" - const val isDefaultNotchMode = "pref_notch_mode" - 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/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 1bbfb659b2..2f82a1a552 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 @@ -159,6 +159,8 @@ class ReaderActivity : BaseRxActivity(), super.onCreate(savedState) setContentView(R.layout.reader_activity) + setNotchCutoutMode() + if (presenter.needsInit()) { val manga = intent.extras!!.getLong("manga", -1) val chapter = intent.extras!!.getLong("chapter", -1) @@ -628,6 +630,23 @@ class ReaderActivity : BaseRxActivity(), } } + /** + * Sets notch cutout mode to "NEVER", if mobile is in a landscape view + */ + private fun setNotchCutoutMode() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + + val currentOrientation = resources.configuration.orientation + + if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { + val params = window.attributes + params.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER + } + + } + } + /** * Class that handles the user preferences of the reader. @@ -685,8 +704,6 @@ class ReaderActivity : BaseRxActivity(), subscriptions += preferences.colorFilterMode().asObservable() .subscribe { setColorFilter(preferences.colorFilter().getOrDefault()) } - - this.setNotchCutoutMode() } /** @@ -799,24 +816,6 @@ class ReaderActivity : BaseRxActivity(), } } - - /** - * Sets notch cutout mode to "NEVER", if mobile is in a landscape view - */ - private fun setNotchCutoutMode() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - - val currentOrientation = resources.configuration.orientation - - if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { - val params = window.attributes - params.layoutInDisplayCutoutMode = - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER - } - - } - } - /** * Sets the brightness of the screen. Range is [-75, 100]. * From -75 to -1 a semi-transparent black view is overlaid with the minimum brightness.