-
Notifications
You must be signed in to change notification settings - Fork 1.4k
CMM-1145 create stats countries card #22546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ff48e1a
Adding the countries card
adalpari 4bc0c68
Handling on click show more
adalpari 5891b38
UI fixes
adalpari 1d6c7dd
Adding missing datasource functions
adalpari f05daf0
Merge remote-tracking branch 'origin/trunk' into feat/CMM-1145-Create…
adalpari 1bb4379
Some adjustments
adalpari 8d47db9
Adding period comparision
adalpari a8535d6
Views fix
adalpari 907ab00
tests
adalpari 9eeed38
Adding more tests
adalpari 0fda461
Improving map JS security
adalpari 9f980a5
Extracting some duplicated code
adalpari bc49b8d
Improving bars drawing
adalpari 099b6bd
Using Parcelable instead of Serializable
adalpari e52bf62
Extracting duplicated code
adalpari ff0bc03
Using common shimmer
adalpari 8e48324
Moving maps helpers inside map package
adalpari 7461117
Fixing lint
adalpari 3b4fecc
Adding some logs
adalpari 2872ca5
Updating library and handling the empty result
adalpari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
WordPress/src/main/java/org/wordpress/android/ui/newstats/components/StatsSummaryCard.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| package org.wordpress.android.ui.newstats.components | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material.icons.Icons | ||
| import androidx.compose.material.icons.filled.KeyboardArrowDown | ||
| import androidx.compose.material.icons.filled.KeyboardArrowUp | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.font.FontWeight | ||
| 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.AppThemeM3 | ||
| import org.wordpress.android.ui.newstats.StatsColors | ||
| import org.wordpress.android.ui.newstats.util.formatStatValue | ||
| import java.util.Locale | ||
| import kotlin.math.abs | ||
|
|
||
| /** | ||
| * A reusable summary card component for stats detail screens. | ||
| * Displays total views with optional change indicator for period comparison. | ||
| * | ||
| * @param totalViews The total views count to display | ||
| * @param dateRange The date range string to display | ||
| * @param totalViewsChange Optional change value compared to previous period (null to hide indicator) | ||
| * @param totalViewsChangePercent Optional change percentage (required if totalViewsChange is provided) | ||
| * @param modifier Modifier for the card | ||
| */ | ||
| @Composable | ||
| fun StatsSummaryCard( | ||
| totalViews: Long, | ||
| dateRange: String, | ||
| totalViewsChange: Long? = null, | ||
| totalViewsChangePercent: Double? = null, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| Box( | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .clip(RoundedCornerShape(12.dp)) | ||
| .background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.5f)) | ||
| .padding(16.dp) | ||
| ) { | ||
| Row( | ||
| modifier = Modifier.fillMaxWidth(), | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Column { | ||
| Text( | ||
| text = stringResource(R.string.stats_views), | ||
| style = MaterialTheme.typography.titleMedium, | ||
| fontWeight = FontWeight.SemiBold | ||
| ) | ||
| Text( | ||
| text = dateRange, | ||
| style = MaterialTheme.typography.bodySmall, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant | ||
| ) | ||
| } | ||
| Column(horizontalAlignment = Alignment.End) { | ||
| Text( | ||
| text = formatStatValue(totalViews), | ||
| style = MaterialTheme.typography.headlineLarge, | ||
| fontWeight = FontWeight.Bold | ||
| ) | ||
| if (totalViewsChange != null && totalViewsChangePercent != null) { | ||
| ViewsChangeIndicator( | ||
| change = totalViewsChange, | ||
| changePercent = totalViewsChangePercent | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun ViewsChangeIndicator( | ||
| change: Long, | ||
| changePercent: Double | ||
| ) { | ||
| if (change == 0L) return | ||
|
|
||
| val isPositive = change > 0 | ||
| val sign = if (isPositive) "+" else "-" | ||
| val color = if (isPositive) StatsColors.ChangeBadgePositive else StatsColors.ChangeBadgeNegative | ||
| val arrowIcon = if (isPositive) Icons.Default.KeyboardArrowUp else Icons.Default.KeyboardArrowDown | ||
|
|
||
| Row(verticalAlignment = Alignment.CenterVertically) { | ||
| Icon( | ||
| imageVector = arrowIcon, | ||
| contentDescription = null, | ||
| modifier = Modifier.size(16.dp), | ||
| tint = color | ||
| ) | ||
| Text( | ||
| text = "$sign${formatStatValue(abs(change))} (${ | ||
| String.format(Locale.getDefault(), "%.1f%%", abs(changePercent)) | ||
| })", | ||
| style = MaterialTheme.typography.labelSmall, | ||
| color = color | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun StatsSummaryCardWithChangePreview() { | ||
| AppThemeM3 { | ||
| StatsSummaryCard( | ||
| totalViews = 5400, | ||
| dateRange = "Last 7 days", | ||
| totalViewsChange = 69, | ||
| totalViewsChangePercent = 1.3 | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun StatsSummaryCardWithoutChangePreview() { | ||
| AppThemeM3 { | ||
| StatsSummaryCard( | ||
| totalViews = 5400, | ||
| dateRange = "Last 7 days" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun StatsSummaryCardNegativeChangePreview() { | ||
| AppThemeM3 { | ||
| StatsSummaryCard( | ||
| totalViews = 4200, | ||
| dateRange = "Last 30 days", | ||
| totalViewsChange = -150, | ||
| totalViewsChangePercent = -3.4 | ||
| ) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.