Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 124 additions & 100 deletions app/src/main/java/com/markel/flowstate/MainActivity.kt

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions app/src/main/java/com/markel/flowstate/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.markel.flowstate

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.markel.flowstate.core.data.UserPreferencesRepository
import com.markel.flowstate.navigation.Screen
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(
private val userPreferencesRepository: UserPreferencesRepository
) : ViewModel() {

private val _startDestination = MutableStateFlow<String?>(null)
val startDestination = _startDestination.asStateFlow()

init {
viewModelScope.launch {
userPreferencesRepository.lastTabRoute.collect { route ->
// If there isn't a saved route, go to Tasks by default
_startDestination.value = route ?: Screen.Tasks.route
}
}
}

fun saveLastTab(route: String) {
viewModelScope.launch {
userPreferencesRepository.saveLastTabRoute(route)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.Flow
Expand All @@ -19,6 +20,9 @@ class UserPreferencesRepository @Inject constructor(
@ApplicationContext private val context: Context
) {
private val IS_GRID_VIEW = booleanPreferencesKey("is_grid_view")
val lastTabRoute: Flow<String?> = context.dataStore.data.map { preferences ->
preferences[stringPreferencesKey("last_tab_route")]
}

val isGridView: Flow<Boolean> = context.dataStore.data
.map { preferences -> preferences[IS_GRID_VIEW] ?: false }
Expand All @@ -28,4 +32,10 @@ class UserPreferencesRepository @Inject constructor(
preferences[IS_GRID_VIEW] = isGrid
}
}

suspend fun saveLastTabRoute(route: String) {
context.dataStore.edit { preferences ->
preferences[stringPreferencesKey("last_tab_route")] = route
}
}
}
4 changes: 4 additions & 0 deletions feature/habits/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)

testImplementation(project(":core:testing"))
testImplementation(libs.turbine)
testImplementation(libs.mockk)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,16 @@ class HabitViewModel @Inject constructor(
habitRepository.getAllEntries(),
_showAddDialog
) { habits, allEntries, showDialog ->
val today = LocalDate.now()
val weekStart = today.with(java.time.DayOfWeek.MONDAY)
val weekDays = (0..6).map { weekStart.plusDays(it.toLong()).toEpochDay() }.toSet()

val weekEntriesByHabit = allEntries
.filter { it.epochDay in weekDays }
val allEntriesByHabit = allEntries
.groupBy({ it.habitId }, { it.epochDay })
.mapValues { it.value.toSet() }

HabitUiState.Success(
habits = habits,
weekEntriesByHabit = weekEntriesByHabit,
weekEntriesByHabit = allEntriesByHabit,
showAddDialog = showDialog,
completedToday = habits.count { hw ->
LocalDate.now().toEpochDay() in (weekEntriesByHabit[hw.habit.id] ?: emptySet())
LocalDate.now().toEpochDay() in (allEntriesByHabit[hw.habit.id] ?: emptySet())
},
totalHabits = habits.size,
motivationalMessageIndex = LocalDate.now().dayOfYear % 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fun HabitCard(

// ── WeekCalendar ────────────────────────
WeekCalendar(
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp),
contentPadding = PaddingValues(horizontal = 0.dp, vertical = 4.dp),
state = weekState,
dayContent = { weekDay ->
val date = weekDay.date
Expand All @@ -139,15 +139,15 @@ fun HabitCard(
val cornerStart by animateDpAsState(
targetValue = when {
isDone && donePrev -> 0.dp
else -> 20.dp
else -> 20.dp
},
animationSpec = spring(stiffness = 400f),
label = "corner_start_${date.dayOfMonth}"
)
val cornerEnd by animateDpAsState(
targetValue = when {
isDone && doneNext -> 0.dp
else -> 20.dp
else -> 20.dp
},
animationSpec = spring(stiffness = 400f),
label = "corner_end_${date.dayOfMonth}"
Expand Down Expand Up @@ -185,7 +185,7 @@ fun HabitCard(
) {
Text(
text = date.dayOfMonth.toString(),
style = MaterialTheme.typography.bodyMedium,
style = MaterialTheme.typography.bodyLarge,
fontWeight = if (isToday) FontWeight.Bold else FontWeight.Normal,
color = when {
isDone && !isFuture -> Color.White
Expand All @@ -196,9 +196,9 @@ fun HabitCard(
)
Text(
text = date.dayOfWeek
.getDisplayName(java.time.format.TextStyle.NARROW, LocalLocale.current.platformLocale)
.getDisplayName(java.time.format.TextStyle.SHORT, LocalLocale.current.platformLocale)
.uppercase(),
style = MaterialTheme.typography.labelSmall,
style = MaterialTheme.typography.labelMedium,
fontSize = 10.sp,
color = when {
isDone && !isFuture -> Color.White.copy(alpha = 0.8f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fun RadarChart(
val textMeasurer = rememberTextMeasurer()
val gridColor = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.4f)
val labelColor = MaterialTheme.colorScheme.onSurfaceVariant
val labelColorStrong = habitColor

val maxVal = dayOfWeekCompletions.values.maxOrNull()?.takeIf { it > 0 } ?: 1
val values = (1..7).map { dow ->
Expand Down Expand Up @@ -98,16 +97,16 @@ fun RadarChart(
val dayMeasured = textMeasurer.measure(
dayLabel,
TextStyle(
fontSize = 11.sp,
fontSize = 14.sp,
fontWeight = if (isStrong) FontWeight.Medium else FontWeight.Normal,
color = if (isStrong) labelColorStrong else labelColor
color = if (isStrong) habitColor else labelColor
)
)
val pctMeasured = textMeasurer.measure(
pctLabel,
TextStyle(
fontSize = 9.sp,
color = if (isStrong) labelColorStrong.copy(alpha = 0.7f)
fontSize = 12.sp,
color = if (isStrong) habitColor.copy(alpha = 0.7f)
else labelColor.copy(alpha = 0.6f)
)
)
Expand Down

This file was deleted.

Loading
Loading