11package com.edricchan.studybuddy.features.tasks.detail.data.impl
22
3- import com.edricchan.studybuddy.features.tasks.data.model.TodoItem
4- import com.edricchan.studybuddy.features.tasks.data.model.TodoProject
5- import com.edricchan.studybuddy.features.tasks.data.repo.TaskProjectDataSource
63import com.edricchan.studybuddy.features.tasks.data.repo.TaskRepository
74import com.edricchan.studybuddy.features.tasks.detail.data.TaskDetailData
85import com.edricchan.studybuddy.features.tasks.detail.data.state.TaskDetailState
96import dagger.assisted.Assisted
107import dagger.assisted.AssistedFactory
118import dagger.assisted.AssistedInject
129import kotlinx.coroutines.CoroutineScope
13- import kotlinx.coroutines.ExperimentalCoroutinesApi
1410import kotlinx.coroutines.flow.SharingStarted
1511import kotlinx.coroutines.flow.StateFlow
1612import kotlinx.coroutines.flow.catch
17- import kotlinx.coroutines.flow.flatMapConcat
18- import kotlinx.coroutines.flow.flowOf
1913import kotlinx.coroutines.flow.map
2014import kotlinx.coroutines.flow.stateIn
2115
2216class FirestoreTaskDetailData @AssistedInject constructor(
2317 @Assisted private val selectedTaskId : String ,
2418 @Assisted private val coroutineScope : CoroutineScope ,
25- repo : TaskRepository ,
26- private val projectSource : TaskProjectDataSource
19+ repo : TaskRepository
2720) : TaskDetailData {
2821 @AssistedFactory
2922 fun interface Factory {
@@ -32,17 +25,6 @@ class FirestoreTaskDetailData @AssistedInject constructor(
3225
3326 override val currentTaskId: String = selectedTaskId
3427
35- @Deprecated(
36- " There is an ambiguity between having no such task item " +
37- " existing (represented by `null`) and the initial `null` value when the underlying " +
38- " flow has yet to start emitting values. Use the currentTaskStateFlow property " +
39- " instead which uses a sealed interface to differentiate between these 2 possible " +
40- " states. Note that the state class uses the domain-specific TaskItem data class " +
41- " which also provides access to the project-related information, if any."
42- )
43- override val currTaskFlow: StateFlow <TodoItem ?> = repo.observeTask(selectedTaskId)
44- .stateIn(coroutineScope, SharingStarted .WhileSubscribed (), null )
45-
4628 override val currentTaskStateFlow: StateFlow <TaskDetailState > =
4729 repo.observeTaskById(selectedTaskId)
4830 .map {
@@ -55,16 +37,4 @@ class FirestoreTaskDetailData @AssistedInject constructor(
5537 started = SharingStarted .WhileSubscribed (),
5638 initialValue = TaskDetailState .Loading
5739 )
58-
59- @Suppress(" DEPRECATION" )
60- @Deprecated(
61- " The project data is now available in the TaskItem domain class. " +
62- " To get the current task data, use the currentTaskStateFlow property"
63- )
64- @OptIn(ExperimentalCoroutinesApi ::class )
65- override val currTaskProjectFlow: StateFlow <TodoProject ?> = currTaskFlow
66- .flatMapConcat { item ->
67- item?.project?.id?.let (projectSource::get) ? : flowOf(null )
68- }
69- .stateIn(coroutineScope, SharingStarted .WhileSubscribed (), null )
7040}
0 commit comments