Merge "Automatically save on return" into main
This commit is contained in:
@@ -39,6 +39,7 @@ import com.android.settings.network.apn.ApnNetworkTypes.getNetworkTypeDisplayNam
|
|||||||
import com.android.settings.network.apn.ApnNetworkTypes.getNetworkTypeSelectedOptionsState
|
import com.android.settings.network.apn.ApnNetworkTypes.getNetworkTypeSelectedOptionsState
|
||||||
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
import com.android.settingslib.spa.framework.common.SettingsPageProvider
|
||||||
import com.android.settingslib.spa.framework.compose.LocalNavController
|
import com.android.settingslib.spa.framework.compose.LocalNavController
|
||||||
|
import com.android.settingslib.spa.framework.compose.OnBackEffect
|
||||||
import com.android.settingslib.spa.widget.editor.SettingsExposedDropdownMenuBox
|
import com.android.settingslib.spa.widget.editor.SettingsExposedDropdownMenuBox
|
||||||
import com.android.settingslib.spa.widget.editor.SettingsExposedDropdownMenuCheckBox
|
import com.android.settingslib.spa.widget.editor.SettingsExposedDropdownMenuCheckBox
|
||||||
import com.android.settingslib.spa.widget.editor.SettingsOutlinedTextField
|
import com.android.settingslib.spa.widget.editor.SettingsOutlinedTextField
|
||||||
@@ -97,21 +98,20 @@ fun ApnPage(apnDataInit: ApnData, apnDataCur: MutableState<ApnData>, uriInit: Ur
|
|||||||
val networkTypeSelectedOptionsState = remember {
|
val networkTypeSelectedOptionsState = remember {
|
||||||
getNetworkTypeSelectedOptionsState(apnData.networkType)
|
getNetworkTypeSelectedOptionsState(apnData.networkType)
|
||||||
}
|
}
|
||||||
|
OnBackEffect{
|
||||||
|
validateAndSaveApnData(
|
||||||
|
apnDataInit,
|
||||||
|
apnData,
|
||||||
|
context,
|
||||||
|
uriInit,
|
||||||
|
networkTypeSelectedOptionsState
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val navController = LocalNavController.current
|
||||||
RegularScaffold(
|
RegularScaffold(
|
||||||
title = if(apnDataInit.newApn) stringResource(id = R.string.apn_add) else stringResource(id = R.string.apn_edit),
|
title = if(apnDataInit.newApn) stringResource(id = R.string.apn_add) else stringResource(id = R.string.apn_edit),
|
||||||
actions = {
|
|
||||||
IconButton(onClick = {
|
|
||||||
validateAndSaveApnData(
|
|
||||||
apnDataInit,
|
|
||||||
apnData,
|
|
||||||
context,
|
|
||||||
uriInit,
|
|
||||||
networkTypeSelectedOptionsState
|
|
||||||
)
|
|
||||||
}) { Icon(imageVector = Icons.Outlined.Done, contentDescription = "Save APN") }
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
Column() {
|
Column {
|
||||||
SettingsOutlinedTextField(
|
SettingsOutlinedTextField(
|
||||||
value = apnData.name,
|
value = apnData.name,
|
||||||
label = stringResource(R.string.apn_name),
|
label = stringResource(R.string.apn_name),
|
||||||
@@ -203,12 +203,12 @@ fun ApnPage(apnDataInit: ApnData, apnDataCur: MutableState<ApnData>, uriInit: Ur
|
|||||||
enabled = apnData.networkTypeEnabled
|
enabled = apnData.networkTypeEnabled
|
||||||
) {}
|
) {}
|
||||||
if (!apnData.newApn) {
|
if (!apnData.newApn) {
|
||||||
val navController = LocalNavController.current
|
|
||||||
Preference(
|
Preference(
|
||||||
object : PreferenceModel {
|
object : PreferenceModel {
|
||||||
override val title = stringResource(R.string.menu_delete)
|
override val title = stringResource(R.string.menu_delete)
|
||||||
override val onClick = {
|
override val onClick = {
|
||||||
deleteApn(uriInit, context)
|
deleteApn(uriInit, context)
|
||||||
|
apnData = apnData.copy(saveEnabled = false)
|
||||||
navController.navigateBack()
|
navController.navigateBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -69,6 +69,7 @@ data class ApnData(
|
|||||||
val networkTypeEnabled: Boolean = true,
|
val networkTypeEnabled: Boolean = true,
|
||||||
val newApn: Boolean = false,
|
val newApn: Boolean = false,
|
||||||
val subId: Int = -1,
|
val subId: Int = -1,
|
||||||
|
val saveEnabled: Boolean = true,
|
||||||
val customizedConfig: CustomizedConfig = CustomizedConfig()
|
val customizedConfig: CustomizedConfig = CustomizedConfig()
|
||||||
) {
|
) {
|
||||||
fun getContentValues(context: Context): ContentValues {
|
fun getContentValues(context: Context): ContentValues {
|
||||||
@@ -230,6 +231,10 @@ fun validateAndSaveApnData(
|
|||||||
uriInit: Uri,
|
uriInit: Uri,
|
||||||
networkTypeSelectedOptionsState: SnapshotStateList<Int>
|
networkTypeSelectedOptionsState: SnapshotStateList<Int>
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
// Can not be saved
|
||||||
|
if (!apnData.saveEnabled) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
// Nothing to do if it's a read only APN
|
// Nothing to do if it's a read only APN
|
||||||
if (apnData.customizedConfig.readOnlyApn) {
|
if (apnData.customizedConfig.readOnlyApn) {
|
||||||
return true
|
return true
|
||||||
|
Reference in New Issue
Block a user