Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bfd072cc authored by songferngwang's avatar songferngwang Committed by SongFerng Wang
Browse files

Add the summary at item in the ListPreference

Bug: 318310357
Bug: 298898436
Bug: 298891941
Test: Build pass
atest ListPreferenceTest

Change-Id: I777a96faf346828720d5d6239fbd8f602a2aeb8d
parent 992fc262
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -37,11 +37,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.widget.dialog.SettingsDialog
import com.android.settingslib.spa.widget.ui.SettingsBody
import com.android.settingslib.spa.widget.ui.SettingsDialogItem

data class ListPreferenceOption(
    val id: Int,
    val text: String,
    val summary: String = String()
)

/**
@@ -129,6 +131,14 @@ private fun Radio(
    ) {
        RadioButton(selected = selected, onClick = null, enabled = enabled)
        Spacer(modifier = Modifier.width(SettingsDimension.itemPaddingEnd))
        Column {
            SettingsDialogItem(text = option.text, enabled = enabled)
            if (option.summary != String()) {
                SettingsBody(
                    body = option.summary,
                    maxLines = 1
                )
            }
        }
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -122,6 +122,26 @@ class ListPreferenceTest {
        composeTestRule.onDialogText(TITLE).assertIsDisplayed()
    }

    @Test
    fun click_optionsNotEmptyAndItemHasSummary_itemShowSummary() {
        composeTestRule.setContent {
            ListPreference(remember {
                object : ListPreferenceModel {
                    override val title = TITLE
                    override val options =
                        listOf(ListPreferenceOption(id = 1, text = "A", summary = "A_Summary"))
                    override val selectedId = mutableIntStateOf(1)
                    override val onIdSelected: (Int) -> Unit = {}
                }
            })
        }

        composeTestRule.onNodeWithText(TITLE).performClick()

        composeTestRule.onDialogText(TITLE).assertIsDisplayed()
        composeTestRule.onNodeWithText("A_Summary").assertIsDisplayed()
    }

    @Test
    fun select() {
        val selectedId = mutableIntStateOf(1)