Skip to content

Commit 435f3ce

Browse files
committed
Fix stats ellipsis and orders
1 parent eb8c5e7 commit 435f3ce

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

app/src/main/java/io/bloco/snowflake/ui/stats/StatsScreen.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ import androidx.compose.ui.res.stringResource
2828
import androidx.compose.ui.text.font.FontWeight
2929
import androidx.compose.ui.text.style.TextAlign
3030
import androidx.compose.ui.text.style.TextOverflow
31+
import androidx.compose.ui.tooling.preview.Preview
3132
import androidx.compose.ui.unit.Dp
3233
import androidx.compose.ui.unit.dp
3334
import androidx.compose.ui.unit.sp
3435
import io.bloco.snowflake.R
36+
import io.bloco.snowflake.models.DayStats
37+
import io.bloco.snowflake.ui.theme.SnowflakeTheme
3538
import java.time.LocalDate
3639
import java.time.format.DateTimeFormatter
3740

@@ -147,6 +150,7 @@ private fun RowScope.StatsCell(
147150
textAlign = if (isLabel) TextAlign.Start else TextAlign.End,
148151
fontSize = 14.sp,
149152
fontWeight = if (isLabel) FontWeight.Bold else FontWeight.Normal,
153+
maxLines = 1,
150154
overflow = TextOverflow.Ellipsis,
151155
modifier = Modifier
152156
.weight(1f)
@@ -169,3 +173,16 @@ private fun Long.humanBytes() =
169173

170174
private val DAY_FORMAT = DateTimeFormatter.ofPattern("dd MMM")
171175
private val MONTH_FORMAT = DateTimeFormatter.ofPattern("MMM yyyy")
176+
177+
@Composable
178+
@Preview
179+
private fun StatsScreenPreview() {
180+
SnowflakeTheme {
181+
StatsScreen(
182+
state = StatsViewModel.State(
183+
total = DayStats(LocalDate.now(), 100, 0, 1000, 1000),
184+
),
185+
goBack = { },
186+
)
187+
}
188+
}

app/src/main/java/io/bloco/snowflake/ui/stats/StatsViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class StatsViewModel(
3737
.groupBy { it.date.withDayOfMonth(1) }
3838
.map { (month, stats) ->
3939
(stats.sum() ?: DayStats()).copy(date = month)
40-
}
40+
}.sortedByDescending { it.date }
4141
val years = stats
4242
.groupBy { it.date.withDayOfYear(1) }
4343
.map { (year, stats) ->
4444
(stats.sum() ?: DayStats()).copy(date = year)
45-
}
45+
}.sortedByDescending { it.date }
4646
return State(
4747
days = days,
4848
months = months,
@@ -60,6 +60,6 @@ class StatsViewModel(
6060

6161
companion object {
6262
private const val LAST_N_DAYS = 5L
63-
private const val LAST_N_MONTHS = 12L
63+
private const val LAST_N_MONTHS = 6L
6464
}
6565
}

0 commit comments

Comments
 (0)