Skip to content

Commit

Permalink
Merge branch 'trunk' into feature/update-compile-sdk-33
Browse files Browse the repository at this point in the history
  • Loading branch information
irfano committed Mar 9, 2023
2 parents 01736fb + 6a51f21 commit 3143cc1
Show file tree
Hide file tree
Showing 33 changed files with 356 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ sealed class JetpackRemoteInstallViewState(
ERROR,
R.string.jetpack_installation_problem,
R.string.jetpack_installation_problem_message,
icon = R.drawable.img_illustration_info_outline_88dp,
icon = R.drawable.ic_warning,
buttonResource = R.string.install_jetpack_retry,
onClick = onClick
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ import org.wordpress.android.ui.blaze.BlazeUIModel
import org.wordpress.android.ui.blaze.BlazeUiState
import org.wordpress.android.ui.blaze.PageUIModel
import org.wordpress.android.ui.blaze.PostUIModel
import org.wordpress.android.ui.compose.components.Button
import org.wordpress.android.ui.compose.components.Drawable
import org.wordpress.android.ui.compose.components.ImageButton
import org.wordpress.android.ui.compose.components.buttons.Button
import org.wordpress.android.ui.compose.components.buttons.Drawable
import org.wordpress.android.ui.compose.components.buttons.ImageButton
import org.wordpress.android.ui.compose.components.MainTopAppBar
import org.wordpress.android.ui.compose.components.NavigationIcons
import org.wordpress.android.ui.compose.theme.AppColor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.wordpress.android.ui.compose.components

import androidx.compose.material.ContentAlpha
import androidx.compose.material.LocalContentAlpha
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider

/**
* Helper Composable to provide the [LocalContentAlpha] to the content. Prefer using the values below to match Material
* guidelines regarding content emphasis:
* - [ContentAlpha.high]
* - [ContentAlpha.medium]
* - [ContentAlpha.disabled]
*
* More info: https://developer.android.com/jetpack/compose/designsystems/material#emphasis
*/
@Composable
fun ContentAlphaProvider(
alpha: Float,
content: @Composable () -> Unit,
) {
CompositionLocalProvider(LocalContentAlpha provides alpha, content = content)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredWidthIn
import androidx.compose.material.ContentAlpha
import androidx.compose.material.LocalContentAlpha
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
Expand Down Expand Up @@ -74,9 +72,7 @@ fun EmptyContent(
}

// To match text color in ActionableEmptyView we need to provide the "medium" content alpha from Material
CompositionLocalProvider(
LocalContentAlpha provides ContentAlpha.medium,
) {
ContentAlphaProvider(ContentAlpha.medium) {
title?.let {
Text(
it,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.wordpress.android.ui.compose.components.buttons

import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

enum class ButtonSize(val height: Dp) {
NORMAL(height = Dp.Unspecified),
// this height matches the jetpack_bottom_sheet_button_height
LARGE(height = 52.dp)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.wordpress.android.ui.compose.components
package org.wordpress.android.ui.compose.components.buttons

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand All @@ -11,7 +11,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester.Companion.createRefs
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.wordpress.android.ui.compose.components
package org.wordpress.android.ui.compose.components.buttons

import android.content.res.Configuration
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
Expand All @@ -16,15 +17,28 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.wordpress.android.R
import org.wordpress.android.ui.compose.theme.AppColor
import org.wordpress.android.ui.compose.theme.AppTheme

@Composable
fun PrimaryButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
isInProgress: Boolean = false,
modifier: Modifier = Modifier
useDefaultMargins: Boolean = true,
buttonSize: ButtonSize = ButtonSize.NORMAL,
) {
var computedModifier: Modifier = modifier

if (useDefaultMargins) {
computedModifier = computedModifier
.padding(top = 20.dp, bottom = 10.dp)
.padding(horizontal = dimensionResource(R.dimen.jp_migration_buttons_padding_horizontal))
}

computedModifier = computedModifier.defaultMinSize(minHeight = buttonSize.height)

Button(
onClick = onClick,
enabled = !isInProgress,
Expand All @@ -33,11 +47,10 @@ fun PrimaryButton(
pressedElevation = 0.dp,
),
colors = ButtonDefaults.buttonColors(
contentColor = AppColor.White,
disabledBackgroundColor = colorResource(R.color.jetpack_green_70),
),
modifier = modifier
.padding(top = 20.dp, bottom = 10.dp)
.padding(horizontal = dimensionResource(R.dimen.jp_migration_buttons_padding_horizontal))
modifier = computedModifier
.fillMaxWidth(),
) {
if (isInProgress) {
Expand Down Expand Up @@ -69,3 +82,21 @@ private fun PrimaryButtonInProgressPreview() {
PrimaryButton(text = "Continue", onClick = {}, isInProgress = true)
}
}

@Preview
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun PrimaryButtonNoDefaultMarginsPreview() {
AppTheme {
PrimaryButton(text = "Continue", onClick = {}, useDefaultMargins = false)
}
}

@Preview
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun PrimaryButtonLargePreview() {
AppTheme {
PrimaryButton(text = "Continue", onClick = {}, buttonSize = ButtonSize.LARGE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.wordpress.android.ui.compose.components.buttons

import android.content.res.Configuration
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.wordpress.android.R
import org.wordpress.android.ui.compose.theme.AppTheme

@Composable
fun SecondaryButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
useDefaultMargins: Boolean = true,
buttonSize: ButtonSize = ButtonSize.NORMAL,
) {
var computedModifier: Modifier = modifier

if (useDefaultMargins) {
computedModifier = computedModifier
.padding(bottom = 10.dp)
.padding(horizontal = dimensionResource(R.dimen.jp_migration_buttons_padding_horizontal))
}

computedModifier = computedModifier.defaultMinSize(minHeight = buttonSize.height)

Button(
onClick = onClick,
enabled = enabled,
elevation = ButtonDefaults.elevation(
defaultElevation = 0.dp,
pressedElevation = 0.dp,
),
colors = ButtonDefaults.buttonColors(
backgroundColor = Color.Transparent,
contentColor = MaterialTheme.colors.primary,
disabledBackgroundColor = Color.Transparent,
disabledContentColor = MaterialTheme.colors.primary,
),
modifier = computedModifier.fillMaxWidth()
) {
Text(text = text)
}
}

@Preview
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun SecondaryButtonPreview() {
AppTheme {
SecondaryButton(text = "Continue", onClick = {})
}
}

@Preview
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun SecondaryButtonNoDefaultMarginsPreview() {
AppTheme {
SecondaryButton(text = "Continue", onClick = {}, useDefaultMargins = false)
}
}

@Preview
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
private fun SecondaryButtonLargePreview() {
AppTheme {
SecondaryButton(text = "Continue", onClick = {}, buttonSize = ButtonSize.LARGE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import org.wordpress.android.ui.compose.components.ContentAlphaProvider
import org.wordpress.android.util.extensions.isRtl
import org.wordpress.android.util.extensions.primaryLocale
import java.util.Locale

/**
* Utility function that returns a Composable function that wraps the [content] inside a [CompositionLocalProvider]
* Utility function that returns a Composable function that wraps the [content] inside a [ContentAlphaProvider]
* setting the [LocalContentAlpha] to 1f. Useful for using with some Material Composables that override that alpha
* Composition Local in a hard-coded fashion (e.g.: TopAppBar). This should not need to be used very often.
*/
fun withFullContentAlpha(content: @Composable () -> Unit): @Composable () -> Unit = {
CompositionLocalProvider(
LocalContentAlpha provides 1f,
ContentAlphaProvider(
1f,
content = content
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class JetpackFullPluginInstallActivity : AppCompatActivity() {
topBar = {
MainTopAppBar(
title = stringResource(toolbarTitle),
navigationIcon = NavigationIcons.BackIcon,
navigationIcon = NavigationIcons.CloseIcon.takeIf { uiState.showCloseButton },
onNavigationIconClick = viewModel::onDismissScreenClick
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sealed class UiState(
@StringRes val imageContentDescription: Int,
@StringRes val title: Int,
@StringRes val description: Int,
val showCloseButton: Boolean = true,
) {
data class Initial(
@StringRes val buttonText: Int
Expand All @@ -25,8 +26,9 @@ sealed class UiState(
toolbarTitle = R.string.jetpack,
image = R.drawable.ic_jetpack_logo_green_24dp,
imageContentDescription = R.string.jetpack_full_plugin_install_jp_logo_content_description,
title = R.string.jetpack_full_plugin_install_installing_title,
description = R.string.jetpack_full_plugin_install_installing_description,
title = R.string.jetpack_full_plugin_install_initial_title,
description = R.string.jetpack_full_plugin_install_initial_description,
showCloseButton = false,
)

data class Done(
Expand All @@ -37,14 +39,15 @@ sealed class UiState(
imageContentDescription = R.string.jetpack_full_plugin_install_jp_logo_content_description,
title = R.string.jetpack_full_plugin_install_done_title,
description = R.string.jetpack_full_plugin_install_done_description,
showCloseButton = false,
)

data class Error(
@StringRes val retryButtonText: Int,
@StringRes val contactSupportButtonText: Int,
) : UiState(
toolbarTitle = R.string.jetpack,
image = R.drawable.img_illustration_info_outline_88dp,
image = R.drawable.ic_warning,
imageContentDescription = R.string.jetpack_full_plugin_install_error_image_content_description,
title = R.string.jetpack_full_plugin_install_error_title,
description = R.string.jetpack_full_plugin_install_error_description,
Expand Down
Loading

0 comments on commit 3143cc1

Please sign in to comment.