Skip to content

Commit

Permalink
WTA #71 Added tab for project history
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob3075 committed Oct 16, 2024
1 parent 1996dd4 commit cebddf4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.jacob.wakatimeapp.details.ui.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.jacob.wakatimeapp.core.models.Time
import com.jacob.wakatimeapp.core.ui.WtaComponentPreviews
import com.jacob.wakatimeapp.core.ui.components.WtaSurface
import com.jacob.wakatimeapp.core.ui.theme.WakaTimeAppTheme
import com.jacob.wakatimeapp.core.ui.theme.cardHeader
import com.jacob.wakatimeapp.core.ui.theme.cardSubtitle
import com.jacob.wakatimeapp.core.ui.theme.spacing
import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.datetime.LocalDate
import kotlinx.datetime.format
import kotlinx.datetime.format.DayOfWeekNames
import kotlinx.datetime.format.MonthNames
import kotlinx.datetime.format.char

@Composable
internal fun ProjectHistory(
statsForProject: ImmutableMap<LocalDate, Time>,
modifier: Modifier = Modifier,
) {
Column(
modifier = modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.small),
) {
Text(text = "Project History", modifier = Modifier.padding(vertical = MaterialTheme.spacing.small))
statsForProject
.filter { it.value != Time.ZERO }
.forEach { localDateTimePair ->
ProjectHistoryItem(entry = localDateTimePair.toPair())
}
}
}

@Composable
fun ProjectHistoryItem(
entry: Pair<LocalDate, Time>,
modifier: Modifier = Modifier,
) {
val format =
LocalDate.Format {
dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED)
chars(", ")
monthName(MonthNames.ENGLISH_ABBREVIATED)
char(' ')
dayOfMonth()
}

WtaSurface(modifier = modifier.fillMaxWidth()) {
Column(
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.extraSmall),
modifier = Modifier.padding(MaterialTheme.spacing.small),
) {
Text(
text = entry.second.longFormattedPrint(),
style = MaterialTheme.typography.cardHeader,
modifier = Modifier.padding(start = MaterialTheme.spacing.small),
)
Text(
text = entry.first.format(format),
style = MaterialTheme.typography.cardSubtitle,
modifier = Modifier.padding(start = MaterialTheme.spacing.small),
)
}
}
}

@WtaComponentPreviews
@Composable
private fun ProjectHistoryItemPreview() {
WakaTimeAppTheme {
Surface {
ProjectHistoryItem(LocalDate.fromEpochDays(1) to Time(1, 1, 1f))
}
}
}

@WtaComponentPreviews
@Composable
private fun ProjectHistoryListPreview() {
WakaTimeAppTheme {
Surface {
ProjectHistory(
statsForProject =
mapOf(
LocalDate.fromEpochDays(1) to Time(1, 1, 1f),
LocalDate.fromEpochDays(2) to Time(1, 1, 1f),
LocalDate.fromEpochDays(3) to Time(1, 1, 1f),
).toImmutableMap(),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.jacob.wakatimeapp.details.ui.components

import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand All @@ -23,15 +22,19 @@ import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.toImmutableList
import kotlinx.datetime.LocalDate

private const val DaysInChart = 30

@Composable
internal fun TimeTab(statsForProject: ImmutableMap<LocalDate, Time>, today: LocalDate, modifier: Modifier = Modifier) {
Column(
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.small),
modifier = modifier.fillMaxSize(),
modifier = modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
) {
RecentTimeSpentChart(statsForProject, today)
QuickStatsCards()
ProjectHistory(statsForProject)
ProjectHistory(statsForProject, modifier = Modifier.padding(horizontal = MaterialTheme.spacing.small))
}
}

Expand All @@ -40,24 +43,6 @@ private fun QuickStatsCards() {
Text(text = "Quick Stats Cards")
}

@Composable
private fun ProjectHistory(statsForProject: ImmutableMap<LocalDate, Time>) {
LazyColumn {
item {
Text(text = "Project History", modifier = Modifier.padding(vertical = MaterialTheme.spacing.small))
}
items(statsForProject.toList()) { localDateTimePair ->
Text(
text = "Date: ${localDateTimePair.first}, Time: ${localDateTimePair.second}",
modifier = Modifier.border(
width = 1.dp,
color = MaterialTheme.colorScheme.primary,
),
)
}
}
}

@Composable
private fun RecentTimeSpentChart(weeklyTimeSpent: ImmutableMap<LocalDate, Time>, today: LocalDate) = Surface(
modifier = Modifier
Expand All @@ -69,10 +54,10 @@ private fun RecentTimeSpentChart(weeklyTimeSpent: ImmutableMap<LocalDate, Time>,
tonalElevation = 2.dp,
) {
VicoBarChart(
timeData = weeklyTimeSpent.values.toMutableList().takeLast(30).toImmutableList(),
timeData = weeklyTimeSpent.values.toMutableList().takeLast(DaysInChart).toImmutableList(),
xAxisFormatter = VicoBarChartData.getDefaultXAxisFormatter(today, skipCount = 5),
modifier = Modifier.padding(MaterialTheme.spacing.small),
columnWidth = 30f,
showLabel = false
showLabel = false,
)
}

0 comments on commit cebddf4

Please sign in to comment.