Skip to content

Commit

Permalink
feat: 添加ZipAlign开关配置
Browse files Browse the repository at this point in the history
  • Loading branch information
jixiaoyong committed Jan 17, 2024
1 parent b9ce45c commit af23c10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/main/kotlin/io/github/jixiaoyong/pages/signapp/SignApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ fun PageSignApp(
val apkSignType by settings.signTypeList.collectAsState(setOf())
val selectedSignInfo by settings.selectedSignInfoBean.collectAsState(null)
val signedDirectory by settings.signedDirectory.collectAsState(null)
val isZipAlign by settings.isZipAlign.collectAsState(false)

var signInfoResult: CommandResult by remember { mutableStateOf(CommandResult.NOT_EXECUT) }

Expand Down Expand Up @@ -240,6 +241,22 @@ fun PageSignApp(

}
}

Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
Text(
"是否开启对齐:",
style = TextStyle(fontWeight = FontWeight.Bold, fontSize = 16.sp),
modifier = Modifier.weight(1f).padding(horizontal = 15.dp)
)

Checkbox(checked = isZipAlign, onCheckedChange = {
settings.save(StorageKeys.ALIGN_ENABLE, it)
})
}
}

Divider()
Expand Down Expand Up @@ -287,7 +304,7 @@ fun PageSignApp(
localSelectedSignInfo.keyStorePassword,
localSelectedSignInfo.keyPassword,
signedApkDirectory = signedDirectory,
zipAlign = false,
zipAlign = isZipAlign,
signVersions = SignType.ALL_SIGN_TYPES.filter {
apkSignType.contains(
it.type
Expand Down
13 changes: 9 additions & 4 deletions src/main/kotlin/io/github/jixiaoyong/utils/SettingsTool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.gson.reflect.TypeToken
import com.russhwolf.settings.ExperimentalSettingsApi
import com.russhwolf.settings.ObservableSettings
import com.russhwolf.settings.Settings
import com.russhwolf.settings.coroutines.getBooleanFlow
import com.russhwolf.settings.coroutines.getStringOrNullFlow
import com.russhwolf.settings.set
import io.github.jixiaoyong.pages.signInfos.SignInfoBean
Expand All @@ -28,12 +29,13 @@ interface KeyValueStorage {

val apkSigner: Flow<String?>
val zipAlign: Flow<String?>
val isZipAlign: Flow<Boolean>
val signedDirectory: Flow<String?>
val signTypeList: Flow<Set<Int>>
val selectedSignInfoBean: Flow<SignInfoBean?>
val signInfoBeans: Flow<List<SignInfoBean>>
fun cleanStorage()
fun save(key: StorageKeys, value: String?)
fun save(key: StorageKeys, value: Any?)
}


Expand All @@ -43,7 +45,8 @@ enum class StorageKeys {
SIGN_INFO_SELECT, // 选中的签名信息
SIGN_INFO_LIST, // 签名信息(密钥/密码等)列表
SIGNED_DIRECTORY, // 签名后文件保存路径
SIGN_TYPE_LIST; // 签名类型列表
SIGN_TYPE_LIST, // 签名类型列表
ALIGN_ENABLE; // 是否开启zipalign压缩

val key get() = this.name
}
Expand All @@ -57,6 +60,8 @@ class SettingsTool(private val scope: CoroutineScope) : KeyValueStorage {
get() = observableSettings.getStringOrNullFlow(StorageKeys.APK_SIGNER_PATH.key)
override val zipAlign: Flow<String?>
get() = observableSettings.getStringOrNullFlow(StorageKeys.ZIP_ALIGN_PATH.key)
override val isZipAlign: Flow<Boolean>
get() = observableSettings.getBooleanFlow(StorageKeys.ALIGN_ENABLE.key, false)
override val signedDirectory: Flow<String?>
get() = observableSettings.getStringOrNullFlow(StorageKeys.SIGNED_DIRECTORY.key)
override var signTypeList: Flow<Set<Int>>
Expand Down Expand Up @@ -85,9 +90,9 @@ class SettingsTool(private val scope: CoroutineScope) : KeyValueStorage {
}
}

override fun save(key: StorageKeys, value: String?) {
override fun save(key: StorageKeys, value: Any?) {
if (value != null) {
settings[key.key] = value
settings[key.key] = value.toString()
} else {
settings.remove(key.key)
}
Expand Down

0 comments on commit af23c10

Please sign in to comment.