From 7e7dea2bd4f68e15d69e8d30c118ac2057508fa9 Mon Sep 17 00:00:00 2001 From: preyearegmi Date: Fri, 14 Sep 2018 19:02:58 +0900 Subject: [PATCH] Dialog for native added but yet to be integrated --- .../home/view/HomeFragment.java | 14 +- .../view1/NativeCountryListingRvAdapter.java | 63 ++++++ .../kycV2/view/view1/KYCView1Fragment.java | 17 ++ .../view1/NativeCountryListRvViewHolder.java | 38 ++++ .../view1/NativeCountryListingDialog.java | 202 ++++++++++++++++++ 5 files changed, 325 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/adapter/view1/NativeCountryListingRvAdapter.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListRvViewHolder.java create mode 100644 app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListingDialog.java diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/home/view/HomeFragment.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/home/view/HomeFragment.java index bd5aa6a6..0c8a0cb7 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/home/view/HomeFragment.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/home/view/HomeFragment.java @@ -42,7 +42,6 @@ import com.facebook.share.widget.ShareDialog; import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog; import com.gmeremit.online.gmeremittance_native.customwidgets.GmeTextView; -import com.gmeremit.online.gmeremittance_native.exchange_rate.view.ExchangeMethodActivity; import com.gmeremit.online.gmeremittance_native.exchange_rate.view.ExchangeMethodV2Activity; import com.gmeremit.online.gmeremittance_native.gme_branches.view.GmeBranchesActivity; import com.gmeremit.online.gmeremittance_native.home.HomeContract; @@ -51,8 +50,6 @@ import com.gmeremit.online.gmeremittance_native.home.helper.OnStartDragListener; import com.gmeremit.online.gmeremittance_native.home.helper.SimpleItemTouchHelperCallback; import com.gmeremit.online.gmeremittance_native.home.model.HomeMenus; import com.gmeremit.online.gmeremittance_native.home.model.Menu; -import com.gmeremit.online.gmeremittance_native.mobile_recharge.view.MobileRechargeActivity; -import com.gmeremit.online.gmeremittance_native.recipient.view.RecipientsListActivity; import com.gmeremit.online.gmeremittance_native.recipientV2.view.recipientlisting.RecipientListingV2Activity; import com.gmeremit.online.gmeremittance_native.reward_points.view.RewardPointsActivity; import com.gmeremit.online.gmeremittance_native.socials.SocialContract; @@ -74,7 +71,6 @@ import com.gmeremit.online.gmeremittance_native.transaction_statement.view.Trans import com.gmeremit.online.gmeremittance_native.utils.Constants; import com.gmeremit.online.gmeremittance_native.utils.Utils; import com.gmeremit.online.gmeremittance_native.utils.other.PersistenceStorageManager; -import com.gmeremit.online.gmeremittance_native.wallet_to_wallet.view.WalletToWalletActivity; import com.google.firebase.iid.FirebaseInstanceId; import com.google.gson.Gson; import com.squareup.picasso.MemoryPolicy; @@ -536,14 +532,14 @@ public class HomeFragment extends Fragment implements HomeContract.MenuItemClick } else if (id == 2) { // if (isVerified()) // startActivity(new Intent(getContext(), MobileRechargeActivity.class)); - showFetaureCommingSoon(); + showFetaureComingSoon(); } else if (id == 3) { startActivity(new Intent(getContext(), ExchangeMethodV2Activity.class)); } else if (id == 4) { startActivity(new Intent(getContext(), TrackYourTransferActivity.class)); } else if (id == 5) { startActivity(new Intent(getContext(), TransactionStatementActivity.class)); -// showFetaureCommingSoon(); +// showFetaureComingSoon(); } else if (id == 6) { // if (Utils.isNetworkConnected(getActivity())) { @@ -552,17 +548,17 @@ public class HomeFragment extends Fragment implements HomeContract.MenuItemClick // } // } else // showGeneralDialog("", "", INTERNET); - showFetaureCommingSoon(); + showFetaureComingSoon(); } } - private void showFetaureCommingSoon() + private void showFetaureComingSoon() { CustomAlertDialog customAlertDialog=new CustomAlertDialog(); customAlertDialog.setAlertType(CustomAlertDialog.AlertType.ALERT); - customAlertDialog.setMessage("This feature is comming soon"); + customAlertDialog.setMessage("This feature is coming soon"); android.app.FragmentManager fragmentManager = getActivity().getFragmentManager(); if (fragmentManager != null) customAlertDialog.show(fragmentManager, "CustomProgressBar"); diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/adapter/view1/NativeCountryListingRvAdapter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/adapter/view1/NativeCountryListingRvAdapter.java new file mode 100644 index 00000000..aa45a3e6 --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/adapter/view1/NativeCountryListingRvAdapter.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 { + + private final NativeCountryListingDialog.NativeCountrySelectionListener listener; + private List 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 data) { + if(data!=null) + { + this.data=data; + notifyDataSetChanged(); + } + } + + +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/KYCView1Fragment.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/KYCView1Fragment.java index 209e7c2b..84364b4a 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/KYCView1Fragment.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/KYCView1Fragment.java @@ -161,6 +161,23 @@ public class KYCView1Fragment extends BaseFragment implements View.OnClickListen showToastMessage("Please fill all the required."); break; } + } + + private void showNativeCountryList() + { + + } + private void showOccupationList() + { + + } + + private void showProvinceList() + { + + } + private void showGenderList() + { } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListRvViewHolder.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListRvViewHolder.java new file mode 100644 index 00000000..5a8f8c39 --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListRvViewHolder.java @@ -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); + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListingDialog.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListingDialog.java new file mode 100644 index 00000000..a9cbc9ab --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV2/view/view1/NativeCountryListingDialog.java @@ -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 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 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 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); + } +}