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

Commit

Permalink
FINCN-152: Added filters for Loan Accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
miPlodder committed May 5, 2019
1 parent d547e08 commit b534bbe
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
Expand Up @@ -28,10 +28,14 @@ interface View extends MvpView {
void showProgressbar();

void hideProgressbar();

void searchedLoanAccounts(List<LoanAccount> loanAccountList);
}

interface Presenter {

void searchLoanAccounts(List<LoanAccount> loanAccountList, String query);

void fetchCustomerLoanAccounts(String customerIdentifier, Integer pageIndex,
Boolean loadmore);

Expand Down
@@ -1,12 +1,18 @@
package org.apache.fineract.ui.online.loanaccounts.loanaccountlist;

import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -86,6 +92,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
setToolbarTitle(getString(R.string.loan_accounts));

showUserInterface();
setHasOptionsMenu(true);

return rootView;
}
Expand Down Expand Up @@ -213,4 +220,44 @@ public void onItemClick(View childView, int position) {
public void onItemLongPress(View childView, int position) {

}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_loan_account_search, menu);
setUpSearchInterface(menu);
}

private void setUpSearchInterface(Menu menu) {
SearchManager searchManager = (SearchManager) getActivity().
getSystemService(Context.SEARCH_SERVICE);

SearchView searchView = (SearchView) menu.findItem(R.id.loan_account_search)
.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity()
.getComponentName()));

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
customerLoansPresenter.searchLoanAccounts(loanAccounts, query);
return false;
}

@Override
public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) {
searchedLoanAccounts(loanAccounts);
}
customerLoansPresenter.searchLoanAccounts(loanAccounts, newText);
return false;
}
});

}

@Override
public void searchedLoanAccounts(List<LoanAccount> loanAccountList) {
customerLoanAdapter.setCustomerLoanAccounts(loanAccountList);
}
}
Expand Up @@ -15,8 +15,10 @@

import javax.inject.Inject;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.functions.Predicate;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

Expand Down Expand Up @@ -115,4 +117,16 @@ public void showCustomerLoanAccounts(List<LoanAccount> loanAccounts) {
getMvpView().showLoanAccounts(loanAccounts);
}
}

@Override
public void searchLoanAccounts(List<LoanAccount> loanAccountList, final String query) {
getMvpView().searchedLoanAccounts(Observable.fromIterable(loanAccountList)
.filter(new Predicate<LoanAccount>() {
@Override
public boolean test(LoanAccount loanAccount) {
return loanAccount.getIdentifier().toLowerCase()
.contains(query.toLowerCase());
}
}).toList().blockingGet());
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/menu/menu_loan_account_search.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/loan_account_search"
android:icon="@drawable/ic_search_black_24dp"
android:title="Loan Account Search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>

0 comments on commit b534bbe

Please sign in to comment.