Remove unused functions and data classes and optimize code structure; update string resources to support new features

This commit is contained in:
ShirkNeko
2025-04-20 22:01:35 +08:00
parent 33dd0ca16b
commit 1dd8651a1a
11 changed files with 27 additions and 116 deletions

View File

@@ -5,30 +5,13 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.animation.AnimatedContentTransitionScope
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.*
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.WindowInsetsSides
import androidx.compose.foundation.layout.displayCutout
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.union
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavBackStackEntry
@@ -43,15 +26,8 @@ import io.zako.zako.UltraToolInstall
import zako.zako.zako.Natives
import zako.zako.zako.ksuApp
import zako.zako.zako.ui.screen.BottomBarDestination
import zako.zako.zako.ui.theme.CardConfig
import zako.zako.zako.ui.theme.KernelSUTheme
import zako.zako.zako.ui.theme.loadCustomBackground
import zako.zako.zako.ui.theme.loadThemeMode
import zako.zako.zako.ui.util.LocalSnackbarHost
import zako.zako.zako.ui.util.getKpmVersion
import zako.zako.zako.ui.util.rootAvailable
import zako.zako.zako.ui.util.install
import zako.zako.zako.ui.theme.*
import zako.zako.zako.ui.util.*
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {

View File

@@ -45,10 +45,6 @@ enum class FlashingStatus {
private var currentFlashingStatus = mutableStateOf(FlashingStatus.FLASHING)
fun getFlashingStatus(): FlashingStatus {
return currentFlashingStatus.value
}
fun setFlashingStatus(status: FlashingStatus) {
currentFlashingStatus.value = status
}

View File

@@ -92,11 +92,9 @@ fun HomeScreen(navigator: DestinationsNavigator) {
val isManager = Natives.becomeManager(ksuApp.packageName)
val deviceModel = getDeviceModel(context)
val ksuVersion = if (isManager) Natives.version else null
val managerVersion = getManagerVersion(context).second
val Zako = "一.*加.*A.*c.*e.*5.*P.*r.*o".toRegex().matches(deviceModel)
val zako = "一.*加.*A.*c.*e.*5.*P.*r.*o".toRegex().matches(deviceModel)
val isVersion = ksuVersion == 12777
val isManagerVersionValid = managerVersion > (ksuVersion ?: 0) + 33
val shouldTriggerRestart = Zako && kernelVersion.isGKI() && (isVersion || isManagerVersionValid)
val shouldTriggerRestart = zako && kernelVersion.isGKI() && (isVersion)
LaunchedEffect(shouldTriggerRestart) {
if (shouldTriggerRestart) {
@@ -709,7 +707,7 @@ private fun getDeviceModel(context: Context): String {
}
}
Build.DEVICE
} catch (e: Exception) {
} catch (_: Exception) {
Build.DEVICE
}
}

View File

@@ -381,6 +381,7 @@ sealed class InstallMethod {
private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) {
val rootAvailable = rootAvailable()
val isAbDevice = isAbDevice()
val horizonKernelSummary = stringResource(R.string.horizon_kernel_summary)
val selectFileTip = stringResource(
id = R.string.select_file_tip,
if (isInitBoot()) "init_boot" else "boot"
@@ -395,12 +396,13 @@ private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) {
if (isAbDevice) {
radioOptions.add(InstallMethod.DirectInstallToInactiveSlot)
}
radioOptions.add(InstallMethod.HorizonKernel(summary = "Flashing the Anykernel3 Kernel"))
radioOptions.add(InstallMethod.HorizonKernel(summary = horizonKernelSummary))
}
var selectedOption by remember { mutableStateOf<InstallMethod?>(null) }
var currentSelectingMethod by remember { mutableStateOf<InstallMethod?>(null) }
val selectImageLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) {
@@ -408,7 +410,7 @@ private fun SelectInstallMethod(onSelected: (InstallMethod) -> Unit = {}) {
it.data?.data?.let { uri ->
val option = when (currentSelectingMethod) {
is InstallMethod.SelectFile -> InstallMethod.SelectFile(uri, summary = selectFileTip)
is InstallMethod.HorizonKernel -> InstallMethod.HorizonKernel(uri, summary = " Flashing the Anykernel3 Kernel")
is InstallMethod.HorizonKernel -> InstallMethod.HorizonKernel(uri, summary = horizonKernelSummary)
else -> null
}
option?.let {

View File

@@ -26,8 +26,6 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import com.ramcosta.composedestinations.annotation.Destination
@@ -38,18 +36,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import zako.zako.zako.ui.component.SwitchItem
import zako.zako.zako.ui.theme.CardConfig
import zako.zako.zako.ui.theme.ThemeColors
import zako.zako.zako.ui.theme.ThemeConfig
import zako.zako.zako.ui.theme.saveCustomBackground
import zako.zako.zako.ui.theme.saveThemeColors
import zako.zako.zako.ui.theme.saveThemeMode
import zako.zako.zako.ui.theme.saveDynamicColorState
import zako.zako.zako.ui.util.getSuSFS
import zako.zako.zako.ui.util.getSuSFSFeatures
import zako.zako.zako.ui.util.susfsSUS_SU_0
import zako.zako.zako.ui.util.susfsSUS_SU_2
import zako.zako.zako.ui.util.susfsSUS_SU_Mode
import zako.zako.zako.ui.theme.*
import zako.zako.zako.ui.util.*
import androidx.core.content.edit
import zako.zako.zako.R

View File

@@ -7,32 +7,14 @@ import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.Undo
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -67,17 +49,8 @@ import kotlinx.coroutines.withContext
import zako.zako.zako.BuildConfig
import zako.zako.zako.Natives
import zako.zako.zako.R
import zako.zako.zako.ui.component.AboutDialog
import zako.zako.zako.ui.component.ConfirmResult
import zako.zako.zako.ui.component.DialogHandle
import zako.zako.zako.ui.component.SwitchItem
import zako.zako.zako.ui.component.rememberConfirmDialog
import zako.zako.zako.ui.component.rememberCustomDialog
import zako.zako.zako.ui.component.rememberLoadingDialog
import zako.zako.zako.ui.theme.CardConfig
import zako.zako.zako.ui.theme.ThemeConfig
import zako.zako.zako.ui.theme.getCardColors
import zako.zako.zako.ui.theme.getCardElevation
import zako.zako.zako.ui.component.*
import zako.zako.zako.ui.theme.*
import zako.zako.zako.ui.util.LocalSnackbarHost
import zako.zako.zako.ui.util.getBugreportFile
import java.time.LocalDateTime

View File

@@ -25,22 +25,14 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import zako.zako.zako.ui.component.ConfirmResult
import zako.zako.zako.ui.component.SearchAppBar
import zako.zako.zako.ui.component.rememberConfirmDialog
import zako.zako.zako.ui.theme.getCardColors
import zako.zako.zako.ui.theme.getCardElevation
import zako.zako.zako.ui.component.*
import zako.zako.zako.ui.theme.*
import zako.zako.zako.ui.viewmodel.KpmViewModel
import zako.zako.zako.ui.util.loadKpmModule
import zako.zako.zako.ui.util.unloadKpmModule
import zako.zako.zako.ui.util.*
import java.io.File
import androidx.core.content.edit
import zako.zako.zako.ui.theme.ThemeConfig
import zako.zako.zako.ui.component.rememberCustomDialog
import zako.zako.zako.ui.component.ConfirmDialogHandle
import zako.zako.zako.R
import java.net.URLDecoder
import java.net.URLEncoder
import java.net.*
/**
* KPM 管理界面

View File

@@ -143,17 +143,6 @@ class KpmViewModel : ViewModel() {
return result
}
fun controlModule(moduleId: String, args: String? = null): Int {
return try {
val result = controlKpmModule(moduleId, args)
Log.d("KsuCli", "Control module $moduleId result: $result")
result
} catch (e: Exception) {
Log.e("KsuCli", "Failed to control module $moduleId", e)
-1
}
}
data class ModuleInfo(
val id: String,
val name: String,

View File

@@ -40,13 +40,6 @@ class ModuleViewModel : ViewModel() {
val dirId: String, // real module id (dir name)
)
data class ModuleUpdateInfo(
val version: String,
val versionCode: Int,
val zipUrl: String,
val changelog: String,
)
var isRefreshing by mutableStateOf(false)
private set
var search by mutableStateOf("")

View File

@@ -214,6 +214,7 @@
<string name="flash_option">刷入选项</string>
<string name="flash_option_tip">选择要刷入的文件</string>
<string name="horizon_kernel">刷写 AnyKernel3 压缩包</string>
<string name="horizon_kernel_summary">刷入 Anykernel3 内核</string>
<string name="root_required">需要 root 权限</string>
<string name="copy_failed">文件复制失败</string>
<string name="reboot_complete_title">刷写完成</string>
@@ -262,4 +263,5 @@
<string name="invalid_file_type">文件类型不正确,请选择 .kpm 文件</string>
<string name="confirm_uninstall_title_with_filename">卸载</string>
<string name="confirm_uninstall_content">将卸载以下 kpm 模块:\n%s</string>
</resources>

View File

@@ -215,6 +215,7 @@
<string name="flash_option">Brush Options</string>
<string name="flash_option_tip">Select the file to be flashed</string>
<string name="horizon_kernel">Anykernel3 Flash</string>
<string name="horizon_kernel_summary">Flashing the Anykernel3 Kernel</string>
<string name="root_required">Requires root privileges</string>
<string name="copy_failed">File Copy Failure</string>
<string name="reboot_complete_title">Scrubbing complete</string>
@@ -266,4 +267,5 @@
<string name="invalid_file_type">Incorrect file type, select .kpm file</string>
<string name="confirm_uninstall_title_with_filename">uninstallation</string>
<string name="confirm_uninstall_content">The following kpm modules will be uninstalled\n%s</string>
</resources>