Browse Source

Search added

master
preyearegmi 6 years ago
parent
commit
7b7d99f358
  1. 91
      app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingDialog.java
  2. 2
      app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingRvAdapter.java
  3. 61
      app/src/main/res/layout/dialog_country_listing.xml

91
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<CountryPaymentService> 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<CountryPaymentService> 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<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 {
void onCountrySelected(CountryPaymentService countryPaymentService);

2
app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/countrylistingdialog/CountryListingRvAdapter.java

@ -54,4 +54,6 @@ public class CountryListingRvAdapter extends RecyclerView.Adapter<CountryListRvV
notifyDataSetChanged();
}
}
}

61
app/src/main/res/layout/dialog_country_listing.xml

@ -25,7 +25,47 @@
android:textColor="@color/colorAccent"
android:text="Cancel" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FBFBFB"
android:elevation="1dp"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="18dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_search_icon"
android:contentDescription="Search Icon"
/>
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeEditText
android:id="@+id/searchEditText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_weight="1"
android:maxLength="20"
android:background="@null"
android:gravity="center_vertical"
android:hint="Search country here..."
android:imeActionLabel="Done"
android:imeOptions="actionDone"
android:inputType="text"
android:textColor="@android:color/black"
android:textSize="14sp"
/>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/countryListRv"
@ -33,8 +73,25 @@
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
android:layout_height="match_parent" />
<com.gmeremit.online.gmeremittance_native.customwidgets.GmeEditText
android:id="@+id/noCountryFoundTextView"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:background="@null"
android:enabled="false"
android:gravity="center"
android:hint="No Country found."
android:imeActionLabel="Done"
android:imeOptions="actionDone"
android:inputType="text"
android:textColor="@android:color/black"
android:textSize="14sp"
/>
</FrameLayout>
</LinearLayout>
Loading…
Cancel
Save