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