mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-12 21:35:18 +01:00
Option to change cutout behavior in portrait
Back on my BS, but this was an uncommited change for months that I was too lazy to stash for release
This commit is contained in:
parent
78933e8191
commit
58defbb5d2
@ -89,7 +89,7 @@ androidExtensions {
|
||||
|
||||
dependencies {
|
||||
// Modified dependencies
|
||||
implementation("com.github.tachiyomiorg:subsampling-scale-image-view:6caf219")
|
||||
implementation("com.github.jays2kings:subsampling-scale-image-view:dfd3e43")
|
||||
implementation("com.github.inorichi:junrar-android:634c1f5")
|
||||
|
||||
// Source models and interfaces from Tachiyomi 1.x
|
||||
|
@ -15,6 +15,8 @@ object PreferenceKeys {
|
||||
|
||||
const val enableTransitions = "pref_enable_transitions_key"
|
||||
|
||||
const val pagerCutoutBehavior = "pager_cutout_behavior"
|
||||
|
||||
const val doubleTapAnimationSpeed = "pref_double_tap_anim_speed"
|
||||
|
||||
const val showPageNumber = "pref_show_page_number_key"
|
||||
|
@ -89,6 +89,8 @@ class PreferencesHelper(val context: Context) {
|
||||
|
||||
fun pageTransitions() = flowPrefs.getBoolean(Keys.enableTransitions, true)
|
||||
|
||||
fun pagerCutoutBehavior() = flowPrefs.getInt(Keys.pagerCutoutBehavior, 1)
|
||||
|
||||
fun doubleTapAnimSpeed() = flowPrefs.getInt(Keys.doubleTapAnimationSpeed, 500)
|
||||
|
||||
fun showPageNumber() = flowPrefs.getBoolean(Keys.showPageNumber, true)
|
||||
|
@ -1,7 +1,9 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.util.bindToPreference
|
||||
@ -13,12 +15,17 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
|
||||
BaseReaderSettingsView(context, attrs) {
|
||||
|
||||
override fun initGeneralPreferences() {
|
||||
scale_type.bindToPreference(preferences.imageScaleType(), 1)
|
||||
scale_type.bindToPreference(preferences.imageScaleType(), 1) {
|
||||
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
|
||||
val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
|
||||
updatePagedGroup(!isWebtoonView)
|
||||
}
|
||||
zoom_start.bindToPreference(preferences.zoomStart(), 1)
|
||||
crop_borders.bindToPreference(preferences.cropBorders())
|
||||
page_transitions.bindToPreference(preferences.pageTransitions())
|
||||
pager_nav.bindToPreference(preferences.navigationModePager())
|
||||
pager_invert.bindToPreference(preferences.pagerNavInverted())
|
||||
extend_past_cutout.bindToPreference(preferences.pagerCutoutBehavior())
|
||||
|
||||
val mangaViewer = (context as? ReaderActivity)?.presenter?.getMangaViewer() ?: 0
|
||||
val isWebtoonView = mangaViewer == ReaderActivity.WEBTOON || mangaViewer == ReaderActivity.VERTICAL_PLUS
|
||||
@ -43,5 +50,18 @@ class ReaderPagedView @JvmOverloads constructor(context: Context, attrs: Attribu
|
||||
private fun updatePagedGroup(show: Boolean) {
|
||||
listOf(scale_type, zoom_start, crop_borders, page_transitions, pager_nav, pager_invert).forEach { it.visibleIf(show) }
|
||||
listOf(crop_borders_webtoon, webtoon_side_padding, webtoon_enable_zoom_out, webtoon_nav, webtoon_invert).forEach { it.visibleIf(!show) }
|
||||
val isFullFit = when (preferences.imageScaleType().get()) {
|
||||
SubsamplingScaleImageView.SCALE_TYPE_FIT_HEIGHT,
|
||||
SubsamplingScaleImageView.SCALE_TYPE_SMART_FIT,
|
||||
SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP -> true
|
||||
else -> false
|
||||
}
|
||||
val ogView = (context as? Activity)?.window?.decorView
|
||||
val hasCutout = if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
||||
ogView?.rootWindowInsets?.displayCutout?.safeInsetTop != null || ogView?.rootWindowInsets?.displayCutout?.safeInsetBottom != null
|
||||
} else {
|
||||
false
|
||||
}
|
||||
extend_past_cutout.visibleIf(show && isFullFit && hasCutout)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.viewer.pager
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerConfig
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
|
||||
@ -34,6 +35,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
|
||||
var readerTheme = 0
|
||||
private set
|
||||
|
||||
var cutoutBehavior = 0
|
||||
private set
|
||||
|
||||
init {
|
||||
preferences.pageTransitions()
|
||||
.register({ usePageTransitions = it })
|
||||
@ -59,6 +63,9 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
|
||||
}
|
||||
.launchIn(scope)
|
||||
|
||||
preferences.pagerCutoutBehavior()
|
||||
.register({ cutoutBehavior = it }, { imagePropertyChangedListener?.invoke() })
|
||||
|
||||
preferences.zoomStart()
|
||||
.register({ zoomTypeFromPreference(it) }, { imagePropertyChangedListener?.invoke() })
|
||||
|
||||
@ -103,6 +110,15 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
|
||||
}
|
||||
}
|
||||
|
||||
fun scaleTypeIsFullFit(): Boolean {
|
||||
return when (imageScaleType) {
|
||||
SubsamplingScaleImageView.SCALE_TYPE_FIT_HEIGHT,
|
||||
SubsamplingScaleImageView.SCALE_TYPE_SMART_FIT,
|
||||
SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateNavigation(navigationMode: Int) {
|
||||
navigator = when (navigationMode) {
|
||||
0 -> defaultNavigation()
|
||||
@ -118,4 +134,10 @@ class PagerConfig(private val viewer: PagerViewer, preferences: PreferencesHelpe
|
||||
enum class ZoomType {
|
||||
Left, Center, Right
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CUTOUT_PAD = 0
|
||||
const val CUTOUT_START_EXTENDED = 1
|
||||
const val CUTOUT_IGNORE = 2
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressBar
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.Companion.CUTOUT_IGNORE
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.Companion.CUTOUT_START_EXTENDED
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerConfig.ZoomType
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||
@ -365,7 +367,18 @@ class PagerPageHolder(
|
||||
setMinimumDpi(90)
|
||||
setMinimumTileDpi(180)
|
||||
setCropBorders(config.imageCropBorders)
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
|
||||
val topInsets =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
||||
viewer.activity.window.decorView.rootWindowInsets.displayCutout?.safeInsetTop?.toFloat() ?: 0f
|
||||
} else 0f
|
||||
val bottomInsets =
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
||||
viewer.activity.window.decorView.rootWindowInsets.displayCutout?.safeInsetBottom?.toFloat() ?: 0f
|
||||
} else 0f
|
||||
setExtendPastCutout(config.cutoutBehavior == CUTOUT_START_EXTENDED && config.scaleTypeIsFullFit() && topInsets + bottomInsets > 0)
|
||||
if ((config.cutoutBehavior != CUTOUT_IGNORE || !config.scaleTypeIsFullFit()) &&
|
||||
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q
|
||||
) {
|
||||
val insets: WindowInsets? = viewer.activity.window.decorView.rootWindowInsets
|
||||
setExtraSpace(
|
||||
0f,
|
||||
@ -377,10 +390,28 @@ class PagerPageHolder(
|
||||
setOnImageEventListener(
|
||||
object : SubsamplingScaleImageView.DefaultOnImageEventListener() {
|
||||
override fun onReady() {
|
||||
var centerV = 0f
|
||||
when (config.imageZoomType) {
|
||||
ZoomType.Left -> setScaleAndCenter(scale, PointF(0f, 0f))
|
||||
ZoomType.Right -> setScaleAndCenter(scale, PointF(sWidth.toFloat(), 0f))
|
||||
ZoomType.Center -> setScaleAndCenter(scale, center.also { it?.y = 0f })
|
||||
ZoomType.Left -> {
|
||||
setScaleAndCenter(scale, PointF(0f, 0f))
|
||||
}
|
||||
ZoomType.Right -> {
|
||||
setScaleAndCenter(scale, PointF(sWidth.toFloat(), 0f))
|
||||
centerV = sWidth.toFloat()
|
||||
}
|
||||
ZoomType.Center -> {
|
||||
setScaleAndCenter(scale, center.also { it?.y = 0f })
|
||||
centerV = center?.x ?: 0f
|
||||
}
|
||||
}
|
||||
if (config.cutoutBehavior == CUTOUT_START_EXTENDED &&
|
||||
topInsets + bottomInsets > 0 &&
|
||||
config.scaleTypeIsFullFit()
|
||||
) {
|
||||
setScaleAndCenter(
|
||||
scale,
|
||||
PointF(centerV, (center?.y?.plus(topInsets)?.minus(bottomInsets) ?: 0f))
|
||||
)
|
||||
}
|
||||
onImageDecoded()
|
||||
}
|
||||
|
@ -40,6 +40,14 @@
|
||||
app:title="@string/scale_type"
|
||||
android:entries="@array/image_scale_type" />
|
||||
|
||||
<eu.kanade.tachiyomi.ui.reader.settings.ReaderSpinnerView
|
||||
android:id="@+id/extend_past_cutout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
app:title="@string/cutout_area_behavior"
|
||||
android:entries="@array/cutout_behavior" />
|
||||
|
||||
<eu.kanade.tachiyomi.ui.reader.settings.ReaderSpinnerView
|
||||
android:id="@+id/zoom_start"
|
||||
android:layout_width="match_parent"
|
||||
@ -65,7 +73,6 @@
|
||||
android:text="@string/animate_page_transitions"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
|
||||
<!-- Webtoon Prefs -->
|
||||
<eu.kanade.tachiyomi.ui.reader.settings.ReaderSpinnerView
|
||||
android:id="@+id/webtoon_nav"
|
||||
|
@ -77,6 +77,12 @@
|
||||
<item>@string/both_axes</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="cutout_behavior">
|
||||
<item>@string/pad_cutout_areas</item>
|
||||
<item>@string/start_past_cutout</item>
|
||||
<item>@string/ignore_cutout_areas</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="clean_up_downloads">
|
||||
<item>@string/clean_orphaned_downloads</item>
|
||||
<item>@string/clean_read_downloads</item>
|
||||
|
@ -378,6 +378,10 @@
|
||||
<string name="horizontally">Horizontally</string>
|
||||
<string name="vertically">Vertically</string>
|
||||
<string name="both_axes">Both Axes</string>
|
||||
<string name="cutout_area_behavior">Cutout area behavior</string>
|
||||
<string name="pad_cutout_areas">Pad cutout areas</string>
|
||||
<string name="start_past_cutout">Start past cutout</string>
|
||||
<string name="ignore_cutout_areas">Ignore cutout areas</string>
|
||||
|
||||
<!-- Manga details -->
|
||||
<string name="about_this_">About this %1$s</string>
|
||||
|
Loading…
Reference in New Issue
Block a user