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

Commit 65812195 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[Spa] Add SettingsIntro" into main

parents 7a3b8baa 678a39cd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.framework.theme.toMediumWeight
import com.android.settingslib.spa.framework.util.annotatedStringResource
import com.android.settingslib.spa.widget.ui.SettingsIntro

/** The widget model for [TopIntroPreference] widget. */
interface TopIntroPreferenceModel {
@@ -74,9 +75,8 @@ fun TopIntroPreference(model: TopIntroPreferenceModel) {
                    )
                    .animateContentSize()
        ) {
            Text(
            SettingsIntro(
                text = model.text,
                style = MaterialTheme.typography.bodyLarge,
                maxLines = if (expanded) MAX_LINE else MIN_LINE,
            )
            if (expanded) TopIntroAnnotatedText(model.labelText)
+2 −3
Original line number Diff line number Diff line
@@ -26,8 +26,7 @@ import com.android.settingslib.spa.framework.util.annotatedStringResource
fun AnnotatedText(@StringRes id: Int) {
    Text(
        text = annotatedStringResource(id),
        style = MaterialTheme.typography.bodyMedium.copy(
        color = MaterialTheme.colorScheme.onSurfaceVariant,
        ),
        style = MaterialTheme.typography.bodyMedium,
    )
}
+22 −5
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.framework.theme.SettingsOpacity.alphaForEnabled
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.framework.theme.toMediumWeight
import com.android.settingslib.spa.framework.theme.isSpaExpressiveEnabled

@Composable
fun SettingsTitle(
@@ -85,6 +84,7 @@ fun SettingsListItem(text: String, enabled: Boolean = true) {
    )
}

/** Settings body text displayed in secondary style. */
@Composable
fun SettingsBody(
    body: String,
@@ -95,10 +95,27 @@ fun SettingsBody(
        Text(
            text = body,
            modifier = Modifier.contentDescription(contentDescription),
            color = if (isSpaExpressiveEnabled) MaterialTheme.colorScheme.onSurface
            else MaterialTheme.colorScheme.onSurfaceVariant,
            style = if (isSpaExpressiveEnabled) MaterialTheme.typography.bodyLarge
            else MaterialTheme.typography.bodyMedium,
            color = MaterialTheme.colorScheme.onSurfaceVariant,
            style = MaterialTheme.typography.bodyMedium,
            overflow = TextOverflow.Ellipsis,
            maxLines = maxLines,
        )
    }
}

/** Settings introduction text. */
@Composable
fun SettingsIntro(
    text: String,
    contentDescription: String? = null,
    maxLines: Int = Int.MAX_VALUE,
) {
    if (text.isNotEmpty()) {
        Text(
            text = text,
            modifier = Modifier.contentDescription(contentDescription),
            color = MaterialTheme.colorScheme.onSurface,
            style = MaterialTheme.typography.bodyLarge,
            overflow = TextOverflow.Ellipsis,
            maxLines = maxLines,
        )
+20 −8
Original line number Diff line number Diff line
@@ -26,21 +26,33 @@ import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class TextTest {
    @get:Rule
    val composeTestRule = createComposeRule()
    @get:Rule val composeTestRule = createComposeRule()

    @Test
    fun settingsTitle() {
        composeTestRule.setContent {
            SettingsTitle(title = "myTitleValue")
        }
        composeTestRule.setContent { SettingsTitle(title = "myTitleValue") }

        composeTestRule.onNodeWithText("myTitleValue").assertIsDisplayed()
    }

    fun placeholderTitle() {
        composeTestRule.setContent {
            PlaceholderTitle(title = "myTitlePlaceholder")
    @Test
    fun settingsBody() {
        composeTestRule.setContent { SettingsBody("body") }

        composeTestRule.onNodeWithText("body").assertIsDisplayed()
    }

    @Test
    fun settingsIntro() {
        composeTestRule.setContent { SettingsIntro("intro") }

        composeTestRule.onNodeWithText("intro").assertIsDisplayed()
    }

    @Test
    fun placeholderTitle() {
        composeTestRule.setContent { PlaceholderTitle(title = "myTitlePlaceholder") }

        composeTestRule.onNodeWithText("myTitlePlaceholder").assertIsDisplayed()
    }
}