redesign app

This commit is contained in:
Meghdad committed 2026-06-23 01:40:25 +03:30
1 parent af0ec12caf
commit 74f70ae3e7
9 files changed
+1040 -257

No files matched your search

@@ -3,6 +3,7 @@ package net.rodakot.remaining.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
@@ -19,6 +20,7 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
@@ -50,7 +52,10 @@ fun RemainingApp(
}
}
Scaffold(snackbarHost = { SnackbarHost(snackbarHostState) }) { outerPadding ->
Scaffold(
containerColor = Color.Transparent,
snackbarHost = { SnackbarHost(snackbarHostState) }
) { outerPadding ->
NavHost(
navController = navController,
startDestination = Route.Dashboard,
@@ -107,11 +112,13 @@ fun RemainingApp(
state.action.captcha?.let { captcha ->
AlertDialog(
onDismissRequest = viewModel::dismissCaptcha,
title = { Text("TCI captcha") },
shape = RoundedCornerShape(8.dp),
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
title = { Text("TCI captcha required") },
text = {
Column {
Text(
"Enter the captcha shown by TCI. This signs in the saved account session.",
"Enter the code shown by TCI to refresh this saved account session.",
color = MaterialTheme.colorScheme.onSurfaceVariant
)
CaptchaImage(
@@ -1,15 +1,25 @@
package net.rodakot.remaining.ui.components
import android.graphics.BitmapFactory
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LinearProgressIndicator
@@ -20,36 +30,149 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import net.rodakot.remaining.domain.AccountStatus
import net.rodakot.remaining.domain.ServiceType
import java.text.DateFormat
import java.util.Date
import java.util.Locale
@Composable
fun StatusChip(status: AccountStatus, modifier: Modifier = Modifier) {
val color = when (status) {
AccountStatus.ACTIVE -> Color(0xFF3DDC84)
AccountStatus.REFRESHING -> Color(0xFF64B5F6)
AccountStatus.CAPTCHA_REQUIRED -> Color(0xFFFFC857)
AccountStatus.NEEDS_AUTH -> Color(0xFFFF9F1C)
AccountStatus.ERROR -> Color(0xFFFF5A5F)
AccountStatus.DISABLED -> MaterialTheme.colorScheme.outline
fun RemainingBackground(
modifier: Modifier = Modifier,
content: @Composable BoxScope.() -> Unit
) {
val colorScheme = MaterialTheme.colorScheme
Box(
modifier = modifier
.fillMaxSize()
.background(
Brush.verticalGradient(
listOf(
colorScheme.background,
colorScheme.surfaceContainerLow,
colorScheme.background
)
)
)
) {
Canvas(modifier = Modifier.fillMaxSize()) {
drawRect(
brush = Brush.linearGradient(
colors = listOf(
colorScheme.primary.copy(alpha = 0.18f),
Color.Transparent,
colorScheme.secondary.copy(alpha = 0.12f)
),
start = Offset.Zero,
end = Offset(size.width, size.height)
)
)
drawLine(
color = colorScheme.primary.copy(alpha = 0.16f),
start = Offset(0f, size.height * 0.18f),
end = Offset(size.width, size.height * 0.04f),
strokeWidth = 2.dp.toPx()
)
drawLine(
color = colorScheme.secondary.copy(alpha = 0.10f),
start = Offset(0f, size.height * 0.88f),
end = Offset(size.width, size.height * 0.72f),
strokeWidth = 2.dp.toPx()
)
}
content()
}
}
@Composable
fun ModernPanel(
modifier: Modifier = Modifier,
contentPadding: PaddingValues = PaddingValues(16.dp),
content: @Composable ColumnScope.() -> Unit
) {
Surface(
modifier = modifier,
shape = RoundedCornerShape(8.dp),
color = MaterialTheme.colorScheme.surfaceContainer.copy(alpha = 0.92f),
contentColor = MaterialTheme.colorScheme.onSurface,
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.55f)),
shadowElevation = 0.dp,
tonalElevation = 0.dp
) {
Column(
modifier = Modifier.padding(contentPadding),
verticalArrangement = Arrangement.spacedBy(12.dp),
content = content
)
}
}
@Composable
fun SectionHeader(
title: String,
modifier: Modifier = Modifier,
subtitle: String? = null
) {
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(3.dp)) {
Text(title, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
subtitle?.let {
Text(
it,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
}
}
}
@Composable
fun ServiceBadge(
serviceType: ServiceType,
modifier: Modifier = Modifier,
label: String = serviceType.shortName
) {
val color = serviceType.accentColor()
Surface(
modifier = modifier,
color = color.copy(alpha = 0.16f),
contentColor = color,
shape = RoundedCornerShape(8.dp)
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, color.copy(alpha = 0.30f))
) {
Text(
text = label,
style = MaterialTheme.typography.labelMedium,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp)
)
}
}
@Composable
fun StatusChip(status: AccountStatus, modifier: Modifier = Modifier) {
val color = status.accentColor()
Surface(
modifier = modifier,
color = color.copy(alpha = 0.16f),
contentColor = color,
shape = RoundedCornerShape(8.dp),
border = BorderStroke(1.dp, color.copy(alpha = 0.30f))
) {
Text(
text = status.displayName,
style = MaterialTheme.typography.labelMedium,
fontWeight = FontWeight.SemiBold,
modifier = Modifier.padding(horizontal = 10.dp, vertical = 5.dp)
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(horizontal = 10.dp, vertical = 6.dp)
)
}
}
@@ -62,20 +185,10 @@ fun UsageBar(
modifier: Modifier = Modifier
) {
val progress = remember(remainingBytes, totalBytes) {
if (remainingBytes == null || totalBytes == null || totalBytes <= 0L) {
null
} else {
(remainingBytes.toFloat() / totalBytes.toFloat()).coerceIn(0f, 1f)
remainingProgress(remainingBytes, totalBytes)
}
}
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(6.dp)) {
LinearProgressIndicator(
progress = { progress ?: 0.62f },
modifier = Modifier
.fillMaxWidth()
.height(8.dp),
trackColor = MaterialTheme.colorScheme.surfaceVariant
)
Column(modifier = modifier, verticalArrangement = Arrangement.spacedBy(7.dp)) {
QuotaBar(progress = progress)
Text(
text = totalDisplay?.let { "Total $it" } ?: "Total quota not reported",
color = MaterialTheme.colorScheme.onSurfaceVariant,
@@ -85,15 +198,103 @@ fun UsageBar(
}
@Composable
fun MetricPill(label: String, value: String, modifier: Modifier = Modifier) {
fun QuotaBar(progress: Float?, modifier: Modifier = Modifier) {
val colorScheme = MaterialTheme.colorScheme
val shape = RoundedCornerShape(8.dp)
Box(
modifier = modifier
.background(MaterialTheme.colorScheme.surfaceVariant, RoundedCornerShape(8.dp))
.padding(horizontal = 12.dp, vertical = 10.dp)
.fillMaxWidth()
.height(10.dp)
.clip(shape)
.background(colorScheme.surfaceContainerHighest.copy(alpha = 0.70f))
.border(1.dp, colorScheme.outlineVariant.copy(alpha = 0.35f), shape)
) {
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(label, color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.labelSmall)
Text(value, fontWeight = FontWeight.SemiBold, style = MaterialTheme.typography.titleSmall)
if (progress != null) {
Box(
modifier = Modifier
.fillMaxHeight()
.fillMaxWidth(progress)
.background(
Brush.horizontalGradient(
listOf(colorScheme.primary, colorScheme.secondary)
)
)
)
} else {
LinearProgressIndicator(
progress = { 0.28f },
modifier = Modifier.fillMaxSize(),
color = colorScheme.outline,
trackColor = Color.Transparent
)
}
}
}
@Composable
fun MetricPill(label: String, value: String, modifier: Modifier = Modifier) {
Surface(
modifier = modifier,
shape = RoundedCornerShape(8.dp),
color = MaterialTheme.colorScheme.surfaceContainerHighest.copy(alpha = 0.60f),
contentColor = MaterialTheme.colorScheme.onSurface,
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.45f))
) {
Column(
modifier = Modifier.padding(horizontal = 12.dp, vertical = 11.dp),
verticalArrangement = Arrangement.spacedBy(3.dp)
) {
Text(
label,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.labelSmall
)
Text(value, fontWeight = FontWeight.Bold, style = MaterialTheme.typography.titleSmall)
}
}
}
@Composable
fun QuotaRing(
progress: Float?,
label: String,
value: String,
modifier: Modifier = Modifier.size(156.dp),
accent: Color = MaterialTheme.colorScheme.primary
) {
val trackColor = MaterialTheme.colorScheme.surfaceContainerHighest
Box(modifier = modifier, contentAlignment = Alignment.Center) {
Canvas(modifier = Modifier.fillMaxSize()) {
val stroke = Stroke(width = 13.dp.toPx(), cap = StrokeCap.Round)
drawArc(
color = trackColor,
startAngle = 135f,
sweepAngle = 270f,
useCenter = false,
style = stroke
)
drawArc(
brush = Brush.sweepGradient(listOf(accent, Color(0xFF8EEBFF), accent)),
startAngle = 135f,
sweepAngle = 270f * (progress ?: 0.64f),
useCenter = false,
style = stroke
)
}
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
value,
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center
)
Text(
label,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.labelMedium,
textAlign = TextAlign.Center
)
}
}
}
@@ -122,8 +323,19 @@ fun InfoRow(label: String, value: String, modifier: Modifier = Modifier) {
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(label, color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(value, fontWeight = FontWeight.Medium)
Text(
label,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium
)
Spacer(modifier = Modifier.size(16.dp))
Text(
value,
fontWeight = FontWeight.SemiBold,
style = MaterialTheme.typography.bodyMedium,
textAlign = TextAlign.End,
modifier = Modifier.weight(1f, fill = false)
)
}
}
@@ -132,3 +344,22 @@ fun Long?.formatTimestamp(): String =
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US)
.format(Date(it))
} ?: "Never"
fun remainingProgress(remainingBytes: Long?, totalBytes: Long?): Float? =
if (remainingBytes == null || totalBytes == null || totalBytes <= 0L) {
null
} else {
(remainingBytes.toFloat() / totalBytes.toFloat()).coerceIn(0f, 1f)
}
fun ServiceType.accentColor(): Color = Color(accentArgb)
fun AccountStatus.accentColor(): Color =
when (this) {
AccountStatus.ACTIVE -> Color(0xFF56E39F)
AccountStatus.REFRESHING -> Color(0xFF8EEBFF)
AccountStatus.CAPTCHA_REQUIRED -> Color(0xFFFFD166)
AccountStatus.NEEDS_AUTH -> Color(0xFFFF8A65)
AccountStatus.ERROR -> Color(0xFFFF6B7A)
AccountStatus.DISABLED -> Color(0xFF93A39A)
}
@@ -1,12 +1,18 @@
package net.rodakot.remaining.ui.screens
import androidx.compose.foundation.BorderStroke
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.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -15,8 +21,6 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilterChip
import androidx.compose.material3.Icon
@@ -25,26 +29,41 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import net.rodakot.remaining.data.AccountDetail
import net.rodakot.remaining.data.AccountSummary
import net.rodakot.remaining.data.UsagePackageEntity
import net.rodakot.remaining.domain.AccountStatus
import net.rodakot.remaining.domain.RefreshInterval
import net.rodakot.remaining.domain.asTrafficDisplay
import net.rodakot.remaining.ui.components.InfoRow
import net.rodakot.remaining.ui.components.MetricPill
import net.rodakot.remaining.ui.components.ModernPanel
import net.rodakot.remaining.ui.components.QuotaRing
import net.rodakot.remaining.ui.components.RemainingBackground
import net.rodakot.remaining.ui.components.SectionHeader
import net.rodakot.remaining.ui.components.ServiceBadge
import net.rodakot.remaining.ui.components.StatusChip
import net.rodakot.remaining.ui.components.UsageBar
import net.rodakot.remaining.ui.components.accentColor
import net.rodakot.remaining.ui.components.formatTimestamp
import net.rodakot.remaining.ui.components.remainingProgress
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -58,10 +77,29 @@ fun AccountDetailScreen(
onDelete: (String) -> Unit
) {
val account = detail?.summary
RemainingBackground {
Scaffold(
containerColor = Color.Transparent,
topBar = {
TopAppBar(
title = { Text(account?.displayName ?: "Account") },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
scrolledContainerColor = Color.Transparent
),
title = {
Column {
Text(account?.displayName ?: "Account", maxLines = 1, overflow = TextOverflow.Ellipsis)
account?.let {
Text(
it.serviceType.displayName,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
}
},
navigationIcon = {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
@@ -77,7 +115,7 @@ fun AccountDetailScreen(
)
}
) { padding ->
if (account == null) {
if (detail == null) {
Column(
modifier = Modifier
.fillMaxSize()
@@ -85,19 +123,27 @@ fun AccountDetailScreen(
.padding(24.dp),
verticalArrangement = Arrangement.Center
) {
ModernPanel(modifier = Modifier.fillMaxWidth()) {
Text("Account not found", style = MaterialTheme.typography.titleLarge)
Text(
"This account may have been removed.",
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
} else {
val currentAccount = detail.summary
AccountDetailContent(
modifier = Modifier.padding(padding),
detail = detail,
busy = busy,
onRefresh = { onRefresh(account.id) },
onPrepareCaptcha = { onPrepareCaptcha(account.id) },
onRefresh = { onRefresh(currentAccount.id) },
onPrepareCaptcha = { onPrepareCaptcha(currentAccount.id) },
onSaveSettings = onSaveSettings
)
}
}
}
}
@Composable
@@ -112,69 +158,51 @@ private fun AccountDetailContent(
val account = detail.summary
LazyColumn(
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(16.dp),
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 24.dp),
verticalArrangement = Arrangement.spacedBy(14.dp)
) {
item {
Card(
shape = RoundedCornerShape(8.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)
) {
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(14.dp)) {
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.weight(1f)) {
Text(account.serviceType.displayName, color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(account.remainingDisplay, style = MaterialTheme.typography.headlineMedium, fontWeight = FontWeight.Bold)
AccountHero(
account = account,
busy = busy,
onRefresh = onRefresh,
onPrepareCaptcha = onPrepareCaptcha
)
}
StatusChip(account.status)
}
UsageBar(account.remainingBytes, account.totalBytes, account.totalDisplay)
account.lastErrorMessage?.let {
Text(it, color = MaterialTheme.colorScheme.error)
item {
ModernPanel {
SectionHeader(
title = "Refresh health",
subtitle = "The timestamps below show scheduler state and last successful data capture."
)
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
MetricPill("Interval", account.refreshInterval.displayName, Modifier.weight(1f))
MetricPill("Next", account.nextRefreshAt.formatTimestamp(), Modifier.weight(1f))
}
InfoRow("Login", account.loginIdentifier)
InfoRow("Refresh interval", account.refreshInterval.displayName)
account.expiresAtText?.let { InfoRow("Package expiry", it) }
InfoRow("Last refresh", account.lastRefreshAt.formatTimestamp())
InfoRow("Last success", account.lastSuccessAt.formatTimestamp())
InfoRow("Next refresh", account.nextRefreshAt.formatTimestamp())
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Button(
onClick = onRefresh,
enabled = !busy && account.enabled,
modifier = Modifier.weight(1f)
) {
Icon(Icons.Default.Refresh, contentDescription = null)
Text(if (busy) "Refreshing" else "Refresh", modifier = Modifier.padding(start = 8.dp))
}
if (account.status == AccountStatus.CAPTCHA_REQUIRED) {
OutlinedButton(
onClick = onPrepareCaptcha,
enabled = !busy,
modifier = Modifier.weight(1f)
) {
Text("Captcha")
}
}
}
}
}
}
item {
AccountSettingsCard(account, onSaveSettings)
AccountSettingsPanel(account, onSaveSettings)
}
item {
Text("Packages", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
SectionHeader(
title = "Packages",
subtitle = if (detail.packages.isEmpty()) "No package details reported yet." else "${detail.packages.size} package record${if (detail.packages.size == 1) "" else "s"}"
)
}
if (detail.packages.isEmpty()) {
item {
ModernPanel {
Text(
"No package details reported yet.",
"Refresh this account to import package-level usage data.",
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
}
} else {
items(detail.packages, key = { it.id }) { item ->
PackageRow(item)
@@ -183,9 +211,105 @@ private fun AccountDetailContent(
}
}
@Composable
private fun AccountHero(
account: AccountSummary,
busy: Boolean,
onRefresh: () -> Unit,
onPrepareCaptcha: () -> Unit
) {
val accent = account.serviceType.accentColor()
val progress = remainingProgress(account.remainingBytes, account.totalBytes)
Surface(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(8.dp),
color = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onSurface,
border = BorderStroke(1.dp, accent.copy(alpha = 0.35f))
) {
Box(
modifier = Modifier
.background(
Brush.linearGradient(
listOf(
accent.copy(alpha = 0.24f),
MaterialTheme.colorScheme.surfaceContainer.copy(alpha = 0.94f),
MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.45f)
)
)
)
.padding(18.dp)
) {
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
Row(verticalAlignment = Alignment.Top, modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
ServiceBadge(account.serviceType)
StatusChip(if (busy) AccountStatus.REFRESHING else account.status)
}
Text(
account.remainingDisplay,
style = MaterialTheme.typography.displaySmall,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface
)
Text(
"Available balance for ${account.displayName}",
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium
)
}
Spacer(modifier = Modifier.width(12.dp))
QuotaRing(
progress = progress,
value = account.remainingDisplay,
label = "remaining",
accent = accent,
modifier = Modifier.size(132.dp)
)
}
UsageBar(
remainingBytes = account.remainingBytes,
totalBytes = account.totalBytes,
totalDisplay = account.totalDisplay
)
account.lastErrorMessage?.let {
Surface(
shape = RoundedCornerShape(8.dp),
color = MaterialTheme.colorScheme.error.copy(alpha = 0.12f),
contentColor = MaterialTheme.colorScheme.error,
modifier = Modifier.fillMaxWidth()
) {
Text(it, modifier = Modifier.padding(10.dp), style = MaterialTheme.typography.bodySmall)
}
}
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Button(
onClick = onRefresh,
enabled = !busy && account.enabled,
modifier = Modifier.weight(1f)
) {
Icon(Icons.Default.Refresh, contentDescription = null, modifier = Modifier.size(18.dp))
Text(if (busy) "Refreshing" else "Refresh now", modifier = Modifier.padding(start = 8.dp))
}
if (account.status == AccountStatus.CAPTCHA_REQUIRED) {
OutlinedButton(
onClick = onPrepareCaptcha,
enabled = !busy,
modifier = Modifier.weight(1f)
) {
Text("Solve captcha")
}
}
}
}
}
}
}
@Composable
@OptIn(ExperimentalMaterial3Api::class)
private fun AccountSettingsCard(
private fun AccountSettingsPanel(
account: AccountSummary,
onSaveSettings: (AccountSummary, RefreshInterval, Boolean, Long, Int, Boolean) -> Unit
) {
@@ -195,20 +319,24 @@ private fun AccountSettingsCard(
var thresholdMb by rememberSaveable(account.id) { mutableStateOf(account.lowDataThresholdMb.toString()) }
var expiryDays by rememberSaveable(account.id) { mutableStateOf(account.expiryThresholdDays.toString()) }
Card(
shape = RoundedCornerShape(8.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainer)
) {
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(14.dp)) {
Text("Account settings", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
Column(Modifier.weight(1f)) {
Text("Enabled", fontWeight = FontWeight.Medium)
Text("Background refresh is paused when disabled.", color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall)
}
Switch(checked = enabled, onCheckedChange = { enabled = it })
}
Text("Refresh interval", fontWeight = FontWeight.Medium)
ModernPanel {
SectionHeader(
title = "Automation",
subtitle = "Tune background refresh and warning thresholds for this account."
)
ToggleRow(
title = "Account enabled",
description = "Pause refreshes without deleting credentials.",
checked = enabled,
onCheckedChange = { enabled = it }
)
ToggleRow(
title = "Alerts",
description = "Notify for low data, expiry, captcha, and failed refreshes.",
checked = alertsEnabled,
onCheckedChange = { alertsEnabled = it }
)
Text("Refresh interval", fontWeight = FontWeight.SemiBold)
RefreshInterval.entries.chunked(2).forEach { rowOptions ->
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
rowOptions.forEach { option ->
@@ -221,28 +349,26 @@ private fun AccountSettingsCard(
)
}
if (rowOptions.size == 1) {
Column(Modifier.weight(1f)) {}
Spacer(Modifier.weight(1f))
}
}
}
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
Text("Alerts", fontWeight = FontWeight.Medium)
Switch(checked = alertsEnabled, onCheckedChange = { alertsEnabled = it })
}
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
OutlinedTextField(
value = thresholdMb,
onValueChange = { thresholdMb = it.filter(Char::isDigit) },
label = { Text("Low data threshold (MB)") },
label = { Text("Low data MB") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
modifier = Modifier.weight(1f)
)
OutlinedTextField(
value = expiryDays,
onValueChange = { expiryDays = it.filter(Char::isDigit) },
label = { Text("Expiry warning threshold (days)") },
label = { Text("Expiry days") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
modifier = Modifier.weight(1f)
)
}
Button(
onClick = {
onSaveSettings(
@@ -256,30 +382,63 @@ private fun AccountSettingsCard(
},
modifier = Modifier.fillMaxWidth()
) {
Text("Save settings")
}
Text("Save automation")
}
}
}
@Composable
private fun PackageRow(item: UsagePackageEntity) {
Card(
shape = RoundedCornerShape(8.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceContainerLow)
private fun ToggleRow(
title: String,
description: String,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(Modifier.padding(14.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Text(item.name, fontWeight = FontWeight.SemiBold)
Text(item.remainingDisplay, style = MaterialTheme.typography.titleMedium)
item.expiresAtText?.let {
Text("Expires: $it", color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall)
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(title, fontWeight = FontWeight.SemiBold)
Text(
description,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
}
Switch(checked = checked, onCheckedChange = onCheckedChange)
}
}
@Composable
private fun PackageRow(item: UsagePackageEntity) {
ModernPanel(contentPadding = PaddingValues(14.dp)) {
Row(verticalAlignment = Alignment.Top, modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(item.name, fontWeight = FontWeight.Bold, style = MaterialTheme.typography.titleMedium)
Text(item.remainingDisplay, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)
}
item.statusText?.let {
Text(it, color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall)
Surface(
shape = RoundedCornerShape(8.dp),
color = MaterialTheme.colorScheme.surfaceContainerHighest,
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
) {
Text(it, style = MaterialTheme.typography.labelSmall, modifier = Modifier.padding(horizontal = 9.dp, vertical = 6.dp))
}
}
}
UsageBar(
remainingBytes = item.remainingBytes,
totalBytes = item.totalBytes,
totalDisplay = item.totalBytes?.asTrafficDisplay()
)
item.expiresAtText?.let {
InfoRow("Expires", it)
}
item.detail?.takeIf { it.isNotBlank() }?.let {
Text(it, color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall)
}
}
}
}
@@ -1,12 +1,17 @@
package net.rodakot.remaining.ui.screens
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
@@ -22,15 +27,19 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
@@ -38,6 +47,11 @@ import androidx.compose.ui.unit.dp
import net.rodakot.remaining.data.CreateAccountRequest
import net.rodakot.remaining.domain.RefreshInterval
import net.rodakot.remaining.domain.ServiceType
import net.rodakot.remaining.ui.components.ModernPanel
import net.rodakot.remaining.ui.components.RemainingBackground
import net.rodakot.remaining.ui.components.SectionHeader
import net.rodakot.remaining.ui.components.ServiceBadge
import net.rodakot.remaining.ui.components.accentColor
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -60,16 +74,62 @@ fun AddAccountScreen(
var expiryDays by rememberSaveable { mutableStateOf("3") }
val canSave = username.isNotBlank() && password.isNotBlank() && !saving
RemainingBackground {
Scaffold(
containerColor = Color.Transparent,
topBar = {
TopAppBar(
title = { Text("Add account") },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
scrolledContainerColor = Color.Transparent
),
title = {
Column {
Text("Connect account", fontWeight = FontWeight.Bold)
Text(
service.displayName,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
},
navigationIcon = {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
}
}
)
},
bottomBar = {
Surface(
color = MaterialTheme.colorScheme.surfaceContainer.copy(alpha = 0.94f),
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.50f))
) {
Button(
onClick = {
onCreateAccount(
CreateAccountRequest(
serviceType = service,
displayName = displayName.trim(),
loginIdentifier = username.trim(),
password = password,
refreshIntervalMinutes = interval.minutes,
alertsEnabled = alertsEnabled,
lowDataThresholdMb = thresholdMb.toLongOrNull()?.coerceAtLeast(1) ?: 1024,
expiryThresholdDays = expiryDays.toIntOrNull()?.coerceAtLeast(1) ?: 3
)
)
onBack()
},
enabled = canSave,
contentPadding = PaddingValues(vertical = 14.dp),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
) {
Text(if (saving) "Saving" else "Save and start tracking")
}
}
}
) { padding ->
Column(
@@ -77,40 +137,39 @@ fun AddAccountScreen(
.fillMaxSize()
.padding(padding)
.verticalScroll(rememberScrollState())
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(18.dp)
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 24.dp),
verticalArrangement = Arrangement.spacedBy(14.dp)
) {
SectionTitle("Service")
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
ModernPanel {
SectionHeader(
title = "Choose service",
subtitle = "Each provider keeps its own login method and refresh behavior."
)
ServiceType.entries.forEach { option ->
FilterChip(
ServiceOption(
option = option,
selected = service == option,
onClick = { service = option },
label = { Text(option.shortName) },
shape = RoundedCornerShape(8.dp)
onSelected = { service = option }
)
}
}
Text(
text = when (service) {
ServiceType.MCI -> "Use your My MCI phone number and password."
ServiceType.JAHAN_NAMA -> "Use your Webotel/Jahan Nama username and password."
ServiceType.TCI -> "TCI needs a manual captcha after the account is saved."
},
color = MaterialTheme.colorScheme.onSurfaceVariant
)
SectionTitle("Credentials")
ModernPanel {
SectionHeader(
title = "Credentials",
subtitle = service.helperText()
)
OutlinedTextField(
value = displayName,
onValueChange = { displayName = it },
label = { Text("Display name") },
placeholder = { Text("${service.shortName} home line") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
)
OutlinedTextField(
value = username,
onValueChange = { username = it.trim() },
onValueChange = { username = it },
label = { Text(if (service == ServiceType.MCI) "Phone number" else "Username") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
@@ -131,74 +190,105 @@ fun AddAccountScreen(
},
modifier = Modifier.fillMaxWidth()
)
}
SectionTitle("Refresh")
ModernPanel {
SectionHeader(
title = "Refresh rhythm",
subtitle = "Shorter intervals update faster and use more background work."
)
PresetChips(
options = RefreshInterval.entries,
selected = interval,
label = { it.displayName },
onSelected = { interval = it }
)
}
SectionTitle("Alerts")
ModernPanel {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(modifier = Modifier.weight(1f)) {
Text("Enable account alerts", fontWeight = FontWeight.Medium)
Text(
"Low data, failed refreshes, and captcha requests",
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
SectionHeader(
title = "Alerts",
subtitle = "Low data, failed refreshes, and captcha requests.",
modifier = Modifier.weight(1f)
)
}
Switch(checked = alertsEnabled, onCheckedChange = { alertsEnabled = it })
}
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
OutlinedTextField(
value = thresholdMb,
onValueChange = { thresholdMb = it.filter(Char::isDigit) },
label = { Text("Low data threshold (MB)") },
label = { Text("Low data MB") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
modifier = Modifier.weight(1f)
)
OutlinedTextField(
value = expiryDays,
onValueChange = { expiryDays = it.filter(Char::isDigit) },
label = { Text("Expiry warning threshold (days)") },
label = { Text("Expiry days") },
singleLine = true,
modifier = Modifier.fillMaxWidth()
modifier = Modifier.weight(1f)
)
Button(
onClick = {
onCreateAccount(
CreateAccountRequest(
serviceType = service,
displayName = displayName.trim(),
loginIdentifier = username.trim(),
password = password,
refreshIntervalMinutes = interval.minutes,
alertsEnabled = alertsEnabled,
lowDataThresholdMb = thresholdMb.toLongOrNull()?.coerceAtLeast(1) ?: 1024,
expiryThresholdDays = expiryDays.toIntOrNull()?.coerceAtLeast(1) ?: 3
)
)
onBack()
},
enabled = canSave,
contentPadding = PaddingValues(vertical = 14.dp),
modifier = Modifier.fillMaxWidth()
) {
Text(if (saving) "Saving" else "Save account")
}
}
}
}
}
}
@Composable
private fun SectionTitle(text: String) {
Text(text, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
private fun ServiceOption(
option: ServiceType,
selected: Boolean,
onSelected: () -> Unit
) {
val accent = option.accentColor()
Surface(
modifier = Modifier
.fillMaxWidth()
.clickable(onClick = onSelected),
shape = RoundedCornerShape(8.dp),
color = if (selected) accent.copy(alpha = 0.16f) else MaterialTheme.colorScheme.surfaceContainerHigh.copy(alpha = 0.62f),
contentColor = MaterialTheme.colorScheme.onSurface,
border = BorderStroke(
1.dp,
if (selected) accent.copy(alpha = 0.72f) else MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.50f)
)
) {
Row(
modifier = Modifier.padding(13.dp),
verticalAlignment = Alignment.CenterVertically
) {
ServiceBadge(option)
Spacer(modifier = Modifier.width(12.dp))
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(option.displayName, fontWeight = FontWeight.Bold)
Text(
option.helperText(),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
}
if (selected) {
Surface(
shape = RoundedCornerShape(8.dp),
color = accent,
contentColor = Color.White
) {
Text(
"Selected",
style = MaterialTheme.typography.labelSmall,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(horizontal = 8.dp, vertical = 5.dp)
)
}
}
}
}
}
@Composable
@@ -222,9 +312,16 @@ private fun <T> PresetChips(
)
}
if (rowOptions.size == 1) {
Column(modifier = Modifier.weight(1f)) {}
Spacer(modifier = Modifier.weight(1f))
}
}
}
}
}
private fun ServiceType.helperText(): String =
when (this) {
ServiceType.MCI -> "Use your My MCI phone number and password."
ServiceType.JAHAN_NAMA -> "Use your Webotel/Jahan Nama username and password."
ServiceType.TCI -> "TCI needs a manual captcha after the account is saved."
}
@@ -1,13 +1,19 @@
package net.rodakot.remaining.ui.screens
import androidx.compose.foundation.BorderStroke
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.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -25,22 +31,35 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import net.rodakot.remaining.data.AccountSummary
import net.rodakot.remaining.domain.AccountStatus
import net.rodakot.remaining.domain.asTrafficDisplay
import net.rodakot.remaining.ui.RemainingUiState
import net.rodakot.remaining.ui.components.MetricPill
import net.rodakot.remaining.ui.components.ModernPanel
import net.rodakot.remaining.ui.components.QuotaBar
import net.rodakot.remaining.ui.components.QuotaRing
import net.rodakot.remaining.ui.components.RemainingBackground
import net.rodakot.remaining.ui.components.SectionHeader
import net.rodakot.remaining.ui.components.ServiceBadge
import net.rodakot.remaining.ui.components.StatusChip
import net.rodakot.remaining.ui.components.UsageBar
import net.rodakot.remaining.ui.components.accentColor
import net.rodakot.remaining.ui.components.formatTimestamp
import net.rodakot.remaining.ui.components.remainingProgress
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -52,14 +71,20 @@ fun DashboardScreen(
onPrepareCaptcha: (String) -> Unit,
onOpenSettings: () -> Unit
) {
RemainingBackground {
Scaffold(
containerColor = Color.Transparent,
topBar = {
TopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
scrolledContainerColor = Color.Transparent
),
title = {
Column {
Text("Remaining", fontWeight = FontWeight.Bold)
Text(
"Usage across all accounts",
"${state.accounts.size} connected account${if (state.accounts.size == 1) "" else "s"}",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
@@ -88,12 +113,19 @@ fun DashboardScreen(
modifier = Modifier
.fillMaxSize()
.padding(padding),
contentPadding = PaddingValues(16.dp),
contentPadding = PaddingValues(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 24.dp),
verticalArrangement = Arrangement.spacedBy(14.dp)
) {
item {
OverviewCard(accounts = state.accounts)
}
item {
SectionHeader(
title = "Accounts",
subtitle = "Tap an account for packages, refresh settings, and history.",
modifier = Modifier.padding(top = 4.dp)
)
}
items(state.accounts, key = { it.id }) { account ->
AccountCard(
account = account,
@@ -106,75 +138,124 @@ fun DashboardScreen(
}
}
}
}
}
@Composable
private fun EmptyDashboard(modifier: Modifier = Modifier, onAddAccount: () -> Unit) {
Column(
modifier = modifier.padding(24.dp),
verticalArrangement = Arrangement.Center
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
ModernPanel(
modifier = Modifier.fillMaxWidth(),
contentPadding = PaddingValues(22.dp)
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(18.dp),
modifier = Modifier.fillMaxWidth()
) {
QuotaRing(progress = null, label = "dashboard", value = "Ready")
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
"Track every service account in one dashboard.",
"Your usage command center",
style = MaterialTheme.typography.headlineSmall,
fontWeight = FontWeight.Bold
)
Text(
"Add MCI, Jahan Nama/Webotel, or TCI accounts, then choose how often each one refreshes.",
"Connect MCI, Webotel, or TCI and the app will keep quota, refresh health, and alerts in one clean view.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 10.dp, bottom = 22.dp)
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.padding(top = 8.dp)
)
Button(onClick = onAddAccount) {
}
Button(onClick = onAddAccount, modifier = Modifier.fillMaxWidth()) {
Icon(Icons.Default.Add, contentDescription = null)
Text("Add account", modifier = Modifier.padding(start = 8.dp))
Text("Connect first account", modifier = Modifier.padding(start = 8.dp))
}
}
}
}
}
@Composable
private fun OverviewCard(accounts: List<AccountSummary>) {
val totalRemaining = remember(accounts) {
accounts.mapNotNull { it.remainingBytes }.sum()
}
val knownRemaining = remember(accounts) { accounts.mapNotNull { it.remainingBytes } }
val totalRemaining = remember(knownRemaining) { knownRemaining.takeIf { it.isNotEmpty() }?.sum() }
val knownTotal = remember(accounts) { accounts.mapNotNull { it.totalBytes } }
val totalQuota = remember(knownTotal) { knownTotal.takeIf { it.isNotEmpty() }?.sum() }
val issueCount = accounts.count {
it.status == AccountStatus.ERROR ||
it.status == AccountStatus.CAPTCHA_REQUIRED ||
it.status == AccountStatus.NEEDS_AUTH
}
val activeCount = accounts.count { it.status == AccountStatus.ACTIVE }
val nextRefresh = accounts.mapNotNull { it.nextRefreshAt }.minOrNull()
val progress = remainingProgress(totalRemaining, totalQuota)
Column(
Surface(
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(8.dp),
color = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onSurface,
border = BorderStroke(1.dp, MaterialTheme.colorScheme.primary.copy(alpha = 0.30f))
) {
Box(
modifier = Modifier
.fillMaxWidth()
.background(
Brush.linearGradient(
colors = listOf(
MaterialTheme.colorScheme.primaryContainer,
MaterialTheme.colorScheme.secondaryContainer
listOf(
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.88f),
MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.70f),
MaterialTheme.colorScheme.surfaceContainer.copy(alpha = 0.94f)
)
),
RoundedCornerShape(8.dp)
)
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(14.dp)
)
.padding(18.dp)
) {
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(
"Dashboard",
style = MaterialTheme.typography.titleLarge,
"Live quota",
color = MaterialTheme.colorScheme.onPrimaryContainer,
style = MaterialTheme.typography.labelLarge
)
Text(
totalRemaining?.asTrafficDisplay() ?: "Unknown",
style = MaterialTheme.typography.displaySmall,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onPrimaryContainer
)
Text(
"Remaining across every connected service",
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium
)
}
QuotaRing(
progress = progress,
value = totalRemaining?.asTrafficDisplay() ?: "--",
label = "left"
)
}
QuotaBar(progress = progress)
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
MetricPill("Remaining", totalRemaining.asTrafficDisplay(), Modifier.weight(1f))
MetricPill("Accounts", accounts.size.toString(), Modifier.weight(1f))
MetricPill("Active", activeCount.toString(), Modifier.weight(1f))
MetricPill("Needs action", issueCount.toString(), Modifier.weight(1f))
}
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
MetricPill("Needs action", issueCount.toString(), Modifier.weight(1f))
MetricPill("Accounts", accounts.size.toString(), Modifier.weight(1f))
MetricPill("Next refresh", nextRefresh.formatTimestamp(), Modifier.weight(1f))
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun AccountCard(
account: AccountSummary,
@@ -183,54 +264,115 @@ private fun AccountCard(
onRefresh: () -> Unit,
onPrepareCaptcha: () -> Unit
) {
val accent = account.serviceType.accentColor()
Card(
onClick = onOpen,
shape = RoundedCornerShape(8.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.surfaceContainer
)
containerColor = MaterialTheme.colorScheme.surfaceContainer.copy(alpha = 0.92f),
contentColor = MaterialTheme.colorScheme.onSurface
),
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.45f))
) {
Column(modifier = Modifier.fillMaxWidth()) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(4.dp)
.background(accent)
)
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
verticalArrangement = Arrangement.spacedBy(13.dp)
) {
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.weight(1f)) {
Text(account.displayName, style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.Top,
modifier = Modifier.fillMaxWidth()
) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(7.dp)) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
ServiceBadge(account.serviceType)
if (!account.enabled) {
StatusChip(AccountStatus.DISABLED)
}
}
Text(
"${account.serviceType.displayName} • ${account.loginIdentifier}",
account.displayName,
style = MaterialTheme.typography.titleLarge,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
account.loginIdentifier,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
StatusChip(account.status)
Spacer(modifier = Modifier.width(10.dp))
StatusChip(if (busy) AccountStatus.REFRESHING else account.status)
}
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text("Remaining", color = MaterialTheme.colorScheme.onSurfaceVariant)
Text(account.remainingDisplay, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)
Row(verticalAlignment = Alignment.Bottom, modifier = Modifier.fillMaxWidth()) {
Column(modifier = Modifier.weight(1f)) {
Text(
"Remaining",
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.labelMedium
)
Text(
account.remainingDisplay,
style = MaterialTheme.typography.headlineMedium,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurface
)
}
Surface(
shape = RoundedCornerShape(8.dp),
color = accent.copy(alpha = 0.13f),
contentColor = accent
) {
Text(
account.refreshInterval.displayName,
style = MaterialTheme.typography.labelSmall,
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(horizontal = 9.dp, vertical = 6.dp)
)
}
}
UsageBar(
remainingBytes = account.remainingBytes,
totalBytes = account.totalBytes,
totalDisplay = account.totalDisplay
)
account.lastErrorMessage?.let {
Surface(
shape = RoundedCornerShape(8.dp),
color = MaterialTheme.colorScheme.error.copy(alpha = 0.12f),
contentColor = MaterialTheme.colorScheme.error,
modifier = Modifier.fillMaxWidth()
) {
Text(
it,
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodySmall
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(10.dp)
)
}
}
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
FilledTonalButton(
onClick = onRefresh,
enabled = !busy && account.enabled,
modifier = Modifier.weight(1f)
) {
Icon(Icons.Default.Refresh, contentDescription = null)
Icon(Icons.Default.Refresh, contentDescription = null, modifier = Modifier.size(18.dp))
Text(if (busy) "Refreshing" else "Refresh", modifier = Modifier.padding(start = 8.dp))
}
if (account.status == AccountStatus.CAPTCHA_REQUIRED) {
@@ -254,4 +396,5 @@ private fun AccountCard(
)
}
}
}
}
@@ -3,6 +3,7 @@ package net.rodakot.remaining.ui.screens
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
@@ -20,13 +21,19 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import net.rodakot.remaining.data.AppSettings
import net.rodakot.remaining.domain.RefreshInterval
import net.rodakot.remaining.domain.ThemePreference
import net.rodakot.remaining.ui.components.ModernPanel
import net.rodakot.remaining.ui.components.RemainingBackground
import net.rodakot.remaining.ui.components.SectionHeader
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -37,10 +44,25 @@ fun SettingsScreen(
onNotificationsChanged: (Boolean) -> Unit,
onDefaultRefreshChanged: (RefreshInterval) -> Unit
) {
RemainingBackground {
Scaffold(
containerColor = Color.Transparent,
topBar = {
TopAppBar(
title = { Text("Settings") },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
scrolledContainerColor = Color.Transparent
),
title = {
Column {
Text("Settings", fontWeight = FontWeight.Bold)
Text(
"App-wide defaults",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
}
},
navigationIcon = {
IconButton(onClick = onBack) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
@@ -54,42 +76,43 @@ fun SettingsScreen(
.fillMaxSize()
.padding(padding)
.verticalScroll(rememberScrollState())
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(18.dp)
.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 24.dp),
verticalArrangement = Arrangement.spacedBy(14.dp)
) {
Text("Appearance", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
ModernPanel {
SectionHeader(
title = "Appearance",
subtitle = "Choose a stable theme or follow the device setting."
)
ThemePreference.entries.forEach { option ->
FilterChip(
selected = settings.themePreference == option,
onClick = { onThemeChanged(option) },
label = { Text(option.displayName) },
modifier = Modifier.weight(1f),
modifier = Modifier.fillMaxWidth(),
shape = RoundedCornerShape(8.dp)
)
}
}
Text("Notifications", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
Column(Modifier.weight(1f)) {
Text("Global alerts", fontWeight = FontWeight.Medium)
Text(
"Controls refresh failures, captcha-needed alerts, and low-data alerts.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
}
Switch(
ModernPanel {
SettingSwitchRow(
title = "Global alerts",
description = "Controls refresh failures, captcha-needed alerts, and low-data alerts.",
checked = settings.notificationsEnabled,
onCheckedChange = onNotificationsChanged
)
}
Text("New accounts", style = MaterialTheme.typography.titleMedium, fontWeight = FontWeight.Bold)
ModernPanel {
SectionHeader(
title = "New account defaults",
subtitle = "These settings apply to accounts you connect later."
)
Text(
"Default refresh interval",
color = MaterialTheme.colorScheme.onSurfaceVariant
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
RefreshInterval.entries.chunked(2).forEach { rowOptions ->
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth()) {
@@ -103,10 +126,36 @@ fun SettingsScreen(
)
}
if (rowOptions.size == 1) {
Column(Modifier.weight(1f)) {}
Spacer(Modifier.weight(1f))
}
}
}
}
}
}
}
}
@Composable
private fun SettingSwitchRow(
title: String,
description: String,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
Text(title, fontWeight = FontWeight.SemiBold)
Text(
description,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall
)
}
Switch(checked = checked, onCheckedChange = onCheckedChange)
}
}
@@ -2,17 +2,22 @@ package net.rodakot.remaining.ui.theme
import androidx.compose.ui.graphics.Color
val Blue80 = Color(0xFF8FD8FF)
val Green80 = Color(0xFF8FE7B0)
val Amber80 = Color(0xFFFFD66B)
val SignalGreen80 = Color(0xFF98F7C7)
val Cyan80 = Color(0xFF8EEBFF)
val Rose80 = Color(0xFFFF9DB2)
val Blue40 = Color(0xFF006B8F)
val Green40 = Color(0xFF006C46)
val Amber40 = Color(0xFF765A00)
val SignalGreen40 = Color(0xFF006C54)
val Cyan40 = Color(0xFF00677A)
val Rose40 = Color(0xFF9C2945)
val DarkBackground = Color(0xFF0D1117)
val DarkSurface = Color(0xFF151B23)
val DarkSurfaceVariant = Color(0xFF222B36)
val LightBackground = Color(0xFFF7F9FC)
val DarkBackground = Color(0xFF070B0A)
val DarkSurface = Color(0xFF101613)
val DarkSurfaceLow = Color(0xFF0C110F)
val DarkSurfaceHigh = Color(0xFF17211D)
val DarkSurfaceVariant = Color(0xFF22302B)
val LightBackground = Color(0xFFF7FBF5)
val LightSurface = Color(0xFFFFFFFF)
val LightSurfaceVariant = Color(0xFFE8EEF5)
val LightSurfaceLow = Color(0xFFEDF6EF)
val LightSurfaceHigh = Color(0xFFE4F1E8)
val LightSurfaceVariant = Color(0xFFDDEBE1)
@@ -7,24 +7,67 @@ import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
private val DarkColorScheme = darkColorScheme(
primary = Blue80,
secondary = Green80,
tertiary = Amber80,
primary = SignalGreen80,
onPrimary = Color(0xFF003826),
primaryContainer = Color(0xFF0A3F31),
onPrimaryContainer = Color(0xFFC7FFE6),
secondary = Cyan80,
onSecondary = Color(0xFF003640),
secondaryContainer = Color(0xFF0B3D46),
onSecondaryContainer = Color(0xFFC5F6FF),
tertiary = Rose80,
onTertiary = Color(0xFF5A0B1F),
tertiaryContainer = Color(0xFF5D1C2B),
onTertiaryContainer = Color(0xFFFFD9E0),
background = DarkBackground,
onBackground = Color(0xFFE2EEE7),
surface = DarkSurface,
surfaceVariant = DarkSurfaceVariant
onSurface = Color(0xFFE5EEE9),
surfaceVariant = DarkSurfaceVariant,
onSurfaceVariant = Color(0xFFB7C8C0),
surfaceContainerLowest = DarkBackground,
surfaceContainerLow = DarkSurfaceLow,
surfaceContainer = DarkSurface,
surfaceContainerHigh = DarkSurfaceHigh,
surfaceContainerHighest = Color(0xFF1C2823),
outline = Color(0xFF7B9188),
outlineVariant = Color(0xFF31453D),
error = Color(0xFFFF8A9A),
onError = Color(0xFF5F0717)
)
private val LightColorScheme = lightColorScheme(
primary = Blue40,
secondary = Green40,
tertiary = Amber40,
primary = SignalGreen40,
onPrimary = Color.White,
primaryContainer = Color(0xFFC9F5DF),
onPrimaryContainer = Color(0xFF002116),
secondary = Cyan40,
onSecondary = Color.White,
secondaryContainer = Color(0xFFC4F3FF),
onSecondaryContainer = Color(0xFF001F26),
tertiary = Rose40,
onTertiary = Color.White,
tertiaryContainer = Color(0xFFFFD9E0),
onTertiaryContainer = Color(0xFF3F0011),
background = LightBackground,
onBackground = Color(0xFF17211C),
surface = LightSurface,
surfaceVariant = LightSurfaceVariant
onSurface = Color(0xFF17211C),
surfaceVariant = LightSurfaceVariant,
onSurfaceVariant = Color(0xFF53635B),
surfaceContainerLowest = Color.White,
surfaceContainerLow = LightSurfaceLow,
surfaceContainer = LightSurface,
surfaceContainerHigh = LightSurfaceHigh,
surfaceContainerHighest = Color(0xFFD8E8DD),
outline = Color(0xFF72857B),
outlineVariant = Color(0xFFC2D4C8),
error = Color(0xFFBA1A1A),
onError = Color.White
)
@Composable
@@ -8,6 +8,13 @@ import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val Typography = Typography(
displaySmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
fontSize = 34.sp,
lineHeight = 38.sp,
letterSpacing = 0.sp
),
headlineMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
@@ -15,6 +22,13 @@ val Typography = Typography(
lineHeight = 34.sp,
letterSpacing = 0.sp
),
headlineSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
fontSize = 24.sp,
lineHeight = 30.sp,
letterSpacing = 0.sp
),
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Bold,
@@ -29,11 +43,46 @@ val Typography = Typography(
lineHeight = 22.sp,
letterSpacing = 0.sp
),
titleSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 14.sp,
lineHeight = 20.sp,
letterSpacing = 0.sp
),
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.sp
),
bodyMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 14.sp,
lineHeight = 20.sp,
letterSpacing = 0.sp
),
labelLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 14.sp,
lineHeight = 20.sp,
letterSpacing = 0.sp
),
labelMedium = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
lineHeight = 16.sp,
letterSpacing = 0.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.SemiBold,
fontSize = 11.sp,
lineHeight = 14.sp,
letterSpacing = 0.sp
)
)