Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
add functionality of search view close using back button
Browse files Browse the repository at this point in the history
  • Loading branch information
EGOR-IND committed Mar 18, 2021
1 parent 592099e commit 82ac4f4
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -94,4 +96,8 @@ public void onDetach() {
callback = null;
}

public void closeSearchView() {
baseSearchView.setIconified(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -77,6 +80,10 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

private void assignBaseFragment(FineractBaseFragment baseFragment) {
this.baseFragment = baseFragment;
}

public void setupNavigationBar() {
navigationView.setNavigationItemSelectedListener(this);

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class AccountsFragment : FineractBaseFragment(), AccountContract.View, SwipeRefr
}
})

baseSearchView = searchView
}

override fun searchedAccount(accounts: List<Account>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class LedgerFragment : FineractBaseFragment(), LedgerContract.View,
}
})

baseSearchView = searchView
}

override fun searchedLedger(ledgers: List<Ledger>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ public boolean onClose() {
return false;
}
});

baseSearchView = searchView;
}

private void findCustomer(String query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class GroupListFragment : FineractBaseFragment(), OnItemClickListener {
return true
}
})

baseSearchView = searchView
}

override fun onItemClick(childView: View?, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public boolean onQueryTextChange(String newText) {
}
});

baseSearchView = searchView;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public boolean onQueryTextChange(String newText) {
}
});

baseSearchView = searchView;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class TellerFragment : FineractBaseFragment(), TellerContract.View, SwipeRefresh
}
})

baseSearchView = searchView
}

override fun searchedTeller(tellers: List<Teller>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ProductFragment : FineractBaseFragment(), ProductContract.View,
}
})

baseSearchView = searchView
}

override fun showEmptyProduct() {
Expand Down

0 comments on commit 82ac4f4

Please sign in to comment.