feat: search customer
diff --git a/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersContract.java b/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersContract.java
index f4464d9..740b44d 100644
--- a/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersContract.java
+++ b/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersContract.java
@@ -28,6 +28,8 @@
void hideProgressbar();
void showMessage(String message);
+
+ void searchCustomerList(Customer searchedCustomer);
}
interface Presenter {
@@ -37,5 +39,7 @@
void fetchCustomers(Integer pageIndex, Integer size);
void showCustomers(List<Customer> customers);
+
+ void searchCustomerOnline(String query);
}
}
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 9aa2e19..36e0edf 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
@@ -2,15 +2,26 @@
import static android.app.Activity.RESULT_OK;
+import android.app.SearchManager;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
+import android.support.design.widget.CoordinatorLayout;
+import android.support.transition.TransitionManager;
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;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
import com.github.therajanmaurya.sweeterror.SweetUIErrorHandler;
@@ -28,6 +39,7 @@
import org.apache.fineract.utils.ConstantKeys;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
@@ -38,7 +50,7 @@
/**
* @author Rajan Maurya
- * On 20/06/17.
+ * On 20/06/17.
*/
public class CustomersFragment extends FineractBaseFragment implements CustomersContract.View,
SwipeRefreshLayout.OnRefreshListener, OnItemClickListener {
@@ -65,6 +77,21 @@
@Inject
PreferencesHelper preferencesHelper;
+ @BindView(R.id.rb_offline)
+ RadioButton rbOffline;
+
+ @BindView(R.id.rb_online)
+ RadioButton rbOnline;
+
+ @BindView(R.id.rg_search)
+ RadioGroup rgSearch;
+
+ @BindView(R.id.coordinator)
+ CoordinatorLayout coordinator;
+
+ @BindView(R.id.ll_search)
+ LinearLayout llSearch;
+
private List<Customer> customers;
private Integer detailsCustomerPosition;
private boolean isNewCustomer = false;
@@ -81,6 +108,7 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
customers = new ArrayList<>();
+ setHasOptionsMenu(true);
}
@Override
@@ -193,6 +221,11 @@
}
@Override
+ public void searchCustomerList(Customer customer) {
+ customerAdapter.setCustomers(Collections.singletonList(customer));
+ }
+
+ @Override
public void showNoInternetConnection() {
showRecyclerView(false);
showFineractNoInternetUI();
@@ -215,6 +248,67 @@
}
@Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
+ super.onCreateOptionsMenu(menu, inflater);
+ inflater.inflate(R.menu.menu_customer, menu);
+ setUpSearchInterface(menu);
+ }
+
+ private void setUpSearchInterface(Menu menu) {
+
+ SearchManager manager = (SearchManager) getActivity().
+ getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView = (SearchView) menu.findItem(
+ R.id.menu_customer_search).getActionView();
+ searchView.setSearchableInfo(manager.getSearchableInfo(getActivity().getComponentName()));
+
+ searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ findCustomer(query);
+ return false;
+ }
+
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ if(TextUtils.isEmpty(newText)){
+ customerAdapter.setCustomers(customers);
+ }
+
+ return false;
+ }
+ });
+
+ searchView.setOnSearchClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ TransitionManager.beginDelayedTransition(coordinator);
+ llSearch.setVisibility(View.VISIBLE);
+ }
+ });
+
+ searchView.setOnCloseListener(new SearchView.OnCloseListener() {
+ @Override
+ public boolean onClose() {
+ rgSearch.clearCheck();
+ TransitionManager.beginDelayedTransition(coordinator);
+ llSearch.setVisibility(View.GONE);
+ return false;
+ }
+ });
+ }
+
+ private void findCustomer(String query) {
+
+ if (rgSearch.getCheckedRadioButtonId() == -1) {
+ Toaster.show(swipeRefreshLayout,getString(R.string.error_finding_customer_options), Toaster.SHORT);
+ }else if (rbOnline.isChecked()) {
+ customerPresenter.searchCustomerOnline(query);
+ }
+ }
+
+
+ @Override
public void onItemClick(View childView, int position) {
detailsCustomerPosition = position;
Intent customerDetailsIntent = new Intent(getActivity(), CustomerDetailsActivity.class);
diff --git a/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersPresenter.java b/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersPresenter.java
index 3fa1415..c49c7a3 100644
--- a/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersPresenter.java
+++ b/app/src/main/java/org/apache/fineract/ui/online/customers/customerlist/CustomersPresenter.java
@@ -111,4 +111,31 @@
getMvpView().showCustomers(customers);
}
}
+
+ @Override
+ public void searchCustomerOnline(String query) {
+ checkViewAttached();
+ getMvpView().showProgressbar();
+ compositeDisposable.add(
+ dataManagerCustomer.fetchCustomer(query)
+ .subscribeOn(Schedulers.io())
+ .observeOn(AndroidSchedulers.mainThread())
+ .subscribeWith(new DisposableObserver<Customer>(){
+ @Override
+ public void onNext(Customer value) {
+ getMvpView().hideProgressbar();
+ getMvpView().searchCustomerList(value);
+ }
+
+ @Override
+ public void onError(Throwable e) {
+ showExceptionError(e,context.getString(R.string.error_finding_customer));
+ }
+
+ @Override
+ public void onComplete() {
+
+ }
+ }));
+ }
}
diff --git a/app/src/main/res/layout/fragment_customer_list.xml b/app/src/main/res/layout/fragment_customer_list.xml
index c91f325..01afc76 100644
--- a/app/src/main/res/layout/fragment_customer_list.xml
+++ b/app/src/main/res/layout/fragment_customer_list.xml
@@ -1,23 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
-<android.support.design.widget.CoordinatorLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_height="match_parent"
- android:layout_width="match_parent">
+ android:id="@+id/coordinator"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
- <android.support.v4.widget.SwipeRefreshLayout
- android:id="@+id/swipe_container"
- android:layout_height="match_parent"
- android:layout_width="match_parent">
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
- <android.support.v7.widget.RecyclerView
- android:id="@+id/rv_customers"
- android:layout_centerHorizontal="true"
- android:layout_height="0dp"
- android:layout_marginBottom="@dimen/layout_padding_30dp"
- android:layout_weight="1"
- android:layout_width="wrap_content"/>
- </android.support.v4.widget.SwipeRefreshLayout>
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/ll_search"
+ android:visibility="gone"
+ android:orientation="vertical">
+
+ <RadioGroup
+ android:id="@+id/rg_search"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:padding="@dimen/layout_padding_16dp">
+
+ <RadioButton
+ android:id="@+id/rb_online"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/online"
+ android:layout_marginStart="@dimen/layout_padding_10dp"
+ android:layout_marginLeft="@dimen/layout_padding_10dp" />
+
+ <View
+ android:layout_width="1dp"
+ android:layout_height="match_parent"
+ android:layout_gravity="center"
+ android:background="#E7DFDF"/>
+
+ <RadioButton
+ android:id="@+id/rb_offline"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/offline"
+ android:layout_marginStart="@dimen/layout_padding_10dp"
+ android:layout_marginLeft="@dimen/layout_padding_10dp" />
+
+
+ </RadioGroup>
+
+ <View
+ android:background="#cbcbcb"
+ android:layout_height="1dp"
+ android:layout_width="match_parent"
+ android:layout_marginBottom="@dimen/layout_padding_10dp"/>
+
+ </LinearLayout>
+
+
+ <android.support.v4.widget.SwipeRefreshLayout
+ android:id="@+id/swipe_container"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <android.support.v7.widget.RecyclerView
+ android:id="@+id/rv_customers"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_marginBottom="@dimen/layout_padding_30dp" />
+
+
+ </android.support.v4.widget.SwipeRefreshLayout>
+
+ </LinearLayout>
<include
layout="@layout/layout_sweet_exception_handler"
diff --git a/app/src/main/res/menu/menu_customer.xml b/app/src/main/res/menu/menu_customer.xml
new file mode 100644
index 0000000..031010d
--- /dev/null
+++ b/app/src/main/res/menu/menu_customer.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <item
+ android:id="@+id/menu_customer_search"
+ android:icon="@drawable/ic_search_black_24dp"
+ android:title="@string/search_customer"
+ 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 c969f51..92ef199 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -179,6 +179,9 @@
<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>
+ <string name="search_customer">Search customer</string>
+ <string name="online">Online</string>
+ <string name="offline">Offline</string>
<string name="select_product">Select product</string>
<string name="no_beneficiary">No beneficiaries</string>
<string name="activities_created_by_on">%1$s, %2$s</string>
@@ -246,6 +249,8 @@
<!--Error Message-->
<string name="error_loading_customers">Error loading customers</string>
+ <string name="error_finding_customer">Error finding customer</string>
+ <string name="error_finding_customer_options">Select at least one option</string>
<string name="error_loading_customer_loans">Error loading customer loans</string>
<string name="error_loading_customer_loan_details">Error loading loan details</string>
<string name="error_loading_deposit_details">Error loading deposit details</string>
diff --git a/app/src/main/resources/customerPage.json b/app/src/main/resources/customerPage.json
index 59f3aa3..eda4821 100644
--- a/app/src/main/resources/customerPage.json
+++ b/app/src/main/resources/customerPage.json
@@ -3,9 +3,101 @@
{
"identifier": "identifier",
"type": "type",
- "givenName": "givenName",
- "middleName": "middleName",
- "surname": "surname",
+ "givenName": "givenName1",
+ "middleName": "middleName1",
+ "surname": "surname1",
+ "dateOfBirth": {
+ "year": 1985,
+ "month": 11,
+ "day": 27
+ },
+ "member": false,
+ "accountBeneficiary": "accountBeneficiary",
+ "referenceCustomer": "referenceCustomer",
+ "assignedOffice": "assignedOffice",
+ "assignedEmployee": "assignedEmployee",
+ "address": {
+ "street": "street",
+ "city": "city",
+ "region": "region",
+ "postalCode": "postalCode",
+ "countryCode": "countryCode",
+ "country": "country"
+ },
+ "contactDetails": [
+ {
+ "type": "EMAIL",
+ "group": "BUSINESS",
+ "value": "value",
+ "preferenceLevel": 1,
+ "validated": false
+ },
+ {
+ "type": "EMAIL",
+ "group": "BUSINESS",
+ "value": "value",
+ "preferenceLevel": 1,
+ "validated": false
+ }
+ ],
+ "currentState": "ACTIVE",
+ "createdBy": "createdBy",
+ "createdOn": "createdOn",
+ "lastModifiedBy": "lastModifiedBy",
+ "lastModifiedOn": "lastModifiedOn"
+ },
+ {
+ "identifier": "identifier2",
+ "type": "type",
+ "givenName": "givenName2",
+ "middleName": "middleName2",
+ "surname": "surname2",
+ "dateOfBirth": {
+ "year": 1985,
+ "month": 11,
+ "day": 27
+ },
+ "member": false,
+ "accountBeneficiary": "accountBeneficiary",
+ "referenceCustomer": "referenceCustomer",
+ "assignedOffice": "assignedOffice",
+ "assignedEmployee": "assignedEmployee",
+ "address": {
+ "street": "street",
+ "city": "city",
+ "region": "region",
+ "postalCode": "postalCode",
+ "countryCode": "countryCode",
+ "country": "country"
+ },
+ "contactDetails": [
+ {
+ "type": "EMAIL",
+ "group": "BUSINESS",
+ "value": "value",
+ "preferenceLevel": 1,
+ "validated": false
+ },
+ {
+ "type": "EMAIL",
+ "group": "BUSINESS",
+ "value": "value",
+ "preferenceLevel": 1,
+ "validated": false
+ }
+ ],
+ "currentState": "ACTIVE",
+ "createdBy": "createdBy",
+ "createdOn": "createdOn",
+ "lastModifiedBy": "lastModifiedBy",
+ "lastModifiedOn": "lastModifiedOn"
+ },
+ {
+ "identifier": "identifier3",
+ "type": "type",
+ "givenName": "givenName3",
+ "middleName": "middleName3",
+ "surname": "surname3",
"dateOfBirth": {
"year": 1985,
"month": 11,
@@ -48,5 +140,5 @@
}
],
"totalPages": 1,
- "totalElements": 1
+ "totalElements": 3
}
\ No newline at end of file