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
The following commit(s) were added to refs/heads/development by this push: new f9b01d3 feat: search identification f9b01d3 is described below commit f9b01d3634f66dd34609ba671e38aa7b65bbe53a Author: Mohak <mohakpuri1...@gmail.com> AuthorDate: Fri Jun 29 19:17:43 2018 +0530 feat: search identification --- .../data/datamanager/DataManagerCustomer.java | 17 +++++++- .../fineract/data/services/CustomerService.java | 4 ++ .../IdentificationsContract.java | 4 ++ .../IdentificationsFragment.java | 49 ++++++++++++++++++++++ .../IdentificationsPresenter.java | 34 ++++++++++++++- .../main/res/menu/menu_identification_search.xml | 12 ++++++ app/src/main/res/values/strings.xml | 4 ++ app/src/main/resources/identification.json | 36 ++++++++++++++-- 8 files changed, 154 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/apache/fineract/data/datamanager/DataManagerCustomer.java b/app/src/main/java/org/apache/fineract/data/datamanager/DataManagerCustomer.java index c2357a2..9b9665a 100644 --- a/app/src/main/java/org/apache/fineract/data/datamanager/DataManagerCustomer.java +++ b/app/src/main/java/org/apache/fineract/data/datamanager/DataManagerCustomer.java @@ -101,8 +101,7 @@ public class DataManagerCustomer extends FineractBaseDataManager { return authenticatedObservableApi(baseApiManager.getCustomerApi() .fetchIdentification(customerIdentifier)) .onErrorResumeNext( - new Function<Throwable, ObservableSource<List<Identification>>> - () { + new Function<Throwable, ObservableSource<List<Identification>>> () { @Override public ObservableSource<List<Identification>> apply( Throwable throwable) @@ -112,6 +111,20 @@ public class DataManagerCustomer extends FineractBaseDataManager { }); } + public Observable<Identification> searchIdentifications(String identifier, String number) { + return authenticatedObservableApi(baseApiManager.getCustomerApi() + .searchIdentification(identifier, number)) + .onErrorResumeNext( + new Function<Throwable, ObservableSource<Identification>>() { + @Override + public ObservableSource<Identification> apply( + Throwable throwable) throws Exception { + return Observable.just(FakeRemoteDataSource + .getIdentifications().get(0)); + } + }); + } + public Completable createIdentificationCard(String identifier, Identification identification) { return authenticatedCompletableApi(baseApiManager.getCustomerApi() .createIdentificationCard(identifier, identification)); diff --git a/app/src/main/java/org/apache/fineract/data/services/CustomerService.java b/app/src/main/java/org/apache/fineract/data/services/CustomerService.java index c548f62..493e38c 100644 --- a/app/src/main/java/org/apache/fineract/data/services/CustomerService.java +++ b/app/src/main/java/org/apache/fineract/data/services/CustomerService.java @@ -62,6 +62,10 @@ public interface CustomerService { Observable<List<Identification>> fetchIdentification( @Path("identifier") String identifier); + @GET(EndPoints.API_CUSTOMER_PATH + "/customers/{identifier}/identifications/{number}") + Observable<Identification> searchIdentification( + @Path("identifier") String identifier, @Path("number") String number); + @POST(EndPoints.API_CUSTOMER_PATH + "/customers/{identifier}/identifications") Completable createIdentificationCard(@Path("identifier") String identifier, @Body Identification identification); diff --git a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsContract.java b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsContract.java index c38030c..5127e53 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsContract.java +++ b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsContract.java @@ -26,10 +26,14 @@ public interface IdentificationsContract { void showEmptyIdentifications(); void showMessage(String message); + + void searchIdentificationList(Identification identification); } interface Presenter { void fetchIdentifications(String customerIdentifier); + + void searchIdentifications(String identifier, String number); } } 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 bca48e2..fa7613e 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 @@ -1,12 +1,18 @@ package org.apache.fineract.ui.online.identification.identificationlist; +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; @@ -23,6 +29,7 @@ import org.apache.fineract.ui.online.identification.identificationdetails.Identi import org.apache.fineract.utils.ConstantKeys; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.inject.Inject; @@ -73,6 +80,8 @@ public class IdentificationsFragment extends FineractBaseFragment implements if (getArguments() != null) { customerIdentifier = getArguments().getString(ConstantKeys.CUSTOMER_IDENTIFIER); } + + setHasOptionsMenu(true); } @Nullable @@ -128,6 +137,7 @@ public class IdentificationsFragment extends FineractBaseFragment implements @Override public void showIdentification(List<Identification> identifications) { showRecyclerView(true); + this.identifications = identifications; identificationAdapter.setIdentifications(identifications); } @@ -165,6 +175,11 @@ public class IdentificationsFragment extends FineractBaseFragment implements } @Override + public void searchIdentificationList(Identification identification) { + identificationAdapter.setIdentifications(Collections.singletonList(identification)); + } + + @Override public void showNoInternetConnection() { showRecyclerView(false); showFineractNoInternetUI(); @@ -177,6 +192,40 @@ public class IdentificationsFragment extends FineractBaseFragment implements } @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + inflater.inflate(R.menu.menu_identification_search, menu); + setUpSearchInterface(menu); + } + + private void setUpSearchInterface(Menu menu) { + + SearchManager manager = (SearchManager) getActivity(). + getSystemService(Context.SEARCH_SERVICE); + final SearchView searchView = (SearchView) menu.findItem( + R.id.identification_search).getActionView(); + searchView.setSearchableInfo(manager.getSearchableInfo(getActivity().getComponentName())); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + identificationsPresenter.searchIdentifications(customerIdentifier, query); + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + if (TextUtils.isEmpty(newText)) { + identificationAdapter.setIdentifications(identifications); + } + + return false; + } + }); + + } + + @Override public void onItemClick(View childView, int position) { ((FineractBaseActivity) getActivity()).replaceFragment( IdentificationDetailsFragment.newInstance(customerIdentifier, diff --git a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsPresenter.java b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsPresenter.java index fa1b855..dcee0a5 100644 --- a/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsPresenter.java +++ b/app/src/main/java/org/apache/fineract/ui/online/identification/identificationlist/IdentificationsPresenter.java @@ -20,7 +20,7 @@ import io.reactivex.schedulers.Schedulers; /** * @author Rajan Maurya - * On 31/07/17. + * On 31/07/17. */ @ConfigPersistent public class IdentificationsPresenter extends BasePresenter<IdentificationsContract.View> @@ -81,4 +81,36 @@ public class IdentificationsPresenter extends BasePresenter<IdentificationsContr }) ); } + + @Override + public void searchIdentifications(String identifier, String number) { + checkViewAttached(); + getMvpView().showProgressbar(); + + compositeDisposable.add(dataManagerCustomer.searchIdentifications(identifier, number) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribeWith(new DisposableObserver<Identification>() { + + @Override + public void onNext(Identification identification) { + getMvpView().hideProgressbar(); + getMvpView().searchIdentificationList(identification); + } + + @Override + public void onError(Throwable e) { + showExceptionError(e, context.getString + (R.string.error_finding_identification)); + } + + @Override + public void onComplete() { + + } + + })); + } + + } diff --git a/app/src/main/res/menu/menu_identification_search.xml b/app/src/main/res/menu/menu_identification_search.xml new file mode 100644 index 0000000..ca560c1 --- /dev/null +++ b/app/src/main/res/menu/menu_identification_search.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/identification_search" + android:icon="@drawable/ic_search_black_24dp" + android:title="@string/identification_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 965f297..d4c6784 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -168,6 +168,7 @@ <string name="customer_updated_successfully">%1$s updated successfully</string> <string name="created_by">Created by</string> <string name="no_deposit_account">No deposit account</string> + <string name="identification_search">Search identification card</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> @@ -213,11 +214,13 @@ <!--Empty data--> <string name="empty_create_loan_products">Oops there are no products, please create at least one to apply for loan</string> <string name="empty_identification_list">Oops there is no identification cards to show</string> + <string name="empty_identification_number">Identification number cannot be empty</string> <string name="empty_debts_to_show">There is no debts to show</string> <string name="empty_income_to_show">There is no income to show</string> <string name="empty_scans_to_show">There is no scans to show</string> <string name="empty_customer_activities">There is no activities to show</string> <string name="empty_roles">There is no roles to show</string> + <string name="empty_search">Search cannot be empty</string> <!--Edit Text validations--> <string name="value_must_greater_or_equal_to">Value must be greater than or equal to  %1$s</string> @@ -249,6 +252,7 @@ <string name="error_fetching_identification_list">Error while fetching identification cards</string> <string name="error_creating_identification_card">Error while creating identification card</string> <string name="error_updating_identification_card">Error while updating identification card</string> + <string name="error_finding_identification">Error find identification</string> <string name="error_fetching_scans">Error while fetching scan cards</string> <string name="error_uploading_identification_scan_card">Error while uploading identification scan card</string> <string name="error_deleting_identification_scan_card">Error while deleting identification scan card</string> diff --git a/app/src/main/resources/identification.json b/app/src/main/resources/identification.json index 25f163d..7101526 100644 --- a/app/src/main/resources/identification.json +++ b/app/src/main/resources/identification.json @@ -1,13 +1,43 @@ [ { - "type": "type", - "number": "number", + "type": "type1", + "number": "number1", "expirationDate": { "year": 1985, "month": 11, "day": 27 }, - "issuer": "issuer", + "issuer": "issuer1", + "createdBy": "createdBy", + "createdOn": "createdOn", + "lastModifiedBy": "lastModifiedBy", + "lastModifiedOn": "lastModifiedOn" + }, + + { + "type": "type2", + "number": "number2", + "expirationDate": { + "year": 1985, + "month": 11, + "day": 27 + }, + "issuer": "issuer2", + "createdBy": "createdBy", + "createdOn": "createdOn", + "lastModifiedBy": "lastModifiedBy", + "lastModifiedOn": "lastModifiedOn" + }, + + { + "type": "type3", + "number": "number3", + "expirationDate": { + "year": 1985, + "month": 11, + "day": 27 + }, + "issuer": "issuer3", "createdBy": "createdBy", "createdOn": "createdOn", "lastModifiedBy": "lastModifiedBy",