ADD: history
This commit is contained in:
parent
85b233ad7e
commit
70b83d7900
2 changed files with 125 additions and 17 deletions
|
@ -57,7 +57,10 @@ fun SoulEchoApp(moodViewModel: MoodViewModel) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
"history" -> {
|
"history" -> {
|
||||||
HistorySection()
|
HistorySection(
|
||||||
|
moodViewModel = moodViewModel,
|
||||||
|
paddingValues = paddingValues,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,137 @@
|
||||||
|
|
||||||
package de.webfussel.soulecho.history
|
package de.webfussel.soulecho.history
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import de.webfussel.soulecho.data.entity.MoodEntity
|
||||||
|
import de.webfussel.soulecho.mood.Moods.getMoodById
|
||||||
|
import de.webfussel.soulecho.ui.theme.getColorForMood
|
||||||
|
import de.webfussel.soulecho.viewmodel.MoodViewModel
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HistorySection() {
|
fun HistorySection(
|
||||||
Column(
|
moodViewModel: MoodViewModel,
|
||||||
|
paddingValues: PaddingValues = PaddingValues(0.dp)
|
||||||
|
) {
|
||||||
|
val allMoods by moodViewModel.allMoods.collectAsState(initial = emptyList())
|
||||||
|
|
||||||
|
LazyColumn(
|
||||||
|
contentPadding = PaddingValues(
|
||||||
|
top = paddingValues.calculateTopPadding(),
|
||||||
|
bottom = paddingValues.calculateBottomPadding(),
|
||||||
|
),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize(),
|
||||||
.padding(16.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center
|
|
||||||
) {
|
) {
|
||||||
Text(
|
if (allMoods.isEmpty()) {
|
||||||
text = "Verlauf",
|
item {
|
||||||
style = MaterialTheme.typography.headlineMedium
|
EmptyHistoryCard()
|
||||||
)
|
}
|
||||||
|
} else {
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
items(
|
||||||
|
items = allMoods,
|
||||||
Text(
|
key = { moodEntity -> moodEntity.id }
|
||||||
text = "Hier wird der Stimmungsverlauf angezeigt",
|
) { moodEntity ->
|
||||||
style = MaterialTheme.typography.bodyLarge
|
MoodHistoryCard(
|
||||||
)
|
moodEntity = moodEntity,
|
||||||
|
onDelete = { moodViewModel.deleteMood(it) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MoodHistoryCard(
|
||||||
|
moodEntity: MoodEntity,
|
||||||
|
onDelete: (MoodEntity) -> Unit
|
||||||
|
) {
|
||||||
|
Column (
|
||||||
|
modifier = Modifier
|
||||||
|
.background(Color.White)
|
||||||
|
.padding(16.dp),
|
||||||
|
){
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
val currentMood = getMoodById(moodEntity.mood)
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(currentMood.icon),
|
||||||
|
contentDescription = currentMood.label,
|
||||||
|
tint = getColorForMood(moodEntity.mood).fg,
|
||||||
|
modifier = Modifier.size(48.dp)
|
||||||
|
)
|
||||||
|
Column (
|
||||||
|
modifier = Modifier.padding(start = 16.dp)
|
||||||
|
){
|
||||||
|
Text(
|
||||||
|
text = currentMood.label,
|
||||||
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = moodEntity.info,
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(
|
||||||
|
text = moodEntity.timestamp.format(
|
||||||
|
DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
||||||
|
),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = Color.Black,
|
||||||
|
modifier = Modifier.padding(top = 4.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
HorizontalDivider(
|
||||||
|
thickness = 1.dp,
|
||||||
|
color = Color.LightGray,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun EmptyHistoryCard() {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(32.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Keine Stimmungen gefunden",
|
||||||
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "Beginnen Sie damit, Ihre erste Stimmung zu erfassen!",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.padding(top = 8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue