From 2fbf80a72f5c4cecc2d5654c8fadc210ebbaabe7 Mon Sep 17 00:00:00 2001 From: preyearegmi Date: Mon, 10 Sep 2018 13:45:44 +0900 Subject: [PATCH] Branch search fixes --- .../CountryFlagMapper.java | 1 + .../AmountDetailSendMoneyFragment.java | 27 ++++- .../PayoutModeBranchListingDialog.java | 113 +++++++++++++----- 3 files changed, 105 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/exchangecountrylistingdialog/CountryFlagMapper.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/exchangecountrylistingdialog/CountryFlagMapper.java index c614f3a8..a4e31f0c 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/exchangecountrylistingdialog/CountryFlagMapper.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/customwidgets/exchangecountrylistingdialog/CountryFlagMapper.java @@ -6,6 +6,7 @@ public class CountryFlagMapper { public static int getFlagFromCountryCode(String countryCode) { switch (countryCode) { + case "BD": return R.drawable.flag_bangladesh; case "KH": diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/amountdetail/AmountDetailSendMoneyFragment.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/amountdetail/AmountDetailSendMoneyFragment.java index 09db911f..dfba914c 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/amountdetail/AmountDetailSendMoneyFragment.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/amountdetail/AmountDetailSendMoneyFragment.java @@ -219,9 +219,14 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. } private void showSelectedCurrency(String selectedCountryCode, String selectedCountryCurrency) { - int flagResId = CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode); + int flagResId = -1; + if (selectedCountryCode != null) + flagResId = CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode); if (flagResId != -1) - this.recepientFlagImageView.setBackgroundResource(CountryFlagMapper.getFlagFromCountryCode(selectedCountryCode)); + this.recepientFlagImageView.setBackgroundResource(flagResId); + else + this.recepientFlagImageView.setBackgroundResource(0); + if (selectedCountryCurrency != null) this.recepientCurrencyTextView.setText(selectedCountryCurrency); } @@ -366,15 +371,25 @@ public class AmountDetailSendMoneyFragment extends BaseFragment implements View. protected void onSuccess(AmountDetailRelatedDataModel amountDetailRelatedDataModel) { if (isUIReady()) { amountDetailRelatedData = amountDetailRelatedDataModel; - if (amountDetailRelatedData.getDefaultSelectedCurrency() != null) + if (amountDetailRelatedData == null||amountDetailRelatedData.getDefaultSelectedCurrency()==null){ + showSelectedCurrency("", "---"); + showPopUpMessage("No payout currency defined, please contact support.", CustomAlertDialog.AlertType.ALERT, null); + continueBtn.setOnClickListener(null); + } else { showSelectedCurrency(amountDetailRelatedData.getDefaultSelectedCurrency().getCountryCode(), amountDetailRelatedData.getDefaultSelectedCurrency().getCurrencyCode()); - updateButtonToCalculate(true); + updateButtonToCalculate(true); + } } scheduleTaskLater(() -> { amountDetailRelatedData = amountDetailRelatedDataModel; - if (amountDetailRelatedData.getDefaultSelectedCurrency() != null) + if (amountDetailRelatedData == null||amountDetailRelatedData.getDefaultSelectedCurrency()==null) { + showSelectedCurrency("", "---"); + showPopUpMessage("No payout currency defined, please contact support.", CustomAlertDialog.AlertType.ALERT, null); + continueBtn.setOnClickListener(null); + } else { showSelectedCurrency(amountDetailRelatedData.getDefaultSelectedCurrency().getCountryCode(), amountDetailRelatedData.getDefaultSelectedCurrency().getCurrencyCode()); - updateButtonToCalculate(true); + updateButtonToCalculate(true); + } }); } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/payoutmode/PayoutModeBranchListingDialog.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/payoutmode/PayoutModeBranchListingDialog.java index 4765202b..d96b17bf 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/payoutmode/PayoutModeBranchListingDialog.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/sendmoneyV2/view/payoutmode/PayoutModeBranchListingDialog.java @@ -25,6 +25,7 @@ import android.widget.ProgressBar; import android.widget.TextView; import com.gmeremit.online.gmeremittance_native.R; +import com.gmeremit.online.gmeremittance_native.base.UIStateHandler; import com.gmeremit.online.gmeremittance_native.customwidgets.LineDividerItemDecoration; import com.gmeremit.online.gmeremittance_native.sendmoneyV2.adapter.PayoutModeBranchListingRvAdapter; import com.gmeremit.online.gmeremittance_native.sendmoneyV2.model.amountdetail.BranchListApiResponse; @@ -55,6 +56,9 @@ public class PayoutModeBranchListingDialog extends DialogFragment implements Vie private CompositeDisposable compositeDisposable; private ProgressBar progressBar; private Interpolator interpolator; + private boolean isUIReady=false; + UIStateHandler uiStateHandler; + @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -74,9 +78,26 @@ public class PayoutModeBranchListingDialog extends DialogFragment implements Vie } + + @Override + public void onPause() { + super.onPause(); + isUIReady=false; + + } + + @Override + public void onResume() { + super.onResume(); + isUIReady=true; + if(uiStateHandler!=null) + uiStateHandler.performPendingUITask(); + } + + private void initialize() { dialogTitle.setText("Select Branch"); - + uiStateHandler=new UIStateHandler(); cancelButton.setOnClickListener(this); searchEditTextView.addTextChangedListener(this); payoutModeBranchListingRvAdapter = new PayoutModeBranchListingRvAdapter(this.listener); @@ -127,6 +148,8 @@ public class PayoutModeBranchListingDialog extends DialogFragment implements Vie @Override public void onDismiss(DialogInterface dialog) { super.onDismiss(dialog); + uiStateHandler.clearPendingTask(); + uiStateHandler=null; cancelButton.setOnClickListener(null); searchEditTextView.removeTextChangedListener(this); compositeDisposable.dispose(); @@ -188,14 +211,11 @@ public class PayoutModeBranchListingDialog extends DialogFragment implements Vie if(noCountryFoundView.getVisibility()!=View.VISIBLE) noCountryFoundView.setVisibility(View.VISIBLE); noCountryFoundView.setHint(message); - } else { if(noCountryFoundView.getVisibility()==View.VISIBLE) noCountryFoundView.setVisibility(View.INVISIBLE); noCountryFoundView.setHint(""); - - } } @@ -255,44 +275,77 @@ public class PayoutModeBranchListingDialog extends DialogFragment implements Vie @Override protected void onSuccess(BranchListApiResponse branchListApiResponse) { - hideProgressView(true); - - if(branchListApiResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) - { - if(branchListApiResponse.getData().isEmpty()) - { - showErrorMessage(false,NO_BRANCH_FOUND); - - } - else - { - showErrorMessage(false, ""); - showRecyclerView(true); - payoutModeBranchListingRvAdapter.setData(branchListApiResponse.getData()); - } - } - else - { - showErrorMessage(true,branchListApiResponse.getMsg()); - showRecyclerView(false); - } + if(isUIReady) { + hideProgressView(true); + + if (branchListApiResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { + if (branchListApiResponse.getData().isEmpty()) { + showErrorMessage(false, NO_BRANCH_FOUND); + + } else { + showErrorMessage(false, ""); + showRecyclerView(true); + payoutModeBranchListingRvAdapter.setData(branchListApiResponse.getData()); + } + } else { + showErrorMessage(true, branchListApiResponse.getMsg()); + showRecyclerView(false); + } + } + else + { + uiStateHandler.enqueueUITask(()->{ + hideProgressView(true); + + if (branchListApiResponse.getErrorCode().equalsIgnoreCase(Constants.SUCCESS_CODE_V2)) { + if (branchListApiResponse.getData().isEmpty()) { + showErrorMessage(false, NO_BRANCH_FOUND); + + } else { + showErrorMessage(false, ""); + showRecyclerView(true); + payoutModeBranchListingRvAdapter.setData(branchListApiResponse.getData()); + } + } else { + showErrorMessage(true, branchListApiResponse.getMsg()); + showRecyclerView(false); + } + }); + } } @Override public void onFailed(String message) { - hideProgressView(true); - showErrorMessage(true,message); + if(isUIReady) { + hideProgressView(true); + showErrorMessage(true, message); + } + else + { + uiStateHandler.enqueueUITask(()->{ + hideProgressView(true); + showErrorMessage(true, message); + }); + } } @Override protected void onConnectionNotEstablished(String message) { - hideProgressView(true); - showErrorMessage(true,message); - + if(isUIReady) { + hideProgressView(true); + showErrorMessage(true, message); + } + else + { + uiStateHandler.enqueueUITask(()->{ + hideProgressView(true); + showErrorMessage(true, message); + }); + } } }