From 12b9a45b5f10af3a3b1233300f26cdc1ad3bcf8d Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:18:09 +0200 Subject: [PATCH 01/55] update actions --- .github/workflows/github.yml | 1 + .github/workflows/release-ci.yml | 2 -- .github/workflows/telegram.yml | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index c90a05549..2d8f81f04 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -80,6 +80,7 @@ jobs: id: create_release uses: actions/create-release@v1 with: + prerelease: ${{ github.event.inputs.track == 'beta' }} tag_name: v${{ env.VERSION }} release_name: v${{ env.VERSION }} body: | diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml index c65853621..439db9c5f 100644 --- a/.github/workflows/release-ci.yml +++ b/.github/workflows/release-ci.yml @@ -30,8 +30,6 @@ on: options: - production - beta - - alpha - - qa jobs: # Build step for both official & spoofed flavors diff --git a/.github/workflows/telegram.yml b/.github/workflows/telegram.yml index 13709fe20..19b57abaf 100644 --- a/.github/workflows/telegram.yml +++ b/.github/workflows/telegram.yml @@ -70,6 +70,7 @@ jobs: ${{ env.MESSAGE }} Branch: ${{ env.BRANCH_NAME }} + Track: ${{ github.event.inputs.track }} [Workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) files: | ${{ steps.find_apks.outputs.OFFICIAL_APK_PATH }} From 0f885ed8ff102a8dbe49e0649fdd73a7cf09f42e Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 9 Oct 2026 14:49:24 +0200 Subject: [PATCH 02/55] Update mmrlx libs and local Maven repo Bump mmrlx to 1.0.223, replace the old WebUI-X Portable helper dependencies with the new mmrlx nio and utilities modules, and add `mavenLocal()` to dependency and plugin resolution so locally published artifacts can be resolved. --- app/build.gradle.kts | 5 ++--- gradle/libs.versions.toml | 7 +++---- settings.gradle.kts | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2ae18e4ef..e4f3ebb3c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -197,9 +197,6 @@ dependencies { implementation(projects.compat) implementation(projects.datastore) - implementation(libs.webuix.hwui) - implementation(libs.webuix.helper) - implementation(libs.kotlin.stdlib) implementation(libs.hiddenApiBypass) @@ -272,6 +269,8 @@ dependencies { ksp(libs.square.moshi.kotlin) implementation(libs.mmrlx.terminal) + implementation(libs.mmrlx.nio) + implementation(libs.mmrlx.utilities) implementation(libs.mmrlx.webui.core) implementation("dev.chrisbanes.haze:haze:1.6.10") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 095d5a087..117ba55ba 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -41,8 +41,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.7.6" -mmrlx = "1.0.152" -webuiXPortable = "c92f5f6c3c" +mmrlx = "1.0.223" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.28.0" @@ -139,6 +138,8 @@ markwon-core = "io.noties.markwon:core:4.6.2" hiddenApiBypass = "org.lsposed.hiddenapibypass:hiddenapibypass:6.1" mmrlx-terminal = { module = "dev.mmrlx:terminal", version.ref = "mmrlx" } mmrlx-webui-core = { module = "dev.mmrlx:webui.core", version.ref = "mmrlx" } +mmrlx-nio = { module = "dev.mmrlx:nio", version.ref = "mmrlx" } +mmrlx-utilities = { module = "dev.mmrlx:utilities", version.ref = "mmrlx" } timber = "com.jakewharton.timber:timber:5.0.1" # Dependencies of the included build-logic @@ -155,8 +156,6 @@ material = { group = "com.google.android.material", name = "material", version.r androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" } runtime-android = { group = "androidx.compose.runtime", name = "runtime-android", version.ref = "runtimeAndroidVersion" } androidx-swiperefreshlayout = { group = "androidx.swiperefreshlayout", name = "swiperefreshlayout", version.ref = "swiperefreshlayout" } -webuix-hwui = { module = "com.github.MMRLApp.WebUI-X-Portable:hwui", version.ref = "webuiXPortable" } -webuix-helper = { module = "com.github.MMRLApp.WebUI-X-Portable:helper", version.ref = "webuiXPortable" } [plugins] android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 7910b760c..58879b97a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,7 @@ dependencyResolutionManagement drm@{ repositories { google() mavenCentral() + mavenLocal() maven("https://jitpack.io") if (user != null && pass != null) { @@ -31,6 +32,7 @@ pluginManagement { repositories { google() mavenCentral() + mavenLocal() gradlePluginPortal() } } From a8b99affd365baabd09839c1d5ae59fc9b6564db Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:23:34 +0200 Subject: [PATCH 03/55] Remove SuperUser and app profile screens Deletes the SuperUser feature stack, including its view model, screens, profile editing UI, and composition local wiring. Navigation is updated to remove the SuperUser destination and simplify access checks to root-only gating, and activity-level providers are cleaned up to drop the removed dependency. --- .../mmrl/ui/activity/MMRLComponentActivity.kt | 3 - .../mmrl/ui/navigation/MainDestination.kt | 16 +- .../ui/providable/LocalSuperUserViewModel.kt | 9 - .../ui/screens/appProfile/AppProfileScreen.kt | 232 ------------ .../appProfile/items/RootProfileConfig.kt | 344 ------------------ .../remember/rememberProfileChange.kt | 142 -------- .../ui/screens/superuser/SuperUserItem.kt | 83 ----- .../ui/screens/superuser/SuperUserList.kt | 59 --- .../ui/screens/superuser/SuperUserMenu.kt | 94 ----- .../ui/screens/superuser/SuperUserScreen.kt | 167 --------- .../mmrl/viewmodel/SuperUserViewModel.kt | 249 ------------- 11 files changed, 1 insertion(+), 1397 deletions(-) delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalSuperUserViewModel.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/AppProfileScreen.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/items/RootProfileConfig.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/remember/rememberProfileChange.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserItem.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserList.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserMenu.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserScreen.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SuperUserViewModel.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt index 82d20f0f0..2ce4467da 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt @@ -34,13 +34,11 @@ import com.dergoogler.mmrl.ui.providable.LocalLifecycleScope import com.dergoogler.mmrl.ui.providable.LocalMainNavController import com.dergoogler.mmrl.ui.providable.LocalNavController import com.dergoogler.mmrl.ui.providable.LocalSettings -import com.dergoogler.mmrl.ui.providable.LocalSuperUserViewModel import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.providable.LocalWindowSizeClass import com.dergoogler.mmrl.ui.theme.Colors import com.dergoogler.mmrl.ui.theme.MMRLAppTheme import com.dergoogler.mmrl.viewmodel.SettingsViewModel -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel import com.ramcosta.composedestinations.utils.rememberDestinationsNavigator import dagger.hilt.android.AndroidEntryPoint import dev.dergoogler.mmrl.compat.BuildCompat @@ -225,7 +223,6 @@ fun BaseContent( LocalWindowSizeClass provides windowSizeClass, LocalDestinationsNavigator provides navigator, LocalActivity provides activity, - LocalSuperUserViewModel provides hiltViewModel(activity), LocalSettings provides hiltViewModel(activity), LocalUserPreferences provides preferences, dev.dergoogler.mmrl.compat.core.LocalUriHandler provides diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt index 0962e3c0b..f52c009ff 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt @@ -4,14 +4,11 @@ import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.compose.runtime.Composable import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.platform.ksu.KsuNative import com.dergoogler.mmrl.ui.remember.rememberIsRoot -import com.dergoogler.mmrl.utils.isManager import com.ramcosta.composedestinations.generated.destinations.HomeScreenDestination import com.ramcosta.composedestinations.generated.destinations.ModulesScreenDestination import com.ramcosta.composedestinations.generated.destinations.RepositoriesScreenDestination import com.ramcosta.composedestinations.generated.destinations.SettingsScreenDestination -import com.ramcosta.composedestinations.generated.destinations.SuperUserScreenDestination import com.ramcosta.composedestinations.spec.DirectionDestinationSpec // @NavHostGraph @@ -34,15 +31,6 @@ enum class MainDestination( requiresKernel = false, ), - SuperUser( - direction = SuperUserScreenDestination, - label = R.string.page_superuser, - icon = R.drawable.user, - iconFilled = R.drawable.user_filled, - requiresRoot = true, - requiresKernel = true, - ), - Repository( direction = RepositoriesScreenDestination, label = R.string.page_repositorys, @@ -75,7 +63,5 @@ enum class MainDestination( val MainDestination.isAccessible: Boolean get() { val isRoot = rememberIsRoot() - if (this.requiresRoot && !isRoot) return false - if (this.requiresKernel && !(KsuNative.isManager && isRoot)) return false - return true + return !(this.requiresRoot && !isRoot) } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalSuperUserViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalSuperUserViewModel.kt deleted file mode 100644 index c58ef3c51..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalSuperUserViewModel.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.dergoogler.mmrl.ui.providable - -import androidx.compose.runtime.staticCompositionLocalOf -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel - -val LocalSuperUserViewModel = - staticCompositionLocalOf { - error("CompositionLocal LocalSuperUserViewModel not present") - } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/AppProfileScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/AppProfileScreen.kt deleted file mode 100644 index 96a9c88dc..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/AppProfileScreen.kt +++ /dev/null @@ -1,232 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.appProfile - -import androidx.annotation.StringRes -import androidx.compose.animation.Crossfade -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.WindowInsetsSides -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.only -import androidx.compose.foundation.layout.safeDrawing -import androidx.compose.foundation.layout.size -import androidx.compose.foundation.rememberScrollState -import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Scaffold -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import coil3.compose.AsyncImage -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.platform.ksu.KsuNative -import com.dergoogler.mmrl.ui.component.LocalScreen -import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.RadioDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Start -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title -import com.dergoogler.mmrl.ui.component.toolbar.BlurNavigateUpToolbar -import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings -import com.dergoogler.mmrl.ui.providable.LocalSnackbarHost -import com.dergoogler.mmrl.ui.screens.appProfile.items.RootProfileConfig -import com.dergoogler.mmrl.ui.screens.appProfile.remember.LocalProfileChange -import com.dergoogler.mmrl.ui.screens.appProfile.remember.rememberProfileChange -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel.AppInfo.Companion.loadIcon -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootGraph -import dev.chrisbanes.haze.hazeSource - -@OptIn(ExperimentalMaterial3Api::class) -@Destination -@Composable -fun AppProfileScreen(appInfo: SuperUserViewModel.AppInfo) = - LocalScreenProvider { - val context = LocalContext.current - val snackBarHost = LocalSnackbarHost.current - val bottomBarPaddingValues = LocalMainScreenInnerPaddings.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() - - val (profile, onProfileChange) = rememberProfileChange(appInfo) - - val icon = - remember { - appInfo.loadIcon(context) - } - - CompositionLocalProvider( - LocalProfileChange provides (profile to onProfileChange), - ) { - Scaffold( - modifier = - Modifier - .nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - BlurNavigateUpToolbar( - fade = true, - fadeDistance = 50f, - navigator = LocalDestinationsNavigator.current, - title = stringResource(R.string.profile), - scrollBehavior = scrollBehavior, - ) - }, - snackbarHost = { - LocalScreen.SnackbarHost() - }, - contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal), - ) { paddingValues -> - val isRootGranted = profile.allowSu - - var mode by rememberSaveable(profile, isRootGranted) { - val initialMode = - if (isRootGranted) { - if (profile.rootUseDefault) Mode.Default else Mode.Custom - } else { - if (profile.nonRootUseDefault) Mode.Default else Mode.Custom - } - mutableStateOf(initialMode) - } - - List( - modifier = - Modifier - .hazeSource(LocalHazeState.current) - .verticalScroll(rememberScrollState()), - ) { - Spacer(Modifier.height(paddingValues.calculateTopPadding())) - - Item { - Title(appInfo.label) - Description(appInfo.packageName) - Start { - AsyncImage( - model = icon, - contentDescription = appInfo.label, - modifier = Modifier.size(48.dp), - ) - } - } - - SwitchItem( - checked = isRootGranted, - onChange = { - onProfileChange(profile.copy(allowSu = it)) - }, - ) { - Icon( - painter = painterResource(R.drawable.square_root_2), - ) - Title(R.string.allow_root_access) - Description(R.string.allow_root_access_desc) - } - - RadioDialogItem( - selection = mode, - options = mode.dialogOptions, - onConfirm = { - if (isRootGranted) { - if (it.value == Mode.Default || it.value == Mode.Custom) { - onProfileChange(profile.copy(rootUseDefault = it.value == Mode.Default)) - } - - mode = it.value - - return@RadioDialogItem - } - - onProfileChange(profile.copy(nonRootUseDefault = (it.value == Mode.Default))) - }, - ) { - Icon(painter = painterResource(R.drawable.disabled)) - Title(R.string.profile) - it.title.nullable { t -> - Description(t) - } - } - - Crossfade( - targetState = (isRootGranted to mode), - label = "", - ) { (granted, currentMode) -> - List { - if (granted) { - if (currentMode == Mode.Custom) { - RootProfileConfig( - fixedName = true, - profile = profile, - onProfileChange = onProfileChange, - ) - } - - return@List - } - - val modifyEnabled = currentMode == Mode.Custom - - SwitchItem( - checked = - if (modifyEnabled) { - profile.umountModules - } else { - KsuNative.isDefaultUmountModules() - }, - enabled = modifyEnabled, - onChange = { - onProfileChange( - profile.copy( - umountModules = it, - nonRootUseDefault = false, - ), - ) - }, - ) { - Title(R.string.settings_umount_modules_default) - Description(R.string.settings_umount_modules_default_desc) - } - } - } - - Spacer(Modifier.height(bottomBarPaddingValues.calculateBottomPadding())) - } - } - } - } - -private enum class Mode( - @StringRes private val res: Int, -) { - Default(R.string.profile_default), - Custom(R.string.profile_custom), - ; - - @get:Composable - val dialogOptions: List> - get() = - entries.map { - RadioDialogItem( - value = it, - title = it.text, - ) - } - - @get:Composable - val text: String get() = stringResource(res) -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/items/RootProfileConfig.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/items/RootProfileConfig.kt deleted file mode 100644 index 4252ab975..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/items/RootProfileConfig.kt +++ /dev/null @@ -1,344 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.appProfile.items - -import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalSoftwareKeyboardController -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.input.ImeAction -import androidx.compose.ui.text.input.KeyboardType -import androidx.core.text.isDigitsOnly -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.platform.SePolicy.isSepolicyValid -import com.dergoogler.mmrl.platform.ksu.Capabilities -import com.dergoogler.mmrl.platform.ksu.Groups -import com.dergoogler.mmrl.platform.ksu.Profile -import com.dergoogler.mmrl.platform.ksu.Profile.Namespace -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.CheckboxDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.CheckboxItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.RadioDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Section -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.TextEditDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.DialogSupportingText -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title - -@Composable -fun ListScope.RootProfileConfig( - modifier: Modifier = Modifier, - fixedName: Boolean, - profile: Profile, - onProfileChange: (Profile) -> Unit, -) { - Section( - title = stringResource(R.string.profile_custom), - ) { - RadioDialogItem( - selection = profile.namespace, - options = NamespaceOptions, - onConfirm = { - onProfileChange(profile.copy(namespace = it.value)) - }, - ) { - Title(R.string.profile_namespace) - it.title.nullable { t -> - Description(t) - } - } - - UidPanel( - uid = profile.uid, - label = "User Identifier (UID)", - onUidChange = { - onProfileChange( - profile.copy( - uid = it, - rootUseDefault = false, - ), - ) - }, - ) - - UidPanel( - uid = profile.gid, - label = "Group Identifier (GID)", - onUidChange = { - onProfileChange( - profile.copy( - gid = it, - rootUseDefault = false, - ), - ) - }, - ) - - val selectedGroups = - profile.groups.ifEmpty { listOf(0) }.let { e -> - e.mapNotNull { g -> - Groups.entries.find { it.gid == g } - } - } - - GroupsPanel(selectedGroups) { - onProfileChange( - profile.copy( - groups = it.map { group -> group.gid }.ifEmpty { listOf(0) }, - rootUseDefault = false, - ), - ) - } - - val selectedCaps = - profile.capabilities.mapNotNull { e -> - Capabilities.entries.find { it.cap == e } - } - - CapsPanel(selectedCaps) { - onProfileChange( - profile.copy( - capabilities = it.map { cap -> cap.cap }, - rootUseDefault = false, - ), - ) - } - } - - Section( - stringResource(R.string.profile_selinux), - ) { - SELinuxPanel( - profile = profile, - onSELinuxChange = { domain, rules -> - onProfileChange( - profile.copy( - context = domain, - rules = rules, - rootUseDefault = false, - ), - ) - }, - ) - } -} - -@Composable -fun ListScope.GroupsPanel( - selected: List, - closeSelection: (selection: List) -> Unit, -) { - val groups = - remember(selected) { - Groups.entries.toTypedArray().sortedWith( - compareBy { if (selected.contains(it)) 0 else 1 } - .then( - compareBy { - when (it) { - Groups.ROOT -> 0 - Groups.SYSTEM -> 1 - Groups.SHELL -> 2 - else -> Int.MAX_VALUE - } - }, - ).then(compareBy { it.name }), - ) - } - - val options = - remember(groups) { - groups.map { value -> - CheckboxItem( - value = value, - title = value.display, - desc = value.desc, - checked = selected.contains(value), - ) - } - } - - CheckboxDialogItem( - strict = false, - multiple = true, - maxChoices = 32, - options = options, - onConfirm = { - closeSelection(it.map { item -> item.value }) - }, - ) { - Title(R.string.profile_groups) - Labels { - selected.forEach { - LabelItem(it.display) - } - } - } -} - -@Composable -fun ListScope.CapsPanel( - selected: Collection, - closeSelection: (selection: List) -> Unit, -) { - val caps = - remember(selected) { - Capabilities.entries.toTypedArray().sortedWith( - compareBy { if (selected.contains(it)) 0 else 1 } - .then(compareBy { it.name }), - ) - } - - val options = - remember(caps) { - caps.map { value -> - CheckboxItem( - value = value, - title = value.display, - desc = value.desc, - checked = selected.contains(value), - ) - } - } - - CheckboxDialogItem( - strict = false, - multiple = true, - options = options, - onConfirm = { - closeSelection(it.map { item -> item.value }) - }, - ) { - Title(R.string.profile_capabilities) - Labels { - selected.forEach { - LabelItem(it.display) - } - } - } -} - -@Composable -private fun ListScope.UidPanel( - uid: Int, - label: String, - onUidChange: (Int) -> Unit, -) { - val keyboardController = LocalSoftwareKeyboardController.current - - var lastValidUid by remember { - mutableIntStateOf(uid) - } - - TextEditDialogItem( - value = uid.toString(), - onValid = { - isTextValidUid(it) - }, - keyboardOptions = - KeyboardOptions( - keyboardType = KeyboardType.Number, - imeAction = ImeAction.Done, - ), - keyboardActions = - KeyboardActions(onDone = { - keyboardController?.hide() - }), - onConfirm = { - if (it.isEmpty()) { - onUidChange(0) - return@TextEditDialogItem - } - val valid = isTextValidUid(it) - - val targetUid = if (valid) it.toInt() else lastValidUid - if (valid) { - lastValidUid = it.toInt() - } - - onUidChange(targetUid) - }, - ) { - Title(label) - Description(it.value) - if (it.isError) { - DialogSupportingText("Invalid Input!") - } - } -} - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -private fun ListScope.SELinuxPanel( - profile: Profile, - onSELinuxChange: (domain: String, rules: String) -> Unit, -) { - TextEditDialogItem( - value = profile.context, - strict = false, - onValid = { - it.matches(Regex("^[a-z_]+:[a-z0-9_]+:[a-z0-9_]+(:[a-z0-9_]+)?$")) - }, - onConfirm = { - onSELinuxChange(it, profile.rules) - }, - ) { - if (it.isError) { - DialogSupportingText(stringResource(R.string.profile_selinux_context_invalid)) - } - - Title(stringResource(R.string.profile_selinux_context)) - Description(it.value) - } - - TextEditDialogItem( - value = profile.rules, - strict = false, - onValid = { - isSepolicyValid(it) - }, - onConfirm = { - onSELinuxChange(profile.context, it) - }, - ) { - Title(stringResource(R.string.profile_selinux_rules)) - - if (it.isError) { - DialogSupportingText(stringResource(R.string.profile_selinux_rules_invalid)) - } - - if (it.value.isBlank()) { - Description(stringResource(R.string.empty)) - } else { - Description(it.value) - } - } -} - -@get:Composable -private val NamespaceOptions: List> - get() { - return enumValues().map { - val title = - when (it) { - Namespace.INHERITED -> stringResource(R.string.profile_namespace_inherited) - Namespace.GLOBAL -> stringResource(R.string.profile_namespace_global) - Namespace.INDIVIDUAL -> stringResource(R.string.profile_namespace_individual) - } - - RadioDialogItem( - value = it.ordinal, - title = title, - ) - } - } - -private fun isTextValidUid(text: String): Boolean = - text.isNotEmpty() && text.isDigitsOnly() && text.toInt() >= 0 && text.toInt() <= Int.MAX_VALUE diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/remember/rememberProfileChange.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/remember/rememberProfileChange.kt deleted file mode 100644 index aececf5c7..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/appProfile/remember/rememberProfileChange.kt +++ /dev/null @@ -1,142 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.appProfile.remember - -import android.util.Log -import androidx.compose.material3.SnackbarHostState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.runtime.staticCompositionLocalOf -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.platform.SePolicy -import com.dergoogler.mmrl.platform.SePolicy.getSepolicy -import com.dergoogler.mmrl.platform.ksu.KsuNative -import com.dergoogler.mmrl.platform.ksu.Profile -import com.dergoogler.mmrl.ui.providable.LocalSnackbarHost -import com.dergoogler.mmrl.ui.providable.LocalSuperUserViewModel -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel -import kotlinx.coroutines.launch - -@Composable -fun rememberProfileChange(info: SuperUserViewModel.AppInfo): Pair Unit> { - val snackBarHost = LocalSnackbarHost.current - val scope = rememberCoroutineScope() - val viewModel = LocalSuperUserViewModel.current - - val initialProfile = - remember(info.packageName, info.uid) { - val profile = KsuNative.getAppProfile(info.packageName, info.uid) - if (profile.allowSu) { - profile.rules = getSepolicy(info.packageName) - } - profile - } - - var profile by rememberSaveable(info.packageName, info.uid) { - mutableStateOf(initialProfile) - } - - // Cache string resources to avoid recomposition - val errorMessages = - remember { - ErrorMessages( - failToUpdateAppProfile = R.string.failed_to_update_app_profile, - failToUpdateSepolicy = R.string.failed_to_update_sepolicy, - suNotAllowed = R.string.su_not_allowed, - ) - } - - val updateProfile: (Profile) -> Unit = - remember(info, snackBarHost, scope, viewModel) { - { newProfile -> - scope.launch { - try { - val result = - updateProfileSafely( - newProfile, - info, - errorMessages, - snackBarHost, - ) - if (result.isSuccess) { - profile = newProfile - viewModel.updateAppProfile(info.packageName, newProfile) - } - } catch (e: Exception) { - Log.e("ProfileChange", "Error updating profile", e) - snackBarHost.showSnackbar("An unexpected error occurred") - } - } - } - } - - return profile to updateProfile -} - -private data class ErrorMessages( - val failToUpdateAppProfile: Int, - val failToUpdateSepolicy: Int, - val suNotAllowed: Int, -) - -private sealed class UpdateResult { - object Success : UpdateResult() - - data class Error( - val messageRes: Int, - val args: List, - ) : UpdateResult() - - val isSuccess: Boolean get() = this is Success -} - -private suspend fun updateProfileSafely( - profile: Profile, - info: SuperUserViewModel.AppInfo, - errorMessages: ErrorMessages, - snackBarHost: SnackbarHostState, -): UpdateResult { - if (profile.allowSu) { - // Validate system UID restrictions - if (isSystemUidForbidden(info.uid)) { - snackBarHost.showSnackbar( - // You'll need to resolve string resource here or pass context - "SU not allowed for system UID ${info.uid}", - ) - return UpdateResult.Error(errorMessages.suNotAllowed, listOf(info.label)) - } - - // Handle SELinux policy updates - if (shouldUpdateSepolicy(profile)) { - val sepolicyResult = SePolicy.setSePolicy(profile.name, profile.rules) - if (!sepolicyResult) { - snackBarHost.showSnackbar("Failed to update SEPolicy for ${info.label}") - return UpdateResult.Error(errorMessages.failToUpdateSepolicy, listOf(info.label)) - } - } - } - - // Update app profile - val profileUpdateSuccess = KsuNative.setAppProfile(profile) - if (!profileUpdateSuccess) { - snackBarHost.showSnackbar("Failed to update app profile for ${info.label}") - return UpdateResult.Error(errorMessages.failToUpdateAppProfile, listOf(info.uid)) - } - - return UpdateResult.Success -} - -private fun isSystemUidForbidden(uid: Int): Boolean { - // sync with allowlist.c - forbid_system_uid - return uid < 2000 && uid != 1000 -} - -private fun shouldUpdateSepolicy(profile: Profile): Boolean = !profile.rootUseDefault && profile.rules.isNotEmpty() - -val LocalProfileChange = - staticCompositionLocalOf Unit>> { - error("CompositionLocal LocalProfileChange not present") - } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserItem.kt deleted file mode 100644 index 26affa14b..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserItem.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.superuser - -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.size -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.unit.dp -import coil3.compose.AsyncImage -import com.dergoogler.mmrl.platform.ksu.KsuNative -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.LabelItemDefaults -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Start -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel.AppInfo.Companion.loadIcon - -@OptIn(ExperimentalLayoutApi::class) -@Composable -fun ListScope.SuperUserItem( - app: SuperUserViewModel.AppInfo, - onClick: () -> Unit, -) { - val context = LocalContext.current - - ButtonItem( - onClick = onClick, - ) { - Title(app.label) - Description(app.packageName) - - Start { - AsyncImage( - model = app.loadIcon(context), - contentDescription = app.label, - modifier = Modifier.size(48.dp), - ) - } - - Labels { - if (app.allowSu) { - LabelItem( - text = "ROOT", - ) - } else { - if (KsuNative.uidShouldUmount(app.uid)) { - LabelItem( - text = "UMOUNT", - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.secondaryContainer, - contentColor = MaterialTheme.colorScheme.onSecondaryContainer, - ), - ) - } - } - if (app.hasCustomProfile) { - LabelItem( - text = "CUSTOM", - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.tertiaryContainer, - contentColor = MaterialTheme.colorScheme.onTertiaryContainer, - ), - ) - } else if (!app.allowSu && !KsuNative.uidShouldUmount(app.uid)) { - LabelItem( - text = "DEFAULT", - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.primaryContainer, - contentColor = MaterialTheme.colorScheme.onPrimaryContainer, - ), - ) - } - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserList.kt deleted file mode 100644 index 76ddbdcee..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserList.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.superuser - -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.calculateStartPadding -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.items -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalLayoutDirection -import androidx.compose.ui.unit.dp -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.scaffold.ScaffoldScope -import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings -import com.dergoogler.mmrl.viewmodel.SuperUserViewModel -import com.ramcosta.composedestinations.generated.destinations.AppProfileScreenDestination -import dev.chrisbanes.haze.hazeSource - -@Composable -fun ScaffoldScope.SuperUserList( - innerPadding: PaddingValues, - list: List, - state: LazyListState, -) { - val navigator = LocalDestinationsNavigator.current - val paddingValues = LocalMainScreenInnerPaddings.current - val layoutDirection = LocalLayoutDirection.current - - this@SuperUserList.ResponsiveContent { - List { - LazyColumn( - state = state, - modifier = - Modifier - .fillMaxSize() - .hazeSource(state = LocalHazeState.current), - contentPadding = - PaddingValues( - top = innerPadding.calculateTopPadding(), - start = innerPadding.calculateStartPadding(layoutDirection), - bottom = paddingValues.calculateBottomPadding(), - end = 0.dp, - ), - ) { - items( - items = list, - key = { it.packageName + it.uid }, - ) { app -> - SuperUserItem(app) { - navigator.navigate(AppProfileScreenDestination(app)) - } - } - } - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserMenu.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserMenu.kt deleted file mode 100644 index 22d71a528..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserMenu.kt +++ /dev/null @@ -1,94 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.superuser - -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.datastore.model.SuperUserMenu -import com.dergoogler.mmrl.ui.component.BottomSheet -import com.dergoogler.mmrl.ui.component.MenuChip -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences - -@Composable -fun SuperUserMenu(setMenu: (SuperUserMenu) -> Unit) { - val userPreferences = LocalUserPreferences.current - var open by rememberSaveable { mutableStateOf(false) } - - IconButton( - onClick = { open = true }, - ) { - Icon( - painter = painterResource(id = R.drawable.filter_outlined), - contentDescription = null, - ) - - if (open) { - MenuBottomSheet( - onClose = { open = false }, - menu = userPreferences.superUserMenu, - setMenu = setMenu, - ) - } - } -} - -@Composable -private fun MenuBottomSheet( - onClose: () -> Unit, - menu: SuperUserMenu, - setMenu: (SuperUserMenu) -> Unit, -) = BottomSheet(onDismissRequest = onClose) { - Text( - text = stringResource(id = R.string.menu_advanced_menu), - style = MaterialTheme.typography.headlineSmall, - modifier = Modifier.align(Alignment.CenterHorizontally), - ) - - Column( - modifier = Modifier.padding(all = 18.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text( - text = stringResource(id = R.string.menu_sort_mode), - style = MaterialTheme.typography.titleSmall, - ) - - FlowRow( - modifier = - Modifier - .fillMaxWidth(1f) - .wrapContentHeight(align = Alignment.Top), - horizontalArrangement = Arrangement.spacedBy(8.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - /*MenuChip( - selected = menu.pinHasRoot, - onClick = { setMenu(menu.copy(pinHasRoot = !menu.pinHasRoot)) }, - label = { Text(text = stringResource(id = R.string.menu_pin_installed)) } - )*/ - - MenuChip( - selected = menu.showSystemApps, - onClick = { setMenu(menu.copy(showSystemApps = !menu.showSystemApps)) }, - label = { Text(text = stringResource(id = R.string.menu_show_system_apps)) }, - ) - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserScreen.kt deleted file mode 100644 index 2d1f727d3..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/superuser/SuperUserScreen.kt +++ /dev/null @@ -1,167 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.superuser - -import androidx.activity.compose.BackHandler -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior -import androidx.compose.material3.pulltorefresh.PullToRefreshBox -import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator -import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.res.painterResource -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.datastore.model.SuperUserMenu -import com.dergoogler.mmrl.ext.currentScreenWidth -import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ui.component.Loading -import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.PageIndicator -import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar -import com.dergoogler.mmrl.ui.providable.LocalSuperUserViewModel -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootGraph - -@Destination -@Composable -fun SuperUserScreen() = - LocalScreenProvider { - val userPrefs = LocalUserPreferences.current - val viewModel = LocalSuperUserViewModel.current - - val list by viewModel.local.collectAsStateWithLifecycle() - val query by viewModel.query.collectAsStateWithLifecycle() - val state by viewModel.screenState.collectAsStateWithLifecycle() - val isLoading by viewModel.isLoading.collectAsStateWithLifecycle() - - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() - - val pullToRefreshState = rememberPullToRefreshState() - - BackHandler( - enabled = viewModel.isSearch, - onBack = viewModel::closeSearch, - ) - - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - isSearch = viewModel.isSearch, - query = query, - onQueryChange = viewModel::search, - onOpenSearch = viewModel::openSearch, - onCloseSearch = viewModel::closeSearch, - setMenu = viewModel::setSuperUserMenu, - scrollBehavior = scrollBehavior, - ) - }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - if (isLoading) { - Loading() - } - - if (list.isEmpty() && !isLoading) { - PageIndicator( - icon = R.drawable.keyframes, - text = if (viewModel.isSearch) R.string.search_empty else R.string.modules_empty, - ) - } - - PullToRefreshBox( - state = pullToRefreshState, - isRefreshing = state.isRefreshing, - onRefresh = viewModel::fetchAppList, - indicator = { - Indicator( - modifier = - Modifier.align(Alignment.TopCenter).let { - if (!userPrefs.enableBlur) { - it.padding(top = innerPadding.calculateTopPadding()) - } else { - it - } - }, - isRefreshing = state.isRefreshing, - state = pullToRefreshState, - ) - }, - ) { - this@Scaffold.SuperUserList( - innerPadding = innerPadding, - list = list, - state = viewModel.listState, - ) - } - } - } - -@Composable -private fun TopBar( - isSearch: Boolean, - query: String, - onQueryChange: (String) -> Unit, - onOpenSearch: () -> Unit, - onCloseSearch: () -> Unit, - setMenu: (SuperUserMenu) -> Unit, - scrollBehavior: TopAppBarScrollBehavior, -) { - val width = currentScreenWidth() - - var currentQuery by remember { mutableStateOf(query) } - DisposableEffect(isSearch) { - onDispose { currentQuery = "" } - } - - BlurSearchToolbar( - scrollBehavior = scrollBehavior, - isSearch = isSearch, - query = currentQuery, - fade = true, - fadeDistance = 50f, - onQueryChange = { - onQueryChange(it) - currentQuery = it - }, - onClose = { - onCloseSearch() - currentQuery = "" - }, - title = { - if (!width.isSmall) return@BlurSearchToolbar - - TopAppBarEventIcon() - }, - actions = { - if (!isSearch) { - IconButton( - onClick = onOpenSearch, - ) { - Icon( - painter = painterResource(id = R.drawable.search), - contentDescription = null, - ) - } - } - - SuperUserMenu( - setMenu = setMenu, - ) - }, - ) -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SuperUserViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SuperUserViewModel.kt deleted file mode 100644 index 25dd5f0eb..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SuperUserViewModel.kt +++ /dev/null @@ -1,249 +0,0 @@ -package com.dergoogler.mmrl.viewmodel - -import android.app.Application -import android.content.Context -import android.content.pm.ApplicationInfo -import android.content.pm.PackageInfo -import android.graphics.Bitmap -import android.graphics.drawable.Drawable -import android.os.Parcelable -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateMapOf -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue -import androidx.compose.ui.unit.Density -import androidx.core.graphics.drawable.toBitmap -import androidx.lifecycle.viewModelScope -import coil3.request.ImageRequest -import coil3.request.crossfade -import com.dergoogler.mmrl.datastore.UserPreferencesRepository -import com.dergoogler.mmrl.datastore.model.SuperUserMenu -import com.dergoogler.mmrl.platform.PlatformManager -import com.dergoogler.mmrl.platform.ksu.KsuNative -import com.dergoogler.mmrl.platform.ksu.Profile -import com.dergoogler.mmrl.repository.LocalRepository -import com.dergoogler.mmrl.repository.ModulesRepository -import com.dergoogler.mmrl.utils.packages -import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onEach -import kotlinx.coroutines.flow.stateIn -import kotlinx.coroutines.flow.update -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import kotlinx.parcelize.Parcelize -import java.text.Collator -import java.util.Locale -import javax.inject.Inject - -@HiltViewModel -class SuperUserViewModel - @Inject - constructor( - application: Application, - localRepository: LocalRepository, - modulesRepository: ModulesRepository, - userPreferencesRepository: UserPreferencesRepository, - ) : MMRLViewModel(application, localRepository, modulesRepository, userPreferencesRepository) { - private val superUserMenu - get() = userPreferencesRepository.data.map { it.superUserMenu } - - var isSearch by mutableStateOf(false) - private set - private val keyFlow = MutableStateFlow("") - val query get() = keyFlow.asStateFlow() - - val listState: LazyListState = LazyListState() - - private val cacheFlow = MutableStateFlow(listOf()) - private val localFlow = MutableStateFlow(listOf()) - val local get() = localFlow.asStateFlow() - - private var isLoadingFlow = MutableStateFlow(false) - val isLoading get() = isLoadingFlow.asStateFlow() - - private val profileOverrides = mutableStateMapOf() - - val screenState: StateFlow = - localFlow - .combine(isLoadingFlow) { items, isRefreshing -> - SuperUserScreenState(items = items, isRefreshing = isRefreshing) - }.stateIn( - scope = viewModelScope, - started = SharingStarted.WhileSubscribed(5000), - initialValue = SuperUserScreenState(), - ) - - init { - providerObserver() - dataObserver() - keyObserver() - } - - private fun providerObserver() { - PlatformManager.isAliveFlow - .onEach { if (it) fetchAppList() } - .launchIn(viewModelScope) - } - - private val comparator get() = - compareBy { - when { - it.profile != null && it.profile.allowSu -> 0 - it.profile != null && - ( - if (it.profile.allowSu) !it.profile.rootUseDefault else !it.profile.nonRootUseDefault - ) -> 1 - - else -> 2 - } - }.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label)) - - private fun dataObserver() { - combine(cacheFlow, superUserMenu) { list, menu -> - if (list.isEmpty()) return@combine - - val comparator = - compareBy { - when { - it.allowSu -> 0 - it.hasCustomProfile -> 1 - else -> 2 - } - }.then(compareBy(Collator.getInstance(Locale.getDefault()), AppInfo::label)) - - localFlow.value = - list - .filter { - menu.showSystemApps || - (it.uid == 2000 || (it.packageInfo.applicationInfo!!.flags and ApplicationInfo.FLAG_SYSTEM) == 0) - }.sortedWith(comparator) - }.launchIn(viewModelScope) - } - - private fun keyObserver() { - combine(keyFlow, cacheFlow, superUserMenu) { key, source, menu -> - val newKey = key.trim() - localFlow.value = - source - .filter { - if (newKey.isNotBlank()) { - it.label.contains(newKey, true) || - it.packageName.contains(newKey, true) - } else { - true - } - }.map { app -> - profileOverrides[app.packageName]?.let { app.copy(profile = it) } ?: app - }.filter { - menu.showSystemApps || - (it.uid == 2000 || (it.packageInfo.applicationInfo!!.flags and ApplicationInfo.FLAG_SYSTEM) == 0) - }.sortedWith(comparator) - }.launchIn(viewModelScope) - } - - fun search(key: String) { - keyFlow.value = key - } - - fun openSearch() { - isSearch = true - } - - fun closeSearch() { - isSearch = false - keyFlow.value = "" - } - - fun setSuperUserMenu(value: SuperUserMenu) = - viewModelScope.launch { - userPreferencesRepository.setSuperUserMenu(value) - } - - private inline fun T.refreshing(block: T.() -> Unit) { - isLoadingFlow.update { true } - block() - isLoadingFlow.update { false } - } - - fun fetchAppList() = - viewModelScope.launch { - refreshing { - cacheFlow.value = - withContext(Dispatchers.IO) { - getAppList() - } - profileOverrides.clear() - } - } - - private fun getAppList(): List { - val pm = context.packageManager - val packages = context.packages - return packages - .map { pkg -> - val appInfo = pkg.applicationInfo!! - val uid = appInfo.uid - val profile = KsuNative.getAppProfile(pkg.packageName, uid) - AppInfo( - label = appInfo.loadLabel(pm).toString(), - packageInfo = pkg, - profile = profile, - ) - }.filter { it.packageName != context.packageName } - } - - fun updateAppProfile( - packageName: String, - newProfile: Profile, - ) { - profileOverrides[packageName] = newProfile - } - - @Parcelize - data class AppInfo( - val label: String, - val packageInfo: PackageInfo, - val profile: Profile? = null, - ) : Parcelable { - val packageName get() = packageInfo.packageName - val uid get() = packageInfo.applicationInfo!!.uid - val allowSu get() = profile?.allowSu == true - val hasCustomProfile - get() = - profile?.let { - if (it.allowSu) !it.rootUseDefault else !it.nonRootUseDefault - } ?: false - - companion object { - fun AppInfo.loadIcon(context: Context): ImageRequest { - val drawable: Drawable? = - packageInfo.applicationInfo?.loadIcon(context.packageManager) - val density = Density(context) - val icon: Bitmap? = - with(density) { - drawable?.toBitmap() - } - - return ImageRequest - .Builder(context) - .data(icon) - .crossfade(true) - .build() - } - } - } - - data class SuperUserScreenState( - val items: List = emptyList(), - val isRefreshing: Boolean = false, - ) - } From e7b7265ab46707999a0b9f22fc612db36c12b87e Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 9 Oct 2026 16:24:26 +0200 Subject: [PATCH 04/55] Refactor module description WebUI routing Replace the custom path handler classes with route-based WebUI registration inside `ViewDescriptionScreen`, including internal asset, readme, inset, and color routes. Add a shared `MimeUtil` for asset MIME detection, and trim unrelated WebUI launcher code from `Extensions.kt` as part of the cleanup. --- .../mmrl/pathHandler/AssetsPathHandler.kt | 28 ---- .../mmrl/pathHandler/InternalPathHandler.kt | 64 --------- .../moduleView/ViewDescriptionScreen.kt | 69 ++++++--- .../mmrl/ui/screens/modules/ModuleItem.kt | 78 ++++++++-- .../com/dergoogler/mmrl/utils/Extensions.kt | 135 ------------------ .../com/dergoogler/mmrl/utils/MimeUtil.kt | 63 ++++++++ 6 files changed, 174 insertions(+), 263 deletions(-) delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/AssetsPathHandler.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/InternalPathHandler.kt create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/utils/MimeUtil.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/AssetsPathHandler.kt b/app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/AssetsPathHandler.kt deleted file mode 100644 index b8255883f..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/AssetsPathHandler.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.dergoogler.mmrl.pathHandler - -import android.util.Log -import android.webkit.WebResourceResponse -import com.dergoogler.mmrl.hybridwebui.HybridWebUI -import dev.mmrlx.webui.PathHandler -import dev.mmrlx.webui.WebUI -import dev.mmrlx.webui.WebUIResourceRequest -import java.io.IOException - -class AssetsPathHandler( - webui: WebUI, -) : PathHandler(webui) { - private val assetHelper get() = kontext.assets - - override fun handle(request: WebUIResourceRequest): WebResourceResponse { - val path = request.path - - try { - val inputStream = assetHelper.open(path.removePrefix("/")) - val mimeType = HybridWebUI.MimeType.getMimeFromFileName(path) - return WebResourceResponse(mimeType, null, inputStream) - } catch (e: IOException) { - Log.e("assetsPathHandler", "Error opening asset path: $path", e) - return notFoundResponse - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/InternalPathHandler.kt b/app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/InternalPathHandler.kt deleted file mode 100644 index c1e90cad5..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/pathHandler/InternalPathHandler.kt +++ /dev/null @@ -1,64 +0,0 @@ -package com.dergoogler.mmrl.pathHandler - - -import android.util.Log -import android.webkit.WebResourceResponse -import androidx.compose.material3.ColorScheme -import com.dergoogler.mmrl.model.WebColors -import dev.mmrlx.webui.PathHandler -import dev.mmrlx.webui.WebUI -import dev.mmrlx.webui.WebUIResourceRequest -import java.io.IOException -import java.net.HttpURLConnection -import java.net.URL - -class InternalPathHandler( - webui: WebUI, - private val readmeUrl: String, - private val colorScheme: ColorScheme, -) : PathHandler(webui) { - override val id = "/internal/" - val webColors get() = WebColors(colorScheme) - val assetsPathHandler = AssetsPathHandler(this) - - override fun handle(request: WebUIResourceRequest): WebResourceResponse { - val path = request.path - - try { - if (path.matches(Regex("^assets(/.*)?$"))) { - return assetsPathHandler.handle( - WebUIResourceRequest( - method = request.method, - isForMainFrame = request.isForMainFrame, - url = request.url, - path = path.removePrefix("assets/"), - requestHeaders = request.requestHeaders, - isRedirect = request.isRedirect, - hasGesture = request.hasGesture() - ) - ) - } - - - - if (path.matches(Regex("readme\\.md"))) { - val connection = URL(readmeUrl).openConnection() as HttpURLConnection - connection.connect() - return htmlResponse(connection.getInputStream()) - } - - if (path.matches(Regex("insets\\.css"))) { - return insets.css.asStyleResponse() - } - - if (path.matches(Regex("colors\\.css"))) { - return webColors.allCssColors.asStyleResponse() - } - - return notFoundResponse - } catch (e: IOException) { - Log.e("InternalPathHandler", "Error opening mmrl asset path: $path", e) - return notFoundResponse - } - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt index c9d93c30b..244c3dc76 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.ColorScheme import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme @@ -17,13 +16,12 @@ import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.pathHandler.InternalPathHandler +import com.dergoogler.mmrl.model.WebColors import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.scaffold.Scaffold import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar @@ -31,6 +29,7 @@ import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.dergoogler.mmrl.utils.MimeUtil import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.navigation.DestinationsNavigator @@ -38,27 +37,30 @@ import dev.chrisbanes.haze.hazeSource import dev.mmrlx.compose.webui.WebUIView import dev.mmrlx.compose.webui.insets import dev.mmrlx.compose.webui.rememberWebUIState - -const val launchUrl = "https://mui.kernelsu.org/internal/assets/markdown.html" +import dev.mmrlx.webui.RouteRegistry +import dev.mmrlx.webui.RouteScope +import dev.mmrlx.webui.WebResourceResponse +import dev.mmrlx.webui.WebUIOptions +import java.net.HttpURLConnection +import java.net.URL @SuppressLint("SetJavaScriptEnabled", "JavascriptInterface") @Composable @Destination fun ViewDescriptionScreen(readmeUrl: String) = LocalScreenProvider { - val density = LocalDensity.current val navigator = LocalDestinationsNavigator.current val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() val userPrefs = LocalUserPreferences.current val scheme = MaterialTheme.colorScheme - @Suppress("KotlinConstantConditions") val wstate = - rememberWebUIState("https://desc.mmrl.dev", "internal/assets/markdown.html") { + val wstate = + rememberWebUIState( + "https://desc.mmrl.dev", + WebUIOptions("internal/assets/markdown.html") + ) { it .settings { - schemeWhitelist += "ksu" - useDefaultApplicationInterface = false - useDefaultFileSystem = false debug = BuildConfig.DEBUG forceKillProcess = false useConsoleInterceptor = false @@ -69,15 +71,35 @@ fun ViewDescriptionScreen(readmeUrl: String) = it.webview.setBackgroundColor(scheme.background.toArgb()) } .chromeClient { } - .registerPathHandler( - InternalPathHandler::class.java - ) { - add( - String::class.java to readmeUrl - ) - add( - ColorScheme::class.java to scheme - ) + .registerRoutes { + val webColors = WebColors(scheme) + + internalRoute("readme.md") { + val connection = URL(readmeUrl).openConnection() as HttpURLConnection + connection.connect() + htmlResponse(connection.getInputStream()) + } + + internalRoute("/internal/insets.css") { + insets.css.asStyleResponse() + } + + internalRoute("/internal/colors.css") { + webColors.allCssColors.asStyleResponse() + } + + internalRoute("/internal/assets/*asset") { + val filePath = request.params["asset"] ?: return@internalRoute notFoundResponse + + try { + val inputStream = kontext.assets.open(filePath) + val mimeType = MimeUtil.getMimeFromFileName(filePath) + response(mimeType = mimeType, data = inputStream) + } catch (e: Exception) { + console.error("Failed to open $filePath from the assets: $e") + notFoundResponse + } + } } } @@ -133,4 +155,9 @@ private fun TopBar( }, title = { Text(text = stringResource(id = R.string.view_module_about_this_module)) }, scrollBehavior = scrollBehavior, -) \ No newline at end of file +) + +private fun RouteRegistry.internalRoute( + name: String, + content: RouteScope.() -> WebResourceResponse, +) = route("internal/$name", content) \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt index 51251cc81..fbc372d0e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt @@ -1,5 +1,11 @@ package com.dergoogler.mmrl.ui.screens.modules +import android.content.ComponentName +import android.content.Intent +import android.util.Log +import android.widget.Toast +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.DrawableRes import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image @@ -71,7 +77,6 @@ import com.dergoogler.mmrl.ui.component.text.BBCodeText import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.utils.toFormattedDateSafely -import com.dergoogler.mmrl.utils.webUILauncher import dev.dergoogler.mmrl.compat.core.LocalUriHandler import kotlinx.coroutines.launch @@ -82,17 +87,17 @@ fun ModuleItem( alpha: Float = 1f, decoration: TextDecoration = TextDecoration.None, switch: - @Composable() - (() -> Unit?)? = null, + @Composable() + (() -> Unit?)? = null, indicator: - @Composable() - (CardScope.() -> Unit?)? = null, + @Composable() + (CardScope.() -> Unit?)? = null, startTrailingButton: - @Composable() - (LiteRowScope.() -> Unit)? = null, + @Composable() + (LiteRowScope.() -> Unit)? = null, trailingButton: - @Composable() - (LiteRowScope.() -> Unit), + @Composable() + (LiteRowScope.() -> Unit), isBlacklisted: Boolean = false, isProviderAlive: Boolean, ) { @@ -115,7 +120,36 @@ fun ModuleItem( !context.isPackageInstalled(userPreferences.webuixPackageName) } - val launch = userPreferences.webUILauncher(context, module) + val webui = + rememberLauncherForActivityResult( + contract = ActivityResultContracts.RequestMultiplePermissions(), + ) { result -> + if (!result.allGranted { perm -> + Toast + .makeText(context, "Permission denied! Requires $perm", Toast.LENGTH_SHORT) + .show() + } + ) { + return@rememberLauncherForActivityResult + } + + try { + val intent = Intent().apply { + component = ComponentName( + userPreferences.webuixPackageName, + "com.dergoogler.mmrl.wx.ui.webui.WebUIActivity" + ) + + putExtra("MODULE_ID", module.id.toString()) + } + + context.startActivity(intent) + } catch (e: Exception) { + e.printStackTrace() + Log.e("webUILauncher", "Failed to launch WebUI", e) + } + } + val clicker: (() -> Unit)? = remember(canWenUIAccessed) { @@ -125,7 +159,11 @@ fun ModuleItem( return@jump } - launch() + webui.launch( + arrayOf( + "com.dergoogler.mmrl.permission.WEBUI_X", + ), + ) } } @@ -138,10 +176,10 @@ fun ModuleItem( Card( border = isBlacklisted nullable - BorderStroke( - width = 1.dp, - color = MaterialTheme.colorScheme.errorContainer, - ), + BorderStroke( + width = 1.dp, + color = MaterialTheme.colorScheme.errorContainer, + ), onClick = clicker, ) { indicator.nullable { @@ -439,3 +477,13 @@ fun StateIndicator( alpha = 0.1f, colorFilter = ColorFilter.tint(color), ) + +private fun Map.allGranted(onDenied: (String) -> Unit): Boolean { + for ((perm, granted) in this) { + if (!granted) { + onDenied(perm) + return false + } + } + return true +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/utils/Extensions.kt b/app/src/main/kotlin/com/dergoogler/mmrl/utils/Extensions.kt index 7d027432a..9e29630b8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/utils/Extensions.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/utils/Extensions.kt @@ -1,27 +1,8 @@ package com.dergoogler.mmrl.utils -import android.annotation.SuppressLint -import android.content.Context -import android.widget.Toast -import androidx.activity.ComponentActivity -import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.runtime.Composable -import com.dergoogler.mmrl.App -import com.dergoogler.mmrl.BuildConfig -import com.dergoogler.mmrl.datastore.model.UserPreferences -import com.dergoogler.mmrl.datastore.model.WebUIEngine -import com.dergoogler.mmrl.ext.findActivity import com.dergoogler.mmrl.ext.toFormattedDateSafely -import com.dergoogler.mmrl.modconf.helper.ModConfLauncher -import com.dergoogler.mmrl.model.local.LocalModule -import com.dergoogler.mmrl.platform.PlatformManager -import com.dergoogler.mmrl.platform.content.LocalModule.Companion.hasModConf -import com.dergoogler.mmrl.platform.content.LocalModule.Companion.hasWebUI -import com.dergoogler.mmrl.platform.ksu.KsuNative -import com.dergoogler.mmrl.platform.model.toModuleConfig import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.dergoogler.mmrl.webui.helper.WebUILauncher import com.topjohnwu.superuser.NoShellException import com.topjohnwu.superuser.Shell @@ -60,119 +41,3 @@ fun createRootShell( } return builder.build(*commands) } - -@SuppressLint("MissingPermission") -@Composable -fun UserPreferences.webUILauncher( - context: Context, - module: LocalModule, -): () -> Unit { - val modId = module.id - val config = modId.toModuleConfig() - - val activity = - context.findActivity() as? ComponentActivity ?: run { - Toast.makeText(context, "No activity found", Toast.LENGTH_SHORT).show() - return {} - } - - val modconfLauncher = - ModConfLauncher( - debug = BuildConfig.DEBUG, - packageName = webuixPackageName, - ) - - val webuiLauncher = - WebUILauncher( - debug = BuildConfig.DEBUG, - packageName = webuixPackageName, - ) - - fun Map.allGranted(onDenied: (String) -> Unit): Boolean { - for ((perm, granted) in this) { - if (!granted) { - onDenied(perm) - return false - } - } - return true - } - - val modconf = - rememberLauncherForActivityResult( - contract = ActivityResultContracts.RequestMultiplePermissions(), - ) { result -> - if (!result.allGranted { perm -> - Toast - .makeText(context, "Permission denied! Requires $perm", Toast.LENGTH_SHORT) - .show() - } - ) { - return@rememberLauncherForActivityResult - } - - modconfLauncher.launch( - context = context, - modId = modId, - platform = workingMode.toPlatform(), - ) - } - - val webui = - rememberLauncherForActivityResult( - contract = ActivityResultContracts.RequestMultiplePermissions(), - ) { result -> - if (!result.allGranted { perm -> - Toast - .makeText(context, "Permission denied! Requires $perm", Toast.LENGTH_SHORT) - .show() - } - ) { - return@rememberLauncherForActivityResult - } - - val effectiveEngine = - when (webuiEngine) { - WebUIEngine.PREFER_MODULE -> - config.getWebuiEngine(context)?.let { - when (it) { - "wx" -> WebUIEngine.WX - "ksu" -> WebUIEngine.KSU - else -> { - Toast.makeText(context, "Unknown WebUI engine", Toast.LENGTH_SHORT).show() - return@rememberLauncherForActivityResult - } - } - } ?: WebUIEngine.WX - - else -> webuiEngine - } - - when (effectiveEngine) { - WebUIEngine.WX -> webuiLauncher.launchWX(context, modId, workingMode.toPlatform()) - WebUIEngine.KSU -> webuiLauncher.launchLegacy(context, modId, workingMode.toPlatform()) - else -> Toast.makeText(context, "Unsupported WebUI engine", Toast.LENGTH_SHORT).show() - } - } - - return { - when { - module.hasModConf -> modconf.launch(arrayOf(modconfLauncher.permissions.MODCONF)) - module.hasWebUI -> - webui.launch( - arrayOf( - webuiLauncher.permissions.WEBUI_X, - webuiLauncher.permissions.WEBUI_LEGACY, - ), - ) - - else -> Toast.makeText(context, "Unsupported module", Toast.LENGTH_SHORT).show() - } - } -} - -val KsuNative.isManager: Boolean - get() { - val pkg = App.context.packageName - return PlatformManager.platform.isKernelSuVariant && becomeManager(pkg) - } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/utils/MimeUtil.kt b/app/src/main/kotlin/com/dergoogler/mmrl/utils/MimeUtil.kt new file mode 100644 index 000000000..9ca504ed0 --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/utils/MimeUtil.kt @@ -0,0 +1,63 @@ +package com.dergoogler.mmrl.utils + +import java.net.URLConnection +import java.util.Locale + +object MimeUtil { + fun getMimeFromFileName(fileName: String?): String? { + if (fileName == null) { + return null + } + + val mimeType = URLConnection.guessContentTypeFromName(fileName) + + if (mimeType != null) { + return mimeType + } + + return guessHardcodedMime(fileName) + } + + private fun guessHardcodedMime(fileName: String): String? { + val finalFullStop = fileName.lastIndexOf('.') + if (finalFullStop == -1) { + return null + } + + val extension = fileName.substring(finalFullStop + 1).lowercase(Locale.getDefault()) + + return when (extension) { + "webm" -> "video/webm" + "mpeg", "mpg" -> "video/mpeg" + "mp3" -> "audio/mpeg" + "wasm" -> "application/wasm" + "xhtml", "xht", "xhtm" -> "application/xhtml+xml" + "flac" -> "audio/flac" + "ogg", "oga", "opus" -> "audio/ogg" + "wav" -> "audio/wav" + "m4a" -> "audio/x-m4a" + "gif" -> "image/gif" + "jpeg", "jpg", "jfif", "pjpeg", "pjp" -> "image/jpeg" + "png" -> "image/png" + "apng" -> "image/apng" + "svg", "svgz" -> "image/svg+xml" + "webp" -> "image/webp" + "mht", "mhtml" -> "multipart/related" + "css" -> "text/css" + "html", "htm", "shtml", "shtm", "ehtml" -> "text/html" + "js", "mjs" -> "application/javascript" + "xml" -> "text/xml" + "mp4", "m4v" -> "video/mp4" + "ogv", "ogm" -> "video/ogg" + "ico" -> "image/x-icon" + "woff" -> "application/font-woff" + "gz", "tgz" -> "application/gzip" + "json" -> "application/json" + "pdf" -> "application/pdf" + "zip" -> "application/zip" + "bmp" -> "image/bmp" + "tiff", "tif" -> "image/tiff" + else -> null + } + } +} \ No newline at end of file From 16943bffe3a2c7ad15d31017c6ede07a55a55fce Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 9 Oct 2026 17:35:06 +0200 Subject: [PATCH 05/55] [skip ci] fuck this shit --- app/build.gradle.kts | 4 +- gradle/libs.versions.toml | 23 ++++++----- ui/build.gradle.kts | 1 + .../mmrl/ui/component/BottomSheet.kt | 16 ++++---- .../mmrl/ui/component/text/BBCodeText.kt | 40 ++++++++++++------- 5 files changed, 49 insertions(+), 35 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e4f3ebb3c..44e83d86c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -269,8 +269,8 @@ dependencies { ksp(libs.square.moshi.kotlin) implementation(libs.mmrlx.terminal) - implementation(libs.mmrlx.nio) - implementation(libs.mmrlx.utilities) +// implementation(libs.mmrlx.nio) +// implementation(libs.mmrlx.utilities) implementation(libs.mmrlx.webui.core) implementation("dev.chrisbanes.haze:haze:1.6.10") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 117ba55ba..1dd8cfaae 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,8 +3,8 @@ androidGradlePlugin = "9.0.0" androidxActivity = "1.10.1" androidxAnnotation = "1.9.1" androidxAppCompat = "1.7.1" -androidxCompose = "1.8.3" -androidxComposeMaterial3 = "1.3.2" +androidxCompose = "1.11.0" +androidxComposeMaterial3 = "1.4.0" androidxCore = "1.16.0" androidxCoreSplashscreen = "1.0.1" androidxDataStore = "1.1.7" @@ -13,7 +13,7 @@ androidxHiltNavigationCompose = "1.2.0" androidxLifecycle = "2.9.1" androidxNavigation = "2.9.0" arbor = "2.0.103" -foundation = "1.8.3" +foundation = "1.11.0" kotlinxHtmlJvm = "0.9.1" multiplatformMarkdownRenderer = "0.27.0" processPhoenix = "3.0.0" @@ -25,13 +25,13 @@ browser = "1.8.0" coilCompose = "2.7.0" composeMarkdown = "0.5.4" hiddenApiRefine = "4.4.0" -hilt = "2.59.2" -kotlin = "2.2.0" +hilt = "2.60.1" +kotlin = "2.4.10" kotlinReflect = "1.9.24" kotlinxCoroutines = "1.8.1" kotlinxDatetime = "0.6.0" kotlinxSerialization = "1.7.1" -ksp = "2.2.0-2.0.2" +ksp = "2.3.11" libsu = "6.0.0" protobuf = "4.34.1" protobufPlugin = "0.9.6" @@ -40,8 +40,8 @@ shizuku = "13.1.5" squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" -runtimeAndroid = "1.7.6" -mmrlx = "1.0.223" +runtimeAndroid = "1.11.0" +mmrlx = "1.0.224" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.28.0" @@ -52,8 +52,9 @@ junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" material = "1.12.0" -material3Android = "1.3.2" -runtimeAndroidVersion = "1.7.8" +materialIcons = "1.7.8" +material3Android = "1.4.0" +runtimeAndroidVersion = "1.11.0" swiperefreshlayout = "1.1.0" composedestinations = "2.2.0" @@ -83,6 +84,7 @@ androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lif androidx-lifecycle-service = { group = "androidx.lifecycle", name = "lifecycle-service", version.ref = "androidxLifecycle" } androidx-lifecycle-viewModel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" } androidx-material = { module = "androidx.compose.material:material" } +androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core", version.ref = "materialIcons" } androidx-webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" } androidx-multidex = { module = "androidx.multidex:multidex", version.ref = "multidex" } androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" } @@ -139,6 +141,7 @@ hiddenApiBypass = "org.lsposed.hiddenapibypass:hiddenapibypass:6.1" mmrlx-terminal = { module = "dev.mmrlx:terminal", version.ref = "mmrlx" } mmrlx-webui-core = { module = "dev.mmrlx:webui.core", version.ref = "mmrlx" } mmrlx-nio = { module = "dev.mmrlx:nio", version.ref = "mmrlx" } +mmrlx-ui = { module = "dev.mmrlx:ui", version.ref = "mmrlx" } mmrlx-utilities = { module = "dev.mmrlx:utilities", version.ref = "mmrlx" } timber = "com.jakewharton.timber:timber:5.0.1" diff --git a/ui/build.gradle.kts b/ui/build.gradle.kts index a7cc481db..426d1f744 100644 --- a/ui/build.gradle.kts +++ b/ui/build.gradle.kts @@ -73,4 +73,5 @@ dependencies { implementation(libs.androidx.material3.android) implementation(libs.androidx.compose.ui.tooling) implementation(libs.androidx.compose.ui.tooling.preview) + implementation("androidx.compose.material:material-icons-extended:1.7.8") } \ No newline at end of file diff --git a/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomSheet.kt b/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomSheet.kt index 17a5194dd..0e8239648 100644 --- a/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomSheet.kt +++ b/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomSheet.kt @@ -50,14 +50,14 @@ fun BottomSheet( modifier, sheetState, sheetMaxWidth, - shape, - containerColor, - contentColor, - tonalElevation, - scrimColor, - dragHandle, - { windowInsets }, - properties, +// shape, +// containerColor, +// contentColor, +// tonalElevation, +// scrimColor, +// dragHandle, +// { windowInsets }, +// properties, ) { val statusBarHeight = WindowInsets.statusBars.asPaddingValues().calculateTopPadding() + 28.dp diff --git a/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/text/BBCodeText.kt b/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/text/BBCodeText.kt index 5f436f227..1d6fd5c8e 100644 --- a/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/text/BBCodeText.kt +++ b/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/text/BBCodeText.kt @@ -55,11 +55,13 @@ enum class BBCodeTag { ; companion object { - fun disableAllExcept(vararg tags: BBCodeTag): Set = entries.filterNot { it in tags }.toSet() + fun disableAllExcept(vararg tags: BBCodeTag): Set = + entries.filterNot { it in tags }.toSet() fun disableAll(): Set = entries.toSet() - fun enableAllExcept(vararg tags: BBCodeTag): Set = entries.filterNot { it in tags }.toSet() + fun enableAllExcept(vararg tags: BBCodeTag): Set = + entries.filterNot { it in tags }.toSet() } } @@ -204,7 +206,11 @@ fun BBCodeText( val ann = string - .getStringAnnotations(tag = "URL", start = position, end = position) + .getStringAnnotations( + tag = "URL", + start = position, + end = position + ) .firstOrNull() ann?.let { @@ -327,13 +333,11 @@ private fun String.toStyleMarkup( placeholderVerticalAlign = PlaceholderVerticalAlign.Center, ), ) { - runCatching { - ProvideContentColorTextStyle( - contentColor = color, - textStyle = textStyle, - ) { - iconContent(value) - } + ProvideContentColorTextStyle( + contentColor = color, + textStyle = textStyle, + ) { + iconContent(value) } } } @@ -350,9 +354,7 @@ private fun String.toStyleMarkup( placeholderVerticalAlign = PlaceholderVerticalAlign.Center, ), ) { - runCatching { - imageContent(value) - } + imageContent(value) } } @@ -360,8 +362,16 @@ private fun String.toStyleMarkup( val current = styleStack.peek() val newStyle = when (tagType) { - BBCodeTag.COLOR -> current.copy(tag = tagType, color = colorFromName(value)) - BBCodeTag.BACKGROUND -> current.copy(tag = tagType, bg = colorFromName(value)) + BBCodeTag.COLOR -> current.copy( + tag = tagType, + color = colorFromName(value) + ) + + BBCodeTag.BACKGROUND -> current.copy( + tag = tagType, + bg = colorFromName(value) + ) + BBCodeTag.BOLD -> current.copy(tag = tagType, bold = true) BBCodeTag.ITALIC -> current.copy(tag = tagType, italic = true) BBCodeTag.UNDERLINE -> current.copy(tag = tagType, underline = true) From 740673c53c707b825e63446bd346e44d3721353a Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:46:57 +0200 Subject: [PATCH 06/55] . --- .../mmrl/ui/screens/main/MainScreen.kt | 22 +------ build-logic/src/main/kotlin/ProjectExt.kt | 2 +- gradle/libs.versions.toml | 64 +++++++++---------- gradle/wrapper/gradle-wrapper.properties | 5 +- 4 files changed, 37 insertions(+), 56 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt index fc8cd65ac..631fa3220 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt @@ -6,24 +6,13 @@ import androidx.compose.animation.ExitTransition import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.imePadding -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.width -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items import androidx.compose.material3.Badge import androidx.compose.material3.BadgedBox import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.NavigationBarItem -import androidx.compose.material3.NavigationDrawerItem -import androidx.compose.material3.NavigationRail -import androidx.compose.material3.NavigationRailItem -import androidx.compose.material3.PermanentDrawerSheet -import androidx.compose.material3.PermanentNavigationDrawer import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -35,15 +24,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavBackStackEntry -import com.dergoogler.mmrl.ext.currentScreenWidth import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ui.component.TopAppBar -import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon import com.dergoogler.mmrl.ui.component.scaffold.ResponsiveScaffold -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold import com.dergoogler.mmrl.ui.component.toolbar.BlurBottomToolbar import com.dergoogler.mmrl.ui.navigation.MainDestination import com.dergoogler.mmrl.ui.navigation.isAccessible @@ -210,10 +194,10 @@ private fun BottomNav(updates: Int) { Modifier .imePadding(), ) { - MainDestination.entries.forEach { screen -> - val isSelected by navController.isRouteOnBackStackAsState(screen.direction) + for (screen in MainDestination.entries) { + if (!screen.isAccessible) continue - if (!screen.isAccessible) return@forEach + val isSelected by navController.isRouteOnBackStackAsState(screen.direction) NavigationBarItem( icon = { diff --git a/build-logic/src/main/kotlin/ProjectExt.kt b/build-logic/src/main/kotlin/ProjectExt.kt index b25057701..0ddbb72aa 100644 --- a/build-logic/src/main/kotlin/ProjectExt.kt +++ b/build-logic/src/main/kotlin/ProjectExt.kt @@ -8,7 +8,7 @@ import java.util.Properties // #### CONFIG START #### -const val COMPILE_SDK = 36 +const val COMPILE_SDK = 37 const val BUILD_TOOLS_VERSION = "$COMPILE_SDK.0.0" const val MIN_SDK = 26 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1dd8cfaae..c633516a5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,60 +1,60 @@ [versions] -androidGradlePlugin = "9.0.0" -androidxActivity = "1.10.1" -androidxAnnotation = "1.9.1" -androidxAppCompat = "1.7.1" -androidxCompose = "1.11.0" +androidGradlePlugin = "9.4.1" +androidxActivity = "1.13.0" +androidxAnnotation = "1.11.0" +androidxAppCompat = "1.8.0" +androidxCompose = "1.12.1" androidxComposeMaterial3 = "1.4.0" -androidxCore = "1.16.0" -androidxCoreSplashscreen = "1.0.1" -androidxDataStore = "1.1.7" +androidxCore = "1.19.1" +androidxCoreSplashscreen = "1.2.0" +androidxDataStore = "1.2.1" androidxDocumentFile = "1.1.0" -androidxHiltNavigationCompose = "1.2.0" -androidxLifecycle = "2.9.1" -androidxNavigation = "2.9.0" +androidxHiltNavigationCompose = "1.4.0" +androidxLifecycle = "2.11.0" +androidxNavigation = "2.10.2" arbor = "2.0.103" -foundation = "1.11.0" +foundation = "1.10.6" +cashLicensee = "1.13.0" kotlinxHtmlJvm = "0.9.1" multiplatformMarkdownRenderer = "0.27.0" processPhoenix = "3.0.0" -webkit = "1.14.0" +webkit = "1.17.1" multidex = "2.0.1" -navigationRuntimeKtx = "2.9.0" -androidxRoom = "2.7.2" +navigationRuntimeKtx = "2.8.5" +androidxRoom = "2.8.5" browser = "1.8.0" -coilCompose = "2.7.0" +coilCompose = "2.1.0" +coilSvg = "3.6.3" composeMarkdown = "0.5.4" hiddenApiRefine = "4.4.0" hilt = "2.60.1" -kotlin = "2.4.10" +kotlin = "2.4.20" kotlinReflect = "1.9.24" kotlinxCoroutines = "1.8.1" kotlinxDatetime = "0.6.0" kotlinxSerialization = "1.7.1" ksp = "2.3.11" libsu = "6.0.0" -protobuf = "4.34.1" -protobufPlugin = "0.9.6" +protobuf = "4.28.2" +protobufPlugin = "0.9.4" semver = "2.0.0" shizuku = "13.1.5" squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" -runtimeAndroid = "1.11.0" +runtimeAndroid = "1.12.1" mmrlx = "1.0.224" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" -apacheCommons = "1.28.0" +apacheCommons = "1.27.1" parcelablelist = "2.0.1" -zoomableVersion = "2.2.0" -kotlinVersion = "2.2.0" +zoomableVersion = "2.15.0" junit = "4.13.2" junitVersion = "1.2.1" espressoCore = "3.6.1" material = "1.12.0" materialIcons = "1.7.8" material3Android = "1.4.0" -runtimeAndroidVersion = "1.11.0" swiperefreshlayout = "1.1.0" composedestinations = "2.2.0" @@ -85,8 +85,8 @@ androidx-lifecycle-service = { group = "androidx.lifecycle", name = "lifecycle-s androidx-lifecycle-viewModel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" } androidx-material = { module = "androidx.compose.material:material" } androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core", version.ref = "materialIcons" } -androidx-webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" } -androidx-multidex = { module = "androidx.multidex:multidex", version.ref = "multidex" } +androidx-webkit = { group = "androidx.webkit", name = "webkit", version.ref = "webkit" } +androidx-multidex = { group = "androidx.multidex", name = "multidex", version.ref = "multidex" } androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" } androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxNavigation" } androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "androidxRoom" } @@ -112,7 +112,7 @@ kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", lib-zoomable = { module = "net.engawapg.lib:zoomable", version.ref = "zoomableVersion" } libsu-core = { group = "com.github.topjohnwu.libsu", name = "core", version.ref = "libsu" } libsu-service = { group = "com.github.topjohnwu.libsu", name = "service", version.ref = "libsu" } -libsu-io = { module = "com.github.topjohnwu.libsu:io", version.ref = "libsu" } +libsu-io = { module = "com.github.topjohnwu.libsu:io", name = "io", version.ref = "libsu" } multiplatform-markdown-renderer-android = { module = "com.mikepenz:multiplatform-markdown-renderer-android", version.ref = "multiplatformMarkdownRenderer" } multiplatform-markdown-renderer-coil3 = { module = "com.mikepenz:multiplatform-markdown-renderer-coil3", version.ref = "multiplatformMarkdownRenderer" } multiplatform-markdown-renderer-m3 = { module = "com.mikepenz:multiplatform-markdown-renderer-m3", version.ref = "multiplatformMarkdownRenderer" } @@ -132,10 +132,8 @@ square-okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = square-okhttp-dnsoverhttps = { group = "com.squareup.okhttp3", name = "okhttp-dnsoverhttps", version.ref = "squareOkhttp" } square-logging-interceptor = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "squareOkhttp" } square-moshi = { group = "com.squareup.moshi", name = "moshi", version.ref = "squareMoshi" } -square-moshi-kotlin = { group = "com.squareup.moshi", name = "moshi-kotlin-codegen", version.ref = "squareMoshi" } - +square-moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "squareMoshi" } dev-rikka-rikkax-parcelablelist = { module = "dev.rikka.rikkax.parcelablelist:parcelablelist", version.ref = "parcelablelist" } - markwon-core = "io.noties.markwon:core:4.6.2" hiddenApiBypass = "org.lsposed.hiddenapibypass:hiddenapibypass:6.1" mmrlx-terminal = { module = "dev.mmrlx:terminal", version.ref = "mmrlx" } @@ -147,7 +145,7 @@ timber = "com.jakewharton.timber:timber:5.0.1" # Dependencies of the included build-logic android-gradle = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } -compose-gradle= { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" } +compose-gradle = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" } kotlin-gradle = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" } ksp-gradle = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" } androidx-runtime-android = { group = "androidx.compose.runtime", name = "runtime-android", version.ref = "runtimeAndroid" } @@ -157,7 +155,7 @@ androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "j androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } material = { group = "com.google.android.material", name = "material", version.ref = "material" } androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" } -runtime-android = { group = "androidx.compose.runtime", name = "runtime-android", version.ref = "runtimeAndroidVersion" } +runtime-android = { group = "androidx.compose.runtime", name = "runtime-android", version.ref = "runtimeAndroid" } androidx-swiperefreshlayout = { group = "androidx.swiperefreshlayout", name = "swiperefreshlayout", version.ref = "swiperefreshlayout" } [plugins] @@ -178,4 +176,4 @@ self-library = { id = "self.library", version = "unspecified" } self-compose = { id = "self.compose", version = "unspecified" } self-hilt = { id = "self.hilt", version = "unspecified" } self-room = { id = "self.room", version = "unspecified" } -jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6510bd8ba..809449e78 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ -#Sat Mar 28 13:59:40 CET 2026 +#Fri Oct 09 20:46:13 CEST 2026 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=a17ddd85a26b6a7f5ddb71ff8b05fc5104c0202c6e64782429790c933686c806 -distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 8dfcfb4731227292807068921c034245bfe526f4 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 15:52:37 +0200 Subject: [PATCH 07/55] Handle back press in module description view Add a Compose `BackHandler` so the description WebView first navigates backward in its own history, and only pops the app navigation stack when no web history remains. Also align internal route registrations (`insets.css`, `colors.css`, `assets/*asset`) with relative paths expected by the local router. --- .../moduleView/ViewDescriptionScreen.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt index 244c3dc76..1f58c4d60 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt @@ -1,6 +1,7 @@ package com.dergoogler.mmrl.ui.screens.moduleView import android.annotation.SuppressLint +import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets @@ -80,16 +81,17 @@ fun ViewDescriptionScreen(readmeUrl: String) = htmlResponse(connection.getInputStream()) } - internalRoute("/internal/insets.css") { + internalRoute("insets.css") { insets.css.asStyleResponse() } - internalRoute("/internal/colors.css") { + internalRoute("colors.css") { webColors.allCssColors.asStyleResponse() } - internalRoute("/internal/assets/*asset") { - val filePath = request.params["asset"] ?: return@internalRoute notFoundResponse + internalRoute("assets/*asset") { + val filePath = + request.params["asset"] ?: return@internalRoute notFoundResponse try { val inputStream = kontext.assets.open(filePath) @@ -109,6 +111,16 @@ fun ViewDescriptionScreen(readmeUrl: String) = } } + // We have to override otherwise the WebUI will close the entire app + BackHandler { + if (wstate.canGoBack()) { + wstate.goBack() + return@BackHandler + } + + navigator.popBackStack() + } + Scaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = { From c41b2079cc1595753e20ce67fa57dbaf70361673 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 17:18:54 +0200 Subject: [PATCH 08/55] Refactor repository screen and toolbar state Introduces a stable `BlurToolbarState` with `rememberBlurToolbarState` to centralize fade/blur alpha behavior and reuse it from search toolbars. The repository UI is consolidated by renaming `TypedModulesList` to `ModulesList`, adding injectable pre-list content, and rebuilding `RepositoryScreen` around that shared list + `BlurSearchToolbar`. Obsolete typed-module/top-picks screens and components were removed, and module author/category links to the deleted typed screen were disabled. --- .../ui/component/toolbar/BlurSearchToolbar.kt | 6 + .../mmrl/ui/component/toolbar/BlurToolbar.kt | 209 +++++--- .../moduleView/items/OtherSourcesItem.kt | 9 +- .../moduleView/sections/AboutModule.kt | 18 +- .../ui/screens/moduleView/sections/Header.kt | 29 +- .../mmrl/ui/screens/modules/ModulesScreen.kt | 6 +- .../TypedModulesList.kt => ModulesList.kt} | 54 +- .../ui/screens/repository/RepositoryScreen.kt | 480 ++++++++---------- .../ui/screens/repository/TopPickModule.kt | 143 ------ .../mmrl/ui/screens/repository/TopPicks.kt | 105 ---- .../repository/modules/TypedModulesScreen.kt | 208 -------- .../mmrl/ui/screens/search/SearchScreen.kt | 2 +- 12 files changed, 410 insertions(+), 859 deletions(-) rename app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/{modules/TypedModulesList.kt => ModulesList.kt} (70%) delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPickModule.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPicks.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesScreen.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt index 454e81dd2..7a5764934 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt @@ -46,7 +46,13 @@ fun BlurSearchToolbar( fadeBackgroundIfNoBlur: Boolean = false, fadeDistance: Float = 200f, fade: Boolean = false, + state: BlurToolbarState = rememberBlurToolbarState( + scrollBehavior = scrollBehavior, + fade = fade, + fadeDistance = fadeDistance, + ), ) = BlurToolbar( + state = state, modifier = modifier, actions = actions, windowInsets = windowInsets, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt index aa9238b6f..c485133df 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt @@ -10,8 +10,9 @@ import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable +import androidx.compose.runtime.State import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawBehind @@ -25,106 +26,160 @@ import dev.chrisbanes.haze.hazeEffect import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi import dev.chrisbanes.haze.materials.HazeMaterials -@OptIn(ExperimentalHazeMaterialsApi::class) +private const val VISIBILITY_THRESHOLD = 0.01f + +/** + * Read-only view of the toolbar's current visual state. + * All properties are snapshot-backed, so reading them in composition + * (or in a draw/layout lambda) will trigger the right invalidation. + */ +@Stable +class BlurToolbarState internal constructor( + private val animatedAlpha: State, + private val targetAlphaState: State, + private val blurEnabled: State, + private val scrollBehavior: TopAppBarScrollBehavior?, +) { + /** Current (animated) alpha, 0f..1f. */ + val alpha: Float get() = animatedAlpha.value + + /** Un-animated alpha derived from scroll position. */ + val targetAlpha: Float get() = targetAlphaState.value + + /** Blur is enabled in prefs AND supported on this device. */ + val isBlurEnabled: Boolean get() = blurEnabled.value + + /** True if the toolbar is visible enough to draw anything. */ + val isVisible: Boolean get() = alpha > VISIBILITY_THRESHOLD + + /** True if the haze blur effect is actually being applied. */ + val isBlurActive: Boolean get() = isBlurEnabled && isVisible + + val isFullyVisible: Boolean get() = alpha >= 1f - VISIBILITY_THRESHOLD + + /** True while the alpha animation is still catching up with its target. */ + val isAnimating: Boolean get() = alpha != targetAlpha + + /** Raw scroll content offset (<= 0 when scrolled), or 0f without a scroll behavior. */ + val contentOffset: Float get() = scrollBehavior?.state?.contentOffset ?: 0f + + /** 0f = expanded, 1f = fully collapsed. */ + val collapsedFraction: Float get() = scrollBehavior?.state?.collapsedFraction ?: 0f + + /** 0f..1f, how much content overlaps the toolbar. */ + val overlappedFraction: Float get() = scrollBehavior?.state?.overlappedFraction ?: 0f +} + @Composable -fun BlurToolbar( - title: @Composable (Float) -> Unit, - modifier: Modifier = Modifier, - navigationIcon: @Composable () -> Unit = {}, - actions: @Composable RowScope.() -> Unit = {}, - expandedHeight: Dp = TopAppBarDefaults.TopAppBarExpandedHeight, - windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - fadeBackgroundIfNoBlur: Boolean = false, - fadeDistance: Float = 200f, - fade: Boolean = false, +fun rememberBlurToolbarState( scrollBehavior: TopAppBarScrollBehavior? = null, -) { + fade: Boolean = false, + fadeDistance: Float = 200f, +): BlurToolbarState { val prefs = LocalUserPreferences.current - val state = scrollBehavior?.state + val scrollState = scrollBehavior?.state - val isBlurEnabled = - remember(prefs) { - prefs.enableBlur && BlurUtil.isBlurSupported() - } + val blurEnabled = remember(prefs) { + derivedStateOf { prefs.enableBlur && BlurUtil.isBlurSupported() } + } - val targetAlpha by remember { + val targetAlpha = remember(scrollState, fade, fadeDistance) { derivedStateOf { - if (!fade || state == null) { + if (!fade || scrollState == null || fadeDistance <= 0f) { 1f } else { - ((-state.contentOffset) / fadeDistance).coerceIn(0f, 1f) + (-scrollState.contentOffset / fadeDistance).coerceIn(0f, 1f) } } } - val animatedAlpha by animateFloatAsState( - targetValue = targetAlpha, - animationSpec = - tween( - durationMillis = 10, - easing = FastOutSlowInEasing, - ), + val animatedAlpha = animateFloatAsState( + targetValue = targetAlpha.value, + animationSpec = tween(durationMillis = 150, easing = FastOutSlowInEasing), label = "toolbar_alpha", ) + return remember(scrollBehavior, blurEnabled, targetAlpha, animatedAlpha) { + BlurToolbarState( + animatedAlpha = animatedAlpha, + targetAlphaState = targetAlpha, + blurEnabled = blurEnabled, + scrollBehavior = scrollBehavior, + ) + } +} + +@OptIn(ExperimentalHazeMaterialsApi::class) +@Composable +fun BlurToolbar( + title: @Composable (Float) -> Unit, + modifier: Modifier = Modifier, + navigationIcon: @Composable () -> Unit = {}, + actions: @Composable RowScope.() -> Unit = {}, + expandedHeight: Dp = TopAppBarDefaults.TopAppBarExpandedHeight, + windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, + fadeBackgroundIfNoBlur: Boolean = false, + fadeDistance: Float = 200f, + fade: Boolean = false, + scrollBehavior: TopAppBarScrollBehavior? = null, + state: BlurToolbarState = rememberBlurToolbarState( + scrollBehavior = scrollBehavior, + fade = fade, + fadeDistance = fadeDistance, + ), +) { val borderColor = MaterialTheme.colorScheme.outline val backgroundColor = MaterialTheme.colorScheme.background - val topAppBarColors = TopAppBarDefaults.topAppBarColors() - val colors = - if (isBlurEnabled) { - topAppBarColors.copy( - scrolledContainerColor = Color.Transparent, - containerColor = Color.Transparent, - ) + val colors = if (state.isBlurEnabled) { + topAppBarColors.copy( + scrolledContainerColor = Color.Transparent, + containerColor = Color.Transparent, + ) + } else { + val container = if (fadeBackgroundIfNoBlur) { + backgroundColor.copy(alpha = state.alpha) } else { - val backgroundColor = - MaterialTheme.colorScheme.background - .let { - if (fadeBackgroundIfNoBlur) { - it.copy(alpha = animatedAlpha) - } else { - it - } - } - - topAppBarColors.copy( - scrolledContainerColor = backgroundColor, - containerColor = backgroundColor, - ) + backgroundColor } + topAppBarColors.copy( + scrolledContainerColor = container, + containerColor = container, + ) + } - val blur = - if (isBlurEnabled && animatedAlpha > 0.01f) { - Modifier.hazeEffect( - state = LocalHazeState.current, - style = HazeMaterials.ultraThin(), - ) { - this@hazeEffect.backgroundColor = backgroundColor - this@hazeEffect.alpha = animatedAlpha - } - } else { - Modifier + val blur = if (state.isBlurActive) { + Modifier.hazeEffect( + state = LocalHazeState.current, + style = HazeMaterials.ultraThin(), + ) { + this.backgroundColor = backgroundColor + this.alpha = state.alpha } + } else { + Modifier + } TopAppBar( - title = { title(animatedAlpha) }, - modifier = - Modifier - .drawBehind { - if (animatedAlpha > 0.01f) { - val borderSize = Dp.Hairline - val y = size.height - borderSize.value - drawLine( - color = borderColor.copy(alpha = animatedAlpha), - start = Offset(0f, y), - end = Offset(size.width, y), - strokeWidth = borderSize.value, - ) - } - }.then(blur) - .then(modifier), + title = { title(state.alpha) }, + modifier = Modifier + .drawBehind { + // Read inside the draw scope so alpha changes only redraw + val alpha = state.alpha + if (alpha > VISIBILITY_THRESHOLD) { + val borderSize = Dp.Hairline + val y = size.height - borderSize.value + drawLine( + color = borderColor.copy(alpha = alpha), + start = Offset(0f, y), + end = Offset(size.width, y), + strokeWidth = borderSize.value, + ) + } + } + .then(blur) + .then(modifier), navigationIcon = navigationIcon, actions = actions, colors = colors, @@ -132,4 +187,4 @@ fun BlurToolbar( windowInsets = windowInsets, expandedHeight = expandedHeight, ) -} +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/OtherSourcesItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/OtherSourcesItem.kt index 0d861b49c..e32115c14 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/OtherSourcesItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/OtherSourcesItem.kt @@ -13,12 +13,15 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.model.online.OtherSources +import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModuleState import com.dergoogler.mmrl.ui.screens.repository.ModuleItemCompact +import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDestination @Composable fun OtherSourcesItem(items: List) { + val navigator = LocalDestinationsNavigator.current val pagerState = rememberPagerState(pageCount = { (items.size + 2) / 3 }) HorizontalPager( @@ -49,7 +52,11 @@ fun OtherSourcesItem(items: List) { sourceProvider = item.repo.name, showLabels = false, showLastUpdated = false, - onClick = {}, + onClick = { + navigator.navigate( + NewViewScreenDestination(item.repo, item.online) + ) + }, ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt index f5ecbc3b4..49aa14686 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt @@ -29,8 +29,6 @@ import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.screens.moduleView.listItemContentPaddingValues -import com.dergoogler.mmrl.ui.screens.repository.modules.ModulesFilter -import com.ramcosta.composedestinations.generated.destinations.TypedModulesScreenDestination import com.ramcosta.composedestinations.generated.destinations.ViewDescriptionScreenDestination @Composable @@ -93,14 +91,14 @@ internal fun AboutModule() { items(it.size) { category -> AssistChip( onClick = { - navigator.navigate( - TypedModulesScreenDestination( - type = ModulesFilter.CATEGORY, - title = it[category], - query = it[category], - repo = repo, - ), - ) +// navigator.navigate( +// TypedModulesScreenDestination( +// type = ModulesFilter.CATEGORY, +// title = it[category], +// query = it[category], +// repo = repo, +// ), +// ) }, label = { Text(it[category]) }, ) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt index f4739fe84..dea019632 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt @@ -1,6 +1,5 @@ package com.dergoogler.mmrl.ui.screens.moduleView.sections -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -44,8 +43,6 @@ import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.providable.LocalVersionItem import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel -import com.dergoogler.mmrl.ui.screens.repository.modules.ModulesFilter -import com.ramcosta.composedestinations.generated.destinations.TypedModulesScreenDestination @Composable internal fun Header() { @@ -104,19 +101,19 @@ internal fun Header() { Spacer(modifier = Modifier.height(4.dp)) Text( - modifier = - Modifier.clickable( - onClick = { - navigator.navigate( - TypedModulesScreenDestination( - type = ModulesFilter.AUTHOR, - title = module.author, - query = module.author, - repo = repo, - ), - ) - }, - ), +// modifier = +// Modifier.clickable( +// onClick = { +// navigator.navigate( +// TypedModulesScreenDestination( +// type = ModulesFilter.AUTHOR, +// title = module.author, +// query = module.author, +// repo = repo, +// ), +// ) +// }, +// ), text = module.author, style = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.surfaceTint), maxLines = 2, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt index f2957e11f..c7a0fd250 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt @@ -188,11 +188,8 @@ private fun TopBar( } BlurSearchToolbar( - scrollBehavior = scrollBehavior, isSearch = isSearch, query = currentQuery, - fade = true, - fadeDistance = 50f, onQueryChange = { onQueryChange(it) currentQuery = it @@ -222,6 +219,9 @@ private fun TopBar( setMenu = setMenu, ) }, + scrollBehavior = scrollBehavior, + fadeDistance = 50f, + fade = true, ) } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt similarity index 70% rename from app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesList.kt rename to app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index c0d5b53f9..de0b73074 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -1,4 +1,4 @@ -package com.dergoogler.mmrl.ui.screens.repository.modules +package com.dergoogler.mmrl.ui.screens.repository import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -9,12 +9,12 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.dp @@ -23,15 +23,12 @@ import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.state.OnlineState import com.dergoogler.mmrl.ui.component.scaffold.ScaffoldScope -import com.dergoogler.mmrl.ui.component.scrollbar.VerticalFastScrollbar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModuleState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.dergoogler.mmrl.ui.screens.repository.ModuleItemCompact -import com.dergoogler.mmrl.ui.screens.repository.ModuleItemDetailed import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDestination import dev.chrisbanes.haze.hazeSource @@ -41,6 +38,7 @@ fun ScaffoldScope.TypedModulesList( repo: Repo, list: List>, state: LazyListState, + beforeContent: LazyListScope.() -> Unit = {}, ) { val navigator = LocalDestinationsNavigator.current val userPreferences = LocalUserPreferences.current @@ -57,16 +55,18 @@ fun ScaffoldScope.TypedModulesList( this@TypedModulesList.ResponsiveContent { LazyColumn( state = state, - modifier = Modifier.fillMaxSize().hazeSource(LocalHazeState.current), + modifier = Modifier + .fillMaxSize() + .hazeSource(LocalHazeState.current), contentPadding = PaddingValues( - top = innerPadding.calculateTopPadding() + pad, + // top = innerPadding.calculateTopPadding(), bottom = pad, - start = innerPadding.calculateStartPadding(layoutDirection) + pad, - end = pad, ), verticalArrangement = Arrangement.spacedBy(16.dp), ) { + beforeContent() + items( items = list, key = { it.second.id }, @@ -81,16 +81,23 @@ fun ScaffoldScope.TypedModulesList( ) } - when (menu.repoListMode) { - RepoListMode.Compact -> - ModuleItemCompact( - onClick = click, - ) + Box( + modifier = Modifier.padding( + start = innerPadding.calculateStartPadding(layoutDirection) + pad, + end = pad, + ) + ) { + when (menu.repoListMode) { + RepoListMode.Compact -> + ModuleItemCompact( + onClick = click, + ) - RepoListMode.Detailed -> - ModuleItemDetailed( - onClick = click, - ) + RepoListMode.Detailed -> + ModuleItemDetailed( + onClick = click, + ) + } } } } @@ -100,16 +107,5 @@ fun ScaffoldScope.TypedModulesList( } } } - - VerticalFastScrollbar( - state = state, - modifier = - Modifier - .align(Alignment.CenterEnd) - .padding( - top = innerPadding.calculateTopPadding(), - bottom = paddingValues.calculateBottomPadding(), - ), - ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index 4903fa61a..ed31c32a7 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -9,32 +9,31 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.alpha import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity @@ -50,318 +49,267 @@ import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R import com.dergoogler.mmrl.database.entity.Repo +import com.dergoogler.mmrl.datastore.model.RepositoryMenu import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.isNotNullOrBlank import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.nullply import com.dergoogler.mmrl.ext.onClick -import com.dergoogler.mmrl.ext.rememberSaveableLazyListState import com.dergoogler.mmrl.ext.stripLinks -import com.dergoogler.mmrl.model.ui.TopCategory import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LabelItem import com.dergoogler.mmrl.ui.component.LabelItemDefaults -import com.dergoogler.mmrl.ui.component.Loading import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.PageIndicator import com.dergoogler.mmrl.ui.component.card.Card import com.dergoogler.mmrl.ui.component.scaffold.Scaffold import com.dergoogler.mmrl.ui.component.text.BBCodeText -import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar +import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar import com.dergoogler.mmrl.ui.component.toolbar.ToolbarTitle -import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings -import com.dergoogler.mmrl.ui.providable.LocalRepo -import com.dergoogler.mmrl.ui.screens.repository.modules.ModulesFilter +import com.dergoogler.mmrl.ui.component.toolbar.rememberBlurToolbarState import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph -import com.ramcosta.composedestinations.generated.destinations.TypedModulesScreenDestination -import dev.chrisbanes.haze.hazeSource import dev.dergoogler.mmrl.compat.core.LocalUriHandler -@Destination() +@Destination @Composable -fun RepositoryScreen(repo: Repo) = - LocalScreenProvider { - val viewModel = RepositoryViewModel.build(repo) - val list by viewModel.online.collectAsStateWithLifecycle() +fun RepositoryScreen( + repo: Repo, +) = LocalScreenProvider { + val browser = LocalUriHandler.current + val density = LocalDensity.current - val browser = LocalUriHandler.current - val density = LocalDensity.current - val navigator = LocalDestinationsNavigator.current - val hazeState = LocalHazeState.current + val viewModel = RepositoryViewModel.build(repo) + val modules by viewModel.online.collectAsStateWithLifecycle() - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val query by viewModel.query.collectAsStateWithLifecycle() + val openSearch = viewModel::openSearch + val closeSearch = viewModel::closeSearch + val search = viewModel::search + val isSearch by viewModel::isSearch + val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() - // Use rememberSaveable to persist scroll position across navigation - val listState = rememberSaveableLazyListState(key = "repository_${repo.url}") + var coverHeight by remember { mutableIntStateOf(0) } + var cardHeight by remember { mutableIntStateOf(0) } - BackHandler( - enabled = viewModel.isSearch, - onBack = viewModel::closeSearch, - ) + BackHandler(enabled = viewModel.isSearch, onBack = viewModel::closeSearch) - val modules = remember(list) { list.map { it.second } } - val topCategories = remember(modules) { TopCategory.fromModuleList(modules) } - val metaModules = remember(modules) { - modules.filter { - it.permissions?.contains("kernelsu.permission.METAMODULE") == true - } - } + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + topBar = { + TopBar( + repo = repo, + isSearch = isSearch, + query = query, + onQueryChange = search, + onOpenSearch = openSearch, + onCloseSearch = closeSearch, + scrollBehavior = scrollBehavior, + setMenu = viewModel::setRepositoryMenu, + ) + }, + contentWindowInsets = WindowInsets.none, + ) { innerPadding -> + if (modules.isEmpty()) { + PageIndicator( + icon = R.drawable.cloud, + text = if (isSearch) R.string.search_empty else R.string.repository_empty, + ) - var coverHeight by remember { mutableIntStateOf(0) } - var cardHeight by remember { mutableIntStateOf(0) } + return@Scaffold + } - CompositionLocalProvider( - LocalRepo provides repo, + this@Scaffold.TypedModulesList( + innerPadding = innerPadding, + repo = repo, + list = modules, + state = viewModel.listState, ) { - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - BlurToolbar( - fadeBackgroundIfNoBlur = true, - navigationIcon = { - IconButton(onClick = { navigator.popBackStack() }) { - Icon( - painter = painterResource(id = R.drawable.arrow_left), - contentDescription = null, + item { + Box { + Cover( + modifier = + Modifier + .fadingEdge( + brush = + Brush.verticalGradient( + colors = listOf( + Color.Transparent, + Color.Black + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, + ), ) - } - }, - title = { - ToolbarTitle( - modifier = Modifier.alpha(it), - title = repo.name, - ) - }, - fade = true, - scrollBehavior = scrollBehavior, + .onGloballyPositioned { coordinates -> + coverHeight = coordinates.size.height + }, + url = repo.cover ?: "ERROR ME", + errorIcon = R.drawable.box, ) - }, - contentWindowInsets = WindowInsets.none, - ) { _ -> - ResponsiveContent { - if (viewModel.isLoading) { - Loading() - - return@ResponsiveContent - } - - if (list.isEmpty() && !viewModel.isLoading) { - PageIndicator( - icon = R.drawable.cloud, - text = if (viewModel.isSearch) R.string.search_empty else R.string.repository_empty, - ) - return@ResponsiveContent - } - - LazyColumn( - state = listState, + Box( modifier = Modifier - .fillMaxSize() - .hazeSource(state = hazeState), - verticalArrangement = Arrangement.spacedBy(16.dp), + .offset(y = 164.4.dp) + .align(Alignment.TopCenter) + .fillMaxWidth(0.85f) + .onGloballyPositioned { coordinates -> + cardHeight = coordinates.size.height + }, ) { - item { - Box { - Cover( - modifier = - Modifier - .fadingEdge( - brush = - Brush.verticalGradient( - colors = listOf( - Color.Transparent, - Color.Black + Card( + modifier = + Modifier + .align(Alignment.BottomCenter) + .background( + brush = + Brush.linearGradient( + colors = + listOf( + MaterialTheme.colorScheme.surfaceColorAtElevation( + 1.dp, ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, + MaterialTheme.colorScheme.background, ), - ) - .onGloballyPositioned { coordinates -> - coverHeight = coordinates.size.height - }, - url = repo.cover ?: "ERROR ME", - errorIcon = R.drawable.box, + start = Offset(0f, 0f), + end = + Offset( + Float.POSITIVE_INFINITY, + Float.POSITIVE_INFINITY, + ), + ), + RoundedCornerShape(20.dp), + ) + .border( + Dp.Hairline, + MaterialTheme.colorScheme.outlineVariant, + RoundedCornerShape(20.dp), + ), + ) { + Column( + modifier = + Modifier + .relative() + .padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + Text( + text = repo.name, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + textAlign = TextAlign.Center, + style = MaterialTheme.typography.headlineMedium, + fontWeight = FontWeight.Bold, + color = MaterialTheme.colorScheme.onBackground, ) - Box( - modifier = - Modifier - .offset(y = 164.4.dp) - .align(Alignment.TopCenter) - .fillMaxWidth(0.85f) - .onGloballyPositioned { coordinates -> - cardHeight = coordinates.size.height - }, - ) { - Card( - modifier = - Modifier - .align(Alignment.BottomCenter) - .background( - brush = - Brush.linearGradient( - colors = - listOf( - MaterialTheme.colorScheme.surfaceColorAtElevation( - 1.dp, - ), - MaterialTheme.colorScheme.background, - ), - start = Offset(0f, 0f), - end = - Offset( - Float.POSITIVE_INFINITY, - Float.POSITIVE_INFINITY, - ), - ), - RoundedCornerShape(20.dp), - ) - .border( - Dp.Hairline, - MaterialTheme.colorScheme.outlineVariant, - RoundedCornerShape(20.dp), - ), - ) { - Column( - modifier = - Modifier - .relative() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - Text( - text = repo.name, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - textAlign = TextAlign.Center, - style = MaterialTheme.typography.headlineMedium, - fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onBackground, - ) + BBCodeText( + text = + ( + repo.description + ?: stringResource(R.string.view_module_no_description) + ).stripLinks( + "", + ), + style = MaterialTheme.typography.bodyMedium, + textAlign = TextAlign.Center, + color = MaterialTheme.colorScheme.outlineVariant, + lineHeight = 20.sp, + ) - BBCodeText( - text = - ( - repo.description - ?: stringResource(R.string.view_module_no_description) - ).stripLinks( - "", - ), - style = MaterialTheme.typography.bodyMedium, - textAlign = TextAlign.Center, - color = MaterialTheme.colorScheme.outlineVariant, - lineHeight = 20.sp, + FlowRow { + repo.nullply { + if (submission.isNotNullOrBlank()) { + LabelItem( + style = + LabelItemDefaults.style.copy( + containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, + contentColor = MaterialTheme.colorScheme.onSurfaceVariant, + ), + modifier = + Modifier.onClick { + browser.openUri(submission) + }, + icon = getDomainIcon(submission), + text = stringResource(R.string.repo_options_submission), ) - - FlowRow { - repo.nullply { - if (submission.isNotNullOrBlank()) { - LabelItem( - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, - contentColor = MaterialTheme.colorScheme.onSurfaceVariant, - ), - modifier = - Modifier.onClick { - browser.openUri(submission) - }, - icon = getDomainIcon(submission), - text = stringResource(R.string.repo_options_submission), - ) - } - } - } } } } - - with(density) { - Spacer(modifier = Modifier.height(((coverHeight / 1.2f) + cardHeight).toDp())) - } - } - } - - item { - val takenModules = remember { modules.take(9) } - val title = stringResource(R.string.page_modules) - - TopPicks( - label = title, - list = takenModules, - onMoreClick = { - navigator.navigate( - TypedModulesScreenDestination( - type = ModulesFilter.ALL, - title = title, - repo = repo, - ), - ) - }, - ) - } - - if (!metaModules.isEmpty() && viewModel.platform.isKernelSuVariant) { - item { - val title = stringResource(R.string.meta_modules) - - TopPicks( - label = title, - icon = com.dergoogler.mmrl.ui.R.drawable.kernelsu_logo, - list = metaModules, - onMoreClick = { - navigator.navigate( - TypedModulesScreenDestination( - type = ModulesFilter.ALL, - title = title, - repo = repo, - ), - ) - }, - ) } } + } - items( - items = topCategories, - key = { it.label }, - ) { - TopPicks( - label = it.label, - list = it.modules, - onMoreClick = { - navigator.navigate( - TypedModulesScreenDestination( - type = ModulesFilter.CATEGORY, - title = it.label, - repo = repo, - query = it.label, - ), - ) - }, - ) - } - - item { - Spacer( - Modifier.height(16.dp), - ) - - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } + with(density) { + Spacer(modifier = Modifier.height((((coverHeight / 1.05f) + cardHeight)).toDp())) } } } } } +} + +@Composable +private fun TopBar( + repo: Repo, + isSearch: Boolean, + query: String, + onQueryChange: (String) -> Unit, + onOpenSearch: () -> Unit, + onCloseSearch: () -> Unit, + scrollBehavior: TopAppBarScrollBehavior, + setMenu: (RepositoryMenu) -> Unit, +) { + val state = rememberBlurToolbarState(scrollBehavior, fade = true) + + var currentQuery by remember { mutableStateOf(query) } + DisposableEffect(isSearch) { + onDispose { currentQuery = "" } + } + + BlurSearchToolbar( + state = state, + fadeBackgroundIfNoBlur = true, + isSearch = isSearch, + query = currentQuery, + scrollBehavior = scrollBehavior, + fade = true, + fadeDistance = 200f, + onQueryChange = { + onQueryChange(it) + currentQuery = it + }, + onClose = { + onCloseSearch() + currentQuery = "" + }, + title = { + ToolbarTitle( + title = repo.name, + modifier = Modifier.graphicsLayer { alpha = state.alpha }, + ) + }, + actions = { + if (!isSearch) { + IconButton( + onClick = onOpenSearch, + ) { + Icon( + painter = painterResource(id = R.drawable.search), + contentDescription = null, + ) + } + } + + RepositoryMenu( + setMenu = setMenu, + ) + }, + ) +} @Composable fun getDomainIcon(url: String) = @@ -378,4 +326,4 @@ fun getDomain(url: String): String = if (host.startsWith("www.")) host.substring(4) else host } catch (_: Exception) { "" - } + } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPickModule.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPickModule.kt deleted file mode 100644 index 0171099bd..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPickModule.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.repository - -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -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.shape.RoundedCornerShape -import androidx.compose.material3.Icon -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalDensity -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.Dp -import androidx.compose.ui.unit.dp -import coil.compose.AsyncImage -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.iconSize -import com.dergoogler.mmrl.ui.component.Logo -import com.dergoogler.mmrl.ui.component.card.Card -import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalOnlineModule -import com.dergoogler.mmrl.ui.providable.LocalRepo -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDestination - -@Composable -fun TopPickModule( - modifier: Modifier = Modifier, - enabled: Boolean = true, -) { - val navigator = LocalDestinationsNavigator.current - val module = LocalOnlineModule.current - val repo = LocalRepo.current - val userPreferences = LocalUserPreferences.current - val menu = userPreferences.repositoryMenu - val isVerified = module.isVerified && menu.showVerified - - Card( - onClick = { - navigator.navigate(NewViewScreenDestination(repo, module)) - }, - modifier = - modifier - .fillMaxWidth() - .border( - width = Dp.Hairline, - color = MaterialTheme.colorScheme.outlineVariant, - shape = RoundedCornerShape(20.dp), - ), - enabled = enabled, - shape = RoundedCornerShape(20.dp), - ) { - Row( - modifier = - Modifier - .padding(all = 16.dp) - .relative(), - verticalAlignment = Alignment.CenterVertically, - ) { - Logo( - contentColor = MaterialTheme.colorScheme.onSecondaryContainer, - containerColor = MaterialTheme.colorScheme.secondaryContainer, - modifier = Modifier.size(64.dp), - shape = RoundedCornerShape(20), - icon = { - if (module.icon != null) { - AsyncImage( - model = module.icon, - contentScale = ContentScale.Crop, - contentDescription = null, - ) - } else { - Icon( - modifier = it, - painter = painterResource(id = R.drawable.box), - contentDescription = null, - ) - } - }, - ) - - Spacer(modifier = Modifier.width(10.dp)) - - Column( - modifier = Modifier.weight(1f), - ) { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - val style = - MaterialTheme.typography.titleSmall.copy( - fontWeight = FontWeight.Bold, - ) - - Text( - text = module.name, - style = style, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - - if (isVerified) { - Icon( - modifier = Modifier.iconSize(LocalDensity.current, style, 1.0f), - painter = painterResource(id = R.drawable.rosette_discount_check), - contentDescription = null, - tint = MaterialTheme.colorScheme.surfaceTint, - ) - } - } - - Spacer(modifier = Modifier.height(2.dp)) - - Text( - text = module.author, - style = MaterialTheme.typography.bodyMedium.copy(), - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - Text( - maxLines = 1, - text = module.versionDisplay, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.outline, - ) - } - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPicks.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPicks.kt deleted file mode 100644 index b8daa2e20..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/TopPicks.kt +++ /dev/null @@ -1,105 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.repository - -import androidx.annotation.DrawableRes -import androidx.compose.animation.animateContentSize -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.pager.HorizontalPager -import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.model.online.OnlineModule -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListItemSlot -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title -import com.dergoogler.mmrl.ui.providable.LocalOnlineModule - -@Composable -fun TopPicks( - label: String, - @DrawableRes icon: Int? = null, - onMoreClick: () -> Unit, - list: List, -) { - val randomModules = - remember(list) { - list - .shuffled() - .sortedBy { if (it == OnlineModule.example()) 1 else 0 } - } - - val pagerState = - rememberPagerState(pageCount = { (randomModules.size + 2) / 3 }) - - List { - ButtonItem( - onClick = onMoreClick, - ) { - icon.nullable { - Icon( - slot = ListItemSlot.Start, - painter = painterResource(it), - ) - } - Title(label) - Icon( - slot = ListItemSlot.End, - painter = painterResource(R.drawable.arrow_right), - ) - } - - Spacer(Modifier.height(8.dp)) - - HorizontalPager( - state = pagerState, - modifier = - Modifier - .fillMaxWidth() - .animateContentSize(), - contentPadding = PaddingValues(horizontal = 16.dp), - ) { page -> - Column( - modifier = - Modifier - .fillMaxWidth() - .padding(horizontal = 6.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - horizontalAlignment = Alignment.CenterHorizontally, - ) { - for (i in 0 until 3) { - val itemIndex = page * 3 + i - if (itemIndex < randomModules.size) { - val item = randomModules[itemIndex] - - CompositionLocalProvider( - LocalOnlineModule provides item, - ) { - if (item.id == "##==online_example==##") { - Spacer(Modifier.height(96.dp)) - return@CompositionLocalProvider - } - - TopPickModule( - modifier = Modifier.height(96.dp), - ) - } - } - } - } - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesScreen.kt deleted file mode 100644 index 03b9d0972..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/modules/TypedModulesScreen.kt +++ /dev/null @@ -1,208 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.repository.modules - -import androidx.activity.compose.BackHandler -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.res.painterResource -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.database.entity.Repo -import com.dergoogler.mmrl.datastore.model.RepositoryMenu -import com.dergoogler.mmrl.ext.isNotNullOrBlank -import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ext.rememberSaveableLazyListState -import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.PageIndicator -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar -import com.dergoogler.mmrl.ui.component.toolbar.ToolbarTitle -import com.dergoogler.mmrl.ui.remember.rememberOnlineModules -import com.dergoogler.mmrl.ui.remember.rememberUserPreferencesRepository -import com.dergoogler.mmrl.ui.screens.repository.RepositoryMenu -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootGraph -import kotlinx.coroutines.launch -import kotlinx.serialization.Serializable - -@Serializable -enum class ModulesFilter { - ALL, - AUTHOR, - CATEGORY, - NAME, -} - -@Destination -@Composable -fun TypedModulesScreen( - title: String? = null, - type: ModulesFilter = ModulesFilter.ALL, - query: String = "", - repo: Repo, -) = LocalScreenProvider { - var searchQuery by remember { mutableStateOf("") } - val modules by rememberOnlineModules(repo, searchQuery) - val userPreferencesRepository = rememberUserPreferencesRepository() - val scope = rememberCoroutineScope() - var isSearch by remember { mutableStateOf(false) } - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() - // Use rememberSaveable to persist scroll position across navigation - val listState = rememberSaveableLazyListState(key = "typed_modules_${repo.url}_${type}_${query}") - - val filterQuery = remember { query } - - val filteredModules = - remember(modules, filterQuery, type, searchQuery) { - modules.filter { (_, m) -> - val typeMatches = - when (type) { - ModulesFilter.ALL -> true - ModulesFilter.AUTHOR -> m.author.equals(filterQuery, ignoreCase = true) - ModulesFilter.CATEGORY -> - m.categories?.any { - it.equals( - filterQuery, - ignoreCase = true, - ) - } ?: false - - ModulesFilter.NAME -> m.name.equals(filterQuery, ignoreCase = true) - } - - val searchMatches = - if (searchQuery.isBlank()) { - true - } else { - m.name.contains(searchQuery, ignoreCase = true) || - m.author.contains(searchQuery, ignoreCase = true) || - (m.categories?.any { it.contains(searchQuery, ignoreCase = true) } ?: false) - } - - typeMatches && searchMatches - } - } - - val openSearch = fun() { - isSearch = true - } - - val closeSearch = fun() { - isSearch = false - searchQuery = "" - } - - val search = fun(data: String) { - searchQuery = data - } - - val setRepositoryMenu = fun(value: RepositoryMenu) { - scope.launch { - userPreferencesRepository.setRepositoryMenu(value) - } - } - - BackHandler(enabled = isSearch, onBack = closeSearch) - - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - title = title, - repo = repo, - isSearch = isSearch, - query = searchQuery, - onQueryChange = search, - onOpenSearch = openSearch, - onCloseSearch = closeSearch, - setMenu = setRepositoryMenu, - ) - }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - if (filteredModules.isEmpty()) { - PageIndicator( - icon = R.drawable.cloud, - text = if (isSearch) R.string.search_empty else R.string.repository_empty, - ) - } - - this@Scaffold.TypedModulesList( - innerPadding = innerPadding, - repo = repo, - list = filteredModules, - state = listState, - ) - } -} - -@Composable -private fun TopBar( - title: String?, - repo: Repo, - isSearch: Boolean, - query: String, - onQueryChange: (String) -> Unit, - onOpenSearch: () -> Unit, - onCloseSearch: () -> Unit, - setMenu: (RepositoryMenu) -> Unit, -) { - var currentQuery by remember { mutableStateOf(query) } - DisposableEffect(isSearch) { - onDispose { currentQuery = "" } - } - - BlurSearchToolbar( - isSearch = isSearch, - query = currentQuery, - fade = true, - fadeDistance = 50f, - onQueryChange = { - onQueryChange(it) - currentQuery = it - }, - onClose = { - onCloseSearch() - currentQuery = "" - }, - title = { - if (title.isNotNullOrBlank()) { - ToolbarTitle( - title = title, - subtitle = repo.name, - ) - - return@BlurSearchToolbar - } - - ToolbarTitle( - title = repo.name, - ) - }, - actions = { - if (!isSearch) { - IconButton( - onClick = onOpenSearch, - ) { - Icon( - painter = painterResource(id = R.drawable.search), - contentDescription = null, - ) - } - } - - RepositoryMenu( - setMenu = setMenu, - ) - }, - ) -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/search/SearchScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/search/SearchScreen.kt index e58f029d1..88c19d370 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/search/SearchScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/search/SearchScreen.kt @@ -35,8 +35,8 @@ fun SearchScreen() = topBar = { BlurSearchToolbar( isSearch = true, - query = query, autoFocus = false, + query = query, onQueryChange = viewModel::search, title = {}, ) From f48c02ae8fb1b802cf0313eb47314da344b8a66c Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 17:26:56 +0200 Subject: [PATCH 09/55] Add WebUI X branding for config permissions Replace the MMRL WebUI config label with a dedicated WebUI X label in the permission UI, update the related user-facing strings, and add a new WebUI X vector icon asset for the badge. --- .../mmrl/ui/component/PermissionItem.kt | 6 +-- app/src/main/res/values/strings.xml | 4 +- .../dergoogler/mmrl/ui/component/LabelItem.kt | 8 ++++ ui/src/main/res/drawable/wxp_logo.xml | 41 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 ui/src/main/res/drawable/wxp_logo.xml diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt index fa0502746..785cb31cd 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt @@ -16,7 +16,7 @@ import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title fun ListScope.PermissionItem( permissions: List, contentPadding: PaddingValues, -) = permissions.forEach { +) = permissions.forEach { it -> val permission = getPermissionDetails(it) permission.nullable { p -> Item( @@ -80,7 +80,7 @@ private fun getPermissionDetails(id: String): Permission? { { KernelSuLabel() APatchLabel() - MMRLLabel() + WebUIXLabel() }, ), "kernelsu.permission.POST_MOUNT" to @@ -111,7 +111,7 @@ private fun getPermissionDetails(id: String): Permission? { Permission( R.string.view_module_features_mmrl_webui_config, R.string.view_module_features_mmrl_webui_config_sub, - { MMRLLabel() }, + { WebUIXLabel() }, ), "mmrl.permission.APKS" to Permission( diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 91b494309..279f9b1c2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -372,8 +372,8 @@ Failed to close the action execution MMRL WebUI This module includes a MMRL only WebUI. - MMRL WebUI Config - This module uses a config file for WebUI\'s in MMRL + WebUI X Config + This module uses a configuration file for WebUI\'s in WebUI X FileSystem API This module maybe used the FileSystem API provided by MMRL. Eruda Console diff --git a/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/LabelItem.kt b/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/LabelItem.kt index b5f9f85c8..d83bca037 100644 --- a/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/LabelItem.kt +++ b/ui/src/main/kotlin/com/dergoogler/mmrl/ui/component/LabelItem.kt @@ -201,6 +201,14 @@ fun MMRLLabel() { ) } +@Composable +fun WebUIXLabel() { + LabelItem( + icon = R.drawable.wxp_logo, + text = "WebUI X", + ) +} + @Composable fun SukiSU() { LabelItem( diff --git a/ui/src/main/res/drawable/wxp_logo.xml b/ui/src/main/res/drawable/wxp_logo.xml new file mode 100644 index 000000000..3720d1718 --- /dev/null +++ b/ui/src/main/res/drawable/wxp_logo.xml @@ -0,0 +1,41 @@ + + + + + + + From dad70c40a1907000ac91e779e9b955800bcd1628 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:05:20 +0200 Subject: [PATCH 10/55] Hide repo bulk install for invalid platforms Gate the repositories bulk-install FAB behind `platform.isValid` so it only appears on supported root platforms. Update platform validity to treat `Unknown` as invalid (alongside `NonRoot`), bump `mmrlx` to `1.0.229`, and clean up redundant self-imports in `PlatformManager`. --- .../repositories/RepositoriesScreen.kt | 41 ++++++++++--------- gradle/libs.versions.toml | 2 +- .../com/dergoogler/mmrl/platform/Platform.kt | 2 +- .../mmrl/platform/PlatformManager.kt | 7 ---- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt index a9da830cd..3e173d8ab 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.repositories +import android.util.Log import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.tween import androidx.compose.animation.scaleIn @@ -87,7 +88,7 @@ fun RepositoriesScreen() = val progress by viewModel.progress.collectAsStateWithLifecycle() val pullToRefreshState = rememberPullToRefreshState() - + // Use rememberSaveable to persist scroll position across navigation val listState = rememberSaveableLazyListState(key = "repositories_list") @@ -166,24 +167,26 @@ fun RepositoriesScreen() = }, contentWindowInsets = WindowInsets.none, floatingActionButton = { - AnimatedVisibility( - visible = showFab, - enter = - scaleIn( - animationSpec = tween(100), - initialScale = 0.8f, - ), - exit = - scaleOut( - animationSpec = tween(100), - targetScale = 0.8f, - ), - ) { - FloatingButton( - onClick = { - bulkInstallBottomSheet = true - }, - ) + if (viewModel.platform.isValid) { + AnimatedVisibility( + visible = showFab, + enter = + scaleIn( + animationSpec = tween(100), + initialScale = 0.8f, + ), + exit = + scaleOut( + animationSpec = tween(100), + targetScale = 0.8f, + ), + ) { + FloatingButton( + onClick = { + bulkInstallBottomSheet = true + }, + ) + } } }, ) { innerPadding -> diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c633516a5..3593d02c5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.224" +mmrlx = "1.0.229" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" diff --git a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/Platform.kt b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/Platform.kt index 7fd1bc033..81b243847 100644 --- a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/Platform.kt +++ b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/Platform.kt @@ -172,7 +172,7 @@ enum class Platform( // Category checks val isKernelSuVariant: Boolean get() = type is PlatformType.KernelSU val isKernelSuOrNext: Boolean get() = this == KernelSU || this == KsuNext - val isValid: Boolean get() = this != NonRoot + val isValid: Boolean get() = this != NonRoot && this != Unknown // Negation checks (computed properties for consistency) val isNotMagisk: Boolean get() = !isMagisk diff --git a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/PlatformManager.kt b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/PlatformManager.kt index 86377b170..074b99921 100644 --- a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/PlatformManager.kt +++ b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/PlatformManager.kt @@ -14,13 +14,6 @@ import androidx.compose.runtime.DisallowComposableCalls import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import com.dergoogler.mmrl.platform.PlatformManager.isAlive -import com.dergoogler.mmrl.platform.PlatformManager.isAliveDeferred -import com.dergoogler.mmrl.platform.PlatformManager.isAliveFlow -import com.dergoogler.mmrl.platform.PlatformManager.mService -import com.dergoogler.mmrl.platform.PlatformManager.proxyBy -import com.dergoogler.mmrl.platform.PlatformManager.serviceOrNull -import com.dergoogler.mmrl.platform.PlatformManager.state import com.dergoogler.mmrl.platform.content.IService import com.dergoogler.mmrl.platform.content.Service import com.dergoogler.mmrl.platform.hiddenApi.HiddenPackageManager From 457acbd4bc9b7a0fb84227e2905c3ecccab3c3d0 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:31:38 +0200 Subject: [PATCH 11/55] Bump library modules to compileSdk 37 Updates compileSdk from 36 to 37 across compat, datastore, ext, platform, and ui modules to align Android build targets. Also adds trailing commas in module include lists in compat and datastore settings for consistent Kotlin DSL formatting. --- compat/build.gradle.kts | 2 +- compat/settings.gradle.kts | 2 +- datastore/build.gradle.kts | 2 +- datastore/settings.gradle.kts | 2 +- ext/build.gradle.kts | 2 +- platform/build.gradle.kts | 2 +- ui/build.gradle.kts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compat/build.gradle.kts b/compat/build.gradle.kts index b9f919f45..b13c7915a 100644 --- a/compat/build.gradle.kts +++ b/compat/build.gradle.kts @@ -8,7 +8,7 @@ plugins { android { namespace = "com.dergoogler.mmrl.compat" - compileSdk = 36 + compileSdk = 37 defaultConfig { minSdk = 26 diff --git a/compat/settings.gradle.kts b/compat/settings.gradle.kts index 10a989ad5..c799adea2 100644 --- a/compat/settings.gradle.kts +++ b/compat/settings.gradle.kts @@ -13,6 +13,6 @@ dependencyResolutionManagement { include( ":platform", - ":ui" + ":ui", ":ext" ) diff --git a/datastore/build.gradle.kts b/datastore/build.gradle.kts index 59eaa7051..a2e294e62 100644 --- a/datastore/build.gradle.kts +++ b/datastore/build.gradle.kts @@ -7,7 +7,7 @@ plugins { android { namespace = "com.dergoogler.mmrl.datastore" - compileSdk = 36 + compileSdk = 37 defaultConfig { minSdk = 26 diff --git a/datastore/settings.gradle.kts b/datastore/settings.gradle.kts index 10a989ad5..c799adea2 100644 --- a/datastore/settings.gradle.kts +++ b/datastore/settings.gradle.kts @@ -13,6 +13,6 @@ dependencyResolutionManagement { include( ":platform", - ":ui" + ":ui", ":ext" ) diff --git a/ext/build.gradle.kts b/ext/build.gradle.kts index 72b3575cd..65f8d45f3 100644 --- a/ext/build.gradle.kts +++ b/ext/build.gradle.kts @@ -8,7 +8,7 @@ plugins { android { namespace = "com.dergoogler.mmrl.ext" - compileSdk = 36 + compileSdk = 37 defaultConfig { minSdk = 26 diff --git a/platform/build.gradle.kts b/platform/build.gradle.kts index da888f8bf..7b5860312 100644 --- a/platform/build.gradle.kts +++ b/platform/build.gradle.kts @@ -10,7 +10,7 @@ plugins { android { namespace = "com.dergoogler.mmrl.platform" - compileSdk = 36 + compileSdk = 37 publishing { singleVariant("release") diff --git a/ui/build.gradle.kts b/ui/build.gradle.kts index 426d1f744..d89502abe 100644 --- a/ui/build.gradle.kts +++ b/ui/build.gradle.kts @@ -7,7 +7,7 @@ plugins { android { namespace = "com.dergoogler.mmrl.ui" - compileSdk = 36 + compileSdk = 37 publishing { singleVariant("release") From edb82f19ef1748dc92ac8ef91222e734b9e55df1 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:32:02 +0200 Subject: [PATCH 12/55] Refine repository search and menu state Refactors `RepositoryViewModel` to derive the repository module list from combined flows, including sorting and prefixed search filtering, instead of managing separate cache/search observers. It also fixes the category toggle in the repository menu and hides the repository cover/header content while search is active. --- .../repositories/RepositoriesScreen.kt | 1 - .../ui/screens/repository/RepositoryMenu.kt | 2 +- .../ui/screens/repository/RepositoryScreen.kt | 210 ++++++------ .../mmrl/viewmodel/RepositoryViewModel.kt | 324 +++++++++--------- 4 files changed, 268 insertions(+), 269 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt index 3e173d8ab..1e78e2dd0 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt @@ -1,6 +1,5 @@ package com.dergoogler.mmrl.ui.screens.repositories -import android.util.Log import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.tween import androidx.compose.animation.scaleIn diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt index 853d31547..1c706f7b8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt @@ -190,7 +190,7 @@ private fun MenuBottomSheet( MenuChip( selected = menu.showCategory, - onClick = { setMenu(menu.copy(showIcon = !menu.showCategory)) }, + onClick = { setMenu(menu.copy(showCategory = !menu.showCategory)) }, label = { Text(text = stringResource(id = R.string.menu_show_category)) }, ) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index ed31c32a7..57ded4d76 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -98,7 +98,7 @@ fun RepositoryScreen( Scaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = { - TopBar( + TopBar0( repo = repo, isSearch = isSearch, query = query, @@ -126,125 +126,127 @@ fun RepositoryScreen( list = modules, state = viewModel.listState, ) { - item { - Box { - Cover( - modifier = - Modifier - .fadingEdge( - brush = - Brush.verticalGradient( - colors = listOf( - Color.Transparent, - Color.Black - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), - ) - .onGloballyPositioned { coordinates -> - coverHeight = coordinates.size.height - }, - url = repo.cover ?: "ERROR ME", - errorIcon = R.drawable.box, - ) - - Box( - modifier = - Modifier - .offset(y = 164.4.dp) - .align(Alignment.TopCenter) - .fillMaxWidth(0.85f) - .onGloballyPositioned { coordinates -> - cardHeight = coordinates.size.height - }, - ) { - Card( + if (!isSearch) { + item { + Box { + Cover( modifier = Modifier - .align(Alignment.BottomCenter) - .background( + .fadingEdge( brush = - Brush.linearGradient( - colors = - listOf( - MaterialTheme.colorScheme.surfaceColorAtElevation( - 1.dp, - ), - MaterialTheme.colorScheme.background, - ), - start = Offset(0f, 0f), - end = - Offset( - Float.POSITIVE_INFINITY, - Float.POSITIVE_INFINITY, - ), + Brush.verticalGradient( + colors = listOf( + Color.Transparent, + Color.Black + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, ), - RoundedCornerShape(20.dp), ) - .border( - Dp.Hairline, - MaterialTheme.colorScheme.outlineVariant, - RoundedCornerShape(20.dp), - ), + .onGloballyPositioned { coordinates -> + coverHeight = coordinates.size.height + }, + url = repo.cover ?: "ERROR ME", + errorIcon = R.drawable.box, + ) + + Box( + modifier = + Modifier + .offset(y = 164.4.dp) + .align(Alignment.TopCenter) + .fillMaxWidth(0.85f) + .onGloballyPositioned { coordinates -> + cardHeight = coordinates.size.height + }, ) { - Column( + Card( modifier = Modifier - .relative() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.spacedBy(16.dp), + .align(Alignment.BottomCenter) + .background( + brush = + Brush.linearGradient( + colors = + listOf( + MaterialTheme.colorScheme.surfaceColorAtElevation( + 1.dp, + ), + MaterialTheme.colorScheme.background, + ), + start = Offset(0f, 0f), + end = + Offset( + Float.POSITIVE_INFINITY, + Float.POSITIVE_INFINITY, + ), + ), + RoundedCornerShape(20.dp), + ) + .border( + Dp.Hairline, + MaterialTheme.colorScheme.outlineVariant, + RoundedCornerShape(20.dp), + ), ) { - Text( - text = repo.name, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - textAlign = TextAlign.Center, - style = MaterialTheme.typography.headlineMedium, - fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onBackground, - ) + Column( + modifier = + Modifier + .relative() + .padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + Text( + text = repo.name, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + textAlign = TextAlign.Center, + style = MaterialTheme.typography.headlineMedium, + fontWeight = FontWeight.Bold, + color = MaterialTheme.colorScheme.onBackground, + ) - BBCodeText( - text = - ( - repo.description - ?: stringResource(R.string.view_module_no_description) - ).stripLinks( - "", - ), - style = MaterialTheme.typography.bodyMedium, - textAlign = TextAlign.Center, - color = MaterialTheme.colorScheme.outlineVariant, - lineHeight = 20.sp, - ) + BBCodeText( + text = + ( + repo.description + ?: stringResource(R.string.view_module_no_description) + ).stripLinks( + "", + ), + style = MaterialTheme.typography.bodyMedium, + textAlign = TextAlign.Center, + color = MaterialTheme.colorScheme.outlineVariant, + lineHeight = 20.sp, + ) - FlowRow { - repo.nullply { - if (submission.isNotNullOrBlank()) { - LabelItem( - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, - contentColor = MaterialTheme.colorScheme.onSurfaceVariant, - ), - modifier = - Modifier.onClick { - browser.openUri(submission) - }, - icon = getDomainIcon(submission), - text = stringResource(R.string.repo_options_submission), - ) + FlowRow { + repo.nullply { + if (submission.isNotNullOrBlank()) { + LabelItem( + style = + LabelItemDefaults.style.copy( + containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, + contentColor = MaterialTheme.colorScheme.onSurfaceVariant, + ), + modifier = + Modifier.onClick { + browser.openUri(submission) + }, + icon = getDomainIcon(submission), + text = stringResource(R.string.repo_options_submission), + ) + } } } } } } - } - with(density) { - Spacer(modifier = Modifier.height((((coverHeight / 1.05f) + cardHeight)).toDp())) + with(density) { + Spacer(modifier = Modifier.height((((coverHeight / 1.05f) + cardHeight)).toDp())) + } } } } @@ -253,7 +255,7 @@ fun RepositoryScreen( } @Composable -private fun TopBar( +private fun TopBar0( repo: Repo, isSearch: Boolean, query: String, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt index c8371ba8a..371cb1c53 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt @@ -23,192 +23,190 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import timber.log.Timber @HiltViewModel(assistedFactory = RepositoryViewModel.Factory::class) class RepositoryViewModel - @AssistedInject - constructor( - @Assisted val repo: Repo, - application: Application, - localRepository: LocalRepository, - modulesRepository: ModulesRepository, - userPreferencesRepository: UserPreferencesRepository, - ) : MMRLViewModel(application, localRepository, modulesRepository, userPreferencesRepository) { - private val repositoryMenu - get() = - userPreferencesRepository.data - .map { it.repositoryMenu } - - var isSearch by mutableStateOf(false) - private set - private val keyFlow = MutableStateFlow("") - val query get() = keyFlow.asStateFlow() - - val listState: LazyListState = LazyListState() - - private val cacheFlow = MutableStateFlow(listOf>()) - private val onlineFlow = MutableStateFlow(listOf>()) - val online get() = onlineFlow.asStateFlow() - - var isLoading by mutableStateOf(true) - private set - - init { - Timber.d("RepositoryViewModel init") - dataObserver() - keyObserver() +@AssistedInject +constructor( + @Assisted val repo: Repo, + application: Application, + localRepository: LocalRepository, + modulesRepository: ModulesRepository, + userPreferencesRepository: UserPreferencesRepository, +) : MMRLViewModel( + application, + localRepository, + modulesRepository, + userPreferencesRepository, +) { + private val keyFlow = MutableStateFlow("") + val query: StateFlow = keyFlow.asStateFlow() + + private val repositoryMenu = + userPreferencesRepository.data.map { it.repositoryMenu } + + val listState: LazyListState = LazyListState() + + var isSearch by mutableStateOf(false) + private set + + var isLoading by mutableStateOf(true) + private set + + private val onlineModules = + if (repo.url.isNotBlank()) { + localRepository.getOnlineAllByUrlAsFlow(repo.url) + } else { + localRepository.getOnlineAllAsFlow() } - private fun dataObserver() { - val onlineModules = - if (repo.url.isNotBlank()) { - localRepository.getOnlineAllByUrlAsFlow(repo.url) - } else { - localRepository.getOnlineAllAsFlow() - } + val online: StateFlow>> = + combine( + onlineModules, + repositoryMenu, + keyFlow, + ) { modules, menu, key -> + val source = modules.map { module -> + val local = localRepository.getLocalByIdOrNull(module.id) - combine( - onlineModules, - repositoryMenu, - ) { list, menu -> - cacheFlow.value = - list - .map { - val local = localRepository.getLocalByIdOrNull(it.id) - val versionsList = it.versions.toMutableList() - - if (local != null) { - UpdateJson.loadToVersionItem(local.updateJson)?.let { es -> - // no need to define here a repo name since we only need to for the last updated - versionsList.add(0, es) - } - } - - it.copy(versions = versionsList).createState( - local = local, - hasUpdatableTag = localRepository.hasUpdatableTag(it.id), - ) to it.copy(versions = versionsList) - }.sortedWith( - comparator(menu.option, menu.descending), - ).let { v -> - val a = - if (menu.pinInstalled) { - v.sortedByDescending { it.first.installed } - } else { - v - } - - if (menu.pinUpdatable) { - a.sortedByDescending { it.first.updatable } - } else { - a - } - } - - isLoading = false - }.launchIn(viewModelScope) - } + val versions = module.versions.toMutableList() - private fun keyObserver() { - combine( - keyFlow, - cacheFlow, - ) { key, source -> - val newKey = - when { - key.startsWith("id:", ignoreCase = true) -> key.removePrefix("id:") - key.startsWith("name:", ignoreCase = true) -> key.removePrefix("name:") - key.startsWith("author:", ignoreCase = true) -> key.removePrefix("author:") - key.startsWith("category:", ignoreCase = true) -> key.removePrefix("category:") - else -> key - }.trim() - - onlineFlow.value = - source.filter { (_, m) -> - if (key.isNotBlank() || newKey.isNotBlank()) { - when { - key.startsWith("id:", ignoreCase = true) -> - m.id.equals(newKey, ignoreCase = true) - - key.startsWith("name:", ignoreCase = true) -> - m.name.equals(newKey, ignoreCase = true) - - key.startsWith("author:", ignoreCase = true) -> - m.author.equals(newKey, ignoreCase = true) - - key.startsWith("category:", ignoreCase = true) -> - m.categories?.any { - it.equals( - newKey, - ignoreCase = true, - ) - } ?: false - - else -> - m.name.contains(key, ignoreCase = true) || - m.author.contains(key, ignoreCase = true) || - m.description?.contains(key, ignoreCase = true) == true - } - } else { - true - } + if (local != null) { + UpdateJson.loadToVersionItem(local.updateJson)?.let { + versions.add(0, it) } - }.launchIn(viewModelScope) - } + } - private fun comparator( - option: Option, - descending: Boolean, - ): Comparator> = - if (descending) { - when (option) { - Option.Name -> compareByDescending { it.second.name.lowercase() } - Option.UpdatedTime -> compareBy { it.first.lastUpdated } - Option.Size -> compareByDescending { 0 } + val updatedModule = module.copy(versions = versions) + + updatedModule.createState( + local = local, + hasUpdatableTag = localRepository.hasUpdatableTag(module.id), + ) to updatedModule + } + + val sorted = source + .sortedWith(comparator(menu.option, menu.descending)) + .let { list -> + if (menu.pinInstalled) { + list.sortedByDescending { it.first.installed } + } else { + list + } } + .let { list -> + if (menu.pinUpdatable) { + list.sortedByDescending { it.first.updatable } + } else { + list + } + } + + isLoading = false + + if (key.isBlank()) { + sorted } else { - when (option) { - Option.Name -> compareBy { it.second.name.lowercase() } - Option.UpdatedTime -> compareByDescending { it.first.lastUpdated } - Option.Size -> compareBy { 0 } + val (searchKey, prefix) = parseSearchKey(key) + + sorted.filter { (_, module) -> + when (prefix) { + "id" -> + module.id.equals(searchKey, ignoreCase = true) + + "name" -> + module.name.equals(searchKey, ignoreCase = true) + + "author" -> + module.author.equals(searchKey, ignoreCase = true) + + "category" -> + module.categories?.any { + it.equals(searchKey, ignoreCase = true) + } == true + + else -> + module.name.contains(searchKey, ignoreCase = true) || + module.author.contains(searchKey, ignoreCase = true) || + module.description?.contains( + searchKey, + ignoreCase = true, + ) == true + } } } - - fun search(key: String) { - keyFlow.value = key + }.stateIn( + scope = viewModelScope, + started = SharingStarted.WhileSubscribed(5_000), + initialValue = emptyList(), + ) + + private fun parseSearchKey(raw: String): Pair { + val prefix = listOf("id", "name", "author", "category") + .firstOrNull { raw.startsWith("$it:", ignoreCase = true) } + + return if (prefix != null) { + raw.substringAfter(":").trim() to prefix + } else { + raw.trim() to null } + } - fun openSearch() { - isSearch = true - } + private fun comparator( + option: Option, + descending: Boolean, + ): Comparator> { + val base: Comparator> = + when (option) { + Option.Name -> + compareBy { it.second.name.lowercase() } - fun closeSearch() { - isSearch = false - keyFlow.value = "" - } + Option.UpdatedTime -> + compareByDescending { it.first.lastUpdated } - fun setRepositoryMenu(value: RepositoryMenu) { - viewModelScope.launch { - userPreferencesRepository.setRepositoryMenu(value) + Option.Size -> + compareByDescending { 0 } } - } - @AssistedFactory - interface Factory { - fun create(repo: Repo): RepositoryViewModel - } + return if (descending) base.reversed() else base + } - companion object { - @Composable - fun build(repo: Repo): RepositoryViewModel = - hiltViewModel { factory -> - factory.create(repo) - } + fun search(key: String) { + keyFlow.value = key + } + + fun openSearch() { + isSearch = true + } + + fun closeSearch() { + isSearch = false + keyFlow.value = "" + } + + fun setRepositoryMenu(value: RepositoryMenu) { + viewModelScope.launch { + userPreferencesRepository.setRepositoryMenu(value) } } + + @AssistedFactory + interface Factory { + fun create(repo: Repo): RepositoryViewModel + } + + companion object { + @Composable + fun build(repo: Repo): RepositoryViewModel = + hiltViewModel { factory -> + factory.create(repo) + } + } +} \ No newline at end of file From 22394ec05605470128e45bf21650091b964ace04 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:33:10 +0200 Subject: [PATCH 13/55] Remove repositories fast scrollbar Drop the `VerticalFastScrollbar` from the repositories list screen and clean up the now-unused Compose imports. This simplifies the layout after the scrollbar was no longer needed. --- .../ui/screens/repositories/RepositoriesList.kt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt index c224ec578..3418716e4 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt @@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.requiredHeightIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState @@ -23,7 +22,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource @@ -31,7 +29,6 @@ import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.model.state.RepoState import com.dergoogler.mmrl.ui.component.scaffold.ScaffoldScope -import com.dergoogler.mmrl.ui.component.scrollbar.VerticalFastScrollbar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings @@ -92,17 +89,6 @@ fun ScaffoldScope.RepositoriesList( } } } - - VerticalFastScrollbar( - state = state, - modifier = - Modifier - .align(Alignment.CenterEnd) - .padding( - top = innerPadding.calculateTopPadding(), - bottom = paddingValues.calculateBottomPadding(), - ), - ) } @Composable From 0931788460de11cc032861373fccab2f7260c350 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:44:59 +0200 Subject: [PATCH 14/55] Animate repository list header transitions Refactors `TypedModulesList` to `ModulesList` and adds `animateContentSize()` to smooth list layout updates. In `RepositoryScreen`, it now reads `repositoryMenu` preferences to adjust top padding for compact mode and uses `AnimatedVisibility` to transition between search and non-search header states instead of abruptly adding/removing the cover item. --- .../mmrl/ui/screens/repository/ModulesList.kt | 6 ++++-- .../ui/screens/repository/RepositoryScreen.kt | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index de0b73074..bfbae90f2 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.repository +import androidx.compose.animation.animateContentSize import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues @@ -33,7 +34,7 @@ import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDest import dev.chrisbanes.haze.hazeSource @Composable -fun ScaffoldScope.TypedModulesList( +fun ScaffoldScope.ModulesList( innerPadding: PaddingValues, repo: Repo, list: List>, @@ -52,11 +53,12 @@ fun ScaffoldScope.TypedModulesList( Box( modifier = Modifier.fillMaxSize(), ) { - this@TypedModulesList.ResponsiveContent { + this@ModulesList.ResponsiveContent { LazyColumn( state = state, modifier = Modifier .fillMaxSize() + .animateContentSize() .hazeSource(LocalHazeState.current), contentPadding = PaddingValues( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index 57ded4d76..86be545ce 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -1,6 +1,7 @@ package com.dergoogler.mmrl.ui.screens.repository import androidx.activity.compose.BackHandler +import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement @@ -49,6 +50,7 @@ import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R import com.dergoogler.mmrl.database.entity.Repo +import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.datastore.model.RepositoryMenu import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.isNotNullOrBlank @@ -67,6 +69,7 @@ import com.dergoogler.mmrl.ui.component.text.BBCodeText import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar import com.dergoogler.mmrl.ui.component.toolbar.ToolbarTitle import com.dergoogler.mmrl.ui.component.toolbar.rememberBlurToolbarState +import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph @@ -77,6 +80,7 @@ import dev.dergoogler.mmrl.compat.core.LocalUriHandler fun RepositoryScreen( repo: Repo, ) = LocalScreenProvider { + val userPreferences = LocalUserPreferences.current val browser = LocalUriHandler.current val density = LocalDensity.current @@ -93,6 +97,9 @@ fun RepositoryScreen( var coverHeight by remember { mutableIntStateOf(0) } var cardHeight by remember { mutableIntStateOf(0) } + val menu = userPreferences.repositoryMenu + val pad = remember(menu) { if (menu.repoListMode == RepoListMode.Compact) 0.dp else 16.dp } + BackHandler(enabled = viewModel.isSearch, onBack = viewModel::closeSearch) Scaffold( @@ -120,15 +127,19 @@ fun RepositoryScreen( return@Scaffold } - this@Scaffold.TypedModulesList( + this@Scaffold.ModulesList( innerPadding = innerPadding, repo = repo, list = modules, state = viewModel.listState, ) { - if (!isSearch) { - item { - Box { + item { + AnimatedVisibility(isSearch) { + Spacer(Modifier.height(innerPadding.calculateTopPadding() + pad)) + } + + AnimatedVisibility(!isSearch) { + Box(Modifier.animateEnterExit()) { Cover( modifier = Modifier From 1904fe775d97fc247d7e840aaaa7ad7fdeb03a9b Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 18:58:42 +0200 Subject: [PATCH 15/55] [skip ci] update workflows --- .github/actions/build-apk/action.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/actions/build-apk/action.yml b/.github/actions/build-apk/action.yml index cea5e54cb..f15a65591 100644 --- a/.github/actions/build-apk/action.yml +++ b/.github/actions/build-apk/action.yml @@ -93,19 +93,10 @@ runs: shell: bash run: | apk_path=$(find app/build/outputs/apk/${{ env.FLAVOR_LOWERCASE }}/${{ env.BUILD_TYPE_LOWERCASE }} -name "*.apk" -print -quit) - mapping_path=$(find app/build/outputs/mapping/${{ env.FLAVOR_LOWERCASE }}${{ env.BUILD_TYPE_CAPITALIZED }} -name "mapping.txt" -print -quit) name=$(basename "$apk_path" .apk) echo "name=$name" >> $GITHUB_OUTPUT echo "path=$apk_path" >> $GITHUB_OUTPUT - echo "mapping=$mapping_path" >> $GITHUB_OUTPUT - - - name: Upload mapping as artifact - if: ${{ steps.apk.outputs.mapping != '' }} - uses: actions/upload-artifact@v4 - with: - name: ${{ inputs.flavor }}-${{ inputs.buildType }}-mapping - path: ${{ steps.apk.outputs.mapping }} - name: Upload APK as artifact uses: actions/upload-artifact@v4 From 0734e469f5b64c8ad2e95c4768a4d2d1dea8db81 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 19:14:22 +0200 Subject: [PATCH 16/55] . --- .github/workflows/github.yml | 2 +- .github/workflows/release-ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 2d8f81f04..9886cfefd 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -112,4 +112,4 @@ jobs: asset_name: ${{ steps.find_apks.outputs.SPOOFED_NAME }} asset_content_type: application/vnd.android.package-archive env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml index 439db9c5f..6dbf0ae36 100644 --- a/.github/workflows/release-ci.yml +++ b/.github/workflows/release-ci.yml @@ -102,8 +102,8 @@ jobs: run: | [ -f gradle.properties ] && [ "$(tail -c1 gradle.properties)" != "" ] && echo >> gradle.properties { - echo "gpr.user=${{ inputs.username }}" - echo "gpr.key=${{ inputs.token }}" + echo "gpr.user=${{ secrets.ACTOR }}" + echo "gpr.key=${{ secrets.GH_TOKEN }}" } >> gradle.properties - name: Set up JDK From ecc350bbafe399728d6102658c279c90861d1909 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 11 Oct 2026 20:01:49 +0200 Subject: [PATCH 17/55] [skip ci] Update build.gradle.kts --- app/build.gradle.kts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 44e83d86c..1bb506d85 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -174,10 +174,14 @@ android { androidComponents { onVariants { variant -> + val distributionFlavor = variant.productFlavors + .firstOrNull { it.first == "distribution" } + ?.second + variant.outputs.filterIsInstance().forEach { output -> output.outputFileName.set( output.versionName.map { vName -> - "MMRL-${vName}-${variant.buildType ?: variant.name}.apk" + "MMRL-$vName-$distributionFlavor.apk" } ) } From 9d6770512dce5eb94861798feb523085b85595d1 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 18 Oct 2026 18:51:23 +0200 Subject: [PATCH 18/55] Migrate UI to MMRLX toolbar, theme and scaffold Add the mmrlx ui and utilities dependencies and bump mmrlx to 1.0.230. Wrap the app in MMRLXTheme. Replace Material3 TopAppBarScrollBehavior/TopAppBarDefaults with the MMRLX ToolbarScrollBehavior/ToolbarDefaults across screens. BlurToolbar now uses the MMRLX Toolbar with Oklch colors, and the haze blur effect is dropped from it. Move the bottom navigation into a new BottomBar component built on the MMRLX NavigationBar. HomeScreen, RepositoriesScreen, RepositoryScreen and the new DescriptionScreen render it themselves, and MainScreen uses the MMRLX Scaffold. Rewrite HomeScreen and the Root/NonRoot items with MMRLX list and card components. Add a WebUI-based DescriptionScreen for module readmes and point AboutModule at it. Move ToolbarIcon and ToolbarEventIcon into TopAppBarEventIcon.kt. --- app/build.gradle.kts | 4 +- .../mmrl/ui/activity/MMRLComponentActivity.kt | 55 +- .../activity/terminal/action/ActionScreen.kt | 6 +- .../terminal/install/InstallScreen.kt | 6 +- .../dergoogler/mmrl/ui/component/BottomBar.kt | 157 +++++ .../mmrl/ui/component/SELinuxStatus.kt | 11 +- .../dergoogler/mmrl/ui/component/Scaffold.kt | 3 +- .../mmrl/ui/component/TopAppBarEventIcon.kt | 73 +- .../toolbar/BlurNavigateUpToolbar.kt | 15 +- .../ui/component/toolbar/BlurSearchToolbar.kt | 8 +- .../mmrl/ui/component/toolbar/BlurToolbar.kt | 47 +- .../mmrl/ui/providable/LocalScrollBehavior.kt | 4 +- .../ExploreRepositoryScreen.kt | 3 +- .../mmrl/ui/screens/home/HomeScreen.kt | 645 +++++++++--------- .../mmrl/ui/screens/home/items/NonRootItem.kt | 40 +- .../mmrl/ui/screens/home/items/RootItem.kt | 87 ++- .../mmrl/ui/screens/main/MainScreen.kt | 161 +---- .../moduleDetails/DescriptionScreen.kt | 177 +++++ .../ui/screens/moduleView/NewViewScreen.kt | 4 +- .../moduleView/ViewDescriptionScreen.kt | 8 +- .../moduleView/sections/AboutModule.kt | 4 +- .../mmrl/ui/screens/modules/ModulesScreen.kt | 8 +- .../repositories/RepositoriesScreen.kt | 12 +- .../ui/screens/repository/RepositoryScreen.kt | 12 +- .../screens/settings/logviewer/LogScreen.kt | 8 +- gradle/libs.versions.toml | 2 +- 26 files changed, 894 insertions(+), 666 deletions(-) create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1bb506d85..4ebd6c12f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -273,8 +273,8 @@ dependencies { ksp(libs.square.moshi.kotlin) implementation(libs.mmrlx.terminal) -// implementation(libs.mmrlx.nio) -// implementation(libs.mmrlx.utilities) + implementation(libs.mmrlx.ui) + implementation(libs.mmrlx.utilities) implementation(libs.mmrlx.webui.core) implementation("dev.chrisbanes.haze:haze:1.6.10") diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt index 2ce4467da..ad77ea39e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/MMRLComponentActivity.kt @@ -44,6 +44,7 @@ import dagger.hilt.android.AndroidEntryPoint import dev.dergoogler.mmrl.compat.BuildCompat import dev.dergoogler.mmrl.compat.core.BrickException import dev.dergoogler.mmrl.compat.core.MMRLUriHandlerImpl +import dev.mmrlx.compose.ui.theme.MMRLXTheme import timber.log.Timber import javax.inject.Inject import kotlin.system.exitProcess @@ -214,30 +215,36 @@ fun BaseContent( val currentTheme = Colors.getColor(preferences.themeColor, preferences.isDarkMode()) val toolbarColor = currentTheme.surface - MMRLAppTheme( - darkMode = preferences.isDarkMode(), - navController = navController, - themeColor = preferences.themeColor, - providerValues = - arrayOf( - LocalWindowSizeClass provides windowSizeClass, - LocalDestinationsNavigator provides navigator, - LocalActivity provides activity, - LocalSettings provides hiltViewModel(activity), - LocalUserPreferences provides preferences, - dev.dergoogler.mmrl.compat.core.LocalUriHandler provides - MMRLUriHandlerImpl( - context, - toolbarColor, - ), - LocalLifecycleScope provides activity.lifecycleScope, - LocalLifecycle provides activity.lifecycle, - LocalUriHandler provides MMRLUriHandlerImpl(context, toolbarColor), - LocalNavController provides navController, - LocalMainNavController provides mainNavController, - ), - content = content, - ) + val darkMode = preferences.isDarkMode() + + MMRLXTheme( + darkTheme = darkMode, + ) { + MMRLAppTheme( + darkMode = darkMode, + navController = navController, + themeColor = preferences.themeColor, + providerValues = + arrayOf( + LocalWindowSizeClass provides windowSizeClass, + LocalDestinationsNavigator provides navigator, + LocalActivity provides activity, + LocalSettings provides hiltViewModel(activity), + LocalUserPreferences provides preferences, + dev.dergoogler.mmrl.compat.core.LocalUriHandler provides + MMRLUriHandlerImpl( + context, + toolbarColor, + ), + LocalLifecycleScope provides activity.lifecycleScope, + LocalLifecycle provides activity.lifecycle, + LocalUriHandler provides MMRLUriHandlerImpl(context, toolbarColor), + LocalNavController provides navController, + LocalMainNavController provides mainNavController, + ), + content = content, + ) + } } fun MMRLComponentActivity.setBaseContent( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt index 1aea464bc..4214e0de1 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt @@ -46,6 +46,8 @@ import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ActionViewModel import dev.chrisbanes.haze.hazeSource import dev.mmrlx.compose.terminal.Terminal +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import dev.mmrlx.terminal.TerminalEmulator.Companion.TERMINAL_CURSOR_STYLE_NONE import kotlinx.coroutines.launch @@ -54,7 +56,7 @@ fun ActionScreen(viewModel: ActionViewModel) = LocalScreenProvider { val scope = rememberCoroutineScope() val snackbarHostState = remember { SnackbarHostState() } - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val userPreferences = LocalUserPreferences.current val context = LocalContext.current @@ -174,7 +176,7 @@ private fun TopBar( exportLog: () -> Unit, event: Event, onBack: () -> Unit, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, enable: Boolean, ) = BlurNavigateUpToolbar( title = stringResource(id = R.string.action_activity), diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt index 852553a1a..c10393df8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt @@ -54,6 +54,8 @@ import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.InstallViewModel import dev.chrisbanes.haze.hazeSource import dev.mmrlx.compose.terminal.Terminal +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import dev.mmrlx.terminal.TerminalEmulator.Companion.TERMINAL_CURSOR_STYLE_NONE import kotlinx.coroutines.launch @@ -62,7 +64,7 @@ fun InstallScreen(viewModel: InstallViewModel) = LocalScreenProvider { val scope = rememberCoroutineScope() val snackbarHostState = remember { SnackbarHostState() } - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val userPreferences = LocalUserPreferences.current val context = LocalContext.current @@ -226,7 +228,7 @@ private fun TopBar( exportLog: () -> Unit, event: Event, onBack: () -> Unit, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, enable: Boolean, ) = BlurNavigateUpToolbar( title = stringResource(id = R.string.install_screen_title), diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt new file mode 100644 index 000000000..9cf34f3ad --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt @@ -0,0 +1,157 @@ +package com.dergoogler.mmrl.ui.component + +import androidx.compose.foundation.layout.imePadding +import androidx.compose.material3.Badge +import androidx.compose.material3.BadgedBox +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import com.dergoogler.mmrl.ui.navigation.MainDestination +import com.dergoogler.mmrl.ui.navigation.isAccessible +import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator +import com.dergoogler.mmrl.ui.providable.LocalNavController +import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.ramcosta.composedestinations.generated.NavGraphs +import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.navigationbar.NavigationBar +import dev.mmrlx.compose.ui.navigationbar.NavigationBarItem +import dev.mmrlx.compose.ui.theme.MMRLXTheme + +@Composable +fun BottomBar(updates: Int = 0) { + val prefs = LocalUserPreferences.current + val navigator = LocalDestinationsNavigator.current + val navController = LocalNavController.current + + NavigationBar( + modifier = + Modifier + .imePadding() + ) { + for (screen in MainDestination.entries) { + if (!screen.isAccessible) continue + + val isSelected by navController.isRouteOnBackStackAsState(screen.direction) + + NavigationBarItem( + icon = { + BaseNavIcon(screen, isSelected, updates) + }, + label = { + Text( + text = stringResource(id = screen.label), + style = MMRLXTheme.typography.labelLarge, + ) + }, + alwaysShowLabel = !prefs.hideBottomBarLabels, + selected = isSelected, + onClick = { + if (isSelected) { + navigator.popBackStack(screen.direction, false) + } + navigator.navigate(screen.direction) { + popUpTo(NavGraphs.root) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + ) + } + } +} +/* +@Composable +private fun RailNav(updates: Int) { + val prefs = LocalUserPreferences.current + val navigator = LocalDestinationsNavigator.current + val navController = LocalNavController.current + + NavigationRail( + header = { + TopAppBarEventIcon() + }, + ) { + MainDestination.entries.forEach { screen -> + val isSelected by navController.isRouteOnBackStackAsState(screen.direction) + + if (!screen.isAccessible) return@forEach + + NavigationRailItem( + icon = { + BaseNavIcon(screen, isSelected, updates) + }, + label = { + Text( + text = stringResource(id = screen.label), + style = MaterialTheme.typography.labelLarge, + ) + }, + alwaysShowLabel = !prefs.hideBottomBarLabels, + selected = isSelected, + onClick = { + if (isSelected) { + navigator.popBackStack(screen.direction, false) + } + navigator.navigate(screen.direction) { + popUpTo(NavGraphs.root) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + ) + } + } +}*/ + +@Composable +private fun BaseNavIcon( + screen: MainDestination, + selected: Boolean, + updates: Int, +) { + if (screen == MainDestination.Modules && updates > 0) { + BadgedBox( + badge = { + Badge { + Text(text = updates.toString()) + } + }, + ) { + Icon( + painter = + painterResource( + id = + if (selected) { + screen.iconFilled + } else { + screen.icon + }, + ), + contentDescription = null, + ) + } + + return + } + + Icon( + painter = + painterResource( + id = + if (selected) { + screen.iconFilled + } else { + screen.icon + }, + ), + contentDescription = null, + ) +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/SELinuxStatus.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/SELinuxStatus.kt index b7f89725d..e1cc68d67 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/SELinuxStatus.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/SELinuxStatus.kt @@ -3,15 +3,14 @@ package com.dergoogler.mmrl.ui.component import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember import androidx.compose.ui.res.painterResource import com.dergoogler.mmrl.R import com.dergoogler.mmrl.platform.PlatformManager -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Title import com.dergoogler.mmrl.ui.remember.remember @Composable diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt index 42f585c19..effb1ecbb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt @@ -29,6 +29,7 @@ import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalNavController import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults @Composable fun SettingsScaffold( @@ -60,7 +61,7 @@ fun SettingsScaffold( relative: @Composable (ListScope.() -> Unit), ) = LocalScreenProvider { val navController = LocalNavController.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() ResponsiveScaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/TopAppBarEventIcon.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/TopAppBarEventIcon.kt index 31d37e462..349771beb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/TopAppBarEventIcon.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/TopAppBarEventIcon.kt @@ -1,11 +1,22 @@ package com.dergoogler.mmrl.ui.component +import androidx.annotation.DrawableRes +import androidx.compose.foundation.layout.size +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.providable.LocalUserPreferences -import com.dergoogler.mmrl.ui.component.toolbar.ToolbarEventIcon import com.dergoogler.mmrl.ui.model.toolbar.ToolbarEvent +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.theme.LocalContentColor +import dev.mmrlx.compose.ui.toolbar.ToolbarTitle @Composable fun TopAppBarEventIcon() { @@ -52,3 +63,63 @@ fun TopAppBarEventIcon() { events = events, ) } + +@Composable +fun ToolbarIcon( + modifier: Modifier = Modifier, + @DrawableRes icon: Int = com.dergoogler.mmrl.ui.R.drawable.mmrl_logo, + subtitle: String? = null, + tint: Color = MaterialTheme.colorScheme.surfaceTint, +) = ToolbarTitle( + modifier = modifier, + titleContent = { + Icon( + modifier = Modifier.size(30.dp), + painter = painterResource(id = icon), + contentDescription = null, + tint = tint, + ) + }, + subtitleContent = { + subtitle?.let { + Text( + text = it, + style = MaterialTheme.typography.bodySmall, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + color = LocalContentColor.current.copy(alpha = 0.75f), + ) + } + } +) + +@Composable +fun ToolbarEventIcon( + events: List, + modifier: Modifier = Modifier, + enabled: Boolean = true, + @DrawableRes nonEventIcon: Int = com.dergoogler.mmrl.ui.R.drawable.mmrl_logo, +) { + if (!enabled) { + return ToolbarIcon( + modifier = modifier, + icon = nonEventIcon, + ) + } + + val event = remember(events) { events.firstOrNull { it.isActive } } + + if (event != null) { + ToolbarIcon( + modifier = modifier, + icon = event.icon, + subtitle = event.getTitle(), + ) + } else { + ToolbarIcon( + modifier = modifier, + icon = nonEventIcon, + ) + } +} + diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt index 820d1b258..055f6fee9 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt @@ -8,7 +8,6 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -17,6 +16,8 @@ import androidx.navigation.NavController import com.dergoogler.mmrl.ext.takeTrue import com.dergoogler.mmrl.ui.R import com.ramcosta.composedestinations.navigation.DestinationsNavigator +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -28,7 +29,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: TopAppBarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior? = null, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -56,7 +57,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: TopAppBarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior? = null, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -84,7 +85,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: TopAppBarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior? = null, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -112,7 +113,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: TopAppBarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior? = null, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -139,8 +140,8 @@ fun BlurNavigateUpToolbar( modifier: Modifier = Modifier, enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, - windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: TopAppBarScrollBehavior? = null, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt index 7a5764934..9606dece8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt @@ -12,8 +12,6 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextFieldDefaults import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember @@ -28,6 +26,8 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.ui.R +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -41,8 +41,8 @@ fun BlurSearchToolbar( title: @Composable () -> Unit, navigationIcon: @Composable () -> Unit = {}, actions: @Composable RowScope.() -> Unit = {}, - windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: TopAppBarScrollBehavior? = null, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, fadeBackgroundIfNoBlur: Boolean = false, fadeDistance: Float = 200f, fade: Boolean = false, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt index c485133df..e446e90f6 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt @@ -5,10 +5,7 @@ import androidx.compose.animation.core.animateFloatAsState import androidx.compose.animation.core.tween import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.runtime.Stable import androidx.compose.runtime.State @@ -17,14 +14,14 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp -import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.utils.BlurUtil -import dev.chrisbanes.haze.hazeEffect import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi -import dev.chrisbanes.haze.materials.HazeMaterials +import dev.mmrlx.compose.ui.theme.MMRLXTheme +import dev.mmrlx.compose.ui.theme.Oklch +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior private const val VISIBILITY_THRESHOLD = 0.01f @@ -38,7 +35,7 @@ class BlurToolbarState internal constructor( private val animatedAlpha: State, private val targetAlphaState: State, private val blurEnabled: State, - private val scrollBehavior: TopAppBarScrollBehavior?, + private val scrollBehavior: ToolbarScrollBehavior?, ) { /** Current (animated) alpha, 0f..1f. */ val alpha: Float get() = animatedAlpha.value @@ -72,7 +69,7 @@ class BlurToolbarState internal constructor( @Composable fun rememberBlurToolbarState( - scrollBehavior: TopAppBarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior? = null, fade: Boolean = false, fadeDistance: Float = 200f, ): BlurToolbarState { @@ -121,25 +118,25 @@ fun BlurToolbar( fadeBackgroundIfNoBlur: Boolean = false, fadeDistance: Float = 200f, fade: Boolean = false, - scrollBehavior: TopAppBarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior? = null, state: BlurToolbarState = rememberBlurToolbarState( scrollBehavior = scrollBehavior, fade = fade, fadeDistance = fadeDistance, ), ) { - val borderColor = MaterialTheme.colorScheme.outline - val backgroundColor = MaterialTheme.colorScheme.background - val topAppBarColors = TopAppBarDefaults.topAppBarColors() + val borderColor = MMRLXTheme.border.okLchColor + val backgroundColor = MMRLXTheme.oklchColors.background + val topAppBarColors = ToolbarDefaults.colors() val colors = if (state.isBlurEnabled) { topAppBarColors.copy( - scrolledContainerColor = Color.Transparent, - containerColor = Color.Transparent, + scrolledContainerColor = Oklch(0.0,0.0, 0.0,0.0), + containerColor = Oklch(0.0,0.0, 0.0,0.0), ) } else { val container = if (fadeBackgroundIfNoBlur) { - backgroundColor.copy(alpha = state.alpha) + backgroundColor.copy(opacity = state.alpha.toDouble()) } else { backgroundColor } @@ -149,19 +146,7 @@ fun BlurToolbar( ) } - val blur = if (state.isBlurActive) { - Modifier.hazeEffect( - state = LocalHazeState.current, - style = HazeMaterials.ultraThin(), - ) { - this.backgroundColor = backgroundColor - this.alpha = state.alpha - } - } else { - Modifier - } - - TopAppBar( + dev.mmrlx.compose.ui.toolbar.Toolbar( title = { title(state.alpha) }, modifier = Modifier .drawBehind { @@ -171,20 +156,18 @@ fun BlurToolbar( val borderSize = Dp.Hairline val y = size.height - borderSize.value drawLine( - color = borderColor.copy(alpha = alpha), + color = borderColor.copy(opacity = alpha.toDouble()).toColor(), start = Offset(0f, y), end = Offset(size.width, y), strokeWidth = borderSize.value, ) } } - .then(blur) .then(modifier), navigationIcon = navigationIcon, actions = actions, colors = colors, scrollBehavior = scrollBehavior, windowInsets = windowInsets, - expandedHeight = expandedHeight, ) } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalScrollBehavior.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalScrollBehavior.kt index 426ddc75a..528e62131 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalScrollBehavior.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/providable/LocalScrollBehavior.kt @@ -1,9 +1,9 @@ package com.dergoogler.mmrl.ui.providable -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.staticCompositionLocalOf +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior val LocalScrollBehavior = - staticCompositionLocalOf { + staticCompositionLocalOf { error("CompositionLocal LocalScrollBehavior not present") } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt index 3018a18d5..4e3946f94 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt @@ -70,6 +70,7 @@ import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.chrisbanes.haze.hazeSource import dev.dergoogler.mmrl.compat.core.LocalUriHandler +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import kotlinx.coroutines.launch @Destination @@ -81,7 +82,7 @@ fun ExploreRepositoryScreen(repo: ExploreRepository) = val scope = rememberCoroutineScope() val snackbarHostState = LocalSnackbarHost.current val browser = LocalUriHandler.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val userPreferences = LocalUserPreferences.current val repositoriesMenu = userPreferences.repositoriesMenu diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 35945cbf8..7408f2401 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -7,26 +7,19 @@ import androidx.compose.animation.expandVertically import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets 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.verticalScroll -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable -import androidx.compose.runtime.ExperimentalComposeApi import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -44,7 +37,6 @@ import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.WorkingMode.Companion.isNonRoot import com.dergoogler.mmrl.datastore.model.WorkingMode.Companion.isRoot -import com.dergoogler.mmrl.ext.currentScreenWidth import com.dergoogler.mmrl.ext.managerVersion import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.nullable @@ -56,21 +48,10 @@ import com.dergoogler.mmrl.platform.file.SuFile.Companion.toFormattedFileSize import com.dergoogler.mmrl.platform.ksu.KsuNative import com.dergoogler.mmrl.stub.IMMRLApiManager import com.dergoogler.mmrl.ui.component.Alert -import com.dergoogler.mmrl.ui.component.LocalScreenProvider +import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.SELinuxStatus import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon -import com.dergoogler.mmrl.ui.component.card.Card -import com.dergoogler.mmrl.ui.component.card.component.Relative -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.remember.rememberLocalAnalytics import com.dergoogler.mmrl.ui.remember.seLinuxContext @@ -84,7 +65,20 @@ import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.AboutScreenDestination import com.ramcosta.composedestinations.generated.destinations.ThankYouScreenDestination -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.layout.outlinedCard +import dev.mmrlx.compose.ui.LinearProgressIndicator +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Title +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.toolbar.Toolbar +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber @@ -92,383 +86,356 @@ import timber.log.Timber val listItemContentPaddingValues: PaddingValues = PaddingValues(vertical = 8.dp, horizontal = 25.dp) @Destination(start = true) -@OptIn(ExperimentalComposeApi::class) @Composable -fun HomeScreen() = - LocalScreenProvider { - val navigator = LocalDestinationsNavigator.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() - val context = LocalContext.current - val userPreferences = LocalUserPreferences.current - val browser = LocalUriHandler.current - - val analytics by rememberLocalAnalytics() - - var openRebootSheet by remember { mutableStateOf(false) } - if (openRebootSheet) { - RebootBottomSheet( - onClose = { openRebootSheet = false }, - ) - } +fun HomeScreen() { + val navigator = LocalDestinationsNavigator.current + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() + val context = LocalContext.current + val userPreferences = LocalUserPreferences.current + val browser = LocalUriHandler.current + + val analytics by rememberLocalAnalytics() + + var openRebootSheet by remember { mutableStateOf(false) } + if (openRebootSheet) { + RebootBottomSheet( + onClose = { openRebootSheet = false }, + ) + } - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - onInfoClick = { - navigator.navigate(AboutScreenDestination) - }, - onHeartClick = { - navigator.navigate(ThankYouScreenDestination) - }, - onRebootClick = { - openRebootSheet = true - }, - scrollBehavior = scrollBehavior, - ) - }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - ResponsiveContent { - Column( - modifier = - Modifier - .hazeSource(state = LocalHazeState.current) - .fillMaxWidth() - .verticalScroll(rememberScrollState()) - .padding(16.dp) - .padding(top = innerPadding.calculateTopPadding()), - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - when { - userPreferences.workingMode.isRoot -> - RootItem( - developerMode = userPreferences.developerMode, - ) - - userPreferences.workingMode.isNonRoot -> - NonRootItem( - developerMode = userPreferences.developerMode, - ) - } + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + TopBar0( + onInfoClick = { + navigator.navigate(AboutScreenDestination) + }, + onHeartClick = { + navigator.navigate(ThankYouScreenDestination) + }, + onRebootClick = { + openRebootSheet = true + }, + scrollBehavior = scrollBehavior, + ) + }, + bottomBar = { + BottomBar() + }, + contentWindowInsets = WindowInsets.none, + ) { + Column( + modifier = + Modifier + .scaffoldHazeSource() + .fillMaxWidth() + .verticalScroll(rememberScrollState()) + .scaffoldPadding() + .padding(16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + when { + userPreferences.workingMode.isRoot -> + RootItem() + + userPreferences.workingMode.isNonRoot -> + NonRootItem() + } - if (userPreferences.checkAppUpdates) { - var changelog by remember { mutableStateOf?>(null) } - LaunchedEffect(Unit) { - runRequest { - withContext(Dispatchers.IO) { - val api = IMMRLApiManager.build() - return@withContext api.changelog.execute() - } - }.onSuccess { list -> - changelog = list - }.onFailure { - Timber.e(it, "unable to get changelog") - } + if (userPreferences.checkAppUpdates) { + var changelog by remember { mutableStateOf?>(null) } + LaunchedEffect(Unit) { + runRequest { + withContext(Dispatchers.IO) { + val api = IMMRLApiManager.build() + return@withContext api.changelog.execute() } + }.onSuccess { list -> + changelog = list + }.onFailure { + Timber.e(it, "unable to get changelog") + } + } - changelog?.let { - val latest = it.first() + changelog?.let { + val latest = it.first() - var changelogSheet by remember { mutableStateOf(false) } - if (changelogSheet) { - ChangelogBottomSheet( - changelog = latest, - onClose = { changelogSheet = false }, - ) - } + var changelogSheet by remember { mutableStateOf(false) } + if (changelogSheet) { + ChangelogBottomSheet( + changelog = latest, + onClose = { changelogSheet = false }, + ) + } - AnimatedVisibility( - visible = - userPreferences.developerMode { devAlwaysShowUpdateAlert } || - ( + AnimatedVisibility( + visible = + userPreferences.developerMode { devAlwaysShowUpdateAlert } || + ( if (latest.preRelease) { userPreferences.checkAppUpdatesPreReleases && - latest.versionCode > context.managerVersion.second + latest.versionCode > context.managerVersion.second } else { latest.versionCode > context.managerVersion.second } - ), - enter = fadeIn() + expandVertically(), - exit = shrinkVertically() + fadeOut(), - ) { - Alert( - onClick = { - changelogSheet = true - }, - backgroundColor = MaterialTheme.colorScheme.tertiaryContainer, - title = stringResource(R.string.update_available), - message = - stringResource( - R.string.new_version_available, - latest.versionName, - ), - icon = R.drawable.cloud_download, - ) - } - } + ), + enter = fadeIn() + expandVertically(), + exit = shrinkVertically() + fadeOut(), + ) { + Alert( + onClick = { + changelogSheet = true + }, + backgroundColor = MaterialTheme.colorScheme.tertiaryContainer, + title = stringResource(R.string.update_available), + message = + stringResource( + R.string.new_version_available, + latest.versionName, + ), + icon = R.drawable.cloud_download, + ) } + } + } - List( - verticalArrangement = Arrangement.spacedBy(16.dp), - contentPadding = listItemContentPaddingValues, - ) { - val scope = this + List( + verticalArrangement = Arrangement.spacedBy(16.dp), + contentPadding = listItemContentPaddingValues, + ) { + val scope = this - Card( - modifier = Modifier.padding(vertical = 16.dp), - ) { - val uname = Os.uname() - Column( - modifier = Modifier.relative(), - ) { - scope.Item { - Icon(painter = painterResource(R.drawable.cookie_man)) - Title(R.string.kernel) - Description(uname.release) - } + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .fillMaxWidth() + ) { + val uname = Os.uname() + scope.Item { + Icon(painter = painterResource(R.drawable.cookie_man)) + Title(R.string.kernel) + Description(uname.release) + } - scope.Item { - Icon(painter = painterResource(R.drawable.launcher_outline)) - Title(R.string.manager_version) - Description("${context.managerVersion.first} (${context.managerVersion.second})") - } + scope.Item { + Icon(painter = painterResource(R.drawable.launcher_outline)) + Title(R.string.manager_version) + Description("${context.managerVersion.first} (${context.managerVersion.second})") + } - scope.Item { - Icon(painter = painterResource(R.drawable.fingerprint)) - Title(R.string.fingerprint) - Description( - if (userPreferences.hideFingerprintInHome) { - stringResource(id = R.string.hidden) - } else { - Build.FINGERPRINT - }, - ) - } + scope.Item { + Icon(painter = painterResource(R.drawable.fingerprint)) + Title(R.string.fingerprint) + Description( + if (userPreferences.hideFingerprintInHome) { + stringResource(id = R.string.hidden) + } else { + Build.FINGERPRINT + }, + ) + } - scope.Item { - Icon(painter = painterResource(R.drawable.cpu_2)) - Title(R.string.architecture) - Description(uname.machine) - } + scope.Item { + Icon(painter = painterResource(R.drawable.cpu_2)) + Title(R.string.architecture) + Description(uname.machine) + } - scope.SELinuxStatus() + scope.SELinuxStatus() - PlatformManager.platform.isKernelSuOrNext.takeTrue { + PlatformManager.platform.isKernelSuOrNext.takeTrue { + scope.Item { + Icon(painter = painterResource(R.drawable.user_outlined)) + Title(R.string.super_user_apps) + Description(superUserCount.toString()) + } + } + } + + PlatformManager.isAlive.takeTrue { + userPreferences.developerMode.takeTrue { + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .fillMaxWidth() + ) { + scope.Item { + Title(R.string.home_root_provider_version_name) + Description(versionName) + } + + scope.Item { + Title(R.string.home_root_provider_se_linux_context) + Description(seLinuxContext) + } + + if (PlatformManager.platform.isKernelSuNext) { + KsuNative.getHookMode().nullable { scope.Item { - Icon(painter = painterResource(R.drawable.user_outlined)) - Title(R.string.super_user_apps) - Description(superUserCount.toString()) + Title(R.string.hook_mode) + Description(it) } } } - } - - PlatformManager.isAlive.takeTrue { - userPreferences.developerMode.takeTrue { - Card( - modifier = Modifier.padding(vertical = 16.dp), - ) { - Column( - modifier = Modifier.relative(), - ) { - scope.Item { - Title(R.string.home_root_provider_version_name) - Description(versionName) - } - - scope.Item { - Title(R.string.home_root_provider_se_linux_context) - Description(seLinuxContext) - } - - if (PlatformManager.platform.isKernelSuNext) { - KsuNative.getHookMode().nullable { - scope.Item { - Title(R.string.hook_mode) - Description(it) - } - } - } - - if (PlatformManager.platform.isSukiSU) { - KsuNative.getHookType().nullable { - scope.Item { - Title(R.string.hook_mode) - Description(it) - } - } - scope.Item { - Title(R.string.kpm_support) - Description(if (KsuNative.isKPMEnabled()) R.string.yes else R.string.no) - } - } + if (PlatformManager.platform.isSukiSU) { + KsuNative.getHookType().nullable { + scope.Item { + Title(R.string.hook_mode) + Description(it) } } + + scope.Item { + Title(R.string.kpm_support) + Description(if (KsuNative.isKPMEnabled()) R.string.yes else R.string.no) + } } } + } + } - if (PlatformManager.platform.isValid) { - analytics.nullable { - Row( - horizontalArrangement = Arrangement.spacedBy(16.dp), - ) { - Card( - modifier = - Modifier - .padding(vertical = 16.dp) - .weight(1f), - ) { - Relative { - scope.Item { - Title(R.string.home_installed_modules) - Description(it.totalModules.toString()) - } - } - } - - Card( - modifier = - Modifier - .padding(vertical = 16.dp) - .weight(1f), - ) { - Relative { - scope.Item { - Title(R.string.home_updated_modules) - Description(it.totalUpdated.toString()) - } - } - } + if (PlatformManager.platform.isValid) { + analytics.nullable { + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp), + ) { + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_installed_modules) + Description(it.totalModules.toString()) } + } - Card( - modifier = - Modifier - .padding(vertical = 16.dp), - ) { - Relative { - scope.Item { - Title(R.string.home_storage_usage) - - Description { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text( - text = it.totalModulesUsageBytes.toFormattedFileSize(), - ) - - LinearProgressIndicator( - progress = { - it.totalStorageUsage - }, - modifier = - Modifier - .height(10.dp) - .weight(1f), - drawStopIndicator = {}, - ) - - Text( - text = it.totalDeviceStorageBytes.toFormattedFileSize(), - ) - } - } - } - } + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_updated_modules) + Description(it.totalUpdated.toString()) } + } + } - Row( - horizontalArrangement = Arrangement.spacedBy(16.dp), - ) { - Card( - modifier = - Modifier - .padding(vertical = 16.dp) - .weight(1f), - ) { - Relative { - scope.Item { - Title(R.string.home_enabled_modules) - Description(it.totalEnabled.toString()) - } - } - } + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .fillMaxWidth() + ) { + scope.Item { + Title(R.string.home_storage_usage) - Card( - modifier = - Modifier - .padding(vertical = 16.dp) - .weight(1f), + Description { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - Relative { - scope.Item { - Title(R.string.home_disabled_modules) - Description(it.totalDisabled.toString()) - } - } + Text( + text = it.totalModulesUsageBytes.toFormattedFileSize(), + ) + + LinearProgressIndicator( + progress = { + it.totalStorageUsage + }, + modifier = + Modifier + .height(10.dp) + .weight(1f), + drawStopIndicator = {}, + ) + + Text( + text = it.totalDeviceStorageBytes.toFormattedFileSize(), + ) } } } } - Card( - modifier = - Modifier - .padding(vertical = 16.dp) - .fillMaxWidth(), - onClick = { - browser.openUri("https://github.com/sponsors/MMRLApp") - }, + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp), ) { - Relative { + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_enabled_modules) + Description(it.totalEnabled.toString()) + } + } + + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { scope.Item { - Title( - id = R.string.home_support_title, - styleTransform = { - val newStyle = it.copy(color = Color.Unspecified) - it.merge(newStyle) - }, - ) - - Description( - id = R.string.home_support_content, - styleTransform = { - val newStyle = it.copy(color = Color.Unspecified) - it.merge(newStyle) - }, - ) + Title(R.string.home_disabled_modules) + Description(it.totalDisabled.toString()) } } } } + } + + Column( + modifier = Modifier + .outlinedCard() + .fillMaxWidth() + .clickable { + browser.openUri("https://github.com/sponsors/MMRLApp") + } + .padding(vertical = 16.dp) + ) { + scope.Item { + Title( + id = R.string.home_support_title, + styleTransform = { + val newStyle = it.copy(color = Color.Unspecified) + it.merge(newStyle) + }, + ) - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) + Description( + id = R.string.home_support_content, + styleTransform = { + val newStyle = it.copy(color = Color.Unspecified) + it.merge(newStyle) + }, + ) + } } } } } +} @Composable -private fun TopBar( +private fun TopBar0( onRebootClick: () -> Unit = {}, onInfoClick: () -> Unit = {}, onHeartClick: () -> Unit = {}, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, ) { - val width = currentScreenWidth() - - BlurToolbar( + Toolbar( scrollBehavior = scrollBehavior, - fade = true, - fadeDistance = 50f, title = { - if (!width.isSmall) return@BlurToolbar - TopAppBarEventIcon() }, actions = { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt index 56c03f1b5..20c6e48a7 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.home.items +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -8,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CornerSize import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme @@ -16,27 +18,36 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.takeTrue -import com.dergoogler.mmrl.ui.component.card.Card +import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import dev.mmrlx.compose.ui.scaffold.PositionLayout +import dev.mmrlx.compose.ui.theme.MMRLXTheme + @Composable -internal fun NonRootItem(developerMode: Boolean = false) = - Card( - color = MaterialTheme.colorScheme.secondaryContainer, +internal fun NonRootItem() { + val userPreferences = LocalUserPreferences.current + val shape = MMRLXTheme.shapes.extraLarge + + PositionLayout( + modifier = Modifier + .clip(shape) + .background(MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f)) ) { - developerMode.takeTrue { + if (userPreferences.developerMode) { Surface( shape = RoundedCornerShape( - topEnd = 20.dp, - bottomStart = 15.dp, - bottomEnd = 0.dp, + topStart = CornerSize(0.dp), + topEnd = shape.topEnd, + bottomStart = CornerSize(15.dp), + bottomEnd = CornerSize(0.dp), ), - color = MaterialTheme.colorScheme.primary, + color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.45f), modifier = Modifier .absolute(Alignment.TopEnd), @@ -44,7 +55,7 @@ internal fun NonRootItem(developerMode: Boolean = false) = Text( text = "USER!DEV", style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onPrimary, + color = MaterialTheme.colorScheme.onSecondaryContainer, modifier = Modifier .padding(horizontal = 16.dp, vertical = 8.dp), @@ -53,14 +64,16 @@ internal fun NonRootItem(developerMode: Boolean = false) = } Row( - modifier = Modifier.relative().padding(20.dp), + modifier = Modifier + .relative() + .padding(20.dp), verticalAlignment = Alignment.CenterVertically, ) { Icon( modifier = Modifier.size(45.dp), painter = painterResource(id = R.drawable.info_circle_filled), contentDescription = null, - tint = MaterialTheme.colorScheme.primary, + tint = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f), ) Spacer(modifier = Modifier.width(16.dp)) @@ -82,3 +95,4 @@ internal fun NonRootItem(developerMode: Boolean = false) = } } } +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt index 15d9516f2..2700a6d96 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.home.items +import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -8,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CornerSize import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme @@ -16,42 +18,43 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.ext.takeTrue import com.dergoogler.mmrl.model.local.FeaturedManager import com.dergoogler.mmrl.model.local.FeaturedManager.Companion.name -import com.dergoogler.mmrl.platform.PlatformManager.isAlive -import com.dergoogler.mmrl.platform.PlatformManager.platform -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.card.Card -import com.dergoogler.mmrl.ui.component.text.TextRow +import com.dergoogler.mmrl.platform.PlatformManager import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.dergoogler.mmrl.ui.remember.isLkmMode import com.dergoogler.mmrl.ui.remember.versionCode +import dev.mmrlx.compose.ui.scaffold.PositionLayout +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable -internal fun RootItem(developerMode: Boolean = false) { +internal fun RootItem() { val userPreferences = LocalUserPreferences.current + val shape = MMRLXTheme.shapes.extraLarge + val isAlive = PlatformManager.isAlive val manager = FeaturedManager.managers.find { userPreferences.workingMode == it.workingMode } - Card( - color = MaterialTheme.colorScheme.secondaryContainer, + PositionLayout( + modifier = Modifier + .clip(shape) + .background(MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f)) ) { - developerMode.takeTrue { + if (userPreferences.developerMode) { Surface( shape = RoundedCornerShape( - topEnd = 20.dp, - bottomStart = 15.dp, - bottomEnd = 0.dp, + topStart = CornerSize(0.dp), + topEnd = shape.topEnd, + bottomStart = CornerSize(15.dp), + bottomEnd = CornerSize(0.dp), ), - color = MaterialTheme.colorScheme.primary, + color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.45f), modifier = Modifier .absolute(Alignment.TopEnd), @@ -59,7 +62,7 @@ internal fun RootItem(developerMode: Boolean = false) { Text( text = "USER!DEV", style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onPrimary, + color = MaterialTheme.colorScheme.onSecondaryContainer, modifier = Modifier .padding(horizontal = 16.dp, vertical = 8.dp), @@ -89,45 +92,33 @@ internal fun RootItem(developerMode: Boolean = false) { modifier = Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(4.dp), ) { - TextRow( - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically, - leadingContent = - (developerMode && platform.isKernelSuOrNext) nullable { - LabelItem( - text = - when (isLkmMode) { - null -> "LTS" - true -> "LKM" - else -> "GKI" - }, + Text( + text = + if (isAlive) { + stringResource( + id = R.string.settings_root_access, + stringResource(id = R.string.settings_root_granted), + ) + } else { + stringResource( + id = R.string.settings_root_access, + stringResource(id = R.string.settings_root_none), ) }, - ) { - Text( - text = - if (isAlive) { - stringResource( - id = R.string.settings_root_access, - stringResource(id = R.string.settings_root_granted), - ) - } else { - stringResource( - id = R.string.settings_root_access, - stringResource(id = R.string.settings_root_none), - ) - }, - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onSecondaryContainer, - ) - } + style = MaterialTheme.typography.titleMedium, + color = MaterialTheme.colorScheme.onSecondaryContainer, + ) Text( text = if (isAlive) { stringResource( id = R.string.settings_root_provider, - manager.name, + if (manager?.name == null) { + "???" + } else { + manager.name + }, ) } else { stringResource( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt index 631fa3220..1c6c73a6e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt @@ -7,14 +7,7 @@ import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.imePadding -import androidx.compose.material3.Badge -import androidx.compose.material3.BadgedBox -import androidx.compose.material3.Icon -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect @@ -22,15 +15,9 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavBackStackEntry import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ui.component.scaffold.ResponsiveScaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurBottomToolbar -import com.dergoogler.mmrl.ui.navigation.MainDestination -import com.dergoogler.mmrl.ui.navigation.isAccessible import com.dergoogler.mmrl.ui.providable.LocalBulkInstall import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalHazeState @@ -46,9 +33,9 @@ import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationSty import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.NavGraphs -import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState import dev.chrisbanes.haze.hazeSource import dev.chrisbanes.haze.rememberHazeState +import dev.mmrlx.compose.ui.scaffold.Scaffold @Destination @Composable @@ -146,17 +133,11 @@ fun MainScreen() { return@CompositionLocalProvider }*/ - ResponsiveScaffold( - bottomBar = { - BottomNav(updates) - }, - railBar = { -// RailNav(updates) - }, + Scaffold( contentWindowInsets = WindowInsets.none, - ) { paddingValues -> + ) { CompositionLocalProvider( - LocalMainScreenInnerPaddings provides paddingValues, + LocalMainScreenInnerPaddings provides contentPadding, ) { CurrentNavHost( modifier = Modifier.hazeSource(hazeState), @@ -183,137 +164,3 @@ private fun CurrentNavHost(modifier: Modifier = Modifier) { ) } -@Composable -private fun BottomNav(updates: Int) { - val prefs = LocalUserPreferences.current - val navigator = LocalDestinationsNavigator.current - val navController = LocalNavController.current - - BlurBottomToolbar( - modifier = - Modifier - .imePadding(), - ) { - for (screen in MainDestination.entries) { - if (!screen.isAccessible) continue - - val isSelected by navController.isRouteOnBackStackAsState(screen.direction) - - NavigationBarItem( - icon = { - BaseNavIcon(screen, isSelected, updates) - }, - label = { - Text( - text = stringResource(id = screen.label), - style = MaterialTheme.typography.labelLarge, - ) - }, - alwaysShowLabel = !prefs.hideBottomBarLabels, - selected = isSelected, - onClick = { - if (isSelected) { - navigator.popBackStack(screen.direction, false) - } - navigator.navigate(screen.direction) { - popUpTo(NavGraphs.root) { - saveState = true - } - launchSingleTop = true - restoreState = true - } - }, - ) - } - } -} -/* -@Composable -private fun RailNav(updates: Int) { - val prefs = LocalUserPreferences.current - val navigator = LocalDestinationsNavigator.current - val navController = LocalNavController.current - - NavigationRail( - header = { - TopAppBarEventIcon() - }, - ) { - MainDestination.entries.forEach { screen -> - val isSelected by navController.isRouteOnBackStackAsState(screen.direction) - - if (!screen.isAccessible) return@forEach - - NavigationRailItem( - icon = { - BaseNavIcon(screen, isSelected, updates) - }, - label = { - Text( - text = stringResource(id = screen.label), - style = MaterialTheme.typography.labelLarge, - ) - }, - alwaysShowLabel = !prefs.hideBottomBarLabels, - selected = isSelected, - onClick = { - if (isSelected) { - navigator.popBackStack(screen.direction, false) - } - navigator.navigate(screen.direction) { - popUpTo(NavGraphs.root) { - saveState = true - } - launchSingleTop = true - restoreState = true - } - }, - ) - } - } -}*/ - -@Composable -private fun BaseNavIcon( - screen: MainDestination, - selected: Boolean, - updates: Int, -) { - if (screen == MainDestination.Modules && updates > 0) { - BadgedBox( - badge = { - Badge { - Text(text = updates.toString()) - } - }, - ) { - Icon( - painter = - painterResource( - id = - if (selected) { - screen.iconFilled - } else { - screen.icon - }, - ), - contentDescription = null, - ) - } - - return - } - - Icon( - painter = - painterResource( - id = - if (selected) { - screen.iconFilled - } else { - screen.icon - }, - ), - contentDescription = null, - ) -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt new file mode 100644 index 000000000..737af2879 --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt @@ -0,0 +1,177 @@ +package com.dergoogler.mmrl.ui.screens.moduleDetails + +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import com.dergoogler.mmrl.BuildConfig +import com.dergoogler.mmrl.R +import com.dergoogler.mmrl.ext.none +import com.dergoogler.mmrl.model.WebColors +import com.dergoogler.mmrl.ui.component.BottomBar +import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator +import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.dergoogler.mmrl.utils.MimeUtil +import com.ramcosta.composedestinations.annotation.Destination +import com.ramcosta.composedestinations.annotation.RootGraph +import com.ramcosta.composedestinations.navigation.DestinationsNavigator +import dev.mmrlx.compose.ui.ext.with +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.theme.MMRLXTheme +import dev.mmrlx.compose.ui.toolbar.Toolbar +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior +import dev.mmrlx.compose.ui.toolbar.ToolbarTitle +import dev.mmrlx.compose.webui.WebUIView +import dev.mmrlx.compose.webui.insets +import dev.mmrlx.compose.webui.rememberWebUIState +import dev.mmrlx.webui.RouteRegistry +import dev.mmrlx.webui.RouteScope +import dev.mmrlx.webui.WebResourceResponse +import dev.mmrlx.webui.WebUIOptions +import java.net.HttpURLConnection +import java.net.URL + +@Composable +@Destination +fun DescriptionScreen(readmeUrl: String) { + val navigator = LocalDestinationsNavigator.current + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() + val userPrefs = LocalUserPreferences.current + + val colors = MMRLXTheme.colors + val scheme = MaterialTheme.colorScheme.copy( + background = colors.background, + onBackground = colors.foreground, + surface = colors.code, + surfaceTint = colors.muted + ) + + val wstate = + rememberWebUIState( + "https://desc.mmrl.dev", + WebUIOptions("internal/assets/markdown.html") + ) { + it + .settings { + debug = BuildConfig.DEBUG + forceKillProcess = false + useConsoleInterceptor = false + darkMode = userPrefs.isDarkMode() + } + .client { + // not related to client + it.webview.setBackgroundColor(scheme.background.toArgb()) + } + .chromeClient { } + .registerRoutes { + val webColors = WebColors(scheme) + + internalRoute("readme.md") { + val connection = URL(readmeUrl).openConnection() as HttpURLConnection + connection.connect() + htmlResponse(connection.getInputStream()) + } + + internalRoute("insets.css") { + insets.css.asStyleResponse() + } + + internalRoute("colors.css") { + webColors.allCssColors.asStyleResponse() + } + + internalRoute("assets/*asset") { + val filePath = + request.params["asset"] ?: return@internalRoute notFoundResponse + + try { + val inputStream = kontext.assets.open(filePath) + val mimeType = MimeUtil.getMimeFromFileName(filePath) + response(mimeType = mimeType, data = inputStream) + } catch (e: Exception) { + console.error("Failed to open $filePath from the assets: $e") + notFoundResponse + } + } + } + } + + DisposableEffect(Unit) { + onDispose { + wstate.destroy() + } + } + + // We have to override otherwise the WebUI will close the entire app + BackHandler { + if (wstate.canGoBack()) { + wstate.goBack() + return@BackHandler + } + + navigator.popBackStack() + } + + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + TopBar0( + scrollBehavior = scrollBehavior, + navigator = navigator, + ) + }, + bottomBar = { + BottomBar() + }, + contentWindowInsets = WindowInsets.none, + ) { + wstate.insets( + PaddingValues( + top = contentPadding.calculateTopPadding(), + bottom = contentPadding.calculateBottomPadding(), + ) + ) + + WebUIView( + modifier = Modifier + .with(this@Scaffold) { + it.scaffoldHazeSource() + } + .fillMaxSize(), + state = wstate + ) + } +} + +@Composable +private fun TopBar0( + navigator: DestinationsNavigator, + scrollBehavior: ToolbarScrollBehavior, +) = Toolbar( + navigationIcon = { + IconButton(onClick = { navigator.popBackStack() }) { + Icon( + painter = painterResource(id = R.drawable.arrow_left), + contentDescription = null, + ) + } + }, + title = { ToolbarTitle(title = stringResource(id = R.string.view_module_about_this_module)) }, + scrollBehavior = scrollBehavior, +) + +private fun RouteRegistry.internalRoute( + name: String, + content: RouteScope.() -> WebResourceResponse, +) = route("internal/$name", content) \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index 592b389c2..1995c48fb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -15,7 +15,6 @@ import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue @@ -73,6 +72,7 @@ import com.dergoogler.mmrl.viewmodel.ModuleViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import timber.log.Timber internal val listItemContentPaddingValues = PaddingValues(vertical = 16.dp, horizontal = 16.dp) @@ -181,7 +181,7 @@ fun NewViewScreen( ) } - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val isBlacklisted by module.isBlacklisted diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt index 1f58c4d60..a7fa6a9f5 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt @@ -10,8 +10,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Modifier @@ -35,6 +33,8 @@ import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.navigation.DestinationsNavigator import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import dev.mmrlx.compose.webui.WebUIView import dev.mmrlx.compose.webui.insets import dev.mmrlx.compose.webui.rememberWebUIState @@ -51,7 +51,7 @@ import java.net.URL fun ViewDescriptionScreen(readmeUrl: String) = LocalScreenProvider { val navigator = LocalDestinationsNavigator.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val userPrefs = LocalUserPreferences.current val scheme = MaterialTheme.colorScheme @@ -155,7 +155,7 @@ fun ViewDescriptionScreen(readmeUrl: String) = @Composable private fun TopBar( navigator: DestinationsNavigator, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, ) = BlurToolbar( navigationIcon = { IconButton(onClick = { navigator.popBackStack() }) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt index 49aa14686..3c593a474 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt @@ -29,7 +29,7 @@ import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.screens.moduleView.listItemContentPaddingValues -import com.ramcosta.composedestinations.generated.destinations.ViewDescriptionScreenDestination +import com.ramcosta.composedestinations.generated.destinations.DescriptionScreenDestination @Composable internal fun AboutModule() { @@ -45,7 +45,7 @@ internal fun AboutModule() { if (!module.readme.isNullOrBlank()) { ButtonItem( onClick = { - navigator.navigate(ViewDescriptionScreenDestination(module.readme)) + navigator.navigate(DescriptionScreenDestination(module.readme)) }, ) { Icon( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt index c7a0fd250..991446019 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt @@ -15,8 +15,6 @@ import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.pulltorefresh.PullToRefreshBox import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState @@ -56,6 +54,8 @@ import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ModulesViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @Destination @Composable @@ -69,7 +69,7 @@ fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) = val state by viewModel.screenState.collectAsStateWithLifecycle() val isLoading by viewModel.isLoading.collectAsStateWithLifecycle() - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val pullToRefreshState = rememberPullToRefreshState() @@ -178,7 +178,7 @@ private fun TopBar( onOpenSearch: () -> Unit, onCloseSearch: () -> Unit, setMenu: (ModulesMenu) -> Unit, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, ) { val width = currentScreenWidth() diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt index 1e78e2dd0..2dc769b2b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt @@ -18,8 +18,6 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.material3.TextButton -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.pulltorefresh.PullToRefreshBox import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState @@ -52,6 +50,7 @@ import com.dergoogler.mmrl.model.local.BulkModule import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.animate.slideInTopToBottom import com.dergoogler.mmrl.ui.animate.slideOutBottomToTop +import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Loading import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.PageIndicator @@ -68,6 +67,8 @@ import com.dergoogler.mmrl.viewmodel.RepositoriesViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.SearchScreenDestination +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import timber.log.Timber import kotlin.reflect.KFunction1 @@ -78,7 +79,7 @@ fun RepositoriesScreen() = val viewModel = hiltViewModel() val userPrefs = LocalUserPreferences.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val list by viewModel.repos.collectAsStateWithLifecycle() val bulkInstallViewModel = LocalBulkInstall.current val bulkModules by bulkInstallViewModel.bulkModules.collectAsStateWithLifecycle() @@ -164,6 +165,9 @@ fun RepositoriesScreen() = scrollBehavior = scrollBehavior, ) }, + bottomBar = { + BottomBar() + }, contentWindowInsets = WindowInsets.none, floatingActionButton = { if (viewModel.platform.isValid) { @@ -305,7 +309,7 @@ private fun AddDialog( private fun TopBar( onAdd: () -> Unit, setMenu: KFunction1, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, ) { val width = currentScreenWidth() val navigator = LocalDestinationsNavigator.current diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index 86be545ce..f05eb90a6 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -19,8 +19,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect @@ -58,6 +56,7 @@ import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.nullply import com.dergoogler.mmrl.ext.onClick import com.dergoogler.mmrl.ext.stripLinks +import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LabelItem import com.dergoogler.mmrl.ui.component.LabelItemDefaults @@ -74,6 +73,8 @@ import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.dergoogler.mmrl.compat.core.LocalUriHandler +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @Destination @Composable @@ -92,7 +93,7 @@ fun RepositoryScreen( val closeSearch = viewModel::closeSearch val search = viewModel::search val isSearch by viewModel::isSearch - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() var coverHeight by remember { mutableIntStateOf(0) } var cardHeight by remember { mutableIntStateOf(0) } @@ -116,6 +117,9 @@ fun RepositoryScreen( setMenu = viewModel::setRepositoryMenu, ) }, + bottomBar = { + BottomBar() + }, contentWindowInsets = WindowInsets.none, ) { innerPadding -> if (modules.isEmpty()) { @@ -273,7 +277,7 @@ private fun TopBar0( onQueryChange: (String) -> Unit, onOpenSearch: () -> Unit, onCloseSearch: () -> Unit, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, setMenu: (RepositoryMenu) -> Unit, ) { val state = rememberBlurToolbarState(scrollBehavior, fade = true) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/logviewer/LogScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/logviewer/LogScreen.kt index 8e202aed4..9c0b235f8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/logviewer/LogScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/logviewer/LogScreen.kt @@ -27,8 +27,6 @@ import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect @@ -69,6 +67,8 @@ import com.dergoogler.mmrl.utils.log.Logcat import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import kotlinx.coroutines.launch private val priorities = listOf("VERBOSE", "DEBUG", "INFO", "WARN", "ERROR") @@ -116,7 +116,7 @@ object LogColors { fun LogScreen() = LocalScreenProvider { val context = LocalContext.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val state = rememberLazyListState() var priority by remember { mutableStateOf("DEBUG") } @@ -205,7 +205,7 @@ fun LogScreen() = private fun TopBar( priority: String, onPriority: (String) -> Unit, - scrollBehavior: TopAppBarScrollBehavior, + scrollBehavior: ToolbarScrollBehavior, ) = BlurNavigateUpToolbar( title = stringResource(id = R.string.settings_log_viewer), navController = LocalNavController.current, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3593d02c5..d6483bf6e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.229" +mmrlx = "1.0.230" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From f7b6ec4039c081f0a09d960edae70333ef2634bc Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:47:47 +0200 Subject: [PATCH 19/55] Migrate settings UI to mmrlx list and scaffold Move settings screens from the in-app list item DSL to the dev.mmrlx.compose.ui list, scaffold and toolbar components, and bump mmrlx to 1.0.231. - Rewrite SettingsScaffold on top of the mmrlx Scaffold. It now takes isMainPage and canScroll instead of allowNavigateBack, modifier and absolute. - Add a local NavigateUpToolbar. - Replace TextEditDialogItem, ButtonItem and Labels with InputDialogItem, RawItem and Supporting. - Rename RadioDialogItem option data to RadioDialogOption. - Move the home items package to home.components. - Remove the blacklist screen, its items and the blacklist alert. - Remove the unused RootScreen and the commented-out drawer code in MainScreen, and drop the @Destination annotation from MainScreen. - Drop BottomBar from DescriptionScreen. --- .../mmrl/model/local/FeaturedManager.kt | 4 +- .../dergoogler/mmrl/ui/component/BottomBar.kt | 11 +- .../dergoogler/mmrl/ui/component/Scaffold.kt | 96 +++--- .../mmrl/ui/screens/home/HomeScreen.kt | 6 +- .../home/{items => components}/NonRootItem.kt | 2 +- .../RebootBottomSheet.kt | 2 +- .../home/{items => components}/RootItem.kt | 2 +- .../mmrl/ui/screens/main/MainScreen.kt | 74 ----- .../mmrl/ui/screens/main/RootScreen.kt | 68 ----- .../moduleDetails/DescriptionScreen.kt | 4 - .../ui/screens/moduleView/NewViewScreen.kt | 4 + .../ui/screens/moduleView/sections/Alerts.kt | 24 -- .../mmrl/ui/screens/modules/ModulesScreen.kt | 4 + .../ui/screens/settings/SettingsScreen.kt | 283 +++++++++--------- .../settings/appearance/AppearanceScreen.kt | 18 +- .../appearance/items/DownloadPathItem.kt | 18 +- .../appearance/screens/AppThemeScreen.kt | 2 - .../settings/blacklist/BlacklistScreen.kt | 54 ---- .../settings/blacklist/items/ModuleItem.kt | 121 -------- .../settings/changelogs/ChangelogScreen.kt | 18 +- .../changelogs/items/ChangelogItem.kt | 21 +- .../settings/developer/DeveloperScreen.kt | 14 +- .../screens/settings/modules/ModulesScreen.kt | 23 +- .../ui/screens/settings/other/OtherScreen.kt | 18 +- .../settings/security/SecurityScreen.kt | 10 +- .../settings/terminal/TerminalScreen.kt | 8 +- .../screens/settings/updates/UpdatesScreen.kt | 66 ++-- .../compose/ui/toolbar/NavigateUpToolbar.kt | 129 ++++++++ gradle/libs.versions.toml | 2 +- 29 files changed, 439 insertions(+), 667 deletions(-) rename app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/{items => components}/NonRootItem.kt (98%) rename app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/{items => components}/RebootBottomSheet.kt (98%) rename app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/{items => components}/RootItem.kt (99%) delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/RootScreen.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/BlacklistScreen.kt delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/items/ModuleItem.kt create mode 100644 app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/model/local/FeaturedManager.kt b/app/src/main/kotlin/com/dergoogler/mmrl/model/local/FeaturedManager.kt index 9f915262a..db4a3bc9c 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/model/local/FeaturedManager.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/model/local/FeaturedManager.kt @@ -5,7 +5,7 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.WorkingMode -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.RadioDialogItem +import dev.mmrlx.compose.ui.list.component.RadioDialogOption data class FeaturedManager( private val nameAs: Any, @@ -15,7 +15,7 @@ data class FeaturedManager( ) { @Composable fun toRadioDialogItem() = - RadioDialogItem( + RadioDialogOption( title = name, value = workingMode, ) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt index 9cf34f3ad..e7f784a2b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt @@ -42,12 +42,13 @@ fun BottomBar(updates: Int = 0) { BaseNavIcon(screen, isSelected, updates) }, label = { - Text( - text = stringResource(id = screen.label), - style = MMRLXTheme.typography.labelLarge, - ) + if (!prefs.hideBottomBarLabels) { + Text( + text = stringResource(id = screen.label), + style = MMRLXTheme.typography.labelLarge, + ) + } }, - alwaysShowLabel = !prefs.hideBottomBarLabels, selected = isSelected, onClick = { if (isSelected) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt index effb1ecbb..78b8f0884 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt @@ -1,116 +1,96 @@ package com.dergoogler.mmrl.ui.component import androidx.annotation.StringRes -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.RowScope -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ext.systemBarsPaddingEnd -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.scaffold.ResponsiveScaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurNavigateUpToolbar -import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar -import com.dergoogler.mmrl.ui.component.toolbar.ToolbarTitle -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalNavController -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.toolbar.NavigateUpToolbar +import dev.mmrlx.compose.ui.toolbar.Toolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults +import dev.mmrlx.compose.ui.toolbar.ToolbarTitle @Composable fun SettingsScaffold( - modifier: ScaffoldModifier = ScaffoldDefaults.settingsScaffoldScrollModifier, @StringRes title: Int, - allowNavigateBack: Boolean = true, + isMainPage: Boolean = false, + canScroll: Boolean = true, actions: @Composable (RowScope.() -> Unit) = {}, floatingActionButton: @Composable () -> Unit = {}, - absolute: @Composable (BoxScope.() -> Unit) = {}, relative: @Composable (ListScope.() -> Unit), ) = SettingsScaffold( title = stringResource(id = title), - modifier = modifier, actions = actions, - allowNavigateBack = allowNavigateBack, + isMainPage = isMainPage, + canScroll = canScroll, floatingActionButton = floatingActionButton, - absolute = absolute, relative = relative, ) @Composable fun SettingsScaffold( - modifier: ScaffoldModifier = ScaffoldDefaults.settingsScaffoldScrollModifier, title: String, - allowNavigateBack: Boolean = true, + isMainPage: Boolean = false, + canScroll: Boolean = true, actions: @Composable (RowScope.() -> Unit) = {}, floatingActionButton: @Composable () -> Unit = {}, - absolute: @Composable (BoxScope.() -> Unit) = {}, relative: @Composable (ListScope.() -> Unit), -) = LocalScreenProvider { +) { val navController = LocalNavController.current - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() + + val scrollModifier = if (canScroll) { + Modifier.verticalScroll(rememberScrollState()) + } else Modifier - ResponsiveScaffold( + Scaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - if (allowNavigateBack) { - BlurNavigateUpToolbar( + toolbar = { + if (!isMainPage) { + NavigateUpToolbar( title = title, navController = navController, actions = actions, - fade = true, - fadeDistance = 50f, scrollBehavior = scrollBehavior, ) } else { - BlurToolbar( + Toolbar( title = { ToolbarTitle(title = title) }, - fade = true, - fadeDistance = 50f, actions = actions, scrollBehavior = scrollBehavior, ) } }, + bottomBar = { + if (isMainPage) { + BottomBar() + } + }, floatingActionButton = floatingActionButton, contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - Box( - modifier = - Modifier - .hazeSource(state = LocalHazeState.current) - .then(modifier.box), - ) { - List( - modifier = - modifier.column - .systemBarsPaddingEnd() - .padding(top = innerPadding.calculateTopPadding()), - content = { - relative() - - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - }, - ) - - absolute() - } + ) { + List( + modifier = Modifier + .then(scrollModifier) + .scaffoldHazeSource() + .scaffoldPadding(), + content = { + relative() + }, + ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 7408f2401..9b98cb3f8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -57,9 +57,9 @@ import com.dergoogler.mmrl.ui.remember.rememberLocalAnalytics import com.dergoogler.mmrl.ui.remember.seLinuxContext import com.dergoogler.mmrl.ui.remember.superUserCount import com.dergoogler.mmrl.ui.remember.versionName -import com.dergoogler.mmrl.ui.screens.home.items.NonRootItem -import com.dergoogler.mmrl.ui.screens.home.items.RebootBottomSheet -import com.dergoogler.mmrl.ui.screens.home.items.RootItem +import com.dergoogler.mmrl.ui.screens.home.components.NonRootItem +import com.dergoogler.mmrl.ui.screens.home.components.RebootBottomSheet +import com.dergoogler.mmrl.ui.screens.home.components.RootItem import com.dergoogler.mmrl.ui.screens.settings.changelogs.items.ChangelogBottomSheet import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/NonRootItem.kt similarity index 98% rename from app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt rename to app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/NonRootItem.kt index 20c6e48a7..7e9f17e94 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/NonRootItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/NonRootItem.kt @@ -1,4 +1,4 @@ -package com.dergoogler.mmrl.ui.screens.home.items +package com.dergoogler.mmrl.ui.screens.home.components import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RebootBottomSheet.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/RebootBottomSheet.kt similarity index 98% rename from app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RebootBottomSheet.kt rename to app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/RebootBottomSheet.kt index 47318ff42..c56e288a6 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RebootBottomSheet.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/RebootBottomSheet.kt @@ -1,4 +1,4 @@ -package com.dergoogler.mmrl.ui.screens.home.items +package com.dergoogler.mmrl.ui.screens.home.components import android.content.Context import android.os.Build diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/RootItem.kt similarity index 99% rename from app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt rename to app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/RootItem.kt index 2700a6d96..d444da02e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/items/RootItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/components/RootItem.kt @@ -1,4 +1,4 @@ -package com.dergoogler.mmrl.ui.screens.home.items +package com.dergoogler.mmrl.ui.screens.home.components import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt index 1c6c73a6e..bc28015d4 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/MainScreen.kt @@ -37,7 +37,6 @@ import dev.chrisbanes.haze.hazeSource import dev.chrisbanes.haze.rememberHazeState import dev.mmrlx.compose.ui.scaffold.Scaffold -@Destination @Composable fun MainScreen() { // val width = currentScreenWidth() @@ -60,79 +59,6 @@ fun MainScreen() { LocalSnackbarHost provides snackbarHostState, LocalBulkInstall provides bulkInstallViewModel, ) { - /*if (width.isLarge) { - Scaffold( - contentWindowInsets = WindowInsets.none, - ) { paddingValues -> - val navController = LocalNavController.current - - PermanentNavigationDrawer( - drawerContent = { - PermanentDrawerSheet( - modifier = - Modifier - .width(240.dp), - ) { - TopAppBar( - title = { - TopAppBarEventIcon() - }, - ) - - LazyColumn( - contentPadding = PaddingValues(8.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - items( - items = MainDestination.entries, - key = { it.name }, - ) { screen -> - val isSelected by navController.isRouteOnBackStackAsState(screen.direction) - - if (!screen.isAccessible) return@items - - NavigationDrawerItem( - icon = { - BaseNavIcon(screen, isSelected, updates) - }, - label = { - Text( - text = stringResource(id = screen.label), - style = MaterialTheme.typography.labelLarge, - ) - }, - selected = isSelected, - onClick = { - if (isSelected) { - navigator.popBackStack(screen.direction, false) - } - navigator.navigate(screen.direction) { - popUpTo(NavGraphs.root) { - saveState = true - } - launchSingleTop = true - restoreState = true - } - }, - ) - } - } - } - }, - ) { - CompositionLocalProvider( - LocalMainScreenInnerPaddings provides paddingValues, - ) { - CurrentNavHost( - Modifier.padding(paddingValues), - ) - } - } - } - - return@CompositionLocalProvider - }*/ - Scaffold( contentWindowInsets = WindowInsets.none, ) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/RootScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/RootScreen.kt deleted file mode 100644 index f8b1303fe..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/main/RootScreen.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.main - -import androidx.compose.animation.AnimatedContentTransitionScope -import androidx.compose.animation.EnterTransition -import androidx.compose.animation.ExitTransition -import androidx.compose.animation.core.tween -import androidx.compose.animation.fadeIn -import androidx.compose.animation.fadeOut -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalContext -import androidx.hilt.navigation.compose.hiltViewModel -import androidx.navigation.NavBackStackEntry -import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.providable.LocalBulkInstall -import com.dergoogler.mmrl.ui.providable.LocalNavController -import com.dergoogler.mmrl.ui.providable.LocalSnackbarHost -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.dergoogler.mmrl.utils.initPlatform -import com.dergoogler.mmrl.viewmodel.BulkInstallViewModel -import com.ramcosta.composedestinations.DestinationsNavHost -import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationStyle -import com.ramcosta.composedestinations.generated.NavGraphs - -@Composable -fun RootScreen() { - val navController = LocalNavController.current - val snackbarHostState = remember { SnackbarHostState() } - val bulkInstallViewModel: BulkInstallViewModel = hiltViewModel() - val context = LocalContext.current - val userPreferences = LocalUserPreferences.current - - LaunchedEffect(Unit) { - initPlatform(context, userPreferences.workingMode.toPlatform()) - } - - Scaffold( - snackbarHost = { SnackbarHost(snackbarHostState) }, - contentWindowInsets = WindowInsets.none, - ) { paddingValues -> - CompositionLocalProvider( - LocalSnackbarHost provides snackbarHostState, - LocalBulkInstall provides bulkInstallViewModel, - ) { - DestinationsNavHost( - modifier = Modifier.padding(bottom = paddingValues.calculateBottomPadding()), - navGraph = NavGraphs.root, - navController = navController, - defaultTransitions = - object : NavHostAnimatedDestinationStyle() { - override val enterTransition: AnimatedContentTransitionScope.() -> EnterTransition - get() = { fadeIn(animationSpec = tween(340)) } - override val exitTransition: AnimatedContentTransitionScope.() -> ExitTransition - get() = { fadeOut(animationSpec = tween(340)) } - }, - ) - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt index 737af2879..c2961ff64 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt @@ -16,7 +16,6 @@ import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.model.WebColors -import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.utils.MimeUtil @@ -131,9 +130,6 @@ fun DescriptionScreen(readmeUrl: String) { navigator = navigator, ) }, - bottomBar = { - BottomBar() - }, contentWindowInsets = WindowInsets.none, ) { wstate.insets( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index 1995c48fb..ef88b9c08 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -42,6 +42,7 @@ import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.model.online.isBlacklisted import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity +import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.scaffold.Scaffold @@ -221,6 +222,9 @@ fun NewViewScreen( topBar = { Toolbar() }, + bottomBar = { + BottomBar() + }, contentWindowInsets = WindowInsets.none, ) { innerPadding -> this@Scaffold.ResponsiveContent { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Alerts.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Alerts.kt index d726e38ee..892c889d9 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Alerts.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Alerts.kt @@ -5,20 +5,15 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.model.online.hasBlacklist import com.dergoogler.mmrl.model.online.hasValidMessage import com.dergoogler.mmrl.ui.component.Alert import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel -import com.dergoogler.mmrl.ui.screens.settings.blacklist.items.BlacklistBottomSheet private val alertPadding = PaddingValues(horizontal = 16.dp) @@ -32,25 +27,6 @@ internal fun Alerts() { module.manager(viewModel.platform) } - module.hasBlacklist { - var open by remember { mutableStateOf(false) } - if (open) { - BlacklistBottomSheet( - module = it, - onClose = { open = false }, - ) - } - - Alert( - icon = R.drawable.alert_circle_filled, - title = stringResource(R.string.blacklisted), - backgroundColor = MaterialTheme.colorScheme.errorContainer, - textColor = MaterialTheme.colorScheme.onErrorContainer, - message = stringResource(R.string.blacklisted_desc), - outsideContentPadding = alertPadding, - ) - } - manager.isNotSupportedRootVersion(viewModel.versionCode) { min -> if (min == -1) { Alert( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt index 991446019..1d0abfe6b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt @@ -43,6 +43,7 @@ import com.dergoogler.mmrl.ext.systemBarsPaddingEnd import com.dergoogler.mmrl.model.local.LocalModule import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity +import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Loading import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.PageIndicator @@ -109,6 +110,9 @@ fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) = scrollBehavior = scrollBehavior, ) }, + bottomBar = { + BottomBar() + }, floatingActionButton = { AnimatedVisibility( visible = showFab, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/SettingsScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/SettingsScreen.kt index dcdf30634..7cbe483c5 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/SettingsScreen.kt @@ -18,14 +18,6 @@ import com.dergoogler.mmrl.model.local.FeaturedManager.Companion.name import com.dergoogler.mmrl.ui.component.SettingsScaffold import com.dergoogler.mmrl.ui.component.dialog.ConfirmData import com.dergoogler.mmrl.ui.component.dialog.rememberConfirm -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListItemSlot -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.RadioDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences @@ -33,7 +25,6 @@ import com.jakewharton.processphoenix.ProcessPhoenix import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.AppearanceScreenDestination -import com.ramcosta.composedestinations.generated.destinations.BlacklistScreenDestination import com.ramcosta.composedestinations.generated.destinations.ChangelogScreenDestination import com.ramcosta.composedestinations.generated.destinations.DeveloperScreenDestination import com.ramcosta.composedestinations.generated.destinations.LogScreenDestination @@ -43,6 +34,13 @@ import com.ramcosta.composedestinations.generated.destinations.SecurityScreenDes import com.ramcosta.composedestinations.generated.destinations.TerminalScreenDestination import com.ramcosta.composedestinations.generated.destinations.UpdatesScreenDestination import com.ramcosta.composedestinations.spec.DirectionDestinationSpec +import dev.mmrlx.compose.ui.list.ListItemSlot +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.ButtonItem +import dev.mmrlx.compose.ui.list.component.RadioDialogItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Title @Destination @Composable @@ -54,151 +52,142 @@ fun SettingsScreen() { val confirm = rememberConfirm(context) SettingsScaffold( - allowNavigateBack = false, + isMainPage = true, title = R.string.page_settings, ) { - List { - context.isPackageInstalled(userPreferences.webuixPackageName).takeFalse { - ButtonItem( - onClick = { - browser.openUri( - if (BuildConfig.IS_GOOGLE_PLAY_BUILD) { - "https://play.google.com/store/apps/details?id=com.dergoogler.mmrl.wx" - } else { - "https://github.com/MMRLApp/WebUI-X-Portable" - }, - ) - }, - ) { - Icon( - painter = painterResource(R.drawable.sandbox), - ) - Title(R.string.settings_try_wxp) - Icon( - slot = ListItemSlot.End, - size = 12.dp, - painter = painterResource(R.drawable.external_link), + context.isPackageInstalled(userPreferences.webuixPackageName).takeFalse { + ButtonItem( + onClick = { + browser.openUri( + if (BuildConfig.IS_GOOGLE_PLAY_BUILD) { + "https://play.google.com/store/apps/details?id=com.dergoogler.mmrl.wx" + } else { + "https://github.com/MMRLApp/WebUI-X-Portable" + }, ) - } + }, + ) { + Icon( + painter = painterResource(R.drawable.sandbox), + ) + Title(R.string.settings_try_wxp) + Icon( + painter = painterResource(R.drawable.external_link), + slot = ListItemSlot.End, + size = 12.dp, + ) } + } - NavButton( - route = AppearanceScreenDestination, - icon = R.drawable.color_swatch, - title = R.string.settings_appearance, - desc = R.string.settings_appearance_desc, - ) - - NavButton( - route = SecurityScreenDestination, - icon = R.drawable.shield, - title = R.string.settings_security, - desc = R.string.settings_security_desc, - ) - - NavButton( - route = UpdatesScreenDestination, - icon = R.drawable.refresh, - title = R.string.settings_updates, - desc = R.string.settings_updates_desc, - ) - - NavButton( - route = ModulesScreen2Destination, - icon = R.drawable.stack_middle, - title = R.string.settings_modules, - desc = R.string.settings_modules_desc, - ) - - NavButton( - route = TerminalScreenDestination, - icon = R.drawable.terminal_2_outlined, - title = R.string.settings_terminal, - desc = R.string.settings_terminal_desc, - ) - - NavButton( - route = OtherScreenDestination, - icon = R.drawable.tool, - title = R.string.settings_other, - desc = R.string.settings_other_desc, - ) - - LinkButton( - uri = Const.RESOURCES_URL, - icon = R.drawable.file_3d, - title = R.string.settings_resources, - desc = R.string.settings_resources_desc, - ) - - val manager = - FeaturedManager.managers.find { userPreferences.workingMode == it.workingMode } - - manager.nullable { mng -> - RadioDialogItem( - selection = mng.workingMode, - options = FeaturedManager.managers.map { it.toRadioDialogItem() }, - onConfirm = { - confirm( - ConfirmData( - title = context.getString(R.string.change_platform), - description = context.getString(R.string.working_mode_change_dialog_desc), - closeText = context.getString(R.string.keep), - onClose = {}, - confirmText = context.getString(R.string.apply), - onConfirm = { - viewModel.setWorkingMode(it.value) - ProcessPhoenix.triggerRebirth(context) - }, - ), - ) - }, - ) { - Icon(painter = painterResource(mng.icon)) - Title(R.string.platform) - Description(mng.name) - } + NavButton( + route = AppearanceScreenDestination, + icon = R.drawable.color_swatch, + title = R.string.settings_appearance, + desc = R.string.settings_appearance_desc, + ) + + NavButton( + route = SecurityScreenDestination, + icon = R.drawable.shield, + title = R.string.settings_security, + desc = R.string.settings_security_desc, + ) + + NavButton( + route = UpdatesScreenDestination, + icon = R.drawable.refresh, + title = R.string.settings_updates, + desc = R.string.settings_updates_desc, + ) + + NavButton( + route = ModulesScreen2Destination, + icon = R.drawable.stack_middle, + title = R.string.settings_modules, + desc = R.string.settings_modules_desc, + ) + + NavButton( + route = TerminalScreenDestination, + icon = R.drawable.terminal_2_outlined, + title = R.string.settings_terminal, + desc = R.string.settings_terminal_desc, + ) + + NavButton( + route = OtherScreenDestination, + icon = R.drawable.tool, + title = R.string.settings_other, + desc = R.string.settings_other_desc, + ) + + LinkButton( + uri = Const.RESOURCES_URL, + icon = R.drawable.file_3d, + title = R.string.settings_resources, + desc = R.string.settings_resources_desc, + ) + + val manager = + FeaturedManager.managers.find { userPreferences.workingMode == it.workingMode } + + manager.nullable { mng -> + RadioDialogItem( + selection = mng.workingMode, + options = FeaturedManager.managers.map { it.toRadioDialogItem() }, + onConfirm = { + confirm( + ConfirmData( + title = context.getString(R.string.change_platform), + description = context.getString(R.string.working_mode_change_dialog_desc), + closeText = context.getString(R.string.keep), + onClose = {}, + confirmText = context.getString(R.string.apply), + onConfirm = { + viewModel.setWorkingMode(it.value) + ProcessPhoenix.triggerRebirth(context) + }, + ), + ) + }, + ) { + Icon(painter = painterResource(mng.icon)) + Title(R.string.platform) + Description(mng.name) } - - NavButton( - route = ChangelogScreenDestination, - icon = R.drawable.files, - title = R.string.settings_changelog, - desc = R.string.settings_changelo_desc, - ) - - NavButton( - route = BlacklistScreenDestination, - icon = R.drawable.file_shredder, - title = R.string.settings_blacklist, - desc = R.string.settings_blacklist_desc, - ) - - NavButton( - route = LogScreenDestination, - icon = R.drawable.logs, - title = R.string.settings_log_viewer, - ) - - NavButton( - route = DeveloperScreenDestination, - icon = R.drawable.bug, - title = R.string.settings_developer, - desc = R.string.settings_developer_desc, - ) - - LinkButton( - uri = Const.PRIVACY_POLICY_URL, - icon = R.drawable.spy, - title = R.string.settings_privacy_policy, - ) - - LinkButton( - uri = Const.TERMS_OF_SERVICE_URL, - icon = R.drawable.files, - title = R.string.settings_terms_of_service, - ) } + + NavButton( + route = ChangelogScreenDestination, + icon = R.drawable.files, + title = R.string.settings_changelog, + desc = R.string.settings_changelo_desc, + ) + + NavButton( + route = LogScreenDestination, + icon = R.drawable.logs, + title = R.string.settings_log_viewer, + ) + + NavButton( + route = DeveloperScreenDestination, + icon = R.drawable.bug, + title = R.string.settings_developer, + desc = R.string.settings_developer_desc, + ) + + LinkButton( + uri = Const.PRIVACY_POLICY_URL, + icon = R.drawable.spy, + title = R.string.settings_privacy_policy, + ) + + LinkButton( + uri = Const.TERMS_OF_SERVICE_URL, + icon = R.drawable.files, + title = R.string.settings_terms_of_service, + ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/AppearanceScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/AppearanceScreen.kt index 43a79ec0e..095706acb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/AppearanceScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/AppearanceScreen.kt @@ -7,12 +7,6 @@ import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.toFormattedDateSafely import com.dergoogler.mmrl.ui.component.LabelItem import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.TextEditDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.DialogDescription -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.screens.settings.NavButton @@ -20,6 +14,12 @@ import com.dergoogler.mmrl.utils.BlurUtil import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.AppThemeScreenDestination +import dev.mmrlx.compose.ui.list.component.InputDialogItem +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.DialogDescription +import dev.mmrlx.compose.ui.list.component.item.Supporting +import dev.mmrlx.compose.ui.list.component.item.Title @Destination @Composable @@ -36,10 +36,10 @@ fun AppearanceScreen() { route = AppThemeScreenDestination, ) - TextEditDialogItem( + InputDialogItem( value = userPreferences.datePattern, onConfirm = { - viewModel.setDatePattern(it) + viewModel.setDatePattern(it.value) }, ) { Title(R.string.settings_date_pattern) @@ -70,7 +70,7 @@ fun AppearanceScreen() { Description(R.string.settings_enable_blur_desc) if (!isBlurSupported) { - Labels { + Supporting { LabelItem(text = stringResource(R.string.view_module_unsupported)) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/items/DownloadPathItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/items/DownloadPathItem.kt index 4ad5501b1..5ebca7e3e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/items/DownloadPathItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/items/DownloadPathItem.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.settings.appearance.items +import androidx.compose.foundation.clickable import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField @@ -10,15 +11,16 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.app.Const import com.dergoogler.mmrl.ui.component.dialog.TextFieldDialog -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.RawItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Title import java.io.File @Composable @@ -35,8 +37,12 @@ fun ListScope.DownloadPathItem( ) } - ButtonItem( - onClick = { edit = true }, + RawItem( + modifier = Modifier + .clickable { + edit = true + } + .contentPadding(), ) { Title(R.string.settings_download_path) Description(File(downloadPath).absolutePath) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/screens/AppThemeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/screens/AppThemeScreen.kt index ea72678ae..b54fb6fbf 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/screens/AppThemeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/appearance/screens/AppThemeScreen.kt @@ -7,7 +7,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ui.component.ScaffoldDefaults import com.dergoogler.mmrl.ui.component.SettingsScaffold import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences @@ -25,7 +24,6 @@ fun AppThemeScreen() { val viewModel = LocalSettings.current SettingsScaffold( - modifier = ScaffoldDefaults.settingsScaffoldScrollModifier, title = R.string.settings_app_theme, ) { Column( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/BlacklistScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/BlacklistScreen.kt deleted file mode 100644 index 54ab8c796..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/BlacklistScreen.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.settings.blacklist - -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ui.component.PageIndicator -import com.dergoogler.mmrl.ui.component.ScaffoldDefaults -import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings -import com.dergoogler.mmrl.ui.providable.LocalSettings -import com.dergoogler.mmrl.ui.screens.settings.blacklist.items.ModuleItem -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootGraph -import dev.chrisbanes.haze.hazeSource - -@Destination -@Composable -fun BlacklistScreen() { - val viewModel = LocalSettings.current - val blacklist = viewModel.allBlacklistEntriesAsFlow - - SettingsScaffold( - modifier = ScaffoldDefaults.settingsScaffoldModifier, - title = R.string.settings_blacklist, - ) { - if (blacklist.isEmpty()) { - PageIndicator( - icon = R.drawable.cloud, - text = R.string.search_empty, - ) - } else { - LazyColumn( - modifier = Modifier.hazeSource(LocalHazeState.current), - ) { - items( - items = blacklist, - key = { it.id }, - ) { module -> - ModuleItem(module = module) - } - - item { - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } - } - } - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/items/ModuleItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/items/ModuleItem.kt deleted file mode 100644 index 619e20d06..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/blacklist/items/ModuleItem.kt +++ /dev/null @@ -1,121 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.settings.blacklist.items - -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Button -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Surface -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalUriHandler -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.dp -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.model.online.Blacklist -import com.dergoogler.mmrl.ui.component.BottomSheet -import com.dergoogler.mmrl.ui.component.MarkdownText -import com.dergoogler.mmrl.ui.component.NavigationBarsSpacer -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title - -@Composable -fun ListScope.ModuleItem(module: Blacklist) { - var open by remember { mutableStateOf(false) } - if (open) { - BlacklistBottomSheet( - module = module, - onClose = { open = false }, - ) - } - - ButtonItem( - onClick = { open = true }, - ) { - Title(module.id) - Description(module.source) - } -} - -@Composable -fun BlacklistBottomSheet( - module: Blacklist, - onClose: () -> Unit, -) = BottomSheet(onDismissRequest = onClose) { - val browser = LocalUriHandler.current - - Column( - modifier = Modifier.padding(bottom = 18.dp), - ) { - Column( - modifier = - Modifier - .fillMaxWidth() - .padding(16.dp), - ) { - Text( - style = MaterialTheme.typography.titleLarge, - text = module.id, - ) - - Spacer(modifier = Modifier.height(16.dp)) - - module.notes?.let { - if (it.isNotEmpty()) { - Surface( - color = MaterialTheme.colorScheme.surface, - tonalElevation = 1.dp, - shape = RoundedCornerShape(20.dp), - ) { - Column( - modifier = - Modifier - .fillMaxWidth() - .padding(16.dp), - ) { - Text( - text = stringResource(R.string.additional_notes), - style = MaterialTheme.typography.titleMedium, - fontWeight = FontWeight.Bold, - modifier = Modifier.padding(bottom = 4.dp), - ) - MarkdownText( - text = it, - style = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.outline), - ) - } - } - - Spacer(modifier = Modifier.height(4.dp)) - } - } - } - - Spacer(modifier = Modifier.height(10.dp)) - - Button( - modifier = - Modifier - .padding(horizontal = 16.dp) - .fillMaxWidth(), - onClick = { - browser.openUri(module.source) - }, - ) { - Text(stringResource(R.string.open_source)) - } - - NavigationBarsSpacer() - } -} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/ChangelogScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/ChangelogScreen.kt index adf82b5ec..d6689bf88 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/ChangelogScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/ChangelogScreen.kt @@ -3,8 +3,6 @@ package com.dergoogler.mmrl.ui.screens.settings.changelogs import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable @@ -13,21 +11,16 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier import com.dergoogler.mmrl.R import com.dergoogler.mmrl.model.online.Changelog import com.dergoogler.mmrl.network.runRequest import com.dergoogler.mmrl.stub.IMMRLApiManager import com.dergoogler.mmrl.ui.component.Loading -import com.dergoogler.mmrl.ui.component.ScaffoldDefaults import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.screens.settings.changelogs.items.ChangelogItem import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph -import dev.chrisbanes.haze.hazeSource import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber @@ -52,7 +45,7 @@ fun ChangelogScreen() { } SettingsScaffold( - modifier = ScaffoldDefaults.settingsScaffoldModifier, + canScroll = false, title = R.string.settings_changelog, ) { AnimatedVisibility( @@ -69,19 +62,12 @@ fun ChangelogScreen() { exit = fadeOut(), ) { changelog?.let { bl -> - LazyColumn( - modifier = Modifier.hazeSource(LocalHazeState.current), - ) { + LazyColumn { items(items = bl, key = { it.versionCode }) { entry -> if (!userPreferences.checkAppUpdatesPreReleases && entry.preRelease) return@items ChangelogItem(changelog = entry) } - - item { - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/items/ChangelogItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/items/ChangelogItem.kt index f3f30dd3c..ab89bca1b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/items/ChangelogItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/changelogs/items/ChangelogItem.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.settings.changelogs.items +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -28,11 +29,11 @@ import com.dergoogler.mmrl.model.online.Changelog import com.dergoogler.mmrl.ui.component.BottomSheet import com.dergoogler.mmrl.ui.component.LabelItem import com.dergoogler.mmrl.ui.component.MarkdownText -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.RawItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Supporting +import dev.mmrlx.compose.ui.list.component.item.Title @Composable fun ListScope.ChangelogItem(changelog: Changelog) { @@ -41,13 +42,17 @@ fun ListScope.ChangelogItem(changelog: Changelog) { ChangelogBottomSheet(changelog = changelog, onClose = { open = false }) } - ButtonItem( - onClick = { open = true }, + RawItem( + modifier = Modifier + .clickable { + open = true + } + .contentPadding(), ) { Title(changelog.versionName) Description(changelog.versionCode.toString()) changelog.preRelease.takeTrue { - Labels { + Supporting { LabelItem( text = stringResource( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt index feb65143b..b367c4e4e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt @@ -5,13 +5,13 @@ import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListItemScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Section -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.ListItemScope +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.Section +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.ramcosta.composedestinations.annotation.Destination diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/modules/ModulesScreen.kt index 6ca26792c..ba1b18748 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/modules/ModulesScreen.kt @@ -7,16 +7,17 @@ import com.dergoogler.mmrl.datastore.model.WebUIEngine import com.dergoogler.mmrl.ui.component.APatchLabel import com.dergoogler.mmrl.ui.component.KernelSuLabel import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.RadioDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Section -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.list.component.RadioDialogItem +import dev.mmrlx.compose.ui.list.component.RadioDialogOption +import dev.mmrlx.compose.ui.list.component.Section +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Supporting +import dev.mmrlx.compose.ui.list.component.item.Title @Destination @Composable @@ -37,7 +38,7 @@ fun ModulesScreen2() { ) { Title(R.string.settings_shell_module_state_change) Description(R.string.settings_shell_module_state_change_desc) - Labels { + Supporting { KernelSuLabel() APatchLabel() } @@ -50,7 +51,7 @@ fun ModulesScreen2() { ) { Title(R.string.settings_use_generic_action) Description(R.string.settings_use_generic_action_desc) - Labels { + Supporting { KernelSuLabel() APatchLabel() } @@ -66,15 +67,15 @@ fun ModulesScreen2() { selection = userPreferences.webuiEngine, options = listOf( - RadioDialogItem( + RadioDialogOption( value = WebUIEngine.WX, title = stringResource(R.string.settings_webui_engine_wx), ), - RadioDialogItem( + RadioDialogOption( value = WebUIEngine.KSU, title = stringResource(R.string.settings_webui_engine_ksu), ), - RadioDialogItem( + RadioDialogOption( value = WebUIEngine.PREFER_MODULE, title = stringResource(R.string.settings_webui_engine_prefer_module), ), diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/other/OtherScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/other/OtherScreen.kt index 12077de1f..65d488c83 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/other/OtherScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/other/OtherScreen.kt @@ -6,16 +6,16 @@ import androidx.compose.ui.platform.LocalContext import com.dergoogler.mmrl.R import com.dergoogler.mmrl.service.ProviderService import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.TextEditDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalSnackbarHost import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.screens.settings.appearance.items.DownloadPathItem import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.list.component.InputDialogItem import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -67,12 +67,14 @@ fun OtherScreen() { Description(R.string.settings_provider_service_desc) } - TextEditDialogItem( + InputDialogItem( value = userPreferences.webuixPackageName, - onConfirm = viewModel::setWebuixPackageName, + onConfirm = { + viewModel.setWebuixPackageName(it.value) + }, ) { - Title(context.getString(R.string.settings_set_spoofed_wxp)) - Description(context.getString(R.string.settings_set_spoofed_wxp_desc)) + Title(R.string.settings_set_spoofed_wxp) + Description(R.string.settings_set_spoofed_wxp_desc) } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/security/SecurityScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/security/SecurityScreen.kt index 94073545f..a238e1ed7 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/security/SecurityScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/security/SecurityScreen.kt @@ -11,14 +11,14 @@ import com.dergoogler.mmrl.R import com.dergoogler.mmrl.platform.ksu.KsuNative import com.dergoogler.mmrl.ui.component.LabelItem import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Supporting +import dev.mmrlx.compose.ui.list.component.item.Title @Destination @Composable @@ -83,7 +83,7 @@ fun SecurityScreen() { Description(R.string.settings_disable_su_desc) if (!isSuDisableSupported) { - Labels { + Supporting { LabelItem(text = stringResource(R.string.view_module_unsupported)) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/terminal/TerminalScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/terminal/TerminalScreen.kt index e3ad72348..9c982efc8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/terminal/TerminalScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/terminal/TerminalScreen.kt @@ -5,10 +5,10 @@ import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.WorkingMode.Companion.isRoot import com.dergoogler.mmrl.ui.component.SettingsScaffold -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Section -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.component.Section +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.ramcosta.composedestinations.annotation.Destination diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/updates/UpdatesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/updates/UpdatesScreen.kt index d061b2831..21257d6e4 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/updates/UpdatesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/updates/UpdatesScreen.kt @@ -3,8 +3,10 @@ package com.dergoogler.mmrl.ui.screens.settings.updates import android.content.Intent import android.provider.Settings import android.widget.Toast +import androidx.compose.foundation.clickable import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource @@ -15,21 +17,25 @@ import com.dergoogler.mmrl.service.RepositoryService import com.dergoogler.mmrl.ui.component.SettingsScaffold import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem import com.dergoogler.mmrl.ui.component.listItem.dsl.component.RadioDialogItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Section -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.SwitchItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.component.RadioDialogItem +import dev.mmrlx.compose.ui.list.component.Section +import dev.mmrlx.compose.ui.list.component.SwitchItem +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalSnackbarHost import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.list.component.RadioDialogOption +import dev.mmrlx.compose.ui.list.component.RawItem import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlin.time.Duration.Companion.milliseconds @Composable -fun radioDialogItem(interval: Long): RadioDialogItem = - RadioDialogItem( +fun radioDialogItem(interval: Long): RadioDialogOption = + RadioDialogOption( title = pluralStringResource(id = R.plurals.hours, count = interval.toInt(), interval), value = interval, ) @@ -63,24 +69,26 @@ fun UpdatesScreen() { title = R.string.settings_updates, ) { Section { - ButtonItem( - onClick = { - val intent = - Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { - putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) - } + RawItem( + modifier = Modifier + .clickable { + val intent = + Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply { + putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName) + } - if (intent.resolveActivity(context.packageManager) != null) { - context.startActivity(intent, null) - } else { - Toast - .makeText( - context, - "Cannot open notification settings", - Toast.LENGTH_SHORT, - ).show() + if (intent.resolveActivity(context.packageManager) != null) { + context.startActivity(intent, null) + } else { + Toast + .makeText( + context, + "Cannot open notification settings", + Toast.LENGTH_SHORT, + ).show() + } } - }, + .contentPadding(), ) { Title(R.string.settings_open_notification_settings) } @@ -123,7 +131,7 @@ fun UpdatesScreen() { } else { RepositoryService.stop(context) while (RepositoryService.isActive) { - delay(100) + delay(100.milliseconds) } viewModel.setRepositoryServiceEnabled(false) snackbarHost.showSnackbar(context.getString(R.string.repository_service_stopped)) @@ -144,8 +152,10 @@ fun UpdatesScreen() { ) { Title(R.string.settings_repo_update_interval) Description( - R.string.settings_repo_update_interval_desc, - userPreferences.autoUpdateReposInterval, + stringResource( + R.string.settings_repo_update_interval_desc, + userPreferences.autoUpdateReposInterval + ), ) } } @@ -190,8 +200,10 @@ fun UpdatesScreen() { ) { Title(R.string.settings_check_modules_update_interval) Description( - R.string.settings_check_modules_update_interval_desc, - userPreferences.checkModuleUpdatesInterval, + stringResource( + R.string.settings_check_modules_update_interval_desc, + userPreferences.checkModuleUpdatesInterval + ), ) } } diff --git a/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt b/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt new file mode 100644 index 000000000..3675c15aa --- /dev/null +++ b/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt @@ -0,0 +1,129 @@ +package dev.mmrlx.compose.ui.toolbar + +import android.content.Context +import androidx.activity.ComponentActivity +import androidx.compose.foundation.layout.RowScope +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource +import androidx.navigation.NavController +import com.ramcosta.composedestinations.navigation.DestinationsNavigator +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.ui.R + +@Composable +fun NavigateUpToolbar( + title: String, + navController: NavController, + modifier: Modifier = Modifier, + subtitle: String? = null, + enable: Boolean = true, + actions: @Composable RowScope.() -> Unit = {}, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, +) = NavigateUpToolbar( + modifier = modifier, + title = title, + subtitle = subtitle, + onBack = { navController.popBackStack() }, + actions = actions, + windowInsets = windowInsets, + scrollBehavior = scrollBehavior, + enable = enable, +) + +@Composable +fun NavigateUpToolbar( + title: String, + navigator: DestinationsNavigator, + modifier: Modifier = Modifier, + subtitle: String? = null, + enable: Boolean = true, + actions: @Composable RowScope.() -> Unit = {}, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, +) = NavigateUpToolbar( + modifier = modifier, + title = title, + subtitle = subtitle, + onBack = { navigator.popBackStack() }, + actions = actions, + windowInsets = windowInsets, + scrollBehavior = scrollBehavior, + enable = enable, +) + +@Composable +fun NavigateUpToolbar( + title: String, + modifier: Modifier = Modifier, + context: Context = LocalContext.current, + subtitle: String? = null, + enable: Boolean = true, + actions: @Composable RowScope.() -> Unit = {}, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, +) = NavigateUpToolbar( + modifier = modifier, + title = title, + subtitle = subtitle, + onBack = { (context as ComponentActivity).finish() }, + actions = actions, + windowInsets = windowInsets, + scrollBehavior = scrollBehavior, + enable = enable, +) + +@Composable +fun NavigateUpToolbar( + title: String, + onBack: () -> Unit, + modifier: Modifier = Modifier, + subtitle: String? = null, + enable: Boolean = true, + actions: @Composable RowScope.() -> Unit = {}, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, +) = NavigateUpToolbar( + modifier = modifier, + title = { + ToolbarTitle(title = title, subtitle = subtitle) + }, + onBack = onBack, + actions = actions, + windowInsets = windowInsets, + scrollBehavior = scrollBehavior, + enable = enable, +) + +@Composable +fun NavigateUpToolbar( + title: @Composable () -> Unit, + onBack: () -> Unit, + modifier: Modifier = Modifier, + enable: Boolean = true, + actions: @Composable RowScope.() -> Unit = {}, + windowInsets: WindowInsets = ToolbarDefaults.windowInsets, + scrollBehavior: ToolbarScrollBehavior? = null, +) = Toolbar( + title = title, + modifier = modifier, + navigationIcon = { + if (enable) { + IconButton( + onClick = { if (enable) onBack() }, + ) { + Icon( + painter = painterResource(id = R.drawable.arrow_left), + contentDescription = null, + ) + } + } + }, + actions = actions, + windowInsets = windowInsets, + scrollBehavior = scrollBehavior, +) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d6483bf6e..0b03d2734 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.230" +mmrlx = "1.0.231" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From a8146f93a0175ec683f33b11602da79a3ce93326 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:53:31 +0200 Subject: [PATCH 20/55] add warning for dev builds --- .../dergoogler/mmrl/ui/screens/home/HomeScreen.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 9b98cb3f8..406074681 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -33,6 +33,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.WorkingMode.Companion.isNonRoot @@ -67,6 +68,7 @@ import com.ramcosta.composedestinations.generated.destinations.AboutScreenDestin import com.ramcosta.composedestinations.generated.destinations.ThankYouScreenDestination import dev.mmrlx.compose.layout.outlinedCard import dev.mmrlx.compose.ui.LinearProgressIndicator +import dev.mmrlx.compose.ui.LocalTextStyle import dev.mmrlx.compose.ui.Text import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton @@ -212,6 +214,19 @@ fun HomeScreen() { .fillMaxWidth() ) { val uname = Os.uname() + + scope.Item { + Title { + Text( + "DEV BUILD! EXPECT ERRORS AND BROKEN UI/UX", + style = LocalTextStyle.current.copy( + fontFamily = FontFamily.Monospace, + color = Color.Red + ) + ) + } + } + scope.Item { Icon(painter = painterResource(R.drawable.cookie_man)) Title(R.string.kernel) From 43b6575dd98c356a8d5693b84f152a3072a8017f Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:19:00 +0100 Subject: [PATCH 21/55] . --- .../ui/component/toolbar/BlurSearchToolbar.kt | 27 +- .../mmrl/ui/screens/home/HomeScreen.kt | 2 +- .../mmrl/ui/screens/modules/ModulesList.kt | 89 ++--- .../mmrl/ui/screens/modules/ModulesScreen.kt | 155 ++++----- .../screens/repositories/RepositoriesList.kt | 70 ++-- .../screens/repositories/RepositoriesMenu.kt | 6 +- .../repositories/RepositoriesScreen.kt | 257 +++++++------- .../mmrl/ui/screens/repository/ModulesList.kt | 100 ++---- .../ui/screens/repository/RepositoryMenu.kt | 6 +- .../ui/screens/repository/RepositoryScreen.kt | 325 ++++++++---------- .../dergoogler/mmrl/ext/PaddingValuesExt.kt | 3 +- 11 files changed, 444 insertions(+), 596 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt index 9606dece8..8c8db2382 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt @@ -5,13 +5,8 @@ import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextFieldDefaults -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember @@ -26,10 +21,14 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.ui.R +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.theme.MMRLXTheme +import dev.mmrlx.compose.ui.toolbar.Toolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior -@OptIn(ExperimentalMaterial3Api::class) @Composable fun BlurSearchToolbar( modifier: Modifier = Modifier, @@ -43,23 +42,11 @@ fun BlurSearchToolbar( actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, scrollBehavior: ToolbarScrollBehavior? = null, - fadeBackgroundIfNoBlur: Boolean = false, - fadeDistance: Float = 200f, - fade: Boolean = false, - state: BlurToolbarState = rememberBlurToolbarState( - scrollBehavior = scrollBehavior, - fade = fade, - fadeDistance = fadeDistance, - ), -) = BlurToolbar( - state = state, +) = Toolbar( modifier = modifier, actions = actions, windowInsets = windowInsets, scrollBehavior = scrollBehavior, - fade = fade, - fadeBackgroundIfNoBlur = fadeBackgroundIfNoBlur, - fadeDistance = fadeDistance, navigationIcon = if (onClose != null && isSearch) { { @@ -117,7 +104,7 @@ fun BlurSearchToolbar( Text(text = stringResource(id = R.string.search_placeholder)) }, singleLine = true, - textStyle = MaterialTheme.typography.bodyLarge, + textStyle = MMRLXTheme.typography.bodyLarge, ) } } else { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 406074681..88a5a882e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -214,7 +214,7 @@ fun HomeScreen() { .fillMaxWidth() ) { val uname = Os.uname() - + scope.Item { Title { Text( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt index b7d998cae..cfea5905e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn @@ -22,7 +21,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext @@ -40,18 +38,14 @@ import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.platform.content.LocalModule.Companion.hasAction import com.dergoogler.mmrl.ui.activity.terminal.action.ActionActivity import com.dergoogler.mmrl.ui.component.VersionItemBottomSheet -import com.dergoogler.mmrl.ui.component.scaffold.ScaffoldScope -import com.dergoogler.mmrl.ui.component.scrollbar.VerticalFastScrollbar -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ModulesViewModel -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.ext.with +import dev.mmrlx.compose.ui.scaffold.ScaffoldScope @Composable fun ScaffoldScope.ModulesList( - innerPadding: PaddingValues, list: List, state: LazyListState, onDownload: (LocalModule, VersionItem, Boolean) -> Unit, @@ -60,53 +54,40 @@ fun ScaffoldScope.ModulesList( ) = Box( modifier = Modifier.fillMaxSize(), ) { - val paddingValues = LocalMainScreenInnerPaddings.current val layoutDirection = LocalLayoutDirection.current - this@ModulesList.ResponsiveContent { - LazyColumn( - state = state, - modifier = - Modifier - .fillMaxSize() - .hazeSource(state = LocalHazeState.current), - contentPadding = - PaddingValues( - top = innerPadding.calculateTopPadding() + 16.dp, - start = innerPadding.calculateStartPadding(layoutDirection) + 16.dp, - bottom = paddingValues.calculateBottomPadding() + 16.dp, - end = 16.dp, - ), - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - items( - items = list, - key = { it.id.id }, - contentType = { "module_item" }, - ) { module -> - CompositionLocalProvider( - LocalModule provides module, - ) { - ModuleItem( - viewModel = viewModel, - onDownload = onDownload, - isProviderAlive = isProviderAlive, - ) - } - } - } - } - - VerticalFastScrollbar( + LazyColumn( state = state, modifier = Modifier - .align(Alignment.CenterEnd) - .padding( - top = innerPadding.calculateTopPadding(), - bottom = paddingValues.calculateBottomPadding(), - ), - ) + .with(this@ModulesList) { + it.scaffoldHazeSource() + }, + contentPadding = + PaddingValues( + top = this@ModulesList.scaffoldTopPadding + 16.dp, + start = this@ModulesList.contentPadding.calculateStartPadding(layoutDirection) + 16.dp, + bottom = this@ModulesList.contentPadding.calculateBottomPadding() + 16.dp, + end = 16.dp, + ), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + items( + items = list, + key = { it.id.id }, + contentType = { "module_item" }, + ) { module -> + CompositionLocalProvider( + LocalModule provides module, + ) { + ModuleItem( + viewModel = viewModel, + onDownload = onDownload, + isProviderAlive = isProviderAlive, + ) + } + } + } } @Composable @@ -230,10 +211,10 @@ private fun ModuleItem( isProviderAlive, ) { isProviderAlive && - ( - !(viewModel.moduleCompatibility.canRestoreModules && userPreferences.useShellForModuleStateChange) || - module.state != State.REMOVE - ) + ( + !(viewModel.moduleCompatibility.canRestoreModules && userPreferences.useShellForModuleStateChange) || + module.state != State.REMOVE + ) } RemoveOrRestore( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt index 1d0abfe6b..b3c9c66b7 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt @@ -9,11 +9,10 @@ import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.PressInteraction +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.padding import androidx.compose.material3.FloatingActionButton -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.pulltorefresh.PullToRefreshBox import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator @@ -36,7 +35,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.ModulesMenu -import com.dergoogler.mmrl.ext.currentScreenWidth import com.dergoogler.mmrl.ext.isScrollingUp import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.systemBarsPaddingEnd @@ -45,93 +43,98 @@ import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Loading -import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.PageIndicator import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ModulesViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @Destination @Composable -fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) = - LocalScreenProvider { - val userPrefs = LocalUserPreferences.current - val context = LocalContext.current +fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) { + val userPrefs = LocalUserPreferences.current + val context = LocalContext.current - val list by viewModel.local.collectAsStateWithLifecycle() - val query by viewModel.query.collectAsStateWithLifecycle() - val state by viewModel.screenState.collectAsStateWithLifecycle() - val isLoading by viewModel.isLoading.collectAsStateWithLifecycle() + val list by viewModel.local.collectAsStateWithLifecycle() + val query by viewModel.query.collectAsStateWithLifecycle() + val state by viewModel.screenState.collectAsStateWithLifecycle() + val isLoading by viewModel.isLoading.collectAsStateWithLifecycle() - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() - val pullToRefreshState = rememberPullToRefreshState() + val pullToRefreshState = rememberPullToRefreshState() - val isScrollingUp by viewModel.listState.isScrollingUp() - val showFab by remember { - derivedStateOf { - isScrollingUp && !viewModel.isSearch && viewModel.isProviderAlive - } + val isScrollingUp by viewModel.listState.isScrollingUp() + val showFab by remember { + derivedStateOf { + isScrollingUp && !viewModel.isSearch && viewModel.isProviderAlive } + } - val download: (LocalModule, VersionItem, Boolean) -> Unit = { module, item, install -> - viewModel.downloader(context, module, item) { - if (install) { - InstallActivity.start( - context = context, - uri = it.toUri(), - ) - } + val download: (LocalModule, VersionItem, Boolean) -> Unit = { module, item, install -> + viewModel.downloader(context, module, item) { + if (install) { + InstallActivity.start( + context = context, + uri = it.toUri(), + ) } } + } - BackHandler( - enabled = viewModel.isSearch, - onBack = viewModel::closeSearch, - ) + BackHandler( + enabled = viewModel.isSearch, + onBack = viewModel::closeSearch, + ) - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - isSearch = viewModel.isSearch, - query = query, - onQueryChange = viewModel::search, - onOpenSearch = viewModel::openSearch, - onCloseSearch = viewModel::closeSearch, - setMenu = viewModel::setModulesMenu, - scrollBehavior = scrollBehavior, - ) - }, - bottomBar = { - BottomBar() - }, - floatingActionButton = { - AnimatedVisibility( - visible = showFab, - enter = - scaleIn( - animationSpec = tween(100), - initialScale = 0.8f, - ), - exit = - scaleOut( - animationSpec = tween(100), - targetScale = 0.8f, - ), - ) { - FloatingButton() - } - }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + TopBar0( + isSearch = viewModel.isSearch, + query = query, + onQueryChange = viewModel::search, + onOpenSearch = viewModel::openSearch, + onCloseSearch = viewModel::closeSearch, + setMenu = viewModel::setModulesMenu, + scrollBehavior = scrollBehavior, + ) + }, + bottomBar = { + BottomBar() + }, + floatingActionButton = { + AnimatedVisibility( + visible = showFab, + enter = + scaleIn( + animationSpec = tween(100), + initialScale = 0.8f, + ), + exit = + scaleOut( + animationSpec = tween(100), + targetScale = 0.8f, + ), + ) { + FloatingButton() + } + }, + contentWindowInsets = WindowInsets.none, + ) { + Box( + modifier = + Modifier + .scaffoldHazeSource() + ) { if (isLoading) { Loading() } @@ -150,20 +153,13 @@ fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) = indicator = { Indicator( modifier = - Modifier.align(Alignment.TopCenter).let { - if (!userPrefs.enableBlur) { - it.padding(top = innerPadding.calculateTopPadding()) - } else { - it - } - }, + Modifier.align(Alignment.TopCenter), isRefreshing = state.isRefreshing, state = pullToRefreshState, ) }, ) { this@Scaffold.ModulesList( - innerPadding = innerPadding, list = list, state = viewModel.listState, viewModel = viewModel, @@ -173,9 +169,10 @@ fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) = } } } +} @Composable -private fun TopBar( +private fun TopBar0( isSearch: Boolean, query: String, onQueryChange: (String) -> Unit, @@ -184,8 +181,6 @@ private fun TopBar( setMenu: (ModulesMenu) -> Unit, scrollBehavior: ToolbarScrollBehavior, ) { - val width = currentScreenWidth() - var currentQuery by remember { mutableStateOf(query) } DisposableEffect(isSearch) { onDispose { currentQuery = "" } @@ -203,8 +198,6 @@ private fun TopBar( currentQuery = "" }, title = { - if (!width.isSmall) return@BlurSearchToolbar - TopAppBarEventIcon() }, actions = { @@ -224,8 +217,6 @@ private fun TopBar( ) }, scrollBehavior = scrollBehavior, - fadeDistance = 50f, - fade = true, ) } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt index 3418716e4..2b2aa5ec8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt @@ -2,11 +2,7 @@ package com.dergoogler.mmrl.ui.screens.repositories import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.requiredHeightIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState @@ -23,18 +19,15 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R +import com.dergoogler.mmrl.ext.plus import com.dergoogler.mmrl.model.state.RepoState -import com.dergoogler.mmrl.ui.component.scaffold.ScaffoldScope import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.screens.repositories.items.ExploreReposCard import com.ramcosta.composedestinations.generated.destinations.RepositoryScreenDestination -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.scaffold.ScaffoldScope @Composable fun ScaffoldScope.RepositoriesList( @@ -42,51 +35,32 @@ fun ScaffoldScope.RepositoriesList( state: LazyListState, delete: (RepoState) -> Unit, getUpdate: (RepoState, (Throwable) -> Unit) -> Unit, - innerPadding: PaddingValues, ) = Box( modifier = Modifier.fillMaxSize(), ) { - val paddingValues = LocalMainScreenInnerPaddings.current - val layoutDirection = LocalLayoutDirection.current val navigator = LocalDestinationsNavigator.current - this@RepositoriesList.ResponsiveContent { - LazyColumn( - state = state, - modifier = - Modifier - .fillMaxSize() - .hazeSource(state = LocalHazeState.current), - contentPadding = - PaddingValues( - top = innerPadding.calculateTopPadding() + 16.dp, - start = innerPadding.calculateStartPadding(layoutDirection) + 16.dp, - bottom = 16.dp, - end = 16.dp, - ), - verticalArrangement = Arrangement.spacedBy(10.dp), - ) { - item { - ExploreReposCard() - } - - items( - items = list, - key = { it.url }, - ) { repo -> - RepositoryItem( - repo = repo, - onClick = { - navigator.navigate(RepositoryScreenDestination(repo.toRepo())) - }, - onUpdate = getUpdate, - onDelete = delete, - ) - } + LazyColumn( + state = state, + contentPadding = this@RepositoriesList.contentPadding + 16.dp, + verticalArrangement = Arrangement.spacedBy(10.dp), + ) { + item { + ExploreReposCard() + } - item { - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } + items( + items = list, + key = { it.url }, + ) { repo -> + RepositoryItem( + repo = repo, + onClick = { + navigator.navigate(RepositoryScreenDestination(repo.toRepo())) + }, + onUpdate = getUpdate, + onDelete = delete, + ) } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesMenu.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesMenu.kt index 4b736cd89..b26767330 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesMenu.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesMenu.kt @@ -6,10 +6,7 @@ import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -29,6 +26,9 @@ import com.dergoogler.mmrl.ui.component.Segment import com.dergoogler.mmrl.ui.component.SegmentedButtons import com.dergoogler.mmrl.ui.component.SegmentedButtonsDefaults import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton @Composable fun RepositoriesMenu(setMenu: (RepositoriesMenu) -> Unit) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt index 2dc769b2b..b7416dbad 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt @@ -4,6 +4,7 @@ import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.tween import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -11,12 +12,9 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.FloatingActionButton -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField -import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.pulltorefresh.PullToRefreshBox import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator @@ -41,7 +39,6 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.RepositoriesMenu -import com.dergoogler.mmrl.ext.currentScreenWidth import com.dergoogler.mmrl.ext.isScrollingUp import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.rememberSaveableLazyListState @@ -52,12 +49,9 @@ import com.dergoogler.mmrl.ui.animate.slideInTopToBottom import com.dergoogler.mmrl.ui.animate.slideOutBottomToTop import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Loading -import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.PageIndicator import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon import com.dergoogler.mmrl.ui.component.dialog.TextFieldDialog -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar import com.dergoogler.mmrl.ui.providable.LocalBulkInstall import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings @@ -67,6 +61,11 @@ import com.dergoogler.mmrl.viewmodel.RepositoriesViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.SearchScreenDestination +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.toolbar.Toolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import timber.log.Timber @@ -74,126 +73,129 @@ import kotlin.reflect.KFunction1 @Destination @Composable -fun RepositoriesScreen() = - LocalScreenProvider { - val viewModel = hiltViewModel() +fun RepositoriesScreen() { + val viewModel = hiltViewModel() - val userPrefs = LocalUserPreferences.current - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() - val list by viewModel.repos.collectAsStateWithLifecycle() - val bulkInstallViewModel = LocalBulkInstall.current - val bulkModules by bulkInstallViewModel.bulkModules.collectAsStateWithLifecycle() + val userPrefs = LocalUserPreferences.current + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() + val list by viewModel.repos.collectAsStateWithLifecycle() + val bulkInstallViewModel = LocalBulkInstall.current + val bulkModules by bulkInstallViewModel.bulkModules.collectAsStateWithLifecycle() - val state by viewModel.screenState.collectAsStateWithLifecycle() - val progress by viewModel.progress.collectAsStateWithLifecycle() + val state by viewModel.screenState.collectAsStateWithLifecycle() + val progress by viewModel.progress.collectAsStateWithLifecycle() - val pullToRefreshState = rememberPullToRefreshState() + val pullToRefreshState = rememberPullToRefreshState() - // Use rememberSaveable to persist scroll position across navigation - val listState = rememberSaveableLazyListState(key = "repositories_list") + // Use rememberSaveable to persist scroll position across navigation + val listState = rememberSaveableLazyListState(key = "repositories_list") - val showFab by listState.isScrollingUp() + val showFab by listState.isScrollingUp() - var repoUrl by remember { mutableStateOf("") } - var message: String by remember { mutableStateOf("") } + var repoUrl by remember { mutableStateOf("") } + var message: String by remember { mutableStateOf("") } - var failure by remember { mutableStateOf(false) } - if (failure) { - FailureDialog( - name = repoUrl, - message = message, - onClose = { - failure = false - message = "" - }, - ) - } - - var add by remember { mutableStateOf(false) } - if (add) { - AddDialog( - onClose = { add = false }, - onAdd = { - repoUrl = it - viewModel.insert(it) { e -> - failure = true - message = e.stackTraceToString() - } - }, - ) - } - - val context = LocalContext.current - var bulkInstallBottomSheet by remember { mutableStateOf(false) } + var failure by remember { mutableStateOf(false) } + if (failure) { + FailureDialog( + name = repoUrl, + message = message, + onClose = { + failure = false + message = "" + }, + ) + } - val bulkDownload: (List, Boolean) -> Unit = { item, install -> - bulkInstallViewModel.downloadMultiple( - items = item, - onAllSuccess = { - bulkInstallViewModel.clearBulkModules() - bulkInstallBottomSheet = false - if (install) { - InstallActivity.start( - context = context, - uri = it, - ) - } - }, - onFailure = { - Timber.e(it) - }, - ) - } + var add by remember { mutableStateOf(false) } + if (add) { + AddDialog( + onClose = { add = false }, + onAdd = { + repoUrl = it + viewModel.insert(it) { e -> + failure = true + message = e.stackTraceToString() + } + }, + ) + } - if (bulkInstallBottomSheet) { - BulkBottomSheet( - onClose = { - bulkInstallBottomSheet = false - }, - modules = bulkModules, - onDownload = bulkDownload, - bulkInstallViewModel = bulkInstallViewModel, - ) - } + val context = LocalContext.current + var bulkInstallBottomSheet by remember { mutableStateOf(false) } - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - setMenu = viewModel::setRepositoriesMenu, - onAdd = { add = true }, - scrollBehavior = scrollBehavior, - ) + val bulkDownload: (List, Boolean) -> Unit = { item, install -> + bulkInstallViewModel.downloadMultiple( + items = item, + onAllSuccess = { + bulkInstallViewModel.clearBulkModules() + bulkInstallBottomSheet = false + if (install) { + InstallActivity.start( + context = context, + uri = it, + ) + } }, - bottomBar = { - BottomBar() + onFailure = { + Timber.e(it) }, - contentWindowInsets = WindowInsets.none, - floatingActionButton = { - if (viewModel.platform.isValid) { - AnimatedVisibility( - visible = showFab, - enter = - scaleIn( - animationSpec = tween(100), - initialScale = 0.8f, - ), - exit = - scaleOut( - animationSpec = tween(100), - targetScale = 0.8f, - ), - ) { - FloatingButton( - onClick = { - bulkInstallBottomSheet = true - }, - ) - } - } + ) + } + + if (bulkInstallBottomSheet) { + BulkBottomSheet( + onClose = { + bulkInstallBottomSheet = false }, - ) { innerPadding -> + modules = bulkModules, + onDownload = bulkDownload, + bulkInstallViewModel = bulkInstallViewModel, + ) + } + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + TopBar0( + setMenu = viewModel::setRepositoriesMenu, + onAdd = { add = true }, + scrollBehavior = scrollBehavior, + ) + }, + bottomBar = { + BottomBar() + }, + contentWindowInsets = WindowInsets.none, + floatingActionButton = { + if (viewModel.platform.isValid) { + AnimatedVisibility( + visible = showFab, + enter = + scaleIn( + animationSpec = tween(100), + initialScale = 0.8f, + ), + exit = + scaleOut( + animationSpec = tween(100), + targetScale = 0.8f, + ), + ) { + FloatingButton( + onClick = { + bulkInstallBottomSheet = true + }, + ) + } + } + }, + ) { + Box( + modifier = + Modifier + .scaffoldHazeSource() + ) { if (viewModel.isLoading) { Loading() } @@ -211,21 +213,13 @@ fun RepositoriesScreen() = onRefresh = viewModel::getRepoAll, indicator = { Indicator( - modifier = - Modifier.align(Alignment.TopCenter).let { - if (!userPrefs.enableBlur) { - it.padding(top = innerPadding.calculateTopPadding()) - } else { - it - } - }, + modifier = Modifier.align(Alignment.TopCenter), isRefreshing = state.isRefreshing, state = pullToRefreshState, ) }, ) { this@Scaffold.RepositoriesList( - innerPadding = innerPadding, list = list, state = listState, delete = viewModel::delete, @@ -239,19 +233,13 @@ fun RepositoriesScreen() = exit = slideOutBottomToTop(), ) { LinearProgressIndicator( - modifier = - Modifier.fillMaxWidth().let { - if (!userPrefs.enableBlur) { - it.padding(top = innerPadding.calculateTopPadding()) - } else { - it - } - }, + modifier = Modifier.fillMaxWidth(), strokeCap = StrokeCap.Round, ) } } } +} @Composable private fun AddDialog( @@ -306,23 +294,18 @@ private fun AddDialog( } @Composable -private fun TopBar( +private fun TopBar0( onAdd: () -> Unit, setMenu: KFunction1, scrollBehavior: ToolbarScrollBehavior, ) { - val width = currentScreenWidth() val navigator = LocalDestinationsNavigator.current - BlurToolbar( + Toolbar( scrollBehavior = scrollBehavior, title = { - if (!width.isSmall) return@BlurToolbar - TopAppBarEventIcon() }, - fadeDistance = 50f, - fade = true, actions = { IconButton( onClick = { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index bfbae90f2..4849f60ac 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -4,10 +4,7 @@ import androidx.compose.animation.animateContentSize import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope @@ -15,27 +12,21 @@ import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.database.entity.Repo import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.state.OnlineState -import com.dergoogler.mmrl.ui.component.scaffold.ScaffoldScope import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModuleState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDestination -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.scaffold.ScaffoldScope @Composable fun ScaffoldScope.ModulesList( - innerPadding: PaddingValues, repo: Repo, list: List>, state: LazyListState, @@ -45,69 +36,50 @@ fun ScaffoldScope.ModulesList( val userPreferences = LocalUserPreferences.current val menu = userPreferences.repositoryMenu - val paddingValues = LocalMainScreenInnerPaddings.current - val layoutDirection = LocalLayoutDirection.current - - val pad = remember(menu) { if (menu.repoListMode == RepoListMode.Compact) 0.dp else 16.dp } - Box( modifier = Modifier.fillMaxSize(), ) { - this@ModulesList.ResponsiveContent { - LazyColumn( - state = state, - modifier = Modifier - .fillMaxSize() - .animateContentSize() - .hazeSource(LocalHazeState.current), - contentPadding = - PaddingValues( - // top = innerPadding.calculateTopPadding(), - bottom = pad, - ), - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - beforeContent() + LazyColumn( + state = state, + modifier = Modifier + .animateContentSize(), + contentPadding = + PaddingValues( + bottom = this@ModulesList.scaffoldBottomPadding + 16.dp, + ), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + beforeContent() - items( - items = list, - key = { it.second.id }, - ) { (moduleState, module) -> - CompositionLocalProvider( - LocalOnlineModuleState provides moduleState, - LocalOnlineModule provides module, - ) { - val click = fun() { - navigator.navigate( - NewViewScreenDestination(repo, module), - ) - } + items( + items = list, + key = { it.second.id }, + ) { (moduleState, module) -> + CompositionLocalProvider( + LocalOnlineModuleState provides moduleState, + LocalOnlineModule provides module, + ) { + val click = fun() { + navigator.navigate( + NewViewScreenDestination(repo, module), + ) + } - Box( - modifier = Modifier.padding( - start = innerPadding.calculateStartPadding(layoutDirection) + pad, - end = pad, - ) - ) { - when (menu.repoListMode) { - RepoListMode.Compact -> - ModuleItemCompact( - onClick = click, - ) + Box(Modifier.padding(horizontal = 16.dp)) { + when (menu.repoListMode) { + RepoListMode.Compact -> + ModuleItemCompact( + onClick = click, + ) - RepoListMode.Detailed -> - ModuleItemDetailed( - onClick = click, - ) - } + RepoListMode.Detailed -> + ModuleItemDetailed( + onClick = click, + ) } } } - - item { - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } } } } -} +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt index 1c706f7b8..b6376bc9a 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt @@ -6,10 +6,7 @@ import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -30,6 +27,9 @@ import com.dergoogler.mmrl.ui.component.Segment import com.dergoogler.mmrl.ui.component.SegmentedButtons import com.dergoogler.mmrl.ui.component.SegmentedButtonsDefaults import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton @Composable fun RepositoryMenu(setMenu: (RepositoryMenu) -> Unit) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index f05eb90a6..cb41360b1 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -2,24 +2,10 @@ package com.dergoogler.mmrl.ui.screens.repository import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility -import androidx.compose.foundation.background -import androidx.compose.foundation.border -import androidx.compose.foundation.layout.Arrangement +import androidx.compose.animation.scaleIn +import androidx.compose.animation.scaleOut import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.offset -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue @@ -27,23 +13,14 @@ import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R @@ -51,28 +28,19 @@ import com.dergoogler.mmrl.database.entity.Repo import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.datastore.model.RepositoryMenu import com.dergoogler.mmrl.ext.fadingEdge -import com.dergoogler.mmrl.ext.isNotNullOrBlank import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.ext.nullply -import com.dergoogler.mmrl.ext.onClick -import com.dergoogler.mmrl.ext.stripLinks import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.LabelItemDefaults -import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.PageIndicator -import com.dergoogler.mmrl.ui.component.card.Card -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.text.BBCodeText import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar -import com.dergoogler.mmrl.ui.component.toolbar.ToolbarTitle -import com.dergoogler.mmrl.ui.component.toolbar.rememberBlurToolbarState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.dergoogler.mmrl.compat.core.LocalUriHandler +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @@ -80,7 +48,7 @@ import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @Composable fun RepositoryScreen( repo: Repo, -) = LocalScreenProvider { +) { val userPreferences = LocalUserPreferences.current val browser = LocalUriHandler.current val density = LocalDensity.current @@ -93,7 +61,7 @@ fun RepositoryScreen( val closeSearch = viewModel::closeSearch val search = viewModel::search val isSearch by viewModel::isSearch - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() var coverHeight by remember { mutableIntStateOf(0) } var cardHeight by remember { mutableIntStateOf(0) } @@ -101,11 +69,11 @@ fun RepositoryScreen( val menu = userPreferences.repositoryMenu val pad = remember(menu) { if (menu.repoListMode == RepoListMode.Compact) 0.dp else 16.dp } - BackHandler(enabled = viewModel.isSearch, onBack = viewModel::closeSearch) + BackHandler(enabled = viewModel.isSearch, onBack = closeSearch) Scaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { + toolbar = { TopBar0( repo = repo, isSearch = isSearch, @@ -121,146 +89,143 @@ fun RepositoryScreen( BottomBar() }, contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - if (modules.isEmpty()) { - PageIndicator( - icon = R.drawable.cloud, - text = if (isSearch) R.string.search_empty else R.string.repository_empty, - ) - - return@Scaffold - } - - this@Scaffold.ModulesList( - innerPadding = innerPadding, - repo = repo, - list = modules, - state = viewModel.listState, + ) { + Box( + modifier = + Modifier + .scaffoldHazeSource() ) { - item { - AnimatedVisibility(isSearch) { - Spacer(Modifier.height(innerPadding.calculateTopPadding() + pad)) - } + if (modules.isEmpty()) { + PageIndicator( + icon = R.drawable.cloud, + text = if (isSearch) R.string.search_empty else R.string.repository_empty, + ) - AnimatedVisibility(!isSearch) { - Box(Modifier.animateEnterExit()) { - Cover( - modifier = - Modifier - .fadingEdge( - brush = - Brush.verticalGradient( - colors = listOf( - Color.Transparent, - Color.Black - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), - ) - .onGloballyPositioned { coordinates -> - coverHeight = coordinates.size.height - }, - url = repo.cover ?: "ERROR ME", - errorIcon = R.drawable.box, - ) + return@Scaffold + } - Box( - modifier = - Modifier - .offset(y = 164.4.dp) - .align(Alignment.TopCenter) - .fillMaxWidth(0.85f) - .onGloballyPositioned { coordinates -> - cardHeight = coordinates.size.height - }, - ) { - Card( + this@Scaffold.ModulesList( + repo = repo, + list = modules, + state = viewModel.listState, + ) { + item { + AnimatedVisibility(!isSearch, enter = scaleIn(), exit = scaleOut()) { + Box(Modifier.animateEnterExit(scaleIn(), scaleOut())) { + Cover( modifier = Modifier - .align(Alignment.BottomCenter) - .background( + .fadingEdge( brush = - Brush.linearGradient( - colors = - listOf( - MaterialTheme.colorScheme.surfaceColorAtElevation( - 1.dp, - ), - MaterialTheme.colorScheme.background, - ), - start = Offset(0f, 0f), - end = - Offset( - Float.POSITIVE_INFINITY, - Float.POSITIVE_INFINITY, - ), + Brush.verticalGradient( + colors = listOf( + Color.Transparent, + Color.Black + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, ), - RoundedCornerShape(20.dp), ) - .border( - Dp.Hairline, - MaterialTheme.colorScheme.outlineVariant, - RoundedCornerShape(20.dp), - ), - ) { - Column( - modifier = - Modifier - .relative() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - Text( - text = repo.name, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - textAlign = TextAlign.Center, - style = MaterialTheme.typography.headlineMedium, - fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onBackground, - ) - - BBCodeText( - text = - ( - repo.description - ?: stringResource(R.string.view_module_no_description) - ).stripLinks( - "", - ), - style = MaterialTheme.typography.bodyMedium, - textAlign = TextAlign.Center, - color = MaterialTheme.colorScheme.outlineVariant, - lineHeight = 20.sp, - ) - - FlowRow { - repo.nullply { - if (submission.isNotNullOrBlank()) { - LabelItem( - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, - contentColor = MaterialTheme.colorScheme.onSurfaceVariant, - ), - modifier = - Modifier.onClick { - browser.openUri(submission) - }, - icon = getDomainIcon(submission), - text = stringResource(R.string.repo_options_submission), - ) - } - } - } - } - } - } - - with(density) { - Spacer(modifier = Modifier.height((((coverHeight / 1.05f) + cardHeight)).toDp())) + .onGloballyPositioned { coordinates -> + coverHeight = coordinates.size.height + }, + url = repo.cover ?: "ERROR ME", + errorIcon = R.drawable.box, + ) +// +// Box( +// modifier = +// Modifier +// .offset(y = 164.4.dp) +// .align(Alignment.TopCenter) +// .fillMaxWidth(0.85f) +// .onGloballyPositioned { coordinates -> +// cardHeight = coordinates.size.height +// }, +// ) { +// Card( +// modifier = +// Modifier +// .align(Alignment.BottomCenter) +// .background( +// brush = +// Brush.linearGradient( +// colors = +// listOf( +// MaterialTheme.colorScheme.surfaceColorAtElevation( +// 1.dp, +// ), +// MaterialTheme.colorScheme.background, +// ), +// start = Offset(0f, 0f), +// end = +// Offset( +// Float.POSITIVE_INFINITY, +// Float.POSITIVE_INFINITY, +// ), +// ), +// RoundedCornerShape(20.dp), +// ) +// .border( +// Dp.Hairline, +// MaterialTheme.colorScheme.outlineVariant, +// RoundedCornerShape(20.dp), +// ), +// ) { +// Column( +// modifier = +// Modifier +// .relative() +// .padding(16.dp), +// horizontalAlignment = Alignment.CenterHorizontally, +// verticalArrangement = Arrangement.spacedBy(16.dp), +// ) { +// Text( +// text = repo.name, +// maxLines = 2, +// overflow = TextOverflow.Ellipsis, +// textAlign = TextAlign.Center, +// style = MaterialTheme.typography.headlineMedium, +// fontWeight = FontWeight.Bold, +// color = MaterialTheme.colorScheme.onBackground, +// ) +// +// BBCodeText( +// text = +// ( +// repo.description +// ?: stringResource(R.string.view_module_no_description) +// ).stripLinks( +// "", +// ), +// style = MaterialTheme.typography.bodyMedium, +// textAlign = TextAlign.Center, +// color = MaterialTheme.colorScheme.outlineVariant, +// lineHeight = 20.sp, +// ) +// +// FlowRow { +// repo.nullply { +// if (submission.isNotNullOrBlank()) { +// LabelItem( +// style = +// LabelItemDefaults.style.copy( +// containerColor = MaterialTheme.colorScheme.surfaceContainerHigh, +// contentColor = MaterialTheme.colorScheme.onSurfaceVariant, +// ), +// modifier = +// Modifier.onClick { +// browser.openUri(submission) +// }, +// icon = getDomainIcon(submission), +// text = stringResource(R.string.repo_options_submission), +// ) +// } +// } +// } +// } +// } +// } } } } @@ -280,21 +245,15 @@ private fun TopBar0( scrollBehavior: ToolbarScrollBehavior, setMenu: (RepositoryMenu) -> Unit, ) { - val state = rememberBlurToolbarState(scrollBehavior, fade = true) - var currentQuery by remember { mutableStateOf(query) } DisposableEffect(isSearch) { onDispose { currentQuery = "" } } BlurSearchToolbar( - state = state, - fadeBackgroundIfNoBlur = true, isSearch = isSearch, query = currentQuery, scrollBehavior = scrollBehavior, - fade = true, - fadeDistance = 200f, onQueryChange = { onQueryChange(it) currentQuery = it @@ -304,10 +263,10 @@ private fun TopBar0( currentQuery = "" }, title = { - ToolbarTitle( - title = repo.name, - modifier = Modifier.graphicsLayer { alpha = state.alpha }, - ) +// ToolbarTitle( +// title = repo.name, +// modifier = Modifier.graphicsLayer { alpha = scrollBehavior.fadeDistance }, +// ) }, actions = { if (!isSearch) { diff --git a/ext/src/main/kotlin/com/dergoogler/mmrl/ext/PaddingValuesExt.kt b/ext/src/main/kotlin/com/dergoogler/mmrl/ext/PaddingValuesExt.kt index 06e3121f8..add7da461 100644 --- a/ext/src/main/kotlin/com/dergoogler/mmrl/ext/PaddingValuesExt.kt +++ b/ext/src/main/kotlin/com/dergoogler/mmrl/ext/PaddingValuesExt.kt @@ -11,7 +11,8 @@ import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection -inline operator fun PaddingValues.plus(other: PaddingValues): PaddingValues = OperatorPaddingValues(this, other, Dp::plus) +inline operator fun PaddingValues.plus(other: Dp): PaddingValues = OperatorPaddingValues(this, + PaddingValues(other), Dp::plus) inline operator fun PaddingValues.minus(other: PaddingValues): PaddingValues = OperatorPaddingValues(this, other, Dp::minus) From 612f6234c2126f9c5e402eb2aa682fa50ff417d4 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:28:20 +0100 Subject: [PATCH 22/55] . --- .../DescriptionScreen.kt | 2 +- .../ui/screens/moduleView/NewViewScreen.kt | 6 +- .../moduleView/ViewDescriptionScreen.kt | 175 ------------------ .../ui/screens/moduleView/sections/Toolbar.kt | 34 +--- .../mmrl/ui/screens/modules/ModulesMenu.kt | 6 +- .../ui/screens/repository/RepositoryScreen.kt | 6 - 6 files changed, 9 insertions(+), 220 deletions(-) rename app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/{moduleDetails => moduleView}/DescriptionScreen.kt (99%) delete mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt similarity index 99% rename from app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt rename to app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt index c2961ff64..fd97cbaa2 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleDetails/DescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt @@ -1,4 +1,4 @@ -package com.dergoogler.mmrl.ui.screens.moduleDetails +package com.dergoogler.mmrl.ui.screens.moduleView import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.PaddingValues diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index ef88b9c08..0b2680d2f 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -42,7 +42,6 @@ import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.model.online.isBlacklisted import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity -import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.scaffold.Scaffold @@ -182,7 +181,7 @@ fun NewViewScreen( ) } - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() val isBlacklisted by module.isBlacklisted @@ -222,9 +221,6 @@ fun NewViewScreen( topBar = { Toolbar() }, - bottomBar = { - BottomBar() - }, contentWindowInsets = WindowInsets.none, ) { innerPadding -> this@Scaffold.ResponsiveContent { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt deleted file mode 100644 index a7fa6a9f5..000000000 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/ViewDescriptionScreen.kt +++ /dev/null @@ -1,175 +0,0 @@ -package com.dergoogler.mmrl.ui.screens.moduleView - -import android.annotation.SuppressLint -import androidx.activity.compose.BackHandler -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.DisposableEffect -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.toArgb -import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.res.stringResource -import com.dergoogler.mmrl.BuildConfig -import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.none -import com.dergoogler.mmrl.model.WebColors -import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar -import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.dergoogler.mmrl.utils.MimeUtil -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootGraph -import com.ramcosta.composedestinations.navigation.DestinationsNavigator -import dev.chrisbanes.haze.hazeSource -import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults -import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior -import dev.mmrlx.compose.webui.WebUIView -import dev.mmrlx.compose.webui.insets -import dev.mmrlx.compose.webui.rememberWebUIState -import dev.mmrlx.webui.RouteRegistry -import dev.mmrlx.webui.RouteScope -import dev.mmrlx.webui.WebResourceResponse -import dev.mmrlx.webui.WebUIOptions -import java.net.HttpURLConnection -import java.net.URL - -@SuppressLint("SetJavaScriptEnabled", "JavascriptInterface") -@Composable -@Destination -fun ViewDescriptionScreen(readmeUrl: String) = - LocalScreenProvider { - val navigator = LocalDestinationsNavigator.current - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() - val userPrefs = LocalUserPreferences.current - val scheme = MaterialTheme.colorScheme - - val wstate = - rememberWebUIState( - "https://desc.mmrl.dev", - WebUIOptions("internal/assets/markdown.html") - ) { - it - .settings { - debug = BuildConfig.DEBUG - forceKillProcess = false - useConsoleInterceptor = false - darkMode = userPrefs.isDarkMode() - } - .client { - // not related to client - it.webview.setBackgroundColor(scheme.background.toArgb()) - } - .chromeClient { } - .registerRoutes { - val webColors = WebColors(scheme) - - internalRoute("readme.md") { - val connection = URL(readmeUrl).openConnection() as HttpURLConnection - connection.connect() - htmlResponse(connection.getInputStream()) - } - - internalRoute("insets.css") { - insets.css.asStyleResponse() - } - - internalRoute("colors.css") { - webColors.allCssColors.asStyleResponse() - } - - internalRoute("assets/*asset") { - val filePath = - request.params["asset"] ?: return@internalRoute notFoundResponse - - try { - val inputStream = kontext.assets.open(filePath) - val mimeType = MimeUtil.getMimeFromFileName(filePath) - response(mimeType = mimeType, data = inputStream) - } catch (e: Exception) { - console.error("Failed to open $filePath from the assets: $e") - notFoundResponse - } - } - } - } - - DisposableEffect(Unit) { - onDispose { - wstate.destroy() - } - } - - // We have to override otherwise the WebUI will close the entire app - BackHandler { - if (wstate.canGoBack()) { - wstate.goBack() - return@BackHandler - } - - navigator.popBackStack() - } - - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - scrollBehavior = scrollBehavior, - navigator = navigator, - ) - }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - val bottomBarPaddingValues = LocalMainScreenInnerPaddings.current - wstate.insets( - PaddingValues( - top = innerPadding.calculateTopPadding(), - bottom = bottomBarPaddingValues.calculateBottomPadding(), - ) - ) - - Column( - modifier = - Modifier - .fillMaxSize() - .hazeSource(LocalHazeState.current), - ) { - this@Scaffold.ResponsiveContent { - WebUIView(wstate) - } - } - } - } - -@Composable -private fun TopBar( - navigator: DestinationsNavigator, - scrollBehavior: ToolbarScrollBehavior, -) = BlurToolbar( - navigationIcon = { - IconButton(onClick = { navigator.popBackStack() }) { - Icon( - painter = painterResource(id = R.drawable.arrow_left), - contentDescription = null, - ) - } - }, - title = { Text(text = stringResource(id = R.string.view_module_about_this_module)) }, - scrollBehavior = scrollBehavior, -) - -private fun RouteRegistry.internalRoute( - name: String, - content: RouteScope.() -> WebResourceResponse, -) = route("internal/$name", content) \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt index 92dbf8484..4dd84f826 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt @@ -4,18 +4,9 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.width import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.SnackbarDuration -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableFloatStateOf -import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalUriHandler @@ -28,7 +19,6 @@ import com.dergoogler.mmrl.ext.shareText import com.dergoogler.mmrl.model.local.BulkModule import com.dergoogler.mmrl.model.online.isValid import com.dergoogler.mmrl.platform.content.isValid -import com.dergoogler.mmrl.ui.component.toolbar.BlurToolbar import com.dergoogler.mmrl.ui.providable.LocalBulkInstall import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalModule @@ -41,6 +31,9 @@ import com.dergoogler.mmrl.ui.providable.LocalVersionItem import com.dergoogler.mmrl.ui.screens.moduleView.items.VersionsItem import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton import kotlinx.coroutines.launch @OptIn(ExperimentalHazeMaterialsApi::class) @@ -61,24 +54,7 @@ internal fun Toolbar() { val scope = rememberCoroutineScope() - val state = scrollBehavior.state - - var alpha by remember { mutableFloatStateOf(0f) } - val fadeDistance = 200f - - LaunchedEffect(state) { - snapshotFlow { state.contentOffset } - .collect { offset -> - val newAlpha = ((-offset) / fadeDistance).coerceIn(0f, 1f) - - // Only update if it actually changes meaningfully - if ((newAlpha < 1f && newAlpha > 0f) || newAlpha != alpha) { - alpha = newAlpha - } - } - } - - BlurToolbar( + dev.mmrlx.compose.ui.toolbar.Toolbar( title = {}, navigationIcon = { IconButton(onClick = { navigator.popBackStack() }) { @@ -88,8 +64,6 @@ internal fun Toolbar() { ) } }, - fade = true, - fadeBackgroundIfNoBlur = true, scrollBehavior = scrollBehavior, actions = { VersionsItem( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesMenu.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesMenu.kt index a2e8c6fd7..78eeae984 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesMenu.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesMenu.kt @@ -8,11 +8,8 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -38,6 +35,9 @@ import com.dergoogler.mmrl.ui.component.Segment import com.dergoogler.mmrl.ui.component.SegmentedButtons import com.dergoogler.mmrl.ui.component.SegmentedButtonsDefaults import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.icon.IconButton @Composable fun ModulesMenu(setMenu: (ModulesMenu) -> Unit) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index cb41360b1..e66ca0773 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -20,12 +20,10 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource -import androidx.compose.ui.unit.dp import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R import com.dergoogler.mmrl.database.entity.Repo -import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.datastore.model.RepositoryMenu import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.none @@ -64,10 +62,6 @@ fun RepositoryScreen( val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() var coverHeight by remember { mutableIntStateOf(0) } - var cardHeight by remember { mutableIntStateOf(0) } - - val menu = userPreferences.repositoryMenu - val pad = remember(menu) { if (menu.repoListMode == RepoListMode.Compact) 0.dp else 16.dp } BackHandler(enabled = viewModel.isSearch, onBack = closeSearch) From f563294931a8c0ac4b1b4083f861c224a1c7da2f Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 25 Oct 2026 14:01:22 +0100 Subject: [PATCH 23/55] . --- .../mmrl/ui/component/AntiFeaturesItem.kt | 8 +- .../mmrl/ui/component/PermissionItem.kt | 12 +- .../screens/moduleView/DescriptionScreen.kt | 2 +- .../ui/screens/moduleView/NewViewScreen.kt | 163 +++++++++--------- .../moduleView/sections/AboutModule.kt | 14 +- .../ui/screens/moduleView/sections/Header.kt | 31 ++-- .../moduleView/sections/Information.kt | 14 +- .../moduleView/sections/Information0.kt | 139 ++++++++------- .../sections/{Toolbar.kt => Toolbar0.kt} | 2 +- .../mmrl/viewmodel/RepositoryViewModel.kt | 3 +- 10 files changed, 200 insertions(+), 188 deletions(-) rename app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/{Toolbar.kt => Toolbar0.kt} (99%) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt index 476e6c6c6..db46d0ce7 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt @@ -3,10 +3,10 @@ package com.dergoogler.mmrl.ui.component import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Title @Composable fun ListScope.AntiFeaturesItem( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt index 785cb31cd..c65d61aef 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt @@ -6,11 +6,11 @@ import androidx.compose.foundation.layout.RowScope import androidx.compose.runtime.Composable import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListScope -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title +import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Supporting +import dev.mmrlx.compose.ui.list.component.item.Title @Composable fun ListScope.PermissionItem( @@ -25,7 +25,7 @@ fun ListScope.PermissionItem( Title(p.title) Description(p.desc) p.rootSolutions.nullable { - Labels { + Supporting { it() } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt index fd97cbaa2..5a407934e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt @@ -45,7 +45,7 @@ import java.net.URL @Destination fun DescriptionScreen(readmeUrl: String) { val navigator = LocalDestinationsNavigator.current - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() val userPrefs = LocalUserPreferences.current val colors = MMRLXTheme.colors diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index 0b2680d2f..4f7749f20 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -6,13 +6,10 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable @@ -36,7 +33,6 @@ import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.ifNotEmpty import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.ext.systemBarsPaddingEnd import com.dergoogler.mmrl.model.local.BulkModule import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.online.VersionItem @@ -44,11 +40,9 @@ import com.dergoogler.mmrl.model.online.isBlacklisted import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold import com.dergoogler.mmrl.ui.providable.LocalBulkInstall import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalHazeState -import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalRepo @@ -67,11 +61,14 @@ import com.dergoogler.mmrl.ui.screens.moduleView.sections.Header import com.dergoogler.mmrl.ui.screens.moduleView.sections.Information import com.dergoogler.mmrl.ui.screens.moduleView.sections.Information0 import com.dergoogler.mmrl.ui.screens.moduleView.sections.Screenshots -import com.dergoogler.mmrl.ui.screens.moduleView.sections.Toolbar +import com.dergoogler.mmrl.ui.screens.moduleView.sections.Toolbar0 import com.dergoogler.mmrl.viewmodel.ModuleViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.HorizontalDivider +import dev.mmrlx.compose.ui.LinearProgressIndicator +import dev.mmrlx.compose.ui.ext.with +import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import timber.log.Timber @@ -218,98 +215,94 @@ fun NewViewScreen( Scaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), snackbarHost = { SnackbarHost(snackbarHostState) }, - topBar = { - Toolbar() + toolbar = { + Toolbar0() }, contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - this@Scaffold.ResponsiveContent { - Column( - modifier = - Modifier - .let { - if (repositoryMenu.showCover && module.hasCover) { - Modifier - } else { - it.padding(innerPadding) - } - }.verticalScroll(rememberScrollState()) - .hazeSource(state = hazeState), - ) { - module.cover.nullable(repositoryMenu.showCover) { - if (it.isNotEmpty()) { - Cover( - modifier = - Modifier.fadingEdge( - Brush.verticalGradient( - colors = - listOf( - Color.Transparent, - Color.Black, - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), - ), - url = it, - ) - } - } - - Column( - modifier = - Modifier - .systemBarsPaddingEnd(), - ) { - Spacer(modifier = Modifier.height(16.dp)) + ) { + val scope = this - Header() - - val progress = - lastVersionItem?.let { - viewModel.getProgress(it) - } ?: 0f - - if (progress != 0f) { - LinearProgressIndicator( - progress = { progress }, - strokeCap = StrokeCap.Round, - modifier = - Modifier - .padding(vertical = 16.dp) - .height(0.9.dp) - .fillMaxWidth(), - ) - } else { - HorizontalDivider( - modifier = Modifier.padding(vertical = 16.dp), - thickness = 0.9.dp, - ) + Column( + modifier = + Modifier + .verticalScroll(rememberScrollState()) + .scaffoldHazeSource() + .let { + if (repositoryMenu.showCover && module.hasCover) { + it + } else { + it.padding(top = scaffoldTopPadding) + } } + ) { + module.cover.nullable(repositoryMenu.showCover) { + if (it.isNotEmpty()) { + Cover( + modifier = + Modifier.fadingEdge( + Brush.verticalGradient( + colors = + listOf( + Color.Transparent, + Color.Black, + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, + ), + ), + url = it, + ) + } + } - Alerts() - - AboutModule() - - Screenshots() + Column( + modifier = Modifier.with(scope) { + it.scaffoldBottomPadding() + } + ) { + Spacer(modifier = Modifier.height(16.dp)) - Spacer(modifier = Modifier.height(16.dp)) + Header() - Information0() + val progress = + lastVersionItem?.let { + viewModel.getProgress(it) + } ?: 0f - // Information section + if (progress != 0f) { + LinearProgressIndicator( + progress = { progress }, + strokeCap = StrokeCap.Round, + modifier = + Modifier + .padding(vertical = 16.dp) + .height(0.9.dp) + .fillMaxWidth(), + ) + } else { HorizontalDivider( modifier = Modifier.padding(vertical = 16.dp), thickness = 0.9.dp, ) + } - Information() + Alerts() - Spacer(modifier = Modifier.navigationBarsPadding()) + AboutModule() - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } + Screenshots() + + Spacer(modifier = Modifier.height(16.dp)) + + Information0() + + // Information section + HorizontalDivider( + modifier = Modifier.padding(vertical = 16.dp), + thickness = 0.9.dp, + ) + + Information() } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt index 3c593a474..fcb4b7986 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt @@ -10,7 +10,6 @@ import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.AssistChip import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -19,17 +18,18 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.model.online.hasCategories -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListItemSlot -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.screens.moduleView.listItemContentPaddingValues import com.ramcosta.composedestinations.generated.destinations.DescriptionScreenDestination +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListItemSlot +import dev.mmrlx.compose.ui.list.component.ButtonItem +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Title @Composable internal fun AboutModule() { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt index dea019632..453b6bdb3 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt @@ -15,7 +15,6 @@ import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedButton -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember @@ -23,19 +22,18 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.isNotNullOrBlank -import com.dergoogler.mmrl.ext.nullable import com.dergoogler.mmrl.model.local.State import com.dergoogler.mmrl.model.online.isBlacklisted import com.dergoogler.mmrl.platform.content.LocalModule.Companion.isEmpty import com.dergoogler.mmrl.platform.content.isValid import com.dergoogler.mmrl.ui.component.Logo -import com.dergoogler.mmrl.ui.component.text.IconText import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModule @@ -43,6 +41,10 @@ import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.providable.LocalVersionItem import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.text.FormatText +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable internal fun Header() { @@ -88,15 +90,22 @@ internal fun Header() { Column( modifier = Modifier.weight(1f), ) { - IconText( - style = MaterialTheme.typography.titleLarge, - tint = MaterialTheme.colorScheme.surfaceTint, - alignment = Alignment.End, + FormatText( + style = MMRLXTheme.typography.titleMedium, + text = module.name + if (module.isVerified) " %y" else "", maxLines = 2, overflow = TextOverflow.Ellipsis, - text = module.name, - resId = module.isVerified nullable R.drawable.rosette_discount_check, - ) + ) { + if (module.isVerified) { + composable { + Icon( + tint = MaterialTheme.colorScheme.surfaceTint, + modifier = Modifier.size(fontSize.dp), + painter = painterResource(id = R.drawable.rosette_discount_check), + ) + } + } + } Spacer(modifier = Modifier.height(4.dp)) @@ -144,7 +153,7 @@ internal fun Header() { OutlinedButton( enabled = viewModel.isProviderAlive && - (!userPreferences.useShellForModuleStateChange || it.state != com.dergoogler.mmrl.model.local.State.REMOVE), + (!userPreferences.useShellForModuleStateChange || it.state != com.dergoogler.mmrl.model.local.State.REMOVE), modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt index 94ef5eda7..2c8fa0fb1 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.graphicsLayer @@ -22,11 +21,6 @@ import com.dergoogler.mmrl.ext.takeTrue import com.dergoogler.mmrl.model.online.isValid import com.dergoogler.mmrl.platform.content.isValid import com.dergoogler.mmrl.platform.file.SuFile.Companion.toFormattedFileSize -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListItemSlot -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.CollapseItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalUserPreferences @@ -34,6 +28,12 @@ import com.dergoogler.mmrl.ui.providable.LocalVersionItem import com.dergoogler.mmrl.ui.screens.moduleView.items.LicenseItem import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel import com.dergoogler.mmrl.utils.toFormattedDateSafely +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListItemSlot +import dev.mmrlx.compose.ui.list.component.CollapseItem +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Title @Composable internal fun Information() { @@ -162,7 +162,7 @@ internal fun Information() { ), ) { CollapseItem( - meta = { icon, rotation -> + first = { icon, rotation -> Title( id = R.string.module_installed, styleTransform = { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt index 27b61f48e..54d7a3bff 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt @@ -12,21 +12,21 @@ import com.dergoogler.mmrl.ext.ifNotNullOrBlank import com.dergoogler.mmrl.ui.component.AntiFeaturesItem import com.dergoogler.mmrl.ui.component.LabelItem import com.dergoogler.mmrl.ui.component.PermissionItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.ListItemSlot -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.CollapseItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Description -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Labels -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.screens.moduleView.items.OtherSourcesItem import com.dergoogler.mmrl.ui.screens.moduleView.listItemContentPaddingValues import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalRequireModules import com.dergoogler.mmrl.ui.screens.moduleView.subListItemContentPaddingValues +import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListItemSlot +import dev.mmrlx.compose.ui.list.component.ButtonItem +import dev.mmrlx.compose.ui.list.component.CollapseItem +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Description +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Supporting +import dev.mmrlx.compose.ui.list.component.item.Title @Composable internal fun Information0() { @@ -39,7 +39,7 @@ internal fun Information0() { contentPadding = listItemContentPaddingValues, ) { CollapseItem( - meta = { icon, rotation -> + first = { icon, rotation -> Title(R.string.view_module_module_support) Icon( slot = ListItemSlot.End, @@ -50,57 +50,57 @@ internal fun Information0() { ) }, ) { - module.donate.ifNotNullOrBlank { - ButtonItem( - contentPadding = subListItemContentPaddingValues, - onClick = { - browser.openUri(it) - }, - ) { - Icon(painter = painterResource(id = R.drawable.currency_dollar)) - Title(R.string.view_module_donate) - Description(R.string.view_module_donate_desc) - } - } - - ButtonItem( + List( contentPadding = subListItemContentPaddingValues, - onClick = { - browser.openUri(module.track.source) - }, ) { - Icon(painter = painterResource(id = R.drawable.brand_git)) - Title(R.string.view_module_source) - } + module.donate.ifNotNullOrBlank { + ButtonItem( + onClick = { + browser.openUri(it) + }, + ) { + Icon(painter = painterResource(id = R.drawable.currency_dollar)) + Title(R.string.view_module_donate) + Description(R.string.view_module_donate_desc) + } + } - module.homepage.ifNotNullOrBlank { ButtonItem( - contentPadding = subListItemContentPaddingValues, onClick = { - browser.openUri(it) + browser.openUri(module.track.source) }, ) { - Icon(painter = painterResource(id = R.drawable.world_www)) - Title(R.string.view_module_homepage) + Icon(painter = painterResource(id = R.drawable.brand_git)) + Title(R.string.view_module_source) } - } - module.support?.ifNotNullOrBlank { - ButtonItem( - contentPadding = subListItemContentPaddingValues, - onClick = { - browser.openUri(it) - }, - ) { - Icon(painter = painterResource(id = R.drawable.heart_handshake)) - Title(R.string.view_module_support) + module.homepage.ifNotNullOrBlank { + ButtonItem( + onClick = { + browser.openUri(it) + }, + ) { + Icon(painter = painterResource(id = R.drawable.world_www)) + Title(R.string.view_module_homepage) + } + } + + module.support?.ifNotNullOrBlank { + ButtonItem( + onClick = { + browser.openUri(it) + }, + ) { + Icon(painter = painterResource(id = R.drawable.heart_handshake)) + Title(R.string.view_module_support) + } } } } module.permissions.ifNotEmpty { CollapseItem( - meta = { icon, rotation -> + first = { icon, rotation -> Title(R.string.view_module_permissions) Icon( slot = ListItemSlot.End, @@ -109,7 +109,7 @@ internal fun Information0() { .graphicsLayer(rotationZ = rotation), painter = painterResource(id = icon), ) - Labels { + Supporting { LabelItem( text = stringResource( @@ -120,16 +120,20 @@ internal fun Information0() { } }, ) { - PermissionItem( + List( contentPadding = subListItemContentPaddingValues, - permissions = it, - ) + ) { + PermissionItem( + contentPadding = subListItemContentPaddingValues, + permissions = it, + ) + } } } module.track.antifeatures.ifNotEmpty { CollapseItem( - meta = { icon, rotation -> + first = { icon, rotation -> Title(R.string.view_module_antifeatures) Icon( slot = ListItemSlot.End, @@ -138,7 +142,7 @@ internal fun Information0() { .graphicsLayer(rotationZ = rotation), painter = painterResource(id = icon), ) - Labels { + Supporting { LabelItem( text = stringResource( @@ -149,16 +153,20 @@ internal fun Information0() { } }, ) { - AntiFeaturesItem( + List( contentPadding = subListItemContentPaddingValues, - antifeatures = it, - ) + ) { + AntiFeaturesItem( + contentPadding = subListItemContentPaddingValues, + antifeatures = it, + ) + } } } requires.ifNotEmpty { requiredIds -> CollapseItem( - meta = { icon, rotation -> + first = { icon, rotation -> Title(R.string.view_module_dependencies) Icon( slot = ListItemSlot.End, @@ -167,7 +175,7 @@ internal fun Information0() { .graphicsLayer(rotationZ = rotation), painter = painterResource(id = icon), ) - Labels { + Supporting { LabelItem( text = stringResource( @@ -178,13 +186,16 @@ internal fun Information0() { } }, ) { - requiredIds.forEach { onlineModule -> - ButtonItem( - contentPadding = subListItemContentPaddingValues, - onClick = {}, - ) { - Title(onlineModule.name) - Description(onlineModule.versionCode.toString()) + List( + contentPadding = subListItemContentPaddingValues, + ) { + requiredIds.forEach { onlineModule -> + ButtonItem( + onClick = {}, + ) { + Title(onlineModule.name) + Description(onlineModule.versionCode.toString()) + } } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar0.kt similarity index 99% rename from app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt rename to app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar0.kt index 4dd84f826..17aa0ee6e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Toolbar0.kt @@ -38,7 +38,7 @@ import kotlinx.coroutines.launch @OptIn(ExperimentalHazeMaterialsApi::class) @Composable -internal fun Toolbar() { +internal fun Toolbar0() { val context = LocalContext.current val viewModel = LocalModuleViewModel.current val repo = LocalRepo.current diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt index 371cb1c53..094be327b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt @@ -6,7 +6,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewModelScope import com.dergoogler.mmrl.database.entity.Repo import com.dergoogler.mmrl.datastore.UserPreferencesRepository @@ -205,7 +204,7 @@ constructor( companion object { @Composable fun build(repo: Repo): RepositoryViewModel = - hiltViewModel { factory -> + androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> factory.create(repo) } } From 4c5838e3bd601701f6077c6eacc16bf89cd7ec39 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:19:15 +0100 Subject: [PATCH 24/55] . --- .../mmrl/ui/screens/moduleView/DescriptionScreen.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt index 5a407934e..8da2090a8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt @@ -4,14 +4,17 @@ import androidx.activity.compose.BackHandler import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.navigationBars import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.none @@ -45,7 +48,7 @@ import java.net.URL @Destination fun DescriptionScreen(readmeUrl: String) { val navigator = LocalDestinationsNavigator.current - val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val userPrefs = LocalUserPreferences.current val colors = MMRLXTheme.colors @@ -135,7 +138,7 @@ fun DescriptionScreen(readmeUrl: String) { wstate.insets( PaddingValues( top = contentPadding.calculateTopPadding(), - bottom = contentPadding.calculateBottomPadding(), + bottom = with(LocalDensity.current) { WindowInsets.navigationBars.getBottom(this).dp }, ) ) From f7612517423c2537f1b22c8216fcc64d153910e9 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:30:05 +0100 Subject: [PATCH 25/55] . --- .../mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt | 10 +++++----- .../mmrl/ui/component/toolbar/BlurSearchToolbar.kt | 2 +- .../mmrl/ui/component/toolbar/BlurToolbar.kt | 2 +- .../mmrl/ui/screens/moduleView/NewViewScreen.kt | 3 +++ .../mmrl/ui/screens/repository/RepositoryScreen.kt | 10 ++++++---- .../dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt | 10 +++++----- gradle/libs.versions.toml | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt index 055f6fee9..5f025444f 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurNavigateUpToolbar.kt @@ -29,7 +29,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -57,7 +57,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -85,7 +85,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -113,7 +113,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = TopAppBarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, @@ -141,7 +141,7 @@ fun BlurNavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, fade: Boolean = false, fadeDistance: Float = 200f, fadeBackgroundIfNoBlur: Boolean = false, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt index 8c8db2382..ddb5741ae 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurSearchToolbar.kt @@ -41,7 +41,7 @@ fun BlurSearchToolbar( navigationIcon: @Composable () -> Unit = {}, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, ) = Toolbar( modifier = modifier, actions = actions, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt index e446e90f6..95b415f11 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/toolbar/BlurToolbar.kt @@ -118,7 +118,7 @@ fun BlurToolbar( fadeBackgroundIfNoBlur: Boolean = false, fadeDistance: Float = 200f, fade: Boolean = false, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, state: BlurToolbarState = rememberBlurToolbarState( scrollBehavior = scrollBehavior, fade = fade, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index 4f7749f20..c92863204 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -67,6 +67,7 @@ import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.mmrlx.compose.ui.HorizontalDivider import dev.mmrlx.compose.ui.LinearProgressIndicator +import dev.mmrlx.compose.ui.NavigationBarsSpacer import dev.mmrlx.compose.ui.ext.with import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults @@ -304,6 +305,8 @@ fun NewViewScreen( Information() } + + NavigationBarsSpacer() } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index e66ca0773..c826f4a08 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -16,6 +16,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity @@ -41,6 +42,7 @@ import dev.mmrlx.compose.ui.icon.IconButton import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior +import dev.mmrlx.compose.ui.toolbar.ToolbarTitle @Destination @Composable @@ -257,10 +259,10 @@ private fun TopBar0( currentQuery = "" }, title = { -// ToolbarTitle( -// title = repo.name, -// modifier = Modifier.graphicsLayer { alpha = scrollBehavior.fadeDistance }, -// ) + ToolbarTitle( + title = repo.name, + modifier = Modifier.graphicsLayer { alpha = scrollBehavior.state.fade }, + ) }, actions = { if (!isSearch) { diff --git a/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt b/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt index 3675c15aa..dcc1e2b96 100644 --- a/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt +++ b/app/src/main/kotlin/dev/mmrlx/compose/ui/toolbar/NavigateUpToolbar.kt @@ -23,7 +23,7 @@ fun NavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, ) = NavigateUpToolbar( modifier = modifier, title = title, @@ -44,7 +44,7 @@ fun NavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, ) = NavigateUpToolbar( modifier = modifier, title = title, @@ -65,7 +65,7 @@ fun NavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, ) = NavigateUpToolbar( modifier = modifier, title = title, @@ -86,7 +86,7 @@ fun NavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, ) = NavigateUpToolbar( modifier = modifier, title = { @@ -107,7 +107,7 @@ fun NavigateUpToolbar( enable: Boolean = true, actions: @Composable RowScope.() -> Unit = {}, windowInsets: WindowInsets = ToolbarDefaults.windowInsets, - scrollBehavior: ToolbarScrollBehavior? = null, + scrollBehavior: ToolbarScrollBehavior = ToolbarScrollBehavior.Empty, ) = Toolbar( title = title, modifier = modifier, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0b03d2734..122f366ea 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.231" +mmrlx = "1.0.232" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 04e5e0e3a5895a67c0a7caeebc7900514c8db353 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 1 Nov 2026 13:51:56 +0100 Subject: [PATCH 26/55] Batch-load versions per repo to speed up listing Add JoinDao.getVersionsByRepoUrl and LocalRepository.getVersionsByRepoUrl so getOnlineAllByUrlAsFlow loads all versions for a repo in one query and groups them by module ID, instead of querying per module. VersionItem gains a moduleId field, set from VersionItemEntity.toItem() and when loading update.json versions. In RepositoryViewModel, isLoading is now a StateFlow, the module flow runs on Dispatchers.IO and resets loading on start, and the sort and filter code is condensed. LocalRepository was also reformatted (indentation only). --- .../dergoogler/mmrl/database/dao/JoinDao.kt | 3 + .../mmrl/database/entity/Version.kt | 1 + .../mmrl/model/online/VersionItem.kt | 4 +- .../mmrl/repository/LocalRepository.kt | 382 +++++++++--------- .../mmrl/viewmodel/ModuleViewModel.kt | 1 + .../mmrl/viewmodel/RepositoryViewModel.kt | 84 ++-- 6 files changed, 237 insertions(+), 238 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt b/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt index 8cc56b878..dc2496fa2 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt @@ -62,4 +62,7 @@ interface JoinDao { repoUrl: String, version: Int = ModulesJson.CURRENT_VERSION, ): List + + @Query("SELECT * FROM versions WHERE repoUrl = :repoUrl") + fun getVersionsByRepoUrl(repoUrl: String): List } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/database/entity/Version.kt b/app/src/main/kotlin/com/dergoogler/mmrl/database/entity/Version.kt index 1804092bb..8f2a1000b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/database/entity/Version.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/database/entity/Version.kt @@ -29,6 +29,7 @@ data class VersionItemEntity( fun toItem() = VersionItem( + moduleId = id, repoUrl = repoUrl, timestamp = timestamp, version = version, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/model/online/VersionItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/model/online/VersionItem.kt index 6f53c197c..f2175d083 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/model/online/VersionItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/model/online/VersionItem.kt @@ -11,6 +11,7 @@ import kotlin.contracts.contract @Serializable @JsonClass(generateAdapter = true) data class VersionItem( + var moduleId: String = "", @Json(ignore = true) val repoUrl: String = "", val timestamp: Float, val version: String, @@ -25,7 +26,8 @@ data class VersionItem( val isEmpty get() = this == EMPTY companion object { - val EMPTY = VersionItem(timestamp = 0f, version = "", versionCode = 0, zipUrl = "") + val EMPTY = + VersionItem(moduleId = "", timestamp = 0f, version = "", versionCode = 0, zipUrl = "") } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt b/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt index b7d7f5f87..62a27d472 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt @@ -17,6 +17,7 @@ import com.dergoogler.mmrl.model.local.LocalModule import com.dergoogler.mmrl.model.online.Blacklist import com.dergoogler.mmrl.model.online.OnlineModule import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.withContext import javax.inject.Inject @@ -24,233 +25,240 @@ import javax.inject.Singleton @Singleton class LocalRepository - @Inject - constructor( - private val repoDao: RepoDao, - private val onlineDao: OnlineDao, - private val versionDao: VersionDao, - private val localDao: LocalDao, - private val joinDao: JoinDao, - private val blacklistDao: BlacklistDao, - ) { - fun getLocalAllAsFlow() = - localDao.getAllAsFlow().map { list -> - list.map { it.toModule() } - } +@Inject +constructor( + private val repoDao: RepoDao, + private val onlineDao: OnlineDao, + private val versionDao: VersionDao, + private val localDao: LocalDao, + private val joinDao: JoinDao, + private val blacklistDao: BlacklistDao, +) { + fun getLocalAllAsFlow() = + localDao.getAllAsFlow().map { list -> + list.map { it.toModule() } + } - fun getLocalAll() = localDao.getAll() + fun getLocalAll() = localDao.getAll() - fun getLocalByIdOrNullAsFlow(id: String) = - localDao.getByIdOrNullAsFlow(id).map { - it?.toModule() - } + fun getLocalByIdOrNullAsFlow(id: String) = + localDao.getByIdOrNullAsFlow(id).map { + it?.toModule() + } - suspend fun getLocalByIdOrNull(id: String) = - withContext(Dispatchers.IO) { - localDao.getByIdOrNull(id)?.toModule() - } + suspend fun getLocalByIdOrNull(id: String) = + withContext(Dispatchers.IO) { + localDao.getByIdOrNull(id)?.toModule() + } - suspend fun insertLocal(value: LocalModule) = - withContext(Dispatchers.IO) { - localDao.insert(LocalModuleEntity(value)) - } + suspend fun insertLocal(value: LocalModule) = + withContext(Dispatchers.IO) { + localDao.insert(LocalModuleEntity(value)) + } - suspend fun insertBlacklist(value: Blacklist) = - withContext(Dispatchers.IO) { - blacklistDao.insert(BlacklistEntity(value)) - } + suspend fun insertBlacklist(value: Blacklist) = + withContext(Dispatchers.IO) { + blacklistDao.insert(BlacklistEntity(value)) + } - suspend fun deleteBlacklistById(id: String) = - withContext(Dispatchers.IO) { - blacklistDao.deleteById(id) - } + suspend fun deleteBlacklistById(id: String) = + withContext(Dispatchers.IO) { + blacklistDao.deleteById(id) + } - suspend fun getBlacklistById(id: String) = - withContext(Dispatchers.IO) { - blacklistDao.getBlacklistEntry(id)?.toBlacklist() - } + suspend fun getBlacklistById(id: String) = + withContext(Dispatchers.IO) { + blacklistDao.getBlacklistEntry(id)?.toBlacklist() + } - fun getBlacklistByIdOrNullAsFlow(id: String) = - blacklistDao.getBlacklistEntryAsFlow(id).map { - it?.toBlacklist() - } + fun getBlacklistByIdOrNullAsFlow(id: String) = + blacklistDao.getBlacklistEntryAsFlow(id).map { + it?.toBlacklist() + } - fun getAllBlacklistEntriesAsFlow() = - blacklistDao.getAllBlacklistEntriesAsFlow().map { - it.map { entity -> entity.toBlacklist() } - } + fun getAllBlacklistEntriesAsFlow() = + blacklistDao.getAllBlacklistEntriesAsFlow().map { + it.map { entity -> entity.toBlacklist() } + } - suspend fun insertLocal(list: List) = - withContext(Dispatchers.IO) { - localDao.insert(list.map { LocalModuleEntity(it) }) - } + suspend fun insertLocal(list: List) = + withContext(Dispatchers.IO) { + localDao.insert(list.map { LocalModuleEntity(it) }) + } - suspend fun deleteLocalAll() = - withContext(Dispatchers.IO) { - localDao.deleteAll() - } + suspend fun deleteLocalAll() = + withContext(Dispatchers.IO) { + localDao.deleteAll() + } - suspend fun insertUpdatableTag( - id: String, - updatable: Boolean, - ) = withContext(Dispatchers.IO) { - localDao.insertUpdatableTag( - LocalModuleUpdatable( - id = id, - updatable = updatable, - ), - ) + suspend fun insertUpdatableTag( + id: String, + updatable: Boolean, + ) = withContext(Dispatchers.IO) { + localDao.insertUpdatableTag( + LocalModuleUpdatable( + id = id, + updatable = updatable, + ), + ) + } + + suspend fun hasUpdatableTag(id: String) = + withContext(Dispatchers.IO) { + localDao.hasUpdatableTagOrNull(id)?.updatable != false } - suspend fun hasUpdatableTag(id: String) = - withContext(Dispatchers.IO) { - localDao.hasUpdatableTagOrNull(id)?.updatable != false - } + suspend fun clearUpdatableTag(new: List) = + withContext(Dispatchers.IO) { + val removed = localDao.getUpdatableTagAll().filter { it.id !in new } + localDao.deleteUpdatableTag(removed) + } - suspend fun clearUpdatableTag(new: List) = - withContext(Dispatchers.IO) { - val removed = localDao.getUpdatableTagAll().filter { it.id !in new } - localDao.deleteUpdatableTag(removed) - } + fun getRepoAllAsFlow() = repoDao.getAllAsFlow() - fun getRepoAllAsFlow() = repoDao.getAllAsFlow() + suspend fun getRepoAll() = + withContext(Dispatchers.IO) { + repoDao.getAll() + } - suspend fun getRepoAll() = - withContext(Dispatchers.IO) { - repoDao.getAll() - } + suspend fun getRepoByUrl(url: String) = + withContext(Dispatchers.IO) { + repoDao.getByUrl(url) + } - suspend fun getRepoByUrl(url: String) = - withContext(Dispatchers.IO) { - repoDao.getByUrl(url) - } + fun getRepoByUrlAsFlow(url: String) = repoDao.getByUrlAsFlow(url) - fun getRepoByUrlAsFlow(url: String) = repoDao.getByUrlAsFlow(url) + suspend fun insertRepo(value: Repo) = + withContext(Dispatchers.IO) { + repoDao.insert(value) + } - suspend fun insertRepo(value: Repo) = - withContext(Dispatchers.IO) { - repoDao.insert(value) - } + suspend fun deleteRepo(value: Repo) = + withContext(Dispatchers.IO) { + repoDao.delete(value) + } - suspend fun deleteRepo(value: Repo) = - withContext(Dispatchers.IO) { - repoDao.delete(value) + fun getOnlineAllAsFlow(duplicates: Boolean = false) = + joinDao.getOnlineAllAsFlow().map { list -> + if (duplicates) { + return@map list.map { it.toModule().copy(versions = getVersionById(it.id)) } } - fun getOnlineAllAsFlow(duplicates: Boolean = false) = - joinDao.getOnlineAllAsFlow().map { list -> - if (duplicates) { - return@map list.map { it.toModule().copy(versions = getVersionById(it.id)) } - } + val values = mutableListOf() + list.forEach { entity -> + val new = entity.toModule() - val values = mutableListOf() - list.forEach { entity -> - val new = entity.toModule() - - if (new in values) { - val old = values.first { it.id == new.id } - if (new.versionCode > old.versionCode) { - values.remove(old) - values.add(new.copy(versions = old.versions)) - } - } else { - values.add( - new.copy(versions = getVersionById(new.id)), - ) + if (new in values) { + val old = values.first { it.id == new.id } + if (new.versionCode > old.versionCode) { + values.remove(old) + values.add(new.copy(versions = old.versions)) } + } else { + values.add( + new.copy(versions = getVersionById(new.id)), + ) } - values } + values + } - fun getOnlineAllByUrlAsFlow(repoUrl: String) = - joinDao.getOnlineAllByUrlAsFlow(repoUrl).map { list -> - val values = mutableListOf() - list.forEach { entity -> - val new = entity.toModule() - - if (new in values) { - val old = values.first { it.id == new.id } - if (new.versionCode > old.versionCode) { - values.remove(old) - values.add(new.copy(versions = old.versions)) - } - } else { - values.add( - new.copy(versions = getVersionByIdAndUrl(new.id, repoUrl)), - ) + fun getOnlineAllByUrlAsFlow(repoUrl: String): Flow> = + joinDao.getOnlineAllByUrlAsFlow(repoUrl).map { entityList -> + val allVersions = getVersionsByRepoUrl(repoUrl) + val versionsByModuleId = allVersions.groupBy { it.moduleId } + val valuesMap = linkedMapOf() + + entityList.forEach { entity -> + val new = entity.toModule() + val existing = valuesMap[new.id] + + if (existing != null) { + if (new.versionCode > existing.versionCode) { + valuesMap[new.id] = new.copy(versions = existing.versions) } + } else { + val matchedVersions = versionsByModuleId[new.id] ?: emptyList() + valuesMap[new.id] = new.copy(versions = matchedVersions) } - - return@map values } - suspend fun getOnlineByIdAndUrl( - id: String, - repoUrl: String, - ) = withContext(Dispatchers.IO) { - joinDao.getOnlineByIdAndUrl(id, repoUrl).toModule(getVersionByIdAndUrl(id, repoUrl)) + return@map valuesMap.values.toList() } - suspend fun getOnlineAllById(id: String) = - withContext(Dispatchers.IO) { - onlineDao.getAllById(id).map { it.toModule(getVersionById(it.id)) } - } - - suspend fun getOnlineAllByUrl(url: String) = - withContext(Dispatchers.IO) { - onlineDao.getAllByUrl(url).map { it.toModule(getVersionByIdAndUrl(it.id, url)) } - } + suspend fun getOnlineByIdAndUrl( + id: String, + repoUrl: String, + ) = withContext(Dispatchers.IO) { + joinDao.getOnlineByIdAndUrl(id, repoUrl).toModule(getVersionByIdAndUrl(id, repoUrl)) + } - suspend fun getOnlineAllByIdAndUrl( - id: String, - repoUrl: String, - ) = withContext(Dispatchers.IO) { - onlineDao.getAllByIdAndUrl(id, repoUrl).map { it.toModule() } + suspend fun getOnlineAllById(id: String) = + withContext(Dispatchers.IO) { + onlineDao.getAllById(id).map { it.toModule(getVersionById(it.id)) } } - suspend fun insertOnline( - list: List, - repoUrl: String, - ) = withContext(Dispatchers.IO) { - val versions = - list - .map { module -> - module.versions.map { - VersionItemEntity( - original = it, - id = module.id, - repoUrl = repoUrl, - ) - } - }.merge() - - versionDao.insert(versions) - onlineDao.insert( - list.map { - OnlineModuleEntity( - original = it, - repoUrl = repoUrl, - blacklist = getBlacklistById(it.id) ?: Blacklist.EMPTY, - ) - }, - ) + suspend fun getOnlineAllByUrl(url: String) = + withContext(Dispatchers.IO) { + onlineDao.getAllByUrl(url).map { it.toModule(getVersionByIdAndUrl(it.id, url)) } } - suspend fun deleteOnlineByUrl(repoUrl: String) = - withContext(Dispatchers.IO) { - versionDao.deleteByUrl(repoUrl) - onlineDao.deleteByUrl(repoUrl) - } + suspend fun getOnlineAllByIdAndUrl( + id: String, + repoUrl: String, + ) = withContext(Dispatchers.IO) { + onlineDao.getAllByIdAndUrl(id, repoUrl).map { it.toModule() } + } - suspend fun getVersionById(id: String) = - withContext(Dispatchers.IO) { - joinDao.getVersionById(id).map { it.toItem() } - } + suspend fun insertOnline( + list: List, + repoUrl: String, + ) = withContext(Dispatchers.IO) { + val versions = + list + .map { module -> + module.versions.map { + VersionItemEntity( + original = it, + id = module.id, + repoUrl = repoUrl, + ) + } + }.merge() + + versionDao.insert(versions) + onlineDao.insert( + list.map { + OnlineModuleEntity( + original = it, + repoUrl = repoUrl, + blacklist = getBlacklistById(it.id) ?: Blacklist.EMPTY, + ) + }, + ) + } + + suspend fun deleteOnlineByUrl(repoUrl: String) = + withContext(Dispatchers.IO) { + versionDao.deleteByUrl(repoUrl) + onlineDao.deleteByUrl(repoUrl) + } - suspend fun getVersionByIdAndUrl( - id: String, - repoUrl: String, - ) = withContext(Dispatchers.IO) { - joinDao.getVersionByIdAndUrl(id, repoUrl).map { it.toItem() } + suspend fun getVersionById(id: String) = + withContext(Dispatchers.IO) { + joinDao.getVersionById(id).map { it.toItem() } } + + suspend fun getVersionByIdAndUrl( + id: String, + repoUrl: String, + ) = withContext(Dispatchers.IO) { + joinDao.getVersionByIdAndUrl(id, repoUrl).map { it.toItem() } + } + + suspend fun getVersionsByRepoUrl( + repoUrl: String, + ) = withContext(Dispatchers.IO) { + joinDao.getVersionsByRepoUrl(repoUrl).map { it.toItem() } } +} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt index 434401884..b2707e674 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt @@ -176,6 +176,7 @@ class ModuleViewModel if (installed) { UpdateJson.loadToVersionItem(local!!.updateJson)?.let { + it.moduleId = module.id versions.add(0, UPDATE_JSON.toRepo() to it) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt index 094be327b..ef095f272 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt @@ -21,12 +21,15 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -56,8 +59,8 @@ constructor( var isSearch by mutableStateOf(false) private set - var isLoading by mutableStateOf(true) - private set + private val _isLoading = MutableStateFlow(true) + val isLoading: StateFlow = _isLoading.asStateFlow() private val onlineModules = if (repo.url.isNotBlank()) { @@ -74,11 +77,11 @@ constructor( ) { modules, menu, key -> val source = modules.map { module -> val local = localRepository.getLocalByIdOrNull(module.id) - val versions = module.versions.toMutableList() if (local != null) { UpdateJson.loadToVersionItem(local.updateJson)?.let { + it.moduleId = module.id versions.add(0, it) } } @@ -94,58 +97,44 @@ constructor( val sorted = source .sortedWith(comparator(menu.option, menu.descending)) .let { list -> - if (menu.pinInstalled) { - list.sortedByDescending { it.first.installed } - } else { - list - } + if (menu.pinInstalled) list.sortedByDescending { it.first.installed } else list } .let { list -> - if (menu.pinUpdatable) { - list.sortedByDescending { it.first.updatable } - } else { - list - } + if (menu.pinUpdatable) list.sortedByDescending { it.first.updatable } else list } - isLoading = false + _isLoading.value = false if (key.isBlank()) { sorted } else { val (searchKey, prefix) = parseSearchKey(key) - sorted.filter { (_, module) -> when (prefix) { - "id" -> - module.id.equals(searchKey, ignoreCase = true) - - "name" -> - module.name.equals(searchKey, ignoreCase = true) - - "author" -> - module.author.equals(searchKey, ignoreCase = true) - - "category" -> - module.categories?.any { - it.equals(searchKey, ignoreCase = true) - } == true - - else -> - module.name.contains(searchKey, ignoreCase = true) || - module.author.contains(searchKey, ignoreCase = true) || - module.description?.contains( - searchKey, - ignoreCase = true, - ) == true + "id" -> module.id.equals(searchKey, ignoreCase = true) + "name" -> module.name.equals(searchKey, ignoreCase = true) + "author" -> module.author.equals(searchKey, ignoreCase = true) + "category" -> module.categories?.any { + it.equals( + searchKey, + ignoreCase = true + ) + } == true + + else -> module.name.contains(searchKey, ignoreCase = true) || + module.author.contains(searchKey, ignoreCase = true) || + module.description?.contains(searchKey, ignoreCase = true) == true } } } - }.stateIn( - scope = viewModelScope, - started = SharingStarted.WhileSubscribed(5_000), - initialValue = emptyList(), - ) + } + .onStart { _isLoading.value = true } + .flowOn(Dispatchers.IO) + .stateIn( + scope = viewModelScope, + started = SharingStarted.WhileSubscribed(5_000), + initialValue = emptyList(), + ) private fun parseSearchKey(raw: String): Pair { val prefix = listOf("id", "name", "author", "category") @@ -164,14 +153,9 @@ constructor( ): Comparator> { val base: Comparator> = when (option) { - Option.Name -> - compareBy { it.second.name.lowercase() } - - Option.UpdatedTime -> - compareByDescending { it.first.lastUpdated } - - Option.Size -> - compareByDescending { 0 } + Option.Name -> compareBy { it.second.name.lowercase() } + Option.UpdatedTime -> compareByDescending { it.first.lastUpdated } + Option.Size -> compareByDescending { 0 } } return if (descending) base.reversed() else base @@ -208,4 +192,4 @@ constructor( factory.create(repo) } } -} \ No newline at end of file +} From 8cd26e25b5d380a458e6b9925caac6f7532aa564 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sun, 1 Nov 2026 16:45:42 +0100 Subject: [PATCH 27/55] . --- .../dergoogler/mmrl/ui/component/BottomBar.kt | 76 ++- .../mmrl/ui/navigation/MainDestination.kt | 7 + .../mmrl/ui/screens/home/HomeScreen.kt | 490 +++++++++--------- .../mmrl/viewmodel/SettingsViewModel.kt | 7 + datastore/build.gradle.kts | 2 + .../datastore/UserPreferencesDataSource.kt | 10 + .../datastore/UserPreferencesRepository.kt | 3 + .../mmrl/datastore/model/UserPreferences.kt | 5 +- gradle/libs.versions.toml | 2 +- 9 files changed, 337 insertions(+), 265 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt index e7f784a2b..ee01017aa 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt @@ -9,63 +9,83 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import com.dergoogler.mmrl.ui.navigation.MainDestination -import com.dergoogler.mmrl.ui.navigation.isAccessible import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalNavController +import com.dergoogler.mmrl.ui.providable.LocalSettings import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.dergoogler.mmrl.ui.remember.rememberIsRoot import com.ramcosta.composedestinations.generated.NavGraphs import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState +import dev.mmrlx.compose.ui.DraggableContainer import dev.mmrlx.compose.ui.Text import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.navigationbar.NavigationBar import dev.mmrlx.compose.ui.navigationbar.NavigationBarItem +import dev.mmrlx.compose.ui.rememberDraggableContainerState import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun BottomBar(updates: Int = 0) { + val isRoot = rememberIsRoot() val prefs = LocalUserPreferences.current val navigator = LocalDestinationsNavigator.current val navController = LocalNavController.current + val settings = LocalSettings.current + + + val state = rememberDraggableContainerState( + initial = prefs.bottomBarOrder + ) { + settings.setBottomBarOrder(it) + } + NavigationBar( modifier = Modifier .imePadding() ) { - for (screen in MainDestination.entries) { - if (!screen.isAccessible) continue + DraggableContainer(state = state) { + row("nav") { + for (screen in MainDestination.entries) { + if ((screen.requiresRoot && !isRoot)) continue - val isSelected by navController.isRouteOnBackStackAsState(screen.direction) + element(screen.id) { + val isSelected by navController.isRouteOnBackStackAsState(screen.direction) - NavigationBarItem( - icon = { - BaseNavIcon(screen, isSelected, updates) - }, - label = { - if (!prefs.hideBottomBarLabels) { - Text( - text = stringResource(id = screen.label), - style = MMRLXTheme.typography.labelLarge, + NavigationBarItem( + icon = { + BaseNavIcon(screen, isSelected, updates) + }, + label = { + if (!prefs.hideBottomBarLabels) { + Text( + text = stringResource(id = screen.label), + style = MMRLXTheme.typography.labelLarge, + ) + } + }, + selected = isSelected, + onClick = { + if (isSelected) { + navigator.popBackStack(screen.direction, false) + } + navigator.navigate(screen.direction) { + popUpTo(NavGraphs.root) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, ) } - }, - selected = isSelected, - onClick = { - if (isSelected) { - navigator.popBackStack(screen.direction, false) - } - navigator.navigate(screen.direction) { - popUpTo(NavGraphs.root) { - saveState = true - } - launchSingleTop = true - restoreState = true - } - }, - ) + } + } } } } + /* @Composable private fun RailNav(updates: Int) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt index f52c009ff..72d010ac8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/navigation/MainDestination.kt @@ -15,6 +15,7 @@ import com.ramcosta.composedestinations.spec.DirectionDestinationSpec // annotation class MainGraph enum class MainDestination( + val id: String, val direction: DirectionDestinationSpec, @StringRes val label: Int, @DrawableRes val icon: Int, @@ -23,6 +24,7 @@ enum class MainDestination( val requiresKernel: Boolean, ) { Home( + id = "home", direction = HomeScreenDestination, label = R.string.page_home, icon = R.drawable.home, @@ -32,6 +34,7 @@ enum class MainDestination( ), Repository( + id = "repositories", direction = RepositoriesScreenDestination, label = R.string.page_repositorys, icon = R.drawable.cloud, @@ -41,6 +44,7 @@ enum class MainDestination( ), Modules( + id = "modules", direction = ModulesScreenDestination, label = R.string.page_modules, icon = R.drawable.keyframes, @@ -50,6 +54,7 @@ enum class MainDestination( ), Settings( + id = "settings", direction = SettingsScreenDestination, label = R.string.page_settings, icon = R.drawable.settings, @@ -65,3 +70,5 @@ val MainDestination.isAccessible: Boolean val isRoot = rememberIsRoot() return !(this.requiresRoot && !isRoot) } + + diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 88a5a882e..36de79601 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -9,6 +9,7 @@ import androidx.compose.animation.fadeOut import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row @@ -67,6 +68,7 @@ import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.AboutScreenDestination import com.ramcosta.composedestinations.generated.destinations.ThankYouScreenDestination import dev.mmrlx.compose.layout.outlinedCard +import dev.mmrlx.compose.ui.DraggableContainer import dev.mmrlx.compose.ui.LinearProgressIndicator import dev.mmrlx.compose.ui.LocalTextStyle import dev.mmrlx.compose.ui.Text @@ -126,7 +128,7 @@ fun HomeScreen() { }, contentWindowInsets = WindowInsets.none, ) { - Column( + List( modifier = Modifier .scaffoldHazeSource() @@ -135,177 +137,185 @@ fun HomeScreen() { .scaffoldPadding() .padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp), + contentPadding = listItemContentPaddingValues ) { - when { - userPreferences.workingMode.isRoot -> - RootItem() + val scope = this - userPreferences.workingMode.isNonRoot -> - NonRootItem() - } + DraggableContainer { + element("root-status") { + Box { + when { + userPreferences.workingMode.isRoot -> + RootItem() - if (userPreferences.checkAppUpdates) { - var changelog by remember { mutableStateOf?>(null) } - LaunchedEffect(Unit) { - runRequest { - withContext(Dispatchers.IO) { - val api = IMMRLApiManager.build() - return@withContext api.changelog.execute() + userPreferences.workingMode.isNonRoot -> + NonRootItem() } - }.onSuccess { list -> - changelog = list - }.onFailure { - Timber.e(it, "unable to get changelog") } } - changelog?.let { - val latest = it.first() + element("update-status") { + if (userPreferences.checkAppUpdates) { + var changelog by remember { mutableStateOf?>(null) } + LaunchedEffect(Unit) { + runRequest { + withContext(Dispatchers.IO) { + val api = IMMRLApiManager.build() + return@withContext api.changelog.execute() + } + }.onSuccess { list -> + changelog = list + }.onFailure { + Timber.e(it, "unable to get changelog") + } + } + + changelog?.let { + val latest = it.first() - var changelogSheet by remember { mutableStateOf(false) } - if (changelogSheet) { - ChangelogBottomSheet( - changelog = latest, - onClose = { changelogSheet = false }, - ) - } + var changelogSheet by remember { mutableStateOf(false) } + if (changelogSheet) { + ChangelogBottomSheet( + changelog = latest, + onClose = { changelogSheet = false }, + ) + } - AnimatedVisibility( - visible = - userPreferences.developerMode { devAlwaysShowUpdateAlert } || - ( - if (latest.preRelease) { - userPreferences.checkAppUpdatesPreReleases && + AnimatedVisibility( + visible = + userPreferences.developerMode { devAlwaysShowUpdateAlert } || + ( + if (latest.preRelease) { + userPreferences.checkAppUpdatesPreReleases && + latest.versionCode > context.managerVersion.second + } else { latest.versionCode > context.managerVersion.second - } else { - latest.versionCode > context.managerVersion.second - } - ), - enter = fadeIn() + expandVertically(), - exit = shrinkVertically() + fadeOut(), - ) { - Alert( - onClick = { - changelogSheet = true - }, - backgroundColor = MaterialTheme.colorScheme.tertiaryContainer, - title = stringResource(R.string.update_available), - message = - stringResource( - R.string.new_version_available, - latest.versionName, - ), - icon = R.drawable.cloud_download, - ) + } + ), + enter = fadeIn() + expandVertically(), + exit = shrinkVertically() + fadeOut(), + ) { + Alert( + onClick = { + changelogSheet = true + }, + backgroundColor = MaterialTheme.colorScheme.tertiaryContainer, + title = stringResource(R.string.update_available), + message = + stringResource( + R.string.new_version_available, + latest.versionName, + ), + icon = R.drawable.cloud_download, + ) + } + } } } - } + + element("device-app-info") { + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .fillMaxWidth() + ) { + val uname = Os.uname() - List( - verticalArrangement = Arrangement.spacedBy(16.dp), - contentPadding = listItemContentPaddingValues, - ) { - val scope = this - - Column( - modifier = Modifier - .outlinedCard() - .padding(vertical = 16.dp) - .fillMaxWidth() - ) { - val uname = Os.uname() - - scope.Item { - Title { - Text( - "DEV BUILD! EXPECT ERRORS AND BROKEN UI/UX", - style = LocalTextStyle.current.copy( - fontFamily = FontFamily.Monospace, - color = Color.Red + scope.Item { + Title { + Text( + "DEV BUILD! EXPECT ERRORS AND BROKEN UI/UX", + style = LocalTextStyle.current.copy( + fontFamily = FontFamily.Monospace, + color = Color.Red + ) ) - ) + } } - } - scope.Item { - Icon(painter = painterResource(R.drawable.cookie_man)) - Title(R.string.kernel) - Description(uname.release) - } + scope.Item { + Icon(painter = painterResource(R.drawable.cookie_man)) + Title(R.string.kernel) + Description(uname.release) + } - scope.Item { - Icon(painter = painterResource(R.drawable.launcher_outline)) - Title(R.string.manager_version) - Description("${context.managerVersion.first} (${context.managerVersion.second})") - } + scope.Item { + Icon(painter = painterResource(R.drawable.launcher_outline)) + Title(R.string.manager_version) + Description("${context.managerVersion.first} (${context.managerVersion.second})") + } - scope.Item { - Icon(painter = painterResource(R.drawable.fingerprint)) - Title(R.string.fingerprint) - Description( - if (userPreferences.hideFingerprintInHome) { - stringResource(id = R.string.hidden) - } else { - Build.FINGERPRINT - }, - ) - } + scope.Item { + Icon(painter = painterResource(R.drawable.fingerprint)) + Title(R.string.fingerprint) + Description( + if (userPreferences.hideFingerprintInHome) { + stringResource(id = R.string.hidden) + } else { + Build.FINGERPRINT + }, + ) + } - scope.Item { - Icon(painter = painterResource(R.drawable.cpu_2)) - Title(R.string.architecture) - Description(uname.machine) - } + scope.Item { + Icon(painter = painterResource(R.drawable.cpu_2)) + Title(R.string.architecture) + Description(uname.machine) + } - scope.SELinuxStatus() + scope.SELinuxStatus() - PlatformManager.platform.isKernelSuOrNext.takeTrue { - scope.Item { - Icon(painter = painterResource(R.drawable.user_outlined)) - Title(R.string.super_user_apps) - Description(superUserCount.toString()) + PlatformManager.platform.isKernelSuOrNext.takeTrue { + scope.Item { + Icon(painter = painterResource(R.drawable.user_outlined)) + Title(R.string.super_user_apps) + Description(superUserCount.toString()) + } } } } - PlatformManager.isAlive.takeTrue { - userPreferences.developerMode.takeTrue { - Column( - modifier = Modifier - .outlinedCard() - .padding(vertical = 16.dp) - .fillMaxWidth() - ) { - scope.Item { - Title(R.string.home_root_provider_version_name) - Description(versionName) - } + element("root-dev-info") { + PlatformManager.isAlive.takeTrue { + userPreferences.developerMode.takeTrue { + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .fillMaxWidth() + ) { + scope.Item { + Title(R.string.home_root_provider_version_name) + Description(versionName) + } - scope.Item { - Title(R.string.home_root_provider_se_linux_context) - Description(seLinuxContext) - } + scope.Item { + Title(R.string.home_root_provider_se_linux_context) + Description(seLinuxContext) + } - if (PlatformManager.platform.isKernelSuNext) { - KsuNative.getHookMode().nullable { - scope.Item { - Title(R.string.hook_mode) - Description(it) + if (PlatformManager.platform.isKernelSuNext) { + KsuNative.getHookMode().nullable { + scope.Item { + Title(R.string.hook_mode) + Description(it) + } } } - } - if (PlatformManager.platform.isSukiSU) { - KsuNative.getHookType().nullable { - scope.Item { - Title(R.string.hook_mode) - Description(it) + if (PlatformManager.platform.isSukiSU) { + KsuNative.getHookType().nullable { + scope.Item { + Title(R.string.hook_mode) + Description(it) + } } - } - scope.Item { - Title(R.string.kpm_support) - Description(if (KsuNative.isKPMEnabled()) R.string.yes else R.string.no) + scope.Item { + Title(R.string.kpm_support) + Description(if (KsuNative.isKPMEnabled()) R.string.yes else R.string.no) + } } } } @@ -314,126 +324,136 @@ fun HomeScreen() { if (PlatformManager.platform.isValid) { analytics.nullable { - Row( - horizontalArrangement = Arrangement.spacedBy(16.dp), - ) { - Column( - modifier = Modifier - .outlinedCard() - .padding(vertical = 16.dp) - .weight(1f) - ) { - scope.Item { - Title(R.string.home_installed_modules) - Description(it.totalModules.toString()) - } - } - - Column( - modifier = Modifier - .outlinedCard() - .padding(vertical = 16.dp) - .weight(1f) + element("analytics-modules") { + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp), ) { - scope.Item { - Title(R.string.home_updated_modules) - Description(it.totalUpdated.toString()) + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_installed_modules) + Description(it.totalModules.toString()) + } } - } - } - Column( - modifier = Modifier - .outlinedCard() - .padding(vertical = 16.dp) - .fillMaxWidth() - ) { - scope.Item { - Title(R.string.home_storage_usage) - - Description { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text( - text = it.totalModulesUsageBytes.toFormattedFileSize(), - ) - - LinearProgressIndicator( - progress = { - it.totalStorageUsage - }, - modifier = - Modifier - .height(10.dp) - .weight(1f), - drawStopIndicator = {}, - ) - - Text( - text = it.totalDeviceStorageBytes.toFormattedFileSize(), - ) + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_updated_modules) + Description(it.totalUpdated.toString()) } } } } - Row( - horizontalArrangement = Arrangement.spacedBy(16.dp), - ) { + + element("analytics-storage") { Column( modifier = Modifier .outlinedCard() .padding(vertical = 16.dp) - .weight(1f) + .fillMaxWidth() ) { scope.Item { - Title(R.string.home_enabled_modules) - Description(it.totalEnabled.toString()) + Title(R.string.home_storage_usage) + + Description { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text( + text = it.totalModulesUsageBytes.toFormattedFileSize(), + ) + + LinearProgressIndicator( + progress = { + it.totalStorageUsage + }, + modifier = + Modifier + .height(10.dp) + .weight(1f), + drawStopIndicator = {}, + ) + + Text( + text = it.totalDeviceStorageBytes.toFormattedFileSize(), + ) + } + } } } + } - Column( - modifier = Modifier - .outlinedCard() - .padding(vertical = 16.dp) - .weight(1f) + + element("analytics-states") { + Row( + horizontalArrangement = Arrangement.spacedBy(16.dp), ) { - scope.Item { - Title(R.string.home_disabled_modules) - Description(it.totalDisabled.toString()) + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_enabled_modules) + Description(it.totalEnabled.toString()) + } + } + + Column( + modifier = Modifier + .outlinedCard() + .padding(vertical = 16.dp) + .weight(1f) + ) { + scope.Item { + Title(R.string.home_disabled_modules) + Description(it.totalDisabled.toString()) + } } } } } } - Column( - modifier = Modifier - .outlinedCard() - .fillMaxWidth() - .clickable { - browser.openUri("https://github.com/sponsors/MMRLApp") + element("support") { + Column( + modifier = Modifier + .outlinedCard() + .fillMaxWidth() + .clickable { + browser.openUri("https://github.com/sponsors/MMRLApp") + } + .padding(vertical = 16.dp) + ) { + scope.Item { + Title( + id = R.string.home_support_title, + styleTransform = { + val newStyle = it.copy(color = Color.Unspecified) + it.merge(newStyle) + }, + ) + + Description( + id = R.string.home_support_content, + styleTransform = { + val newStyle = it.copy(color = Color.Unspecified) + it.merge(newStyle) + }, + ) } - .padding(vertical = 16.dp) - ) { - scope.Item { - Title( - id = R.string.home_support_title, - styleTransform = { - val newStyle = it.copy(color = Color.Unspecified) - it.merge(newStyle) - }, - ) - - Description( - id = R.string.home_support_content, - styleTransform = { - val newStyle = it.copy(color = Color.Unspecified) - it.merge(newStyle) - }, - ) } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SettingsViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SettingsViewModel.kt index 92c410af1..8766b904c 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SettingsViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/SettingsViewModel.kt @@ -13,6 +13,7 @@ import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository import com.dergoogler.mmrl.utils.BlurUtil import dagger.hilt.android.lifecycle.HiltViewModel +import dev.mmrlx.compose.ui.DraggableSnapshot import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -307,4 +308,10 @@ class SettingsViewModel userPreferencesRepository.setProviderServiceEnabled(value) } } + + fun setBottomBarOrder(value: DraggableSnapshot) { + viewModelScope.launch { + userPreferencesRepository.setBottomBarOrder(value) + } + } } diff --git a/datastore/build.gradle.kts b/datastore/build.gradle.kts index a2e294e62..4d6243a7f 100644 --- a/datastore/build.gradle.kts +++ b/datastore/build.gradle.kts @@ -45,6 +45,8 @@ dependencies { implementation(projects.platform) implementation(projects.ui) + compileOnly(libs.mmrlx.ui) + implementation(libs.androidx.core.ktx) implementation(libs.androidx.datastore.core) implementation(libs.kotlinx.serialization.protobuf) diff --git a/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesDataSource.kt b/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesDataSource.kt index b3c06e39a..592a05213 100644 --- a/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesDataSource.kt +++ b/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesDataSource.kt @@ -10,6 +10,7 @@ import com.dergoogler.mmrl.datastore.model.SuperUserMenu import com.dergoogler.mmrl.datastore.model.UserPreferences import com.dergoogler.mmrl.datastore.model.WebUIEngine import com.dergoogler.mmrl.datastore.model.WorkingMode +import dev.mmrlx.compose.ui.DraggableSnapshot import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import javax.inject.Inject @@ -425,4 +426,13 @@ class UserPreferencesDataSource ) } } + + suspend fun setBottomBarOrder(value: DraggableSnapshot) = + withContext(Dispatchers.IO) { + userPreferences.updateData { + it.copy( + bottomBarOrder = value, + ) + } + } } diff --git a/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesRepository.kt b/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesRepository.kt index 8b5fde4bd..81e1d0bc0 100644 --- a/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesRepository.kt +++ b/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/UserPreferencesRepository.kt @@ -8,6 +8,7 @@ import com.dergoogler.mmrl.datastore.model.RepositoryMenu import com.dergoogler.mmrl.datastore.model.SuperUserMenu import com.dergoogler.mmrl.datastore.model.WebUIEngine import com.dergoogler.mmrl.datastore.model.WorkingMode +import dev.mmrlx.compose.ui.DraggableSnapshot import javax.inject.Inject import javax.inject.Singleton @@ -108,4 +109,6 @@ class UserPreferencesRepository suspend fun setModuleServiceEnabled(value: Boolean) = userPreferencesDataSource.setModuleServiceEnabled(value) suspend fun setProviderServiceEnabled(value: Boolean) = userPreferencesDataSource.setProviderServiceEnabled(value) + + suspend fun setBottomBarOrder(value: DraggableSnapshot) = userPreferencesDataSource.setBottomBarOrder(value) } diff --git a/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/model/UserPreferences.kt b/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/model/UserPreferences.kt index 6d34ab97a..218b54809 100644 --- a/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/model/UserPreferences.kt +++ b/datastore/src/main/kotlin/com/dergoogler/mmrl/datastore/model/UserPreferences.kt @@ -10,6 +10,7 @@ import android.os.Environment import com.dergoogler.mmrl.datastore.BuildConfig import com.dergoogler.mmrl.ui.theme.Colors import com.dergoogler.mmrl.ui.theme.Colors.Companion.getColorScheme +import dev.mmrlx.compose.ui.DraggableSnapshot import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromByteArray @@ -77,6 +78,7 @@ data class UserPreferences( @ProtoNumber(44) val repositoryServiceEnabled: Boolean = false, @ProtoNumber(45) val moduleServiceEnabled: Boolean = false, @ProtoNumber(46) val providerServiceEnabled: Boolean = false, + @ProtoNumber(47) val bottomBarOrder: DraggableSnapshot = DraggableSnapshot(), ) { fun isDarkMode() = when (darkMode) { @@ -114,6 +116,7 @@ data class UserPreferences( ) @OptIn(ExperimentalSerializationApi::class) - fun decodeFrom(input: InputStream): UserPreferences = ProtoBuf.decodeFromByteArray(input.readBytes()) + fun decodeFrom(input: InputStream): UserPreferences = + ProtoBuf.decodeFromByteArray(input.readBytes()) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 122f366ea..5994cbb5c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.232" +mmrlx = "1.0.241" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 3bded0f1cfe7d86ed0bad380527aeb53610028bf Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:00:27 +0100 Subject: [PATCH 28/55] Update MMRLx and repository navigation Pass the navigator to the explore repository toolbar and update the MMRLx dependency to 1.0.245. --- .../ui/screens/exploreRepositories/ExploreRepositoryScreen.kt | 1 + gradle/libs.versions.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt index 4e3946f94..cbc4e0039 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt @@ -121,6 +121,7 @@ fun ExploreRepositoryScreen(repo: ExploreRepository) = modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), topBar = { BlurNavigateUpToolbar( + navigator = navigator, title = "", scrollBehavior = scrollBehavior, fade = true, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5994cbb5c..9b0c2cd07 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.241" +mmrlx = "1.0.245" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 85e1772637bf493020eb23ed25a83f77ee295f3c Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 5 Nov 2026 20:56:31 +0100 Subject: [PATCH 29/55] . --- commits.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commits.sh b/commits.sh index 9e421bd94..8780f40d8 100644 --- a/commits.sh +++ b/commits.sh @@ -2,7 +2,7 @@ REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" MAX_CHARS="${1:-4000}" -REPO_BRANCH="${2:-master}" +REPO_BRANCH=${GITHUB_REF#refs/heads/} get_latest_tag() { git describe --tags --abbrev=0 $REPO_BRANCH 2>/dev/null From ce78e4b6ac1436197c7737df256aef4d4837414d Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:13:16 +0100 Subject: [PATCH 30/55] . --- .github/workflows/release-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml index 6dbf0ae36..830fd9268 100644 --- a/.github/workflows/release-ci.yml +++ b/.github/workflows/release-ci.yml @@ -1,7 +1,7 @@ name: Release CI permissions: - contents: read + contents: write packages: read on: From 84924b77c4bd5ff6977f32981464aa236d905afe Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:00:45 +0100 Subject: [PATCH 31/55] clean: move install confirm and downloader into own components --- .../ui/screens/moduleView/NewViewScreen.kt | 354 +++++------ .../moduleView/items/InstallConfirmDialog.kt | 186 ++++-- .../moduleView/items/rememberDownload.kt | 30 + .../mmrl/viewmodel/ModuleViewModel.kt | 569 +++++++++--------- 4 files changed, 595 insertions(+), 544 deletions(-) create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index c92863204..6217466ac 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -26,18 +26,14 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp -import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.database.entity.Repo import com.dergoogler.mmrl.ext.fadingEdge -import com.dergoogler.mmrl.ext.ifNotEmpty import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.model.local.BulkModule import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.model.online.isBlacklisted -import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.providable.LocalBulkInstall @@ -52,7 +48,7 @@ import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.providable.LocalVersionItem import com.dergoogler.mmrl.ui.screens.moduleView.items.InstallConfirmDialog import com.dergoogler.mmrl.ui.screens.moduleView.items.ViewTrackBottomSheet -import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewDownloader +import com.dergoogler.mmrl.ui.screens.moduleView.items.rememberDownload import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalRequireModules import com.dergoogler.mmrl.ui.screens.moduleView.sections.AboutModule @@ -71,7 +67,6 @@ import dev.mmrlx.compose.ui.NavigationBarsSpacer import dev.mmrlx.compose.ui.ext.with import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults -import timber.log.Timber internal val listItemContentPaddingValues = PaddingValues(vertical = 16.dp, horizontal = 16.dp) internal val subListItemContentPaddingValues = PaddingValues(vertical = 8.dp, horizontal = 16.dp) @@ -82,232 +77,169 @@ fun NewViewScreen( repo: Repo, module: OnlineModule, ) = LocalScreenProvider { - val viewModel = ModuleViewModel.build(repo, module) - - val navigator = LocalDestinationsNavigator.current - val bulkInstallViewModel = LocalBulkInstall.current - val userPreferences = LocalUserPreferences.current - val repositoryMenu = userPreferences.repositoryMenu - val module = viewModel.online - val moduleAll by viewModel.onlineAll.collectAsStateWithLifecycle() - val local = viewModel.local - val lastVersionItem = viewModel.lastVersionItem - val context = LocalContext.current - val density = LocalDensity.current - val browser = LocalUriHandler.current - val hazeState = LocalHazeState.current - - val listState = rememberLazyListState() - - val screenshotsLazyListState = rememberLazyListState() - val categoriesLazyListState = rememberLazyListState() - - val scope = rememberCoroutineScope() - val snackbarHostState = remember { SnackbarHostState() } + ModuleViewModel.LocalProvider(repo, module) { viewModel -> + val navigator = LocalDestinationsNavigator.current + val bulkInstallViewModel = LocalBulkInstall.current + val userPreferences = LocalUserPreferences.current + val repositoryMenu = userPreferences.repositoryMenu + val module = viewModel.online + val moduleAll by viewModel.onlineAll.collectAsStateWithLifecycle() + val local = viewModel.local + val lastVersionItem = viewModel.lastVersionItem + val context = LocalContext.current + val density = LocalDensity.current + val browser = LocalUriHandler.current + val hazeState = LocalHazeState.current + + val listState = rememberLazyListState() + + val screenshotsLazyListState = rememberLazyListState() + val categoriesLazyListState = rememberLazyListState() + + val scope = rememberCoroutineScope() + val snackbarHostState = remember { SnackbarHostState() } + + val manager = module.manager(viewModel.platform) + val requires = + manager.require?.let { + moduleAll + .filter { onlineModules -> + onlineModules.second.id in it + }.map { it2 -> it2.second } + } ?: emptyList() + + + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() + + val isBlacklisted by module.isBlacklisted + + if (viewModel.versionSelectBottomSheet) { + VersionSelectBottomSheet( + onClose = { viewModel.versionSelectBottomSheet = false }, + versions = viewModel.versions, + localVersionCode = viewModel.localVersionCode, + isProviderAlive = viewModel.isProviderAlive, + getProgress = { viewModel.getProgress(it) }, + onDownload = rememberDownload(), + isBlacklisted = isBlacklisted, + ) + } - val download: (VersionItem, Boolean) -> Unit = { item, install -> - viewModel.downloader(context, item) { - if (install) { - viewModel.installConfirm = false - InstallActivity.start( - context = context, - uri = it.toUri(), - confirm = false, - ) - } + if (viewModel.viewTrackBottomSheet) { + ViewTrackBottomSheet( + onClose = { viewModel.viewTrackBottomSheet = false }, + tracks = viewModel.tracks, + ) } - } - val manager = module.manager(viewModel.platform) - val requires = - manager.require?.let { - moduleAll - .filter { onlineModules -> - onlineModules.second.id in it - }.map { it2 -> it2.second } - } ?: emptyList() + CompositionLocalProvider( + LocalSnackbarHost provides snackbarHostState, + LocalOnlineModule provides module, + LocalVersionItem provides (lastVersionItem ?: VersionItem.EMPTY), + LocalModule provides (local ?: com.dergoogler.mmrl.platform.content.LocalModule.EMPTY), + LocalRepo provides repo, + LocalModuleViewModel provides viewModel, + LocalRequireModules provides requires, + LocalScrollBehavior provides scrollBehavior, + ) { + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + snackbarHost = { SnackbarHost(snackbarHostState) }, + toolbar = { + Toolbar0() + }, + contentWindowInsets = WindowInsets.none, + ) { + val scope = this - if (viewModel.installConfirm) { - InstallConfirmDialog( - name = module.name, - requires = requires, - onClose = { - viewModel.installConfirm = false - }, - onConfirm = { - lastVersionItem?.let { download(it, true) } - }, - onConfirmDeps = { - lastVersionItem?.let { item -> - val bulkModules = mutableListOf() - bulkModules.add( - BulkModule( - id = module.id, - name = module.name, - versionItem = item, - ), - ) - bulkModules.addAll( - requires.map { r -> - BulkModule( - id = r.id, - name = r.name, - versionItem = r.versions.first(), + Column( + modifier = + Modifier + .verticalScroll(rememberScrollState()) + .scaffoldHazeSource() + .let { + if (repositoryMenu.showCover && module.hasCover) { + it + } else { + it.padding(top = scaffoldTopPadding) + } + } + ) { + module.cover.nullable(repositoryMenu.showCover) { + if (it.isNotEmpty()) { + Cover( + modifier = + Modifier.fadingEdge( + Brush.verticalGradient( + colors = + listOf( + Color.Transparent, + Color.Black, + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, + ), + ), + url = it, ) - }, - ) - - bulkModules.ifNotEmpty { - bulkInstallViewModel.downloadMultiple( - items = bulkModules, - onAllSuccess = { uris -> - viewModel.installConfirm = false - InstallActivity.start( - context = context, - uri = uris, - confirm = false, - ) - }, - onFailure = { err -> - viewModel.installConfirm = false - Timber.e(err) - }, - ) + } } - } - }, - ) - } - val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() - - val isBlacklisted by module.isBlacklisted - - if (viewModel.versionSelectBottomSheet) { - VersionSelectBottomSheet( - onClose = { viewModel.versionSelectBottomSheet = false }, - versions = viewModel.versions, - localVersionCode = viewModel.localVersionCode, - isProviderAlive = viewModel.isProviderAlive, - getProgress = { viewModel.getProgress(it) }, - onDownload = download, - isBlacklisted = isBlacklisted, - ) - } - - if (viewModel.viewTrackBottomSheet) { - ViewTrackBottomSheet( - onClose = { viewModel.viewTrackBottomSheet = false }, - tracks = viewModel.tracks, - ) - } + Column( + modifier = Modifier.with(scope) { + it.scaffoldBottomPadding() + } + ) { + Spacer(modifier = Modifier.height(16.dp)) + + Header() + + val progress = + lastVersionItem?.let { + viewModel.getProgress(it) + } ?: 0f + + if (progress != 0f) { + LinearProgressIndicator( + progress = { progress }, + strokeCap = StrokeCap.Round, + modifier = + Modifier + .padding(vertical = 16.dp) + .height(0.9.dp) + .fillMaxWidth(), + ) + } else { + HorizontalDivider( + modifier = Modifier.padding(vertical = 16.dp), + thickness = 0.9.dp, + ) + } - CompositionLocalProvider( - LocalSnackbarHost provides snackbarHostState, - LocalOnlineModule provides module, - LocalVersionItem provides (lastVersionItem ?: VersionItem.EMPTY), - LocalModule provides (local ?: com.dergoogler.mmrl.platform.content.LocalModule.EMPTY), - LocalRepo provides repo, - LocalModuleViewModel provides viewModel, - LocalModuleViewDownloader provides download, - LocalRequireModules provides requires, - LocalScrollBehavior provides scrollBehavior, - ) { - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - snackbarHost = { SnackbarHost(snackbarHostState) }, - toolbar = { - Toolbar0() - }, - contentWindowInsets = WindowInsets.none, - ) { - val scope = this + Alerts() - Column( - modifier = - Modifier - .verticalScroll(rememberScrollState()) - .scaffoldHazeSource() - .let { - if (repositoryMenu.showCover && module.hasCover) { - it - } else { - it.padding(top = scaffoldTopPadding) - } - } - ) { - module.cover.nullable(repositoryMenu.showCover) { - if (it.isNotEmpty()) { - Cover( - modifier = - Modifier.fadingEdge( - Brush.verticalGradient( - colors = - listOf( - Color.Transparent, - Color.Black, - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), - ), - url = it, - ) - } - } + AboutModule() - Column( - modifier = Modifier.with(scope) { - it.scaffoldBottomPadding() - } - ) { - Spacer(modifier = Modifier.height(16.dp)) + Screenshots() - Header() + Spacer(modifier = Modifier.height(16.dp)) - val progress = - lastVersionItem?.let { - viewModel.getProgress(it) - } ?: 0f + Information0() - if (progress != 0f) { - LinearProgressIndicator( - progress = { progress }, - strokeCap = StrokeCap.Round, - modifier = - Modifier - .padding(vertical = 16.dp) - .height(0.9.dp) - .fillMaxWidth(), - ) - } else { + // Information section HorizontalDivider( modifier = Modifier.padding(vertical = 16.dp), thickness = 0.9.dp, ) - } - - Alerts() - - AboutModule() - Screenshots() - - Spacer(modifier = Modifier.height(16.dp)) - - Information0() - - // Information section - HorizontalDivider( - modifier = Modifier.padding(vertical = 16.dp), - thickness = 0.9.dp, - ) + Information() + } - Information() + NavigationBarsSpacer() } - - NavigationBarsSpacer() } } + + InstallConfirmDialog() } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/InstallConfirmDialog.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/InstallConfirmDialog.kt index 371ee6cfb..041ad3854 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/InstallConfirmDialog.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/InstallConfirmDialog.kt @@ -3,88 +3,146 @@ package com.dergoogler.mmrl.ui.screens.moduleView.items import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.ifNotEmpty import com.dergoogler.mmrl.ext.isNotNullOrEmpty -import com.dergoogler.mmrl.model.online.OnlineModule +import com.dergoogler.mmrl.model.local.BulkModule +import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.component.BulletList import com.dergoogler.mmrl.ui.component.text.BBCodeText +import com.dergoogler.mmrl.ui.providable.LocalBulkInstall +import com.dergoogler.mmrl.viewmodel.ModuleViewModel +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.button.Button +import dev.mmrlx.compose.ui.button.ButtonVariant +import dev.mmrlx.compose.ui.dialog.Content +import dev.mmrlx.compose.ui.dialog.Dialog +import dev.mmrlx.compose.ui.dialog.Footer +import dev.mmrlx.compose.ui.dialog.Title +import timber.log.Timber @Composable -fun InstallConfirmDialog( - name: String, - requires: List, - onClose: () -> Unit, - onConfirm: () -> Unit, - onConfirmDeps: () -> Unit, -) { - AlertDialog( - title = { - Text(text = stringResource(id = R.string.view_module_install_confirm_title)) - }, - text = { - Column { - if (requires.isNotNullOrEmpty()) { - BBCodeText( - text = - stringResource( - R.string.view_module_install_confirm_desc_deps, - name, - ), - ) +fun InstallConfirmDialog() { + val bulkInstallViewModel = LocalBulkInstall.current + val context = LocalContext.current + val vm = ModuleViewModel.current + val module = vm.module + val lastVersionItem = vm.lastVersionItem + val requires = vm.requires - Spacer(modifier = Modifier.height(8.dp)) + val download = rememberDownload() - BulletList( - items = requires.map { it.name }, - ) - } else { - BBCodeText( - text = - stringResource( - R.string.view_module_install_confirm_desc, - name, - ), - ) + if (vm.installConfirm) + Dialog( + onDismissRequest = { + vm.installConfirm = false + } + ) { + Title { + Text(text = stringResource(id = R.string.view_module_install_confirm_title)) + } + + Content { + Column { + if (requires.isNotNullOrEmpty()) { + BBCodeText( + text = + stringResource( + R.string.view_module_install_confirm_desc_deps, + module.name, + ), + ) + + Spacer(modifier = Modifier.height(8.dp)) + + BulletList( + items = requires.map { it.name }, + ) + } else { + BBCodeText( + text = + stringResource( + R.string.view_module_install_confirm_desc, + module.name, + ), + ) + } } } - }, - onDismissRequest = { - onClose() - }, - confirmButton = { - requires.ifNotEmpty { - TextButton( + + Footer { + Button( onClick = { - onConfirmDeps() + vm.installConfirm = false }, + + variant = ButtonVariant.Outline, ) { - Text(text = stringResource(id = R.string.view_module_install_confirm_confirm_deps)) + Text(text = stringResource(id = R.string.install_screen_reboot_dismiss)) + } + + requires.ifNotEmpty { + Button( + onClick = { + lastVersionItem?.let { item -> + val bulkModules = mutableListOf() + bulkModules.add( + BulkModule( + id = module.id, + name = module.name, + versionItem = item, + ), + ) + bulkModules.addAll( + requires.map { r -> + BulkModule( + id = r.id, + name = r.name, + versionItem = r.versions.first(), + ) + }, + ) + + bulkModules.ifNotEmpty { + bulkInstallViewModel.downloadMultiple( + items = bulkModules, + onAllSuccess = { uris -> + vm.installConfirm = false + InstallActivity.start( + context = context, + uri = uris, + confirm = false, + ) + }, + onFailure = { err -> + vm.installConfirm = false + Timber.e(err) + }, + ) + } + } + }, + + variant = ButtonVariant.Ghost, + ) { + Text(text = stringResource(id = R.string.view_module_install_confirm_confirm_deps)) + } + } + + Button( + onClick = { + vm.installConfirm = false + lastVersionItem?.let { download(it, true) } + }, + variant = ButtonVariant.Default, + ) { + Text(text = stringResource(id = R.string.view_module_install_confirm_confirm)) } } - TextButton( - onClick = { - onConfirm() - }, - ) { - Text(text = stringResource(id = R.string.view_module_install_confirm_confirm)) - } - }, - dismissButton = { - TextButton( - onClick = { - onClose() - }, - ) { - Text(text = stringResource(id = R.string.install_screen_reboot_dismiss)) - } - }, - ) + } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt new file mode 100644 index 000000000..1ae8038ad --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt @@ -0,0 +1,30 @@ +package com.dergoogler.mmrl.ui.screens.moduleView.items + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.platform.LocalContext +import androidx.core.net.toUri +import com.dergoogler.mmrl.model.online.VersionItem +import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity +import com.dergoogler.mmrl.viewmodel.ModuleViewModel + +@Composable +fun rememberDownload(): (VersionItem, Boolean) -> Unit { + val context = LocalContext.current + val vm = ModuleViewModel.current + + return remember { + { item, install -> + vm.downloader(context, item) { + if (install) { + vm.installConfirm = false + InstallActivity.start( + context = context, + uri = it.toUri(), + confirm = false, + ) + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt index b2707e674..857ffe413 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt @@ -4,11 +4,13 @@ import android.app.Application import android.content.Context import android.widget.Toast import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.runtime.staticCompositionLocalOf import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewModelScope @@ -54,320 +56,349 @@ data class ModuleOps( @HiltViewModel(assistedFactory = ModuleViewModel.Factory::class) class ModuleViewModel - @AssistedInject - constructor( - @Assisted val repo: Repo, - @Assisted val module: OnlineModule, - localRepository: LocalRepository, - modulesRepository: ModulesRepository, - userPreferencesRepository: UserPreferencesRepository, - application: Application, - ) : MMRLViewModel( - localRepository = localRepository, - modulesRepository = modulesRepository, - userPreferencesRepository = userPreferencesRepository, - application = application, - ) { - var installConfirm by mutableStateOf(false) - var menuExpanded by mutableStateOf(false) - var versionSelectBottomSheet by mutableStateOf(false) - var viewTrackBottomSheet by mutableStateOf(false) - - val version: String - get() = - PlatformManager.get("") { - with(moduleManager) { version } - } +@AssistedInject +constructor( + @Assisted val repo: Repo, + @Assisted val module: OnlineModule, + localRepository: LocalRepository, + modulesRepository: ModulesRepository, + userPreferencesRepository: UserPreferencesRepository, + application: Application, +) : MMRLViewModel( + localRepository = localRepository, + modulesRepository = modulesRepository, + userPreferencesRepository = userPreferencesRepository, + application = application, +) { + var installConfirm by mutableStateOf(false) + var menuExpanded by mutableStateOf(false) + var versionSelectBottomSheet by mutableStateOf(false) + var viewTrackBottomSheet by mutableStateOf(false) + + val version: String + get() = + PlatformManager.get("") { + with(moduleManager) { version } + } - val versionCode: Int - get() = - PlatformManager.get(0) { - with(moduleManager) { versionCode } - } + val versionCode: Int + get() = + PlatformManager.get(0) { + with(moduleManager) { versionCode } + } - var online: OnlineModule by mutableStateOf(OnlineModule.example()) - private set - val lastVersionItem by derivedStateOf { - val firstRepo = versions.getOrNull(0)?.first - val item = - if (firstRepo?.name == UPDATE_JSON) { - versions.getOrNull(1) - } else { - versions.getOrNull(0) - } - item?.second - } - val isEmptyAbout - get() = - online.homepage.orEmpty().isBlank() && + val manager by derivedStateOf { module.manager(platform) } + var online: OnlineModule by mutableStateOf(OnlineModule.example()) + private set + + val requires by derivedStateOf { + manager.require?.let { + onlineAll.value + .filter { onlineModules -> + onlineModules.second.id in it + }.map { it2 -> it2.second } + } ?: emptyList() + } + + val lastVersionItem by derivedStateOf { + val firstRepo = versions.getOrNull(0)?.first + val item = + if (firstRepo?.name == UPDATE_JSON) { + versions.getOrNull(1) + } else { + versions.getOrNull(0) + } + item?.second + } + val isEmptyAbout + get() = + online.homepage.orEmpty().isBlank() && online.track.source.isBlank() && online.support.orEmpty().isBlank() - val isEmptyReadme get() = !online.hasReadme - val readme get() = online.readme.orEmpty() - var local: LocalModule? by mutableStateOf(null) - private set + val isEmptyReadme get() = !online.hasReadme + val readme get() = online.readme.orEmpty() + var local: LocalModule? by mutableStateOf(null) + private set - private val installed get() = local?.let { it.author == online.author } ?: false - var notifyUpdates by mutableStateOf(false) - private set + private val installed get() = local?.let { it.author == online.author } ?: false + var notifyUpdates by mutableStateOf(false) + private set - val localVersionCode - get() = - if (notifyUpdates && installed) local!!.versionCode else Int.MAX_VALUE - val updatableSize by derivedStateOf { - versions.count { it.second.versionCode > localVersionCode } - } + val localVersionCode + get() = + if (notifyUpdates && installed) local!!.versionCode else Int.MAX_VALUE + val updatableSize by derivedStateOf { + versions.count { it.second.versionCode > localVersionCode } + } - val otherSources = mutableStateListOf() - val versions = mutableStateListOf>() - val tracks = mutableStateListOf>() + val otherSources = mutableStateListOf() + val versions = mutableStateListOf>() + val tracks = mutableStateListOf>() - init { - Timber.d("ModuleViewModel init: ${module.id}") - loadData() - modulesAll() - } + init { + Timber.d("ModuleViewModel init: ${module.id}") + loadData() + modulesAll() + } - private fun loadData() = - viewModelScope.launch { - localRepository.getOnlineByIdAndUrl(module.id, repo.url).let { - online = it - } + private fun loadData() = + viewModelScope.launch { + localRepository.getOnlineByIdAndUrl(module.id, repo.url).let { + online = it + } - localRepository.getOnlineAllById(module.id).let { - val filtered = it.filter { f -> f.repoUrl != repo.url } - - otherSources.addAll( - filtered.map { module -> - OtherSources( - repo = localRepository.getRepoByUrl(module.repoUrl), - online = module, - state = - module.createState( - local = localRepository.getLocalByIdOrNull(module.id), - hasUpdatableTag = localRepository.hasUpdatableTag(module.id), - ), - ) - }, - ) - } + localRepository.getOnlineAllById(module.id).let { + val filtered = it.filter { f -> f.repoUrl != repo.url } + + otherSources.addAll( + filtered.map { module -> + OtherSources( + repo = localRepository.getRepoByUrl(module.repoUrl), + online = module, + state = + module.createState( + local = localRepository.getLocalByIdOrNull(module.id), + hasUpdatableTag = localRepository.hasUpdatableTag(module.id), + ), + ) + }, + ) + } - localRepository.getLocalByIdOrNull(module.id)?.let { - local = it - notifyUpdates = localRepository.hasUpdatableTag(module.id) - } + localRepository.getLocalByIdOrNull(module.id)?.let { + local = it + notifyUpdates = localRepository.hasUpdatableTag(module.id) + } - localRepository.getVersionByIdAndUrl(module.id, repo.url).forEach { - val repo = localRepository.getRepoByUrl(it.repoUrl) + localRepository.getVersionByIdAndUrl(module.id, repo.url).forEach { + val repo = localRepository.getRepoByUrl(it.repoUrl) - val item = repo to it - val track = - repo to + val item = repo to it + val track = + repo to localRepository .getOnlineByIdAndUrl( id = online.id, repoUrl = it.repoUrl, ).track - versions.add(item) - if (track !in tracks) tracks.add(track) - } + versions.add(item) + if (track !in tracks) tracks.add(track) + } - if (installed) { - UpdateJson.loadToVersionItem(local!!.updateJson)?.let { - it.moduleId = module.id - versions.add(0, UPDATE_JSON.toRepo() to it) - } + if (installed) { + UpdateJson.loadToVersionItem(local!!.updateJson)?.let { + it.moduleId = module.id + versions.add(0, UPDATE_JSON.toRepo() to it) } } - - private val onlineAllFlow = MutableStateFlow(listOf>()) - val onlineAll get() = onlineAllFlow.asStateFlow() - - private fun modulesAll() { - combine( - localRepository.getOnlineAllAsFlow(), - ) { list -> - onlineAllFlow.value = - list.first().map { - it.createState( - local = localRepository.getLocalByIdOrNull(it.id), - hasUpdatableTag = localRepository.hasUpdatableTag(it.id), - ) to it - } - }.launchIn(viewModelScope) } - fun setUpdatesTag(updatable: Boolean) { - viewModelScope.launch { - notifyUpdates = updatable - localRepository.insertUpdatableTag(module.id, updatable) - } + private val onlineAllFlow = MutableStateFlow(listOf>()) + val onlineAll get() = onlineAllFlow.asStateFlow() + + private fun modulesAll() { + combine( + localRepository.getOnlineAllAsFlow(), + ) { list -> + onlineAllFlow.value = + list.first().map { + it.createState( + local = localRepository.getLocalByIdOrNull(it.id), + hasUpdatableTag = localRepository.hasUpdatableTag(it.id), + ) to it + } + }.launchIn(viewModelScope) + } + + fun setUpdatesTag(updatable: Boolean) { + viewModelScope.launch { + notifyUpdates = updatable + localRepository.insertUpdatableTag(module.id, updatable) } + } - fun downloader( - context: Context, - item: VersionItem, - onSuccess: (File) -> Unit, - ) { - viewModelScope.launch { - val downloadPath = - File( - userPreferencesRepository.data - .first() - .downloadPath, - ) - - val filename = - Utils.getFilename( - name = online.name, - version = item.version, - versionCode = item.versionCode, - extension = "zip", - ) - - val task = - DownloadService.TaskItem( - key = item.hashCode(), - url = item.zipUrl, - filename = filename, - title = online.name, - desc = item.versionDisplay, - ) - - val listener = - object : DownloadService.IDownloadListener { - override fun getProgress(value: Float) {} - - override fun onFileExists() { - Toast - .makeText( - context, - context.getString(R.string.file_already_exists), - Toast.LENGTH_SHORT, - ).show() - } + fun downloader( + context: Context, + item: VersionItem, + onSuccess: (File) -> Unit, + ) { + viewModelScope.launch { + val downloadPath = + File( + userPreferencesRepository.data + .first() + .downloadPath, + ) - override fun onSuccess() { - if (downloadPath.exists() && downloadPath.mkdirs()) { - Timber.d("Created directory: $downloadPath") - } + val filename = + Utils.getFilename( + name = online.name, + version = item.version, + versionCode = item.versionCode, + extension = "zip", + ) - onSuccess(downloadPath.resolve(filename)) - } + val task = + DownloadService.TaskItem( + key = item.hashCode(), + url = item.zipUrl, + filename = filename, + title = online.name, + desc = item.versionDisplay, + ) - override fun onFailure(e: Throwable) { - Timber.d(e) - } + val listener = + object : DownloadService.IDownloadListener { + override fun getProgress(value: Float) {} + + override fun onFileExists() { + Toast + .makeText( + context, + context.getString(R.string.file_already_exists), + Toast.LENGTH_SHORT, + ).show() } - DownloadService.start( - context = context, - task = task, - listener = listener, - ) - } - } - - @Composable - fun getProgress(item: VersionItem): Float { - val progress by DownloadService - .getProgressByKey(item.hashCode()) - .collectAsStateWithLifecycle(initialValue = 0f) + override fun onSuccess() { + if (downloadPath.exists() && downloadPath.mkdirs()) { + Timber.d("Created directory: $downloadPath") + } - return progress - } + onSuccess(downloadPath.resolve(filename)) + } - private val opsTasks = mutableStateListOf() - private val opsCallback = - object : IModuleOpsCallback.Stub() { - override fun onSuccess(id: ModId) { - viewModelScope.launch { - modulesRepository.getLocal(id) - opsTasks.remove(id) + override fun onFailure(e: Throwable) { + Timber.d(e) } } - override fun onFailure( - id: ModId, - msg: String?, - ) { + DownloadService.start( + context = context, + task = task, + listener = listener, + ) + } + } + + @Composable + fun getProgress(item: VersionItem): Float { + val progress by DownloadService + .getProgressByKey(item.hashCode()) + .collectAsStateWithLifecycle(initialValue = 0f) + + return progress + } + + private val opsTasks = mutableStateListOf() + private val opsCallback = + object : IModuleOpsCallback.Stub() { + override fun onSuccess(id: ModId) { + viewModelScope.launch { + modulesRepository.getLocal(id) opsTasks.remove(id) - Timber.w("$id: $msg") } } - fun createModuleOps( - useShell: Boolean, - module: LocalModule, - ) = when (module.state) { - State.ENABLE -> - ModuleOps( - isOpsRunning = opsTasks.contains(module.id), - toggle = { - opsTasks.add(module.id) - PlatformManager.moduleManager.disable(module.id, useShell, opsCallback) - }, - change = { - Timber.d("Pressed ENABLE") - opsTasks.add(module.id) - PlatformManager.moduleManager.remove(module.id, useShell, opsCallback) - local = local?.copy(state = State.REMOVE) - }, - ) + override fun onFailure( + id: ModId, + msg: String?, + ) { + opsTasks.remove(id) + Timber.w("$id: $msg") + } + } - State.DISABLE -> - ModuleOps( - isOpsRunning = opsTasks.contains(module.id), - toggle = { - opsTasks.add(module.id) - PlatformManager.moduleManager.enable(module.id, useShell, opsCallback) - }, - change = { - Timber.d("Pressed DISABLE") - opsTasks.add(module.id) - PlatformManager.moduleManager.remove(module.id, useShell, opsCallback) - local = local?.copy(state = State.REMOVE) - }, - ) + fun createModuleOps( + useShell: Boolean, + module: LocalModule, + ) = when (module.state) { + State.ENABLE -> + ModuleOps( + isOpsRunning = opsTasks.contains(module.id), + toggle = { + opsTasks.add(module.id) + PlatformManager.moduleManager.disable(module.id, useShell, opsCallback) + }, + change = { + Timber.d("Pressed ENABLE") + opsTasks.add(module.id) + PlatformManager.moduleManager.remove(module.id, useShell, opsCallback) + local = local?.copy(state = State.REMOVE) + }, + ) + + State.DISABLE -> + ModuleOps( + isOpsRunning = opsTasks.contains(module.id), + toggle = { + opsTasks.add(module.id) + PlatformManager.moduleManager.enable(module.id, useShell, opsCallback) + }, + change = { + Timber.d("Pressed DISABLE") + opsTasks.add(module.id) + PlatformManager.moduleManager.remove(module.id, useShell, opsCallback) + local = local?.copy(state = State.REMOVE) + }, + ) + + State.REMOVE -> + ModuleOps( + isOpsRunning = opsTasks.contains(module.id), + toggle = {}, + change = { + Timber.d("Pressed REMOVE") + opsTasks.add(module.id) + PlatformManager.moduleManager.enable(module.id, useShell, opsCallback) + local = local?.copy(state = State.ENABLE) + }, + ) + + State.UPDATE -> + ModuleOps( + isOpsRunning = opsTasks.contains(module.id), + toggle = {}, + change = {}, + ) + } - State.REMOVE -> - ModuleOps( - isOpsRunning = opsTasks.contains(module.id), - toggle = {}, - change = { - Timber.d("Pressed REMOVE") - opsTasks.add(module.id) - PlatformManager.moduleManager.enable(module.id, useShell, opsCallback) - local = local?.copy(state = State.ENABLE) - }, - ) + @AssistedFactory + interface Factory { + fun create( + repo: Repo, + module: OnlineModule, + ): ModuleViewModel + } - State.UPDATE -> - ModuleOps( - isOpsRunning = opsTasks.contains(module.id), - toggle = {}, - change = {}, - ) - } + companion object { + @Composable + fun build( + repo: Repo, + module: OnlineModule, + ): ModuleViewModel = + hiltViewModel { factory -> + factory.create(repo, module) + } - @AssistedFactory - interface Factory { - fun create( - repo: Repo, - module: OnlineModule, - ): ModuleViewModel + @Composable + fun LocalProvider( + repo: Repo, + module: OnlineModule, + scope: @Composable (ModuleViewModel) -> Unit, + ) { + val vm = build(repo, module) + CompositionLocalProvider(local provides vm) { + scope(vm) + } } - companion object { - @Composable - fun build( - repo: Repo, - module: OnlineModule, - ): ModuleViewModel = - hiltViewModel { factory -> - factory.create(repo, module) - } - } + private val local = + staticCompositionLocalOf { error("No ModulesViewModel found!") } + + @get:Composable + val current: ModuleViewModel get() = local.current } +} From d8d6c7391166cc79a754a69dce4bd01c2ca4e161 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:10:48 +0100 Subject: [PATCH 32/55] Handle download permission failures Start downloads without requesting notification permission, and propagate storage permission denials and other download failures to callers. Slightly thicken the module view divider. --- .../mmrl/service/DownloadService.kt | 27 ++++++++++++++----- .../ui/screens/moduleView/NewViewScreen.kt | 2 +- .../moduleView/items/rememberDownload.kt | 27 +++++++++++-------- .../mmrl/viewmodel/ModuleViewModel.kt | 3 ++- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/service/DownloadService.kt b/app/src/main/kotlin/com/dergoogler/mmrl/service/DownloadService.kt index 0b9c48433..2277f6198 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/service/DownloadService.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/service/DownloadService.kt @@ -279,28 +279,41 @@ class DownloadService : LifecycleService() { progress } + fun start( context: Context, task: TaskItem, listener: IDownloadListener, ) { val permissions = mutableListOf() + if (Build.VERSION.SDK_INT <= 29) { permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE) } - if (BuildCompat.atLeastT) { - permissions.add(Manifest.permission.POST_NOTIFICATIONS) + + fun startDownload() { + val intent = Intent(context, DownloadService::class.java) + intent.putExtra(EXTRA_TASK, task) + + listeners[task] = listener + context.startService(intent) + } + + if (permissions.isEmpty()) { + startDownload() + return } PermissionCompat.requestPermissions(context, permissions) { state -> if (state.allGranted) { - val intent = Intent(context, DownloadService::class.java) - intent.putExtra(EXTRA_TASK, task) - - listeners[task] = listener - context.startService(intent) + startDownload() + } else { + listener.onFailure( + SecurityException("Storage permission denied") + ) } } } + } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt index 6217466ac..18795b7b9 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/NewViewScreen.kt @@ -206,7 +206,7 @@ fun NewViewScreen( modifier = Modifier .padding(vertical = 16.dp) - .height(0.9.dp) + .height(1.2.dp) .fillMaxWidth(), ) } else { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt index 1ae8038ad..ceb119223 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/items/rememberDownload.kt @@ -9,22 +9,27 @@ import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.viewmodel.ModuleViewModel @Composable -fun rememberDownload(): (VersionItem, Boolean) -> Unit { +fun rememberDownload(onFailure: (Throwable) -> Unit = {}): (VersionItem, Boolean) -> Unit { val context = LocalContext.current val vm = ModuleViewModel.current return remember { { item, install -> - vm.downloader(context, item) { - if (install) { - vm.installConfirm = false - InstallActivity.start( - context = context, - uri = it.toUri(), - confirm = false, - ) - } - } + vm.downloader( + context = context, + item = item, + onSuccess = { + if (install) { + vm.installConfirm = false + InstallActivity.start( + context = context, + uri = it.toUri(), + confirm = false, + ) + } + }, + onFailure = onFailure + ) } } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt index 857ffe413..9f7c66771 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ModuleViewModel.kt @@ -223,6 +223,7 @@ constructor( context: Context, item: VersionItem, onSuccess: (File) -> Unit, + onFailure: (Throwable) -> Unit = {}, ) { viewModelScope.launch { val downloadPath = @@ -271,7 +272,7 @@ constructor( } override fun onFailure(e: Throwable) { - Timber.d(e) + onFailure(e) } } From d7136a4d846d540571211365dd65fbcfd68c7fd7 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:36:14 +0100 Subject: [PATCH 33/55] fix: when ptr is used with fadePinnedScrollbehavior the toolbar background stayed transparent --- .../com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt | 6 +++--- gradle/libs.versions.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt index b3c9c66b7..4762cfbdb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt @@ -14,9 +14,6 @@ import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.padding import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.pulltorefresh.PullToRefreshBox -import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator -import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect @@ -51,8 +48,11 @@ import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ModulesViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph +import dev.mmrlx.compose.ui.PullToRefreshBox +import dev.mmrlx.compose.ui.PullToRefreshDefaults.Indicator import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.rememberPullToRefreshState import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9b0c2cd07..9bbed77cf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.245" +mmrlx = "1.0.246" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 8b123a13c36d995fb6a91afaf662c243b6e75ef8 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 17:38:04 +0100 Subject: [PATCH 34/55] Refresh detailed module cards Rework module details with MMRLX components, responsive badges, and updated star/date metadata. Add a branch icon and upgrade MMRLX to 1.0.247. --- .../screens/repository/ModuleItemDetailed.kt | 383 +++++++++++------- .../mmrl/ui/screens/repository/ModulesList.kt | 2 +- app/src/main/res/drawable/git_branch.xml | 48 +++ gradle/libs.versions.toml | 2 +- 4 files changed, 296 insertions(+), 139 deletions(-) create mode 100644 app/src/main/res/drawable/git_branch.xml diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt index 1baa8f62d..bb3e81159 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt @@ -1,14 +1,16 @@ package com.dergoogler.mmrl.ui.screens.repository +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Icon +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.widthIn import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -20,23 +22,26 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.style.TextDecoration -import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.addIfNotThere import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.isNotNullOrEmpty import com.dergoogler.mmrl.ext.nullable +import com.dergoogler.mmrl.ext.toFormattedDateSafely import com.dergoogler.mmrl.ui.component.Cover -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.LabelItemDefaults -import com.dergoogler.mmrl.ui.component.card.Card -import com.dergoogler.mmrl.ui.component.text.BBCodeText -import com.dergoogler.mmrl.ui.component.text.IconText import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModuleState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.dergoogler.mmrl.utils.toFormattedDateSafely +import dev.mmrlx.compose.layout.flashlightCard +import dev.mmrlx.compose.ui.Avatar +import dev.mmrlx.compose.ui.Badge +import dev.mmrlx.compose.ui.BadgeVariant +import dev.mmrlx.compose.ui.HorizontalDivider +import dev.mmrlx.compose.ui.LocalTextStyle +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.text.FormatText +import dev.mmrlx.compose.ui.theme.MMRLXTheme enum class LabelType { LICENSE, @@ -65,22 +70,41 @@ fun ModuleItemDetailed( val showAntifeaturesLabel = module.track.hasAntifeatures && menu.showAntiFeatures val showCategoryLabel = module.categories.isNotNullOrEmpty() && menu.showCategory - val labelsToShow = remember { mutableListOf() } - if (showLicenseLabel) labelsToShow.addIfNotThere(LabelType.LICENSE) - if (showInstalledLabel) labelsToShow.addIfNotThere(LabelType.INSTALLED) - if (showAntifeaturesLabel) labelsToShow.addIfNotThere(LabelType.ANTIFEATURES) - if (showCategoryLabel) labelsToShow.addIfNotThere(LabelType.CATEGORY) - if (state.updatable) labelsToShow.addIfNotThere(LabelType.UPDATABLE) + val labelsToShow = buildList { + if (showLicenseLabel) { + add(LabelType.LICENSE) + } + + if (showInstalledLabel) { + add(LabelType.INSTALLED) + } + + if (showAntifeaturesLabel) { + add(LabelType.ANTIFEATURES) + } + + if (showCategoryLabel) { + add(LabelType.CATEGORY) + } + + if (state.updatable) { + add(LabelType.UPDATABLE) + } + } val hasLabel = labelsToShow.isNotEmpty() - Card( - enabled = enabled, - onClick = onClick, + Box( + modifier = Modifier + .combinedClickable( + onClick = onClick, + enabled = enabled + ) + .widthIn(600.dp) + .fillMaxWidth() + .flashlightCard() ) { - Column( - modifier = Modifier.relative(), - ) { + Column { module.cover.nullable(menu.showCover) { if (it.isNotEmpty()) { Cover( @@ -102,150 +126,235 @@ fun ModuleItemDetailed( } } - Row( - modifier = Modifier.padding(all = 16.dp), - verticalAlignment = Alignment.CenterVertically, + Column( + modifier = + Modifier + .padding(all = 16.dp) + .alpha(alpha = alpha), + verticalArrangement = Arrangement.spacedBy(2.dp), ) { - Column( - modifier = - Modifier - .alpha(alpha = alpha) - .weight(1f), - verticalArrangement = Arrangement.spacedBy(2.dp), + Row( + modifier = Modifier.padding(bottom = 8.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(16.dp) ) { - IconText( - style = - MaterialTheme.typography.titleSmall.copy( - textDecoration = decoration, - ), - tint = MaterialTheme.colorScheme.surfaceTint, - alignment = Alignment.End, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - text = module.name, - resId = isVerified nullable R.drawable.rosette_discount_check, - ) + if (menu.showIcon) { + Avatar( + initials = module.name.take( + 2 + ).uppercase(), + size = 36.dp, + //painter = module.icon?.toPainter() + ) + } - Text( - text = - stringResource( - id = R.string.module_version_author, - module.versionDisplay, - module.author, - ), - style = MaterialTheme.typography.bodySmall, - textDecoration = decoration, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) + Column { + FormatText( + text = buildString { +// if (module.metaModule) { +// append("%y ") +// } + append(module.name) + if (isVerified) { + append(" %y") + } + }, + style = MMRLXTheme.typography.titleSmall + ) { +// if (module.metaModule) { +// composable { +// Badge( +// text = "M", +// variant = BadgeVariant.Secondary, +// ) +// } +// } - if (menu.showUpdatedTime) { - BBCodeText( - style = MaterialTheme.typography.bodySmall, - textDecoration = decoration, - color = MaterialTheme.colorScheme.outline, - text = state.lastUpdated.toFormattedDateSafely + if (module.stars != null && menu.showStars) " • [icon=star] ${module.stars}" else "", - iconContent = { - if (it == "star") { + if (isVerified) { + composable { Icon( - painter = painterResource(id = R.drawable.star), + modifier = Modifier.size(fontSize.dp), + painter = painterResource(id = R.drawable.rosette_discount_check), contentDescription = null, + tint = MaterialTheme.colorScheme.surfaceTint ) } } + } + + Text( + text = stringResource( + id = R.string.module_version_author, + module.versionDisplay, + module.author, + ), + style = MMRLXTheme.typography.labelSmall, + color = MMRLXTheme.colors.mutedForeground ) } } - } - Text( - modifier = - Modifier - .alpha(alpha = alpha) - .padding(end = 16.dp, bottom = 16.dp, start = 16.dp), - text = - module.description + Text( + modifier = Modifier.padding(top = 8.dp, bottom = 4.dp), + text = module.description ?: stringResource(R.string.view_module_no_description), - maxLines = 5, - overflow = TextOverflow.Ellipsis, - style = - MaterialTheme.typography.bodySmall.apply { + style = MMRLXTheme.typography.bodySmall.apply { if (module.description.isNullOrBlank()) { copy( fontStyle = FontStyle.Italic, ) } - }, - textDecoration = decoration, - color = MaterialTheme.colorScheme.outline, - ) - - Spacer(modifier = Modifier.weight(1f)) - - if (hasLabel) { - Row( - modifier = - Modifier - .padding(end = 16.dp, bottom = 16.dp, start = 16.dp) - .fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - labelsToShow.forEach { labelType -> - when (labelType) { - LabelType.CATEGORY -> - module.categories - ?.firstOrNull() - .nullable { category -> - LabelItem( - icon = R.drawable.category, - text = category, - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.secondaryContainer, - contentColor = MaterialTheme.colorScheme.onSecondaryContainer, - ), - ) - } + } + ) - LabelType.LICENSE -> - module.license.nullable { license -> - LabelItem( - icon = R.drawable.tag, - text = license, - ) - } + val stats = remember(menu) { + buildString { + if (menu.showStars && module.stars != null) { + append("%y %s") + } + if ((menu.showStars && module.stars != null) && menu.showUpdatedTime) { + append(" %s ") + } + if (menu.showUpdatedTime) { + append("%y %s") + } + } + } - LabelType.ANTIFEATURES -> - LabelItem( - icon = R.drawable.alert_triangle, - text = stringResource(id = R.string.view_module_antifeatures), - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.onTertiary, - contentColor = MaterialTheme.colorScheme.onTertiaryContainer, - ), + if (stats.isNotEmpty()) { + FormatText( + modifier = Modifier.padding(top = 4.dp, bottom = 8.dp), + text = stats, + style = MMRLXTheme.typography.labelSmall, + color = MMRLXTheme.colors.mutedForeground + ) { + if (menu.showStars && module.stars != null) { + composable { + Icon( + modifier = Modifier.size(fontSize.dp), + painter = painterResource(R.drawable.star), + tint = MMRLXTheme.colors.mutedForeground ) + } + string(module.stars.toString()) + } - LabelType.INSTALLED -> - LabelItem( - text = stringResource(id = R.string.module_installed), - ) + if ((menu.showStars && module.stars != null) && menu.showUpdatedTime) { + string("•") + } - LabelType.UPDATABLE -> - LabelItem( - text = stringResource(id = R.string.module_new), - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.error, - contentColor = MaterialTheme.colorScheme.onError, - ), + if (menu.showUpdatedTime) { + composable { + Icon( + modifier = Modifier.size(fontSize.dp), + painter = painterResource(R.drawable.git_branch), + tint = MMRLXTheme.colors.mutedForeground ) + } + string(state.lastUpdated.toFormattedDateSafely(userPreferences.datePattern)) } } } - Spacer(modifier = Modifier.weight(1f)) + HorizontalDivider(Modifier.padding(top = 8.dp)) + + if (hasLabel) { + FlowRow( + modifier = + Modifier + .padding(top = 8.dp) + .fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(4.dp), + ) { + labelsToShow.forEach { labelType -> + when (labelType) { + LabelType.CATEGORY -> { + module.categories + ?.firstOrNull() + .nullable { category -> + Badge( + variant = BadgeVariant.Secondary + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy( + 4.dp + ) + ) { + Icon( + modifier = Modifier.sizeByFontSize(), + painter = painterResource(R.drawable.category) + ) + Text(text = category) + } + } + } + } + + LabelType.LICENSE -> { + module.license.nullable { license -> + Badge( + modifier = Modifier.widthIn(max = 100.dp), + variant = BadgeVariant.Default + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy( + 4.dp + ) + ) { + Icon( + modifier = Modifier.sizeByFontSize(), + painter = painterResource(R.drawable.tag) + ) + Text(text = license) + } + } + } + } + + LabelType.ANTIFEATURES -> { + Badge( + variant = BadgeVariant.Warning + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy( + 4.dp + ) + ) { + Icon( + modifier = Modifier.sizeByFontSize(), + painter = painterResource(R.drawable.alert_triangle) + ) + Text(text = stringResource(id = R.string.view_module_antifeatures)) + } + } + } + + LabelType.INSTALLED -> { + Badge( + variant = BadgeVariant.Default + ) { + Text(text = stringResource(id = R.string.module_installed)) + } + } + + LabelType.UPDATABLE -> { + Badge( + variant = BadgeVariant.Outline + ) { + Text(text = stringResource(id = R.string.module_new)) + } + } + } + } + } + } } } } } + +@Composable +fun Modifier.sizeByFontSize() = this.size(LocalTextStyle.current.fontSize.value.dp) \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index 4849f60ac..e5f9a4f46 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -47,7 +47,7 @@ fun ScaffoldScope.ModulesList( PaddingValues( bottom = this@ModulesList.scaffoldBottomPadding + 16.dp, ), - verticalArrangement = Arrangement.spacedBy(16.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), ) { beforeContent() diff --git a/app/src/main/res/drawable/git_branch.xml b/app/src/main/res/drawable/git_branch.xml new file mode 100644 index 000000000..42d19fbd8 --- /dev/null +++ b/app/src/main/res/drawable/git_branch.xml @@ -0,0 +1,48 @@ + + + + + + + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9bbed77cf..f5c7a8e14 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.246" +mmrlx = "1.0.247" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 10e8f7df64059b91d38da38a021275c9f11cb462 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 18:07:15 +0100 Subject: [PATCH 35/55] Migrate repository menu to MMRLX components Add MenuChip1, a FilterChip-based chip built on the MMRLX compose UI library, and use it in RepositoryMenu. The menu bottom sheet now uses rememberModalBottomSheet, MMRLXTheme typography and the MMRLX SegmentedButtons. Remove the repo list mode (compact/detailed) selector. ModulesList now always renders ModuleItemDetailed. In ModuleItemDetailed, the divider is now shown only when labels are present. --- .../dergoogler/mmrl/ui/component/MenuChip1.kt | 62 +++++++++++ .../screens/repository/ModuleItemDetailed.kt | 3 +- .../mmrl/ui/screens/repository/ModulesList.kt | 15 +-- .../ui/screens/repository/RepositoryMenu.kt | 101 +++++------------- 4 files changed, 95 insertions(+), 86 deletions(-) create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/component/MenuChip1.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/MenuChip1.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/MenuChip1.kt new file mode 100644 index 000000000..47ab72225 --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/MenuChip1.kt @@ -0,0 +1,62 @@ +package com.dergoogler.mmrl.ui.component + +import androidx.compose.foundation.Canvas +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import dev.mmrlx.compose.ui.chip.FilterChip +import dev.mmrlx.compose.ui.chip.FilterChipDefaults +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.theme.LocalContentColor + +@Composable +fun MenuChip1( + selected: Boolean, + onClick: () -> Unit, + label: @Composable () -> Unit, + modifier: Modifier = Modifier, + enabled: Boolean = true, +) { + FilterChip( + selected = selected, + onClick = onClick, + label = label, + modifier = modifier.height(FilterChipDefaults.Height), + enabled = enabled, + leadingIcon = { + if (!selected) { + Point1(size = 8.dp) + } + }, + trailingIcon = { + if (selected) { + Icon( + painter = painterResource(dev.mmrlx.ui.R.drawable.done), + contentDescription = null, + modifier = Modifier.size(FilterChipDefaults.IconSize), + ) + } + }, + shape = CircleShape, + ) +} + +@Composable +private fun Point1( + size: Dp, + color: Color = LocalContentColor.current, +) = Canvas( + modifier = Modifier.size(size), +) { + drawCircle( + color = color, + radius = this.size.width / 2, + center = this.center, + ) +} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt index bb3e81159..23c3b24f0 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt @@ -256,9 +256,10 @@ fun ModuleItemDetailed( } } - HorizontalDivider(Modifier.padding(top = 8.dp)) if (hasLabel) { + HorizontalDivider(Modifier.padding(top = 8.dp)) + FlowRow( modifier = Modifier diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index e5f9a4f46..7791410f9 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -15,7 +15,6 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.database.entity.Repo -import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.state.OnlineState import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator @@ -66,17 +65,9 @@ fun ScaffoldScope.ModulesList( } Box(Modifier.padding(horizontal = 16.dp)) { - when (menu.repoListMode) { - RepoListMode.Compact -> - ModuleItemCompact( - onClick = click, - ) - - RepoListMode.Detailed -> - ModuleItemDetailed( - onClick = click, - ) - } + ModuleItemDetailed( + onClick = click, + ) } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt index b6376bc9a..fad97503b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryMenu.kt @@ -2,16 +2,12 @@ package com.dergoogler.mmrl.ui.screens.repository import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.FlowRow import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -19,35 +15,31 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.datastore.model.Option -import com.dergoogler.mmrl.datastore.model.RepoListMode import com.dergoogler.mmrl.datastore.model.RepositoryMenu -import com.dergoogler.mmrl.ui.component.BottomSheet -import com.dergoogler.mmrl.ui.component.MenuChip -import com.dergoogler.mmrl.ui.component.Segment -import com.dergoogler.mmrl.ui.component.SegmentedButtons -import com.dergoogler.mmrl.ui.component.SegmentedButtonsDefaults +import com.dergoogler.mmrl.ui.component.MenuChip1 import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.button.Segment +import dev.mmrlx.compose.ui.button.SegmentedButtons +import dev.mmrlx.compose.ui.dialog.rememberModalBottomSheet import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun RepositoryMenu(setMenu: (RepositoryMenu) -> Unit) { - val userPreferences = LocalUserPreferences.current - var open by rememberSaveable { mutableStateOf(false) } + val sheet = rememberModalBottomSheet() IconButton( - onClick = { open = true }, + onClick = { sheet.open() }, ) { Icon( painter = painterResource(id = R.drawable.filter_outlined), contentDescription = null, ) - if (open) { + sheet { MenuBottomSheet( - onClose = { open = false }, - menu = userPreferences.repositoryMenu, setMenu = setMenu, ) } @@ -55,11 +47,12 @@ fun RepositoryMenu(setMenu: (RepositoryMenu) -> Unit) { } @Composable -private fun MenuBottomSheet( - onClose: () -> Unit, - menu: RepositoryMenu, +private fun ColumnScope.MenuBottomSheet( setMenu: (RepositoryMenu) -> Unit, -) = BottomSheet(onDismissRequest = onClose) { +) { + val userPreferences = LocalUserPreferences.current + val menu = userPreferences.repositoryMenu + val options = listOf( Option.Name to R.string.menu_sort_option_name, @@ -67,15 +60,9 @@ private fun MenuBottomSheet( Option.Size to R.string.menu_sort_option_size, ) - val optionsRepoListMode = - listOf( - RepoListMode.Detailed to R.string.menu_sort_repolistmode_detailed, - RepoListMode.Compact to R.string.menu_sort_repolistmode_compact, - ) - Text( text = stringResource(id = R.string.menu_advanced_menu), - style = MaterialTheme.typography.headlineSmall, + style = MMRLXTheme.typography.headlineSmall, modifier = Modifier.align(Alignment.CenterHorizontally), ) @@ -85,46 +72,14 @@ private fun MenuBottomSheet( ) { Text( text = stringResource(id = R.string.menu_sort_mode), - style = MaterialTheme.typography.titleSmall, + style = MMRLXTheme.typography.titleSmall, ) - SegmentedButtons( - border = - SegmentedButtonsDefaults.border( - color = MaterialTheme.colorScheme.secondary, - ), - ) { + SegmentedButtons { options.forEach { (option, label) -> Segment( selected = option == menu.option, onClick = { setMenu(menu.copy(option = option)) }, - colors = - SegmentedButtonsDefaults.buttonColor( - selectedContainerColor = MaterialTheme.colorScheme.secondary, - selectedContentColor = MaterialTheme.colorScheme.onSecondary, - ), - icon = null, - ) { - Text(text = stringResource(id = label)) - } - } - } - - SegmentedButtons( - border = - SegmentedButtonsDefaults.border( - color = MaterialTheme.colorScheme.secondary, - ), - ) { - optionsRepoListMode.forEach { (repoListMode, label) -> - Segment( - selected = repoListMode == menu.repoListMode, - onClick = { setMenu(menu.copy(repoListMode = repoListMode)) }, - colors = - SegmentedButtonsDefaults.buttonColor( - selectedContainerColor = MaterialTheme.colorScheme.secondary, - selectedContentColor = MaterialTheme.colorScheme.onSecondary, - ), icon = null, ) { Text(text = stringResource(id = label)) @@ -140,67 +95,67 @@ private fun MenuBottomSheet( horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp), ) { - MenuChip( + MenuChip1( selected = menu.descending, onClick = { setMenu(menu.copy(descending = !menu.descending)) }, label = { Text(text = stringResource(id = R.string.menu_descending)) }, ) - MenuChip( + MenuChip1( selected = menu.pinInstalled, onClick = { setMenu(menu.copy(pinInstalled = !menu.pinInstalled)) }, label = { Text(text = stringResource(id = R.string.menu_pin_installed)) }, ) - MenuChip( + MenuChip1( selected = menu.pinUpdatable, onClick = { setMenu(menu.copy(pinUpdatable = !menu.pinUpdatable)) }, label = { Text(text = stringResource(id = R.string.menu_pin_updatable)) }, ) - MenuChip( + MenuChip1( selected = menu.showIcon, onClick = { setMenu(menu.copy(showIcon = !menu.showIcon)) }, label = { Text(text = stringResource(id = R.string.menu_show_icon)) }, ) - MenuChip( + MenuChip1( selected = menu.showCover, onClick = { setMenu(menu.copy(showCover = !menu.showCover)) }, label = { Text(text = stringResource(id = R.string.menu_show_cover)) }, ) - MenuChip( + MenuChip1( selected = menu.showVerified, onClick = { setMenu(menu.copy(showVerified = !menu.showVerified)) }, label = { Text(text = stringResource(id = R.string.menu_show_verified)) }, ) - MenuChip( + MenuChip1( selected = menu.showLicense, onClick = { setMenu(menu.copy(showLicense = !menu.showLicense)) }, label = { Text(text = stringResource(id = R.string.menu_show_license)) }, ) - MenuChip( + MenuChip1( selected = menu.showAntiFeatures, onClick = { setMenu(menu.copy(showAntiFeatures = !menu.showAntiFeatures)) }, label = { Text(text = stringResource(id = R.string.menu_show_antifeatures)) }, ) - MenuChip( + MenuChip1( selected = menu.showCategory, onClick = { setMenu(menu.copy(showCategory = !menu.showCategory)) }, label = { Text(text = stringResource(id = R.string.menu_show_category)) }, ) - MenuChip( + MenuChip1( selected = menu.showUpdatedTime, onClick = { setMenu(menu.copy(showUpdatedTime = !menu.showUpdatedTime)) }, label = { Text(text = stringResource(id = R.string.menu_show_updated)) }, ) - MenuChip( + MenuChip1( enabled = menu.showUpdatedTime, selected = menu.showStars, onClick = { setMenu(menu.copy(showStars = !menu.showStars)) }, From 2a022b5e98c5cecc12d1730e569d84d6a5f9896e Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 18:35:32 +0100 Subject: [PATCH 36/55] Provide RepositoryViewModel via CompositionLocal Add a `LocalProvider` and `current` accessor to RepositoryViewModel so child composables can read it without prop drilling. RepositoryScreen now wraps its content in the provider, and TopBar0 reads search state and actions from the view model instead of taking them as parameters. ModulesList also uses the view model: it adds top content padding while searching and drops the unused user preferences lookup. --- .../mmrl/ui/screens/repository/ModulesList.kt | 23 ++++---- .../ui/screens/repository/RepositoryScreen.kt | 57 ++++++------------- .../mmrl/viewmodel/RepositoryViewModel.kt | 18 ++++++ 3 files changed, 48 insertions(+), 50 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index 7791410f9..7a535f7e9 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -20,7 +20,7 @@ import com.dergoogler.mmrl.model.state.OnlineState import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalOnlineModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModuleState -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDestination import dev.mmrlx.compose.ui.scaffold.ScaffoldScope @@ -31,9 +31,9 @@ fun ScaffoldScope.ModulesList( state: LazyListState, beforeContent: LazyListScope.() -> Unit = {}, ) { + val vm = RepositoryViewModel.current val navigator = LocalDestinationsNavigator.current - val userPreferences = LocalUserPreferences.current - val menu = userPreferences.repositoryMenu + val isSearch by vm::isSearch Box( modifier = Modifier.fillMaxSize(), @@ -44,6 +44,7 @@ fun ScaffoldScope.ModulesList( .animateContentSize(), contentPadding = PaddingValues( + top = if (!isSearch) 0.dp else this@ModulesList.scaffoldTopPadding, bottom = this@ModulesList.scaffoldBottomPadding + 16.dp, ), verticalArrangement = Arrangement.spacedBy(8.dp), @@ -58,15 +59,15 @@ fun ScaffoldScope.ModulesList( LocalOnlineModuleState provides moduleState, LocalOnlineModule provides module, ) { - val click = fun() { - navigator.navigate( - NewViewScreenDestination(repo, module), - ) - } - - Box(Modifier.padding(horizontal = 16.dp)) { + Box( + modifier = Modifier.padding(horizontal = 16.dp) + ) { ModuleItemDetailed( - onClick = click, + onClick = { + navigator.navigate( + NewViewScreenDestination(repo, module), + ) + }, ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index c826f4a08..4006ba5a5 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -19,24 +19,20 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onGloballyPositioned -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.dergoogler.mmrl.R import com.dergoogler.mmrl.database.entity.Repo -import com.dergoogler.mmrl.datastore.model.RepositoryMenu import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.PageIndicator import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph -import dev.dergoogler.mmrl.compat.core.LocalUriHandler import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton import dev.mmrlx.compose.ui.scaffold.Scaffold @@ -48,37 +44,19 @@ import dev.mmrlx.compose.ui.toolbar.ToolbarTitle @Composable fun RepositoryScreen( repo: Repo, -) { - val userPreferences = LocalUserPreferences.current - val browser = LocalUriHandler.current - val density = LocalDensity.current - - val viewModel = RepositoryViewModel.build(repo) - val modules by viewModel.online.collectAsStateWithLifecycle() - - val query by viewModel.query.collectAsStateWithLifecycle() - val openSearch = viewModel::openSearch - val closeSearch = viewModel::closeSearch - val search = viewModel::search - val isSearch by viewModel::isSearch +) = RepositoryViewModel.LocalProvider(repo) { vm -> + val modules by vm.online.collectAsStateWithLifecycle() val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() - var coverHeight by remember { mutableIntStateOf(0) } - BackHandler(enabled = viewModel.isSearch, onBack = closeSearch) + val isSearch by vm::isSearch + BackHandler(enabled = vm.isSearch, onBack = vm::closeSearch) Scaffold( modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), toolbar = { TopBar0( - repo = repo, - isSearch = isSearch, - query = query, - onQueryChange = search, - onOpenSearch = openSearch, - onCloseSearch = closeSearch, scrollBehavior = scrollBehavior, - setMenu = viewModel::setRepositoryMenu, ) }, bottomBar = { @@ -103,7 +81,7 @@ fun RepositoryScreen( this@Scaffold.ModulesList( repo = repo, list = modules, - state = viewModel.listState, + state = vm.listState, ) { item { AnimatedVisibility(!isSearch, enter = scaleIn(), exit = scaleOut()) { @@ -232,15 +210,16 @@ fun RepositoryScreen( @Composable private fun TopBar0( - repo: Repo, - isSearch: Boolean, - query: String, - onQueryChange: (String) -> Unit, - onOpenSearch: () -> Unit, - onCloseSearch: () -> Unit, scrollBehavior: ToolbarScrollBehavior, - setMenu: (RepositoryMenu) -> Unit, ) { + val vm = RepositoryViewModel.current + + val query by vm.query.collectAsStateWithLifecycle() + val openSearch = vm::openSearch + val closeSearch = vm::closeSearch + val search = vm::search + val isSearch by vm::isSearch + var currentQuery by remember { mutableStateOf(query) } DisposableEffect(isSearch) { onDispose { currentQuery = "" } @@ -251,23 +230,23 @@ private fun TopBar0( query = currentQuery, scrollBehavior = scrollBehavior, onQueryChange = { - onQueryChange(it) + search(it) currentQuery = it }, onClose = { - onCloseSearch() + closeSearch() currentQuery = "" }, title = { ToolbarTitle( - title = repo.name, + title = vm.repo.name, modifier = Modifier.graphicsLayer { alpha = scrollBehavior.state.fade }, ) }, actions = { if (!isSearch) { IconButton( - onClick = onOpenSearch, + onClick = openSearch, ) { Icon( painter = painterResource(id = R.drawable.search), @@ -277,7 +256,7 @@ private fun TopBar0( } RepositoryMenu( - setMenu = setMenu, + setMenu = vm::setRepositoryMenu, ) }, ) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt index ef095f272..a056cb10f 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt @@ -3,9 +3,11 @@ package com.dergoogler.mmrl.viewmodel import android.app.Application import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.compose.runtime.staticCompositionLocalOf import androidx.lifecycle.viewModelScope import com.dergoogler.mmrl.database.entity.Repo import com.dergoogler.mmrl.datastore.UserPreferencesRepository @@ -191,5 +193,21 @@ constructor( androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> factory.create(repo) } + + private val local = + staticCompositionLocalOf { error("No RepositoryViewModel found!") } + + @get:Composable + val current: RepositoryViewModel get() = local.current + + @Composable + fun LocalProvider(repo: Repo, content: @Composable (RepositoryViewModel) -> Unit) { + val vm = build(repo) + CompositionLocalProvider( + local provides vm, + ) { + content(vm) + } + } } } From 2e7d9a2b0ecce1df5ea45862b834d4f4aea54046 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:23:54 +0100 Subject: [PATCH 37/55] Show module icons and add back button to repo ModuleItemDetailed now loads the module icon with Coil (memory and disk cache enabled) and falls back to the initials avatar if loading fails. The license text is limited to one line with an ellipsis. Added a Painter.isEmptyOrZero helper. RepositoryScreen's top bar now has a back navigation button that pops the back stack. --- .../screens/repository/ModuleItemDetailed.kt | 41 +++++++++++++++++-- .../ui/screens/repository/RepositoryScreen.kt | 10 +++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt index 23c3b24f0..29eff135e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt @@ -16,13 +16,21 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha +import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import coil.compose.AsyncImagePainter +import coil.compose.rememberAsyncImagePainter +import coil.request.CachePolicy +import coil.request.ImageRequest import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.isNotNullOrEmpty @@ -58,6 +66,7 @@ fun ModuleItemDetailed( decoration: TextDecoration = TextDecoration.None, enabled: Boolean = true, ) { + val context = LocalContext.current val module = LocalOnlineModule.current val state = LocalOnlineModuleState.current @@ -139,12 +148,27 @@ fun ModuleItemDetailed( horizontalArrangement = Arrangement.spacedBy(16.dp) ) { if (menu.showIcon) { + val painter = rememberAsyncImagePainter( + model = + ImageRequest + .Builder(context) + .data(module.icon) + .memoryCacheKey(module.icon) + .diskCacheKey(module.icon) + .diskCachePolicy(CachePolicy.ENABLED) + .memoryCachePolicy(CachePolicy.ENABLED) + .build(), + ) + + val isError = + remember(painter.state) { painter.state is AsyncImagePainter.State.Error } + Avatar( initials = module.name.take( 2 ).uppercase(), size = 36.dp, - //painter = module.icon?.toPainter() + painter = if (isError) null else painter, ) } @@ -308,7 +332,11 @@ fun ModuleItemDetailed( modifier = Modifier.sizeByFontSize(), painter = painterResource(R.drawable.tag) ) - Text(text = license) + Text( + text = license, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) } } } @@ -357,5 +385,12 @@ fun ModuleItemDetailed( } } +// TODO: export @Composable -fun Modifier.sizeByFontSize() = this.size(LocalTextStyle.current.fontSize.value.dp) \ No newline at end of file +fun Modifier.sizeByFontSize() = this.size(LocalTextStyle.current.fontSize.value.dp) + +// TODO: export +fun Painter.isEmptyOrZero(): Boolean { + val size = this.intrinsicSize + return size == Size.Unspecified || size.width == 0f || size.height == 0f +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index 4006ba5a5..459f5f7be 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -30,6 +30,7 @@ import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.PageIndicator import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar +import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph @@ -213,6 +214,7 @@ private fun TopBar0( scrollBehavior: ToolbarScrollBehavior, ) { val vm = RepositoryViewModel.current + val navigator = LocalDestinationsNavigator.current val query by vm.query.collectAsStateWithLifecycle() val openSearch = vm::openSearch @@ -243,6 +245,14 @@ private fun TopBar0( modifier = Modifier.graphicsLayer { alpha = scrollBehavior.state.fade }, ) }, + navigationIcon = { + IconButton(onClick = { navigator.popBackStack() }) { + Icon( + painter = painterResource(id = R.drawable.arrow_left), + contentDescription = null, + ) + } + }, actions = { if (!isSearch) { IconButton( From 4088f6bc94b17bbeb17c61f8644e5d34f16028e7 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:30:06 +0100 Subject: [PATCH 38/55] Align description screen colors with app theme Apply theme border, foreground, and code colors to additional Material color scheme roles. --- .../mmrl/ui/screens/moduleView/DescriptionScreen.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt index 8da2090a8..19bfe8717 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt @@ -51,12 +51,20 @@ fun DescriptionScreen(readmeUrl: String) { val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() val userPrefs = LocalUserPreferences.current + val border = MMRLXTheme.border val colors = MMRLXTheme.colors val scheme = MaterialTheme.colorScheme.copy( background = colors.background, onBackground = colors.foreground, surface = colors.code, - surfaceTint = colors.muted + surfaceTint = colors.muted, + outline = border.color, + outlineVariant = border.color, + onSurface = colors.foreground, + onSurfaceVariant = colors.mutedForeground, + surfaceVariant = colors.code, + inverseSurface = colors.code, + inverseOnSurface = colors.foreground, ) val wstate = From 1f47d48e8b997a57ef584ea933fec18b4dbb6c34 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:47:05 +0100 Subject: [PATCH 39/55] Block JavaScript namespaces in module descriptions Block the fs and webui namespaces in the description WebView and update mmrlx to 1.0.248. --- .../dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt | 2 ++ gradle/libs.versions.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt index 19bfe8717..2d29e3096 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/DescriptionScreen.kt @@ -78,6 +78,8 @@ fun DescriptionScreen(readmeUrl: String) { forceKillProcess = false useConsoleInterceptor = false darkMode = userPrefs.isDarkMode() + // default namespaces + blockedJavaScriptNamespaces += listOf("fs", "webui") } .client { // not related to client diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f5c7a8e14..d5fcb7fe3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.247" +mmrlx = "1.0.248" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 98d0d0836770b23ebec18bacdb47703b0db058fc Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 21:18:50 +0100 Subject: [PATCH 40/55] Use ZIP headers for update timestamps Fetch ZIP metadata with a HEAD request, falling back from Last-Modified to Date. Also configure redirect handling, compatible TLS, and a separate DNS bootstrap client. --- .../dergoogler/mmrl/model/json/UpdateJson.kt | 41 +++++++++++-------- .../dergoogler/mmrl/network/NetworkUtils.kt | 26 ++++++++++-- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/model/json/UpdateJson.kt b/app/src/main/kotlin/com/dergoogler/mmrl/model/json/UpdateJson.kt index 69d8dfdb9..5674981e8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/model/json/UpdateJson.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/model/json/UpdateJson.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.model.json +import android.util.Log import com.dergoogler.mmrl.model.online.VersionItem import com.dergoogler.mmrl.network.NetworkUtils import com.squareup.moshi.JsonClass @@ -39,28 +40,34 @@ data class UpdateJson( suspend fun loadToVersionItem(url: String): VersionItem? { if (!NetworkUtils.isUrl(url)) return null - val result = - NetworkUtils.request(url) { body, headers -> - val adapter = - Moshi - .Builder() - .build() - .adapter() + val result = NetworkUtils.request(url) { body, headers -> + val adapter = Moshi.Builder().build().adapter() + adapter.fromJson(body.string()) to headers + } + + if (!result.isSuccess) { + Log.d("UpdateJson", "request failed: ${result.exceptionOrNull()}") + return null + } - adapter.fromJson(body.string()) to headers - } + val (json, _) = result.getOrThrow() + if (json == null) return null - if (result.isSuccess) { - val (json, headers) = result.getOrThrow() - if (json != null) { - val t = headers.getInstant("Last-Modified")?.toEpochMilli() - val timestamp = (t ?: 0L) / 1000f + val zipResult = NetworkUtils.requestHead(json.zipUrl) - return json.toItemOrNull(timestamp) - } + if (!zipResult.isSuccess) { + Log.d("UpdateJson", "zip head request failed: ${zipResult.exceptionOrNull()}") + return null } - return null + val headers = zipResult.getOrThrow() + + val instant = headers.getInstant("Last-Modified") ?: headers.getInstant("Date") + val t = instant?.toEpochMilli() + val timestamp = (t ?: 0L) / 1000f + + return json.toItemOrNull(timestamp) } + } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/network/NetworkUtils.kt b/app/src/main/kotlin/com/dergoogler/mmrl/network/NetworkUtils.kt index d141819a4..8b6f915e6 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/network/NetworkUtils.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/network/NetworkUtils.kt @@ -49,7 +49,10 @@ object NetworkUtils { .matches(url) fun createOkHttpClient(): OkHttpClient { - val builder = OkHttpClient.Builder().cache(cacheOrNull) + val builder = OkHttpClient.Builder() + .cache(cacheOrNull) + .followRedirects(true) + .followSslRedirects(true) if (BuildConfig.DEBUG) { builder.addInterceptor( @@ -59,10 +62,11 @@ object NetworkUtils { }, ) } else { - builder.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS)) + builder.connectionSpecs(listOf(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS)) } - builder.dns(DnsResolver(builder.build(), useDoh)) + val bootstrapClient = OkHttpClient.Builder().build() + builder.dns(DnsResolver(bootstrapClient, useDoh)) builder.addInterceptor { chain -> val request = chain.request().newBuilder() @@ -74,6 +78,7 @@ object NetworkUtils { return builder.build() } + fun createRetrofit(): Retrofit.Builder { val client = createOkHttpClient() @@ -99,6 +104,21 @@ object NetworkUtils { } } + suspend fun requestHead(url: String): Result = withContext(Dispatchers.IO) { + runCatching { + val client = createOkHttpClient() + val request = Request.Builder() + .url(url) + .head() // Tells the server to only return headers, no body + .build() + + client.newCall(request).execute().use { response -> + if (!response.isSuccessful) throw Exception(response.toString()) + response.headers + } + } + } + suspend fun requestString(url: String) = request( url = url, From e40e21daf7588e7e94d444c0f14f6ffebb3c7fc6 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Fri, 6 Nov 2026 22:08:48 +0100 Subject: [PATCH 41/55] Paginate repository module listings Move repository search, sorting, and filtering into database queries and load modules incrementally as users scroll. Add search parsing tests and update mmrlx. --- app/build.gradle.kts | 1 + .../dergoogler/mmrl/database/dao/JoinDao.kt | 83 +++++++++ .../dergoogler/mmrl/database/dao/LocalDao.kt | 6 + .../mmrl/repository/LocalRepository.kt | 42 +++++ .../mmrl/repository/RepositorySearch.kt | 19 +++ .../mmrl/ui/screens/repository/ModulesList.kt | 30 ++++ .../ui/screens/repository/RepositoryScreen.kt | 23 ++- .../mmrl/viewmodel/RepositoryViewModel.kt | 158 ++++++++---------- .../mmrl/repository/RepositorySearchTest.kt | 20 +++ gradle/libs.versions.toml | 2 +- 10 files changed, 286 insertions(+), 98 deletions(-) create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/repository/RepositorySearch.kt create mode 100644 app/src/test/kotlin/com/dergoogler/mmrl/repository/RepositorySearchTest.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4ebd6c12f..df82a6e8e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -192,6 +192,7 @@ androidComponents { } dependencies { + testImplementation(libs.junit) implementation(libs.androidx.lifecycle.process) implementation(libs.androidx.swiperefreshlayout) compileOnly(projects.hiddenApi) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt b/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt index dc2496fa2..69af90ae3 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/JoinDao.kt @@ -9,6 +9,89 @@ import kotlinx.coroutines.flow.Flow @Dao interface JoinDao { + @Query( + """ + SELECT m.* + FROM onlineModules m + JOIN repos r ON m.repoUrl = r.url + LEFT JOIN localModules l ON l.id = m.id + LEFT JOIN localModules_updatable u ON u.id = m.id + WHERE r.enable = 1 AND r.version = :version AND (:repoUrl = '' OR m.repoUrl = :repoUrl) + AND (:repoUrl != '' OR NOT EXISTS ( + SELECT 1 FROM onlineModules other + JOIN repos otherRepo ON other.repoUrl = otherRepo.url + WHERE other.id = m.id AND otherRepo.enable = 1 AND otherRepo.version = :version + AND (other.versionCode > m.versionCode OR + (other.versionCode = m.versionCode AND other.rowid < m.rowid)) + )) + AND ( + (:prefix = '' AND (instr(lower(m.name), lower(:search)) > 0 + OR instr(lower(m.author), lower(:search)) > 0 + OR instr(lower(m.description), lower(:search)) > 0)) + OR (:prefix = 'id' AND m.id = :search COLLATE NOCASE) + OR (:prefix = 'name' AND m.name = :search COLLATE NOCASE) + OR (:prefix = 'author' AND m.author = :search COLLATE NOCASE) + OR (:prefix = 'category' AND m.categories LIKE :categoryPattern ESCAPE '\') + ) + ORDER BY + CASE WHEN :pinUpdatable AND l.author = m.author AND l.versionCode < m.versionCode + AND (u.updatable IS NULL OR u.updatable = 1) THEN 1 ELSE 0 END DESC, + CASE WHEN :pinInstalled AND l.author = m.author THEN 1 ELSE 0 END DESC, + CASE WHEN :sort = 'Name' AND NOT :descending THEN lower(m.name) END ASC, + CASE WHEN :sort = 'Name' AND :descending THEN lower(m.name) END DESC, + CASE WHEN :sort = 'UpdatedTime' AND NOT :descending THEN COALESCE( + (SELECT v.timestamp FROM versions v JOIN repos vr ON v.repoUrl = vr.url + WHERE v.id = m.id AND vr.enable = 1 AND vr.version = :version + AND (:repoUrl = '' OR v.repoUrl = m.repoUrl) + ORDER BY CASE WHEN :repoUrl = '' THEN v.versionCode END DESC, v.rowid LIMIT 1), 0) + END DESC, + CASE WHEN :sort = 'UpdatedTime' AND :descending THEN COALESCE( + (SELECT v.timestamp FROM versions v JOIN repos vr ON v.repoUrl = vr.url + WHERE v.id = m.id AND vr.enable = 1 AND vr.version = :version + AND (:repoUrl = '' OR v.repoUrl = m.repoUrl) + ORDER BY CASE WHEN :repoUrl = '' THEN v.versionCode END DESC, v.rowid LIMIT 1), 0) + END ASC, + m.rowid + LIMIT :limit OFFSET :offset + """, + ) + suspend fun getRepositoryPage( + repoUrl: String, + search: String, + prefix: String, + categoryPattern: String, + sort: String, + descending: Boolean, + pinInstalled: Boolean, + pinUpdatable: Boolean, + limit: Int, + offset: Int, + version: Int = ModulesJson.CURRENT_VERSION, + ): List + + @Query( + """ + SELECT (SELECT COUNT(*) FROM onlineModules) + (SELECT COUNT(*) FROM repos) + + (SELECT COUNT(*) FROM versions) + (SELECT COUNT(*) FROM localModules) + + (SELECT COUNT(*) FROM localModules_updatable) + """, + ) + fun observeRepositoryChanges(): Flow + + @Query( + """ + SELECT v.* FROM versions v JOIN repos r ON v.repoUrl = r.url + WHERE v.id IN (:ids) AND r.enable = 1 AND r.version = :version + AND (:repoUrl = '' OR v.repoUrl = :repoUrl) + ORDER BY CASE WHEN :repoUrl = '' THEN v.versionCode END DESC, v.rowid + """, + ) + suspend fun getRepositoryVersions( + ids: List, + repoUrl: String, + version: Int = ModulesJson.CURRENT_VERSION, + ): List + @Query( "SELECT m.* " + "FROM onlineModules m " + diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/LocalDao.kt b/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/LocalDao.kt index a901ec489..57372e1b8 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/LocalDao.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/database/dao/LocalDao.kt @@ -17,6 +17,12 @@ interface LocalDao { @Query("SELECT * FROM localModules") fun getAll(): List + @Query("SELECT * FROM localModules WHERE id IN (:ids)") + suspend fun getByIds(ids: List): List + + @Query("SELECT * FROM localModules_updatable WHERE id IN (:ids)") + suspend fun getUpdatableTagsByIds(ids: List): List + @Query("SELECT * FROM localModules WHERE id = :id LIMIT 1") suspend fun getByIdOrNull(id: String): LocalModuleEntity? diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt b/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt index 62a27d472..6317ee764 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/repository/LocalRepository.kt @@ -16,6 +16,9 @@ import com.dergoogler.mmrl.ext.merge import com.dergoogler.mmrl.model.local.LocalModule import com.dergoogler.mmrl.model.online.Blacklist import com.dergoogler.mmrl.model.online.OnlineModule +import com.dergoogler.mmrl.model.state.OnlineState +import com.dergoogler.mmrl.model.state.OnlineState.Companion.createState +import com.dergoogler.mmrl.datastore.model.RepositoryMenu import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map @@ -163,6 +166,45 @@ constructor( values } + fun observeRepositoryChanges() = joinDao.observeRepositoryChanges() + + suspend fun getRepositoryPage( + repoUrl: String, + search: RepositorySearch, + menu: RepositoryMenu, + offset: Int, + limit: Int, + ): Pair>, Boolean> = + withContext(Dispatchers.IO) { + val entities = joinDao.getRepositoryPage( + repoUrl = repoUrl, + search = search.text, + prefix = search.prefix, + categoryPattern = search.categoryPattern, + sort = menu.option.name, + descending = menu.descending, + pinInstalled = menu.pinInstalled, + pinUpdatable = menu.pinUpdatable, + offset = offset, + limit = limit, + ) + val hasMore = entities.size == limit + val page = entities + if (page.isEmpty()) return@withContext emptyList>() to false + val ids = page.map { it.id } + val versions = joinDao.getRepositoryVersions(ids, repoUrl).groupBy { it.id } + val locals = localDao.getByIds(ids).associateBy { it.id } + val tags = localDao.getUpdatableTagsByIds(ids).associateBy { it.id } + val modules = page.map { entity -> + val module = entity.toModule(versions[entity.id].orEmpty().map { it.toItem() }) + module.createState( + local = locals[entity.id]?.toModule(), + hasUpdatableTag = tags[entity.id]?.updatable != false, + ) to module + } + modules to hasMore + } + fun getOnlineAllByUrlAsFlow(repoUrl: String): Flow> = joinDao.getOnlineAllByUrlAsFlow(repoUrl).map { entityList -> val allVersions = getVersionsByRepoUrl(repoUrl) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/repository/RepositorySearch.kt b/app/src/main/kotlin/com/dergoogler/mmrl/repository/RepositorySearch.kt new file mode 100644 index 000000000..1f1df3c26 --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/repository/RepositorySearch.kt @@ -0,0 +1,19 @@ +package com.dergoogler.mmrl.repository + +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +data class RepositorySearch(val text: String, val prefix: String, val categoryPattern: String) { + companion object { + fun parse(raw: String): RepositorySearch { + val prefix = listOf("id", "name", "author", "category") + .firstOrNull { raw.startsWith("$it:", ignoreCase = true) }.orEmpty() + val text = if (prefix.isEmpty()) raw.trim() else raw.substringAfter(":").trim() + val category = Json.encodeToString(text) + .replace("\\", "\\\\") + .replace("%", "\\%") + .replace("_", "\\_") + return RepositorySearch(text, prefix, "%$category%") + } + } +} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index 7a535f7e9..f0334702c 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -5,13 +5,18 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.snapshotFlow +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.database.entity.Repo @@ -23,18 +28,33 @@ import com.dergoogler.mmrl.ui.providable.LocalOnlineModuleState import com.dergoogler.mmrl.viewmodel.RepositoryViewModel import com.ramcosta.composedestinations.generated.destinations.NewViewScreenDestination import dev.mmrlx.compose.ui.scaffold.ScaffoldScope +import kotlinx.coroutines.flow.distinctUntilChanged @Composable fun ScaffoldScope.ModulesList( repo: Repo, list: List>, state: LazyListState, + hasMore: Boolean, + isLoading: Boolean, beforeContent: LazyListScope.() -> Unit = {}, ) { val vm = RepositoryViewModel.current val navigator = LocalDestinationsNavigator.current val isSearch by vm::isSearch + LaunchedEffect(state, list.size, hasMore, isLoading) { + if (list.isNotEmpty() && hasMore && !isLoading) { + snapshotFlow { + val layout = state.layoutInfo + val lastVisible = layout.visibleItemsInfo.lastOrNull()?.index ?: -1 + lastVisible >= 0 && lastVisible >= layout.totalItemsCount - 4 + }.distinctUntilChanged().collect { nearEnd -> + if (nearEnd) vm.loadMore() + } + } + } + Box( modifier = Modifier.fillMaxSize(), ) { @@ -72,6 +92,16 @@ fun ScaffoldScope.ModulesList( } } } + if (isLoading) { + item { + Box( + modifier = Modifier.fillMaxWidth().padding(16.dp), + contentAlignment = Alignment.Center, + ) { + CircularProgressIndicator() + } + } + } } } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index 459f5f7be..c93f403ff 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -6,6 +6,8 @@ import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue @@ -14,6 +16,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.Alignment import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer @@ -46,7 +49,9 @@ import dev.mmrlx.compose.ui.toolbar.ToolbarTitle fun RepositoryScreen( repo: Repo, ) = RepositoryViewModel.LocalProvider(repo) { vm -> - val modules by vm.online.collectAsStateWithLifecycle() + val page by vm.page.collectAsStateWithLifecycle() + val isLoading by vm.isLoading.collectAsStateWithLifecycle() + val modules = page.modules val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() var coverHeight by remember { mutableIntStateOf(0) } @@ -71,10 +76,16 @@ fun RepositoryScreen( .scaffoldHazeSource() ) { if (modules.isEmpty()) { - PageIndicator( - icon = R.drawable.cloud, - text = if (isSearch) R.string.search_empty else R.string.repository_empty, - ) + if (isLoading) { + Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { + CircularProgressIndicator() + } + } else { + PageIndicator( + icon = R.drawable.cloud, + text = if (isSearch) R.string.search_empty else R.string.repository_empty, + ) + } return@Scaffold } @@ -83,6 +94,8 @@ fun RepositoryScreen( repo = repo, list = modules, state = vm.listState, + hasMore = page.hasMore, + isLoading = isLoading, ) { item { AnimatedVisibility(!isSearch, enter = scaleIn(), exit = scaleOut()) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt index a056cb10f..2a7dd209a 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/RepositoryViewModel.kt @@ -11,26 +11,29 @@ import androidx.compose.runtime.staticCompositionLocalOf import androidx.lifecycle.viewModelScope import com.dergoogler.mmrl.database.entity.Repo import com.dergoogler.mmrl.datastore.UserPreferencesRepository -import com.dergoogler.mmrl.datastore.model.Option import com.dergoogler.mmrl.datastore.model.RepositoryMenu -import com.dergoogler.mmrl.model.json.UpdateJson import com.dergoogler.mmrl.model.online.OnlineModule import com.dergoogler.mmrl.model.state.OnlineState -import com.dergoogler.mmrl.model.state.OnlineState.Companion.createState import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository +import com.dergoogler.mmrl.repository.RepositorySearch import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch @@ -55,6 +58,10 @@ constructor( private val repositoryMenu = userPreferencesRepository.data.map { it.repositoryMenu } + .distinctUntilChanged { old, new -> + old.option == new.option && old.descending == new.descending && + old.pinInstalled == new.pinInstalled && old.pinUpdatable == new.pinUpdatable + } val listState: LazyListState = LazyListState() @@ -64,107 +71,65 @@ constructor( private val _isLoading = MutableStateFlow(true) val isLoading: StateFlow = _isLoading.asStateFlow() - private val onlineModules = - if (repo.url.isNotBlank()) { - localRepository.getOnlineAllByUrlAsFlow(repo.url) - } else { - localRepository.getOnlineAllAsFlow() - } - - val online: StateFlow>> = - combine( - onlineModules, - repositoryMenu, - keyFlow, - ) { modules, menu, key -> - val source = modules.map { module -> - val local = localRepository.getLocalByIdOrNull(module.id) - val versions = module.versions.toMutableList() - - if (local != null) { - UpdateJson.loadToVersionItem(local.updateJson)?.let { - it.moduleId = module.id - versions.add(0, it) - } - } - - val updatedModule = module.copy(versions = versions) - - updatedModule.createState( - local = local, - hasUpdatableTag = localRepository.hasUpdatableTag(module.id), - ) to updatedModule - } - - val sorted = source - .sortedWith(comparator(menu.option, menu.descending)) - .let { list -> - if (menu.pinInstalled) list.sortedByDescending { it.first.installed } else list - } - .let { list -> - if (menu.pinUpdatable) list.sortedByDescending { it.first.updatable } else list - } - - _isLoading.value = false - - if (key.isBlank()) { - sorted - } else { - val (searchKey, prefix) = parseSearchKey(key) - sorted.filter { (_, module) -> - when (prefix) { - "id" -> module.id.equals(searchKey, ignoreCase = true) - "name" -> module.name.equals(searchKey, ignoreCase = true) - "author" -> module.author.equals(searchKey, ignoreCase = true) - "category" -> module.categories?.any { - it.equals( - searchKey, - ignoreCase = true + class ModulePage( + val modules: List> = emptyList(), + val hasMore: Boolean = false, + val loadedThrough: Int = 0, + ) + + private val requestedCount = MutableStateFlow(PAGE_SIZE) + + @OptIn(ExperimentalCoroutinesApi::class) + val page: StateFlow = + combine(repositoryMenu, keyFlow) { menu, key -> menu to RepositorySearch.parse(key) } + .flatMapLatest { (menu, search) -> + localRepository.observeRepositoryChanges().flatMapLatest { + val loaded = mutableListOf>() + var hasMore = true + requestedCount.mapLatest { count -> + _isLoading.value = true + while (loaded.size < count && hasMore) { + val (modules, more) = localRepository.getRepositoryPage( + repoUrl = repo.url.takeUnless { it.isBlank() } ?: "", + search = search, + menu = menu, + offset = loaded.size, + limit = minOf(PAGE_SIZE, count - loaded.size), ) - } == true - - else -> module.name.contains(searchKey, ignoreCase = true) || - module.author.contains(searchKey, ignoreCase = true) || - module.description?.contains(searchKey, ignoreCase = true) == true + loaded.addAll(modules) + hasMore = more + } + _isLoading.value = false + ModulePage( + modules = loaded.take(count), + hasMore = hasMore || loaded.size > count, + loadedThrough = minOf(count, loaded.size), + ) } } } - } .onStart { _isLoading.value = true } .flowOn(Dispatchers.IO) .stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000), - initialValue = emptyList(), + initialValue = ModulePage(), ) - private fun parseSearchKey(raw: String): Pair { - val prefix = listOf("id", "name", "author", "category") - .firstOrNull { raw.startsWith("$it:", ignoreCase = true) } - - return if (prefix != null) { - raw.substringAfter(":").trim() to prefix - } else { - raw.trim() to null - } - } - - private fun comparator( - option: Option, - descending: Boolean, - ): Comparator> { - val base: Comparator> = - when (option) { - Option.Name -> compareBy { it.second.name.lowercase() } - Option.UpdatedTime -> compareByDescending { it.first.lastUpdated } - Option.Size -> compareByDescending { 0 } - } - - return if (descending) base.reversed() else base - } - fun search(key: String) { + if (keyFlow.value == key) return + _isLoading.value = true + requestedCount.value = PAGE_SIZE keyFlow.value = key + viewModelScope.launch { listState.scrollToItem(0) } + } + + fun loadMore() { + val current = page.value + if (!_isLoading.value && current.hasMore && requestedCount.value <= current.loadedThrough) { + _isLoading.value = true + requestedCount.value += PAGE_SIZE + } } fun openSearch() { @@ -173,11 +138,19 @@ constructor( fun closeSearch() { isSearch = false - keyFlow.value = "" + search("") } fun setRepositoryMenu(value: RepositoryMenu) { viewModelScope.launch { + val current = repositoryMenu.first() + if (current.option != value.option || current.descending != value.descending || + current.pinInstalled != value.pinInstalled || current.pinUpdatable != value.pinUpdatable + ) { + _isLoading.value = true + requestedCount.value = PAGE_SIZE + listState.scrollToItem(0) + } userPreferencesRepository.setRepositoryMenu(value) } } @@ -188,6 +161,7 @@ constructor( } companion object { + private const val PAGE_SIZE = 30 @Composable fun build(repo: Repo): RepositoryViewModel = androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> diff --git a/app/src/test/kotlin/com/dergoogler/mmrl/repository/RepositorySearchTest.kt b/app/src/test/kotlin/com/dergoogler/mmrl/repository/RepositorySearchTest.kt new file mode 100644 index 000000000..22bd8b396 --- /dev/null +++ b/app/src/test/kotlin/com/dergoogler/mmrl/repository/RepositorySearchTest.kt @@ -0,0 +1,20 @@ +package com.dergoogler.mmrl.repository + +import org.junit.Assert.assertEquals +import org.junit.Test + +class RepositorySearchTest { + @Test + fun parsesSearchPrefixesAndWhitespace() { + assertEquals(RepositorySearch("value", "id", "%\"value\"%"), RepositorySearch.parse("ID: value ")) + assertEquals(RepositorySearch("name:thing", "", "%\"name:thing\"%"), RepositorySearch.parse(" name:thing ")) + assertEquals(RepositorySearch("", "author", "%\"\"%"), RepositorySearch.parse("author: ")) + } + + @Test + fun escapesCategoryPatternsAndJsonCharacters() { + val search = RepositorySearch.parse("category:100%_\\tools") + assertEquals("category", search.prefix) + assertEquals("%\"100\\%\\_\\\\\\\\tools\"%", search.categoryPattern) + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d5fcb7fe3..1cab79a33 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.248" +mmrlx = "1.0.249" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 1dafd0c5581e54dea95d716fa0f0ce08a2286b88 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 18:52:06 +0100 Subject: [PATCH 42/55] Update module installation and terminal UI Refresh the installation screen and terminal logging, add a latest-version download action, and use explicit module manager binaries for shell commands. Update the MMRLX dependency and terminal view model providers. --- app/build.gradle.kts | 1 - .../terminal/install/InstallActivity.kt | 57 ++-- .../terminal/install/InstallScreen.kt | 291 +++++++++--------- .../moduleView/sections/AboutModule.kt | 8 +- .../ui/screens/moduleView/sections/Header.kt | 92 ++++-- .../mmrl/viewmodel/ActionViewModel.kt | 64 +++- .../mmrl/viewmodel/InstallViewModel.kt | 100 ++++-- .../mmrl/viewmodel/TerminalViewModel.kt | 69 ++++- app/src/main/res/values/strings_terminal.xml | 20 +- gradle/libs.versions.toml | 2 +- .../mmrl/platform/stub/IModuleManager.aidl | 1 + .../platform/manager/APatchModuleManager.kt | 12 +- .../platform/manager/KernelSUModuleManager.kt | 12 +- .../platform/manager/KsuNextModuleManager.kt | 2 +- .../platform/manager/MagiskModuleManager.kt | 6 +- 15 files changed, 457 insertions(+), 280 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index df82a6e8e..9eac79680 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -87,7 +87,6 @@ android { getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro" ) - resValue("string", "app_name", baseAppName) buildConfigField("Boolean", "IS_DEV_VERSION", "false") buildConfigField("Boolean", "IS_GOOGLE_PLAY_BUILD", "false") isDebuggable = false diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallActivity.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallActivity.kt index 7b84dad08..2816a40d0 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallActivity.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallActivity.kt @@ -4,14 +4,11 @@ import android.content.Context import android.content.Intent import android.net.Uri import android.os.Bundle -import android.util.Log -import androidx.activity.viewModels import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.lifecycleScope import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.tmpDir import com.dergoogler.mmrl.ui.activity.TerminalActivity import com.dergoogler.mmrl.ui.activity.setBaseContent import com.dergoogler.mmrl.ui.component.dialog.ConfirmDialog @@ -22,7 +19,6 @@ import timber.log.Timber class InstallActivity : TerminalActivity() { private var confirmDialog by mutableStateOf(true) - private val viewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { Timber.d("InstallActivity onCreate") @@ -40,8 +36,6 @@ class InstallActivity : TerminalActivity() { } } - Log.d(TAG, "InstallActivity onCreate: $uris") - val confirm = intent.getBooleanExtra("confirm", true) if (uris.isNullOrEmpty()) { @@ -49,41 +43,36 @@ class InstallActivity : TerminalActivity() { return } - if (!confirm) { - initModule(uris.toList()) - } - setBaseContent { - if (confirm && confirmDialog) { - ConfirmDialog( - title = R.string.install_screen_confirm_title, - description = R.string.install_screen_confirm_text, - onClose = { - confirmDialog = false - finish() - }, - onConfirm = { - confirmDialog = false - initModule(uris.toList()) - }, - ) - } + InstallViewModel.LocalProvider { + if (!confirm) { + it.initModule(uris.toList()) + } - InstallScreen(viewModel) - } - } + if (confirm && confirmDialog) { + ConfirmDialog( + title = R.string.install_screen_confirm_title, + description = R.string.install_screen_confirm_text, + onClose = { + confirmDialog = false + finish() + }, + onConfirm = { + confirmDialog = false + it.initModule(uris.toList()) + }, + ) + } - override fun onDestroy() { - Timber.d("InstallActivity onDestroy") - tmpDir.deleteRecursively() - viewModel.destroy() - super.onDestroy() + InstallScreen() + } + } } - private fun initModule(uris: List) { + private fun InstallViewModel.initModule(uris: List) { val job = lifecycleScope.launch { - viewModel.installModules( + installModules( uris = uris, ) } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt index c10393df8..9d8df35d1 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/install/InstallScreen.kt @@ -9,7 +9,6 @@ import androidx.compose.animation.scaleIn import androidx.compose.animation.scaleOut import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon @@ -17,8 +16,6 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf @@ -45,192 +42,192 @@ import com.dergoogler.mmrl.app.Event.Companion.isSucceeded import com.dergoogler.mmrl.ext.isScrollingUp import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ui.activity.MMRLComponentActivity -import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.dialog.ConfirmDialog -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurNavigateUpToolbar -import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.InstallViewModel -import dev.chrisbanes.haze.hazeSource import dev.mmrlx.compose.terminal.Terminal +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.theme.MMRLXTheme +import dev.mmrlx.compose.ui.toolbar.NavigateUpToolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import dev.mmrlx.terminal.TerminalEmulator.Companion.TERMINAL_CURSOR_STYLE_NONE import kotlinx.coroutines.launch @Composable -fun InstallScreen(viewModel: InstallViewModel) = - LocalScreenProvider { - val scope = rememberCoroutineScope() - val snackbarHostState = remember { SnackbarHostState() } - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() +fun InstallScreen() { + val vm = InstallViewModel.current + val scope = rememberCoroutineScope() + val snackbarHostState = remember { SnackbarHostState() } + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() - val userPreferences = LocalUserPreferences.current - val context = LocalContext.current + val userPreferences = LocalUserPreferences.current + val context = LocalContext.current - val focusRequester = remember { FocusRequester() } - val listState = rememberLazyListState() - val isScrollingUp by listState.isScrollingUp() - val showFab by remember { - derivedStateOf { - isScrollingUp && viewModel.event.isSucceeded - } + val focusRequester = remember { FocusRequester() } + val listState = rememberLazyListState() + val isScrollingUp by listState.isScrollingUp() + val showFab by remember { + derivedStateOf { + isScrollingUp && vm.event.isSucceeded } + } - var confirmReboot by remember { mutableStateOf(false) } - var cancelInstall by remember { mutableStateOf(false) } + var confirmReboot by remember { mutableStateOf(false) } + var cancelInstall by remember { mutableStateOf(false) } - val event = viewModel.event + val event = vm.event - val allowCancel = userPreferences.allowCancelInstall + val allowCancel = userPreferences.allowCancelInstall - LaunchedEffect(focusRequester) { - focusRequester.requestFocus() + LaunchedEffect(focusRequester) { + focusRequester.requestFocus() + } + + val backHandler = { + if (allowCancel) { + when { + event.isLoading /* && shell.isAlive */ -> cancelInstall = true + event.isFinished -> (context as MMRLComponentActivity).finish() + } + } else { + if (event.isFinished) { + (context as MMRLComponentActivity).finish() + } } + } - val backHandler = { - if (allowCancel) { - when { - event.isLoading /* && shell.isAlive */ -> cancelInstall = true - event.isFinished -> (context as MMRLComponentActivity).finish() - } - } else { - if (event.isFinished) { - (context as MMRLComponentActivity).finish() - } + BackHandler( + enabled = if (!allowCancel) event.isLoading else true, + onBack = backHandler, + ) + + val launcher = + rememberLauncherForActivityResult( + ActivityResultContracts.CreateDocument("*/*"), + ) { uri -> + if (uri == null) return@rememberLauncherForActivityResult + + scope.launch { + vm + .writeLogsTo(uri) + .onSuccess { + val message = context.getString(R.string.install_logs_saved) + snackbarHostState.showSnackbar( + message = message, + duration = SnackbarDuration.Short, + ) + }.onFailure { + val message = + context.getString( + R.string.install_logs_save_failed, + it.message ?: context.getString(R.string.unknown_error), + ) + snackbarHostState.showSnackbar( + message = message, + duration = SnackbarDuration.Short, + ) + } } } - BackHandler( - enabled = if (!allowCancel) event.isLoading else true, - onBack = backHandler, + if (confirmReboot) { + ConfirmDialog( + title = R.string.install_screen_reboot_title, + description = R.string.install_screen_reboot_text, + onClose = { confirmReboot = false }, + onConfirm = { + confirmReboot = false + vm.reboot() + }, ) + } - val launcher = - rememberLauncherForActivityResult( - ActivityResultContracts.CreateDocument("*/*"), - ) { uri -> - if (uri == null) return@rememberLauncherForActivityResult - + if (cancelInstall) { + ConfirmDialog( + title = R.string.install_screen_cancel_title, + description = R.string.install_screen_cancel_text, + onClose = { cancelInstall = false }, + onConfirm = { scope.launch { - viewModel - .writeLogsTo(uri) - .onSuccess { - val message = context.getString(R.string.install_logs_saved) - snackbarHostState.showSnackbar( - message = message, - duration = SnackbarDuration.Short, - ) - }.onFailure { - val message = - context.getString( - R.string.install_logs_save_failed, - it.message ?: context.getString(R.string.unknown_error), - ) - snackbarHostState.showSnackbar( - message = message, - duration = SnackbarDuration.Short, - ) - } + cancelInstall = false + // shell.close() } - } + }, + ) + } - if (confirmReboot) { - ConfirmDialog( - title = R.string.install_screen_reboot_title, - description = R.string.install_screen_reboot_text, - onClose = { confirmReboot = false }, - onConfirm = { - confirmReboot = false - viewModel.reboot() - }, - ) - } + Scaffold( + modifier = + Modifier + .onKeyEvent { + when (it.key) { + Key.VolumeUp, Key.VolumeDown -> event.isLoading - if (cancelInstall) { - ConfirmDialog( - title = R.string.install_screen_cancel_title, - description = R.string.install_screen_cancel_text, - onClose = { cancelInstall = false }, - onConfirm = { - scope.launch { - cancelInstall = false - // shell.close() + else -> false } - }, + } + .focusRequester(focusRequester) + .focusable() + .nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + TopBar0( + exportLog = { launcher.launch(vm.logfile) }, + event = event, + enable = if (!allowCancel) event.isFinished else true, + scrollBehavior = scrollBehavior, + onBack = backHandler, ) - } - - Scaffold( - modifier = - Modifier - .onKeyEvent { - when (it.key) { - Key.VolumeUp, Key.VolumeDown -> event.isLoading - - else -> false + }, + floatingActionButton = { + AnimatedVisibility( + visible = showFab, + enter = + scaleIn( + animationSpec = tween(100), + initialScale = 0.8f, + ), + exit = + scaleOut( + animationSpec = tween(100), + targetScale = 0.8f, + ), + ) { + FloatingButton( + reboot = { + if (userPreferences.confirmReboot) { + confirmReboot = true + } else { + vm.reboot() } - } - .focusRequester(focusRequester) - .focusable() - .nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - exportLog = { launcher.launch(viewModel.logfile) }, - event = event, - enable = if (!allowCancel) event.isFinished else true, - scrollBehavior = scrollBehavior, - onBack = backHandler, + }, ) - }, - floatingActionButton = { - AnimatedVisibility( - visible = showFab, - enter = - scaleIn( - animationSpec = tween(100), - initialScale = 0.8f, - ), - exit = - scaleOut( - animationSpec = tween(100), - targetScale = 0.8f, - ), - ) { - FloatingButton( - reboot = { - if (userPreferences.confirmReboot) { - confirmReboot = true - } else { - viewModel.reboot() - } - }, - ) - } - }, - snackbarHost = { SnackbarHost(snackbarHostState) }, - contentWindowInsets = WindowInsets.none, - ) { - Terminal( - modifier = Modifier - .hazeSource(LocalHazeState.current) - .padding(it) - ) { emu -> - emu.setCursorStyle(TERMINAL_CURSOR_STYLE_NONE) - viewModel.onEmulatorCreated(emu) } + }, + snackbarHost = { SnackbarHost(snackbarHostState) }, + contentWindowInsets = WindowInsets.none, + ) { + Terminal( + containerColor = MMRLXTheme.colors.background, + contentColor = MMRLXTheme.colors.foreground, + modifier = Modifier + .scaffoldHazeSource(), + contentPadding = contentPadding + ) { emu -> + emu.setCursorStyle(TERMINAL_CURSOR_STYLE_NONE) + vm.onEmulatorCreated(emu) } } +} @Composable -private fun TopBar( +private fun TopBar0( exportLog: () -> Unit, event: Event, onBack: () -> Unit, scrollBehavior: ToolbarScrollBehavior, enable: Boolean, -) = BlurNavigateUpToolbar( +) = NavigateUpToolbar( title = stringResource(id = R.string.install_screen_title), subtitle = stringResource( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt index fcb4b7986..09c3317d5 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.AssistChip -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -20,7 +19,6 @@ import com.dergoogler.mmrl.R import com.dergoogler.mmrl.model.online.hasCategories import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalOnlineModule -import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.screens.moduleView.listItemContentPaddingValues import com.ramcosta.composedestinations.generated.destinations.DescriptionScreenDestination import dev.mmrlx.compose.ui.Text @@ -30,10 +28,10 @@ import dev.mmrlx.compose.ui.list.component.ButtonItem import dev.mmrlx.compose.ui.list.component.Item import dev.mmrlx.compose.ui.list.component.item.Icon import dev.mmrlx.compose.ui.list.component.item.Title +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable internal fun AboutModule() { - val repo = LocalRepo.current val module = LocalOnlineModule.current val navigator = LocalDestinationsNavigator.current @@ -67,14 +65,14 @@ internal fun AboutModule() { module.description ?: stringResource(R.string.view_module_no_description), style = - MaterialTheme.typography.bodyMedium.apply { + MMRLXTheme.typography.bodyMedium.apply { if (module.description.isNullOrBlank()) { copy( fontStyle = FontStyle.Italic, ) } }, - color = MaterialTheme.colorScheme.outline, + color = MMRLXTheme.colors.secondaryForeground, ) module.hasCategories { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt index 453b6bdb3..6e7f70943 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt @@ -10,11 +10,9 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Button import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.remember @@ -34,14 +32,20 @@ import com.dergoogler.mmrl.model.online.isBlacklisted import com.dergoogler.mmrl.platform.content.LocalModule.Companion.isEmpty import com.dergoogler.mmrl.platform.content.isValid import com.dergoogler.mmrl.ui.component.Logo -import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalOnlineModule -import com.dergoogler.mmrl.ui.providable.LocalRepo import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.ui.providable.LocalVersionItem -import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel +import com.dergoogler.mmrl.ui.screens.moduleView.items.rememberDownload +import com.dergoogler.mmrl.viewmodel.ModuleViewModel import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.button.Button +import dev.mmrlx.compose.ui.button.ButtonVariant +import dev.mmrlx.compose.ui.button.Divider +import dev.mmrlx.compose.ui.button.HorizontalButtonGroup +import dev.mmrlx.compose.ui.dialog.Item +import dev.mmrlx.compose.ui.dialog.PopupMenu +import dev.mmrlx.compose.ui.dialog.rememberPopupMenuState import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.text.FormatText import dev.mmrlx.compose.ui.theme.MMRLXTheme @@ -49,12 +53,10 @@ import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable internal fun Header() { val userPreferences = LocalUserPreferences.current - val viewModel = LocalModuleViewModel.current - val repo = LocalRepo.current + val vm = ModuleViewModel.current val module = LocalOnlineModule.current val lastVersionItem = LocalVersionItem.current val local = LocalModule.current - val navigator = LocalDestinationsNavigator.current val density = LocalDensity.current val isBlacklisted by module.isBlacklisted @@ -144,21 +146,22 @@ internal fun Header() { it, it.state, ) { - viewModel.createModuleOps( + vm.createModuleOps( userPreferences.useShellForModuleStateChange, it, ) } - OutlinedButton( + Button( enabled = - viewModel.isProviderAlive && + vm.isProviderAlive && (!userPreferences.useShellForModuleStateChange || it.state != com.dergoogler.mmrl.model.local.State.REMOVE), modifier = Modifier .fillMaxWidth() .weight(1f), onClick = ops.change, + variant = ButtonVariant.Outline, ) { val style = LocalTextStyle.current val progressSize = @@ -194,20 +197,61 @@ internal fun Header() { else -> R.string.module_reinstall } - Button( - enabled = viewModel.isProviderAlive && !lastVersionItem.isEmpty && !isBlacklisted, - modifier = - Modifier - .fillMaxWidth() - .weight(1f), - onClick = { - viewModel.installConfirm = true - }, + val moreMenu = rememberPopupMenuState() + val download = rememberDownload() + + HorizontalButtonGroup( + modifier = Modifier.weight(1f) ) { - Text( - text = stringResource(id = buttonTextResId), - maxLines = 1, - ) + Button( + enabled = vm.isProviderAlive && !lastVersionItem.isEmpty && !isBlacklisted, + modifier = + Modifier + .fillMaxWidth() + .weight(1f), + shape = shape(0, 2), + variant = ButtonVariant.Default, + onClick = { + vm.installConfirm = true + }, + ) { + Text( + text = stringResource(id = buttonTextResId), + maxLines = 1, + ) + } + + Divider() + + Button( + onClick = { + moreMenu.open() + }, + shape = shape(1, 2), + variant = ButtonVariant.Default + ) { + Icon( + painter = painterResource(id = R.drawable.chevron_down), + contentDescription = null + ) + } + + PopupMenu( + state = moreMenu, + maxWidth = 220.dp + ) { + val latestVersionDownloadEnabled = vm.lastVersionItem != null + Item( + enabled = latestVersionDownloadEnabled, + icon = R.drawable.file_download, + title = "Download latest", + onClick = { + if (latestVersionDownloadEnabled) { + download(vm.lastVersionItem!!, false) + } + } + ) + } } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt index 150a76f0f..eb8241975 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt @@ -2,6 +2,11 @@ package com.dergoogler.mmrl.viewmodel import android.app.Application import android.os.Build +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.staticCompositionLocalOf import androidx.lifecycle.viewModelScope import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R @@ -15,7 +20,12 @@ import com.dergoogler.mmrl.platform.model.ModId import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository import com.topjohnwu.superuser.CallbackList +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel +import dev.mmrlx.compose.ui.theme.Colors +import dev.mmrlx.compose.ui.theme.MMRLXTheme import dev.mmrlx.terminal.newSuperUserPty import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first @@ -23,17 +33,25 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import timber.log.Timber import java.time.LocalDateTime -import javax.inject.Inject -@HiltViewModel +@HiltViewModel(assistedFactory = ActionViewModel.Factory::class) class ActionViewModel -@Inject +@AssistedInject constructor( + @Assisted mxColors: Colors, + @Assisted mdColors: ColorScheme, application: Application, localRepository: LocalRepository, modulesRepository: ModulesRepository, userPreferencesRepository: UserPreferencesRepository, -) : TerminalViewModel(application, localRepository, modulesRepository, userPreferencesRepository) { +) : TerminalViewModel( + mxColors, + mdColors, + application, + localRepository, + modulesRepository, + userPreferencesRepository +) { val logfile get() = "Action_${LocalDateTime.now()}.log" init { @@ -150,4 +168,42 @@ constructor( } return@withContext false } + + @AssistedFactory + interface Factory { + fun create( + mxColors: Colors, + mdColors: ColorScheme, + ): ActionViewModel + } + + companion object { + @Composable + fun build( + mxColors: Colors, + mdColors: ColorScheme, + ): ActionViewModel = + androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> + factory.create(mxColors, mdColors) + } + + private val local = + staticCompositionLocalOf { error("No ActionViewModel found!") } + + @get:Composable + val current: ActionViewModel get() = local.current + + @Composable + fun LocalProvider(content: @Composable (ActionViewModel) -> Unit) { + val mxColors = MMRLXTheme.colors + val mdColors = MaterialTheme.colorScheme + + val vm = build(mxColors, mdColors) + CompositionLocalProvider( + local provides vm, + ) { + content(vm) + } + } + } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt index f71a194d6..cfce06696 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt @@ -2,6 +2,11 @@ package com.dergoogler.mmrl.viewmodel import android.app.Application import android.net.Uri +import androidx.compose.material3.ColorScheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.staticCompositionLocalOf import androidx.lifecycle.viewModelScope import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R @@ -21,8 +26,13 @@ import com.dergoogler.mmrl.platform.file.SuFile import com.dergoogler.mmrl.platform.file.SuFile.Companion.toFormattedFileSize import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository -import com.topjohnwu.superuser.CallbackList +import dagger.assisted.Assisted +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel +import dev.mmrlx.compose.ui.theme.Colors +import dev.mmrlx.compose.ui.theme.MMRLXTheme +import dev.mmrlx.terminal.PtyListener import dev.mmrlx.terminal.newSuperUserPty import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first @@ -32,44 +42,36 @@ import kotlinx.coroutines.withContext import timber.log.Timber import java.io.File import java.time.LocalDateTime -import javax.inject.Inject -@HiltViewModel +@HiltViewModel(assistedFactory = InstallViewModel.Factory::class) class InstallViewModel -@Inject +@AssistedInject constructor( + @Assisted mxColors: Colors, + @Assisted mdColors: ColorScheme, application: Application, localRepository: LocalRepository, modulesRepository: ModulesRepository, userPreferencesRepository: UserPreferencesRepository, -) : TerminalViewModel(application, localRepository, modulesRepository, userPreferencesRepository) { +) : TerminalViewModel( + mxColors, + mdColors, + application, + localRepository, + modulesRepository, + userPreferencesRepository +) { val logfile get() = "Install_${LocalDateTime.now()}.log" - init { - Timber.d("InstallViewModel initialized") - } - - private val stdoutCallbackList = - object : CallbackList() { - override fun onAddElement(msg: String?) { - if (msg == null) return - - viewModelScope.launch { - log(msg) - } - } + private val listener = object : PtyListener { + override fun onStdout(data: ByteArray) { + log(data) } - private val stderrCallbackList = - object : CallbackList() { - override fun onAddElement(msg: String?) { - if (msg == null) return - - viewModelScope.launch { - devLog(msg) - } - } + override fun onStderr(data: ByteArray) { + devLog(data) } + } suspend fun installModules(uris: List) { if (!platformReadyDeferred.await()) { @@ -275,7 +277,11 @@ constructor( }*/ val emu = emulatorReady.await() - val result = emu.newSuperUserPty(installCommand, env) + val result = emu.newSuperUserPty( + command = installCommand, + env = env, + listener = listener + ) val success = result.isSuccess if (success) { module.nullable(::insertLocal) @@ -327,4 +333,42 @@ constructor( } } } + + @AssistedFactory + interface Factory { + fun create( + mxColors: Colors, + mdColors: ColorScheme, + ): InstallViewModel + } + + companion object { + @Composable + fun build( + mxColors: Colors, + mdColors: ColorScheme, + ): InstallViewModel = + androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> + factory.create(mxColors, mdColors) + } + + private val local = + staticCompositionLocalOf { error("No InstallViewModel found!") } + + @get:Composable + val current: InstallViewModel get() = local.current + + @Composable + fun LocalProvider(content: @Composable (InstallViewModel) -> Unit) { + val mxColors = MMRLXTheme.colors + val mdColors = MaterialTheme.colorScheme + + val vm = build(mxColors, mdColors) + CompositionLocalProvider( + local provides vm, + ) { + content(vm) + } + } + } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt index 77e07a916..06fd6dc74 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt @@ -1,11 +1,13 @@ package com.dergoogler.mmrl.viewmodel import android.app.Application +import android.content.Context import android.content.res.Configuration import android.content.res.Resources import android.net.Uri import androidx.annotation.MainThread import androidx.annotation.StringRes +import androidx.compose.material3.ColorScheme import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -18,8 +20,10 @@ import com.dergoogler.mmrl.platform.PlatformManager import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository import com.dergoogler.mmrl.utils.initPlatform +import dev.mmrlx.compose.ui.theme.Colors import dev.mmrlx.terminal.TerminalEmulator import dev.mmrlx.terminal.appendLineOnMain +import dev.mmrlx.terminal.appendTextOnMain import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow @@ -30,11 +34,10 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import timber.log.Timber import java.util.Locale -import javax.inject.Inject -open class TerminalViewModel -@Inject -constructor( +open class TerminalViewModel( + val mxColors: Colors, + val mdColors: ColorScheme, application: Application, localRepository: LocalRepository, modulesRepository: ModulesRepository, @@ -138,23 +141,29 @@ constructor( } @MainThread - protected fun log( - @StringRes message: Int, - vararg format: Any?, + protected fun devLog( + data: ByteArray, ) { - log( - message = context.getString(message, *format), - log = localizedEnglishResources.getString(message, *format), - ) + if (devMode) log(data) } @MainThread protected fun log( @StringRes message: Int, + vararg format: Any? = emptyArray(), ) { + if (format.isEmpty()) { + log( + message = context.getAnsiString(message).formatIfError(), + log = localizedEnglishResources.getString(message), + ) + + return + } + log( - message = context.getString(message), - log = localizedEnglishResources.getString(message), + message = context.getAnsiString(message, *format).formatIfError(), + log = localizedEnglishResources.getString(message, *format), ) } @@ -170,4 +179,38 @@ constructor( } } + + @MainThread + protected fun log( + data: ByteArray, + ) { + viewModelScope.launch(Dispatchers.Main) { + val emu = emulatorReady.await() + emu.appendTextOnMain(data.formatIfError()) + logs += data.contentToString() + } + } + + private val errorAnsiColor = "\u001B[0;38;5;168;49m" + private val ansiReset = "\u001B[0m" + + fun String.formatIfError(): String { + if (isEmpty() || this[0] != '!') return this + + return errorAnsiColor + this + ansiReset + } + + fun ByteArray.formatIfError(): ByteArray { + if (isEmpty() || this[0] != '!'.code.toByte()) return this + + return errorAnsiColor.encodeToByteArray() + this + ansiReset.encodeToByteArray() + } + + private fun Context.getAnsiString( + @StringRes resId: Int, + vararg formatArgs: Any?, + ): String { + return getString(resId, *formatArgs) + .replace("\\x1b", "\u001B") + } } diff --git a/app/src/main/res/values/strings_terminal.xml b/app/src/main/res/values/strings_terminal.xml index 6b1ce9ef1..66784405c 100644 --- a/app/src/main/res/values/strings_terminal.xml +++ b/app/src/main/res/values/strings_terminal.xml @@ -6,25 +6,25 @@ ! Installation aborted due to an error - Path: %1$s - Copying zip to temp directory - ::group::Module info + Module info ! Copying failed ! Unable to gather module info - - Installing [color=primary]%1$s[/color] - [color=red]! Module not found.[/color] + - Installing \\x1b[0;38;5;135;49m%1$s\\x1b[0m + ! Module not found. ! This module don\'t have an action. ! Module is disabled or removed. Unable to execute action. - Execution failed. Try to use Shell for the Action execution, Settings → Module → Use Shell for Module Action. - [color=red]! Unable to find path for uri: %1$s[/color] + ! Unable to find path for uri: %1$s ! %1$s is not a module file. Magisk modules must be .zip files. Skipping… - Removed updated folder - [color=red]! Failed to remove updated folder[/color] - [color=error]! Unrooted platforms are not supported[/color] + ! Failed to remove updated folder + ! Unrooted platforms are not supported ! Module manager is null ! File manager is null [bold]- Waiting for PlatformManager to initialize…[/bold] - [color=red]! Failed to initialize Platform[/color] - [bold]- Platform initialized[/bold] - [color=red]! Platform initialization failed. Cannot proceed with installation.[/color] - [color=red]! Platform is not active. Cannot proceed with installation.[/color] + ! Failed to initialize Platform + \\x1b[1;39;49m- Platform initialized\\x1b[0m + ! Platform initialization failed. Cannot proceed with installation. + ! Platform is not active. Cannot proceed with installation. - Deleted ZIP file: %s diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1cab79a33..ced10b2dd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.249" +mmrlx = "1.0.259" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" diff --git a/platform/src/main/aidl/com/dergoogler/mmrl/platform/stub/IModuleManager.aidl b/platform/src/main/aidl/com/dergoogler/mmrl/platform/stub/IModuleManager.aidl index 3278100c0..c8ac02237 100644 --- a/platform/src/main/aidl/com/dergoogler/mmrl/platform/stub/IModuleManager.aidl +++ b/platform/src/main/aidl/com/dergoogler/mmrl/platform/stub/IModuleManager.aidl @@ -10,6 +10,7 @@ import com.dergoogler.mmrl.platform.stub.IModuleOpsCallback; interface IModuleManager { String getManagerName(); String getVersion(); + String getBinary(); int getVersionCode(); List getModules(); ModuleCompatibility getModuleCompatibility(); diff --git a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/APatchModuleManager.kt b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/APatchModuleManager.kt index 0b47e4e23..c9a2c62ac 100644 --- a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/APatchModuleManager.kt +++ b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/APatchModuleManager.kt @@ -17,6 +17,8 @@ open class APatchModuleManager : BaseModuleManager() { override fun getVersionCode(): Int = mVersionCode + override fun getBinary() = "/data/adb/ap/bin/apd" + override fun getModuleCompatibility() = ModuleCompatibility( hasMagicMount = @@ -39,7 +41,7 @@ open class APatchModuleManager : BaseModuleManager() { if (!dir.exists()) callback.onFailure(id, null) if (useShell) { - "apd module enable $id".submit { + "$binary module enable $id".submit { if (isSuccess) { callback.onSuccess(id) } else { @@ -67,7 +69,7 @@ open class APatchModuleManager : BaseModuleManager() { if (!dir.exists()) return callback.onFailure(id, null) if (useShell) { - "apd module disable $id".submit { + "$binary module disable $id".submit { if (isSuccess) { callback.onSuccess(id) } else { @@ -95,7 +97,7 @@ open class APatchModuleManager : BaseModuleManager() { if (!dir.exists()) return callback.onFailure(id, null) if (useShell) { - "apd module uninstall $id".submit { + "$binary module uninstall $id".submit { if (isSuccess) { callback.onSuccess(id) } else { @@ -114,9 +116,9 @@ open class APatchModuleManager : BaseModuleManager() { } } - override fun getInstallCommand(path: String): String = "apd module install \"$path\"" + override fun getInstallCommand(path: String): String = "$binary module install \"$path\"" - override fun getActionCommand(id: ModId): String = "apd module action ${id.id}" + override fun getActionCommand(id: ModId): String = "$binary module action ${id.id}" override fun getActionEnvironment(): List = listOf( diff --git a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KernelSUModuleManager.kt b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KernelSUModuleManager.kt index 4efaf502a..c975c8600 100644 --- a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KernelSUModuleManager.kt +++ b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KernelSUModuleManager.kt @@ -16,6 +16,8 @@ open class KernelSUModuleManager : BaseModuleManager() { override fun getVersion(): String = mVersion + override fun getBinary() = "/data/adb/ksu/bin/ksud" + override fun getVersionCode(): Int { val ksuVersion = KsuNative.getVersion() @@ -65,7 +67,7 @@ open class KernelSUModuleManager : BaseModuleManager() { if (!dir.exists()) callback.onFailure(id, null) if (useShell) { - "ksud module enable $id".submit { + "$binary module enable $id".submit { if (isSuccess) { callback.onSuccess(id) } else { @@ -93,7 +95,7 @@ open class KernelSUModuleManager : BaseModuleManager() { if (!dir.exists()) return callback.onFailure(id, null) if (useShell) { - "ksud module disable $id".submit { + "$binary module disable $id".submit { if (isSuccess) { callback.onSuccess(id) } else { @@ -121,7 +123,7 @@ open class KernelSUModuleManager : BaseModuleManager() { if (!dir.exists()) return callback.onFailure(id, null) if (useShell) { - "ksud module uninstall $id".submit { + "$binary module uninstall $id".submit { if (isSuccess) { callback.onSuccess(id) } else { @@ -140,9 +142,9 @@ open class KernelSUModuleManager : BaseModuleManager() { } } - override fun getInstallCommand(path: String): String = "ksud module install \"$path\"" + override fun getInstallCommand(path: String): String = "$binary module install \"$path\"" - override fun getActionCommand(id: ModId): String = "ksud module action ${id.id}" + override fun getActionCommand(id: ModId): String = "$binary module action ${id.id}" override fun getActionEnvironment(): List = listOf( diff --git a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KsuNextModuleManager.kt b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KsuNextModuleManager.kt index 2631b2606..43c5c57dd 100644 --- a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KsuNextModuleManager.kt +++ b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/KsuNextModuleManager.kt @@ -24,7 +24,7 @@ open class KsuNextModuleManager : KernelSUModuleManager() { if (!dir.exists()) callback.onFailure(id, null) if (useShell) { - "ksud module restore $id && ksud module enable $id".submit { + "$binary module restore $id && $binary module enable $id".submit { if (isSuccess) { callback.onSuccess(id) } else { diff --git a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/MagiskModuleManager.kt b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/MagiskModuleManager.kt index 1d42c4514..a7b61dc7e 100644 --- a/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/MagiskModuleManager.kt +++ b/platform/src/main/kotlin/com/dergoogler/mmrl/platform/manager/MagiskModuleManager.kt @@ -11,6 +11,8 @@ import com.dergoogler.mmrl.platform.stub.IModuleOpsCallback open class MagiskModuleManager : BaseModuleManager() { override fun getManagerName(): String = "Magisk" + override fun getBinary() = "magisk" + override fun getModuleCompatibility() = ModuleCompatibility( hasMagicMount = true, @@ -75,7 +77,7 @@ open class MagiskModuleManager : BaseModuleManager() { } } - override fun getInstallCommand(path: String): String = "magisk --install-module \"$path\"" + override fun getInstallCommand(path: String): String = "$binary --install-module \"$path\"" override fun getActionCommand(id: ModId): String = "" @@ -84,7 +86,7 @@ open class MagiskModuleManager : BaseModuleManager() { "export ASH_STANDALONE=1", "export MAGISK=true", "export MAGISK_VER=$version", - "export MAGISKTMP=$(magisk --path)", + "export MAGISKTMP=$($binary --path)", "export MAGISK_VER_CODE=$versionCode", ) From 0350ea2802917b41c9dea3e99b7a1f1cdec698bd Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 19:41:50 +0100 Subject: [PATCH 43/55] Manage terminal PTY lifecycle and cancellation Launch action and installation commands through the shared PTY lifecycle, stream output through listeners, and close the PTY when an action is canceled. Update the action screen to use the composition-local view model and shared scaffold. --- .../terminal/action/ActionActivity.kt | 28 +-- .../activity/terminal/action/ActionScreen.kt | 211 +++++++++--------- .../mmrl/viewmodel/ActionViewModel.kt | 120 ++++------ .../mmrl/viewmodel/InstallViewModel.kt | 19 +- .../mmrl/viewmodel/TerminalViewModel.kt | 38 +++- 5 files changed, 194 insertions(+), 222 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionActivity.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionActivity.kt index f0b425c52..f8be64e4a 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionActivity.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionActivity.kt @@ -4,7 +4,6 @@ import android.content.Context import android.content.Intent import android.os.Bundle import android.util.Log -import androidx.activity.viewModels import androidx.lifecycle.lifecycleScope import com.dergoogler.mmrl.platform.model.ModId import com.dergoogler.mmrl.platform.model.ModId.Companion.getModId @@ -17,37 +16,32 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class ActionActivity : TerminalActivity() { - private val viewModel by viewModels() - override fun onCreate(savedInstanceState: Bundle?) { Log.d(TAG, "onCreate") super.onCreate(savedInstanceState) val modId = intent.getModId() - if (modId.isNullOrEmpty()) { - finish() - } else { - Log.d(TAG, "onCreate: $modId") - initAction(modId) - } setBaseContent { - ActionScreen(viewModel) + ActionViewModel.LocalProvider { + if (modId.isNullOrEmpty()) { + finish() + } else { + it.initAction(modId) + } + + ActionScreen() + } } } - private fun initAction(modId: ModId) { + private fun ActionViewModel.initAction(modId: ModId) { lifecycleScope.launch(Dispatchers.IO) { - viewModel.runAction(modId) + runAction(modId) } } - override fun onDestroy() { - viewModel.destroy() - super.onDestroy() - } - companion object { private const val TAG = "ActionActivity" diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt index 4214e0de1..d2f057e0f 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt @@ -5,15 +5,12 @@ import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -37,139 +34,137 @@ import com.dergoogler.mmrl.app.Event.Companion.isFinished import com.dergoogler.mmrl.app.Event.Companion.isLoading import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ui.activity.MMRLComponentActivity -import com.dergoogler.mmrl.ui.component.LocalScreenProvider import com.dergoogler.mmrl.ui.component.dialog.ConfirmDialog -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurNavigateUpToolbar -import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ActionViewModel -import dev.chrisbanes.haze.hazeSource import dev.mmrlx.compose.terminal.Terminal +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.toolbar.NavigateUpToolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior import dev.mmrlx.terminal.TerminalEmulator.Companion.TERMINAL_CURSOR_STYLE_NONE import kotlinx.coroutines.launch @Composable -fun ActionScreen(viewModel: ActionViewModel) = - LocalScreenProvider { - val scope = rememberCoroutineScope() - val snackbarHostState = remember { SnackbarHostState() } - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() +fun ActionScreen() { + val vm = ActionViewModel.current + val scope = rememberCoroutineScope() + val snackbarHostState = remember { SnackbarHostState() } + val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() - val userPreferences = LocalUserPreferences.current - val context = LocalContext.current + val userPreferences = LocalUserPreferences.current + val context = LocalContext.current + val activity = (context as MMRLComponentActivity) - val focusRequester = remember { FocusRequester() } - val listState = rememberLazyListState() + val focusRequester = remember { FocusRequester() } + val listState = rememberLazyListState() - LaunchedEffect(focusRequester) { - focusRequester.requestFocus() - } + LaunchedEffect(focusRequester) { + focusRequester.requestFocus() + } - var cancelAction by remember { mutableStateOf(false) } + var cancelAction by remember { mutableStateOf(false) } - val event = viewModel.event + val event = vm.event - val allowCancel = userPreferences.allowCancelAction + val allowCancel = userPreferences.allowCancelAction - val backHandler = { - if (allowCancel) { - when { - event.isLoading /* && shell.isAlive */ -> cancelAction = true - event.isFinished -> (context as MMRLComponentActivity).finish() - } - } else { - if (event.isFinished) { - (context as MMRLComponentActivity).finish() - } + val backHandler = { + if (allowCancel) { + when { + event.isLoading /* && shell.isAlive */ -> cancelAction = true + event.isFinished -> activity.finish() + } + } else { + if (event.isFinished) { + activity.finish() } } + } - BackHandler( - enabled = if (!allowCancel) event.isLoading else true, - onBack = backHandler, - ) - val launcher = - rememberLauncherForActivityResult( - ActivityResultContracts.CreateDocument("*/*"), - ) { uri -> - if (uri == null) return@rememberLauncherForActivityResult - - scope.launch { - viewModel - .writeLogsTo(uri) - .onSuccess { - val message = context.getString(R.string.install_logs_saved) - snackbarHostState.showSnackbar( - message = message, - duration = SnackbarDuration.Short, - ) - }.onFailure { - val message = - context.getString( - R.string.install_logs_save_failed, - it.message ?: context.getString(R.string.unknown_error), - ) - snackbarHostState.showSnackbar( - message = message, - duration = SnackbarDuration.Short, + BackHandler( + enabled = allowCancel || event.isLoading, + onBack = backHandler, + ) + + val launcher = + rememberLauncherForActivityResult( + ActivityResultContracts.CreateDocument("*/*"), + ) { uri -> + if (uri == null) return@rememberLauncherForActivityResult + + scope.launch { + vm + .writeLogsTo(uri) + .onSuccess { + val message = context.getString(R.string.install_logs_saved) + snackbarHostState.showSnackbar( + message = message, + duration = SnackbarDuration.Short, + ) + }.onFailure { + val message = + context.getString( + R.string.install_logs_save_failed, + it.message ?: context.getString(R.string.unknown_error), ) - } - } - } - - if (cancelAction) { - ConfirmDialog( - title = R.string.action_screen_cancel_title, - description = R.string.action_screen_cancel_text, - onClose = { cancelAction = false }, - onConfirm = { - scope.launch { - cancelAction = false - // shell.close() + snackbarHostState.showSnackbar( + message = message, + duration = SnackbarDuration.Short, + ) } - }, - ) + } } - Scaffold( - modifier = - Modifier - .onKeyEvent { - when (it.key) { - Key.VolumeUp, Key.VolumeDown -> event.isLoading + if (cancelAction) { + ConfirmDialog( + title = R.string.action_screen_cancel_title, + description = R.string.action_screen_cancel_text, + onClose = { cancelAction = false }, + onConfirm = { + cancelAction = false + vm.closePty() + activity.finish() + }, + ) + } + + Scaffold( + modifier = + Modifier + .onKeyEvent { + when (it.key) { + Key.VolumeUp, Key.VolumeDown -> event.isLoading - else -> false - } + else -> false } - .focusRequester(focusRequester) - .focusable() - .nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - TopBar( - exportLog = { launcher.launch(viewModel.logfile) }, - event = event, - enable = if (!allowCancel) event.isFinished else true, - scrollBehavior = scrollBehavior, - onBack = backHandler, - ) - }, - snackbarHost = { SnackbarHost(snackbarHostState) }, - contentWindowInsets = WindowInsets.none, - ) { - Terminal( - modifier = Modifier - .hazeSource(LocalHazeState.current) - .padding(it) - ) { emu -> - emu.setCursorStyle(TERMINAL_CURSOR_STYLE_NONE) - viewModel.onEmulatorCreated(emu) - } + } + .focusRequester(focusRequester) + .focusable() + .nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + TopBar( + exportLog = { launcher.launch(vm.logfile) }, + event = event, + enable = if (!allowCancel) event.isFinished else true, + scrollBehavior = scrollBehavior, + onBack = backHandler, + ) + }, + snackbarHost = { SnackbarHost(snackbarHostState) }, + contentWindowInsets = WindowInsets.none, + ) { + Terminal( + modifier = Modifier + .scaffoldHazeSource(), + contentPadding = contentPadding + ) { emu -> + emu.setCursorStyle(TERMINAL_CURSOR_STYLE_NONE) + vm.onEmulatorCreated(emu) } } +} @Composable private fun TopBar( @@ -178,7 +173,7 @@ private fun TopBar( onBack: () -> Unit, scrollBehavior: ToolbarScrollBehavior, enable: Boolean, -) = BlurNavigateUpToolbar( +) = NavigateUpToolbar( title = stringResource(id = R.string.action_activity), subtitle = stringResource( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt index eb8241975..e0c36f66e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/ActionViewModel.kt @@ -12,26 +12,23 @@ import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R import com.dergoogler.mmrl.app.Event import com.dergoogler.mmrl.datastore.UserPreferencesRepository -import com.dergoogler.mmrl.model.terminal.ScriptError import com.dergoogler.mmrl.platform.PlatformManager import com.dergoogler.mmrl.platform.content.LocalModule.Companion.hasAction import com.dergoogler.mmrl.platform.content.State import com.dergoogler.mmrl.platform.model.ModId import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository -import com.topjohnwu.superuser.CallbackList import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import dagger.hilt.android.lifecycle.HiltViewModel import dev.mmrlx.compose.ui.theme.Colors import dev.mmrlx.compose.ui.theme.MMRLXTheme -import dev.mmrlx.terminal.newSuperUserPty +import dev.mmrlx.terminal.PtyListener +import dev.mmrlx.terminal.launchSuperUserPty import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import timber.log.Timber import java.time.LocalDateTime @HiltViewModel(assistedFactory = ActionViewModel.Factory::class) @@ -54,36 +51,15 @@ constructor( ) { val logfile get() = "Action_${LocalDateTime.now()}.log" - init { - Timber.d("ActionViewModel initialized") - } - - private val stdoutCallbackList = - object : CallbackList() { - override fun onAddElement(msg: String?) { - msg?.let { - viewModelScope.launch { log(it) } - } - } + private val listener = object : PtyListener { + override fun onStdout(data: ByteArray) { + log(data) } - private val stderrCallbackList = - object : CallbackList() { - override fun onAddElement(msg: String?) { - msg?.let { - viewModelScope.launch { - val error = ScriptError.fromString(it) - - if (error != null) { - devLog("::error title=${error.title}::At Line ${error.lineNumber}: ${error.message}") - return@launch - } - - devLog(it) - } - } - } + override fun onStderr(data: ByteArray) { + devLog(data) } + } suspend fun runAction(modId: ModId) = withContext(Dispatchers.IO) { @@ -125,18 +101,6 @@ constructor( legacy: Boolean, ): Boolean = withContext(Dispatchers.IO) { - val shellEnv = - listOf( - "export PATH=/data/adb/ap/bin:/data/adb/ksu/bin:/data/adb/magisk:\$PATH", - "export MMRL=true", - "export MMRL_VER=${BuildConfig.VERSION_NAME}", - "export MMRL_VER_CODE=${BuildConfig.VERSION_CODE}", - "export BOOTMODE=true", - "export ARCH=${Build.SUPPORTED_ABIS.firstOrNull().orEmpty()}", - "export API=${Build.VERSION.SDK_INT}", - "export IS64BIT=${Build.SUPPORTED_64_BIT_ABIS.isNotEmpty()}", - ) - val env = mapOf( "ASH_STANDALONE" to "1", "MMRL" to "true", @@ -155,18 +119,18 @@ constructor( PlatformManager.moduleManager.getActionCommand(modId) } - val emu = emulatorReady.await() - val result = emu.newSuperUserPty(command, env) - val success = result.isSuccess - if (success) { - return@withContext true - } else { - withContext(Dispatchers.Main) { - log(R.string.execution_failed_try_to_use_shell_for_the_action_execution_settings_module_use_shell_for_module_action) - result.onFailure { devLog("Shell Error: $it") } - } - } - return@withContext false + val emu = emulatorDeferred.await() + + ptyDeferred.complete( + emu.launchSuperUserPty( + scope = viewModelScope, + command = command, + env = env, + listener = listener + ) + ) + + return@withContext ptyDeferred.isSuccess() } @AssistedFactory @@ -178,32 +142,32 @@ constructor( } companion object { - @Composable - fun build( - mxColors: Colors, - mdColors: ColorScheme, - ): ActionViewModel = - androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> - factory.create(mxColors, mdColors) - } + @Composable + fun build( + mxColors: Colors, + mdColors: ColorScheme, + ): ActionViewModel = + androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel { factory -> + factory.create(mxColors, mdColors) + } - private val local = - staticCompositionLocalOf { error("No ActionViewModel found!") } + private val local = + staticCompositionLocalOf { error("No ActionViewModel found!") } - @get:Composable - val current: ActionViewModel get() = local.current + @get:Composable + val current: ActionViewModel get() = local.current - @Composable - fun LocalProvider(content: @Composable (ActionViewModel) -> Unit) { - val mxColors = MMRLXTheme.colors - val mdColors = MaterialTheme.colorScheme + @Composable + fun LocalProvider(content: @Composable (ActionViewModel) -> Unit) { + val mxColors = MMRLXTheme.colors + val mdColors = MaterialTheme.colorScheme - val vm = build(mxColors, mdColors) - CompositionLocalProvider( - local provides vm, - ) { - content(vm) - } + val vm = build(mxColors, mdColors) + CompositionLocalProvider( + local provides vm, + ) { + content(vm) } } + } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt index cfce06696..8686d392a 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt @@ -33,7 +33,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import dev.mmrlx.compose.ui.theme.Colors import dev.mmrlx.compose.ui.theme.MMRLXTheme import dev.mmrlx.terminal.PtyListener -import dev.mmrlx.terminal.newSuperUserPty +import dev.mmrlx.terminal.launchSuperUserPty import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch @@ -276,13 +276,16 @@ constructor( return@withContext false }*/ - val emu = emulatorReady.await() - val result = emu.newSuperUserPty( - command = installCommand, - env = env, - listener = listener + val emu = emulatorDeferred.await() + ptyDeferred.complete( + emu.launchSuperUserPty( + scope = viewModelScope, + command = installCommand, + env = env, + listener = listener + ) ) - val success = result.isSuccess + val success = ptyDeferred.isSuccess() if (success) { module.nullable(::insertLocal) @@ -292,7 +295,6 @@ constructor( } else { withContext(Dispatchers.Main) { log("Error: Installation failed for ${zipFile.name}. Exit code: ${-999/*result.code*/}") - result.onFailure { devLog("Shell Error: $it") } } if (module != null /*&& !shell.isAlive*/) { withContext(Dispatchers.IO) { @@ -307,6 +309,7 @@ constructor( } } } + return@withContext success } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt index 06fd6dc74..2b77a5f7e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt @@ -5,6 +5,7 @@ import android.content.Context import android.content.res.Configuration import android.content.res.Resources import android.net.Uri +import android.util.Log import androidx.annotation.MainThread import androidx.annotation.StringRes import androidx.compose.material3.ColorScheme @@ -21,6 +22,7 @@ import com.dergoogler.mmrl.repository.LocalRepository import com.dergoogler.mmrl.repository.ModulesRepository import com.dergoogler.mmrl.utils.initPlatform import dev.mmrlx.compose.ui.theme.Colors +import dev.mmrlx.terminal.Pty import dev.mmrlx.terminal.TerminalEmulator import dev.mmrlx.terminal.appendLineOnMain import dev.mmrlx.terminal.appendTextOnMain @@ -45,12 +47,11 @@ open class TerminalViewModel( ) : MMRLViewModel(application, localRepository, modulesRepository, userPreferencesRepository) { protected val logs = mutableListOf() - protected var emulator: TerminalEmulator? = null - protected val emulatorReady = CompletableDeferred() + protected val emulatorDeferred = CompletableDeferred() + protected var ptyDeferred = CompletableDeferred() var event by mutableStateOf(Event.LOADING) - val terminal by mutableStateOf(null) private val localFlow = MutableStateFlow(null) val local get() = localFlow.asStateFlow() @@ -82,11 +83,25 @@ open class TerminalViewModel( } } + fun closePty() { + viewModelScope.launch { + val pty = ptyDeferred.await() + pty.close() + } + } + override fun onCleared() { -// terminal.shell.close() -// terminal.currentCard = null -// terminal.currentGroup = null - super.onCleared() + viewModelScope.launch { + val pty = ptyDeferred.await() + + try { + pty.close() + pty.destroy() + } catch (e: Exception) { + Log.e("TerminalViewModel", "Failed to destroy pty", e) + pty.destroyForcibly() + } + } } fun reboot(reason: String = "") { @@ -94,8 +109,7 @@ open class TerminalViewModel( } fun onEmulatorCreated(emu: TerminalEmulator) { - emulator = emu - emulatorReady.complete(emu) + emulatorDeferred.complete(emu) } suspend fun writeLogsTo(uri: Uri) = @@ -173,7 +187,7 @@ open class TerminalViewModel( log: String = message, ) { viewModelScope.launch(Dispatchers.Main) { - val emu = emulatorReady.await() + val emu = emulatorDeferred.await() emu.appendLineOnMain(message) logs += log @@ -185,7 +199,7 @@ open class TerminalViewModel( data: ByteArray, ) { viewModelScope.launch(Dispatchers.Main) { - val emu = emulatorReady.await() + val emu = emulatorDeferred.await() emu.appendTextOnMain(data.formatIfError()) logs += data.contentToString() } @@ -213,4 +227,6 @@ open class TerminalViewModel( return getString(resId, *formatArgs) .replace("\\x1b", "\u001B") } + + suspend fun CompletableDeferred.isSuccess() = await().waitForAsync() == 0 } From 886adef9ac9347de461cb7f1fd6a1ff0de2373da Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 19:43:55 +0100 Subject: [PATCH 44/55] Apply theme colors to action terminal Use the theme background and foreground colors for the action screen terminal. --- .../mmrl/ui/activity/terminal/action/ActionScreen.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt index d2f057e0f..fe0f39ba0 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/activity/terminal/action/ActionScreen.kt @@ -39,6 +39,7 @@ import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ActionViewModel import dev.mmrlx.compose.terminal.Terminal import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.theme.MMRLXTheme import dev.mmrlx.compose.ui.toolbar.NavigateUpToolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @@ -147,7 +148,7 @@ fun ActionScreen() { TopBar( exportLog = { launcher.launch(vm.logfile) }, event = event, - enable = if (!allowCancel) event.isFinished else true, + enable = allowCancel || event.isFinished, scrollBehavior = scrollBehavior, onBack = backHandler, ) @@ -156,6 +157,8 @@ fun ActionScreen() { contentWindowInsets = WindowInsets.none, ) { Terminal( + containerColor = MMRLXTheme.colors.background, + contentColor = MMRLXTheme.colors.foreground, modifier = Modifier .scaffoldHazeSource(), contentPadding = contentPadding From 3d19d7d215a4c06c96c26c481b049bdda60aabbb Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 20:22:24 +0100 Subject: [PATCH 45/55] . --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ced10b2dd..9e1e88f06 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.259" +mmrlx = "1.0.260" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From abdcdd4521229602ac0b3c826fc6035bf80b7290 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 21:16:20 +0100 Subject: [PATCH 46/55] [skip ci] Add navigation rail to main screens Add a reorderable navigation rail that shares bottom bar preferences, adjust toolbar and repository padding for rail layouts, and update MMRLX. --- .../dergoogler/mmrl/ui/component/BottomBar.kt | 2 - .../dergoogler/mmrl/ui/component/RailNav.kt | 179 ++++++++++++++++++ .../dergoogler/mmrl/ui/component/Scaffold.kt | 5 + .../mmrl/ui/screens/home/HomeScreen.kt | 11 +- .../mmrl/ui/screens/modules/ModulesScreen.kt | 7 + .../repositories/RepositoriesScreen.kt | 7 + .../mmrl/ui/screens/repository/ModulesList.kt | 14 +- .../ui/screens/repository/RepositoryScreen.kt | 6 +- gradle/libs.versions.toml | 2 +- 9 files changed, 224 insertions(+), 9 deletions(-) create mode 100644 app/src/main/kotlin/com/dergoogler/mmrl/ui/component/RailNav.kt diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt index ee01017aa..06755dc33 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/BottomBar.kt @@ -32,14 +32,12 @@ fun BottomBar(updates: Int = 0) { val navController = LocalNavController.current val settings = LocalSettings.current - val state = rememberDraggableContainerState( initial = prefs.bottomBarOrder ) { settings.setBottomBarOrder(it) } - NavigationBar( modifier = Modifier diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/RailNav.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/RailNav.kt new file mode 100644 index 000000000..19d6e5a89 --- /dev/null +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/RailNav.kt @@ -0,0 +1,179 @@ +package com.dergoogler.mmrl.ui.component + +import androidx.compose.foundation.layout.imePadding +import androidx.compose.material3.Badge +import androidx.compose.material3.BadgedBox +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import com.dergoogler.mmrl.ui.navigation.MainDestination +import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator +import com.dergoogler.mmrl.ui.providable.LocalNavController +import com.dergoogler.mmrl.ui.providable.LocalSettings +import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.dergoogler.mmrl.ui.remember.rememberIsRoot +import com.ramcosta.composedestinations.generated.NavGraphs +import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState +import dev.mmrlx.compose.ui.DraggableContainer +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.navigationrail.NavigationRail +import dev.mmrlx.compose.ui.navigationrail.NavigationRailItem +import dev.mmrlx.compose.ui.rememberDraggableContainerState +import dev.mmrlx.compose.ui.theme.MMRLXTheme + +@Composable +fun RailNav(updates: Int = 0) { + val isRoot = rememberIsRoot() + val prefs = LocalUserPreferences.current + val navigator = LocalDestinationsNavigator.current + val navController = LocalNavController.current + val settings = LocalSettings.current + + val state = rememberDraggableContainerState( + initial = prefs.bottomBarOrder + ) { + settings.setBottomBarOrder(it) + } + + NavigationRail( + header = { + TopAppBarEventIcon() + }, + modifier = + Modifier + .imePadding() + ) { + DraggableContainer(state = state) { + column("nav") { + for (screen in MainDestination.entries) { + if ((screen.requiresRoot && !isRoot)) continue + + element(screen.id) { + val isSelected by navController.isRouteOnBackStackAsState(screen.direction) + + NavigationRailItem( + icon = { + BaseNavIcon(screen, isSelected, updates) + }, + label = { + if (!prefs.hideBottomBarLabels) { + Text( + text = stringResource(id = screen.label), + style = MMRLXTheme.typography.labelLarge, + ) + } + }, + selected = isSelected, + onClick = { + if (isSelected) { + navigator.popBackStack(screen.direction, false) + } + navigator.navigate(screen.direction) { + popUpTo(NavGraphs.root) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + ) + } + } + } + } + } +} + +/* +@Composable +private fun RailNav(updates: Int) { + val prefs = LocalUserPreferences.current + val navigator = LocalDestinationsNavigator.current + val navController = LocalNavController.current + + NavigationRail( + header = { + TopAppBarEventIcon() + }, + ) { + MainDestination.entries.forEach { screen -> + val isSelected by navController.isRouteOnBackStackAsState(screen.direction) + + if (!screen.isAccessible) return@forEach + + NavigationRailItem( + icon = { + BaseNavIcon(screen, isSelected, updates) + }, + label = { + Text( + text = stringResource(id = screen.label), + style = MaterialTheme.typography.labelLarge, + ) + }, + alwaysShowLabel = !prefs.hideBottomBarLabels, + selected = isSelected, + onClick = { + if (isSelected) { + navigator.popBackStack(screen.direction, false) + } + navigator.navigate(screen.direction) { + popUpTo(NavGraphs.root) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + ) + } + } +}*/ + +@Composable +private fun BaseNavIcon( + screen: MainDestination, + selected: Boolean, + updates: Int, +) { + if (screen == MainDestination.Modules && updates > 0) { + BadgedBox( + badge = { + Badge { + Text(text = updates.toString()) + } + }, + ) { + Icon( + painter = + painterResource( + id = + if (selected) { + screen.iconFilled + } else { + screen.icon + }, + ), + contentDescription = null, + ) + } + + return + } + + Icon( + painter = + painterResource( + id = + if (selected) { + screen.iconFilled + } else { + screen.icon + }, + ), + contentDescription = null, + ) +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt index 78b8f0884..15a626c39 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/Scaffold.kt @@ -79,6 +79,11 @@ fun SettingsScaffold( BottomBar() } }, + rail = { + if (isMainPage) { + RailNav() + } + }, floatingActionButton = floatingActionButton, contentWindowInsets = WindowInsets.none, ) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 36de79601..b206db596 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -51,6 +51,7 @@ import com.dergoogler.mmrl.platform.ksu.KsuNative import com.dergoogler.mmrl.stub.IMMRLApiManager import com.dergoogler.mmrl.ui.component.Alert import com.dergoogler.mmrl.ui.component.BottomBar +import com.dergoogler.mmrl.ui.component.RailNav import com.dergoogler.mmrl.ui.component.SELinuxStatus import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator @@ -79,6 +80,7 @@ import dev.mmrlx.compose.ui.list.component.Item import dev.mmrlx.compose.ui.list.component.item.Description import dev.mmrlx.compose.ui.list.component.item.Icon import dev.mmrlx.compose.ui.list.component.item.Title +import dev.mmrlx.compose.ui.scaffold.LocalScaffoldScope import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.Toolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults @@ -126,6 +128,9 @@ fun HomeScreen() { bottomBar = { BottomBar() }, + rail = { + RailNav() + }, contentWindowInsets = WindowInsets.none, ) { List( @@ -212,7 +217,7 @@ fun HomeScreen() { } } } - + element("device-app-info") { Column( modifier = Modifier @@ -468,9 +473,13 @@ private fun TopBar0( onHeartClick: () -> Unit = {}, scrollBehavior: ToolbarScrollBehavior, ) { + val scope = LocalScaffoldScope.current + Toolbar( scrollBehavior = scrollBehavior, title = { + if (scope.hasRail) return@Toolbar + TopAppBarEventIcon() }, actions = { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt index 4762cfbdb..a5c14d8f4 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesScreen.kt @@ -41,6 +41,7 @@ import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Loading import com.dergoogler.mmrl.ui.component.PageIndicator +import com.dergoogler.mmrl.ui.component.RailNav import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings @@ -53,6 +54,7 @@ import dev.mmrlx.compose.ui.PullToRefreshDefaults.Indicator import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton import dev.mmrlx.compose.ui.rememberPullToRefreshState +import dev.mmrlx.compose.ui.scaffold.LocalScaffoldScope import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import dev.mmrlx.compose.ui.toolbar.ToolbarScrollBehavior @@ -111,6 +113,9 @@ fun ModulesScreen(viewModel: ModulesViewModel = hiltViewModel()) { bottomBar = { BottomBar() }, + rail = { + RailNav() + }, floatingActionButton = { AnimatedVisibility( visible = showFab, @@ -181,6 +186,7 @@ private fun TopBar0( setMenu: (ModulesMenu) -> Unit, scrollBehavior: ToolbarScrollBehavior, ) { + val scope = LocalScaffoldScope.current var currentQuery by remember { mutableStateOf(query) } DisposableEffect(isSearch) { onDispose { currentQuery = "" } @@ -198,6 +204,7 @@ private fun TopBar0( currentQuery = "" }, title = { + if (scope.hasRail) return@BlurSearchToolbar TopAppBarEventIcon() }, actions = { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt index b7416dbad..8f0365f50 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt @@ -50,6 +50,7 @@ import com.dergoogler.mmrl.ui.animate.slideOutBottomToTop import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Loading import com.dergoogler.mmrl.ui.component.PageIndicator +import com.dergoogler.mmrl.ui.component.RailNav import com.dergoogler.mmrl.ui.component.TopAppBarEventIcon import com.dergoogler.mmrl.ui.component.dialog.TextFieldDialog import com.dergoogler.mmrl.ui.providable.LocalBulkInstall @@ -64,6 +65,7 @@ import com.ramcosta.composedestinations.generated.destinations.SearchScreenDesti import dev.mmrlx.compose.ui.Text import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton +import dev.mmrlx.compose.ui.scaffold.LocalScaffoldScope import dev.mmrlx.compose.ui.scaffold.Scaffold import dev.mmrlx.compose.ui.toolbar.Toolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults @@ -166,6 +168,9 @@ fun RepositoriesScreen() { bottomBar = { BottomBar() }, + rail = { + RailNav() + }, contentWindowInsets = WindowInsets.none, floatingActionButton = { if (viewModel.platform.isValid) { @@ -299,11 +304,13 @@ private fun TopBar0( setMenu: KFunction1, scrollBehavior: ToolbarScrollBehavior, ) { + val scope = LocalScaffoldScope.current val navigator = LocalDestinationsNavigator.current Toolbar( scrollBehavior = scrollBehavior, title = { + if (scope.hasRail) return@Toolbar TopAppBarEventIcon() }, actions = { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index f0334702c..bb8f6d5bf 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -39,6 +39,7 @@ fun ScaffoldScope.ModulesList( isLoading: Boolean, beforeContent: LazyListScope.() -> Unit = {}, ) { + val scope = this val vm = RepositoryViewModel.current val navigator = LocalDestinationsNavigator.current val isSearch by vm::isSearch @@ -64,8 +65,8 @@ fun ScaffoldScope.ModulesList( .animateContentSize(), contentPadding = PaddingValues( - top = if (!isSearch) 0.dp else this@ModulesList.scaffoldTopPadding, - bottom = this@ModulesList.scaffoldBottomPadding + 16.dp, + top = if (!isSearch) 0.dp else scope.scaffoldTopPadding, + bottom = scope.scaffoldBottomPadding + 16.dp, ), verticalArrangement = Arrangement.spacedBy(8.dp), ) { @@ -80,7 +81,10 @@ fun ScaffoldScope.ModulesList( LocalOnlineModule provides module, ) { Box( - modifier = Modifier.padding(horizontal = 16.dp) + modifier = Modifier.padding( + start = scope.scaffoldStartPadding + 16.dp, + end = scope.scaffoldEndPadding + 16.dp + ) ) { ModuleItemDetailed( onClick = { @@ -95,7 +99,9 @@ fun ScaffoldScope.ModulesList( if (isLoading) { item { Box( - modifier = Modifier.fillMaxWidth().padding(16.dp), + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), contentAlignment = Alignment.Center, ) { CircularProgressIndicator() diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt index c93f403ff..7454f7355 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/RepositoryScreen.kt @@ -15,8 +15,8 @@ import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.graphicsLayer @@ -32,6 +32,7 @@ import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ui.component.BottomBar import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.PageIndicator +import com.dergoogler.mmrl.ui.component.RailNav import com.dergoogler.mmrl.ui.component.toolbar.BlurSearchToolbar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.viewmodel.RepositoryViewModel @@ -68,6 +69,9 @@ fun RepositoryScreen( bottomBar = { BottomBar() }, + rail = { + RailNav() + }, contentWindowInsets = WindowInsets.none, ) { Box( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9e1e88f06..b4b23b6de 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.260" +mmrlx = "1.0.263" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From a8d90b9dce75ffdd9bbdce8ea3f9c5139f835249 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 21:34:01 +0100 Subject: [PATCH 47/55] Add developer controls to trigger module failures Add buttons that trigger module installation and action script failures for testing. --- .../settings/developer/DeveloperScreen.kt | 42 +++++++++++++++++-- app/src/main/res/values/strings.xml | 4 ++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt index b367c4e4e..d4123a433 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/settings/developer/DeveloperScreen.kt @@ -1,21 +1,27 @@ package com.dergoogler.mmrl.ui.screens.settings.developer import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import androidx.core.net.toUri import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R +import com.dergoogler.mmrl.platform.model.ModId.Companion.toModId +import com.dergoogler.mmrl.ui.activity.terminal.action.ActionActivity +import com.dergoogler.mmrl.ui.activity.terminal.install.InstallActivity import com.dergoogler.mmrl.ui.component.SettingsScaffold +import com.dergoogler.mmrl.ui.providable.LocalSettings +import com.dergoogler.mmrl.ui.providable.LocalUserPreferences +import com.ramcosta.composedestinations.annotation.Destination +import com.ramcosta.composedestinations.annotation.RootGraph import dev.mmrlx.compose.ui.list.ListItemScope import dev.mmrlx.compose.ui.list.ListScope +import dev.mmrlx.compose.ui.list.component.ButtonItem import dev.mmrlx.compose.ui.list.component.Item import dev.mmrlx.compose.ui.list.component.Section import dev.mmrlx.compose.ui.list.component.SwitchItem import dev.mmrlx.compose.ui.list.component.item.Description import dev.mmrlx.compose.ui.list.component.item.Title -import com.dergoogler.mmrl.ui.providable.LocalSettings -import com.dergoogler.mmrl.ui.providable.LocalUserPreferences -import com.ramcosta.composedestinations.annotation.Destination -import com.ramcosta.composedestinations.annotation.RootGraph @Composable fun ListScope.DeveloperSwitch( @@ -37,6 +43,7 @@ fun ListScope.DeveloperSwitch( @Destination @Composable fun DeveloperScreen() { + val context = LocalContext.current val viewModel = LocalSettings.current val userPreferences = LocalUserPreferences.current @@ -60,6 +67,33 @@ fun DeveloperScreen() { } } + Section { + ButtonItem( + onClick = { + InstallActivity.start( + context = context, + uri = "FUQDUP".toUri(), + confirm = false, + ) + } + ) { + Title(R.string.settings_cause_module_install_fail) + Description(R.string.settings_cause_module_install_fail_desc) + } + + ButtonItem( + onClick = { + ActionActivity.start( + context = context, + modId = "FUQDUP".toModId(), + ) + } + ) { + Title(R.string.settings_cause_module_action_fail) + Description(R.string.settings_cause_module_action_fail_desc) + } + } + Section( divider = false, ) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 279f9b1c2..2e722e64f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -472,4 +472,8 @@ Empty Disable su compatibility Temporarily disable the ability of any app to gain root privileges via the ⁠su command (Existing root processes won\'t be affected). + Cause Install Fail + Causes a module installation fail + Cause Action Script Fail + Causes a module action script fail From 4682327d138f7fb5d8c899a55bcec09e81161900 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Sat, 7 Nov 2026 21:59:19 +0100 Subject: [PATCH 48/55] Improve terminal error formatting and exit codes Highlight lines beginning with `!` or `[!]` in string and byte output, and report the actual exit code when installation fails. --- .../mmrl/viewmodel/InstallViewModel.kt | 3 +- .../mmrl/viewmodel/TerminalViewModel.kt | 76 +++++++++++++++++-- 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt index 8686d392a..91bbd976f 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/InstallViewModel.kt @@ -2,6 +2,7 @@ package com.dergoogler.mmrl.viewmodel import android.app.Application import android.net.Uri +import android.util.Log import androidx.compose.material3.ColorScheme import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable @@ -294,7 +295,7 @@ constructor( } } else { withContext(Dispatchers.Main) { - log("Error: Installation failed for ${zipFile.name}. Exit code: ${-999/*result.code*/}") + log("! Installation failed for ${zipFile.name}. Exit code: ${ptyDeferred.waitFor()}") } if (module != null /*&& !shell.isAlive*/) { withContext(Dispatchers.IO) { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt index 2b77a5f7e..8512e4720 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/viewmodel/TerminalViewModel.kt @@ -35,6 +35,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import timber.log.Timber +import java.io.ByteArrayOutputStream import java.util.Locale open class TerminalViewModel( @@ -207,17 +208,75 @@ open class TerminalViewModel( private val errorAnsiColor = "\u001B[0;38;5;168;49m" private val ansiReset = "\u001B[0m" + private val errorAnsiColorByteArray = errorAnsiColor.encodeToByteArray() + private val ansiResetByteArray = ansiReset.encodeToByteArray() + + fun String.formatIfError(): String = + lineSequence() + .joinToString("\n") { line -> + if (line.startsWith("!") || line.startsWith("[!]")) { + "$errorAnsiColor$line$ansiReset" + } else { + line + } + } - fun String.formatIfError(): String { - if (isEmpty() || this[0] != '!') return this + fun ByteArray.formatIfError(): ByteArray { + val output = ByteArrayOutputStream(size) + + var lineStart = 0 + + for (i in indices) { + if (i == lineStart) { + val isError = + this[i] == '!'.code.toByte() || + ( + i + 2 < size && + this[i] == '['.code.toByte() && + this[i + 1] == '!'.code.toByte() && + this[i + 2] == ']'.code.toByte() + ) + + if (isError) { + output.write(errorAnsiColorByteArray) + } + } - return errorAnsiColor + this + ansiReset - } + if (this[i] == '\n'.code.toByte()) { + if (i > lineStart) { + val isError = + this[lineStart] == '!'.code.toByte() || + ( + i - lineStart >= 3 && + this[lineStart] == '['.code.toByte() && + this[lineStart + 1] == '!'.code.toByte() && + this[lineStart + 2] == ']'.code.toByte() + ) + + if (isError) output.write(ansiResetByteArray) + } - fun ByteArray.formatIfError(): ByteArray { - if (isEmpty() || this[0] != '!'.code.toByte()) return this + lineStart = i + 1 + } + + output.write(this[i].toInt()) + } + + // Handle the final line without a trailing newline. + if (lineStart < size) { + val isError = + this[lineStart] == '!'.code.toByte() || + ( + size - lineStart >= 3 && + this[lineStart] == '['.code.toByte() && + this[lineStart + 1] == '!'.code.toByte() && + this[lineStart + 2] == ']'.code.toByte() + ) + + if (isError) output.write(ansiResetByteArray) + } - return errorAnsiColor.encodeToByteArray() + this + ansiReset.encodeToByteArray() + return output.toByteArray() } private fun Context.getAnsiString( @@ -228,5 +287,6 @@ open class TerminalViewModel( .replace("\\x1b", "\u001B") } - suspend fun CompletableDeferred.isSuccess() = await().waitForAsync() == 0 + suspend fun CompletableDeferred.waitFor() = await().waitForAsync() + suspend fun CompletableDeferred.isSuccess() = waitFor() == 0 } From 4d6647f4945cd734cf6337cefbdcff4c56e580a4 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 17:53:53 +0100 Subject: [PATCH 49/55] Update MMRLX and migrate list styling Upgrade MMRLX to 1.0.289 and adapt list padding, text styles, and the download menu to the updated component APIs. Also fixes #670 --- .../mmrl/ui/component/AntiFeaturesItem.kt | 6 +--- .../mmrl/ui/component/PermissionItem.kt | 5 +--- .../mmrl/ui/screens/home/HomeScreen.kt | 29 ++++++++----------- .../moduleView/sections/AboutModule.kt | 3 +- .../ui/screens/moduleView/sections/Header.kt | 16 ++++++---- .../moduleView/sections/Information.kt | 15 ++++------ .../moduleView/sections/Information0.kt | 13 ++++----- gradle/libs.versions.toml | 2 +- 8 files changed, 39 insertions(+), 50 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt index db46d0ce7..f9d1f6a85 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/AntiFeaturesItem.kt @@ -1,6 +1,5 @@ package com.dergoogler.mmrl.ui.component -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.runtime.Composable import com.dergoogler.mmrl.R import dev.mmrlx.compose.ui.list.ListScope @@ -11,14 +10,11 @@ import dev.mmrlx.compose.ui.list.component.item.Title @Composable fun ListScope.AntiFeaturesItem( antifeatures: List, - contentPadding: PaddingValues, ) = antifeatures.forEach { val result = getAntifeatureDetails(it) result?.let { val (nameResId, descResId) = result - Item( - contentPadding = contentPadding, - ) { + Item { Title(nameResId) Description(descResId) } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt index c65d61aef..ca0d2d88d 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/component/PermissionItem.kt @@ -15,13 +15,10 @@ import dev.mmrlx.compose.ui.list.component.item.Title @Composable fun ListScope.PermissionItem( permissions: List, - contentPadding: PaddingValues, ) = permissions.forEach { it -> val permission = getPermissionDetails(it) permission.nullable { p -> - Item( - contentPadding = contentPadding, - ) { + Item{ Title(p.title) Description(p.desc) p.rootSolutions.nullable { diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index b206db596..39474c040 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -76,6 +76,7 @@ import dev.mmrlx.compose.ui.Text import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.icon.IconButton import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListDefaults import dev.mmrlx.compose.ui.list.component.Item import dev.mmrlx.compose.ui.list.component.item.Description import dev.mmrlx.compose.ui.list.component.item.Icon @@ -142,7 +143,7 @@ fun HomeScreen() { .scaffoldPadding() .padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp), - contentPadding = listItemContentPaddingValues + style = ListDefaults.style.copy(contentPadding = listItemContentPaddingValues), ) { val scope = this @@ -328,7 +329,7 @@ fun HomeScreen() { } if (PlatformManager.platform.isValid) { - analytics.nullable { + analytics.nullable { al -> element("analytics-modules") { Row( horizontalArrangement = Arrangement.spacedBy(16.dp), @@ -341,7 +342,7 @@ fun HomeScreen() { ) { scope.Item { Title(R.string.home_installed_modules) - Description(it.totalModules.toString()) + Description(al.totalModules.toString()) } } @@ -353,7 +354,7 @@ fun HomeScreen() { ) { scope.Item { Title(R.string.home_updated_modules) - Description(it.totalUpdated.toString()) + Description(al.totalUpdated.toString()) } } } @@ -376,12 +377,12 @@ fun HomeScreen() { horizontalArrangement = Arrangement.spacedBy(8.dp), ) { Text( - text = it.totalModulesUsageBytes.toFormattedFileSize(), + text = al.totalModulesUsageBytes.toFormattedFileSize(), ) LinearProgressIndicator( progress = { - it.totalStorageUsage + al.totalStorageUsage }, modifier = Modifier @@ -391,7 +392,7 @@ fun HomeScreen() { ) Text( - text = it.totalDeviceStorageBytes.toFormattedFileSize(), + text = al.totalDeviceStorageBytes.toFormattedFileSize(), ) } } @@ -412,7 +413,7 @@ fun HomeScreen() { ) { scope.Item { Title(R.string.home_enabled_modules) - Description(it.totalEnabled.toString()) + Description(al.totalEnabled.toString()) } } @@ -424,7 +425,7 @@ fun HomeScreen() { ) { scope.Item { Title(R.string.home_disabled_modules) - Description(it.totalDisabled.toString()) + Description(al.totalDisabled.toString()) } } } @@ -445,18 +446,12 @@ fun HomeScreen() { scope.Item { Title( id = R.string.home_support_title, - styleTransform = { - val newStyle = it.copy(color = Color.Unspecified) - it.merge(newStyle) - }, + style = style.titleStyle.copy(color=Color.Unspecified) ) Description( id = R.string.home_support_content, - styleTransform = { - val newStyle = it.copy(color = Color.Unspecified) - it.merge(newStyle) - }, + style = style.titleStyle.copy(color=Color.Unspecified) ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt index 09c3317d5..821eb41e7 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/AboutModule.kt @@ -23,6 +23,7 @@ import com.dergoogler.mmrl.ui.screens.moduleView.listItemContentPaddingValues import com.ramcosta.composedestinations.generated.destinations.DescriptionScreenDestination import dev.mmrlx.compose.ui.Text import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListDefaults import dev.mmrlx.compose.ui.list.ListItemSlot import dev.mmrlx.compose.ui.list.component.ButtonItem import dev.mmrlx.compose.ui.list.component.Item @@ -38,7 +39,7 @@ internal fun AboutModule() { val categoriesLazyListState = rememberLazyListState() List( - contentPadding = listItemContentPaddingValues, + style = ListDefaults.style.copy(contentPadding = listItemContentPaddingValues), ) { if (!module.readme.isNullOrBlank()) { ButtonItem( diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt index 6e7f70943..5443b1328 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Header.kt @@ -43,10 +43,11 @@ import dev.mmrlx.compose.ui.button.Button import dev.mmrlx.compose.ui.button.ButtonVariant import dev.mmrlx.compose.ui.button.Divider import dev.mmrlx.compose.ui.button.HorizontalButtonGroup -import dev.mmrlx.compose.ui.dialog.Item import dev.mmrlx.compose.ui.dialog.PopupMenu import dev.mmrlx.compose.ui.dialog.rememberPopupMenuState import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.list.component.ButtonItem +import dev.mmrlx.compose.ui.list.component.item.Title import dev.mmrlx.compose.ui.text.FormatText import dev.mmrlx.compose.ui.theme.MMRLXTheme @@ -241,16 +242,19 @@ internal fun Header() { maxWidth = 220.dp ) { val latestVersionDownloadEnabled = vm.lastVersionItem != null - Item( - enabled = latestVersionDownloadEnabled, - icon = R.drawable.file_download, - title = "Download latest", + ButtonItem( onClick = { if (latestVersionDownloadEnabled) { download(vm.lastVersionItem!!, false) } } - ) + ) { + Title(text = "Download latest") + Icon( + painter = painterResource(id = R.drawable.file_download), + contentDescription = null + ) + } } } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt index 2c8fa0fb1..ddc82f41c 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information.kt @@ -30,6 +30,7 @@ import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel import com.dergoogler.mmrl.utils.toFormattedDateSafely import dev.mmrlx.compose.ui.Text import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListDefaults import dev.mmrlx.compose.ui.list.ListItemSlot import dev.mmrlx.compose.ui.list.component.CollapseItem import dev.mmrlx.compose.ui.list.component.item.Icon @@ -155,22 +156,18 @@ internal fun Information() { local.isValid { loc -> List( - contentPadding = - PaddingValues( + style = ListDefaults.style.copy( + contentPadding = PaddingValues( vertical = 8.dp, horizontal = 16.dp, - ), + ) + ), ) { CollapseItem( first = { icon, rotation -> Title( id = R.string.module_installed, - styleTransform = { - val newStyle = - MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.surfaceTint) - - it.merge(newStyle) - }, + style = style.titleStyle.copy(color = MaterialTheme.colorScheme.surfaceTint), ) Icon( slot = ListItemSlot.End, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt index 54d7a3bff..ab43dcac6 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/moduleView/sections/Information0.kt @@ -19,6 +19,7 @@ import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalModuleViewModel import com.dergoogler.mmrl.ui.screens.moduleView.providable.LocalRequireModules import com.dergoogler.mmrl.ui.screens.moduleView.subListItemContentPaddingValues import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.ListDefaults import dev.mmrlx.compose.ui.list.ListItemSlot import dev.mmrlx.compose.ui.list.component.ButtonItem import dev.mmrlx.compose.ui.list.component.CollapseItem @@ -36,7 +37,7 @@ internal fun Information0() { val requires = LocalRequireModules.current List( - contentPadding = listItemContentPaddingValues, + style = ListDefaults.style.copy(contentPadding = listItemContentPaddingValues), ) { CollapseItem( first = { icon, rotation -> @@ -51,7 +52,7 @@ internal fun Information0() { }, ) { List( - contentPadding = subListItemContentPaddingValues, + style = style.copy(contentPadding = subListItemContentPaddingValues), ) { module.donate.ifNotNullOrBlank { ButtonItem( @@ -121,10 +122,9 @@ internal fun Information0() { }, ) { List( - contentPadding = subListItemContentPaddingValues, + style = style.copy(contentPadding = subListItemContentPaddingValues), ) { PermissionItem( - contentPadding = subListItemContentPaddingValues, permissions = it, ) } @@ -154,10 +154,9 @@ internal fun Information0() { }, ) { List( - contentPadding = subListItemContentPaddingValues, + style = style.copy(contentPadding = subListItemContentPaddingValues), ) { AntiFeaturesItem( - contentPadding = subListItemContentPaddingValues, antifeatures = it, ) } @@ -187,7 +186,7 @@ internal fun Information0() { }, ) { List( - contentPadding = subListItemContentPaddingValues, + style = style.copy(contentPadding = subListItemContentPaddingValues), ) { requiredIds.forEach { onlineModule -> ButtonItem( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b4b23b6de..2e890301c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -43,7 +43,7 @@ squareRetrofit = "2.11.0" squareOkhttp = "4.12.0" squareMoshi = "1.15.1" runtimeAndroid = "1.12.1" -mmrlx = "1.0.263" +mmrlx = "1.0.289" workRuntimeKtx = "2.10.0" lifecycleProcess = "2.8.7" apacheCommons = "1.27.1" From 0470cac352b9020eb2466f3a5c3107f726c390e8 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:14:19 +0100 Subject: [PATCH 50/55] Refresh repository and module card layouts Use MMRLX styling and grouped actions for repository cards, and remove the detailed module card width constraint. --- .../mmrl/ui/screens/home/HomeScreen.kt | 8 +- .../screens/repositories/RepositoriesList.kt | 4 +- .../ui/screens/repositories/RepositoryItem.kt | 267 +++++++++--------- .../screens/repository/ModuleItemDetailed.kt | 1 - 4 files changed, 146 insertions(+), 134 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt index 39474c040..18d2fbbb4 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/home/HomeScreen.kt @@ -231,10 +231,10 @@ fun HomeScreen() { scope.Item { Title { Text( - "DEV BUILD! EXPECT ERRORS AND BROKEN UI/UX", + "ONGOING UI/UX MIGRATION!", style = LocalTextStyle.current.copy( fontFamily = FontFamily.Monospace, - color = Color.Red + color = Color.Yellow ) ) } @@ -446,12 +446,12 @@ fun HomeScreen() { scope.Item { Title( id = R.string.home_support_title, - style = style.titleStyle.copy(color=Color.Unspecified) + style = style.titleStyle.copy(color = Color.Unspecified) ) Description( id = R.string.home_support_content, - style = style.titleStyle.copy(color=Color.Unspecified) + style = style.titleStyle.copy(color = Color.Unspecified) ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt index 2b2aa5ec8..751a4d2dd 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesList.kt @@ -42,8 +42,8 @@ fun ScaffoldScope.RepositoriesList( LazyColumn( state = state, - contentPadding = this@RepositoriesList.contentPadding + 16.dp, - verticalArrangement = Arrangement.spacedBy(10.dp), + contentPadding = this@RepositoriesList.contentPadding + 8.dp, + verticalArrangement = Arrangement.spacedBy(8.dp), ) { item { ExploreReposCard() diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt index ede01ab94..875f68eb0 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt @@ -2,10 +2,10 @@ package com.dergoogler.mmrl.ui.screens.repositories import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.absolutePadding @@ -14,12 +14,8 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.FilledTonalButton -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -47,8 +43,6 @@ import com.dergoogler.mmrl.model.state.RepoState import com.dergoogler.mmrl.ui.component.BottomSheet import com.dergoogler.mmrl.ui.component.Cover import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.LabelItemDefaults -import com.dergoogler.mmrl.ui.component.card.Card import com.dergoogler.mmrl.ui.component.listItem.dsl.List import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon @@ -56,6 +50,17 @@ import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.utils.toFormattedDateSafely import dev.dergoogler.mmrl.compat.core.LocalUriHandler +import dev.mmrlx.compose.layout.flashlightCard +import dev.mmrlx.compose.ui.Badge +import dev.mmrlx.compose.ui.BadgeVariant +import dev.mmrlx.compose.ui.HorizontalDivider +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.button.Button +import dev.mmrlx.compose.ui.button.ButtonGroupScope +import dev.mmrlx.compose.ui.button.ButtonVariant +import dev.mmrlx.compose.ui.button.HorizontalButtonGroup +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun RepositoryItem( @@ -78,145 +83,155 @@ fun RepositoryItem( val repoCover = repo.cover.nullable(menu.showCover) { it } - Card( - enabled = repo.compatible, - onClick = onClick, + + Column( + modifier = Modifier + .combinedClickable( + onClick = onClick, + enabled = repo.compatible + ) + .fillMaxWidth() + .flashlightCard() ) { - Column( - modifier = Modifier.relative(), - ) { - repoCover.nullable(menu.showCover) { - if (it.isNotEmpty()) { - Box( - contentAlignment = Alignment.Center, - ) { - Cover( - modifier = - Modifier.fadingEdge( - brush = - Brush.verticalGradient( - colors = - listOf( - Color.Transparent, - Color.Black, - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), - ), - url = it, - ) + repoCover.nullable(menu.showCover) { + if (it.isNotEmpty()) { + Box( + contentAlignment = Alignment.Center, + ) { + Cover( + modifier = + Modifier.fadingEdge( + brush = + Brush.verticalGradient( + colors = + listOf( + Color.Transparent, + Color.Black, + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, + ), + ), + url = it, + ) - menu.showModulesCount.takeTrue { - Box( - modifier = - Modifier - .absolutePadding( - top = 16.dp, - right = 16.dp, - ).align(Alignment.TopEnd), - ) { - ModuleCountLabelItem(repo) - } + menu.showModulesCount.takeTrue { + Box( + modifier = + Modifier + .absolutePadding( + top = 16.dp, + right = 16.dp, + ) + .align(Alignment.TopEnd), + ) { + ModuleCountLabelItem(repo) } } } } + } - Row( - modifier = Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp), - verticalAlignment = Alignment.Top, + Row( + modifier = Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp), + verticalAlignment = Alignment.Top, + ) { + Column( + modifier = + Modifier + .weight(1f) + .alpha(alpha), + verticalArrangement = Arrangement.spacedBy(2.dp), ) { - Column( - modifier = - Modifier - .weight(1f) - .alpha(alpha), - verticalArrangement = Arrangement.spacedBy(2.dp), - ) { + Text( + text = repo.name, + style = + MaterialTheme.typography.titleSmall + .copy(fontWeight = FontWeight.Bold), + maxLines = 2, + overflow = TextOverflow.Ellipsis, + textDecoration = textDecoration, + ) + + menu.showUpdatedTime.takeTrue { Text( - text = repo.name, - style = - MaterialTheme.typography.titleSmall - .copy(fontWeight = FontWeight.Bold), - maxLines = 2, - overflow = TextOverflow.Ellipsis, + text = + stringResource( + id = R.string.module_update_at, + repo.timestamp.toFormattedDateSafely, + ), + style = MMRLXTheme.typography.bodySmall, + color = MMRLXTheme.colors.secondaryForeground, textDecoration = textDecoration, ) - - menu.showUpdatedTime.takeTrue { - Text( - text = - stringResource( - id = R.string.module_update_at, - repo.timestamp.toFormattedDateSafely, - ), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.outline, - textDecoration = textDecoration, - ) - } - } - - if (repoCover == null && menu.showModulesCount) { - ModuleCountLabelItem(repo) } } - repo.description.nullable { - Text( - modifier = - Modifier - .alpha(alpha = alpha) - .padding(top = 16.dp) - .padding(horizontal = 16.dp), - text = it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.outline, - ) + if (repoCover == null && menu.showModulesCount) { + ModuleCountLabelItem(repo) } + } - HorizontalDivider( - thickness = 1.5.dp, - color = MaterialTheme.colorScheme.surface, - modifier = Modifier.padding(top = 8.dp), - ) - - Row( + repo.description.nullable { + Text( modifier = Modifier - .padding(horizontal = 16.dp, vertical = 8.dp), - horizontalArrangement = Arrangement.spacedBy(8.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - var open by remember { mutableStateOf(false) } - if (open) { - BottomSheetForItem( - repo = repo, - onDelete = delete, - onClose = { open = false }, - ) - } + .alpha(alpha = alpha) + .padding(top = 16.dp) + .padding(horizontal = 16.dp), + text = it, + style = MMRLXTheme.typography.bodySmall, + color = MMRLXTheme.colors.secondaryForeground, + ) + } + + HorizontalDivider( + modifier = Modifier.padding(top = 8.dp), + ) + Row( + modifier = + Modifier + .padding(horizontal = 16.dp, vertical = 8.dp), + horizontalArrangement = Arrangement.spacedBy(8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + var open by remember { mutableStateOf(false) } + if (open) { + BottomSheetForItem( + repo = repo, + onDelete = delete, + onClose = { open = false }, + ) + } + + HorizontalButtonGroup { CardButtonItem( + index = 0, + count = 1, icon = R.drawable.share, enabled = isEnabled, onClick = { context.shareText(repo.url) }, ) + } - Spacer(Modifier.weight(1f)) + Spacer(Modifier.weight(1f)) + HorizontalButtonGroup { CardButtonItem( - icon = R.drawable.at, - label = R.string.repo_options, - onClick = { open = true }, + index = 0, + count = 2, + icon = R.drawable.cloud_download, + label = R.string.repo_options_update, + onClick = update, enabled = isEnabled, ) CardButtonItem( - icon = R.drawable.cloud_download, - label = R.string.repo_options_update, - onClick = update, + index = 1, + count = 2, + icon = R.drawable.dots_vertical, + onClick = { open = true }, enabled = isEnabled, ) } @@ -338,15 +353,18 @@ private fun BottomSheetForItem( } @Composable -private fun CardButtonItem( +private fun ButtonGroupScope.CardButtonItem( @DrawableRes icon: Int, @StringRes label: Int? = null, onClick: () -> Unit, + index: Int, + count: Int, enabled: Boolean = true, -) = FilledTonalButton( +) = Button( onClick = onClick, enabled = enabled, - contentPadding = PaddingValues(horizontal = 12.dp), + shape = shape(index, count), + variant = ButtonVariant.Outline, ) { Icon( modifier = Modifier.size(20.dp), @@ -355,7 +373,7 @@ private fun CardButtonItem( ) label?.let { - Spacer(modifier = Modifier.width(6.dp)) + Spacer(modifier = Modifier.width(8.dp)) Text( text = stringResource(id = label), ) @@ -365,18 +383,13 @@ private fun CardButtonItem( @Composable private fun ModuleCountLabelItem(repo: RepoState) { if (repo.compatible) { - LabelItem( + Badge( text = stringResource(id = R.string.repo_modules, repo.size), - upperCase = false, ) } else { - LabelItem( + Badge( text = stringResource(id = R.string.repo_incompatible), - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.error, - contentColor = MaterialTheme.colorScheme.onError, - ), + variant = BadgeVariant.Warning ) } } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt index 29eff135e..defee1444 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt @@ -109,7 +109,6 @@ fun ModuleItemDetailed( onClick = onClick, enabled = enabled ) - .widthIn(600.dp) .fillMaxWidth() .flashlightCard() ) { From 0157264e70166202c41e23635239cd51cd42dd53 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:21:42 +0100 Subject: [PATCH 51/55] Restyle explore repositories card Use the MMRLX flashlight card, typography, and colors while preserving navigation to repository exploration. --- .../repositories/items/ExploreReposCard.kt | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/items/ExploreReposCard.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/items/ExploreReposCard.kt index af0721290..8c7ed6e8f 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/items/ExploreReposCard.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/items/ExploreReposCard.kt @@ -1,5 +1,6 @@ package com.dergoogler.mmrl.ui.screens.repositories.items +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -8,9 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -18,25 +17,29 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ui.component.card.Card import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.ramcosta.composedestinations.generated.destinations.ExploreRepositoriesScreenDestination +import dev.mmrlx.compose.layout.flashlightCard +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.icon.Icon +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun ExploreReposCard() { val navigator = LocalDestinationsNavigator.current - Card( - onClick = { - navigator.navigate(ExploreRepositoriesScreenDestination) - }, - modifier = - Modifier - .fillMaxWidth() - .padding(20.dp), + Column( + modifier = Modifier + .combinedClickable( + onClick = { + navigator.navigate(ExploreRepositoriesScreenDestination) + } + ) + .fillMaxWidth() + .flashlightCard() + .padding(20.dp) ) { Row( - modifier = Modifier.relative(), verticalAlignment = Alignment.CenterVertically, ) { Icon( @@ -46,7 +49,6 @@ fun ExploreReposCard() { id = R.drawable.cloud, ), contentDescription = null, - tint = MaterialTheme.colorScheme.primary, ) Spacer(modifier = Modifier.width(16.dp)) @@ -56,14 +58,14 @@ fun ExploreReposCard() { ) { Text( text = stringResource(R.string.explore_more_repositories), - style = MaterialTheme.typography.titleMedium, - color = MaterialTheme.colorScheme.onSurface, + style = MMRLXTheme.typography.titleMedium, + color = MMRLXTheme.colors.secondaryForeground, ) Text( text = stringResource(R.string.get_the_most_out_of_mmrl), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurface, + style = MMRLXTheme.typography.bodyMedium, + color = MMRLXTheme.colors.secondaryForeground, ) } } From b187e59538e7c6488d972011be6fdb6c786f2fbd Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:22:07 +0100 Subject: [PATCH 52/55] Use shared pull-to-refresh components Switch the repositories screen from Material 3 pull-to-refresh imports to the shared `dev.mmrlx.compose.ui` components. --- .../mmrl/ui/screens/repositories/RepositoriesScreen.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt index 8f0365f50..43c1d7b1b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoriesScreen.kt @@ -16,9 +16,9 @@ import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.TextButton -import androidx.compose.material3.pulltorefresh.PullToRefreshBox -import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator -import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState +import dev.mmrlx.compose.ui.PullToRefreshBox +import dev.mmrlx.compose.ui.PullToRefreshDefaults.Indicator +import dev.mmrlx.compose.ui.rememberPullToRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf From a4fae993b9872904f5aa7fcc6ade1dd9f8e56e41 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:53:12 +0100 Subject: [PATCH 53/55] Migrate repository exploration UI to MMRLX Update exploration screens and cards to use MMRLX scaffolds, toolbars, components, and theme styling. Limit repository descriptions to three lines. --- .../ExploreRepositoriesScreen.kt | 141 +++-- .../ExploreRepositoryScreen.kt | 516 ++++++++++-------- .../exploreRepositories/items/HeadlineCard.kt | 103 ++-- .../exploreRepositories/items/MemberCard.kt | 109 ++-- .../exploreRepositories/items/RepoCard.kt | 185 ++++--- 5 files changed, 568 insertions(+), 486 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoriesScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoriesScreen.kt index bfdd5143d..72d6e92cb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoriesScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoriesScreen.kt @@ -4,13 +4,10 @@ import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -22,109 +19,97 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.none import com.dergoogler.mmrl.ext.nullable +import com.dergoogler.mmrl.ext.plus import com.dergoogler.mmrl.model.online.ExploreRepository import com.dergoogler.mmrl.network.runRequest import com.dergoogler.mmrl.stub.IMMRLApiManager import com.dergoogler.mmrl.ui.component.Loading -import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurNavigateUpToolbar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator -import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings import com.dergoogler.mmrl.ui.screens.exploreRepositories.items.HeadlineCard import com.dergoogler.mmrl.ui.screens.exploreRepositories.items.RepoCard import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph -import dev.chrisbanes.haze.hazeSource +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.toolbar.NavigateUpToolbar +import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import timber.log.Timber @Destination @Composable -fun ExploreRepositoriesScreen() = - LocalScreenProvider { - var exploreRepositories by remember { mutableStateOf?>(null) } +fun ExploreRepositoriesScreen() { + var exploreRepositories by remember { mutableStateOf?>(null) } - val navigator = LocalDestinationsNavigator.current - val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior() + val navigator = LocalDestinationsNavigator.current + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() - LaunchedEffect(Unit) { - runRequest { - withContext(Dispatchers.IO) { - val api = IMMRLApiManager.build() - return@withContext api.repositories.execute() - } - }.onSuccess { list -> - exploreRepositories = list - }.onFailure { - Timber.e(it, "unable to get recommended repos") + LaunchedEffect(Unit) { + runRequest { + withContext(Dispatchers.IO) { + val api = IMMRLApiManager.build() + return@withContext api.repositories.execute() } + }.onSuccess { list -> + exploreRepositories = list + }.onFailure { + Timber.e(it, "unable to get recommended repos") } + } - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - BlurNavigateUpToolbar( - title = stringResource(id = R.string.explore_repositories), - fade = true, - fadeDistance = 50f, - ) - }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - this@Scaffold.ResponsiveContent { - AnimatedVisibility( - visible = exploreRepositories == null, - enter = fadeIn(), - exit = fadeOut(), - ) { - Loading() - } + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + NavigateUpToolbar( + navigator = navigator, + title = stringResource(id = R.string.explore_repositories), + scrollBehavior = scrollBehavior + ) + }, + ) { + AnimatedVisibility( + visible = exploreRepositories == null, + enter = fadeIn(), + exit = fadeOut(), + ) { + Loading() + } - AnimatedVisibility( - visible = exploreRepositories != null, - enter = fadeIn(), - exit = fadeOut(), + AnimatedVisibility( + visible = exploreRepositories != null, + enter = fadeIn(), + exit = fadeOut(), + ) { + exploreRepositories.nullable { er -> + LazyColumn( + modifier = Modifier.scaffoldHazeSource(), + verticalArrangement = Arrangement.spacedBy(8.dp), + contentPadding = contentPadding + 16.dp, ) { - exploreRepositories.nullable { er -> - LazyColumn( - modifier = Modifier.hazeSource(LocalHazeState.current), - verticalArrangement = Arrangement.spacedBy(16.dp), - contentPadding = - PaddingValues( - start = 16.dp, - top = innerPadding.calculateTopPadding() + 16.dp, - end = 16.dp, - bottom = 16.dp, - ), - ) { - item { - HeadlineCard( - repoCount = er.size, - moduleCount = er.sumOf { it.modulesCount ?: 0 }, - ) - } + item { + HeadlineCard( + repoCount = er.size, + moduleCount = er.sumOf { it.modulesCount ?: 0 }, + ) + } - items( - items = er, - key = { it.url }, - ) { repo -> - RepoCard( - repo = repo, - ) - } + items( + items = er, + key = { it.url }, + ) { repo -> + RepoCard( + repo = repo, + ) + } - item { - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } - } + item { + val paddingValues = LocalMainScreenInnerPaddings.current + Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) } } } } } +} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt index cbc4e0039..687cf6f3b 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/ExploreRepositoryScreen.kt @@ -2,6 +2,7 @@ package com.dergoogler.mmrl.ui.screens.exploreRepositories import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row @@ -14,14 +15,8 @@ import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items -import androidx.compose.material3.Button -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedButton -import androidx.compose.material3.SnackbarDuration -import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -36,7 +31,9 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.dergoogler.mmrl.R @@ -49,15 +46,6 @@ import com.dergoogler.mmrl.ext.systemBarsPaddingEnd import com.dergoogler.mmrl.ext.toDecodedUrl import com.dergoogler.mmrl.model.online.ExploreRepository import com.dergoogler.mmrl.ui.component.Cover -import com.dergoogler.mmrl.ui.component.HorizontalDividerWithText -import com.dergoogler.mmrl.ui.component.LocalScreenProvider -import com.dergoogler.mmrl.ui.component.listItem.dsl.List -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.ButtonItem -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.Item -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Icon -import com.dergoogler.mmrl.ui.component.listItem.dsl.component.item.Title -import com.dergoogler.mmrl.ui.component.scaffold.Scaffold -import com.dergoogler.mmrl.ui.component.toolbar.BlurNavigateUpToolbar import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalHazeState import com.dergoogler.mmrl.ui.providable.LocalMainScreenInnerPaddings @@ -70,256 +58,336 @@ import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.annotation.RootGraph import dev.chrisbanes.haze.hazeSource import dev.dergoogler.mmrl.compat.core.LocalUriHandler +import dev.mmrlx.compose.ui.HorizontalDivider +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.button.Button +import dev.mmrlx.compose.ui.button.ButtonVariant +import dev.mmrlx.compose.ui.list.List +import dev.mmrlx.compose.ui.list.component.ButtonItem +import dev.mmrlx.compose.ui.list.component.Item +import dev.mmrlx.compose.ui.list.component.item.Icon +import dev.mmrlx.compose.ui.list.component.item.Title +import dev.mmrlx.compose.ui.scaffold.Scaffold +import dev.mmrlx.compose.ui.theme.Border +import dev.mmrlx.compose.ui.theme.LocalBorder +import dev.mmrlx.compose.ui.theme.MMRLXTheme +import dev.mmrlx.compose.ui.toolbar.NavigateUpToolbar import dev.mmrlx.compose.ui.toolbar.ToolbarDefaults import kotlinx.coroutines.launch @Destination @Composable -fun ExploreRepositoryScreen(repo: ExploreRepository) = - LocalScreenProvider { - val viewModel = hiltViewModel() - val navigator = LocalDestinationsNavigator.current - val scope = rememberCoroutineScope() - val snackbarHostState = LocalSnackbarHost.current - val browser = LocalUriHandler.current - val scrollBehavior = ToolbarDefaults.pinnedScrollBehavior() +fun ExploreRepositoryScreen(repo: ExploreRepository) { + val viewModel = hiltViewModel() + val navigator = LocalDestinationsNavigator.current + val scope = rememberCoroutineScope() + val snackbarHostState = LocalSnackbarHost.current + val browser = LocalUriHandler.current + val scrollBehavior = ToolbarDefaults.fadePinnedScrollBehavior() - val userPreferences = LocalUserPreferences.current - val repositoriesMenu = userPreferences.repositoriesMenu + val userPreferences = LocalUserPreferences.current + val repositoriesMenu = userPreferences.repositoriesMenu - val context = LocalContext.current + val context = LocalContext.current + val colors = MMRLXTheme.colors - var failure by remember { mutableStateOf(false) } - var message: String by remember { mutableStateOf("") } + var failure by remember { mutableStateOf(false) } + var message by remember { mutableStateOf("") } - if (failure) { - FailureDialog( - name = repo.url, - message = message, - onClose = { - failure = false - message = "" - }, - ) - } + if (failure) { + FailureDialog( + name = repo.url, + message = message, + onClose = { + failure = false + message = "" + }, + ) + } - val onAdd: () -> Unit = { - viewModel.insert(url = repo.url, onSuccess = { + val onAdd: () -> Unit = { + viewModel.insert( + url = repo.url, + onSuccess = { scope.launch { snackbarHostState.showSnackbar( message = context.getString(R.string.repo_added), - duration = SnackbarDuration.Short, + duration = androidx.compose.material3.SnackbarDuration.Short, ) } - }, onFailure = { e -> + }, + onFailure = { e -> failure = true message = e.stackTraceToString() - }) - } - - Scaffold( - modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), - topBar = { - BlurNavigateUpToolbar( - navigator = navigator, - title = "", - scrollBehavior = scrollBehavior, - fade = true, - fadeBackgroundIfNoBlur = true, - ) }, - contentWindowInsets = WindowInsets.none, - ) { innerPadding -> - this@Scaffold.ResponsiveContent { - LazyVerticalGrid( - modifier = Modifier.hazeSource(LocalHazeState.current), - columns = GridCells.Fixed(2), - contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = 16.dp), - horizontalArrangement = Arrangement.spacedBy(16.dp), - verticalArrangement = Arrangement.spacedBy(16.dp), - ) { - item(span = { GridItemSpan(2) }) { - List( - modifier = - Modifier - .let { - if (repositoriesMenu.showCover && repo.hasCover) { - Modifier - } else { - it.padding(innerPadding) - } - }.fillMaxWidth() - .fillWidthOfParent(16.dp), - ) { - repo.cover.nullable(repositoriesMenu.showCover) { - if (it.isNotEmpty()) { - Cover( - modifier = - Modifier.fadingEdge( - Brush.verticalGradient( - colors = - listOf( - Color.Transparent, - Color.Black, - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), - ), - url = it, - ) - } + ) + } + + Scaffold( + modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection), + toolbar = { + NavigateUpToolbar( + navigator = navigator, + title = "", + scrollBehavior = scrollBehavior, + ) + }, + contentWindowInsets = WindowInsets.none, + ) { + LazyVerticalGrid( + modifier = Modifier.scaffoldHazeSource(), + columns = GridCells.Fixed(2), + contentPadding = PaddingValues( + start = 16.dp, + end = 16.dp, + bottom = 16.dp, + ), + horizontalArrangement = Arrangement.spacedBy(16.dp), + verticalArrangement = Arrangement.spacedBy(16.dp), + ) { + item(span = { GridItemSpan(2) }) { + List( + modifier = Modifier + .let { + if (repositoriesMenu.showCover && repo.hasCover) { + it + } else { + it.padding(contentPadding) } + } + .fillMaxWidth() + .fillWidthOfParent(16.dp), + ) { + repo.cover.nullable(repositoriesMenu.showCover) { + if (it.isNotEmpty()) { + Cover( + modifier = Modifier.fadingEdge( + Brush.verticalGradient( + colors = listOf( + Color.Transparent, + Color.Black, + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, + ), + ), + url = it, + ) + } + } + + Column( + modifier = Modifier.systemBarsPaddingEnd(), + ) { + Spacer(modifier = Modifier.height(16.dp)) + Row( + modifier = Modifier.padding(horizontal = 16.dp), + verticalAlignment = Alignment.Top, + ) { Column( - modifier = - Modifier - .systemBarsPaddingEnd(), + modifier = Modifier.weight(1f), ) { - Spacer(modifier = Modifier.height(16.dp)) - - Row( - modifier = Modifier.padding(horizontal = 16.dp), - verticalAlignment = Alignment.Top, - ) { - Column( - modifier = Modifier.weight(1f), - ) { - Text( - text = repo.name.toDecodedUrl(), - style = MaterialTheme.typography.titleLarge, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - ) - - Spacer(modifier = Modifier.height(4.dp)) - - Text( - modifier = - Modifier.clickable( - onClick = { - browser.openUri(repo.url) - }, - ), - text = repo.url, - style = MaterialTheme.typography.bodyMedium.copy(color = MaterialTheme.colorScheme.surfaceTint), - maxLines = 2, - overflow = TextOverflow.Ellipsis, - ) - } - } - - Spacer(modifier = Modifier.height(16.dp)) - - Row( - modifier = Modifier.padding(horizontal = 16.dp), - verticalAlignment = Alignment.Top, - horizontalArrangement = Arrangement.spacedBy(16.dp), - ) { - repo.submission.nullable { - OutlinedButton( - modifier = - Modifier - .fillMaxWidth() - .weight(1f), - onClick = { - browser.openUri(it) - }, - ) { - Text( - text = - stringResource( - id = R.string.submit_module, - ), - maxLines = 1, - ) - } - } + Text( + text = repo.name.toDecodedUrl(), + style = MMRLXTheme.typography.titleLarge, + color = colors.foreground, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + ) - Button( - modifier = - Modifier - .fillMaxWidth() - .weight(1f), - onClick = onAdd, - ) { - Text( - text = stringResource(id = R.string.repo_add_dialog_add), - maxLines = 1, - ) - } - } + Spacer(modifier = Modifier.height(4.dp)) - HorizontalDivider( - modifier = Modifier.padding(vertical = 16.dp), - thickness = 0.9.dp, + Text( + modifier = Modifier.clickable { + browser.openUri(repo.url) + }, + text = repo.url, + style = MMRLXTheme.typography.bodyMedium, + color = colors.primary, + maxLines = 2, + overflow = TextOverflow.Ellipsis, ) + } + } - repo.description.nullable { - this@List.Item { - Title(R.string.about_this_repository) - } + Spacer(modifier = Modifier.height(16.dp)) + Row( + modifier = Modifier.padding(horizontal = 16.dp), + verticalAlignment = Alignment.Top, + horizontalArrangement = Arrangement.spacedBy(16.dp), + ) { + repo.submission.nullable { + Button( + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onClick = { + browser.openUri(it) + }, + variant = ButtonVariant.Outline, + ) { Text( - modifier = Modifier.padding(horizontal = 16.dp), - text = it.toDecodedUrl(force = true), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.outline, + text = stringResource(R.string.submit_module), + maxLines = 1, ) } + } - Spacer(modifier = Modifier.height(8.dp)) + Button( + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onClick = onAdd, + ) { + Text( + text = stringResource(R.string.repo_add_dialog_add), + maxLines = 1, + ) + } + } - List { - repo.modulesCount.nullable { - Item { - Icon(painter = painterResource(id = R.drawable.keyframes)) - Title( - pluralStringResource( - id = R.plurals.module_count_explore_repo, - count = it, - it, - ), - ) - } - } + HorizontalDivider( + modifier = Modifier.padding(vertical = 16.dp), + thickness = 0.9.dp, + color = colors.border, + ) - repo.donate.nullable { - ButtonItem( - onClick = { - browser.openUri(it) - }, - ) { - Icon(painter = painterResource(id = R.drawable.currency_dollar)) - Title(R.string.view_module_donate) - } - } - } + repo.description.nullable { + this@List.Item { + Title(R.string.about_this_repository) } - } - } - if (repo.members.isNotNullOrEmpty()) { - item(span = { GridItemSpan(2) }) { - HorizontalDividerWithText( - text = stringResource(R.string.team), - thickness = 0.9.dp, + Text( + modifier = Modifier.padding(horizontal = 16.dp), + text = it.toDecodedUrl(force = true), + style = MMRLXTheme.typography.bodyMedium, + color = colors.mutedForeground, ) } - items( - items = repo.members, - key = { it.name }, - ) { - MemberCard(member = it) + Spacer(modifier = Modifier.height(8.dp)) + + List { + repo.modulesCount.nullable { + Item { + Icon(painter = painterResource(R.drawable.keyframes)) + Title( + pluralStringResource( + id = R.plurals.module_count_explore_repo, + count = it, + it, + ), + ) + } + } + + repo.donate.nullable { + ButtonItem( + onClick = { + browser.openUri(it) + }, + ) { + Icon(painter = painterResource(R.drawable.currency_dollar)) + Title(R.string.view_module_donate) + } + } } } + } + } - item(span = { GridItemSpan(2) }) { - val paddingValues = LocalMainScreenInnerPaddings.current - Spacer(modifier = Modifier.height(paddingValues.calculateBottomPadding())) - } + if (repo.members.isNotNullOrEmpty()) { + item(span = { GridItemSpan(2) }) { + HorizontalDividerWithText( + text = stringResource(R.string.team), + color = MMRLXTheme.colors.accentForeground, + thickness = 0.9.dp, + ) + } + + items( + items = repo.members, + key = { it.name }, + ) { + MemberCard(member = it) } } + + item(span = { GridItemSpan(2) }) { + val paddingValues = LocalMainScreenInnerPaddings.current + Spacer( + modifier = Modifier.height( + paddingValues.calculateBottomPadding(), + ), + ) + } + } + } +} + +@Composable +fun HorizontalDividerWithText( + text: String, + color: Color = MMRLXTheme.border.color, + textStyle: TextStyle = + MMRLXTheme.typography.titleMedium.copy( + color = color, + ), + paddingValues: PaddingValues = PaddingValues(horizontal = 16.dp, vertical = 8.dp), + thickness: Dp = MMRLXTheme.border.dp, +) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, + modifier = Modifier.padding(paddingValues), + ) { + HorizontalDivider( + color = color, + modifier = + Modifier + .weight(1f) + .fadingEdge( + Brush.horizontalGradient( + colors = + listOf( + Color.Transparent, + Color.Black, + ), + startX = 0f, + endX = Float.POSITIVE_INFINITY, + ), + ), + thickness = thickness, + ) + + Box( + modifier = Modifier.padding(horizontal = 24.dp), + ) { + Text( + text = text, + style = textStyle, + ) } + + HorizontalDivider( + color = color, + modifier = + Modifier + .weight(1f) + .fadingEdge( + Brush.horizontalGradient( + colors = + listOf( + Color.Transparent, + Color.Black, + ), + startX = Float.POSITIVE_INFINITY, + endX = 0f, + ), + ), + thickness = thickness, + ) } +} diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/HeadlineCard.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/HeadlineCard.kt index 16015fce1..81823227e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/HeadlineCard.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/HeadlineCard.kt @@ -9,9 +9,7 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text -import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -20,38 +18,42 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ui.component.text.BBCodeText +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun HeadlineCard( repoCount: Int, moduleCount: Int, ) { + val colors = MMRLXTheme.colors + Box( - modifier = - Modifier - .fillMaxWidth() - .background( - brush = - Brush.linearGradient( - colors = - listOf( - MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp), - MaterialTheme.colorScheme.background, - ), - start = Offset(0f, 0f), - end = Offset(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY), - ), - RoundedCornerShape(20.dp), - ).border( - Dp.Hairline, - MaterialTheme.colorScheme.outlineVariant, - RoundedCornerShape(20.dp), - ).padding(24.dp), + modifier = Modifier + .fillMaxWidth() + .background( + brush = Brush.linearGradient( + colors = listOf( + colors.secondary, + colors.background, + ), + start = Offset.Zero, + end = Offset( + Float.POSITIVE_INFINITY, + Float.POSITIVE_INFINITY, + ), + ), + shape = RoundedCornerShape(20.dp), + ) + .border( + MMRLXTheme.border.dp, + MMRLXTheme.border.color, + RoundedCornerShape(20.dp), + ) + .padding(24.dp), ) { Column( horizontalAlignment = Alignment.CenterHorizontally, @@ -59,23 +61,31 @@ fun HeadlineCard( ) { Text( text = stringResource(R.string.module_repositories), - style = MaterialTheme.typography.headlineMedium, + style = MMRLXTheme.typography.headlineMedium, fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.onBackground, + color = colors.foreground, ) BBCodeText( - text = stringResource(R.string.explore_repos_discover_text, repoCount, moduleCount), - style = MaterialTheme.typography.bodyMedium, + text = stringResource( + R.string.explore_repos_discover_text, + repoCount, + moduleCount, + ), + style = MMRLXTheme.typography.bodyMedium, textAlign = TextAlign.Center, - color = MaterialTheme.colorScheme.outlineVariant, + color = colors.foreground, lineHeight = 20.sp, ) Row( horizontalArrangement = Arrangement.spacedBy(20.dp), ) { - StatBox(repoCount.toString(), stringResource(R.string.page_repos)) + StatBox( + repoCount.toString(), + stringResource(R.string.page_repos), + ) + StatBox( stringResource(R.string.count_with_plus, moduleCount), stringResource(R.string.available_modules), @@ -90,27 +100,36 @@ fun StatBox( value: String, label: String, ) { + val colors = MMRLXTheme.colors + Column( - modifier = - Modifier - .background(MaterialTheme.colorScheme.background, RoundedCornerShape(20.dp)) - .border( - Dp.Hairline, - MaterialTheme.colorScheme.outlineVariant, - RoundedCornerShape(20.dp), - ).padding(horizontal = 24.dp, vertical = 12.dp), + modifier = Modifier + .background( + colors.background, + RoundedCornerShape(20.dp), + ) + .border( + MMRLXTheme.border.dp, + MMRLXTheme.border.color, + RoundedCornerShape(20.dp), + ) + .padding( + horizontal = 24.dp, + vertical = 12.dp, + ), horizontalAlignment = Alignment.CenterHorizontally, ) { Text( text = value, - style = MaterialTheme.typography.headlineSmall, + style = MMRLXTheme.typography.headlineSmall, fontWeight = FontWeight.Bold, - color = MaterialTheme.colorScheme.surfaceTint, + color = colors.foreground, ) + Text( text = label, - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.outline, + style = MMRLXTheme.typography.bodyMedium, + color = colors.mutedForeground, ) } -} +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/MemberCard.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/MemberCard.kt index 6efcca26a..85ed8a0ef 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/MemberCard.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/MemberCard.kt @@ -11,7 +11,6 @@ import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Icon -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.ripple @@ -20,6 +19,7 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import coil.compose.AsyncImage @@ -28,8 +28,9 @@ import com.dergoogler.mmrl.ext.isNotNullOrEmpty import com.dergoogler.mmrl.ext.nullable import com.dergoogler.mmrl.ext.toDecodedUrl import com.dergoogler.mmrl.model.online.ExploreRepositoryMember -import com.dergoogler.mmrl.ui.component.card.Card -import dev.dergoogler.mmrl.compat.core.LocalUriHandler +import dev.mmrlx.compose.layout.card +import dev.mmrlx.compose.ui.scaffold.PositionLayout +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun MemberCard( @@ -37,48 +38,47 @@ fun MemberCard( index: Int? = null, ) { val browser = LocalUriHandler.current + val colors = MMRLXTheme.colors val interactionSource = remember { MutableInteractionSource() } - Card { + PositionLayout(modifier = Modifier.card()) { index.nullable { if (it < 3) { Surface( - shape = - RoundedCornerShape( - topEnd = 20.dp, - bottomStart = 0.dp, - bottomEnd = 0.dp, - ), - color = MaterialTheme.colorScheme.primary, + shape = RoundedCornerShape( + topEnd = 20.dp, + bottomStart = 0.dp, + bottomEnd = 0.dp, + ), + color = colors.primary, modifier = Modifier.absolute(Alignment.TopEnd), ) { Text( text = "#${it + 1}", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onPrimary, - modifier = - Modifier - .padding(horizontal = 16.dp, vertical = 8.dp), + style = MMRLXTheme.typography.bodySmall, + color = colors.primaryForeground, + modifier = Modifier.padding( + horizontal = 16.dp, + vertical = 8.dp, + ), ) } } } Column( - modifier = - Modifier - .relative() - .fillMaxWidth() - .padding(horizontal = 32.dp, vertical = 48.dp), + modifier = Modifier + .relative() + .fillMaxWidth() + .padding(horizontal = 32.dp, vertical = 48.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center, ) { AsyncImage( model = member.avatar, - modifier = - Modifier - .size(60.dp) - .clip(RoundedCornerShape(100)), + modifier = Modifier + .size(60.dp) + .clip(RoundedCornerShape(100)), contentDescription = null, ) @@ -90,25 +90,26 @@ fun MemberCard( Text( text = member.name.toDecodedUrl(), maxLines = 1, - style = MaterialTheme.typography.titleMedium, + style = MMRLXTheme.typography.titleMedium, + color = colors.foreground, ) + member.title.nullable { Text( text = it.toDecodedUrl(), maxLines = 1, - style = MaterialTheme.typography.titleSmall.copy(color = MaterialTheme.colorScheme.outline), + style = MMRLXTheme.typography.titleSmall, + color = colors.mutedForeground, ) } if (member.links.isNotNullOrEmpty()) { LazyRow( - modifier = - Modifier.padding( - top = 24.dp, - start = 16.dp, - end = 16.dp, - bottom = 0.dp, - ), + modifier = Modifier.padding( + top = 24.dp, + start = 16.dp, + end = 16.dp, + ), horizontalArrangement = Arrangement.spacedBy(16.dp), ) { items( @@ -116,28 +117,26 @@ fun MemberCard( key = { it.icon }, ) { Icon( - painter = - painterResource( - id = - when (it.icon.lowercase()) { - "github" -> R.drawable.brand_github - "gitlab" -> R.drawable.brand_gitlab - "commit" -> R.drawable.git_commit - else -> R.drawable.transparent - }, + painter = painterResource( + id = when (it.icon.lowercase()) { + "github" -> R.drawable.brand_github + "gitlab" -> R.drawable.brand_gitlab + "commit" -> R.drawable.git_commit + else -> R.drawable.transparent + }, + ), + modifier = Modifier + .clip(RoundedCornerShape(100)) + .clickable( + enabled = true, + interactionSource = interactionSource, + onClick = { + browser.openUri(it.link) + }, + indication = ripple(), ), - modifier = - Modifier - .clip(RoundedCornerShape(100)) - .clickable( - enabled = true, - interactionSource = interactionSource, - onClick = { - browser.openUri(it.link) - }, - indication = ripple(), - ), contentDescription = it.icon.lowercase(), + tint = colors.foreground, ) } } @@ -145,4 +144,4 @@ fun MemberCard( } } } -} +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/RepoCard.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/RepoCard.kt index ae6e781e1..c35450e74 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/RepoCard.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/exploreRepositories/items/RepoCard.kt @@ -1,15 +1,15 @@ package com.dergoogler.mmrl.ui.screens.exploreRepositories.items +import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.absolutePadding +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -24,12 +24,14 @@ import com.dergoogler.mmrl.ext.fadingEdge import com.dergoogler.mmrl.ext.nullable import com.dergoogler.mmrl.model.online.ExploreRepository import com.dergoogler.mmrl.ui.component.Cover -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.card.Card import com.dergoogler.mmrl.ui.providable.LocalDestinationsNavigator import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.utils.toFormattedDateSafely import com.ramcosta.composedestinations.generated.destinations.ExploreRepositoryScreenDestination +import dev.mmrlx.compose.layout.flashlightCard +import dev.mmrlx.compose.ui.Badge +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun RepoCard(repo: ExploreRepository) { @@ -37,112 +39,121 @@ fun RepoCard(repo: ExploreRepository) { val userPreferences = LocalUserPreferences.current val menu = userPreferences.repositoriesMenu + val colors = MMRLXTheme.colors + val repoCover = repo.cover.nullable(menu.showCover) { it } - Card( - onClick = { - navigator.navigate(ExploreRepositoryScreenDestination(repo)) - }, + Column( + modifier = Modifier + .combinedClickable( + onClick = { + navigator.navigate(ExploreRepositoryScreenDestination(repo)) + }, + ) + .fillMaxWidth() + .flashlightCard(), ) { - Column( - modifier = Modifier.relative(), - ) { - repoCover.nullable(menu.showCover) { - if (it.isNotEmpty()) { - Box( - contentAlignment = Alignment.Center, - ) { - Cover( - modifier = - Modifier.fadingEdge( - brush = - Brush.verticalGradient( - colors = - listOf( - Color.Transparent, - Color.Black, - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), + repoCover.nullable(menu.showCover) { + if (it.isNotEmpty()) { + Box( + contentAlignment = Alignment.Center, + ) { + Cover( + modifier = Modifier.fadingEdge( + brush = Brush.verticalGradient( + colors = listOf( + Color.Transparent, + Color.Black, ), - url = it, - ) + startY = Float.POSITIVE_INFINITY, + endY = 0f, + ), + ), + url = it, + ) - repo.modulesCount.nullable(menu.showModulesCount) { - Box( - modifier = - Modifier - .absolutePadding( - top = 16.dp, - right = 16.dp, - ).align(Alignment.TopEnd), - ) { - ModuleCountLabelItem(it) - } + repo.modulesCount.nullable(menu.showModulesCount) { + Box( + modifier = Modifier + .absolutePadding( + top = 16.dp, + right = 16.dp, + ) + .align(Alignment.TopEnd), + ) { + ModuleCountLabelItem(it) } } } } + } - Row( - modifier = Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp), - verticalAlignment = Alignment.Top, + Row( + modifier = Modifier.padding( + top = 16.dp, + start = 16.dp, + end = 16.dp, + ), + verticalAlignment = Alignment.Top, + ) { + Column( + modifier = Modifier.weight(1f), + verticalArrangement = Arrangement.spacedBy(2.dp), ) { - Column( - modifier = - Modifier - .weight(1f), - verticalArrangement = Arrangement.spacedBy(2.dp), - ) { + Text( + text = repo.name, + style = MMRLXTheme.typography.titleSmall.copy( + fontWeight = FontWeight.Bold, + ), + color = colors.foreground, + maxLines = 2, + overflow = TextOverflow.Ellipsis, + ) + + repo.timestamp.nullable(menu.showUpdatedTime) { Text( - text = repo.name, - style = - MaterialTheme.typography.titleSmall - .copy(fontWeight = FontWeight.Bold), - maxLines = 2, - overflow = TextOverflow.Ellipsis, + text = stringResource( + id = R.string.module_update_at, + it.toFormattedDateSafely, + ), + style = MMRLXTheme.typography.bodySmall, + color = colors.mutedForeground, ) - - repo.timestamp.nullable(menu.showUpdatedTime) { - Text( - text = - stringResource( - id = R.string.module_update_at, - it.toFormattedDateSafely, - ), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.outline, - ) - } - } - - if (repoCover == null && repo.modulesCount !== null && menu.showModulesCount) { - ModuleCountLabelItem(repo.modulesCount) } } - repo.description.nullable { - Text( - modifier = - Modifier - .padding(top = 16.dp) - .padding(horizontal = 16.dp), - text = it, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.outline, - ) + if ( + repoCover == null && + repo.modulesCount != null && + menu.showModulesCount + ) { + ModuleCountLabelItem(repo.modulesCount) } + } - Spacer(modifier = Modifier.height(16.dp)) + repo.description.nullable { + Text( + modifier = Modifier + .padding(top = 16.dp) + .padding(horizontal = 16.dp), + text = it, + style = MMRLXTheme.typography.bodySmall, + color = colors.mutedForeground, + maxLines = 3, + overflow = TextOverflow.Ellipsis, + ) } + + Spacer(modifier = Modifier.height(16.dp)) } } @Composable private fun ModuleCountLabelItem(count: Int) { - LabelItem( - text = stringResource(id = R.string.repo_modules, count), - upperCase = false, + Badge( + text = stringResource( + id = R.string.repo_modules, + count, + ), ) } From a8d5d06e9b25ed5bd55032bfbe26b1d0244eedb3 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:57:02 +0100 Subject: [PATCH 54/55] Use muted colors for repository metadata Apply the muted foreground color to repository timestamps and descriptions, and to module descriptions. --- .../dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt | 4 ++-- .../mmrl/ui/screens/repository/ModuleItemDetailed.kt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt index 875f68eb0..bf6c4132e 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repositories/RepositoryItem.kt @@ -161,7 +161,7 @@ fun RepositoryItem( repo.timestamp.toFormattedDateSafely, ), style = MMRLXTheme.typography.bodySmall, - color = MMRLXTheme.colors.secondaryForeground, + color = MMRLXTheme.colors.mutedForeground, textDecoration = textDecoration, ) } @@ -181,7 +181,7 @@ fun RepositoryItem( .padding(horizontal = 16.dp), text = it, style = MMRLXTheme.typography.bodySmall, - color = MMRLXTheme.colors.secondaryForeground, + color = MMRLXTheme.colors.mutedForeground, ) } diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt index defee1444..ebfbb0bf4 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModuleItemDetailed.kt @@ -221,6 +221,7 @@ fun ModuleItemDetailed( modifier = Modifier.padding(top = 8.dp, bottom = 4.dp), text = module.description ?: stringResource(R.string.view_module_no_description), + color = MMRLXTheme.colors.mutedForeground, style = MMRLXTheme.typography.bodySmall.apply { if (module.description.isNullOrBlank()) { copy( From c40049cebfeebc10926721e4824ec67a08c1bbc7 Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 12 Nov 2026 19:32:05 +0100 Subject: [PATCH 55/55] [skip ci] Redesign installed module cards with MMRLX Migrate module cards and controls to MMRLX components, group action buttons, and adjust list spacing. Remove direct WebUI launching, configured name and description rendering, and blacklist border styling. --- .../mmrl/ui/screens/modules/ModuleItem.kt | 454 ++++-------------- .../mmrl/ui/screens/modules/ModulesList.kt | 103 ++-- .../mmrl/ui/screens/repository/ModulesList.kt | 2 +- 3 files changed, 148 insertions(+), 411 deletions(-) diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt index fbc372d0e..37e0980ca 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModuleItem.kt @@ -1,37 +1,18 @@ package com.dergoogler.mmrl.ui.screens.modules -import android.content.ComponentName -import android.content.Intent -import android.util.Log -import android.widget.Toast -import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.DrawableRes -import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.requiredSize -import androidx.compose.foundation.layout.size -import androidx.compose.material3.Button -import androidx.compose.material3.HorizontalDivider -import androidx.compose.material3.Icon -import androidx.compose.material3.LinearProgressIndicator -import androidx.compose.material3.LocalContentColor -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha @@ -39,46 +20,31 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.StrokeCap -import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp -import com.dergoogler.mmrl.BuildConfig import com.dergoogler.mmrl.R import com.dergoogler.mmrl.ext.fadingEdge -import com.dergoogler.mmrl.ext.isPackageInstalled import com.dergoogler.mmrl.ext.nullable -import com.dergoogler.mmrl.ext.rememberTrue -import com.dergoogler.mmrl.model.local.State import com.dergoogler.mmrl.model.local.versionDisplay import com.dergoogler.mmrl.platform.content.LocalModule.Companion.config -import com.dergoogler.mmrl.platform.content.LocalModule.Companion.hasModConf -import com.dergoogler.mmrl.platform.content.LocalModule.Companion.hasWebUI import com.dergoogler.mmrl.platform.file.SuFile import com.dergoogler.mmrl.platform.file.SuFile.Companion.toFormattedFileSize import com.dergoogler.mmrl.platform.model.ModId.Companion.moduleDir -import com.dergoogler.mmrl.ui.component.BottomSheet -import com.dergoogler.mmrl.ui.component.LabelItem -import com.dergoogler.mmrl.ui.component.LabelItemDefaults import com.dergoogler.mmrl.ui.component.LocalCover -import com.dergoogler.mmrl.ui.component.card.Card -import com.dergoogler.mmrl.ui.component.card.CardScope -import com.dergoogler.mmrl.ui.component.card.component.Absolute -import com.dergoogler.mmrl.ui.component.lite.column.LiteColumn -import com.dergoogler.mmrl.ui.component.lite.row.LiteRow -import com.dergoogler.mmrl.ui.component.lite.row.LiteRowScope -import com.dergoogler.mmrl.ui.component.lite.row.VerticalAlignment -import com.dergoogler.mmrl.ui.component.text.BBCodeTag -import com.dergoogler.mmrl.ui.component.text.BBCodeText import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.utils.toFormattedDateSafely -import dev.dergoogler.mmrl.compat.core.LocalUriHandler -import kotlinx.coroutines.launch +import dev.mmrlx.compose.layout.flashlightCard +import dev.mmrlx.compose.ui.Badge +import dev.mmrlx.compose.ui.BadgeVariant +import dev.mmrlx.compose.ui.HorizontalDivider +import dev.mmrlx.compose.ui.LinearProgressIndicator +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.scaffold.PositionLayout +import dev.mmrlx.compose.ui.theme.MMRLXTheme @Composable fun ModuleItem( @@ -86,204 +52,89 @@ fun ModuleItem( indeterminate: Boolean = false, alpha: Float = 1f, decoration: TextDecoration = TextDecoration.None, - switch: - @Composable() - (() -> Unit?)? = null, - indicator: - @Composable() - (CardScope.() -> Unit?)? = null, - startTrailingButton: - @Composable() - (LiteRowScope.() -> Unit)? = null, - trailingButton: - @Composable() - (LiteRowScope.() -> Unit), - isBlacklisted: Boolean = false, - isProviderAlive: Boolean, + switch: @Composable (() -> Unit?)? = null, + indicator: @Composable (() -> Unit?)? = null, + startTrailingButton: @Composable (RowScope.() -> Unit)? = null, + trailingButton: @Composable (RowScope.() -> Unit), ) { + val colors = MMRLXTheme.colors + val userPreferences = LocalUserPreferences.current val menu = userPreferences.modulesMenu - val context = LocalContext.current - val density = LocalDensity.current - val module = LocalModule.current - var requiredAppBottomSheet by remember { mutableStateOf(false) } - - val canWenUIAccessed = - remember(isProviderAlive, module) { - isProviderAlive && (module.hasWebUI || module.hasModConf) && module.state != State.REMOVE - } - - val isWebUIXNotInstalled = - remember(context) { - !context.isPackageInstalled(userPreferences.webuixPackageName) - } - - val webui = - rememberLauncherForActivityResult( - contract = ActivityResultContracts.RequestMultiplePermissions(), - ) { result -> - if (!result.allGranted { perm -> - Toast - .makeText(context, "Permission denied! Requires $perm", Toast.LENGTH_SHORT) - .show() - } - ) { - return@rememberLauncherForActivityResult - } - - try { - val intent = Intent().apply { - component = ComponentName( - userPreferences.webuixPackageName, - "com.dergoogler.mmrl.wx.ui.webui.WebUIActivity" - ) - - putExtra("MODULE_ID", module.id.toString()) - } - - context.startActivity(intent) - } catch (e: Exception) { - e.printStackTrace() - Log.e("webUILauncher", "Failed to launch WebUI", e) - } - } - - - val clicker: (() -> Unit)? = - remember(canWenUIAccessed) { - canWenUIAccessed nullable jump@{ - if (isWebUIXNotInstalled) { - requiredAppBottomSheet = true - return@jump - } - - webui.launch( - arrayOf( - "com.dergoogler.mmrl.permission.WEBUI_X", - ), - ) - } - } - - if (requiredAppBottomSheet) { - BottomSheetForWXP { - requiredAppBottomSheet = false - } - } - - Card( - border = - isBlacklisted nullable - BorderStroke( - width = 1.dp, - color = MaterialTheme.colorScheme.errorContainer, - ), - onClick = clicker, + PositionLayout( + modifier = Modifier + .fillMaxWidth() + .flashlightCard(), ) { indicator.nullable { - Absolute( - alignment = Alignment.Center, + Box( + modifier = Modifier.absolute(Alignment.Center), ) { it() } } - LiteColumn( + Column( modifier = Modifier.relative(), ) { - module.config.cover.nullable(menu.showCover) { + module.config.cover.nullable(menu.showCover) { it -> val file = SuFile(module.id.moduleDir, it) file.exists { LocalCover( - modifier = - Modifier.fadingEdge( - brush = - Brush.verticalGradient( - colors = - listOf( - Color.Transparent, - Color.Black, - ), - startY = Float.POSITIVE_INFINITY, - endY = 0f, - ), + modifier = Modifier.fadingEdge( + brush = Brush.verticalGradient( + colors = listOf( + Color.Transparent, + Color.Black, + ), + startY = Float.POSITIVE_INFINITY, + endY = 0f, ), + ), inputStream = it.newInputStream(), ) } } - LiteRow( - modifier = Modifier.padding(all = 16.dp), - verticalAlignment = VerticalAlignment.Center, + Row( + modifier = Modifier.padding(16.dp), + verticalAlignment = Alignment.CenterVertically, ) { - LiteColumn( - modifier = - Modifier - .alpha(alpha = alpha) - .weight(1f), - spaceBetweenItem = 2.dp, + Column( + modifier = Modifier + .alpha(alpha) + .weight(1f), + verticalArrangement = Arrangement.spacedBy(2.dp), ) { - val name = - remember { - module.config.name ?: module.name - } - - val prefix = fun(): String? { - if (!canWenUIAccessed) return null - if (module.hasWebUI) return "[icon=webui] " - if (module.hasModConf) return "[image=modconf] " - return null - } - - BBCodeText( - text = name, - bbEnabled = false, - disabledTags = BBCodeTag.disableAllExcept(BBCodeTag.ICON, BBCodeTag.IMAGE), - iconContent = - (canWenUIAccessed && module.hasWebUI) nullable { - Icon( - painter = painterResource(id = R.drawable.sandbox), - contentDescription = null, - tint = LocalContentColor.current, - ) - }, - imageContent = - (canWenUIAccessed && module.hasModConf) nullable { - Image( - painter = painterResource(id = com.dergoogler.mmrl.ui.R.drawable.jetpackcomposeicon), - contentDescription = null, - ) - }, - prefix = prefix(), - style = MaterialTheme.typography.titleSmall, + Text( + text = module.name, + style = MMRLXTheme.typography.titleSmall, + color = colors.foreground, ) Text( - text = - stringResource( - id = R.string.module_version_author, - module.versionDisplay, - module.author, - ), - style = MaterialTheme.typography.bodySmall, + text = stringResource( + id = R.string.module_version_author, + module.versionDisplay, + module.author, + ), + style = MMRLXTheme.typography.bodySmall, textDecoration = decoration, - color = MaterialTheme.colorScheme.onSurfaceVariant, + color = colors.mutedForeground, ) if (module.lastUpdated != 0L && menu.showUpdatedTime) { Text( - text = - stringResource( - id = R.string.module_update_at, - module.lastUpdated.toFormattedDateSafely, - ), - style = MaterialTheme.typography.bodySmall, + text = stringResource( + id = R.string.module_update_at, + module.lastUpdated.toFormattedDateSafely, + ), + style = MMRLXTheme.typography.bodySmall, textDecoration = decoration, - color = MaterialTheme.colorScheme.outline, + color = colors.mutedForeground, ) } } @@ -291,177 +142,80 @@ fun ModuleItem( switch?.invoke() } - val bbEnabled = - remember(module) { - module.config.description != null - } - - val desc = remember(module) { module.config.description ?: module.description } - - BBCodeText( - modifier = - Modifier - .alpha(alpha = alpha) - .padding(horizontal = 16.dp), - text = desc, - bbEnabled = bbEnabled, - style = MaterialTheme.typography.bodySmall, + Text( + modifier = Modifier + .alpha(alpha) + .padding(horizontal = 16.dp), + text = module.description, + style = MMRLXTheme.typography.bodySmall, maxLines = 5, overflow = TextOverflow.Ellipsis, textDecoration = decoration, - color = MaterialTheme.colorScheme.outline, + color = colors.mutedForeground, ) - LiteRow( - modifier = - Modifier - .padding(horizontal = 16.dp, vertical = 8.dp) - .fillMaxWidth(), - verticalAlignment = VerticalAlignment.Center, - spaceBetweenItem = 8.dp, + Row( + modifier = Modifier + .padding(horizontal = 16.dp, vertical = 8.dp) + .fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - userPreferences.developerMode.rememberTrue { - LabelItem( + if (userPreferences.developerMode) { + Badge( text = module.id.id, - upperCase = false, ) } - LabelItem( + Badge( text = module.size.toFormattedFileSize(), - style = - LabelItemDefaults.style.copy( - containerColor = MaterialTheme.colorScheme.secondaryContainer, - contentColor = MaterialTheme.colorScheme.onSecondaryContainer, - ), + variant = BadgeVariant.Secondary ) } when { - indeterminate -> + indeterminate -> { LinearProgressIndicator( strokeCap = StrokeCap.Round, - modifier = - Modifier - .padding(top = 8.dp) - .height(2.dp) - .fillMaxWidth(), + modifier = Modifier + .padding(top = 8.dp) + .height(2.dp) + .fillMaxWidth(), ) + } - progress != 0f -> + progress != 0f -> { LinearProgressIndicator( progress = { progress }, strokeCap = StrokeCap.Round, - modifier = - Modifier - .padding(top = 8.dp) - .height(1.5.dp) - .fillMaxWidth(), + modifier = Modifier + .padding(top = 8.dp) + .height(1.5.dp) + .fillMaxWidth(), ) + } - else -> + else -> { HorizontalDivider( thickness = 1.5.dp, - color = MaterialTheme.colorScheme.surface, + color = colors.border, modifier = Modifier.padding(top = 8.dp), ) + } } - LiteRow( - modifier = - Modifier - .padding(horizontal = 16.dp, vertical = 8.dp) - .fillMaxWidth(), - verticalAlignment = VerticalAlignment.Center, + Row( + modifier = Modifier + .padding(horizontal = 16.dp, vertical = 8.dp) + .fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, ) { startTrailingButton?.invoke(this) - Spacer(modifier = Modifier.weight(1f)) - trailingButton.invoke(this) - } - } - } -} - -@Composable -fun BottomSheetForWXP(onCancel: () -> Unit) { - val browser = LocalUriHandler.current - val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) - val scope = rememberCoroutineScope() - - BottomSheet( - onDismissRequest = onCancel, - ) { - Column( - modifier = - Modifier - .fillMaxWidth() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Top, - ) { - Icon( - painter = painterResource(id = R.drawable.sandbox), - contentDescription = null, - modifier = Modifier.size(98.dp), - tint = MaterialTheme.colorScheme.primary, - ) - - Spacer(modifier = Modifier.height(16.dp)) - Text( - text = stringResource(R.string.external_app_required_title), - style = MaterialTheme.typography.headlineSmall, - color = MaterialTheme.colorScheme.onSurface, - ) - - Spacer(modifier = Modifier.height(12.dp)) - - Text( - text = stringResource(R.string.external_app_required_desc), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = - Modifier - .padding(horizontal = 16.dp) - .fillMaxWidth(), - textAlign = TextAlign.Center, - ) - - Spacer(modifier = Modifier.height(24.dp)) - - Button( - onClick = { - scope.launch { sheetState.hide() }.invokeOnCompletion { - if (!sheetState.isVisible) { - browser.openUri( - if (BuildConfig.IS_GOOGLE_PLAY_BUILD) { - "https://play.google.com/store/apps/details?id=com.dergoogler.mmrl.wx" - } else { - "https://github.com/MMRLApp/WebUI-X-Portable" - }, - ) - } - } - }, - modifier = Modifier.fillMaxWidth(), - ) { - Text(stringResource(R.string.module_download)) - } - - Spacer(modifier = Modifier.height(8.dp)) + Spacer(modifier = Modifier.weight(1f)) - TextButton( - onClick = { - scope.launch { sheetState.hide() }.invokeOnCompletion { - onCancel() - } - }, - modifier = Modifier.fillMaxWidth(), - ) { - Text(stringResource(com.dergoogler.mmrl.ui.R.string.cancel)) + trailingButton.invoke(this) } - - Spacer(modifier = Modifier.height(16.dp)) } } } @@ -469,7 +223,7 @@ fun BottomSheetForWXP(onCancel: () -> Unit) { @Composable fun StateIndicator( @DrawableRes icon: Int, - color: Color = MaterialTheme.colorScheme.outline, + color: Color = MMRLXTheme.colors.mutedForeground, ) = Image( modifier = Modifier.requiredSize(150.dp), painter = painterResource(id = icon), @@ -477,13 +231,3 @@ fun StateIndicator( alpha = 0.1f, colorFilter = ColorFilter.tint(color), ) - -private fun Map.allGranted(onDenied: (String) -> Unit): Boolean { - for ((perm, granted) in this) { - if (!granted) { - onDenied(perm) - return false - } - } - return true -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt index cfea5905e..988dccccb 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/modules/ModulesList.kt @@ -2,27 +2,21 @@ package com.dergoogler.mmrl.ui.screens.modules import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.calculateStartPadding import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items -import androidx.compose.material3.FilledTonalButton -import androidx.compose.material3.Icon -import androidx.compose.material3.Switch -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Shape import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.painterResource @@ -30,7 +24,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import com.dergoogler.mmrl.R -import com.dergoogler.mmrl.ext.rememberTrue +import com.dergoogler.mmrl.ext.plus import com.dergoogler.mmrl.model.local.LocalModule import com.dergoogler.mmrl.model.local.State import com.dergoogler.mmrl.model.online.Blacklist @@ -41,7 +35,13 @@ import com.dergoogler.mmrl.ui.component.VersionItemBottomSheet import com.dergoogler.mmrl.ui.providable.LocalModule import com.dergoogler.mmrl.ui.providable.LocalUserPreferences import com.dergoogler.mmrl.viewmodel.ModulesViewModel +import dev.mmrlx.compose.ui.Switch +import dev.mmrlx.compose.ui.Text +import dev.mmrlx.compose.ui.button.Button +import dev.mmrlx.compose.ui.button.ButtonVariant +import dev.mmrlx.compose.ui.button.HorizontalButtonGroup import dev.mmrlx.compose.ui.ext.with +import dev.mmrlx.compose.ui.icon.Icon import dev.mmrlx.compose.ui.scaffold.ScaffoldScope @Composable @@ -63,14 +63,8 @@ fun ScaffoldScope.ModulesList( .with(this@ModulesList) { it.scaffoldHazeSource() }, - contentPadding = - PaddingValues( - top = this@ModulesList.scaffoldTopPadding + 16.dp, - start = this@ModulesList.contentPadding.calculateStartPadding(layoutDirection) + 16.dp, - bottom = this@ModulesList.contentPadding.calculateBottomPadding() + 16.dp, - end = 16.dp, - ), - verticalArrangement = Arrangement.spacedBy(16.dp), + contentPadding = this@ModulesList.contentPadding + 8.dp, + verticalArrangement = Arrangement.spacedBy(8.dp), ) { items( items = list, @@ -137,6 +131,18 @@ private fun ModuleItem( var open by remember { mutableStateOf(false) } + val isRemoveOrRestoreEnabled = remember( + userPreferences.useShellForModuleStateChange, + module.state, + isProviderAlive, + ) { + isProviderAlive && + ( + !(viewModel.moduleCompatibility.canRestoreModules && userPreferences.useShellForModuleStateChange) || + module.state != State.REMOVE + ) + } + VersionItemBottomSheetIfNeeded( open = open, item = item, @@ -147,8 +153,6 @@ private fun ModuleItem( ) ModuleItem( - isProviderAlive = isProviderAlive, - isBlacklisted = isBlacklisted, progress = progress, indeterminate = ops.isOpsRunning, alpha = @@ -176,7 +180,7 @@ private fun ModuleItem( } }, startTrailingButton = { - module.hasAction.rememberTrue { + if (module.hasAction) { ActionButton( enabled = isActionEnabled, onClick = @@ -192,36 +196,26 @@ private fun ModuleItem( } }, trailingButton = { - item?.let { itm -> - val hasUpdate = remember(itm, module.versionCode) { - itm.versionCode > module.versionCode + HorizontalButtonGroup { + item?.let { itm -> + val hasUpdate = remember(itm, module.versionCode) { + itm.versionCode > module.versionCode + } + + UpdateButton( + enabled = hasUpdate, + shape = shape(0, 2), + onClick = remember { { open = true } }, + ) } - UpdateButton( - enabled = hasUpdate, - onClick = remember { { open = true } }, + RemoveOrRestore( + module = module, + shape = if (item != null) shape(1, 2) else shape(0, 1), + enabled = isRemoveOrRestoreEnabled, + onClick = ops.change, ) - - Spacer(modifier = Modifier.width(12.dp)) } - - val isRemoveOrRestoreEnabled = remember( - userPreferences.useShellForModuleStateChange, - module.state, - isProviderAlive, - ) { - isProviderAlive && - ( - !(viewModel.moduleCompatibility.canRestoreModules && userPreferences.useShellForModuleStateChange) || - module.state != State.REMOVE - ) - } - - RemoveOrRestore( - module = module, - enabled = isRemoveOrRestoreEnabled, - onClick = ops.change, - ) }, ) } @@ -250,16 +244,17 @@ private fun VersionItemBottomSheetIfNeeded( @Composable private fun UpdateButton( enabled: Boolean, + shape: Shape, onClick: () -> Unit, ) { - val contentPadding = remember { PaddingValues(horizontal = 12.dp) } val iconSize = remember { Modifier.size(20.dp) } val spacerWidth = remember { Modifier.width(6.dp) } - FilledTonalButton( + Button( onClick = onClick, + shape = shape, enabled = enabled, - contentPadding = contentPadding, + variant = ButtonVariant.Outline, ) { Icon( modifier = iconSize, @@ -274,21 +269,21 @@ private fun UpdateButton( } } -@OptIn(ExperimentalComposeUiApi::class) @Composable private fun RemoveOrRestore( module: LocalModule, enabled: Boolean, + shape: Shape, onClick: () -> Unit, ) { - val contentPadding = remember { PaddingValues(horizontal = 12.dp) } val iconSize = remember { Modifier.size(20.dp) } val spacerWidth = remember { Modifier.width(6.dp) } - FilledTonalButton( + Button( onClick = onClick, enabled = enabled, - contentPadding = contentPadding, + shape = shape, + variant = ButtonVariant.Outline, ) { Icon( modifier = iconSize, @@ -324,13 +319,11 @@ private fun ActionButton( enabled: Boolean, onClick: () -> Unit, ) { - val contentPadding = remember { PaddingValues(horizontal = 12.dp) } val iconSize = remember { Modifier.size(20.dp) } - FilledTonalButton( + Button( onClick = onClick, enabled = enabled, - contentPadding = contentPadding, ) { Icon( modifier = iconSize, diff --git a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt index bb8f6d5bf..494fc03a5 100644 --- a/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt +++ b/app/src/main/kotlin/com/dergoogler/mmrl/ui/screens/repository/ModulesList.kt @@ -66,7 +66,7 @@ fun ScaffoldScope.ModulesList( contentPadding = PaddingValues( top = if (!isSearch) 0.dp else scope.scaffoldTopPadding, - bottom = scope.scaffoldBottomPadding + 16.dp, + bottom = scope.scaffoldBottomPadding + 8.dp, ), verticalArrangement = Arrangement.spacedBy(8.dp), ) {