Merge "Fine tune App Info and App Buttons"
This commit is contained in:
@@ -40,6 +40,9 @@ object SettingsDimension {
|
||||
/** The size when app icon is displayed in App info page. */
|
||||
val appIconInfoSize = 48.dp
|
||||
|
||||
/** The [PaddingValues] for buttons. */
|
||||
val buttonPadding = PaddingValues(horizontal = itemPaddingEnd, vertical = 12.dp)
|
||||
|
||||
/** The sizes info of illustration widget. */
|
||||
val illustrationMaxWidth = 412.dp
|
||||
val illustrationMaxHeight = 300.dp
|
||||
|
||||
@@ -142,3 +142,7 @@ internal fun rememberSettingsTypography(): Typography {
|
||||
val settingsFontFamily = rememberSettingsFontFamily()
|
||||
return remember { SettingsTypography(settingsFontFamily).typography }
|
||||
}
|
||||
|
||||
/** Creates a new [TextStyle] which font weight set to medium. */
|
||||
internal fun TextStyle.toMediumWeight() =
|
||||
copy(fontWeight = FontWeight.Medium, letterSpacing = 0.01.em)
|
||||
|
||||
@@ -64,7 +64,7 @@ data class ActionButton(
|
||||
fun ActionButtons(actionButtons: List<ActionButton>) {
|
||||
Row(
|
||||
Modifier
|
||||
.padding(SettingsDimension.itemPaddingVertical)
|
||||
.padding(SettingsDimension.buttonPadding)
|
||||
.clip(SettingsShape.CornerLarge)
|
||||
.height(IntrinsicSize.Min)
|
||||
) {
|
||||
@@ -94,9 +94,7 @@ private fun RowScope.ActionButton(actionButton: ActionButton) {
|
||||
),
|
||||
contentPadding = PaddingValues(horizontal = 4.dp, vertical = 20.dp),
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Icon(
|
||||
imageVector = actionButton.imageVector,
|
||||
contentDescription = null,
|
||||
@@ -105,7 +103,7 @@ private fun RowScope.ActionButton(actionButton: ActionButton) {
|
||||
Spacer(Modifier.height(4.dp))
|
||||
Text(
|
||||
text = actionButton.text,
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,18 +30,24 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.android.settingslib.spa.framework.theme.SettingsTheme
|
||||
import com.android.settingslib.spa.framework.theme.toMediumWeight
|
||||
|
||||
@Composable
|
||||
fun SettingsTitle(title: State<String>) {
|
||||
SettingsTitle(title.value)
|
||||
fun SettingsTitle(title: State<String>, useMediumWeight: Boolean = false) {
|
||||
SettingsTitle(title.value, useMediumWeight)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SettingsTitle(title: String) {
|
||||
fun SettingsTitle(title: String, useMediumWeight: Boolean = false) {
|
||||
Text(
|
||||
text = title,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
style = MaterialTheme.typography.titleMedium.let {
|
||||
when (useMediumWeight) {
|
||||
true -> it.toMediumWeight()
|
||||
else -> it
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -101,5 +101,5 @@ internal fun AppIcon(app: ApplicationInfo, size: Dp) {
|
||||
@Composable
|
||||
internal fun AppLabel(app: ApplicationInfo) {
|
||||
val appRepository = rememberAppRepository()
|
||||
SettingsTitle(appRepository.produceLabel(app))
|
||||
SettingsTitle(title = appRepository.produceLabel(app), useMediumWeight = true)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settingslib.spaprivileged.template.app
|
||||
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class AppInfoTest {
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
private var context: Context = ApplicationProvider.getApplicationContext()
|
||||
|
||||
@Test
|
||||
fun appInfoLabel_isDisplayed() {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
applicationInfo = APP
|
||||
}
|
||||
val appInfoProvider = AppInfoProvider(packageInfo)
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
appInfoProvider.AppInfo()
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(LABEL).assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appInfoVersion_whenDisplayVersionIsFalse() {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
applicationInfo = APP
|
||||
versionName = VERSION_NAME
|
||||
}
|
||||
val appInfoProvider = AppInfoProvider(packageInfo)
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
appInfoProvider.AppInfo(displayVersion = false)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(VERSION_NAME).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun appInfoVersion_whenDisplayVersionIsTrue() {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
applicationInfo = APP
|
||||
versionName = VERSION_NAME
|
||||
}
|
||||
val appInfoProvider = AppInfoProvider(packageInfo)
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
appInfoProvider.AppInfo(displayVersion = true)
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText(VERSION_NAME).assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun footerAppVersion_versionIsDisplayed() {
|
||||
val packageInfo = PackageInfo().apply {
|
||||
applicationInfo = APP
|
||||
versionName = VERSION_NAME
|
||||
}
|
||||
val appInfoProvider = AppInfoProvider(packageInfo)
|
||||
|
||||
composeTestRule.setContent {
|
||||
CompositionLocalProvider(LocalContext provides context) {
|
||||
appInfoProvider.FooterAppVersion()
|
||||
}
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithText("version $VERSION_NAME").assertIsDisplayed()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val LABEL = "Label"
|
||||
const val VERSION_NAME = "VersionName"
|
||||
val APP = object : ApplicationInfo() {
|
||||
override fun loadLabel(pm: PackageManager) = LABEL
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user