diff --git a/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt b/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt index 38dd14eef7..dfd4766d67 100644 --- a/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt +++ b/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListFragment.kt @@ -4,9 +4,6 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.getValue import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.activityViewModels @@ -41,24 +38,20 @@ class EventListFragment : FragmentGlobalAbstract() { ?.plus(EventListModule()) ?.inject(this) + val programEventsViewModel by activityViewModels() + + eventListViewModel.onSyncClickedListener = { eventUid -> + eventUid?.let { programEventsViewModel.eventSyncClicked.value = it } + } + + eventListViewModel.onCardClickedListener = { eventUid, orgUnitUid -> + programEventsViewModel.eventClicked.value = Pair(eventUid, orgUnitUid) + } + return ComposeView(requireContext()).apply { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { val workingListViewModel by viewModels { workingListViewModelFactory } - val programEventsViewModel by activityViewModels() - val cardClicked by eventListViewModel.onEventCardClick.collectAsState(null) - val syncClicked by eventListViewModel.onSyncClick.collectAsState(null) - - LaunchedEffect(key1 = cardClicked) { - cardClicked?.let { - programEventsViewModel.eventClicked.value = it - } - } - - LaunchedEffect(key1 = syncClicked) { - programEventsViewModel.eventSyncClicked.value = syncClicked - } - EventListScreen( eventListViewModel, workingListViewModel, diff --git a/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListViewModel.kt b/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListViewModel.kt index 36056adcb2..f352e09210 100644 --- a/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListViewModel.kt +++ b/app/src/main/java/org/dhis2/usescases/programEventDetail/eventList/EventListViewModel.kt @@ -5,14 +5,11 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData import androidx.paging.map -import io.reactivex.disposables.CompositeDisposable import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map -import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.dhis2.commons.filters.FilterManager import org.dhis2.commons.ui.model.ListCardUiModel @@ -29,11 +26,9 @@ class EventListViewModel( val cardMapper: EventCardMapper, ) : ViewModel() { - val disposable = CompositeDisposable() - private var _onSyncClick: MutableStateFlow = MutableStateFlow(null) - val onSyncClick: Flow = _onSyncClick - private var _onEventCardClick: MutableStateFlow?> = MutableStateFlow(null) - val onEventCardClick: Flow?> = _onEventCardClick + var onSyncClickedListener: (eventUid: String?) -> Unit = { _ -> } + + var onCardClickedListener: (eventUid: String, orgUnitUid: String) -> Unit = { _, _ -> } private val _displayOrgUnitName = MutableLiveData(true) val displayOrgUnitName = _displayOrgUnitName @@ -59,17 +54,15 @@ class EventListViewModel( editable = eventRepository.isEventEditable(event.uid()), displayOrgUnit = displayOrgUnitName.value ?: true, onSyncIconClick = { - onSyncIconClick( + onSyncClickedListener( eventModel.event?.uid(), ) }, onCardClick = { eventModel.event?.let { event -> - onEventCardClick( - Pair( - event.uid(), - event.organisationUnit() ?: "", - ), + onCardClickedListener( + event.uid(), + event.organisationUnit() ?: "", ) } }, @@ -81,18 +74,6 @@ class EventListViewModel( val eventList = _eventList - private fun onSyncIconClick(eventUid: String?) { - viewModelScope.launch { - _onSyncClick.emit(eventUid) - } - } - - private fun onEventCardClick(eventUidAndOrgUnit: Pair) { - viewModelScope.launch { - _onEventCardClick.emit(eventUidAndOrgUnit) - } - } - fun refreshData() { filterManager.publishData() }