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 originalSimCarrierName = subInfo.displayName.toString()
85 var titleSimName by remember {
86 mutableStateOf(onboardingService.getSubscriptionInfoDisplayName(subInfo))
87 }
88 val phoneNumber = phoneNumber(subInfo)
89 val alertDialogPresenter = rememberAlertDialogPresenter(
90 confirmButton = AlertDialogButton(
91 stringResource(R.string.mobile_network_sim_name_rename),
92 titleSimName.isNotBlank()
93 ) {
94 onboardingService.addItemForRenaming(
95 subInfo, if (titleSimName.isEmpty()) originalSimCarrierName else titleSimName
96 )
97 },
98 dismissButton = AlertDialogButton(
99 stringResource(R.string.cancel),
100 ) {
101 titleSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
102 },
103 title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
104 text = {
105 Text(
106 phoneNumber.value ?: "",
107 modifier = Modifier.padding(bottom = SettingsDimension.itemPaddingVertical)
108 )
109 SettingsOutlinedTextField(
110 value = titleSimName,
111 label = stringResource(R.string.sim_onboarding_label_sim_dialog_label),
112 placeholder = {Text(text = originalSimCarrierName)},
113 modifier = Modifier.fillMaxWidth().testTag("contentInput")
114 ) {
115 titleSimName = it
116 }
117 },
118 )
119 Preference(object : PreferenceModel {
120 override val title = titleSimName
121 override val summary = { phoneNumber.value ?: "" }
122 override val onClick = alertDialogPresenter::open
123 })
124 }
125