|
@ -2,10 +2,15 @@ package com.gmeremit.online.gmeremittance_native.customwidgets.countrylistingdia |
|
|
|
|
|
|
|
|
import android.app.Dialog; |
|
|
import android.app.Dialog; |
|
|
import android.app.DialogFragment; |
|
|
import android.app.DialogFragment; |
|
|
|
|
|
import android.content.DialogInterface; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.support.v7.app.AlertDialog; |
|
|
import android.support.v7.app.AlertDialog; |
|
|
import android.support.v7.widget.RecyclerView; |
|
|
import android.support.v7.widget.RecyclerView; |
|
|
|
|
|
import android.text.Editable; |
|
|
|
|
|
import android.text.TextWatcher; |
|
|
import android.view.View; |
|
|
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.R; |
|
|
import com.gmeremit.online.gmeremittance_native.customwidgets.LineDividerItemDecoration; |
|
|
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.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
public class CountryListingDialog extends DialogFragment implements View.OnClickListener { |
|
|
|
|
|
|
|
|
public class CountryListingDialog extends DialogFragment implements View.OnClickListener, TextWatcher { |
|
|
|
|
|
|
|
|
private List<CountryPaymentService> data; |
|
|
private List<CountryPaymentService> data; |
|
|
private CountrySelectionListener listener; |
|
|
private CountrySelectionListener listener; |
|
|
private RecyclerView countryListRv; |
|
|
private RecyclerView countryListRv; |
|
|
private View cancelButton; |
|
|
private View cancelButton; |
|
|
|
|
|
private EditText noCountryFoundView; |
|
|
|
|
|
private EditText searchEditTextView; |
|
|
|
|
|
private CountryListingRvAdapter countryListingRvAdapter; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) { |
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) { |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
|
|
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_country_listing, null); |
|
|
View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_country_listing, null); |
|
|
countryListRv = view.findViewById(R.id.countryListRv); |
|
|
countryListRv = view.findViewById(R.id.countryListRv); |
|
|
|
|
|
noCountryFoundView = view.findViewById(R.id.noCountryFoundTextView); |
|
|
cancelButton = view.findViewById(R.id.iv_cancel); |
|
|
cancelButton = view.findViewById(R.id.iv_cancel); |
|
|
|
|
|
searchEditTextView = view.findViewById(R.id.searchEditText); |
|
|
|
|
|
|
|
|
builder.setView(view); |
|
|
builder.setView(view); |
|
|
initialize(); |
|
|
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() { |
|
|
private void initialize() { |
|
|
cancelButton.setOnClickListener(this); |
|
|
cancelButton.setOnClickListener(this); |
|
|
CountryListingRvAdapter countryListingRvAdapter=new CountryListingRvAdapter(this.listener); |
|
|
|
|
|
|
|
|
searchEditTextView.addTextChangedListener(this); |
|
|
|
|
|
countryListingRvAdapter = new CountryListingRvAdapter(this.listener); |
|
|
countryListingRvAdapter.setData(this.data); |
|
|
countryListingRvAdapter.setData(this.data); |
|
|
countryListRv.setAdapter(countryListingRvAdapter); |
|
|
countryListRv.setAdapter(countryListingRvAdapter); |
|
|
LineDividerItemDecoration lineDividerItemDecoration=new LineDividerItemDecoration(getActivity(),LineDividerItemDecoration.VERTICAL_LIST); |
|
|
|
|
|
|
|
|
LineDividerItemDecoration lineDividerItemDecoration = new LineDividerItemDecoration(getActivity(), LineDividerItemDecoration.VERTICAL_LIST); |
|
|
countryListRv.addItemDecoration(lineDividerItemDecoration); |
|
|
countryListRv.addItemDecoration(lineDividerItemDecoration); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setListener(CountrySelectionListener listener) |
|
|
|
|
|
{ |
|
|
|
|
|
this.listener=listener; |
|
|
|
|
|
|
|
|
public void setListener(CountrySelectionListener listener) { |
|
|
|
|
|
this.listener = listener; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setCountryPaymentData(List<CountryPaymentService> data) { |
|
|
public void setCountryPaymentData(List<CountryPaymentService> data) { |
|
@ -55,8 +73,7 @@ public class CountryListingDialog extends DialogFragment implements View.OnClick |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onClick(View v) { |
|
|
public void onClick(View v) { |
|
|
switch(v.getId()) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
switch (v.getId()) { |
|
|
case R.id.iv_cancel: |
|
|
case R.id.iv_cancel: |
|
|
cancelButton.setOnClickListener(null); |
|
|
cancelButton.setOnClickListener(null); |
|
|
dismiss(); |
|
|
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<CountryPaymentService> 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 { |
|
|
public interface CountrySelectionListener { |
|
|
void onCountrySelected(CountryPaymentService countryPaymentService); |
|
|
void onCountrySelected(CountryPaymentService countryPaymentService); |
|
|