refactor FeedEntry
This commit is contained in:
parent
9df80f4f93
commit
08c779030e
3 changed files with 119 additions and 76 deletions
|
@ -3,10 +3,13 @@ package be.ugent.sel.studeez.common.composable
|
|||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
@Composable
|
||||
|
@ -23,4 +26,14 @@ fun Headline(
|
|||
fontSize = 34.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DateText(date: String) {
|
||||
Text(
|
||||
text = date,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(horizontal = 10.dp)
|
||||
)
|
||||
}
|
|
@ -1,26 +1,19 @@
|
|||
package be.ugent.sel.studeez.screens.home
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import be.ugent.sel.studeez.R
|
||||
import be.ugent.sel.studeez.common.composable.StealthButton
|
||||
import be.ugent.sel.studeez.data.local.models.FeedEntry
|
||||
import be.ugent.sel.studeez.common.composable.DateText
|
||||
import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds
|
||||
|
||||
@Composable
|
||||
|
@ -29,10 +22,10 @@ fun Feed(
|
|||
viewModel: FeedViewModel = hiltViewModel()
|
||||
) {
|
||||
val feedEntries = viewModel.getFeedEntries().collectAsState(initial = emptyMap())
|
||||
|
||||
|
||||
LazyColumn {
|
||||
|
||||
items(feedEntries.value.toList()) {(date, feedEntries) ->
|
||||
items(feedEntries.value.toList()) { (date, feedEntries) ->
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
modifier = Modifier
|
||||
|
@ -49,7 +42,7 @@ fun Feed(
|
|||
)
|
||||
}
|
||||
feedEntries.forEach { feedEntry ->
|
||||
FeedEntryCard(feedEntry = feedEntry) {
|
||||
FeedEntry(feedEntry = feedEntry) {
|
||||
viewModel.continueWithTask(open, feedEntry.subjectId, feedEntry.taskId)
|
||||
}
|
||||
}
|
||||
|
@ -58,70 +51,11 @@ fun Feed(
|
|||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun DateText(date: String) {
|
||||
Text(
|
||||
text = date,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(horizontal = 10.dp)
|
||||
fun FeedPreview() {
|
||||
Feed(
|
||||
open = {},
|
||||
viewModel = hiltViewModel(),
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FeedEntryCard(
|
||||
feedEntry: FeedEntry,
|
||||
continueWithTask: () -> Unit,
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 10.dp, vertical = 5.dp),
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.padding(start = 10.dp)
|
||||
.weight(3f)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(20.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color(feedEntry.argb_color)),
|
||||
)
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(0.dp)
|
||||
) {
|
||||
Text(
|
||||
text = feedEntry.subJectName,
|
||||
fontWeight = FontWeight.Bold,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(text = feedEntry.taskName)
|
||||
Text(text = HoursMinutesSeconds(feedEntry.totalStudyTime).toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
StealthButton(
|
||||
text = R.string.start,
|
||||
modifier = Modifier
|
||||
.padding(start = 10.dp, end = 5.dp)
|
||||
.weight(1f)
|
||||
) {
|
||||
continueWithTask()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package be.ugent.sel.studeez.screens.home
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import be.ugent.sel.studeez.R
|
||||
import be.ugent.sel.studeez.common.composable.StealthButton
|
||||
import be.ugent.sel.studeez.data.local.models.FeedEntry
|
||||
import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds
|
||||
|
||||
@Composable
|
||||
fun FeedEntry(
|
||||
feedEntry: FeedEntry,
|
||||
continueWithTask: () -> Unit,
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 10.dp, vertical = 5.dp),
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.padding(start = 10.dp)
|
||||
.weight(11f)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(20.dp)
|
||||
.clip(CircleShape)
|
||||
.background(Color(feedEntry.argb_color)),
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(0.dp)
|
||||
) {
|
||||
Text(
|
||||
text = feedEntry.subJectName,
|
||||
fontWeight = FontWeight.Bold,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
)
|
||||
Text(
|
||||
text = feedEntry.taskName,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
Text(text = HoursMinutesSeconds(feedEntry.totalStudyTime).toString())
|
||||
}
|
||||
}
|
||||
StealthButton(
|
||||
text = R.string.continue_task,
|
||||
modifier = Modifier
|
||||
.padding(start = 10.dp, end = 5.dp)
|
||||
.weight(6f)
|
||||
) {
|
||||
continueWithTask()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun FeedEntryPreview() {
|
||||
FeedEntry(
|
||||
continueWithTask = {},
|
||||
feedEntry = FeedEntry(
|
||||
argb_color = 0xFFFFD200,
|
||||
subJectName = "Test Subject",
|
||||
taskName = "Test Taskkkkkkkkkkkkkkkkkkkkkkkkk",
|
||||
totalStudyTime = 20,
|
||||
)
|
||||
)
|
||||
}
|
Reference in a new issue