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

Commit bafc6b7a authored by SongFerng Wang's avatar SongFerng Wang Committed by Android (Google) Code Review
Browse files

Merge "Add the summary at item in the ListPreference" into main

parents 0136da98 bfd072cc
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)