preyearegmi
6 years ago
5 changed files with 325 additions and 9 deletions
-
14app/src/main/java/com/gmeremit/online/gmeremittance_native/home/view/HomeFragment.java
-
63app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/adapter/view1/NativeCountryListingRvAdapter.java
-
17app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/KYCView1Fragment.java
-
38app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListRvViewHolder.java
-
202app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListingDialog.java
@ -0,0 +1,63 @@ |
|||||
|
package com.gmeremit.online.gmeremittance_native.kycV2.adapter.view1; |
||||
|
|
||||
|
import android.support.v7.widget.RecyclerView; |
||||
|
import android.view.LayoutInflater; |
||||
|
import android.view.View; |
||||
|
import android.view.ViewGroup; |
||||
|
|
||||
|
import com.gmeremit.online.gmeremittance_native.R; |
||||
|
import com.gmeremit.online.gmeremittance_native.customwidgets.exchangecountrylistingdialog.CountryFlagMapper; |
||||
|
import com.gmeremit.online.gmeremittance_native.kycV2.model.NativeCountry; |
||||
|
import com.gmeremit.online.gmeremittance_native.kycV2.view.view1.NativeCountryListingDialog; |
||||
|
import com.gmeremit.online.gmeremittance_native.recipientV2.model.recipientadd.CountryDetailModel; |
||||
|
import com.gmeremit.online.gmeremittance_native.recipientV2.view.RecipientCountryListRvViewHolder; |
||||
|
import com.gmeremit.online.gmeremittance_native.recipientV2.view.RecipientCountryListingDialog; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class NativeCountryListingRvAdapter extends RecyclerView.Adapter<RecipientCountryListRvViewHolder> { |
||||
|
|
||||
|
private final NativeCountryListingDialog.NativeCountrySelectionListener listener; |
||||
|
private List<NativeCountry> data; |
||||
|
|
||||
|
public NativeCountryListingRvAdapter(NativeCountryListingDialog.NativeCountrySelectionListener listener) { |
||||
|
this.data=new ArrayList<>(); |
||||
|
this.listener=listener; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public RecipientCountryListRvViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
||||
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.countrylist_item_view, parent, false); |
||||
|
return new RecipientCountryListRvViewHolder(view); } |
||||
|
|
||||
|
@Override |
||||
|
public void onBindViewHolder(final RecipientCountryListRvViewHolder holder, int position) { |
||||
|
holder.itemView.setOnClickListener(new View.OnClickListener() { |
||||
|
@Override |
||||
|
public void onClick(View v) { |
||||
|
if(listener!=null) |
||||
|
listener.onNativeCountrySelected(data.get(holder.getAdapterPosition())); |
||||
|
} |
||||
|
}); |
||||
|
NativeCountry countryPaymentService= data.get(position); |
||||
|
// holder.setFlagImage(CountryFlagMapper.getFlagFromCountryCode(countryPaymentService.getCode())); |
||||
|
// holder.setCountryName(countryPaymentService.getName()); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int getItemCount() { |
||||
|
return data.size(); |
||||
|
} |
||||
|
|
||||
|
public void setData(List<NativeCountry> data) { |
||||
|
if(data!=null) |
||||
|
{ |
||||
|
this.data=data; |
||||
|
notifyDataSetChanged(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
package com.gmeremit.online.gmeremittance_native.kycV2.view.view1; |
||||
|
|
||||
|
import android.support.v7.widget.RecyclerView; |
||||
|
import android.view.View; |
||||
|
import android.widget.ImageView; |
||||
|
import android.widget.TextView; |
||||
|
|
||||
|
import com.gmeremit.online.gmeremittance_native.R; |
||||
|
|
||||
|
import butterknife.BindView; |
||||
|
import butterknife.ButterKnife; |
||||
|
|
||||
|
public class NativeCountryListRvViewHolder extends RecyclerView.ViewHolder { |
||||
|
|
||||
|
@BindView(R.id.countryName) |
||||
|
TextView countryNameTxtView; |
||||
|
|
||||
|
@BindView(R.id.countryFlagImageView) |
||||
|
ImageView countryImageView; |
||||
|
|
||||
|
|
||||
|
public NativeCountryListRvViewHolder(View itemView) { |
||||
|
super(itemView); |
||||
|
ButterKnife.bind(this, itemView); |
||||
|
} |
||||
|
|
||||
|
public void setFlagImage(int resId) |
||||
|
{ |
||||
|
if(resId!=-1) |
||||
|
countryImageView.setBackgroundResource(resId); |
||||
|
} |
||||
|
|
||||
|
public void setCountryName(String name) |
||||
|
{ |
||||
|
if(name!=null) |
||||
|
countryNameTxtView.setText(name); |
||||
|
} |
||||
|
} |
@ -0,0 +1,202 @@ |
|||||
|
package com.gmeremit.online.gmeremittance_native.kycV2.view.view1; |
||||
|
|
||||
|
import android.app.Dialog; |
||||
|
import android.app.DialogFragment; |
||||
|
import android.content.Context; |
||||
|
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.util.Log; |
||||
|
import android.view.View; |
||||
|
import android.view.ViewGroup; |
||||
|
import android.view.Window; |
||||
|
import android.view.inputmethod.InputMethodManager; |
||||
|
import android.widget.EditText; |
||||
|
|
||||
|
import com.gmeremit.online.gmeremittance_native.R; |
||||
|
import com.gmeremit.online.gmeremittance_native.customwidgets.LineDividerItemDecoration; |
||||
|
import com.gmeremit.online.gmeremittance_native.kycV2.adapter.view1.NativeCountryListingRvAdapter; |
||||
|
import com.gmeremit.online.gmeremittance_native.kycV2.model.NativeCountry; |
||||
|
import com.gmeremit.online.gmeremittance_native.recipientV2.adapter.RecipientCountryListingRvAdapter; |
||||
|
import com.gmeremit.online.gmeremittance_native.recipientV2.model.recipientadd.CountryDetailModel; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class NativeCountryListingDialog extends DialogFragment implements View.OnClickListener, TextWatcher { |
||||
|
|
||||
|
private List<NativeCountry> data; |
||||
|
private NativeCountrySelectionListener listener; |
||||
|
private RecyclerView countryListRv; |
||||
|
private View cancelButton; |
||||
|
private EditText noCountryFoundView; |
||||
|
private EditText searchEditTextView; |
||||
|
private NativeCountryListingRvAdapter countryListingRvAdapter; |
||||
|
private View searchViewContainer; |
||||
|
|
||||
|
|
||||
|
@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); |
||||
|
searchViewContainer= view.findViewById(R.id.searchViewContainer); |
||||
|
|
||||
|
builder.setView(view); |
||||
|
|
||||
|
|
||||
|
initialize(); |
||||
|
return builder.create(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private void initialize() { |
||||
|
cancelButton.setOnClickListener(this); |
||||
|
searchEditTextView.addTextChangedListener(this); |
||||
|
countryListingRvAdapter = new NativeCountryListingRvAdapter(this.listener); |
||||
|
countryListingRvAdapter.setData(this.data); |
||||
|
countryListRv.setAdapter(countryListingRvAdapter); |
||||
|
LineDividerItemDecoration lineDividerItemDecoration = new LineDividerItemDecoration(getActivity(), LineDividerItemDecoration.VERTICAL_LIST); |
||||
|
countryListRv.addItemDecoration(lineDividerItemDecoration); |
||||
|
|
||||
|
searchViewContainer.setOnClickListener(new View.OnClickListener() { |
||||
|
@Override |
||||
|
public void onClick(View v) { |
||||
|
searchEditTextView.requestFocus(); |
||||
|
showKeyBoard(searchEditTextView); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void setListener(NativeCountrySelectionListener listener) { |
||||
|
this.listener = listener; |
||||
|
} |
||||
|
|
||||
|
public void setCountryData(List<NativeCountry> data) { |
||||
|
if (data != null) { |
||||
|
this.data = data; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onStart() { |
||||
|
super.onStart(); |
||||
|
|
||||
|
Window window = getDialog().getWindow(); |
||||
|
if (window != null) { |
||||
|
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); |
||||
|
window.setBackgroundDrawableResource(R.drawable.ic_rounded_grey_bg_with_inset); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onClick(View v) { |
||||
|
switch (v.getId()) { |
||||
|
case R.id.iv_cancel: |
||||
|
cancelButton.setOnClickListener(null); |
||||
|
hideKeyboard(); |
||||
|
dismiss(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void onDismiss(DialogInterface dialog) { |
||||
|
super.onDismiss(dialog); |
||||
|
cancelButton.setOnClickListener(null); |
||||
|
searchEditTextView.removeTextChangedListener(this); |
||||
|
searchViewContainer.setOnClickListener(null); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private void showCountryNotFoundView(boolean action) { |
||||
|
if (action) { |
||||
|
if (countryListRv.getVisibility() == View.VISIBLE) { |
||||
|
countryListRv.setVisibility(View.GONE); |
||||
|
noCountryFoundView.setVisibility(View.VISIBLE); |
||||
|
} |
||||
|
} else { |
||||
|
if (countryListRv.getVisibility() != View.VISIBLE) { |
||||
|
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<NativeCountry> searchedData = new ArrayList<>(); |
||||
|
for (NativeCountry item : data) { |
||||
|
if (item.getText().toLowerCase().contains(s.toLowerCase())) { |
||||
|
searchedData.add(item); |
||||
|
} |
||||
|
} |
||||
|
if (searchedData.size() > 0) |
||||
|
showCountryNotFoundView(false); |
||||
|
else |
||||
|
showCountryNotFoundView(true); |
||||
|
countryListingRvAdapter.setData(searchedData); |
||||
|
|
||||
|
} else { |
||||
|
showCountryNotFoundView(false); |
||||
|
countryListingRvAdapter.setData(this.data); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void hideKeyboard() { |
||||
|
// Check if no view has focus: |
||||
|
try { |
||||
|
View view = getActivity().getCurrentFocus(); |
||||
|
|
||||
|
InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); |
||||
|
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); |
||||
|
} |
||||
|
catch(Exception ex) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void showKeyBoard(View view) { |
||||
|
try { |
||||
|
InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
||||
|
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); |
||||
|
Log.d("GMEEXCEPTION", "Keyboard shown"); |
||||
|
} catch (NullPointerException e) { |
||||
|
Log.d("GMEEXCEPTION", "Null pointer while showing keyboard"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public interface NativeCountrySelectionListener { |
||||
|
void onNativeCountrySelected(NativeCountry countryPaymentService); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue