1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.settings.spa.network
18
19 import android.telephony.SubscriptionInfo
20 import androidx.compose.foundation.layout.fillMaxWidth
21 import androidx.compose.foundation.layout.padding
22 import androidx.compose.material.icons.Icons
23 import androidx.compose.material.icons.outlined.SignalCellularAlt
24 import androidx.compose.material3.Text
25 import androidx.compose.runtime.Composable
26 import androidx.compose.runtime.getValue
27 import androidx.compose.runtime.mutableStateOf
28 import androidx.compose.runtime.remember
29 import androidx.compose.runtime.setValue
30 import androidx.compose.ui.Modifier
31 import androidx.compose.ui.platform.testTag
32 import androidx.compose.ui.res.stringResource
33 import com.android.settings.R
34 import com.android.settings.network.SimOnboardingService
35 import com.android.settingslib.spa.framework.theme.SettingsDimension
36 import com.android.settingslib.spa.widget.dialog.AlertDialogButton
37 import com.android.settingslib.spa.widget.dialog.rememberAlertDialogPresenter
38 import com.android.settingslib.spa.widget.editor.SettingsOutlinedTextField
39
40 import com.android.settingslib.spa.widget.preference.Preference
41 import com.android.settingslib.spa.widget.preference.PreferenceModel
42 import com.android.settingslib.spa.widget.scaffold.BottomAppBarButton
43 import com.android.settingslib.spa.widget.scaffold.SuwScaffold
44
45 /**
46 * the sim onboarding label compose
47 */
48 @Composable
SimOnboardingLabelSimImplnull49 fun SimOnboardingLabelSimImpl(
50 nextAction: () -> Unit,
51 cancelAction: () -> Unit,
52 onboardingService: SimOnboardingService
53 ) {
54 SuwScaffold(
55 imageVector = Icons.Outlined.SignalCellularAlt,
56 title = stringResource(R.string.sim_onboarding_label_sim_title),
57 actionButton = BottomAppBarButton(
58 text = stringResource(R.string.sim_onboarding_next),
59 onClick = nextAction
60 ),
61 dismissButton = BottomAppBarButton(
62 text = stringResource(R.string.cancel),
63 onClick = cancelAction
64 ),
65 ) {
66 LabelSimBody(onboardingService)
67 }
68 }
69
70 @Composable
LabelSimBodynull71 private fun LabelSimBody(onboardingService: SimOnboardingService) {
72 SimOnboardingMessage(stringResource(R.string.sim_onboarding_label_sim_msg))
73
74 for (subInfo in onboardingService.getSelectableSubscriptionInfoList()) {
75 LabelSimPreference(onboardingService, subInfo)
76 }
77 }
78
79 @Composable
LabelSimPreferencenull80 private fun LabelSimPreference(
81 onboardingService: SimOnboardingService,
82 subInfo: SubscriptionInfo,
83 ) {
84 val currentSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
85 var prefTitle by remember {
86 mutableStateOf(currentSimName)
87 }
88 var dialogInputContent by remember {
89 mutableStateOf(currentSimName)
90 }
91 val phoneNumber = phoneNumber(subInfo)
92 val alertDialogPresenter = rememberAlertDialogPresenter(
93 confirmButton = AlertDialogButton(
94 stringResource(R.string.mobile_network_sim_name_rename),
95 dialogInputContent.isNotBlank()
96 ) {
97 onboardingService.addItemForRenaming(
98 subInfo, dialogInputContent
99 )
100 prefTitle = dialogInputContent
101 },
102 dismissButton = AlertDialogButton(
103 stringResource(R.string.cancel),
104 ) {
105 // Do nothing
106 },
107 title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
108 text = {
109 Text(
110 phoneNumber.value ?: "",
111 modifier = Modifier.padding(bottom = SettingsDimension.itemPaddingVertical)
112 )
113 SettingsOutlinedTextField(
114 value = dialogInputContent,
115 label = stringResource(R.string.sim_onboarding_label_sim_dialog_label),
116 placeholder = {Text(text = subInfo.displayName.toString())},
117 modifier = Modifier
118 .fillMaxWidth()
119 .testTag("contentInput")
120 ) {
121 dialogInputContent = it
122 }
123 },
124 )
125 Preference(object : PreferenceModel {
126 override val title = prefTitle
127 override val summary = { phoneNumber.value ?: "" }
128 override val onClick = alertDialogPresenter::open
129 })
130 }
131