• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.about
18 
19 import android.content.Context
20 import androidx.compose.material3.Text
21 import androidx.compose.runtime.Composable
22 import androidx.compose.runtime.remember
23 import androidx.compose.ui.platform.LocalContext
24 import androidx.compose.ui.res.stringResource
25 import com.android.settings.R
26 import com.android.settings.deviceinfo.DeviceNamePreferenceController
27 import com.android.settingslib.spa.widget.dialog.AlertDialogButton
28 import com.android.settingslib.spa.widget.dialog.rememberAlertDialogPresenter
29 import com.android.settingslib.spa.widget.preference.Preference
30 import com.android.settingslib.spa.widget.preference.PreferenceModel
31 
32 object DeviceNamePreference {
33 
34     @Composable
EntryItemnull35     fun EntryItem() {
36         val context = LocalContext.current
37         val deviceNamePresenter = remember { DeviceNamePresenter(context) }
38         // TODO: Instead of a AlertDialog, it should be a dialog that accepts text input.
39         val dialogPresenter = rememberAlertDialogPresenter(
40             confirmButton = AlertDialogButton(
41                 stringResource(R.string.okay), onClick = DeviceNamePreference::confirmChange
42             ),
43             dismissButton = AlertDialogButton(stringResource(R.string.cancel)),
44             title = stringResource(R.string.my_device_info_device_name_preference_title),
45             text = { Text(deviceNamePresenter.deviceName) },
46         )
47         Preference(object : PreferenceModel {
48             override val title =
49                 stringResource(R.string.my_device_info_device_name_preference_title)
50             override val summary = { deviceNamePresenter.deviceName }
51             override val onClick = dialogPresenter::open
52         })
53 
54     }
55 
confirmChangenull56     private fun confirmChange() {
57         // TODO: Save the change of the device name.
58     }
59 }
60 
61 class DeviceNamePresenter(val context: Context) {
62     private val deviceNamePreferenceController =
63         DeviceNamePreferenceController(context, "unused_key")
64 
65     val deviceName: String get() = deviceNamePreferenceController.summary.toString()
66 }
67