Skip to content

Commit

Permalink
[ANDROAPP-6417] Can't click same card twice in event list (#3771)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan authored Aug 20, 2024
1 parent aa5fedc commit 674ce41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,24 +38,20 @@ class EventListFragment : FragmentGlobalAbstract() {
?.plus(EventListModule())
?.inject(this)

val programEventsViewModel by activityViewModels<ProgramEventDetailViewModel>()

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<WorkingListViewModel> { workingListViewModelFactory }
val programEventsViewModel by activityViewModels<ProgramEventDetailViewModel>()
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,11 +26,9 @@ class EventListViewModel(
val cardMapper: EventCardMapper,
) : ViewModel() {

val disposable = CompositeDisposable()
private var _onSyncClick: MutableStateFlow<String?> = MutableStateFlow(null)
val onSyncClick: Flow<String?> = _onSyncClick
private var _onEventCardClick: MutableStateFlow<Pair<String, String>?> = MutableStateFlow(null)
val onEventCardClick: Flow<Pair<String, String>?> = _onEventCardClick
var onSyncClickedListener: (eventUid: String?) -> Unit = { _ -> }

var onCardClickedListener: (eventUid: String, orgUnitUid: String) -> Unit = { _, _ -> }

private val _displayOrgUnitName = MutableLiveData(true)
val displayOrgUnitName = _displayOrgUnitName
Expand All @@ -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() ?: "",
)
}
},
Expand All @@ -81,18 +74,6 @@ class EventListViewModel(

val eventList = _eventList

private fun onSyncIconClick(eventUid: String?) {
viewModelScope.launch {
_onSyncClick.emit(eventUid)
}
}

private fun onEventCardClick(eventUidAndOrgUnit: Pair<String, String>) {
viewModelScope.launch {
_onEventCardClick.emit(eventUidAndOrgUnit)
}
}

fun refreshData() {
filterManager.publishData()
}
Expand Down

0 comments on commit 674ce41

Please sign in to comment.