From f594afa9f474d6858180e393ee2f5b1364e55d63 Mon Sep 17 00:00:00 2001 From: Miguel Vasco Macamo Date: Thu, 1 Dec 2022 14:23:34 +0200 Subject: [PATCH] Androapp 5065 (#31) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set old Facility * Test of old facility * Set old facility * Update paperwork.json * Update HomeActivity.kt * Write logic for table content * get facility from viewModel * Update paperwork.json * [ANDROAPP-5065] ktlint check Co-authored-by: andresmr Co-authored-by: Andrés Miguel Rubio --- app/src/main/assets/paperwork.json | 2 +- .../java/org/dhis2/android/rtsm/ui/home/HomeViewModel.kt | 6 ++++++ .../rtsm/ui/home/screens/components/DropdownComponent.kt | 6 ++++++ .../rtsm/ui/home/screens/components/MainContent.kt | 8 +++++--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/paperwork.json b/app/src/main/assets/paperwork.json index b1478a04f7..ab468329fb 100644 --- a/app/src/main/assets/paperwork.json +++ b/app/src/main/assets/paperwork.json @@ -1 +1 @@ -{"buildTime":"2022-12-01 10:29","gitSha":"5bcdbca40"} \ No newline at end of file +{"buildTime":"2022-12-01 11:16","gitSha":"261ea3c0b"} \ No newline at end of file diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/HomeViewModel.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/HomeViewModel.kt index 20d6d4b409..a4bdfabeff 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/HomeViewModel.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/HomeViewModel.kt @@ -64,6 +64,9 @@ class HomeViewModel @Inject constructor( private val _scanText = MutableStateFlow("") val scanText = _scanText.asStateFlow() + private val _oldSelectedFacility = MutableStateFlow("") + val oldSelectedFacility = _oldSelectedFacility.asStateFlow() + private val _transactionDate = MutableStateFlow(LocalDateTime.now()) val transactionDate: StateFlow get() = _transactionDate @@ -244,4 +247,7 @@ class HomeViewModel @Inject constructor( fun setDestinationSelected(status: Boolean) { _hasDestinationSelected.value = status } + fun setOldSelectedFacility(text: String) { + _oldSelectedFacility.value = text + } } diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/DropdownComponent.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/DropdownComponent.kt index 43122bfd87..51ee5ebc27 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/DropdownComponent.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/DropdownComponent.kt @@ -223,6 +223,7 @@ fun DropdownComponentFacilities( val interactionSource = remember { MutableInteractionSource() } if (interactionSource.collectIsPressedAsState().value) { + viewModel.setFacilitySelected(false) openOrgUnitTreeSelector(supportFragmentManager, homeContext, data, viewModel) } @@ -260,6 +261,7 @@ fun DropdownComponentFacilities( trailingIcon = { IconButton( onClick = { + viewModel.setFacilitySelected(false) openOrgUnitTreeSelector( supportFragmentManager, homeContext, @@ -480,12 +482,16 @@ fun openOrgUnitTreeSelector( viewModel.setFacility(orgUnitDialog.selectedOrgUnitModel) viewModel.fromFacilitiesLabel(orgUnitDialog.selectedOrgUnitName) viewModel.setSelectedText(orgUnitDialog.selectedOrgUnitName) + viewModel.setOldSelectedFacility(orgUnitDialog.selectedOrgUnitName) orgUnitData = orgUnitDialog.selectedOrgUnitModel viewModel.setFacilitySelected(true) } orgUnitDialog.dismiss() } .setNegativeListener { + if (viewModel.oldSelectedFacility.value != "") { + viewModel.setFacilitySelected(true) + } orgUnitDialog.dismiss() } diff --git a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt index f3dca15855..06e448d4ab 100644 --- a/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt +++ b/stock-managment/src/main/java/org/dhis2/android/rtsm/ui/home/screens/components/MainContent.kt @@ -202,7 +202,9 @@ fun MainContent( if (viewModel.toolbarTitle.collectAsState().value.name == TransactionType.DISTRIBUTION.name ) { - if (hasFacilitySelected && hasDestinationSelected == true) { + if (viewModel.hasFacilitySelected.collectAsState().value && + hasDestinationSelected == true + ) { updateTableState(manageStockViewModel, viewModel) ManageStockTable(manageStockViewModel) { scope.launch { backdropState.conceal() } @@ -211,7 +213,7 @@ fun MainContent( } else if (viewModel.toolbarTitle.collectAsState().value.name == TransactionType.CORRECTION.name ) { - if (hasFacilitySelected) { + if (viewModel.hasFacilitySelected.collectAsState().value) { updateTableState(manageStockViewModel, viewModel) ManageStockTable(manageStockViewModel) { scope.launch { backdropState.conceal() } @@ -220,7 +222,7 @@ fun MainContent( } else if (viewModel.toolbarTitle.collectAsState().value.name == TransactionType.DISCARD.name ) { - if (hasFacilitySelected) { + if (viewModel.hasFacilitySelected.collectAsState().value) { updateTableState(manageStockViewModel, viewModel) ManageStockTable(manageStockViewModel) { scope.launch { backdropState.conceal() }