1 /*
<lambda>null2 * 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 androidx.compose.material.icons.Icons
20 import androidx.compose.material.icons.outlined.SignalCellularAlt
21 import androidx.compose.runtime.Composable
22 import androidx.compose.runtime.MutableState
23 import androidx.compose.runtime.mutableStateOf
24 import androidx.compose.runtime.remember
25 import androidx.compose.runtime.saveable.rememberSaveable
26 import androidx.compose.ui.res.stringResource
27 import com.android.settings.R
28 import com.android.settings.network.SimOnboardingService
29 import com.android.settingslib.spa.widget.preference.CheckboxPreference
30 import com.android.settingslib.spa.widget.preference.CheckboxPreferenceModel
31 import com.android.settingslib.spa.widget.scaffold.BottomAppBarButton
32 import com.android.settingslib.spa.widget.scaffold.SuwScaffold
33
34 /**
35 * the sim onboarding select sim compose
36 */
37 @Composable
38 fun SimOnboardingSelectSimImpl(
39 nextAction: () -> Unit,
40 cancelAction: () -> Unit,
41 onboardingService: SimOnboardingService
42 ) {
43 var actionButtonController = rememberSaveable { mutableStateOf(false) }
44
45 SuwScaffold(
46 imageVector = Icons.Outlined.SignalCellularAlt,
47 title = stringResource(id = R.string.sim_onboarding_select_sim_title),
48 actionButton = BottomAppBarButton(
49 text = stringResource(id = R.string.sim_onboarding_next),
50 enabled = actionButtonController.value,
51 onClick = nextAction
52 ),
53 dismissButton = BottomAppBarButton(
54 text = stringResource(id = R.string.cancel),
55 onClick = cancelAction
56 ),
57 ) {
58 SelectSimBody(onboardingService, actionButtonController)
59 }
60 }
61
62 @Composable
SelectSimBodynull63 private fun SelectSimBody(
64 onboardingService: SimOnboardingService,
65 isFinished: MutableState<Boolean>
66 ) {
67 SimOnboardingMessage(stringResource(id = R.string.sim_onboarding_select_sim_msg))
68
69 isFinished.value = onboardingService.isSimSelectionFinished
70 for (subInfo in onboardingService.getSelectableSubscriptionInfoList()) {
71 var title = onboardingService.getSubscriptionInfoDisplayName(subInfo)
72 val phoneNumber = phoneNumber(subInfo)
73 var checked = rememberSaveable {
74 mutableStateOf(
75 onboardingService.getSelectedSubscriptionInfoList().contains(subInfo)
76 )
77 }
78 CheckboxPreference(remember {
79 object : CheckboxPreferenceModel {
80 override val title = title
81 override val summary: () -> String
82 get() = { phoneNumber.value ?: "" }
83 override val checked = { checked.value }
84 override val onCheckedChange = { newChecked: Boolean ->
85 checked.value = newChecked
86 if (newChecked) {
87 onboardingService.addItemForSelectedSim(subInfo)
88 } else {
89 onboardingService.removeItemForSelectedSim(subInfo)
90 }
91 isFinished.value = onboardingService.isSimSelectionFinished
92 }
93 override val changeable = {
94 subInfo.isActive
95 && (!isFinished.value || (isFinished.value && checked.value))
96 }
97 }
98 })
99 }
100 }
101