Show elapsed-time cursor on usage bars
This commit is contained in:
1 parent
84f978f16d
commit
cd0229bed6
3 files changed
+116
-30
No files matched your search
@@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
@@ -41,6 +40,7 @@ fun UsageDialog(
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
var signingIn by remember { mutableStateOf(false) }
|
||||
val now = rememberUsageNow()
|
||||
// A plain Dialog rather than an AlertDialog, for the spacing alone. AlertDialog fixes the gaps
|
||||
// between its title, content and buttons at sizes meant for a sentence of prose and a decision;
|
||||
// this is a dense read-out, and those gaps left a band of empty dialog above Close that was
|
||||
@@ -88,7 +88,7 @@ fun UsageDialog(
|
||||
)
|
||||
)
|
||||
}
|
||||
UsageBody(state, onSignIn = { signingIn = true })
|
||||
UsageBody(state, now, onSignIn = { signingIn = true })
|
||||
}
|
||||
TextButton(onClick = onDismiss, modifier = Modifier.align(Alignment.End)) {
|
||||
Text("Close")
|
||||
@@ -113,7 +113,11 @@ fun UsageDialog(
|
||||
|
||||
/** What came back, or why nothing did. Split out so the dialog above reads as its own shape. */
|
||||
@Composable
|
||||
private fun UsageBody(state: LoadState<List<UsageSnapshot>>, onSignIn: () -> Unit) {
|
||||
private fun UsageBody(
|
||||
state: LoadState<List<UsageSnapshot>>,
|
||||
now: OffsetDateTime,
|
||||
onSignIn: () -> Unit,
|
||||
) {
|
||||
Column {
|
||||
when (val current = state) {
|
||||
is LoadState.Loading -> CircularProgressIndicator()
|
||||
@@ -152,7 +156,7 @@ private fun UsageBody(state: LoadState<List<UsageSnapshot>>, onSignIn: () -> Uni
|
||||
if (windowIndex > 0) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
}
|
||||
WindowBar(window)
|
||||
WindowBar(window, now)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,7 +223,7 @@ private fun SnapshotState(snapshot: UsageSnapshot, onSignIn: () -> Unit) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WindowBar(window: UsageWindow) {
|
||||
private fun WindowBar(window: UsageWindow, now: OffsetDateTime) {
|
||||
Column {
|
||||
Row(modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
@@ -230,12 +234,8 @@ private fun WindowBar(window: UsageWindow) {
|
||||
Text("${window.percent.toInt()}%", style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
Spacer(Modifier.height(4.dp))
|
||||
LinearProgressIndicator(
|
||||
progress = { (window.percent / 100.0).toFloat().coerceIn(0f, 1f) },
|
||||
color = quotaColor(window.percent),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
resetLine(window)?.let {
|
||||
UsageProgressIndicator(window, now, Modifier.fillMaxWidth())
|
||||
resetLine(window, now)?.let {
|
||||
Spacer(Modifier.height(2.dp))
|
||||
Text(
|
||||
it,
|
||||
@@ -254,8 +254,8 @@ private fun WindowBar(window: UsageWindow) {
|
||||
* failure appeared as an ISO string in a sentence written for a person. Both are named in
|
||||
* [WindowEnd], and the session bar words them the same way.
|
||||
*/
|
||||
private fun resetLine(window: UsageWindow): String? =
|
||||
when (val end = windowEnd(window.resetsAt, OffsetDateTime.now())) {
|
||||
private fun resetLine(window: UsageWindow, now: OffsetDateTime): String? =
|
||||
when (val end = windowEnd(window.resetsAt, now)) {
|
||||
WindowEnd.NotRunning -> null
|
||||
WindowEnd.Unreadable -> "reset time unreadable"
|
||||
is WindowEnd.Ends ->
|
||||
|
||||
Reference in new issue
Block a user