Improve "Meny" tab UI with Material3 card-based grid tiles for modern look and feel

This commit is contained in:
2025-10-01 20:40:55 +02:00
parent b3c98570a7
commit 704342b6e2

View File

@@ -4,10 +4,15 @@ 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.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.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Bookmark
@@ -22,6 +27,8 @@ import androidx.compose.material.icons.filled.Place
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
@@ -47,7 +54,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.decodeToImageBitmap
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import app.cash.sqldelight.coroutines.asFlow // SQLDelight coroutine-extensions (Flow-stöd för queries)
@@ -548,41 +555,33 @@ fun KlottrAppShell(
modifier = Modifier.padding(16.dp)
)
// Fält med menyval
Column(
LazyVerticalGrid(
columns = GridCells.Fixed(3),
modifier = Modifier
.fillMaxSize()
.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
verticalArrangement = Arrangement.spacedBy(12.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
MenuItem(icon = Icons.Filled.Settings, label = "Inställningar") {
showSettings = true
}
MenuItem(icon = Icons.Filled.Info, label = "Om") {
showAbout = true
}
MenuItem(icon = Icons.Filled.Person, label = "Konto") {
// TODO: senare
}
MenuItem(icon = Icons.Filled.Bookmark, label = "Bokmärken") {
// TODO: senare
}
MenuItem(icon = Icons.Filled.Create, label = "Mitt klotter") {
// TODO: senare
}
MenuItem(
icon = Icons.Filled.Login,
label = if (loggedIn) "Logga ut" else "Logga in"
) {
if (loggedIn) {
onLogout()
} else {
onLogin()
items(listOf(
Triple(Icons.Filled.Settings, "Inställningar") { showSettings = true },
Triple(Icons.Filled.Info, "Om") { showAbout = true },
Triple(Icons.Filled.Person, "Konto") { },
Triple(Icons.Filled.Bookmark, "Bokmärken") { },
Triple(Icons.Filled.Create, "Mitt klotter") { },
Triple(
Icons.Filled.Login,
if (loggedIn) "Logga ut" else "Logga in"
) {
if (loggedIn) onLogout() else onLogin()
}
)) { (icon, label, action) ->
MenuTile(icon = icon, label = label, onClick = action)
}
}
}
}
else -> {
Box(modifier = Modifier.padding(innerPadding)) {
Text("Här kommer ${selectedTab}-sidan")
@@ -1333,3 +1332,34 @@ private fun MenuItem(icon: ImageVector, label: String, onClick: () -> Unit) {
}
}
}
@Composable
private fun MenuTile(icon: ImageVector, label: String, onClick: () -> Unit) {
Card(
onClick = onClick,
modifier = Modifier.size(110.dp),
shape = MaterialTheme.shapes.medium,
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(12.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Icon(
icon,
contentDescription = label,
modifier = Modifier.size(32.dp),
tint = MaterialTheme.colorScheme.primary
)
Spacer(modifier = Modifier.height(8.dp))
Text(
label,
style = MaterialTheme.typography.bodySmall,
textAlign = TextAlign.Center
)
}
}
}