mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-05 00:28:56 +01:00
Tweak tablet UI mode setting (#8262)
This commit is contained in:
@@ -65,7 +65,7 @@ import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.preference.asHotFlow
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.getThemeColor
|
||||
import eu.kanade.tachiyomi.util.system.isTablet
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.view.setNavigationBarTransparentCompat
|
||||
@@ -610,7 +610,7 @@ class MainActivity : BaseActivity() {
|
||||
binding.appbar.isVisible = !isComposeController
|
||||
binding.controllerContainer.enableScrollingBehavior(!isComposeController)
|
||||
|
||||
if (!isTablet()) {
|
||||
if (!isTabletUi()) {
|
||||
// Save lift state
|
||||
if (isPush) {
|
||||
if (router.backstackSize > 1) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.core.os.bundleOf
|
||||
import com.bluelinelabs.conductor.ControllerChangeHandler
|
||||
import com.bluelinelabs.conductor.ControllerChangeType
|
||||
@@ -25,7 +26,6 @@ import eu.kanade.presentation.manga.DownloadAction
|
||||
import eu.kanade.presentation.manga.MangaScreen
|
||||
import eu.kanade.presentation.manga.components.DeleteChaptersDialog
|
||||
import eu.kanade.presentation.manga.components.DownloadCustomAmountDialog
|
||||
import eu.kanade.presentation.util.calculateWindowWidthSizeClass
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
@@ -52,6 +52,7 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||
import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -112,10 +113,13 @@ class MangaController : FullComposeController<MangaPresenter> {
|
||||
val isHttpSource = remember { successState.source is HttpSource }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
val configuration = LocalConfiguration.current
|
||||
val isTabletUi = remember { configuration.isTabletUi() } // won't survive config change
|
||||
|
||||
MangaScreen(
|
||||
state = successState,
|
||||
snackbarHostState = snackbarHostState,
|
||||
windowWidthSizeClass = calculateWindowWidthSizeClass(),
|
||||
isTabletUi = isTabletUi,
|
||||
onBackClicked = router::popCurrentController,
|
||||
onChapterClicked = this::openChapter,
|
||||
onDownloadChapter = this::onDownloadChapters.takeIf { !successState.source.isLocalOrStub() },
|
||||
|
||||
@@ -6,9 +6,10 @@ import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.with
|
||||
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.core.os.bundleOf
|
||||
import cafe.adriel.voyager.navigator.Navigator
|
||||
import cafe.adriel.voyager.transitions.ScreenTransition
|
||||
@@ -19,8 +20,8 @@ import eu.kanade.presentation.more.settings.screen.SettingsGeneralScreen
|
||||
import eu.kanade.presentation.more.settings.screen.SettingsMainScreen
|
||||
import eu.kanade.presentation.util.LocalBackPress
|
||||
import eu.kanade.presentation.util.LocalRouter
|
||||
import eu.kanade.presentation.util.calculateWindowWidthSizeClass
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BasicFullComposeController
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
|
||||
class SettingsMainController(bundle: Bundle = bundleOf()) : BasicFullComposeController(bundle) {
|
||||
|
||||
@@ -39,8 +40,9 @@ class SettingsMainController(bundle: Bundle = bundleOf()) : BasicFullComposeCont
|
||||
@Composable
|
||||
override fun ComposeContent() {
|
||||
CompositionLocalProvider(LocalRouter provides router) {
|
||||
val widthSizeClass = calculateWindowWidthSizeClass()
|
||||
if (widthSizeClass == WindowWidthSizeClass.Compact) {
|
||||
val configuration = LocalConfiguration.current
|
||||
val isTabletUi = remember { configuration.isTabletUi() } // won't survive config change
|
||||
if (!isTabletUi) {
|
||||
Navigator(
|
||||
screen = if (toBackupScreen) {
|
||||
SettingsBackupScreen()
|
||||
|
||||
@@ -50,8 +50,6 @@ import java.io.File
|
||||
import kotlin.math.max
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
private const val TABLET_UI_MIN_SCREEN_WIDTH_DP = 720
|
||||
|
||||
/**
|
||||
* Copies a string to clipboard
|
||||
*
|
||||
@@ -263,28 +261,46 @@ fun Context.createFileInCacheDir(name: String): File {
|
||||
return file
|
||||
}
|
||||
|
||||
/**
|
||||
* We consider anything with a width of >= 720dp as a tablet, i.e. with layouts in layout-sw720dp.
|
||||
*/
|
||||
fun Context.isTablet(): Boolean {
|
||||
return resources.configuration.smallestScreenWidthDp >= TABLET_UI_MIN_SCREEN_WIDTH_DP
|
||||
private const val TABLET_UI_REQUIRED_SCREEN_WIDTH_DP = 720
|
||||
|
||||
// some tablets have screen width like 711dp = 1600px / 2.25
|
||||
private const val TABLET_UI_MIN_SCREEN_WIDTH_PORTRAIT_DP = 700
|
||||
|
||||
// make sure icons on the nav rail fit
|
||||
private const val TABLET_UI_MIN_SCREEN_WIDTH_LANDSCAPE_DP = 600
|
||||
|
||||
fun Context.isTabletUi(): Boolean {
|
||||
return resources.configuration.isTabletUi()
|
||||
}
|
||||
|
||||
fun Configuration.isTabletUi(): Boolean {
|
||||
return smallestScreenWidthDp >= TABLET_UI_REQUIRED_SCREEN_WIDTH_DP
|
||||
}
|
||||
|
||||
fun Configuration.isAutoTabletUiAvailable(): Boolean {
|
||||
return smallestScreenWidthDp >= TABLET_UI_MIN_SCREEN_WIDTH_LANDSCAPE_DP
|
||||
}
|
||||
|
||||
// TODO: move the logic to `isTabletUi()` when main activity is rewritten in Compose
|
||||
fun Context.prepareTabletUiContext(): Context {
|
||||
val configuration = resources.configuration
|
||||
val expected = when (Injekt.get<UiPreferences>().tabletUiMode().get()) {
|
||||
TabletUiMode.AUTOMATIC -> isTablet()
|
||||
TabletUiMode.AUTOMATIC ->
|
||||
configuration.smallestScreenWidthDp >= when (configuration.orientation) {
|
||||
Configuration.ORIENTATION_PORTRAIT -> TABLET_UI_MIN_SCREEN_WIDTH_PORTRAIT_DP
|
||||
else -> TABLET_UI_MIN_SCREEN_WIDTH_LANDSCAPE_DP
|
||||
}
|
||||
TabletUiMode.ALWAYS -> true
|
||||
TabletUiMode.LANDSCAPE -> configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
TabletUiMode.NEVER -> false
|
||||
}
|
||||
if (configuration.smallestScreenWidthDp >= TABLET_UI_MIN_SCREEN_WIDTH_DP != expected) {
|
||||
if (configuration.isTabletUi() != expected) {
|
||||
val overrideConf = Configuration()
|
||||
overrideConf.setTo(configuration)
|
||||
overrideConf.smallestScreenWidthDp = if (expected) {
|
||||
overrideConf.smallestScreenWidthDp.coerceAtLeast(TABLET_UI_MIN_SCREEN_WIDTH_DP)
|
||||
overrideConf.smallestScreenWidthDp.coerceAtLeast(TABLET_UI_REQUIRED_SCREEN_WIDTH_DP)
|
||||
} else {
|
||||
overrideConf.smallestScreenWidthDp.coerceAtMost(TABLET_UI_MIN_SCREEN_WIDTH_DP - 1)
|
||||
overrideConf.smallestScreenWidthDp.coerceAtMost(TABLET_UI_REQUIRED_SCREEN_WIDTH_DP - 1)
|
||||
}
|
||||
return createConfigurationContext(overrideConf)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import androidx.core.view.isVisible
|
||||
import androidx.customview.view.AbsSavedState
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import eu.kanade.tachiyomi.util.system.isTablet
|
||||
import eu.kanade.tachiyomi.util.system.isTabletUi
|
||||
import eu.kanade.tachiyomi.util.view.findChild
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ class TachiyomiCoordinatorLayout @JvmOverloads constructor(
|
||||
) {
|
||||
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
|
||||
// Disable elevation overlay when tabs are visible
|
||||
if (context.isTablet().not()) {
|
||||
if (context.isTabletUi().not()) {
|
||||
if (target is ComposeView) {
|
||||
val scrollCondition = if (type == ViewCompat.TYPE_NON_TOUCH) {
|
||||
dyUnconsumed >= 0
|
||||
|
||||
Reference in New Issue
Block a user