Improve the number on "Label SIM" page

Bug: 318310357
Test: manual - on Mobile Settings
Change-Id: I79149db550e8d84dd2104cbfd72e144dddeb81cd
diff --git a/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt b/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt
index 3b2d5ec..94e4a88 100644
--- a/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt
+++ b/src/com/android/settings/spa/network/SimOnboardingLabelSim.kt
@@ -16,6 +16,7 @@
 
 package com.android.settings.spa.network
 
+import android.telephony.SubscriptionInfo
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.padding
 import androidx.compose.material.icons.Icons
@@ -63,52 +64,55 @@
             cancelAction
         ),
     ) {
-        labelSimBody(onboardingService)
+        LabelSimBody(onboardingService)
     }
 }
 
 @Composable
-private fun labelSimBody(onboardingService: SimOnboardingService) {
+private fun LabelSimBody(onboardingService: SimOnboardingService) {
     Column(Modifier.padding(SettingsDimension.itemPadding)) {
         SettingsBody(stringResource(R.string.sim_onboarding_label_sim_msg))
     }
 
     for (subInfo in onboardingService.getSelectableSubscriptionInfoList()) {
-        var titleSimName by remember {
-            mutableStateOf(
-                onboardingService.getSubscriptionInfoDisplayName(subInfo)
-            )
-        }
-        var summaryNumber = subInfo.number
-            // TODO using the SubscriptionUtil.getFormattedPhoneNumber
-        val alertDialogPresenter = rememberAlertDialogPresenter(
-            confirmButton = AlertDialogButton(
-                stringResource(R.string.mobile_network_sim_name_rename)
-            ) {
-                onboardingService.addItemForRenaming(subInfo, titleSimName)
-            },
-            dismissButton = AlertDialogButton(stringResource(R.string.cancel)) {
-                titleSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
-            },
-            title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
-            text = {
-                Text(summaryNumber,
-                    modifier = Modifier.padding(bottom = SettingsDimension.itemPaddingVertical))
-                SettingsOutlinedTextField(
-                    value = titleSimName,
-                    label = stringResource(R.string.sim_onboarding_label_sim_dialog_label),
-                    enabled = true,
-                    shape = MaterialTheme.shapes.extraLarge
-                ) {
-                    titleSimName = it
-                }
-            },
-        )
-        Preference(object : PreferenceModel {
-            override val title = titleSimName
-            override val summary: () -> String
-                get() = { summaryNumber }
-            override val onClick = alertDialogPresenter::open
-        })
+        LabelSimPreference(onboardingService, subInfo)
     }
-}
\ No newline at end of file
+}
+
+@Composable
+private fun LabelSimPreference(
+    onboardingService: SimOnboardingService,
+    subInfo: SubscriptionInfo,
+) {
+    var titleSimName by remember {
+        mutableStateOf(onboardingService.getSubscriptionInfoDisplayName(subInfo))
+    }
+    val phoneNumber = phoneNumber(subInfo)
+    val alertDialogPresenter = rememberAlertDialogPresenter(
+        confirmButton = AlertDialogButton(stringResource(R.string.mobile_network_sim_name_rename)) {
+            onboardingService.addItemForRenaming(subInfo, titleSimName)
+        },
+        dismissButton = AlertDialogButton(stringResource(R.string.cancel)) {
+            titleSimName = onboardingService.getSubscriptionInfoDisplayName(subInfo)
+        },
+        title = stringResource(R.string.sim_onboarding_label_sim_dialog_title),
+        text = {
+            Text(
+                phoneNumber.value ?: "",
+                modifier = Modifier.padding(bottom = SettingsDimension.itemPaddingVertical)
+            )
+            SettingsOutlinedTextField(
+                value = titleSimName,
+                label = stringResource(R.string.sim_onboarding_label_sim_dialog_label),
+                shape = MaterialTheme.shapes.extraLarge
+            ) {
+                titleSimName = it
+            }
+        },
+    )
+    Preference(object : PreferenceModel {
+        override val title = titleSimName
+        override val summary = { phoneNumber.value ?: "" }
+        override val onClick = alertDialogPresenter::open
+    })
+}
diff --git a/src/com/android/settings/spa/network/SimsSection.kt b/src/com/android/settings/spa/network/SimsSection.kt
index 9e4cf9f..0b638c4 100644
--- a/src/com/android/settings/spa/network/SimsSection.kt
+++ b/src/com/android/settings/spa/network/SimsSection.kt
@@ -25,6 +25,7 @@
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.outlined.Add
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.State
 import androidx.compose.runtime.remember
 import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.stringResource
@@ -58,9 +59,7 @@
     val checked = remember(subInfo.subscriptionId) {
         context.isSubscriptionEnabledFlow(subInfo.subscriptionId)
     }.collectAsStateWithLifecycle(initialValue = false)
-    val phoneNumber = remember(subInfo) {
-        context.phoneNumberFlow(subInfo)
-    }.collectAsStateWithLifecycle(initialValue = null)
+    val phoneNumber = phoneNumber(subInfo)
     RestrictedTwoTargetSwitchPreference(
         model = object : SwitchPreferenceModel {
             override val title = subInfo.displayName.toString()
@@ -81,6 +80,14 @@
 }
 
 @Composable
+fun phoneNumber(subInfo: SubscriptionInfo): State<String?> {
+    val context = LocalContext.current
+    return remember(subInfo) {
+        context.phoneNumberFlow(subInfo)
+    }.collectAsStateWithLifecycle(initialValue = null)
+}
+
+@Composable
 private fun AddSim() {
     val context = LocalContext.current
     if (remember { MobileNetworkUtils.showEuiccSettings(context) }) {