Skip to content

Commit c5294bf

Browse files
some updates
1 parent d71b1d0 commit c5294bf

File tree

8 files changed

+31
-30
lines changed

8 files changed

+31
-30
lines changed

Diff for: app/src/main/java/com/example/studysmart/data/repository/TaskRepositoryImpl.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class TaskRepositoryImpl @Inject constructor(
2323
return taskDao.getTaskById(taskId)
2424
}
2525

26-
override fun getUpcomingTasksForSubject(subjectInt: Int): Flow<List<Task>> {
27-
return taskDao.getTasksForSubject(subjectInt)
26+
override fun getUpcomingTasksForSubject(subjectId: Int): Flow<List<Task>> {
27+
return taskDao.getTasksForSubject(subjectId)
2828
.map { tasks -> tasks.filter { it.isComplete.not() } }
2929
.map { tasks -> sortTasks(tasks) }
3030
}
3131

32-
override fun getCompletedTasksForSubject(subjectInt: Int): Flow<List<Task>> {
33-
return taskDao.getTasksForSubject(subjectInt)
32+
override fun getCompletedTasksForSubject(subjectId: Int): Flow<List<Task>> {
33+
return taskDao.getTasksForSubject(subjectId)
3434
.map { tasks -> tasks.filter { it.isComplete } }
3535
.map { tasks -> sortTasks(tasks) }
3636
}

Diff for: app/src/main/java/com/example/studysmart/domain/model/Subject.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.example.studysmart.domain.model
22

3-
import androidx.compose.ui.graphics.Color
43
import androidx.room.Entity
54
import androidx.room.PrimaryKey
65
import com.example.studysmart.presentation.theme.gradient1

Diff for: app/src/main/java/com/example/studysmart/domain/repository/TaskRepository.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ interface TaskRepository {
1111

1212
suspend fun getTaskById(taskId: Int): Task?
1313

14-
fun getUpcomingTasksForSubject(subjectInt: Int): Flow<List<Task>>
14+
fun getUpcomingTasksForSubject(subjectId: Int): Flow<List<Task>>
1515

16-
fun getCompletedTasksForSubject(subjectInt: Int): Flow<List<Task>>
16+
fun getCompletedTasksForSubject(subjectId: Int): Flow<List<Task>>
1717

1818
fun getAllUpcomingTasks(): Flow<List<Task>>
1919
}

Diff for: app/src/main/java/com/example/studysmart/presentation/dashboard/DashboardScreen.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ import com.example.studysmart.presentation.subject.SubjectScreenNavArgs
5959
import com.example.studysmart.presentation.task.TaskScreenNavArgs
6060
import com.example.studysmart.util.SnackbarEvent
6161
import com.ramcosta.composedestinations.annotation.Destination
62+
import com.ramcosta.composedestinations.annotation.RootNavGraph
6263
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
6364
import kotlinx.coroutines.flow.SharedFlow
6465
import kotlinx.coroutines.flow.collectLatest
6566

66-
@Destination(start = true)
67+
@RootNavGraph(start = true)
68+
@Destination
6769
@Composable
6870
fun DashboardScreenRoute(
6971
navigator: DestinationsNavigator
@@ -133,9 +135,9 @@ private fun DashboardScreen(
133135
isOpen = isAddSubjectDialogOpen,
134136
subjectName = state.subjectName,
135137
goalHours = state.goalStudyHours,
138+
selectedColors = state.subjectCardColors,
136139
onSubjectNameChange = { onEvent(DashboardEvent.OnSubjectNameChange(it)) },
137140
onGoalHoursChange = { onEvent(DashboardEvent.OnGoalStudyHoursChange(it)) },
138-
selectedColors = state.subjectCardColors,
139141
onColorChange = { onEvent(DashboardEvent.OnSubjectCardColorChange(it)) },
140142
onDismissRequest = { isAddSubjectDialogOpen = false },
141143
onConfirmButtonClick = {

Diff for: app/src/main/java/com/example/studysmart/presentation/dashboard/DashboardViewModel.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ class DashboardViewModel @Inject constructor(
5454
val tasks: StateFlow<List<Task>> = taskRepository.getAllUpcomingTasks()
5555
.stateIn(
5656
scope = viewModelScope,
57-
started = SharingStarted.WhileSubscribed(5000),
57+
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 5000),
5858
initialValue = emptyList()
5959
)
6060

6161
val recentSessions: StateFlow<List<Session>> = sessionRepository.getRecentFiveSessions()
6262
.stateIn(
6363
scope = viewModelScope,
64-
started = SharingStarted.WhileSubscribed(5000),
64+
started = SharingStarted.WhileSubscribed(stopTimeoutMillis = 5000),
6565
initialValue = emptyList()
6666
)
6767

@@ -140,13 +140,13 @@ class DashboardViewModel @Inject constructor(
140140
)
141141
}
142142
_snackbarEventFlow.emit(
143-
SnackbarEvent.ShowSnackbar("Subject saved successfully")
143+
SnackbarEvent.ShowSnackbar(message = "Subject saved successfully")
144144
)
145145
} catch (e: Exception) {
146146
_snackbarEventFlow.emit(
147147
SnackbarEvent.ShowSnackbar(
148-
"Couldn't save subject. ${e.message}",
149-
SnackbarDuration.Long
148+
message = "Couldn't save subject. ${e.message}",
149+
duration = SnackbarDuration.Long
150150
)
151151
)
152152
}

Diff for: app/src/main/java/com/example/studysmart/presentation/subject/SubjectScreen.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fun SubjectScreenRoute(
8080
snackbarEvent = viewModel.snackbarEventFlow,
8181
onBackButtonClick = { navigator.navigateUp() },
8282
onAddTaskButtonClick = {
83-
val navArg = TaskScreenNavArgs(taskId = null, subjectId = -1)
83+
val navArg = TaskScreenNavArgs(taskId = null, subjectId = state.currentSubjectId)
8484
navigator.navigate(TaskScreenRouteDestination(navArgs = navArg))
8585
},
8686
onTaskCardClick = { taskId ->
@@ -203,8 +203,8 @@ private fun SubjectScreen(
203203
modifier = Modifier
204204
.fillMaxWidth()
205205
.padding(12.dp),
206-
studiedHours = state.goalStudyHours,
207-
goalHours = state.studiedHours.toString(),
206+
studiedHours = state.studiedHours.toString(),
207+
goalHours = state.goalStudyHours,
208208
progress = state.progress
209209
)
210210
}
@@ -295,7 +295,7 @@ private fun SubjectOverviewSection(
295295
goalHours: String,
296296
progress: Float
297297
) {
298-
val percentageProgress = remember(progress) {
298+
val percentageProgress = remember(key1 = progress) {
299299
(progress * 100).toInt().coerceIn(0, 100)
300300
}
301301

@@ -312,7 +312,7 @@ private fun SubjectOverviewSection(
312312
Spacer(modifier = Modifier.width(10.dp))
313313
CountCard(
314314
modifier = Modifier.weight(1f),
315-
headingText = "Study Hours",
315+
headingText = "Studied Hours",
316316
count = studiedHours
317317
)
318318
Spacer(modifier = Modifier.width(10.dp))

Diff for: app/src/main/java/com/example/studysmart/presentation/subject/SubjectViewModel.kt

+8-7
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ class SubjectViewModel @Inject constructor(
8484
}
8585
}
8686

87-
SubjectEvent.UpdateSubject -> updateSubject()
88-
SubjectEvent.DeleteSubject -> deleteSubject()
89-
SubjectEvent.DeleteSession -> {}
9087
is SubjectEvent.OnDeleteSessionButtonClick -> {}
9188
is SubjectEvent.OnTaskIsCompleteChange -> {
9289
updateTask(event.task)
9390
}
9491

92+
SubjectEvent.UpdateSubject -> updateSubject()
93+
SubjectEvent.DeleteSubject -> deleteSubject()
94+
SubjectEvent.DeleteSession -> {}
95+
9596
SubjectEvent.UpdateProgress -> {
9697
val goalStudyHours = state.value.goalStudyHours.toFloatOrNull() ?: 1f
9798
_state.update {
@@ -121,7 +122,7 @@ class SubjectViewModel @Inject constructor(
121122
_snackbarEventFlow.emit(
122123
SnackbarEvent.ShowSnackbar(
123124
message = "Couldn't update subject. ${e.message}",
124-
SnackbarDuration.Long
125+
duration = SnackbarDuration.Long
125126
)
126127
)
127128
}
@@ -136,7 +137,7 @@ class SubjectViewModel @Inject constructor(
136137
it.copy(
137138
subjectName = subject.name,
138139
goalStudyHours = subject.goalHours.toString(),
139-
subjectCardColors = subject.colors.map { Color(it) },
140+
subjectCardColors = subject.colors.map { colors -> Color(colors) },
140141
currentSubjectId = subject.subjectId
141142
)
142143
}
@@ -190,8 +191,8 @@ class SubjectViewModel @Inject constructor(
190191
} catch (e: Exception) {
191192
_snackbarEventFlow.emit(
192193
SnackbarEvent.ShowSnackbar(
193-
"Couldn't update task. ${e.message}",
194-
SnackbarDuration.Long
194+
message = "Couldn't update task. ${e.message}",
195+
duration = SnackbarDuration.Long
195196
)
196197
)
197198
}

Diff for: app/src/main/java/com/example/studysmart/presentation/task/TaskViewModel.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class TaskViewModel @Inject constructor(
119119
} catch (e: Exception) {
120120
_snackbarEventFlow.emit(
121121
SnackbarEvent.ShowSnackbar(
122-
message = "Couldn't Task subject. ${e.message}",
122+
message = "Couldn't delete task. ${e.message}",
123123
duration = SnackbarDuration.Long
124124
)
125125
)
@@ -133,8 +133,7 @@ class TaskViewModel @Inject constructor(
133133
if (state.subjectId == null || state.relatedToSubject == null) {
134134
_snackbarEventFlow.emit(
135135
SnackbarEvent.ShowSnackbar(
136-
message = "Please select subject related to the task",
137-
SnackbarDuration.Long
136+
message = "Please select subject related to the task"
138137
)
139138
)
140139
return@launch
@@ -160,7 +159,7 @@ class TaskViewModel @Inject constructor(
160159
_snackbarEventFlow.emit(
161160
SnackbarEvent.ShowSnackbar(
162161
message = "Couldn't save task. ${e.message}",
163-
SnackbarDuration.Long
162+
duration = SnackbarDuration.Long
164163
)
165164
)
166165
}

0 commit comments

Comments
 (0)