From 1cde313314b4ea9ec9c89c49471ef6289bc8929e Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Wed, 25 May 2022 18:19:37 +0300 Subject: [PATCH] Disable bottom nav menu items on click - Closes #301 --- gradle.properties | 2 +- opensrp-child/build.gradle | 2 +- .../activity/BaseChildRegisterActivity.java | 16 +++++++++++++++- .../child/contract/ChildRegisterContract.java | 2 ++ .../fragment/BaseChildRegisterFragment.java | 2 +- .../listener/ChildBottomNavigationListener.java | 4 ++++ 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 78bb20ff7..6c834dc7c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.8.1-ALPHA9-SNAPSHOT +VERSION_NAME=0.8.6-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Child Library diff --git a/opensrp-child/build.gradle b/opensrp-child/build.gradle index fd467dbd3..e45201728 100644 --- a/opensrp-child/build.gradle +++ b/opensrp-child/build.gradle @@ -122,7 +122,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-v4' } - api('org.smartregister:opensrp-client-native-form:2.1.15-SNAPSHOT@aar') { + api('org.smartregister:opensrp-client-native-form:2.1.16-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' diff --git a/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildRegisterActivity.java b/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildRegisterActivity.java index 4915d44ae..3be99aeb2 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildRegisterActivity.java +++ b/opensrp-child/src/main/java/org/smartregister/child/activity/BaseChildRegisterActivity.java @@ -10,7 +10,6 @@ import com.google.android.gms.vision.barcode.Barcode; import com.google.android.material.bottomnavigation.LabelVisibilityMode; import com.vijay.jsonwizard.constants.JsonFormConstants; -import com.vijay.jsonwizard.domain.Form; import org.json.JSONObject; import org.smartregister.AllConstants; @@ -27,6 +26,7 @@ import org.smartregister.child.util.ChildJsonFormUtils; import org.smartregister.child.util.Constants; import org.smartregister.child.util.Utils; +import org.smartregister.client.utils.domain.Form; import org.smartregister.helper.BottomNavigationHelper; import org.smartregister.view.activity.BaseRegisterActivity; @@ -46,6 +46,7 @@ public abstract class BaseChildRegisterActivity extends BaseRegisterActivity imp protected boolean isAdvancedSearch = false; protected HashMap advancedSearchFormData = new HashMap<>(); + private int disabledMenuId; @Override protected void onCreate(Bundle savedInstanceState) { @@ -205,6 +206,9 @@ public void onResume() { } protected void onChildRegisterResumption() { + + reEnableMenuItem(); + if (isAdvancedSearch) { refreshAdvancedSearchFormValues(); switchToAdvancedSearchFromRegister(); @@ -214,6 +218,11 @@ protected void onChildRegisterResumption() { } } + private void reEnableMenuItem() { + if (disabledMenuId != 0) + bottomNavigationView.getMenu().findItem(disabledMenuId).setEnabled(true); + } + protected void refreshAdvancedSearchFormValues() { setFormData(this.advancedSearchFormData); ((BaseAdvancedSearchFragment) findFragmentByPosition(ADVANCED_SEARCH_POSITION)).assignedValuesBeforeBarcode(); @@ -289,4 +298,9 @@ public void saveForm(String jsonString, UpdateRegisterParams updateRegisterParam public void dissmissProgressDialog() { hideProgressDialog(); } + + @Override + public void setActiveMenuItem(int menuItemId) { + disabledMenuId = menuItemId; + } } \ No newline at end of file diff --git a/opensrp-child/src/main/java/org/smartregister/child/contract/ChildRegisterContract.java b/opensrp-child/src/main/java/org/smartregister/child/contract/ChildRegisterContract.java index 485531bdc..1a54b259d 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/contract/ChildRegisterContract.java +++ b/opensrp-child/src/main/java/org/smartregister/child/contract/ChildRegisterContract.java @@ -20,6 +20,8 @@ public interface ChildRegisterContract { interface View extends BaseRegisterContract.View { ChildRegisterContract.Presenter presenter(); + + void setActiveMenuItem(int menuItemId); } interface Presenter extends BaseRegisterContract.Presenter { diff --git a/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseChildRegisterFragment.java b/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseChildRegisterFragment.java index f38f53549..420034977 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseChildRegisterFragment.java +++ b/opensrp-child/src/main/java/org/smartregister/child/fragment/BaseChildRegisterFragment.java @@ -454,7 +454,7 @@ public void run() { // For overdue count // FIXME: Count generated on first sync is not correct String sqlOverdueCount = Utils.metadata().getRegisterQueryProvider() - .getCountExecuteQuery(filterSelectionCondition(true),""); + .getCountExecuteQuery(filterSelectionCondition(true), ""); Timber.i(sqlOverdueCount); overDueCount = commonRepository().countSearchIds(sqlOverdueCount); Timber.i("Total Overdue Count %d ", overDueCount); diff --git a/opensrp-child/src/main/java/org/smartregister/child/listener/ChildBottomNavigationListener.java b/opensrp-child/src/main/java/org/smartregister/child/listener/ChildBottomNavigationListener.java index 141502ad0..9c2bf667b 100644 --- a/opensrp-child/src/main/java/org/smartregister/child/listener/ChildBottomNavigationListener.java +++ b/opensrp-child/src/main/java/org/smartregister/child/listener/ChildBottomNavigationListener.java @@ -21,15 +21,19 @@ public ChildBottomNavigationListener(BaseChildRegisterActivity context) { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { + item.setEnabled(false);//Disable menu item if (item.getItemId() == R.id.action_home) { getBaseRegisterActivityReference().switchToBaseFragment(); } else if (item.getItemId() == R.id.action_scan_qr) { getBaseRegisterActivityReference().startQrCodeScanner(); } else if (item.getItemId() == R.id.action_search) { getBaseRegisterActivityReference().switchToFragment(1); + item.setEnabled(true);//Fragment switch - reset immediately } else if (item.getItemId() == R.id.action_register) { getBaseRegisterActivityReference().startRegistration(); } + if (this.baseRegisterActivity.get() != null) + this.baseRegisterActivity.get().setActiveMenuItem(item.getItemId()); return true; }