From 45317e3975e011c6ba623e1392597fe48ff70c3e Mon Sep 17 00:00:00 2001 From: BinTianqi Date: Mon, 3 Jun 2024 13:51:22 +0800 Subject: [PATCH] use state to control RadioButtonItem and CheckBoxItem --- .../owndroid/dpm/ApplicationManage.kt | 14 ++-- .../bintianqi/owndroid/dpm/ManagedProfile.kt | 2 +- .../com/bintianqi/owndroid/dpm/Network.kt | 57 ++++++++-------- .../com/bintianqi/owndroid/dpm/Password.kt | 60 ++++++++--------- .../bintianqi/owndroid/dpm/SystemManager.kt | 66 +++++++++---------- .../com/bintianqi/owndroid/dpm/UserManager.kt | 12 ++-- .../com/bintianqi/owndroid/ui/Components.kt | 16 ++--- 7 files changed, 114 insertions(+), 113 deletions(-) diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt index 5347391..5918174 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ApplicationManage.kt @@ -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) { diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt index 65481eb..3786cb7 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/ManagedProfile.kt @@ -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( diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt index fecd498..9988563 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/Network.kt @@ -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)) @@ -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) { @@ -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 @@ -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( @@ -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) } diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt index c1a8746..b723b73 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/Password.kt @@ -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 = { @@ -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)) @@ -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)) @@ -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 = { diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt index 7527813..a458fac 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/SystemManager.kt @@ -337,7 +337,7 @@ private fun Keyguard() { if(VERSION.SDK_INT >= 26) { CheckBoxItem( stringResource(R.string.require_enter_password_again), - { flag==FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY }, + flag == FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY, { flag = if(flag==0) {1}else{0} } ) } @@ -505,9 +505,9 @@ private fun PermissionPolicy() { Spacer(Modifier.padding(vertical = 10.dp)) Text(text = stringResource(R.string.permission_policy), style = typography.headlineLarge) Spacer(Modifier.padding(vertical = 5.dp)) - RadioButtonItem(stringResource(R.string.default_stringres), { selectedPolicy==PERMISSION_POLICY_PROMPT }, { selectedPolicy= PERMISSION_POLICY_PROMPT }) - RadioButtonItem(stringResource(R.string.auto_grant), { selectedPolicy==PERMISSION_POLICY_AUTO_GRANT }, { selectedPolicy= PERMISSION_POLICY_AUTO_GRANT }) - RadioButtonItem(stringResource(R.string.auto_deny), { selectedPolicy==PERMISSION_POLICY_AUTO_DENY }, { selectedPolicy= PERMISSION_POLICY_AUTO_DENY }) + RadioButtonItem(stringResource(R.string.default_stringres), selectedPolicy == PERMISSION_POLICY_PROMPT, { selectedPolicy = PERMISSION_POLICY_PROMPT }) + RadioButtonItem(stringResource(R.string.auto_grant), selectedPolicy == PERMISSION_POLICY_AUTO_GRANT, { selectedPolicy = PERMISSION_POLICY_AUTO_GRANT }) + RadioButtonItem(stringResource(R.string.auto_deny), selectedPolicy == PERMISSION_POLICY_AUTO_DENY, { selectedPolicy = PERMISSION_POLICY_AUTO_DENY }) Spacer(Modifier.padding(vertical = 5.dp)) Button( onClick = { @@ -533,17 +533,17 @@ private fun MTEPolicy() { var selectedMtePolicy by remember { mutableIntStateOf(dpm.mtePolicy) } RadioButtonItem( stringResource(R.string.decide_by_user), - { selectedMtePolicy == MTE_NOT_CONTROLLED_BY_POLICY }, + selectedMtePolicy == MTE_NOT_CONTROLLED_BY_POLICY, { selectedMtePolicy = MTE_NOT_CONTROLLED_BY_POLICY } ) RadioButtonItem( stringResource(R.string.enabled), - { selectedMtePolicy == MTE_ENABLED }, + selectedMtePolicy == MTE_ENABLED, { selectedMtePolicy = MTE_ENABLED } ) RadioButtonItem( stringResource(R.string.disabled), - { selectedMtePolicy == MTE_DISABLED }, + selectedMtePolicy == MTE_DISABLED, { selectedMtePolicy = MTE_DISABLED } ) Button( @@ -578,22 +578,22 @@ private fun NearbyStreamingPolicy() { Spacer(Modifier.padding(vertical = 3.dp)) RadioButtonItem( stringResource(R.string.decide_by_user), - { appPolicy == NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY }, + appPolicy == NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY, { appPolicy = NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY } ) RadioButtonItem( stringResource(R.string.enabled), - { appPolicy == NEARBY_STREAMING_ENABLED }, + appPolicy == NEARBY_STREAMING_ENABLED, { appPolicy = NEARBY_STREAMING_ENABLED } ) RadioButtonItem( stringResource(R.string.disabled), - { appPolicy == NEARBY_STREAMING_DISABLED }, + appPolicy == NEARBY_STREAMING_DISABLED, { appPolicy = NEARBY_STREAMING_DISABLED } ) RadioButtonItem( stringResource(R.string.enable_if_secure_enough), - { appPolicy == NEARBY_STREAMING_SAME_MANAGED_ACCOUNT_ONLY }, + appPolicy == NEARBY_STREAMING_SAME_MANAGED_ACCOUNT_ONLY, { appPolicy = NEARBY_STREAMING_SAME_MANAGED_ACCOUNT_ONLY } ) Spacer(Modifier.padding(vertical = 3.dp)) @@ -612,22 +612,22 @@ private fun NearbyStreamingPolicy() { Spacer(Modifier.padding(vertical = 3.dp)) RadioButtonItem( stringResource(R.string.decide_by_user), - { notificationPolicy == NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY }, + notificationPolicy == NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY, { notificationPolicy = NEARBY_STREAMING_NOT_CONTROLLED_BY_POLICY } ) RadioButtonItem( stringResource(R.string.enabled), - { notificationPolicy == NEARBY_STREAMING_ENABLED }, + notificationPolicy == NEARBY_STREAMING_ENABLED, { notificationPolicy = NEARBY_STREAMING_ENABLED } ) RadioButtonItem( stringResource(R.string.disabled), - { notificationPolicy == NEARBY_STREAMING_DISABLED }, + notificationPolicy == NEARBY_STREAMING_DISABLED, { notificationPolicy = NEARBY_STREAMING_DISABLED } ) RadioButtonItem( stringResource(R.string.enable_if_secure_enough), - { notificationPolicy == NEARBY_STREAMING_SAME_MANAGED_ACCOUNT_ONLY }, + notificationPolicy == NEARBY_STREAMING_SAME_MANAGED_ACCOUNT_ONLY, { notificationPolicy = NEARBY_STREAMING_SAME_MANAGED_ACCOUNT_ONLY } ) Spacer(Modifier.padding(vertical = 3.dp)) @@ -689,17 +689,17 @@ private fun LockTaskFeatures() { Text(text = stringResource(R.string.lock_task_feature), style = typography.headlineLarge) Spacer(Modifier.padding(vertical = 5.dp)) if(!inited) { refreshFeature(); custom=dpm.getLockTaskFeatures(receiver)!=0; inited= true } - RadioButtonItem(stringResource(R.string.disable_all), { !custom }, { custom=false }) - RadioButtonItem(stringResource(R.string.custom), { custom }, { custom= true }) + RadioButtonItem(stringResource(R.string.disable_all), !custom, { custom = false }) + RadioButtonItem(stringResource(R.string.custom), custom, { custom = true }) AnimatedVisibility(custom) { Column { - CheckBoxItem(stringResource(R.string.ltf_sys_info), { sysInfo }, { sysInfo = !sysInfo }) - CheckBoxItem(stringResource(R.string.ltf_notifications), { notifications }, { notifications = !notifications }) - CheckBoxItem(stringResource(R.string.ltf_home), { home }, { home = !home }) - CheckBoxItem(stringResource(R.string.ltf_overview), { overview }, { overview = !overview }) - CheckBoxItem(stringResource(R.string.ltf_global_actions), { globalAction}, {globalAction = !globalAction}) - CheckBoxItem(stringResource(R.string.ltf_keyguard), { keyGuard }, { keyGuard = !keyGuard }) - if(VERSION.SDK_INT >= 30) { CheckBoxItem(stringResource(R.string.ltf_block_activity_start_in_task), { blockAct }, { blockAct=!blockAct }) } + CheckBoxItem(stringResource(R.string.ltf_sys_info), sysInfo, { sysInfo = it }) + CheckBoxItem(stringResource(R.string.ltf_notifications), notifications, { notifications = it }) + CheckBoxItem(stringResource(R.string.ltf_home), home, { home = it }) + CheckBoxItem(stringResource(R.string.ltf_overview), overview, { overview = it }) + CheckBoxItem(stringResource(R.string.ltf_global_actions), globalAction, { globalAction = it }) + CheckBoxItem(stringResource(R.string.ltf_keyguard), keyGuard, { keyGuard = it }) + if(VERSION.SDK_INT >= 30) { CheckBoxItem(stringResource(R.string.ltf_block_activity_start_in_task), blockAct, { blockAct = it }) } } } Button( @@ -949,7 +949,7 @@ fun FactoryResetProtection() { } AnimatedVisibility(usePolicy) { Column { - CheckBoxItem(stringResource(R.string.enable_frp), { enabled }, { enabled = !enabled }) + CheckBoxItem(stringResource(R.string.enable_frp), enabled, { enabled = it }) Text(stringResource(R.string.account_list_is)) Text( text = if(accountList.isEmpty()) stringResource(R.string.none) else accountList.toText(), @@ -1032,15 +1032,15 @@ private fun WipeData() { Spacer(Modifier.padding(vertical = 5.dp)) CheckBoxItem( stringResource(R.string.wipe_external_storage), - { externalStorage }, { externalStorage = !externalStorage; confirmed = false } + externalStorage, { externalStorage = it; confirmed = false } ) if(VERSION.SDK_INT >= 22 && isDeviceOwner(dpm)) { CheckBoxItem(stringResource(R.string.wipe_reset_protection_data), - { protectionData }, { protectionData = !protectionData; confirmed = false} + protectionData, { protectionData = it; confirmed = false} ) } - if(VERSION.SDK_INT >= 28) { CheckBoxItem(stringResource(R.string.wipe_euicc), { euicc }, { euicc = !euicc; confirmed = false }) } - if(VERSION.SDK_INT >= 29) { CheckBoxItem(stringResource(R.string.wipe_silently), { silent }, { silent = !silent; confirmed = false }) } + if(VERSION.SDK_INT >= 28) { CheckBoxItem(stringResource(R.string.wipe_euicc), euicc, { euicc = it; confirmed = false }) } + if(VERSION.SDK_INT >= 29) { CheckBoxItem(stringResource(R.string.wipe_silently), silent, { silent = it; confirmed = false }) } AnimatedVisibility(!silent && VERSION.SDK_INT >= 28) { OutlinedTextField( value = reason, onValueChange = { reason = it }, @@ -1120,17 +1120,17 @@ private fun SysUpdatePolicy() { Spacer(Modifier.padding(vertical = 5.dp)) RadioButtonItem( stringResource(R.string.system_update_policy_automatic), - { selectedPolicy == TYPE_INSTALL_AUTOMATIC }, { selectedPolicy = TYPE_INSTALL_AUTOMATIC } + selectedPolicy == TYPE_INSTALL_AUTOMATIC, { selectedPolicy = TYPE_INSTALL_AUTOMATIC } ) RadioButtonItem( stringResource(R.string.system_update_policy_install_windowed), - { selectedPolicy == TYPE_INSTALL_WINDOWED }, { selectedPolicy = TYPE_INSTALL_WINDOWED } + selectedPolicy == TYPE_INSTALL_WINDOWED, { selectedPolicy = TYPE_INSTALL_WINDOWED } ) RadioButtonItem( stringResource(R.string.system_update_policy_postpone), - { selectedPolicy == TYPE_POSTPONE}, { selectedPolicy = TYPE_POSTPONE } + selectedPolicy == TYPE_POSTPONE, { selectedPolicy = TYPE_POSTPONE } ) - RadioButtonItem(stringResource(R.string.none), { selectedPolicy == null }, { selectedPolicy = null }) + RadioButtonItem(stringResource(R.string.none), selectedPolicy == null, { selectedPolicy = null }) var windowedPolicyStart by remember { mutableStateOf("") } var windowedPolicyEnd by remember { mutableStateOf("") } if(selectedPolicy == 2) { diff --git a/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt b/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt index 5ec2ae0..780f2f7 100644 --- a/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt +++ b/app/src/main/java/com/bintianqi/owndroid/dpm/UserManager.kt @@ -202,7 +202,7 @@ private fun UserOperation() { ) Spacer(Modifier.padding(vertical = 3.dp)) if(VERSION.SDK_INT >= 24) { - CheckBoxItem(text = stringResource(R.string.use_uid), checked = { useUid }, operation = { idInput=""; useUid = !useUid}) + CheckBoxItem(text = stringResource(R.string.use_uid), checked = useUid, operation = { idInput=""; useUid = it }) } Spacer(Modifier.padding(vertical = 5.dp)) if(VERSION.SDK_INT > 28) { @@ -301,21 +301,21 @@ private fun CreateUser() { ) Spacer(Modifier.padding(vertical = 5.dp)) var selectedFlag by remember { mutableIntStateOf(0) } - RadioButtonItem(stringResource(R.string.none), { selectedFlag == 0 }, { selectedFlag = 0 }) + RadioButtonItem(stringResource(R.string.none), selectedFlag == 0, { selectedFlag = 0 }) RadioButtonItem( stringResource(R.string.create_user_skip_wizard), - { selectedFlag == DevicePolicyManager.SKIP_SETUP_WIZARD }, + selectedFlag == DevicePolicyManager.SKIP_SETUP_WIZARD, { selectedFlag = DevicePolicyManager.SKIP_SETUP_WIZARD } ) if(VERSION.SDK_INT >= 28) { RadioButtonItem( stringResource(R.string.create_user_ephemeral_user), - { selectedFlag == DevicePolicyManager.MAKE_USER_EPHEMERAL }, + selectedFlag == DevicePolicyManager.MAKE_USER_EPHEMERAL, { selectedFlag = DevicePolicyManager.MAKE_USER_EPHEMERAL } ) RadioButtonItem( stringResource(R.string.create_user_enable_all_system_app), - { selectedFlag == DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED }, + selectedFlag == DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED, { selectedFlag = DevicePolicyManager.LEAVE_ALL_SYSTEM_APPS_ENABLED } ) } @@ -521,7 +521,7 @@ private fun UserIcon() { Spacer(Modifier.padding(vertical = 5.dp)) Text(text = stringResource(R.string.pick_a_square_image)) Spacer(Modifier.padding(vertical = 5.dp)) - CheckBoxItem(stringResource(R.string.file_picker_instead_gallery), {getContent}, {getContent=!getContent}) + CheckBoxItem(stringResource(R.string.file_picker_instead_gallery), getContent, { getContent = it }) Spacer(Modifier.padding(vertical = 5.dp)) Button( onClick = { diff --git a/app/src/main/java/com/bintianqi/owndroid/ui/Components.kt b/app/src/main/java/com/bintianqi/owndroid/ui/Components.kt index 82d349e..898f4fc 100644 --- a/app/src/main/java/com/bintianqi/owndroid/ui/Components.kt +++ b/app/src/main/java/com/bintianqi/owndroid/ui/Components.kt @@ -81,8 +81,8 @@ fun Information(content: @Composable ()->Unit) { @Composable fun RadioButtonItem( text: String, - selected: ()->Boolean, - operation: ()->Unit, + selected: Boolean, + operation: () -> Unit, textColor: Color = colorScheme.onBackground ) { Row(verticalAlignment = Alignment.CenterVertically,modifier = Modifier @@ -90,7 +90,7 @@ fun RadioButtonItem( .clip(RoundedCornerShape(25)) .clickable(onClick = operation) ) { - RadioButton(selected = selected(), onClick = operation) + RadioButton(selected = selected, onClick = operation) Text(text = text, color = textColor, modifier = Modifier.padding(bottom = if(zhCN) { 2 } else { 0 }.dp)) } } @@ -98,18 +98,18 @@ fun RadioButtonItem( @Composable fun CheckBoxItem( text: String, - checked: ()->Boolean, - operation: ()->Unit, + checked: Boolean, + operation: (Boolean) -> Unit, textColor: Color = colorScheme.onBackground ) { Row(verticalAlignment = Alignment.CenterVertically,modifier = Modifier .fillMaxWidth() .clip(RoundedCornerShape(25)) - .clickable(onClick = operation) + .clickable { operation(!checked) } ) { Checkbox( - checked = checked(), - onCheckedChange = { operation() } + checked = checked, + onCheckedChange = operation ) Text(text = text, color = textColor, modifier = Modifier.padding(bottom = if(zhCN) { 2 } else { 0 }.dp)) }