mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: use two columns on wide screens
Home and Settings are columns of cards, which became very wide and sparse on large windows. Add a small AdaptiveColumns helper that splits the content into two equal columns on expanded width windows, capped in width and centered, and falls back to the existing single column otherwise. Settings wraps each title and card pair so they stay together, and moves the App section to the second column when the root-only sections are hidden. The Superuser detail page only has a few rows, so cap its width and center it instead of splitting it. Assisted-by: Claude Opus 5.5
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package com.topjohnwu.magisk.ui.component
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.window.core.layout.WindowWidthSizeClass
|
||||
|
||||
/**
|
||||
* Shows [first] and [second] side by side as two equal columns, centered and capped in width,
|
||||
* on expanded width windows. Otherwise, shows them one after the other in a single column.
|
||||
*/
|
||||
@Composable
|
||||
fun AdaptiveColumns(
|
||||
modifier: Modifier = Modifier,
|
||||
spacing: Dp = 12.dp,
|
||||
first: @Composable ColumnScope.() -> Unit,
|
||||
second: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
val twoColumns =
|
||||
currentWindowAdaptiveInfo().windowSizeClass.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED
|
||||
val arrangement = Arrangement.spacedBy(spacing)
|
||||
if (twoColumns) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentWidth(Alignment.CenterHorizontally)
|
||||
.widthIn(max = 1200.dp),
|
||||
horizontalArrangement = arrangement,
|
||||
) {
|
||||
Column(Modifier.weight(1f), verticalArrangement = arrangement, content = first)
|
||||
Column(Modifier.weight(1f), verticalArrangement = arrangement, content = second)
|
||||
}
|
||||
} else {
|
||||
Column(modifier, verticalArrangement = arrangement) {
|
||||
first()
|
||||
second()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,7 @@ import com.topjohnwu.magisk.core.ktx.toast
|
||||
import com.topjohnwu.magisk.core.tasks.AppMigration
|
||||
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
|
||||
import com.topjohnwu.magisk.ui.MainActivity
|
||||
import com.topjohnwu.magisk.ui.component.AdaptiveColumns
|
||||
import com.topjohnwu.magisk.ui.component.MagiskDialog
|
||||
import com.topjohnwu.magisk.ui.component.MarkdownTextAsync
|
||||
import com.topjohnwu.magisk.ui.component.rememberLoadingDialog
|
||||
@@ -268,7 +269,7 @@ fun HomeScreen(
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
AdaptiveColumns(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.nestedScroll(scrollBehavior.nestedScrollConnection)
|
||||
@@ -276,51 +277,53 @@ fun HomeScreen(
|
||||
.verticalScrollbar(scrollState, contentPadding = PaddingValues(vertical = 12.dp))
|
||||
.verticalScroll(scrollState)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
if (uiState.isNoticeVisible) {
|
||||
NoticeCard(onHide = viewModel::hideNotice)
|
||||
}
|
||||
spacing = 12.dp,
|
||||
first = {
|
||||
if (uiState.isNoticeVisible) {
|
||||
NoticeCard(onHide = viewModel::hideNotice)
|
||||
}
|
||||
|
||||
CoreCard(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
state = uiState.magiskState,
|
||||
version = uiState.magiskInstalledVersion,
|
||||
onInstallClicked = { showInstallDialog = true }
|
||||
)
|
||||
CoreCard(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
state = uiState.magiskState,
|
||||
version = uiState.magiskInstalledVersion,
|
||||
onInstallClicked = { showInstallDialog = true }
|
||||
)
|
||||
|
||||
StatusCard()
|
||||
StatusCard()
|
||||
|
||||
AppCard(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
state = uiState.appState,
|
||||
version = uiState.managerInstalledVersion,
|
||||
remoteVersion = uiState.managerRemoteVersion,
|
||||
progress = uiState.managerProgress,
|
||||
isHidden = context.packageName != BuildConfig.APP_PACKAGE_NAME,
|
||||
onManagerPressed = viewModel::onManagerPressed,
|
||||
onHideRestorePressed = viewModel::onHideRestorePressed,
|
||||
)
|
||||
AppCard(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
state = uiState.appState,
|
||||
version = uiState.managerInstalledVersion,
|
||||
remoteVersion = uiState.managerRemoteVersion,
|
||||
progress = uiState.managerProgress,
|
||||
isHidden = context.packageName != BuildConfig.APP_PACKAGE_NAME,
|
||||
onManagerPressed = viewModel::onManagerPressed,
|
||||
onHideRestorePressed = viewModel::onHideRestorePressed,
|
||||
)
|
||||
},
|
||||
second = {
|
||||
Text(
|
||||
text = stringResource(CoreR.string.home_support_title),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp, top = 8.dp, bottom = 4.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = stringResource(CoreR.string.home_support_title),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp, top = 8.dp, bottom = 4.dp)
|
||||
)
|
||||
SupportCard(onLinkClicked = viewModel::onLinkPressed)
|
||||
|
||||
SupportCard(onLinkClicked = viewModel::onLinkPressed)
|
||||
|
||||
Text(
|
||||
text = stringResource(CoreR.string.home_follow_title),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp, top = 8.dp, bottom = 4.dp)
|
||||
)
|
||||
DevelopersCard(onLinkClicked = viewModel::onLinkPressed)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(CoreR.string.home_follow_title),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(start = 16.dp, top = 8.dp, bottom = 4.dp)
|
||||
)
|
||||
DevelopersCard(onLinkClicked = viewModel::onLinkPressed)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
InstallDialog(
|
||||
|
||||
@@ -3,10 +3,8 @@ package com.topjohnwu.magisk.ui.settings
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
@@ -44,6 +42,7 @@ import com.topjohnwu.magisk.core.model.ColorMode
|
||||
import com.topjohnwu.magisk.core.utils.LocaleSetting
|
||||
import com.topjohnwu.magisk.core.utils.MediaStoreUtils
|
||||
import com.topjohnwu.magisk.ui.ThemeState
|
||||
import com.topjohnwu.magisk.ui.component.AdaptiveColumns
|
||||
import com.topjohnwu.magisk.ui.component.MagiskDialog
|
||||
import com.topjohnwu.magisk.ui.component.SettingsArrow
|
||||
import com.topjohnwu.magisk.ui.component.SettingsDropdown
|
||||
@@ -69,27 +68,37 @@ fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
// Without root, the Magisk and Superuser sections are hidden, so move the
|
||||
// App section to the second column to avoid leaving it empty.
|
||||
val hasRootSections = Info.env.isActive || Info.showSuperUser
|
||||
// Each section emits a title and a card, so wrap them in a Column to keep them together
|
||||
AdaptiveColumns(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.nestedScroll(scrollBehavior.nestedScrollConnection)
|
||||
.padding(padding)
|
||||
.verticalScrollbar(scrollState, contentPadding = PaddingValues(vertical = 12.dp))
|
||||
.verticalScroll(scrollState)
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||
) {
|
||||
CustomizationSection(viewModel = viewModel)
|
||||
Spacer(Modifier.height(16.dp))
|
||||
AppSettingsSection()
|
||||
if (Info.env.isActive) {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
MagiskSection(viewModel = viewModel)
|
||||
}
|
||||
if (Info.showSuperUser) {
|
||||
Spacer(Modifier.height(16.dp))
|
||||
SuperuserSection(viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
spacing = 16.dp,
|
||||
first = {
|
||||
Column { CustomizationSection(viewModel = viewModel) }
|
||||
if (hasRootSections) {
|
||||
Column { AppSettingsSection() }
|
||||
}
|
||||
},
|
||||
second = {
|
||||
if (!hasRootSections) {
|
||||
Column { AppSettingsSection() }
|
||||
}
|
||||
if (Info.env.isActive) {
|
||||
Column { MagiskSection(viewModel = viewModel) }
|
||||
}
|
||||
if (Info.showSuperUser) {
|
||||
Column { SuperuserSection(viewModel = viewModel) }
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@@ -122,6 +124,8 @@ fun SuperuserDetailScreen(
|
||||
.padding(padding)
|
||||
.verticalScrollbar(scrollState, contentPadding = PaddingValues(vertical = 12.dp))
|
||||
.verticalScroll(scrollState)
|
||||
.wrapContentWidth(Alignment.CenterHorizontally)
|
||||
.widthIn(max = 720.dp)
|
||||
.padding(horizontal = 12.dp, vertical = 12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user