diff --git a/app/src/main/java/org/apache/fineract/ui/base/FineractBaseFragment.java b/app/src/main/java/org/apache/fineract/ui/base/FineractBaseFragment.java index 10339607..97ec3756 100644 --- a/app/src/main/java/org/apache/fineract/ui/base/FineractBaseFragment.java +++ b/app/src/main/java/org/apache/fineract/ui/base/FineractBaseFragment.java @@ -5,6 +5,7 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.SearchView; import androidx.fragment.app.Fragment; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -18,6 +19,7 @@ public class FineractBaseFragment extends Fragment { private BaseActivityCallback callback; private ProgressBarHandler progressBarHandler; private FineractUIErrorHandler fineractUIErrorHandler; + public SearchView baseSearchView; @Override public void onCreate(Bundle savedInstanceState) { @@ -94,4 +96,8 @@ public void onDetach() { callback = null; } + public void closeSearchView() { + baseSearchView.setIconified(true); + } + } \ No newline at end of file diff --git a/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java b/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java index 7f0460d9..0c03c071 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java +++ b/app/src/main/java/org/apache/fineract/ui/online/DashboardActivity.java @@ -22,6 +22,7 @@ import org.apache.fineract.data.local.PreferencesHelper; import org.apache.fineract.jobs.StartSyncJob; import org.apache.fineract.ui.base.FineractBaseActivity; +import org.apache.fineract.ui.base.FineractBaseFragment; import org.apache.fineract.ui.base.Toaster; import org.apache.fineract.ui.offline.CustomerPayloadFragment; import org.apache.fineract.ui.online.accounting.ledgers.LedgerFragment; @@ -60,6 +61,8 @@ public class DashboardActivity extends FineractBaseActivity implements private boolean isBackPressedOnce = false; + private FineractBaseFragment baseFragment; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -77,6 +80,10 @@ protected void onCreate(Bundle savedInstanceState) { } } + private void assignBaseFragment(FineractBaseFragment baseFragment) { + this.baseFragment = baseFragment; + } + public void setupNavigationBar() { navigationView.setNavigationItemSelectedListener(this); @@ -112,36 +119,54 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.item_dashboard: - replaceFragment(DashboardFragment.newInstance(), true, R.id.container); + DashboardFragment dashboardFragment = DashboardFragment.newInstance(); + replaceFragment(dashboardFragment, true, R.id.container); + assignBaseFragment(dashboardFragment.newInstance()); break; case R.id.item_roles: - replaceFragment(RolesFragment.newInstance(), true, R.id.container); + RolesFragment rolesFragment = RolesFragment.newInstance(); + replaceFragment(rolesFragment, true, R.id.container); + assignBaseFragment(rolesFragment); break; case R.id.item_customer: - replaceFragment(CustomersFragment.newInstance(), true, R.id.container); + CustomersFragment customersFragment = CustomersFragment.newInstance(); + replaceFragment(customersFragment, true, R.id.container); + assignBaseFragment(customersFragment); break; case R.id.item_customer_payload: - replaceFragment(CustomerPayloadFragment.newInstance(), true, + CustomerPayloadFragment payloadFragment = + CustomerPayloadFragment.newInstance(); + replaceFragment(payloadFragment, true, R.id.container); break; case R.id.item_product: - replaceFragment(ProductFragment.Companion.newInstance(), true, + ProductFragment productFragment = ProductFragment.Companion.newInstance(); + replaceFragment(productFragment, true, R.id.container); + assignBaseFragment(productFragment); break; case R.id.item_logout: logout(); break; case R.id.item_ledger: - replaceFragment(LedgerFragment.Companion.newInstance(), true, R.id.container); + LedgerFragment ledgerFragment = LedgerFragment.Companion.newInstance(); + replaceFragment(ledgerFragment, true, R.id.container); + assignBaseFragment(ledgerFragment); break; case R.id.item_accounts: - replaceFragment(AccountsFragment.Companion.newInstance(), true, R.id.container); + AccountsFragment accountsFragment = AccountsFragment.Companion.newInstance(); + replaceFragment(accountsFragment, true, R.id.container); + assignBaseFragment(accountsFragment); break; case R.id.item_teller: - replaceFragment(TellerFragment.Companion.newInstance(), true, R.id.container); + TellerFragment tellerFragment = TellerFragment.Companion.newInstance(); + replaceFragment(tellerFragment, true, R.id.container); + assignBaseFragment(tellerFragment); break; case R.id.item_groups: - replaceFragment(GroupListFragment.Companion.newInstance(), true, R.id.container); + GroupListFragment groupListFragment = GroupListFragment.Companion.newInstance(); + replaceFragment(groupListFragment, true, R.id.container); + assignBaseFragment(groupListFragment); } drawerLayout.closeDrawer(GravityCompat.START); @@ -151,6 +176,12 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) { @Override public void onBackPressed() { + if (baseFragment.baseSearchView != null && + !baseFragment.baseSearchView.isIconified()) { + baseFragment.closeSearchView(); + return; + } + if (drawerLayout.isDrawerOpen(GravityCompat.START)) { drawerLayout.closeDrawer(GravityCompat.START); return; diff --git a/app/src/main/java/org/apache/fineract/ui/online/accounting/accounts/AccountsFragment.kt b/app/src/main/java/org/apache/fineract/ui/online/accounting/accounts/AccountsFragment.kt index 67c27d8a..b8d6a736 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/accounting/accounts/AccountsFragment.kt +++ b/app/src/main/java/org/apache/fineract/ui/online/accounting/accounts/AccountsFragment.kt @@ -107,6 +107,7 @@ class AccountsFragment : FineractBaseFragment(), AccountContract.View, SwipeRefr } }) + baseSearchView = searchView } override fun searchedAccount(accounts: List) { diff --git a/app/src/main/java/org/apache/fineract/ui/online/accounting/ledgers/LedgerFragment.kt b/app/src/main/java/org/apache/fineract/ui/online/accounting/ledgers/LedgerFragment.kt index 75c50be5..8f84f7e7 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/accounting/ledgers/LedgerFragment.kt +++ b/app/src/main/java/org/apache/fineract/ui/online/accounting/ledgers/LedgerFragment.kt @@ -126,6 +126,7 @@ class LedgerFragment : FineractBaseFragment(), LedgerContract.View, } }) + baseSearchView = searchView } override fun searchedLedger(ledgers: List) { diff --git a/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersFragment.java b/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersFragment.java index b4d80d1f..ce61b2d7 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersFragment.java +++ b/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersFragment.java @@ -302,6 +302,8 @@ public boolean onClose() { return false; } }); + + baseSearchView = searchView; } private void findCustomer(String query) { diff --git a/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupListFragment.kt b/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupListFragment.kt index 448554b6..461c4949 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupListFragment.kt +++ b/app/src/main/java/org/apache/fineract/ui/online/groups/grouplist/GroupListFragment.kt @@ -110,6 +110,8 @@ class GroupListFragment : FineractBaseFragment(), OnItemClickListener { return true } }) + + baseSearchView = searchView } override fun onItemClick(childView: View?, position: Int) { diff --git a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsActivity.java b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsActivity.java index 24c7161a..a091ef04 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsActivity.java +++ b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsActivity.java @@ -4,6 +4,7 @@ import org.apache.fineract.R; import org.apache.fineract.ui.base.FineractBaseActivity; +import org.apache.fineract.ui.base.FineractBaseFragment; import org.apache.fineract.utils.ConstantKeys; /** @@ -13,17 +14,33 @@ public class IdentificationsActivity extends FineractBaseActivity { + private FineractBaseFragment baseFragment; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_toolbar_container); String identifier = getIntent().getExtras().getString(ConstantKeys.CUSTOMER_IDENTIFIER); + IdentificationsFragment identificationsFragment = + IdentificationsFragment.newInstance(identifier); + replaceFragment(identificationsFragment, false, R.id.container); + assignBaseFragment(identificationsFragment); - replaceFragment(IdentificationsFragment.newInstance(identifier), false, - R.id.container); + showBackButton(); + } + private void assignBaseFragment(FineractBaseFragment baseFragment) { + this.baseFragment = baseFragment; + } - showBackButton(); + @Override + public void onBackPressed() { + if (baseFragment.baseSearchView != null && + !baseFragment.baseSearchView.isIconified()) { + baseFragment.closeSearchView(); + return; + } + super.onBackPressed(); } } diff --git a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsFragment.java b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsFragment.java index 733b6883..27ad19f1 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsFragment.java +++ b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsFragment.java @@ -222,6 +222,7 @@ public boolean onQueryTextChange(String newText) { } }); + baseSearchView = searchView; } @Override diff --git a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsActivity.java b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsActivity.java index 8344668e..347bb701 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsActivity.java +++ b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsActivity.java @@ -4,6 +4,7 @@ import org.apache.fineract.R; import org.apache.fineract.ui.base.FineractBaseActivity; +import org.apache.fineract.ui.base.FineractBaseFragment; import org.apache.fineract.utils.ConstantKeys; /** @@ -12,14 +13,32 @@ */ public class LoanAccountsActivity extends FineractBaseActivity { + private FineractBaseFragment baseFragment; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_toolbar_container); String identifier = getIntent().getExtras().getString(ConstantKeys.CUSTOMER_IDENTIFIER); - replaceFragment(LoanAccountsFragment.newInstance(identifier), false, R.id.container); + LoanAccountsFragment loanAccountsFragment = LoanAccountsFragment.newInstance(identifier); + replaceFragment(loanAccountsFragment, false, R.id.container); + assignBaseFragment(loanAccountsFragment); showBackButton(); } + + private void assignBaseFragment(FineractBaseFragment baseFragment) { + this.baseFragment = baseFragment; + } + + @Override + public void onBackPressed() { + if (baseFragment.baseSearchView != null && + !baseFragment.baseSearchView.isIconified()) { + baseFragment.closeSearchView(); + return; + } + super.onBackPressed(); + } } diff --git a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsFragment.java b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsFragment.java index 7862fca1..bbe47e20 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsFragment.java +++ b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsFragment.java @@ -254,6 +254,7 @@ public boolean onQueryTextChange(String newText) { } }); + baseSearchView = searchView; } @Override diff --git a/app/src/main/java/org/apache/fineract/ui/online/teller/TellerFragment.kt b/app/src/main/java/org/apache/fineract/ui/online/teller/TellerFragment.kt index 9a889297..c4c1f4ed 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/teller/TellerFragment.kt +++ b/app/src/main/java/org/apache/fineract/ui/online/teller/TellerFragment.kt @@ -126,6 +126,7 @@ class TellerFragment : FineractBaseFragment(), TellerContract.View, SwipeRefresh } }) + baseSearchView = searchView } override fun searchedTeller(tellers: List) { diff --git a/app/src/main/java/org/apache/fineract/ui/product/ProductFragment.kt b/app/src/main/java/org/apache/fineract/ui/product/ProductFragment.kt index aa46396c..404b6953 100644 --- a/app/src/main/java/org/apache/fineract/ui/product/ProductFragment.kt +++ b/app/src/main/java/org/apache/fineract/ui/product/ProductFragment.kt @@ -125,6 +125,7 @@ class ProductFragment : FineractBaseFragment(), ProductContract.View, } }) + baseSearchView = searchView } override fun showEmptyProduct() {