Skip to content

Commit

Permalink
minor refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob3075 committed Jan 16, 2025
1 parent ae0bf2b commit 7983f58
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal fun ColumnScope.ChipContent(
Text(
text = cardHeading,
color = gradient.onStartColor,
style = MaterialTheme.typography.titleLarge,
style = statValueTextStyle,
modifier = Modifier
.removeFontPadding(statValueTextStyle)
.graphicsLayer {
Expand Down Expand Up @@ -76,15 +76,16 @@ internal fun BoxScope.CardContent(
Text(
text = cardHeading,
textAlign = TextAlign.End,
style = MaterialTheme.typography.displayLarge,
style = MaterialTheme.typography.displaySmall,
color = gradient.onEndColor,
modifier = Modifier.removeFontPadding(MaterialTheme.typography.displayLarge),
modifier = Modifier.removeFontPadding(MaterialTheme.typography.displaySmall),
)
Text(
text = cardSubHeading,
style = MaterialTheme.typography.cardContent,
color = gradient.onStartColor,
)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.jacob.wakatimeapp.core.models.Streak
import com.jacob.wakatimeapp.core.ui.components.cards.FlippableStatsChip
import com.jacob.wakatimeapp.core.ui.theme.assets
Expand All @@ -31,7 +32,7 @@ internal fun ProjectStreakChips(detailsPageData: DetailsPageViewState.Loaded, mo
cardHeading = "${detailsPageData.longestStreakInProject.days} Days",
cardSubHeading = "Longest Streak",
gradient = MaterialTheme.gradients.shifter,
statValueTextStyle = MaterialTheme.typography.titleMedium,
statValueTextStyle = MaterialTheme.typography.headlineSmall,
)
},
backContent = {
Expand All @@ -51,7 +52,7 @@ internal fun ProjectStreakChips(detailsPageData: DetailsPageViewState.Loaded, mo
cardHeading = "${detailsPageData.currentStreakInProject.days} Days",
cardSubHeading = "Current Streak",
gradient = MaterialTheme.gradients.reef,
statValueTextStyle = MaterialTheme.typography.titleMedium,
statValueTextStyle = MaterialTheme.typography.headlineSmall,
)
},
backContent = { StreakRangeDisplay(detailsPageData.currentStreakInProject, MaterialTheme.gradients.reef) },
Expand All @@ -64,7 +65,9 @@ private fun StreakRangeDisplay(streak: Streak, gradient: Gradient) {
Text(
text = streak.formattedPrintRange(),
color = gradient.onStartColor,
style = MaterialTheme.typography.bodyLarge,
style = MaterialTheme.typography.titleSmall.copy(
fontSize = 18.sp
),
)
Text(
text = "Streak Range",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,42 @@ internal fun QuickStatsCards(detailsPageData: DetailsPageViewState.Loaded) {
FlippableStatsChip(
modifier = Modifier.weight(1f),
gradient = MaterialTheme.gradients.quepal,
iconId = MaterialTheme.assets.icons.calendar,
frontContent = {
ChipContent(
cardSubHeading = "Start date",
cardHeading = detailsPageData.startDate.format(format),
gradient = MaterialTheme.gradients.quepal,
statValueTextStyle = MaterialTheme.typography.titleMedium,
statValueTextStyle = MaterialTheme.typography.titleLarge,
)
},
backContent = {
ChipContent(
cardSubHeading = "No. of days worked",
cardHeading = detailsPageData.numberOfDaysWorked.toString(),
gradient = MaterialTheme.gradients.quepal,
statValueTextStyle = MaterialTheme.typography.titleMedium,
statValueTextStyle = MaterialTheme.typography.headlineSmall,
)
},
)
FlippableStatsChip(
modifier = Modifier.weight(1f),
gradient = MaterialTheme.gradients.flare,
iconId = MaterialTheme.assets.icons.calendar,
frontContent = {
ChipContent(
cardHeading = detailsPageData.dayMostWorked.format(format),
cardSubHeading = "Day Most Worked",
gradient = MaterialTheme.gradients.flare,
statValueTextStyle = MaterialTheme.typography.titleMedium,
statValueTextStyle = MaterialTheme.typography.titleLarge,
)
},
backContent = {
ChipContent(
cardHeading = detailsPageData.maxTimeWorkedInDay.formattedPrint(),
cardSubHeading = "Most Time in 1 Day",
gradient = MaterialTheme.gradients.flare,
statValueTextStyle = MaterialTheme.typography.titleMedium,
statValueTextStyle = MaterialTheme.typography.headlineSmall,
)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,24 @@ fun List<ProjectPerDay>.toModel(): ImmutableList<Project> {

fun List<DayWithProjects>.toLast7RangeDaysStats(): Last7DaysStats {
val mostUsedLanguage = flatMap {
it.projectsForDay
.flatMap { projectPerDay -> projectPerDay.languages.values }
}.maxByOrNull { it.time.totalSeconds }
it.projectsForDay.map { projectPerDay -> projectPerDay.languages.mostUsed }
}.filterNotNull()
.maxByOrNull { it.time.totalSeconds }

val mostUsedEditor = flatMap {
it.projectsForDay
.flatMap { projectPerDay -> projectPerDay.editors.values }
}.maxByOrNull { it.time.totalSeconds }
it.projectsForDay.map { projectPerDay -> projectPerDay.editors.mostUsed }
}.filterNotNull()
.maxByOrNull { it.time.totalSeconds }

val mostUsedOperatingSystem = flatMap {
it.projectsForDay
.flatMap { projectPerDay -> projectPerDay.operatingSystems.values }
}.maxByOrNull { it.time.totalSeconds }
it.projectsForDay.map { projectPerDay -> projectPerDay.operatingSystems.mostUsed }
}.filterNotNull()
.maxByOrNull { it.time.totalSeconds }

val todaysStats = maxByOrNull { it.day.date }
val projectWorkedOnToday = (todaysStats?.projectsForDay ?: emptyList()).toModel()
val projectWorkedOnToday = (todaysStats?.projectsForDay ?: emptyList())
.filter { it.grandTotal != Time.ZERO }
.toModel()
return Last7DaysStats(
timeSpentToday = todaysStats?.day?.grandTotal ?: Time.ZERO,
projectsWorkedOn = projectWorkedOnToday,
Expand Down

0 comments on commit 7983f58

Please sign in to comment.