-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using activeSurveyFlow to make flow async #2890
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.stateIn | ||
|
@@ -82,7 +83,7 @@ internal constructor( | |
private val submissionRepository: SubmissionRepository, | ||
private val offlineUuidGenerator: OfflineUuidGenerator, | ||
locationOfInterestRepository: LocationOfInterestRepository, | ||
surveyRepository: SurveyRepository, | ||
private val surveyRepository: SurveyRepository, | ||
) : AbstractViewModel() { | ||
|
||
private val _uiState: MutableStateFlow<UiState?> = MutableStateFlow(null) | ||
|
@@ -97,8 +98,15 @@ internal constructor( | |
private var shouldLoadFromDraft: Boolean = savedStateHandle[TASK_SHOULD_LOAD_FROM_DRAFT] ?: false | ||
private var draftDeltas: List<ValueDelta>? = null | ||
|
||
private val activeSurvey: Survey = requireNotNull(surveyRepository.activeSurvey) | ||
private val job: Job = activeSurvey.getJob(jobId) ?: error("couldn't retrieve job for $jobId") | ||
private val _activeSurvey = MutableStateFlow<Survey?>(null) | ||
val activeSurvey = _activeSurvey.asStateFlow() | ||
|
||
init { | ||
viewModelScope.launch { surveyRepository.activeSurveyFlow.collect { _activeSurvey.value = it } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't |
||
} | ||
|
||
private val job: Job = | ||
activeSurvey.value?.getJob(jobId) ?: error("couldn't retrieve job for $jobId") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling |
||
private var customLoiName: String? | ||
get() = savedStateHandle[TASK_LOI_NAME_KEY] | ||
set(value) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean for this to be make public? I don't see a use anywhere else.