This is an automated email from the ASF dual-hosted git repository.

rajanmaurya154 pushed a commit to branch development
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mobile.git

commit a10ef92e0d1c6175d79d84c69a8eb13f589bf044
Author: miPlodder <academic.ra...@gmail.com>
AuthorDate: Sun May 5 19:45:42 2019 +0530

    FINCN-152: Added filters for Loan Accounts
---
 .../loanaccountlist/LoanAccountsContract.java      |  4 ++
 .../loanaccountlist/LoanAccountsFragment.java      | 47 ++++++++++++++++++++++
 .../loanaccountlist/LoanAccountsPresenter.java     | 14 +++++++
 app/src/main/res/menu/menu_loan_account_search.xml | 10 +++++
 app/src/main/res/values/strings.xml                |  1 +
 5 files changed, 76 insertions(+)

diff --git 
a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsContract.java
 
b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsContract.java
index 3d55a5b..89cd040 100644
--- 
a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsContract.java
+++ 
b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsContract.java
@@ -28,10 +28,14 @@ public interface LoanAccountsContract {
         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);
 
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 f9aca09..34a97dd 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
@@ -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;
 
@@ -86,6 +92,7 @@ public class LoanAccountsFragment extends 
FineractBaseFragment implements LoanAc
         setToolbarTitle(getString(R.string.loan_accounts));
 
         showUserInterface();
+        setHasOptionsMenu(true);
 
         return rootView;
     }
@@ -213,4 +220,44 @@ public class LoanAccountsFragment extends 
FineractBaseFragment implements LoanAc
     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);
+    }
 }
diff --git 
a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsPresenter.java
 
b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsPresenter.java
index 7135ff7..88ceb65 100644
--- 
a/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsPresenter.java
+++ 
b/app/src/main/java/org/apache/fineract/ui/online/loanaccounts/loanaccountlist/LoanAccountsPresenter.java
@@ -15,8 +15,10 @@ import java.util.List;
 
 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;
 
@@ -115,4 +117,16 @@ public class LoanAccountsPresenter extends 
BasePresenter<LoanAccountsContract.Vi
             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());
+    }
 }
diff --git a/app/src/main/res/menu/menu_loan_account_search.xml 
b/app/src/main/res/menu/menu_loan_account_search.xml
new file mode 100644
index 0000000..0f7c895
--- /dev/null
+++ b/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="@string/loan_account_search"
+        app:showAsAction="always"
+        app:actionViewClass="android.support.v7.widget.SearchView" />
+</menu>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml 
b/app/src/main/res/values/strings.xml
index 63544cd..5d3f569 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -175,6 +175,7 @@
     <string name="identification_search">Search identification card</string>
     <string name="ledger_search">Ledger Search</string>
     <string name="teller_search">Search teller</string>
+    <string name="loan_account_search">Loan Account Search</string>
     <string name="loan_last_modified_by">%1$s %2$s</string>
     <string name="loan_created_by">%1$s %2$s</string>
     <string name="search_beneficiary">Search beneficiary</string>

Reply via email to