Skip to content

Commit

Permalink
Reset data filter queries on filter questionnaire launch (#3432)
Browse files Browse the repository at this point in the history
Signed-off-by: Elly Kitoto <junkmailstoelly@gmail.com>
  • Loading branch information
ellykits committed Aug 6, 2024
1 parent c186468 commit 490c294
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ open class AppMainActivity : BaseMultiLanguageActivity(), QuestionnaireHandler,
findNavController(R.id.nav_host).removeOnDestinationChangedListener(sentryNavListener)
}

override fun onQuestionnaireLaunched(questionnaireConfig: QuestionnaireConfig) {
// Data filter QRs are not persisted; reset filters when questionnaire is launched
if (!questionnaireConfig.saveQuestionnaireResponse) {
appMainViewModel.resetRegisterFilters.value = true
}
}

override suspend fun onSubmitQuestionnaire(activityResult: ActivityResult) {
if (activityResult.resultCode == RESULT_OK) {
val questionnaireResponse: QuestionnaireResponse? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.core.os.bundleOf
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.work.WorkManager
Expand Down Expand Up @@ -110,6 +111,8 @@ constructor(

val appDrawerUiState = mutableStateOf(AppDrawerUIState())

val resetRegisterFilters = MutableLiveData(false)

val unSyncedResourcesCount = mutableIntStateOf(0)

val applicationConfiguration: ApplicationConfiguration by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ private fun SideMenuItem(
modifier =
modifier
.fillMaxWidth()
.padding(vertical = padding.dp)
.clickable { onSideMenuClick() }
.padding(vertical = padding.dp)
.testTag(SIDE_MENU_ITEM_MAIN_ROW_TEST_TAG)
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ class RegisterFragment : Fragment(), OnSyncListener {
.launchIn(lifecycleScope)
}
}

appMainViewModel.resetRegisterFilters.observe(viewLifecycleOwner) { resetFilters ->
if (resetFilters) {
registerViewModel.registerFilterState.value = RegisterFilterState()
refreshRegisterData()
appMainViewModel.resetRegisterFilters.value = false
}
}
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ interface QuestionnaireHandler {
)
.putExtras(extraIntentBundle),
)
onQuestionnaireLaunched(questionnaireConfig)
}
}

fun onQuestionnaireLaunched(questionnaireConfig: QuestionnaireConfig)

suspend fun onSubmitQuestionnaire(activityResult: ActivityResult)
}

0 comments on commit 490c294

Please sign in to comment.