diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingDialog.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingDialog.java index 4ade1890..4f1b4f20 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingDialog.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingDialog.java @@ -2,10 +2,15 @@ package com.gmeremit.online.gmeremittance_native.customwidgets.countrylistingdia import android.app.Dialog; import android.app.DialogFragment; +import android.content.DialogInterface; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; +import android.text.Editable; +import android.text.TextWatcher; import android.view.View; +import android.view.Window; +import android.widget.EditText; import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.customwidgets.LineDividerItemDecoration; @@ -14,37 +19,50 @@ import com.gmeremit.online.gmeremittance_native.exchange_rate.model.datav2.Count import java.util.ArrayList; import java.util.List; -public class CountryListingDialog extends DialogFragment implements View.OnClickListener { +public class CountryListingDialog extends DialogFragment implements View.OnClickListener, TextWatcher { private List data; private CountrySelectionListener listener; private RecyclerView countryListRv; private View cancelButton; + private EditText noCountryFoundView; + private EditText searchEditTextView; + private CountryListingRvAdapter countryListingRvAdapter; @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_country_listing, null); countryListRv = view.findViewById(R.id.countryListRv); + noCountryFoundView = view.findViewById(R.id.noCountryFoundTextView); cancelButton = view.findViewById(R.id.iv_cancel); + searchEditTextView = view.findViewById(R.id.searchEditText); + builder.setView(view); initialize(); - return builder.create(); + Dialog dialog = builder.create(); + try { + Window window = dialog.getWindow(); + window.setBackgroundDrawableResource(R.drawable.ic_rounded_white); + } catch (NullPointerException e) { + + } + return dialog; } private void initialize() { cancelButton.setOnClickListener(this); - CountryListingRvAdapter countryListingRvAdapter=new CountryListingRvAdapter(this.listener); + searchEditTextView.addTextChangedListener(this); + countryListingRvAdapter = new CountryListingRvAdapter(this.listener); countryListingRvAdapter.setData(this.data); countryListRv.setAdapter(countryListingRvAdapter); - LineDividerItemDecoration lineDividerItemDecoration=new LineDividerItemDecoration(getActivity(),LineDividerItemDecoration.VERTICAL_LIST); + LineDividerItemDecoration lineDividerItemDecoration = new LineDividerItemDecoration(getActivity(), LineDividerItemDecoration.VERTICAL_LIST); countryListRv.addItemDecoration(lineDividerItemDecoration); } - public void setListener(CountrySelectionListener listener) - { - this.listener=listener; + public void setListener(CountrySelectionListener listener) { + this.listener = listener; } public void setCountryPaymentData(List data) { @@ -55,8 +73,7 @@ public class CountryListingDialog extends DialogFragment implements View.OnClick @Override public void onClick(View v) { - switch(v.getId()) - { + switch (v.getId()) { case R.id.iv_cancel: cancelButton.setOnClickListener(null); dismiss(); @@ -64,6 +81,62 @@ public class CountryListingDialog extends DialogFragment implements View.OnClick } } + @Override + public void onDismiss(DialogInterface dialog) { + super.onDismiss(dialog); + cancelButton.setOnClickListener(null); + searchEditTextView.removeTextChangedListener(this); + } + + private void showCountryNotFoundView(boolean action) { + if (action) { + int rvHeight = countryListRv.getHeight(); + noCountryFoundView.setHeight(rvHeight); + countryListRv.setVisibility(View.GONE); + noCountryFoundView.setVisibility(View.VISIBLE); + } else { + noCountryFoundView.setVisibility(View.GONE); + countryListRv.setVisibility(View.VISIBLE); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + if (countryListingRvAdapter != null) { + searchForCountry(s.toString()); + } + } + + private void searchForCountry(String s) { + if (this.data != null) { + if (s.length() > 0) { + List searchedData = new ArrayList<>(); + for (CountryPaymentService item : data) { + if (item.getCountry().toLowerCase().contains(s.toLowerCase())) { + searchedData.add(item); + } + } + if (searchedData.size() > 0) + showCountryNotFoundView(false); + else + showCountryNotFoundView(true); + countryListingRvAdapter.setData(searchedData); + + } else + countryListingRvAdapter.setData(this.data); + } + } + public interface CountrySelectionListener { void onCountrySelected(CountryPaymentService countryPaymentService); diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingRvAdapter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingRvAdapter.java index a6f7ecc6..bc82462b 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingRvAdapter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingRvAdapter.java @@ -54,4 +54,6 @@ public class CountryListingRvAdapter extends RecyclerView.Adapter + + + + + + - + + android:layout_weight="1"> + + + +