From 4217119848ee5610dcb0fc0899a14cea7835a160 Mon Sep 17 00:00:00 2001 From: Elly Kitoto Date: Tue, 12 Nov 2024 11:19:20 +0300 Subject: [PATCH] Fix UI freeze on launch register screen (#3599) * Move tasks to io thread Signed-off-by: Elly Kitoto * Separate count state from the rest of register UI state Signed-off-by: Elly Kitoto * Run spotless Signed-off-by: Elly Kitoto --------- Signed-off-by: Elly Kitoto --- .../ui/register/RegisterScreenTest.kt | 84 +++++++++++----- .../components/RegisterCardListTest.kt | 5 + .../quest/ui/register/RegisterFragment.kt | 17 ++-- .../quest/ui/register/RegisterScreen.kt | 15 ++- .../quest/ui/register/RegisterUiCountState.kt | 23 +++++ .../quest/ui/register/RegisterUiState.kt | 3 - .../quest/ui/register/RegisterViewModel.kt | 98 ++++++++++--------- .../register/components/RegisterCardList.kt | 4 +- .../quest/ui/register/RegisterFragmentTest.kt | 4 + .../ui/register/RegisterViewModelTest.kt | 6 +- 10 files changed, 168 insertions(+), 91 deletions(-) create mode 100644 android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiCountState.kt diff --git a/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/RegisterScreenTest.kt b/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/RegisterScreenTest.kt index 2cf5fd089a..ae25e225f6 100644 --- a/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/RegisterScreenTest.kt +++ b/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/RegisterScreenTest.kt @@ -67,6 +67,7 @@ import org.smartregister.fhircore.quest.ui.register.NO_REGISTER_VIEW_COLUMN_TEST import org.smartregister.fhircore.quest.ui.register.NoRegisterDataView import org.smartregister.fhircore.quest.ui.register.REGISTER_CARD_TEST_TAG import org.smartregister.fhircore.quest.ui.register.RegisterScreen +import org.smartregister.fhircore.quest.ui.register.RegisterUiCountState import org.smartregister.fhircore.quest.ui.register.RegisterUiState import org.smartregister.fhircore.quest.ui.register.TOP_REGISTER_SCREEN_TEST_TAG import org.smartregister.fhircore.quest.ui.shared.components.SYNC_PROGRESS_INDICATOR_TEST_TAG @@ -126,9 +127,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 0, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), @@ -146,6 +144,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 0, + ), onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, @@ -168,9 +172,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 1, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), @@ -188,6 +189,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 1, + ), onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, @@ -213,13 +220,17 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 1, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), ) + + val registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 1, + ) val searchText = mutableStateOf(SearchQuery.emptyText) val currentPage = mutableStateOf(0) @@ -233,6 +244,7 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = registerUiCountState, onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, @@ -258,9 +270,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "childRegister"), registerId = "register101", - totalRecordsCount = 0, - filteredRecordsCount = 0, - pagesCount = 1, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), @@ -283,6 +292,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 0, + filteredRecordsCount = 0, + pagesCount = 1, + ), onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, @@ -304,9 +319,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 0, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), @@ -324,6 +336,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 0, + ), onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, @@ -351,9 +369,6 @@ class RegisterScreenTest { listOf(ActionConfig(trigger = ActionTrigger.ON_SEARCH_SINGLE_RESULT)), ), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 0, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), @@ -371,6 +386,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 0, + ), onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, @@ -429,9 +450,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 0, progressPercentage = flowOf(50), isSyncUpload = flowOf(true), currentSyncJobStatus = @@ -455,6 +473,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 0, + ), appDrawerUIState = AppDrawerUIState( currentSyncJobStatus = @@ -489,9 +513,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 0, progressPercentage = flowOf(100), isSyncUpload = flowOf(false), currentSyncJobStatus = flowOf(CurrentSyncJobStatus.Succeeded(OffsetDateTime.now())), @@ -509,6 +530,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 0, + ), appDrawerUIState = AppDrawerUIState( currentSyncJobStatus = CurrentSyncJobStatus.Succeeded(OffsetDateTime.now()), @@ -541,9 +568,6 @@ class RegisterScreenTest { registerConfiguration = configurationRegistry.retrieveConfiguration(ConfigType.Register, "householdRegister"), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 0, progressPercentage = flowOf(100), isSyncUpload = flowOf(false), currentSyncJobStatus = flowOf(CurrentSyncJobStatus.Succeeded(OffsetDateTime.now())), @@ -561,6 +585,12 @@ class RegisterScreenTest { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 0, + ), appDrawerUIState = AppDrawerUIState( currentSyncJobStatus = CurrentSyncJobStatus.Failed(OffsetDateTime.now()), diff --git a/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/components/RegisterCardListTest.kt b/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/components/RegisterCardListTest.kt index 8d3967f60a..65531bc954 100644 --- a/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/components/RegisterCardListTest.kt +++ b/android/quest/src/androidTest/java/org/smartregister/fhircore/quest/integration/ui/register/components/RegisterCardListTest.kt @@ -37,6 +37,7 @@ import org.junit.Test import org.smartregister.fhircore.engine.configuration.register.RegisterCardConfig import org.smartregister.fhircore.engine.configuration.view.CompoundTextProperties import org.smartregister.fhircore.engine.domain.model.ResourceData +import org.smartregister.fhircore.quest.ui.register.RegisterUiCountState import org.smartregister.fhircore.quest.ui.register.RegisterUiState import org.smartregister.fhircore.quest.ui.register.components.REGISTER_CARD_LIST_TEST_TAG import org.smartregister.fhircore.quest.ui.register.components.RegisterCardList @@ -58,6 +59,7 @@ class RegisterCardListTest { lazyListState = rememberLazyListState(), onEvent = {}, registerUiState = RegisterUiState(), + registerUiCountState = RegisterUiCountState(), currentPage = mutableStateOf(1), onSearchByQrSingleResultAction = {}, decodeImage = null, @@ -84,6 +86,7 @@ class RegisterCardListTest { lazyListState = rememberLazyListState(), onEvent = {}, registerUiState = RegisterUiState(), + registerUiCountState = RegisterUiCountState(), currentPage = mutableStateOf(1), onSearchByQrSingleResultAction = {}, decodeImage = null, @@ -116,6 +119,7 @@ class RegisterCardListTest { lazyListState = rememberLazyListState(), onEvent = {}, registerUiState = RegisterUiState(), + registerUiCountState = RegisterUiCountState(), currentPage = mutableStateOf(1), showPagination = true, onSearchByQrSingleResultAction = {}, @@ -144,6 +148,7 @@ class RegisterCardListTest { lazyListState = rememberLazyListState(), onEvent = {}, registerUiState = RegisterUiState(), + registerUiCountState = RegisterUiCountState(), currentPage = mutableStateOf(1), onSearchByQrSingleResultAction = {}, decodeImage = null, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterFragment.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterFragment.kt index 9d31df58c9..9e6aff8fb8 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterFragment.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterFragment.kt @@ -88,16 +88,12 @@ class RegisterFragment : Fragment(), OnSyncListener { savedInstanceState: Bundle?, ): View { with(registerFragmentArgs) { - viewLifecycleOwner.lifecycleScope.launch { - viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) { - registerViewModel.retrieveRegisterUiState( - registerId = registerId, - screenTitle = screenTitle, - params = params, - clearCache = false, - ) - } - } + registerViewModel.retrieveRegisterUiState( + registerId = registerId, + screenTitle = screenTitle, + params = params, + clearCache = false, + ) } return ComposeView(requireContext()).apply { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) @@ -174,6 +170,7 @@ class RegisterFragment : Fragment(), OnSyncListener { openDrawer = openDrawer, onEvent = registerViewModel::onEvent, registerUiState = registerViewModel.registerUiState.value, + registerUiCountState = registerViewModel.registerUiCountState.value, appDrawerUIState = appMainViewModel.appDrawerUiState.value, onAppMainEvent = { appMainViewModel.onEvent(it) }, searchQuery = searchViewModel.searchQuery, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt index 515739ff58..1d15b76bf5 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterScreen.kt @@ -93,6 +93,7 @@ fun RegisterScreen( openDrawer: (Boolean) -> Unit, onEvent: (RegisterEvent) -> Unit, registerUiState: RegisterUiState, + registerUiCountState: RegisterUiCountState, appDrawerUIState: AppDrawerUIState = AppDrawerUIState(), onAppMainEvent: (AppMainEvent) -> Unit, searchQuery: MutableState, @@ -114,7 +115,7 @@ fun RegisterScreen( registerUiState.registerConfiguration?.topScreenSection?.title ?: "" }, searchQuery = searchQuery.value, - filteredRecordsCount = registerUiState.filteredRecordsCount, + filteredRecordsCount = registerUiCountState.filteredRecordsCount, isSearchBarVisible = registerUiState.registerConfiguration?.searchBar?.visible ?: true, searchPlaceholder = registerUiState.registerConfiguration?.searchBar?.display, showSearchByQrCode = registerUiState.registerConfiguration?.showSearchByQrCode ?: false, @@ -198,6 +199,7 @@ fun RegisterScreen( lazyListState = lazyListState, onEvent = onEvent, registerUiState = registerUiState, + registerUiCountState = registerUiCountState, currentPage = currentPage, showPagination = !registerUiState.registerConfiguration.infiniteScroll && @@ -292,13 +294,17 @@ fun RegisterScreenWithDataPreview() { FhirResourceConfig(baseResource = ResourceConfig(resource = ResourceType.Patient)), ), registerId = "register101", - totalRecordsCount = 1, - filteredRecordsCount = 0, - pagesCount = 1, progressPercentage = flowOf(0), isSyncUpload = flowOf(false), params = emptyList(), ) + + val registerUiCountState = + RegisterUiCountState( + totalRecordsCount = 1, + filteredRecordsCount = 0, + pagesCount = 1, + ) val searchText = remember { mutableStateOf(SearchQuery.emptyText) } val currentPage = remember { mutableIntStateOf(0) } val data = listOf(ResourceData("1", ResourceType.Patient, emptyMap())) @@ -310,6 +316,7 @@ fun RegisterScreenWithDataPreview() { openDrawer = {}, onEvent = {}, registerUiState = registerUiState, + registerUiCountState = registerUiCountState, onAppMainEvent = {}, searchQuery = searchText, currentPage = currentPage, diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiCountState.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiCountState.kt new file mode 100644 index 0000000000..d319d0de2c --- /dev/null +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiCountState.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2021-2024 Ona Systems, Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.smartregister.fhircore.quest.ui.register + +data class RegisterUiCountState( + val totalRecordsCount: Long = 0, + val filteredRecordsCount: Long? = null, + val pagesCount: Int = 1, +) diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiState.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiState.kt index 49698fa760..eabfe3e00d 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiState.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterUiState.kt @@ -27,9 +27,6 @@ data class RegisterUiState( val isFirstTimeSync: Boolean = false, val registerConfiguration: RegisterConfiguration? = null, val registerId: String = "", - val totalRecordsCount: Long = 0, - val filteredRecordsCount: Long = 0, - val pagesCount: Int = 1, val progressPercentage: Flow = flowOf(0), val isSyncUpload: Flow = flowOf(false), val currentSyncJobStatus: Flow = flowOf(null), diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModel.kt index 3d8aca437c..8658c3dc6d 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModel.kt @@ -73,6 +73,7 @@ import org.smartregister.fhircore.engine.domain.model.ResourceConfig import org.smartregister.fhircore.engine.domain.model.ResourceData import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor +import org.smartregister.fhircore.engine.util.DispatcherProvider import org.smartregister.fhircore.engine.util.SharedPreferenceKey import org.smartregister.fhircore.engine.util.SharedPreferencesHelper import org.smartregister.fhircore.engine.util.extension.encodeJson @@ -90,11 +91,13 @@ constructor( val configurationRegistry: ConfigurationRegistry, val sharedPreferencesHelper: SharedPreferencesHelper, val resourceDataRulesExecutor: ResourceDataRulesExecutor, + val dispatcherProvider: DispatcherProvider, ) : ViewModel() { private val _snackBarStateFlow = MutableSharedFlow() val snackBarStateFlow = _snackBarStateFlow.asSharedFlow() val registerUiState = mutableStateOf(RegisterUiState()) + val registerUiCountState = mutableStateOf(RegisterUiCountState()) val currentPage: MutableState = mutableIntStateOf(0) val registerData: MutableStateFlow>> = MutableStateFlow(emptyFlow()) val pagesDataCache = mutableMapOf>>() @@ -622,12 +625,18 @@ constructor( ) { if (registerId.isNotEmpty()) { val paramsMap: Map = params.toParamDataMap() - viewModelScope.launch { - val currentRegisterConfiguration = retrieveRegisterConfiguration(registerId, paramsMap) - if (currentRegisterConfiguration.infiniteScroll) { - registerData.value = - retrieveCompleteRegisterData(currentRegisterConfiguration.id, clearCache) - } else { + + val currentRegisterConfiguration = retrieveRegisterConfiguration(registerId, paramsMap) + if (currentRegisterConfiguration.infiniteScroll) { + registerData.value = + retrieveCompleteRegisterData(currentRegisterConfiguration.id, clearCache) + } else { + paginateRegisterData( + registerId = registerId, + loadAll = false, + clearCache = clearCache, + ) + viewModelScope.launch(dispatcherProvider.io()) { _totalRecordsCount.longValue = registerRepository.countRegisterData( registerId = registerId, @@ -643,49 +652,50 @@ constructor( fhirResourceConfig = registerFilterState.value.fhirResourceConfig, ) } - paginateRegisterData( - registerId = registerId, - loadAll = false, - clearCache = clearCache, - ) - } - registerUiState.value = - RegisterUiState( - screenTitle = currentRegisterConfiguration.registerTitle ?: screenTitle, - isFirstTimeSync = - sharedPreferencesHelper - .read( - SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name, - null, - ) - .isNullOrEmpty() && - _totalRecordsCount.longValue == 0L && - applicationConfiguration.usePractitionerAssignedLocationOnSync, - registerConfiguration = currentRegisterConfiguration, - registerId = registerId, - totalRecordsCount = _totalRecordsCount.longValue, - filteredRecordsCount = _filteredRecordsCount.longValue, - pagesCount = - ceil( - (if (registerFilterState.value.fhirResourceConfig != null) { - _filteredRecordsCount.longValue - } else { - _totalRecordsCount.longValue - }) - .toDouble() - .div(currentRegisterConfiguration.pageSize.toLong()), - ) - .toInt(), - progressPercentage = _percentageProgress, - isSyncUpload = _isUploadSync, - currentSyncJobStatus = _currentSyncJobStatusFlow, - params = params?.toList() ?: emptyList(), - ) + registerUiCountState.value = + RegisterUiCountState( + totalRecordsCount = _totalRecordsCount.longValue, + filteredRecordsCount = _filteredRecordsCount.longValue, + pagesCount = + ceil( + (if (registerFilterState.value.fhirResourceConfig != null) { + _filteredRecordsCount.longValue + } else { + _totalRecordsCount.longValue + }) + .toDouble() + .div(currentRegisterConfiguration.pageSize.toLong()), + ) + .toInt(), + ) + } } + + registerUiState.value = + RegisterUiState( + screenTitle = currentRegisterConfiguration.registerTitle ?: screenTitle, + isFirstTimeSync = isFirstTimeSync(), + registerConfiguration = currentRegisterConfiguration, + registerId = registerId, + progressPercentage = _percentageProgress, + isSyncUpload = _isUploadSync, + currentSyncJobStatus = _currentSyncJobStatusFlow, + params = params?.toList() ?: emptyList(), + ) } } + private fun isFirstTimeSync() = + sharedPreferencesHelper + .read( + SharedPreferenceKey.LAST_SYNC_TIMESTAMP.name, + null, + ) + .isNullOrEmpty() && + applicationConfiguration.usePractitionerAssignedLocationOnSync && + _totalRecordsCount.longValue == 0L + suspend fun emitSnackBarState(snackBarMessageConfig: SnackBarMessageConfig) { _snackBarStateFlow.emit(snackBarMessageConfig) } diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/components/RegisterCardList.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/components/RegisterCardList.kt index 4121a7af8d..a78c065897 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/components/RegisterCardList.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/register/components/RegisterCardList.kt @@ -41,6 +41,7 @@ import org.smartregister.fhircore.engine.ui.components.ErrorMessage import org.smartregister.fhircore.engine.ui.components.register.RegisterFooter import org.smartregister.fhircore.engine.ui.theme.DividerColor import org.smartregister.fhircore.quest.ui.register.RegisterEvent +import org.smartregister.fhircore.quest.ui.register.RegisterUiCountState import org.smartregister.fhircore.quest.ui.register.RegisterUiState import org.smartregister.fhircore.quest.ui.shared.components.ViewRenderer import timber.log.Timber @@ -62,6 +63,7 @@ fun RegisterCardList( lazyListState: LazyListState, onEvent: (RegisterEvent) -> Unit, registerUiState: RegisterUiState, + registerUiCountState: RegisterUiCountState, currentPage: MutableState, showPagination: Boolean = false, onSearchByQrSingleResultAction: (ResourceData) -> Unit, @@ -132,7 +134,7 @@ fun RegisterCardList( RegisterFooter( resultCount = pagingItems.itemCount, currentPage = currentPage.value.plus(1), - pagesCount = registerUiState.pagesCount, + pagesCount = registerUiCountState.pagesCount, previousButtonClickListener = { onEvent(RegisterEvent.MoveToPreviousPage) }, nextButtonClickListener = { onEvent(RegisterEvent.MoveToNextPage) }, ) diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterFragmentTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterFragmentTest.kt index 66775f2953..a4a903b17e 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterFragmentTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterFragmentTest.kt @@ -51,6 +51,7 @@ import org.smartregister.fhircore.engine.domain.model.ActionConfig import org.smartregister.fhircore.engine.domain.model.ResourceData import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig import org.smartregister.fhircore.engine.domain.model.ToolBarHomeNavigation +import org.smartregister.fhircore.engine.util.DispatcherProvider import org.smartregister.fhircore.quest.app.fakes.Faker import org.smartregister.fhircore.quest.event.EventBus import org.smartregister.fhircore.quest.navigation.NavigationArg @@ -66,6 +67,8 @@ class RegisterFragmentTest : RobolectricTest() { @Inject lateinit var eventBus: EventBus + @Inject lateinit var dispatcherProvider: DispatcherProvider + @BindValue val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry() @@ -87,6 +90,7 @@ class RegisterFragmentTest : RobolectricTest() { configurationRegistry = configurationRegistry, sharedPreferencesHelper = Faker.buildSharedPreferencesHelper(), resourceDataRulesExecutor = mockk(), + dispatcherProvider = dispatcherProvider, ), ) registerFragmentMock = mockk() diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModelTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModelTest.kt index 3746f047c9..5a9aeeb48d 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModelTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/ui/register/RegisterViewModelTest.kt @@ -55,6 +55,7 @@ import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig import org.smartregister.fhircore.engine.domain.model.FilterCriterionConfig import org.smartregister.fhircore.engine.domain.model.ResourceConfig import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor +import org.smartregister.fhircore.engine.util.DispatcherProvider import org.smartregister.fhircore.engine.util.SharedPreferenceKey import org.smartregister.fhircore.engine.util.SharedPreferencesHelper import org.smartregister.fhircore.quest.app.fakes.Faker @@ -67,6 +68,8 @@ class RegisterViewModelTest : RobolectricTest() { @Inject lateinit var resourceDataRulesExecutor: ResourceDataRulesExecutor + @Inject lateinit var dispatcherProvider: DispatcherProvider + private val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry() private lateinit var registerViewModel: RegisterViewModel private lateinit var registerRepository: RegisterRepository @@ -87,6 +90,7 @@ class RegisterViewModelTest : RobolectricTest() { configurationRegistry = configurationRegistry, sharedPreferencesHelper = sharedPreferencesHelper, resourceDataRulesExecutor = resourceDataRulesExecutor, + dispatcherProvider = dispatcherProvider, ), ) @@ -138,8 +142,6 @@ class RegisterViewModelTest : RobolectricTest() { val registerConfiguration = registerUiState.registerConfiguration Assert.assertNotNull(registerConfiguration) Assert.assertEquals("app", registerConfiguration?.appId) - Assert.assertEquals(200, registerUiState.totalRecordsCount) - Assert.assertEquals(20, registerUiState.pagesCount) } @Test