From 75502edb217537efa6fbdfa7bcafcbc5f3289ed4 Mon Sep 17 00:00:00 2001 From: cooltey Date: Mon, 13 Jan 2025 16:20:14 -0800 Subject: [PATCH 01/11] Convert XML styles to Compose --- .../org/wikipedia/compose/ComposeStyles.kt | 76 +++++++++++++++++++ .../compose/styles/WikipediaStyle.kt | 55 ++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 app/src/main/java/org/wikipedia/compose/ComposeStyles.kt create mode 100644 app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt diff --git a/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt b/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt new file mode 100644 index 00000000000..a06c3deae95 --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt @@ -0,0 +1,76 @@ +package org.wikipedia.compose + +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +object ComposeStyles { + + val H1 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 24.sp, + lineHeight = 32.sp + ) + + val H1_AppBar = H1.copy(lineHeight = 24.sp) + + val H1_Article = H1.copy( + fontFamily = FontFamily.Serif, + fontWeight = FontWeight.Normal + ) + + val H2 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 20.sp, + lineHeight = 28.sp + ) + + val H3 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 16.sp, + lineHeight = 24.sp + ) + + val H3_Button = H3.copy( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium + ) + + val H3_Article = H3.copy( + fontFamily = FontFamily.Serif, + fontWeight = FontWeight.Normal + ) + + + val P = H3.copy(fontWeight = FontWeight.Normal) + + val P_Article = P.copy(lineHeight = 28.sp) + + val H4 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 14.sp, + lineHeight = 24.sp + ) + + val List = H4.copy( + fontWeight = FontWeight.Normal + ) + + val Chip = H4.copy( + fontWeight = FontWeight.Medium + ) + + val H5 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 12.sp, + lineHeight = 18.sp + ) + + val Small = H5.copy(fontWeight = FontWeight.Medium) +} diff --git a/app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt b/app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt new file mode 100644 index 00000000000..3ecadd184d1 --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt @@ -0,0 +1,55 @@ +package org.wikipedia.compose.styles + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Snackbar +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.wikipedia.compose.ComposeStyles +import org.wikipedia.compose.theme.WikipediaTheme + +object WikipediaStyle { + + @Composable + fun Snackbar( + message: String, + actionLabel: String? = null, + onActionClick: (() -> Unit)? = null, + modifier: Modifier = Modifier + ) { + Snackbar( + action = { + if (actionLabel != null && onActionClick != null) { + TextButton( + onClick = onActionClick, + modifier = Modifier.padding(end = 8.dp) + ) { + Text( + text = actionLabel, + style = ComposeStyles.H3_Button.copy( + color = WikipediaTheme.colors.progressiveColor + ) + ) + } + } + }, + modifier = modifier.padding(16.dp) + ) { + Text( + text = message, + style = ComposeStyles.H3_Button.copy( + color = WikipediaTheme.colors.primaryColor, + letterSpacing = 0.sp + ), + maxLines = 10, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(top = 0.dp, bottom = 0.dp, start = 0.dp, end = 8.dp) + ) + } + } +} From 88a993023c114ca19c315c35fa8eb37713763c9a Mon Sep 17 00:00:00 2001 From: cooltey Date: Mon, 13 Jan 2025 16:29:17 -0800 Subject: [PATCH 02/11] Lint --- app/src/main/java/org/wikipedia/compose/ComposeStyles.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt b/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt index a06c3deae95..663e64a66cd 100644 --- a/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt +++ b/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt @@ -45,7 +45,6 @@ object ComposeStyles { fontWeight = FontWeight.Normal ) - val P = H3.copy(fontWeight = FontWeight.Normal) val P_Article = P.copy(lineHeight = 28.sp) From d3d83555f5f1e1fffbc0cda0be90f1a70732f1de Mon Sep 17 00:00:00 2001 From: cooltey Date: Tue, 14 Jan 2025 16:16:25 -0800 Subject: [PATCH 03/11] Code review comments --- .../org/wikipedia/compose/ComposeStyles.kt | 75 ---------------- .../WikiSnackbar.kt} | 9 +- .../wikipedia/compose/theme/WikipediaTheme.kt | 7 +- .../compose/theme/WikipediaTypography.kt | 90 +++++++++++++++++++ 4 files changed, 100 insertions(+), 81 deletions(-) delete mode 100644 app/src/main/java/org/wikipedia/compose/ComposeStyles.kt rename app/src/main/java/org/wikipedia/compose/{styles/WikipediaStyle.kt => components/WikiSnackbar.kt} (87%) create mode 100644 app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt diff --git a/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt b/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt deleted file mode 100644 index 663e64a66cd..00000000000 --- a/app/src/main/java/org/wikipedia/compose/ComposeStyles.kt +++ /dev/null @@ -1,75 +0,0 @@ -package org.wikipedia.compose - -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.unit.sp - -object ComposeStyles { - - val H1 = TextStyle( - fontFamily = FontFamily.SansSerif, - fontWeight = FontWeight.Bold, - fontSize = 24.sp, - lineHeight = 32.sp - ) - - val H1_AppBar = H1.copy(lineHeight = 24.sp) - - val H1_Article = H1.copy( - fontFamily = FontFamily.Serif, - fontWeight = FontWeight.Normal - ) - - val H2 = TextStyle( - fontFamily = FontFamily.SansSerif, - fontWeight = FontWeight.Bold, - fontSize = 20.sp, - lineHeight = 28.sp - ) - - val H3 = TextStyle( - fontFamily = FontFamily.SansSerif, - fontWeight = FontWeight.Bold, - fontSize = 16.sp, - lineHeight = 24.sp - ) - - val H3_Button = H3.copy( - fontFamily = FontFamily.SansSerif, - fontWeight = FontWeight.Medium - ) - - val H3_Article = H3.copy( - fontFamily = FontFamily.Serif, - fontWeight = FontWeight.Normal - ) - - val P = H3.copy(fontWeight = FontWeight.Normal) - - val P_Article = P.copy(lineHeight = 28.sp) - - val H4 = TextStyle( - fontFamily = FontFamily.SansSerif, - fontWeight = FontWeight.Bold, - fontSize = 14.sp, - lineHeight = 24.sp - ) - - val List = H4.copy( - fontWeight = FontWeight.Normal - ) - - val Chip = H4.copy( - fontWeight = FontWeight.Medium - ) - - val H5 = TextStyle( - fontFamily = FontFamily.SansSerif, - fontWeight = FontWeight.Bold, - fontSize = 12.sp, - lineHeight = 18.sp - ) - - val Small = H5.copy(fontWeight = FontWeight.Medium) -} diff --git a/app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt b/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt similarity index 87% rename from app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt rename to app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt index 3ecadd184d1..15e6b2aa8a3 100644 --- a/app/src/main/java/org/wikipedia/compose/styles/WikipediaStyle.kt +++ b/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt @@ -1,4 +1,4 @@ -package org.wikipedia.compose.styles +package org.wikipedia.compose.components import androidx.compose.foundation.layout.padding import androidx.compose.material3.Snackbar @@ -9,10 +9,9 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import org.wikipedia.compose.ComposeStyles import org.wikipedia.compose.theme.WikipediaTheme -object WikipediaStyle { +class WikiSnackbar { @Composable fun Snackbar( @@ -30,7 +29,7 @@ object WikipediaStyle { ) { Text( text = actionLabel, - style = ComposeStyles.H3_Button.copy( + style = WikipediaTheme.typography.h3.copy( color = WikipediaTheme.colors.progressiveColor ) ) @@ -41,7 +40,7 @@ object WikipediaStyle { ) { Text( text = message, - style = ComposeStyles.H3_Button.copy( + style = WikipediaTheme.typography.h3.copy( color = WikipediaTheme.colors.primaryColor, letterSpacing = 0.sp ), diff --git a/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt index d1aa7fb0078..5f700e87bd2 100644 --- a/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt +++ b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTheme.kt @@ -22,7 +22,8 @@ fun BaseTheme( } CompositionLocalProvider( - LocalWikipediaColor provides wikipediaColorSystem + LocalWikipediaColor provides wikipediaColorSystem, + LocalWikipediaTypography provides Typography ) { content() } @@ -32,4 +33,8 @@ object WikipediaTheme { val colors: WikipediaColor @Composable get() = LocalWikipediaColor.current + + val typography: WikipediaTypography + @Composable + get() = LocalWikipediaTypography.current } diff --git a/app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt new file mode 100644 index 00000000000..9eb32d4a6a5 --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/theme/WikipediaTypography.kt @@ -0,0 +1,90 @@ +package org.wikipedia.compose.theme + +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +@Immutable +data class WikipediaTypography( + val h1: TextStyle = TextStyle(), + val h2: TextStyle = TextStyle(), + val h3: TextStyle = TextStyle(), + val h4: TextStyle = TextStyle(), + val h5: TextStyle = TextStyle(), + val p: TextStyle = TextStyle(), + val button: TextStyle = TextStyle(), + val article: TextStyle = TextStyle(), + val list: TextStyle = TextStyle(), + val chip: TextStyle = TextStyle(), + val small: TextStyle = TextStyle() +) + +val LocalWikipediaTypography = staticCompositionLocalOf { + WikipediaTypography() +} + +val Typography = WikipediaTypography( + h1 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 24.sp, + lineHeight = 32.sp + ), + h2 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 20.sp, + lineHeight = 28.sp + ), + h3 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 16.sp, + lineHeight = 24.sp + ), + h4 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 14.sp, + lineHeight = 24.sp + ), + h5 = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Bold, + fontSize = 12.sp, + lineHeight = 18.sp + ), + button = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium, + fontSize = 16.sp, + lineHeight = 24.sp + ), + article = TextStyle( + fontFamily = FontFamily.Serif, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp + ), + list = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Normal, + fontSize = 14.sp, + lineHeight = 24.sp + ), + chip = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium, + fontSize = 14.sp, + lineHeight = 24.sp + ), + small = TextStyle( + fontFamily = FontFamily.SansSerif, + fontWeight = FontWeight.Medium, + fontSize = 12.sp, + lineHeight = 18.sp + ) +) From 79ae7d05877bc49690f64b114b97c8099cf3ecdf Mon Sep 17 00:00:00 2001 From: cooltey Date: Tue, 14 Jan 2025 17:13:00 -0800 Subject: [PATCH 04/11] Adding button styles --- .../compose/components/WikiButtons.kt | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt new file mode 100644 index 00000000000..6f09300435b --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt @@ -0,0 +1,168 @@ +package org.wikipedia.compose.components + +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.wikipedia.compose.theme.WikipediaTheme + +class WikiButtons { + + @Composable + fun Button( + text: String, + backgroundColor: Color = WikipediaTheme.colors.progressiveColor, + contentColor: Color = WikipediaTheme.colors.paperColor, + icon: @Composable (() -> Unit)? = null, + onClick: () -> Unit, + modifier: Modifier = Modifier + ) { + Button( + onClick = onClick, + modifier = modifier, + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor, + ), + contentPadding = ButtonDefaults.ContentPadding + ) { + icon?.invoke() + Text( + text = text, + fontSize = 16.sp, + modifier = Modifier.padding(start = 8.dp, end = 8.dp) + ) + } + } + + @Composable + fun TextButton( + text: String, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + icon: @Composable (() -> Unit)? = null, + onClick: () -> Unit, + modifier: Modifier = Modifier, + ) { + Button( + onClick = onClick, + modifier = modifier, + colors = ButtonDefaults.buttonColors( + containerColor = Color.Transparent, + contentColor = contentColor + ), + elevation = ButtonDefaults.elevatedButtonElevation(0.dp) + ) { + icon?.invoke() + Text( + text = text, + fontSize = 16.sp + ) + } + } + + @Composable + fun OutlineButton( + text: String, + backgroundColor: Color = WikipediaTheme.colors.paperColor, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + borderColor: Color = WikipediaTheme.colors.borderColor, + cornerRadius: Int = 8, + strokeWidth: Int = 1, + icon: @Composable (() -> Unit)? = null, + onClick: () -> Unit, + modifier: Modifier = Modifier + ) { + Button( + onClick = onClick, + modifier = modifier.border( + width = strokeWidth.dp, + color = borderColor, + shape = RoundedCornerShape(cornerRadius.dp) + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ) + ) { + icon?.invoke() + Text( + text = text, + fontSize = 16.sp + ) + } + } + + @Composable + fun SmallOutlineButton( + text: String, + backgroundColor: Color = WikipediaTheme.colors.paperColor, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + borderColor: Color = WikipediaTheme.colors.borderColor, + cornerRadius: Int = 16, + icon: @Composable (() -> Unit)? = null, + onClick: () -> Unit, + modifier: Modifier = Modifier + ) { + Button( + onClick = onClick, + modifier = modifier.border( + width = 1.dp, + color = borderColor, + shape = RoundedCornerShape(cornerRadius.dp) + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ), + contentPadding = PaddingValues(horizontal = 16.dp) + ) { + icon?.invoke() + Text( + text = text, + fontSize = 16.sp + ) + } + } + + @Composable + fun ThemeColorCircularButton( + text: String = "Aa", + backgroundColor: Color, + contentColor: Color, + borderColor: Color, + onClick: () -> Unit, + modifier: Modifier = Modifier + ) { + Button( + onClick = onClick, + modifier = modifier.size(40.dp).border( + width = 1.dp, + color = borderColor, + shape = CircleShape + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ), + contentPadding = PaddingValues(0.dp) + ) { + Text( + text = text, + style = WikipediaTheme.typography.h3.copy( + color = WikipediaTheme.colors.primaryColor, + letterSpacing = 0.sp + ) + ) + } + } +} From a993d795f63cdbccb9a6bc6dec231aa233c97030 Mon Sep 17 00:00:00 2001 From: cooltey Date: Wed, 15 Jan 2025 11:23:20 -0800 Subject: [PATCH 05/11] Code review comments --- .../compose/components/WikiButtons.kt | 245 ++++++++---------- .../compose/components/WikiSnackbar.kt | 71 +++-- 2 files changed, 144 insertions(+), 172 deletions(-) diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt index 6f09300435b..bed3d6da63d 100644 --- a/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt +++ b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt @@ -2,7 +2,6 @@ package org.wikipedia.compose.components import androidx.compose.foundation.border import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape @@ -16,153 +15,129 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import org.wikipedia.compose.theme.WikipediaTheme -class WikiButtons { - - @Composable - fun Button( - text: String, - backgroundColor: Color = WikipediaTheme.colors.progressiveColor, - contentColor: Color = WikipediaTheme.colors.paperColor, - icon: @Composable (() -> Unit)? = null, - onClick: () -> Unit, - modifier: Modifier = Modifier +@Composable +fun Button( + onClick: () -> Unit, + modifier: Modifier = Modifier, + backgroundColor: Color = WikipediaTheme.colors.progressiveColor, + contentColor: Color = WikipediaTheme.colors.paperColor, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier, + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor, + ), + contentPadding = ButtonDefaults.ContentPadding ) { - Button( - onClick = onClick, - modifier = modifier, - colors = ButtonDefaults.buttonColors( - containerColor = backgroundColor, - contentColor = contentColor, - ), - contentPadding = ButtonDefaults.ContentPadding - ) { - icon?.invoke() - Text( - text = text, - fontSize = 16.sp, - modifier = Modifier.padding(start = 8.dp, end = 8.dp) - ) - } + content() } +} - @Composable - fun TextButton( - text: String, - contentColor: Color = WikipediaTheme.colors.progressiveColor, - icon: @Composable (() -> Unit)? = null, - onClick: () -> Unit, - modifier: Modifier = Modifier, +@Composable +fun TextButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier, + colors = ButtonDefaults.buttonColors( + containerColor = Color.Transparent, + contentColor = contentColor + ), + elevation = ButtonDefaults.elevatedButtonElevation(0.dp) ) { - Button( - onClick = onClick, - modifier = modifier, - colors = ButtonDefaults.buttonColors( - containerColor = Color.Transparent, - contentColor = contentColor - ), - elevation = ButtonDefaults.elevatedButtonElevation(0.dp) - ) { - icon?.invoke() - Text( - text = text, - fontSize = 16.sp - ) - } + content() } +} - @Composable - fun OutlineButton( - text: String, - backgroundColor: Color = WikipediaTheme.colors.paperColor, - contentColor: Color = WikipediaTheme.colors.progressiveColor, - borderColor: Color = WikipediaTheme.colors.borderColor, - cornerRadius: Int = 8, - strokeWidth: Int = 1, - icon: @Composable (() -> Unit)? = null, - onClick: () -> Unit, - modifier: Modifier = Modifier +@Composable +fun OutlineButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + backgroundColor: Color = WikipediaTheme.colors.paperColor, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + borderColor: Color = WikipediaTheme.colors.borderColor, + cornerRadius: Int = 8, + strokeWidth: Int = 1, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier.border( + width = strokeWidth.dp, + color = borderColor, + shape = RoundedCornerShape(cornerRadius.dp) + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ) ) { - Button( - onClick = onClick, - modifier = modifier.border( - width = strokeWidth.dp, - color = borderColor, - shape = RoundedCornerShape(cornerRadius.dp) - ), - colors = ButtonDefaults.buttonColors( - containerColor = backgroundColor, - contentColor = contentColor - ) - ) { - icon?.invoke() - Text( - text = text, - fontSize = 16.sp - ) - } + content() } +} - @Composable - fun SmallOutlineButton( - text: String, - backgroundColor: Color = WikipediaTheme.colors.paperColor, - contentColor: Color = WikipediaTheme.colors.progressiveColor, - borderColor: Color = WikipediaTheme.colors.borderColor, - cornerRadius: Int = 16, - icon: @Composable (() -> Unit)? = null, - onClick: () -> Unit, - modifier: Modifier = Modifier +@Composable +fun SmallOutlineButton( + onClick: () -> Unit, + modifier: Modifier = Modifier, + backgroundColor: Color = WikipediaTheme.colors.paperColor, + contentColor: Color = WikipediaTheme.colors.progressiveColor, + borderColor: Color = WikipediaTheme.colors.borderColor, + cornerRadius: Int = 16, + content: @Composable (() -> Unit) +) { + Button( + onClick = onClick, + modifier = modifier.border( + width = 1.dp, + color = borderColor, + shape = RoundedCornerShape(cornerRadius.dp) + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ), + contentPadding = PaddingValues(horizontal = 16.dp) ) { - Button( - onClick = onClick, - modifier = modifier.border( - width = 1.dp, - color = borderColor, - shape = RoundedCornerShape(cornerRadius.dp) - ), - colors = ButtonDefaults.buttonColors( - containerColor = backgroundColor, - contentColor = contentColor - ), - contentPadding = PaddingValues(horizontal = 16.dp) - ) { - icon?.invoke() - Text( - text = text, - fontSize = 16.sp - ) - } + content() } +} - @Composable - fun ThemeColorCircularButton( - text: String = "Aa", - backgroundColor: Color, - contentColor: Color, - borderColor: Color, - onClick: () -> Unit, - modifier: Modifier = Modifier +@Composable +fun ThemeColorCircularButton( + onClick: () -> Unit, + text: String = "Aa", + modifier: Modifier = Modifier, + backgroundColor: Color, + contentColor: Color, + borderColor: Color +) { + Button( + onClick = onClick, + modifier = modifier.size(40.dp).border( + width = 1.dp, + color = borderColor, + shape = CircleShape + ), + colors = ButtonDefaults.buttonColors( + containerColor = backgroundColor, + contentColor = contentColor + ), + contentPadding = PaddingValues(0.dp) ) { - Button( - onClick = onClick, - modifier = modifier.size(40.dp).border( - width = 1.dp, - color = borderColor, - shape = CircleShape - ), - colors = ButtonDefaults.buttonColors( - containerColor = backgroundColor, - contentColor = contentColor - ), - contentPadding = PaddingValues(0.dp) - ) { - Text( - text = text, - style = WikipediaTheme.typography.h3.copy( - color = WikipediaTheme.colors.primaryColor, - letterSpacing = 0.sp - ) + Text( + text = text, + style = WikipediaTheme.typography.h3.copy( + color = WikipediaTheme.colors.primaryColor, + letterSpacing = 0.sp ) - } + ) } } diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt b/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt index 15e6b2aa8a3..a59f9ac613a 100644 --- a/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt +++ b/app/src/main/java/org/wikipedia/compose/components/WikiSnackbar.kt @@ -11,44 +11,41 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import org.wikipedia.compose.theme.WikipediaTheme -class WikiSnackbar { - - @Composable - fun Snackbar( - message: String, - actionLabel: String? = null, - onActionClick: (() -> Unit)? = null, - modifier: Modifier = Modifier - ) { - Snackbar( - action = { - if (actionLabel != null && onActionClick != null) { - TextButton( - onClick = onActionClick, - modifier = Modifier.padding(end = 8.dp) - ) { - Text( - text = actionLabel, - style = WikipediaTheme.typography.h3.copy( - color = WikipediaTheme.colors.progressiveColor - ) +@Composable +fun Snackbar( + message: String, + modifier: Modifier = Modifier, + actionLabel: String? = null, + onActionClick: (() -> Unit)? = null, +) { + Snackbar( + action = { + if (actionLabel != null && onActionClick != null) { + TextButton( + onClick = onActionClick, + modifier = Modifier.padding(end = 8.dp) + ) { + Text( + text = actionLabel, + style = WikipediaTheme.typography.h3.copy( + color = WikipediaTheme.colors.progressiveColor ) - } + ) } - }, - modifier = modifier.padding(16.dp) - ) { - Text( - text = message, - style = WikipediaTheme.typography.h3.copy( - color = WikipediaTheme.colors.primaryColor, - letterSpacing = 0.sp - ), - maxLines = 10, - overflow = TextOverflow.Ellipsis, - modifier = Modifier - .padding(top = 0.dp, bottom = 0.dp, start = 0.dp, end = 8.dp) - ) - } + } + }, + modifier = modifier.padding(16.dp) + ) { + Text( + text = message, + style = WikipediaTheme.typography.h3.copy( + color = WikipediaTheme.colors.primaryColor, + letterSpacing = 0.sp + ), + maxLines = 10, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(top = 0.dp, bottom = 0.dp, start = 0.dp, end = 8.dp) + ) } } From 139f88f484a507c4dd25e03772556881a8617033 Mon Sep 17 00:00:00 2001 From: cooltey Date: Wed, 15 Jan 2025 15:36:33 -0800 Subject: [PATCH 06/11] Add TopAppBar and remove unused style --- .../compose/components/WikiActionBar.kt | 54 +++++++++++++++++++ .../compose/components/WikiButtons.kt | 2 +- app/src/main/res/values/styles.xml | 13 ----- 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 app/src/main/java/org/wikipedia/compose/components/WikiActionBar.kt diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiActionBar.kt b/app/src/main/java/org/wikipedia/compose/components/WikiActionBar.kt new file mode 100644 index 00000000000..6a218ded66e --- /dev/null +++ b/app/src/main/java/org/wikipedia/compose/components/WikiActionBar.kt @@ -0,0 +1,54 @@ +package org.wikipedia.compose.components + +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.ArrowBack +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import org.wikipedia.compose.theme.WikipediaTheme + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun WikiTopAppBar( + title: String, + onNavigationClick: (() -> Unit), + modifier: Modifier = Modifier +) { + val navigationIcon = Icons.AutoMirrored.Filled.ArrowBack + val backgroundColor = WikipediaTheme.colors.paperColor + val elevation = 0.dp // Elevation set to 0dp + val titleStyle = WikipediaTheme.typography.h1.copy( + lineHeight = 24.sp + ) + + TopAppBar( + title = { + Text( + text = title, + style = titleStyle, + color = WikipediaTheme.colors.primaryColor + ) + }, + navigationIcon = { + IconButton(onClick = onNavigationClick) { + Icon( + imageVector = navigationIcon, + contentDescription = null + ) + } + }, + colors = TopAppBarDefaults.topAppBarColors().copy( + containerColor = backgroundColor, + titleContentColor = WikipediaTheme.colors.primaryColor + ), + modifier = modifier.shadow(elevation = elevation) + ) +} diff --git a/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt index bed3d6da63d..d68b75e8aa2 100644 --- a/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt +++ b/app/src/main/java/org/wikipedia/compose/components/WikiButtons.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.sp import org.wikipedia.compose.theme.WikipediaTheme @Composable -fun Button( +fun AppButton( onClick: () -> Unit, modifier: Modifier = Modifier, backgroundColor: Color = WikipediaTheme.colors.progressiveColor, diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 2010a4f6e9d..d5664969a49 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -551,19 +551,6 @@ @style/TextInputLayoutErrorTextAppearance - -