Skip to content

Commit

Permalink
use state to control RadioButtonItem and CheckBoxItem
Browse files Browse the repository at this point in the history
  • Loading branch information
BinTianqi committed Jun 3, 2024
1 parent f47a851 commit 45317e3
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -567,22 +567,22 @@ private fun CredentialManagePolicy(pkgName: String) {
Spacer(Modifier.padding(vertical = 5.dp))
RadioButtonItem(
stringResource(R.string.none),
{ policyType==-1 }, { policyType=-1 }
policyType == -1, { policyType = -1 }
)
RadioButtonItem(
stringResource(R.string.blacklist),
{ policyType==PACKAGE_POLICY_BLOCKLIST },
{ policyType=PACKAGE_POLICY_BLOCKLIST }
policyType == PACKAGE_POLICY_BLOCKLIST,
{ policyType = PACKAGE_POLICY_BLOCKLIST }
)
RadioButtonItem(
stringResource(R.string.whitelist),
{ policyType==PACKAGE_POLICY_ALLOWLIST },
{ policyType=PACKAGE_POLICY_ALLOWLIST }
policyType == PACKAGE_POLICY_ALLOWLIST,
{ policyType = PACKAGE_POLICY_ALLOWLIST }
)
RadioButtonItem(
stringResource(R.string.whitelist_and_system_app),
{ policyType==PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM },
{ policyType=PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM }
policyType == PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM,
{ policyType = PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM }
)
Spacer(Modifier.padding(vertical = 5.dp))
AnimatedVisibility(policyType != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private fun CreateWorkProfile() {
Spacer(Modifier.padding(vertical = 5.dp))
var skipEncrypt by remember { mutableStateOf(false) }
if(VERSION.SDK_INT>=24) {
CheckBoxItem(stringResource(R.string.skip_encryption), { skipEncrypt }, { skipEncrypt=!skipEncrypt })
CheckBoxItem(stringResource(R.string.skip_encryption), skipEncrypt, { skipEncrypt = it })
}
Spacer(Modifier.padding(vertical = 5.dp))
Button(
Expand Down
57 changes: 29 additions & 28 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,29 +212,30 @@ private fun Switches() {
private fun WifiSecLevel() {
val context = LocalContext.current
val dpm = context.getSystemService(ComponentActivity.DEVICE_POLICY_SERVICE) as DevicePolicyManager
var selectedWifiSecLevel by remember { mutableIntStateOf(0) }
LaunchedEffect(Unit) { selectedWifiSecLevel = dpm.minimumRequiredWifiSecurityLevel }
Column(modifier = Modifier.fillMaxSize().padding(horizontal = 8.dp).verticalScroll(rememberScrollState())) {
var selectedWifiSecLevel by remember { mutableIntStateOf(dpm.minimumRequiredWifiSecurityLevel) }
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.min_wifi_security_level), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
RadioButtonItem(
stringResource(R.string.wifi_security_level_open),
{ selectedWifiSecLevel == WIFI_SECURITY_OPEN },
selectedWifiSecLevel == WIFI_SECURITY_OPEN,
{ selectedWifiSecLevel = WIFI_SECURITY_OPEN }
)
RadioButtonItem(
"WEP, WPA(2)-PSK",
{ selectedWifiSecLevel == WIFI_SECURITY_PERSONAL },
selectedWifiSecLevel == WIFI_SECURITY_PERSONAL,
{ selectedWifiSecLevel = WIFI_SECURITY_PERSONAL }
)
RadioButtonItem(
"WPA-EAP",
{ selectedWifiSecLevel == WIFI_SECURITY_ENTERPRISE_EAP },
selectedWifiSecLevel == WIFI_SECURITY_ENTERPRISE_EAP,
{ selectedWifiSecLevel = WIFI_SECURITY_ENTERPRISE_EAP }
)
RadioButtonItem(
"WPA3-192bit",
{ selectedWifiSecLevel == WIFI_SECURITY_ENTERPRISE_192 },
selectedWifiSecLevel == WIFI_SECURITY_ENTERPRISE_192,
{ selectedWifiSecLevel = WIFI_SECURITY_ENTERPRISE_192 }
)
Spacer(Modifier.padding(vertical = 5.dp))
Expand Down Expand Up @@ -272,17 +273,17 @@ private fun WifiSsidPolicy() {
Spacer(Modifier.padding(vertical = 5.dp))
RadioButtonItem(
stringResource(R.string.none),
{ selectedPolicyType == -1 },
selectedPolicyType == -1,
{ selectedPolicyType = -1 }
)
RadioButtonItem(
stringResource(R.string.whitelist),
{ selectedPolicyType == WIFI_SSID_POLICY_TYPE_ALLOWLIST },
selectedPolicyType == WIFI_SSID_POLICY_TYPE_ALLOWLIST,
{ selectedPolicyType = WIFI_SSID_POLICY_TYPE_ALLOWLIST }
)
RadioButtonItem(
stringResource(R.string.blacklist),
{ selectedPolicyType == WIFI_SSID_POLICY_TYPE_DENYLIST },
selectedPolicyType == WIFI_SSID_POLICY_TYPE_DENYLIST,
{ selectedPolicyType = WIFI_SSID_POLICY_TYPE_DENYLIST }
)
AnimatedVisibility(selectedPolicyType != -1) {
Expand Down Expand Up @@ -641,10 +642,10 @@ private fun APN() {
}

Text(text = stringResource(R.string.auth_type), style = typography.titleLarge)
RadioButtonItem(stringResource(R.string.none), { selectedAuthType==AUTH_TYPE_NONE }, { selectedAuthType=AUTH_TYPE_NONE })
RadioButtonItem("CHAP", { selectedAuthType==AUTH_TYPE_CHAP }, { selectedAuthType=AUTH_TYPE_CHAP })
RadioButtonItem("PAP", { selectedAuthType==AUTH_TYPE_PAP}, { selectedAuthType=AUTH_TYPE_PAP })
RadioButtonItem("PAP/CHAP", { selectedAuthType==AUTH_TYPE_PAP_OR_CHAP}, { selectedAuthType=AUTH_TYPE_PAP_OR_CHAP })
RadioButtonItem(stringResource(R.string.none), selectedAuthType==AUTH_TYPE_NONE , { selectedAuthType=AUTH_TYPE_NONE })
RadioButtonItem("CHAP", selectedAuthType == AUTH_TYPE_CHAP , { selectedAuthType = AUTH_TYPE_CHAP })
RadioButtonItem("PAP", selectedAuthType == AUTH_TYPE_PAP, { selectedAuthType = AUTH_TYPE_PAP })
RadioButtonItem("PAP/CHAP", selectedAuthType == AUTH_TYPE_PAP_OR_CHAP, { selectedAuthType = AUTH_TYPE_PAP_OR_CHAP })

if(VERSION.SDK_INT>=29) {
val ts = context.getSystemService(ComponentActivity.TELEPHONY_SERVICE) as TelephonyManager
Expand Down Expand Up @@ -751,10 +752,10 @@ private fun APN() {
}

Text(text = "MVNO", style = typography.titleLarge)
RadioButtonItem("SPN", { mvnoType == MVNO_TYPE_SPN }, { mvnoType = MVNO_TYPE_SPN })
RadioButtonItem("IMSI", { mvnoType == MVNO_TYPE_IMSI }, { mvnoType = MVNO_TYPE_IMSI })
RadioButtonItem("GID", { mvnoType == MVNO_TYPE_GID }, { mvnoType = MVNO_TYPE_GID })
RadioButtonItem("ICCID", { mvnoType == MVNO_TYPE_ICCID }, { mvnoType = MVNO_TYPE_ICCID })
RadioButtonItem("SPN", mvnoType == MVNO_TYPE_SPN, { mvnoType = MVNO_TYPE_SPN })
RadioButtonItem("IMSI", mvnoType == MVNO_TYPE_IMSI, { mvnoType = MVNO_TYPE_IMSI })
RadioButtonItem("GID", mvnoType == MVNO_TYPE_GID, { mvnoType = MVNO_TYPE_GID })
RadioButtonItem("ICCID", mvnoType == MVNO_TYPE_ICCID, { mvnoType = MVNO_TYPE_ICCID })

Text(text = stringResource(R.string.network_type), style = typography.titleLarge)
TextField(
Expand Down Expand Up @@ -798,23 +799,23 @@ private fun APN() {
}

Text(text = stringResource(R.string.protocol), style = typography.titleLarge)
RadioButtonItem("IPV4", { protocol == PROTOCOL_IP }, { protocol = PROTOCOL_IP })
RadioButtonItem("IPV6", { protocol == PROTOCOL_IPV6 }, { protocol = PROTOCOL_IPV6 })
RadioButtonItem("IPV4/IPV6", { protocol == PROTOCOL_IPV4V6 }, { protocol = PROTOCOL_IPV4V6 })
RadioButtonItem("PPP", { protocol == PROTOCOL_PPP }, { protocol = PROTOCOL_PPP })
RadioButtonItem("IPV4", protocol == PROTOCOL_IP, { protocol = PROTOCOL_IP })
RadioButtonItem("IPV6", protocol == PROTOCOL_IPV6, { protocol = PROTOCOL_IPV6 })
RadioButtonItem("IPV4/IPV6", protocol == PROTOCOL_IPV4V6, { protocol = PROTOCOL_IPV4V6 })
RadioButtonItem("PPP", protocol == PROTOCOL_PPP, { protocol = PROTOCOL_PPP })
if(VERSION.SDK_INT>=29) {
RadioButtonItem("non-IP", { protocol == PROTOCOL_NON_IP }, { protocol = PROTOCOL_NON_IP })
RadioButtonItem("Unstructured", { protocol == PROTOCOL_UNSTRUCTURED }, { protocol = PROTOCOL_UNSTRUCTURED })
RadioButtonItem("non-IP", protocol == PROTOCOL_NON_IP, { protocol = PROTOCOL_NON_IP })
RadioButtonItem("Unstructured", protocol == PROTOCOL_UNSTRUCTURED, { protocol = PROTOCOL_UNSTRUCTURED })
}

Text(text = stringResource(R.string.roaming_protocol), style = typography.titleLarge)
RadioButtonItem("IPV4", { roamingProtocol == PROTOCOL_IP }, { roamingProtocol = PROTOCOL_IP })
RadioButtonItem("IPV6", { roamingProtocol == PROTOCOL_IPV6 }, { roamingProtocol = PROTOCOL_IPV6 })
RadioButtonItem("IPV4/IPV6", { roamingProtocol == PROTOCOL_IPV4V6 }, { roamingProtocol = PROTOCOL_IPV4V6 })
RadioButtonItem("PPP", { roamingProtocol == PROTOCOL_PPP }, { roamingProtocol = PROTOCOL_PPP})
RadioButtonItem("IPV4", roamingProtocol == PROTOCOL_IP, { roamingProtocol = PROTOCOL_IP })
RadioButtonItem("IPV6", roamingProtocol == PROTOCOL_IPV6, { roamingProtocol = PROTOCOL_IPV6 })
RadioButtonItem("IPV4/IPV6", roamingProtocol == PROTOCOL_IPV4V6, { roamingProtocol = PROTOCOL_IPV4V6 })
RadioButtonItem("PPP", roamingProtocol == PROTOCOL_PPP, { roamingProtocol = PROTOCOL_PPP})
if(VERSION.SDK_INT>=29) {
RadioButtonItem("non-IP", { roamingProtocol == PROTOCOL_NON_IP }, { roamingProtocol = PROTOCOL_NON_IP })
RadioButtonItem("Unstructured", { roamingProtocol == PROTOCOL_UNSTRUCTURED }, { roamingProtocol = PROTOCOL_UNSTRUCTURED })
RadioButtonItem("non-IP", roamingProtocol == PROTOCOL_NON_IP, { roamingProtocol = PROTOCOL_NON_IP })
RadioButtonItem("Unstructured", roamingProtocol == PROTOCOL_UNSTRUCTURED, { roamingProtocol = PROTOCOL_UNSTRUCTURED })
}

var finalStep by remember { mutableStateOf(false) }
Expand Down
60 changes: 30 additions & 30 deletions app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@ private fun ResetPassword() {
if(VERSION.SDK_INT >= 23) {
RadioButtonItem(
stringResource(R.string.do_not_ask_credentials_on_boot),
{ resetPwdFlag == RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT },
resetPwdFlag == RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT,
{ resetPwdFlag = RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT }
)
}
RadioButtonItem(
stringResource(R.string.reset_password_require_entry),
{ resetPwdFlag==RESET_PASSWORD_REQUIRE_ENTRY },
{ resetPwdFlag=RESET_PASSWORD_REQUIRE_ENTRY }
resetPwdFlag == RESET_PASSWORD_REQUIRE_ENTRY,
{ resetPwdFlag = RESET_PASSWORD_REQUIRE_ENTRY }
)
RadioButtonItem(stringResource(R.string.none), { resetPwdFlag==0 }, { resetPwdFlag=0 })
RadioButtonItem(stringResource(R.string.none), resetPwdFlag == 0, { resetPwdFlag = 0 })
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = {
Expand Down Expand Up @@ -310,22 +310,22 @@ private fun PasswordComplexity() {
Spacer(Modifier.padding(vertical = 5.dp))
RadioButtonItem(
passwordComplexity[0].second,
{ selectedItem == passwordComplexity[0].first },
selectedItem == passwordComplexity[0].first,
{ selectedItem = passwordComplexity[0].first }
)
RadioButtonItem(
passwordComplexity[1].second,
{ selectedItem == passwordComplexity[1].first },
selectedItem == passwordComplexity[1].first,
{ selectedItem = passwordComplexity[1].first }
)
RadioButtonItem(
passwordComplexity[2].second,
{ selectedItem == passwordComplexity[2].first },
selectedItem == passwordComplexity[2].first,
{ selectedItem = passwordComplexity[2].first }
)
RadioButtonItem(
passwordComplexity[3].second,
{ selectedItem == passwordComplexity[3].first },
selectedItem == passwordComplexity[3].first,
{ selectedItem = passwordComplexity[3].first }
)
Spacer(Modifier.padding(vertical = 5.dp))
Expand Down Expand Up @@ -564,24 +564,24 @@ private fun KeyguardDisabledFeatures() {
Spacer(Modifier.padding(vertical = 10.dp))
Text(text = stringResource(R.string.keyguard_disabled_features), style = typography.headlineLarge)
Spacer(Modifier.padding(vertical = 5.dp))
RadioButtonItem(stringResource(R.string.enable_all), { state==0 }, { state=0 })
RadioButtonItem(stringResource(R.string.disable_all), { state==1 }, { state=1 })
RadioButtonItem(stringResource(R.string.custom), { state==2 }, { state=2 })
RadioButtonItem(stringResource(R.string.enable_all), state == 0, { state = 0 })
RadioButtonItem(stringResource(R.string.disable_all), state == 1, { state = 1 })
RadioButtonItem(stringResource(R.string.custom), state == 2 , { state = 2 })
AnimatedVisibility(state==2) {
Column {
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_widgets), { widgets }, { widgets=!widgets })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_camera), { camera }, { camera=!camera })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_notification), { notification }, { notification=!notification })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_unredacted_notification), { unredacted }, { unredacted=!unredacted })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_trust_agents), { agents }, { agents=!agents })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_fingerprint), { fingerprint }, { fingerprint=!fingerprint })
if(VERSION.SDK_INT >= 24) { CheckBoxItem(stringResource(R.string.keyguard_disabled_features_remote_input), { remote} , { remote=!remote }) }
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_widgets), widgets, { widgets = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_camera), camera, { camera = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_notification), notification, { notification = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_unredacted_notification), unredacted, { unredacted = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_trust_agents), agents, { agents = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_fingerprint), fingerprint, { fingerprint = it })
if(VERSION.SDK_INT >= 24) { CheckBoxItem(stringResource(R.string.keyguard_disabled_features_remote_input), remote , { remote = it }) }
if(VERSION.SDK_INT >= 28) {
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_face), { face }, { face=!face })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_iris), { iris }, { iris=!iris })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_biometrics), { biometrics }, { biometrics=!biometrics })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_face), face, { face = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_iris), iris, { iris = it })
CheckBoxItem(stringResource(R.string.keyguard_disabled_features_biometrics), biometrics, { biometrics = it })
}
if(VERSION.SDK_INT >= 34) { CheckBoxItem(stringResource(R.string.keyguard_disabled_features_shortcuts), { shortcuts }, { shortcuts=!shortcuts }) }
if(VERSION.SDK_INT >= 34) { CheckBoxItem(stringResource(R.string.keyguard_disabled_features_shortcuts), shortcuts, { shortcuts = it }) }
}
}
Spacer(Modifier.padding(vertical = 5.dp))
Expand Down Expand Up @@ -640,14 +640,14 @@ private fun PasswordQuality() {
Text(text = stringResource(R.string.password_complexity_instead_password_quality))
if(VERSION.SDK_INT >= 31) { Text(text = stringResource(R.string.password_quality_deprecated_desc), color = colorScheme.error) }
Spacer(Modifier.padding(vertical = 5.dp))
RadioButtonItem(passwordQuality[0].second, { selectedItem == passwordQuality[0].first }, { selectedItem = passwordQuality[0].first })
RadioButtonItem(passwordQuality[1].second, { selectedItem == passwordQuality[1].first }, { selectedItem = passwordQuality[1].first })
RadioButtonItem(passwordQuality[2].second, { selectedItem == passwordQuality[2].first }, { selectedItem = passwordQuality[2].first })
RadioButtonItem(passwordQuality[3].second, { selectedItem == passwordQuality[3].first }, { selectedItem = passwordQuality[3].first })
RadioButtonItem(passwordQuality[4].second, { selectedItem == passwordQuality[4].first }, { selectedItem = passwordQuality[4].first })
RadioButtonItem(passwordQuality[5].second, { selectedItem == passwordQuality[5].first }, { selectedItem = passwordQuality[5].first })
RadioButtonItem(passwordQuality[6].second, { selectedItem == passwordQuality[6].first }, { selectedItem = passwordQuality[6].first })
RadioButtonItem(passwordQuality[7].second, { selectedItem == passwordQuality[7].first }, { selectedItem = passwordQuality[7].first })
RadioButtonItem(passwordQuality[0].second, selectedItem == passwordQuality[0].first, { selectedItem = passwordQuality[0].first })
RadioButtonItem(passwordQuality[1].second, selectedItem == passwordQuality[1].first, { selectedItem = passwordQuality[1].first })
RadioButtonItem(passwordQuality[2].second, selectedItem == passwordQuality[2].first, { selectedItem = passwordQuality[2].first })
RadioButtonItem(passwordQuality[3].second, selectedItem == passwordQuality[3].first, { selectedItem = passwordQuality[3].first })
RadioButtonItem(passwordQuality[4].second, selectedItem == passwordQuality[4].first, { selectedItem = passwordQuality[4].first })
RadioButtonItem(passwordQuality[5].second, selectedItem == passwordQuality[5].first, { selectedItem = passwordQuality[5].first })
RadioButtonItem(passwordQuality[6].second, selectedItem == passwordQuality[6].first, { selectedItem = passwordQuality[6].first })
RadioButtonItem(passwordQuality[7].second, selectedItem == passwordQuality[7].first, { selectedItem = passwordQuality[7].first })
Spacer(Modifier.padding(vertical = 5.dp))
Button(
onClick = {
Expand Down
Loading

0 comments on commit 45317e3

Please sign in to comment.