Skip to content

Commit c93bdf5

Browse files
Fix: Move DB operations to IO dispatcher in FeedbackDetailViewModel
The `loadFeedback`, `closeFeedback`, and `addReply` functions in `FeedbackDetailViewModel` were performing database operations on the main thread, which could lead to UI unresponsiveness (ANR). This change wraps the repository calls within `viewModelScope.launch(Dispatchers.IO)` to ensure they are executed on a background thread.
1 parent 83a17ba commit c93bdf5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

app/src/main/java/org/ole/planet/myplanet/ui/feedback/FeedbackDetailViewModel.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ class FeedbackDetailViewModel @Inject constructor(
2727
val events: SharedFlow<FeedbackDetailEvent> = _events.asSharedFlow()
2828

2929
fun loadFeedback(id: String?) {
30-
viewModelScope.launch {
30+
viewModelScope.launch(Dispatchers.IO) {
3131
_feedback.value = feedbackRepository.getFeedbackById(id)
3232
}
3333
}
3434

3535
fun closeFeedback(id: String?) {
36-
viewModelScope.launch {
36+
viewModelScope.launch(Dispatchers.IO) {
3737
feedbackRepository.closeFeedback(id)
3838
_feedback.value = feedbackRepository.getFeedbackById(id)
3939
_events.emit(FeedbackDetailEvent.CloseFeedbackSuccess)
4040
}
4141
}
4242

4343
fun addReply(id: String?, obj: JsonObject) {
44-
viewModelScope.launch {
44+
viewModelScope.launch(Dispatchers.IO) {
4545
feedbackRepository.addReply(id, obj)
4646
_feedback.value = feedbackRepository.getFeedbackById(id)
4747
}

0 commit comments

Comments
 (0)