11package ro.code4.monitorizarevot.ui.forms
22
33import android.annotation.SuppressLint
4- import android.view.View
54import androidx.lifecycle.LiveData
65import androidx.lifecycle.MediatorLiveData
76import androidx.lifecycle.MutableLiveData
@@ -26,7 +25,7 @@ class FormsViewModel : BaseFormViewModel() {
2625 private val formsLiveData = MutableLiveData <ArrayList <ListItem >>()
2726 private val selectedFormLiveData = MutableLiveData <FormDetails >()
2827 private val selectedQuestionLiveData = MutableLiveData <Pair <FormDetails , Question >>()
29- private val syncVisibilityLiveData = MediatorLiveData <Int >()
28+ private val unSyncedDataCountLiveData = MediatorLiveData <Int >()
3029 private val navigateToNotesLiveData = MutableLiveData <Question ?>()
3130 private val pollingStationLiveData = MutableLiveData <PollingStationInfo >()
3231
@@ -36,31 +35,23 @@ class FormsViewModel : BaseFormViewModel() {
3635 }
3736
3837 private fun subscribe () {
39-
4038 val notSyncedQuestionsCount = repository.getNotSyncedQuestions()
4139 val notSyncedNotesCount = repository.getNotSyncedNotes()
4240 val notSyncedPollingStationsCount = repository.getNotSyncedPollingStationsCount()
4341 fun update () {
44- syncVisibilityLiveData.value =
45- if ((notSyncedQuestionsCount.value ? : 0 ) + (notSyncedNotesCount.value
46- ? : 0 ) + (notSyncedPollingStationsCount.value ? : 0 ) > 0
47- ) View .VISIBLE else View .GONE
48- }
49- syncVisibilityLiveData.addSource(notSyncedQuestionsCount) {
50- update()
51- }
52- syncVisibilityLiveData.addSource(notSyncedNotesCount) {
53- update()
54- }
55- syncVisibilityLiveData.addSource(notSyncedPollingStationsCount) {
56- update()
42+ unSyncedDataCountLiveData.value =
43+ (notSyncedQuestionsCount.value ? : 0 ) + (notSyncedNotesCount.value ? : 0 ) +
44+ (notSyncedPollingStationsCount.value ? : 0 )
5745 }
46+ unSyncedDataCountLiveData.addSource(notSyncedQuestionsCount) { update() }
47+ unSyncedDataCountLiveData.addSource(notSyncedNotesCount) { update() }
48+ unSyncedDataCountLiveData.addSource(notSyncedPollingStationsCount) { update() }
5849
5950 disposables.add(Observable .combineLatest(
6051 repository.getAnswers(countyCode, pollingStationNumber),
6152 repository.getFormsWithQuestions(),
62- BiFunction <List <AnsweredQuestionPOJO >, List <FormWithSections >, Pair <List <AnsweredQuestionPOJO >, List <FormWithSections >>> {
63- t1, t2 -> Pair (t1, t2)
53+ BiFunction <List <AnsweredQuestionPOJO >, List <FormWithSections >, Pair <List <AnsweredQuestionPOJO >, List <FormWithSections >>> { t1, t2 ->
54+ Pair (t1, t2)
6455 }
6556 ).subscribe {
6657 processList(it.first, it.second)
@@ -136,7 +127,7 @@ class FormsViewModel : BaseFormViewModel() {
136127 selectedQuestionLiveData.postValue(Pair (selectedFormLiveData.value!! , question))
137128 }
138129
139- fun syncVisibility (): LiveData <Int > = syncVisibilityLiveData
130+ fun unSyncedDataCount (): LiveData <Int > = unSyncedDataCountLiveData
140131
141132 fun sync () {
142133 repository.syncData()
0 commit comments