From 1b41abdb385e7f6b043af4effaa97615e74f8ede Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Mon, 6 May 2019 12:28:57 -0700 Subject: [PATCH 01/27] initial-gql-integration --- .../ui/repository/TransferMethodConfigurationRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java index e89c8bab5..49bfc8b75 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java @@ -36,6 +36,7 @@ public interface TransferMethodConfigurationRepository { + //TODO update GQL integration development feature void getKeys(@NonNull final LoadKeysCallback loadKeysCallback); void getFields(@NonNull final String country, @NonNull final String currency, From bbf223c0c61d8d29615595cd7058a6e562f75390 Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Mon, 6 May 2019 12:34:04 -0700 Subject: [PATCH 02/27] initial gql integration code compilation and test passed state --- ...TransferMethodConfigurationRepository.java | 15 +- ...sferMethodConfigurationRepositoryImpl.java | 76 ++--- .../AddTransferMethodContract.java | 8 +- .../AddTransferMethodFragment.java | 15 +- .../AddTransferMethodPresenter.java | 18 +- .../ui/transfermethod/FeeFormatter.java | 34 +- .../SelectTransferMethodPresenter.java | 69 ++--- .../TransferMethodSelectionItem.java | 12 +- .../ui/view/widget/AbstractWidget.java | 2 +- .../android/ui/view/widget/DateWidget.java | 2 +- .../ui/view/widget/ExpiryDateWidget.java | 2 +- .../android/ui/view/widget/NumberWidget.java | 2 +- .../android/ui/view/widget/PhoneWidget.java | 2 +- .../ui/view/widget/SelectionWidget.java | 4 +- .../android/ui/view/widget/TextWidget.java | 2 +- .../android/ui/view/widget/WidgetFactory.java | 4 +- ...MethodConfigurationRepositoryImplTest.java | 81 ++--- .../AddTransferMethodPresenterTest.java | 35 +-- .../ui/transfermethod/FeeFormatterTest.java | 70 +++-- .../SelectTransferMethodPresenterTest.java | 9 +- .../add_transfer_method_presenter_test.json | 37 ++- ui/src/test/resources/fee_information.json | 77 +++++ .../successful_tmc_fields_response.json | 216 ++++++++----- .../successful_tmc_keys_response.json | 292 ++++++++---------- 24 files changed, 624 insertions(+), 460 deletions(-) create mode 100644 ui/src/test/resources/fee_information.json diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java index 49bfc8b75..57d42645e 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepository.java @@ -24,19 +24,17 @@ * USE OR OTHER DEALINGS * IN THE SOFTWARE. */ - package com.hyperwallet.android.ui.repository; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.hyperwallet.android.model.HyperwalletErrors; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationField; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKey; public interface TransferMethodConfigurationRepository { - //TODO update GQL integration development feature void getKeys(@NonNull final LoadKeysCallback loadKeysCallback); void getFields(@NonNull final String country, @NonNull final String currency, @@ -47,15 +45,16 @@ void getFields(@NonNull final String country, @NonNull final String currency, void refreshFields(); interface LoadKeysCallback { - void onKeysLoaded( - @Nullable final HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult); + + void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKey transferMethodConfigurationKey); void onError(@NonNull final HyperwalletErrors errors); } interface LoadFieldsCallback { - void onFieldsLoaded(@Nullable final HyperwalletTransferMethodConfigurationFieldResult - transferMethodConfigurationFieldResult); + + void onFieldsLoaded(@Nullable final HyperwalletTransferMethodConfigurationField field, + @Nullable final String processingType); void onError(@NonNull final HyperwalletErrors errors); } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java index 008c87176..2d1d10d85 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java @@ -24,7 +24,6 @@ * USE OR OTHER DEALINGS * IN THE SOFTWARE. */ - package com.hyperwallet.android.ui.repository; import android.os.Handler; @@ -36,8 +35,9 @@ import com.hyperwallet.android.Hyperwallet; import com.hyperwallet.android.exception.HyperwalletException; import com.hyperwallet.android.listener.HyperwalletListener; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationField; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKey; +import com.hyperwallet.android.model.meta.keyed.HyperwalletTransferMethodType; import com.hyperwallet.android.model.meta.query.HyperwalletTransferMethodConfigurationFieldQuery; import com.hyperwallet.android.model.meta.query.HyperwalletTransferMethodConfigurationKeysQuery; import com.hyperwallet.android.ui.util.EspressoIdlingResource; @@ -45,12 +45,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Set; public class TransferMethodConfigurationRepositoryImpl implements TransferMethodConfigurationRepository { private static final String INDIVIDUAL = "INDIVIDUAL"; - private HyperwalletTransferMethodConfigurationKeyResult mTransferMethodConfigurationKeyResult; + private HyperwalletTransferMethodConfigurationKey mTransferMethodConfigurationKey; private final Handler mHandler; - private final Map mFieldMap; + private final Map mFieldMap; TransferMethodConfigurationRepositoryImpl() { mHandler = new Handler(); @@ -64,11 +65,10 @@ Hyperwallet getHyperwallet() { @VisibleForTesting() protected TransferMethodConfigurationRepositoryImpl(@Nullable Handler handler, - HyperwalletTransferMethodConfigurationKeyResult - transferMethodConfigurationKeyResult, Map fieldMap) { + HyperwalletTransferMethodConfigurationKey transferMethodConfigurationKey, + Map fieldMap) { mHandler = handler; - mTransferMethodConfigurationKeyResult = transferMethodConfigurationKeyResult; + mTransferMethodConfigurationKey = transferMethodConfigurationKey; mFieldMap = fieldMap; } @@ -78,11 +78,11 @@ void getTransferMethodConfigurationKeyResult(final LoadKeysCallback loadKeysCall EspressoIdlingResource.increment(); getHyperwallet().retrieveTransferMethodConfigurationKeys(query, - new HyperwalletListener() { + new HyperwalletListener() { @Override - public void onSuccess(@Nullable HyperwalletTransferMethodConfigurationKeyResult result) { - mTransferMethodConfigurationKeyResult = result; - loadKeysCallback.onKeysLoaded(mTransferMethodConfigurationKeyResult); + public void onSuccess(@Nullable HyperwalletTransferMethodConfigurationKey result) { + mTransferMethodConfigurationKey = result; + loadKeysCallback.onKeysLoaded(mTransferMethodConfigurationKey); EspressoIdlingResource.decrement(); } @@ -111,12 +111,13 @@ void getTransferMethodConfigurationFieldResult(@NonNull final String country, getHyperwallet().retrieveTransferMethodConfigurationFields( query, - new HyperwalletListener() { + new HyperwalletListener() { @Override - public void onSuccess(HyperwalletTransferMethodConfigurationFieldResult result) { + public void onSuccess(HyperwalletTransferMethodConfigurationField result) { FieldMapKey fieldMapKey = new FieldMapKey(country, currency, transferMethodType); mFieldMap.put(fieldMapKey, result); - loadFieldsCallback.onFieldsLoaded(result); + loadFieldsCallback.onFieldsLoaded(result, + getProcessingTime(country, currency, transferMethodType)); EspressoIdlingResource.decrement(); } @@ -136,10 +137,10 @@ public Handler getHandler() { @Override public synchronized void getKeys(@NonNull final LoadKeysCallback loadKeysCallback) { - if (mTransferMethodConfigurationKeyResult == null) { + if (mTransferMethodConfigurationKey == null) { getTransferMethodConfigurationKeyResult(loadKeysCallback); } else { - loadKeysCallback.onKeysLoaded(mTransferMethodConfigurationKeyResult); + loadKeysCallback.onKeysLoaded(mTransferMethodConfigurationKey); } } @@ -147,27 +148,42 @@ public synchronized void getKeys(@NonNull final LoadKeysCallback loadKeysCallbac public synchronized void getFields(@NonNull final String country, @NonNull final String currency, @NonNull final String transferMethodType, @NonNull final LoadFieldsCallback loadFieldsCallback) { + FieldMapKey fieldMapKey = new FieldMapKey(country, currency, transferMethodType); - HyperwalletTransferMethodConfigurationFieldResult transferMethodConfigurationFieldResult = mFieldMap.get( - fieldMapKey); + HyperwalletTransferMethodConfigurationField transferMethodConfigurationField = mFieldMap.get(fieldMapKey); // if there is no value for country-currency-type combination, // it means api call was never made or this combination or it was refreshed - if (transferMethodConfigurationFieldResult == null) { + if (transferMethodConfigurationField == null) { getTransferMethodConfigurationFieldResult(country, currency, transferMethodType, loadFieldsCallback); } else { - loadFieldsCallback.onFieldsLoaded(transferMethodConfigurationFieldResult); + loadFieldsCallback.onFieldsLoaded(transferMethodConfigurationField, + getProcessingTime(country, currency, transferMethodType)); } } @Override public void refreshKeys() { - mTransferMethodConfigurationKeyResult = null; + mTransferMethodConfigurationKey = null; } @Override public void refreshFields() { mFieldMap.clear(); } + + @Nullable + private String getProcessingTime(String country, String currency, String transferMethodType) { + if (mTransferMethodConfigurationKey != null) { + Set transferMethodTypes = mTransferMethodConfigurationKey + .getTransferMethodType(country, currency); + for (HyperwalletTransferMethodType type : transferMethodTypes) { + if (type.getName().equals(transferMethodType)) { + return type.getProcessingTime(); + } + } + } + return null; + } } class FieldMapKey { @@ -181,18 +197,6 @@ class FieldMapKey { this.mTransferMethodType = mTransferMethodType; } - private String getCountry() { - return mCountry; - } - - private String getCurrency() { - return mCurrency; - } - - private String getTransferMethodType() { - return mTransferMethodType; - } - @Override public boolean equals(Object o) { @@ -211,6 +215,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(mCountry, mCurrency, mTransferMethodType); } - - } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java index 6b2d136ba..1966e1467 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodContract.java @@ -20,8 +20,8 @@ import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletTransferMethod; -import com.hyperwallet.android.model.meta.Fee; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.HyperwalletFee; +import com.hyperwallet.android.model.meta.field.HyperwalletFieldGroup; import java.util.List; @@ -38,9 +38,9 @@ interface View { void showErrorLoadTransferMethodConfigurationFields(@NonNull final List errors); - void showTransferMethodFields(@NonNull final List fields); + void showTransferMethodFields(@NonNull final List fields); - void showTransactionInformation(List fees, String processingTime); + void showTransactionInformation(List fees, String processingTime); void showCreateButtonProgressBar(); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java index 131ec7e0e..31e565882 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java @@ -48,8 +48,9 @@ import com.hyperwallet.android.model.HyperwalletBankCard; import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletTransferMethod; -import com.hyperwallet.android.model.meta.Fee; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.HyperwalletFee; +import com.hyperwallet.android.model.meta.field.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletFieldGroup; import com.hyperwallet.android.ui.HyperwalletLocalBroadcast; import com.hyperwallet.android.ui.repository.RepositoryFactory; import com.hyperwallet.android.ui.view.WidgetSelectionDialogFragment; @@ -287,11 +288,14 @@ public void notifyTransferMethodAdded(@NonNull final HyperwalletTransferMethod t } @Override - public void showTransferMethodFields(@NonNull final List fields) { + public void showTransferMethodFields(@NonNull final List fields) { mDynamicContainer.removeAllViews(); int previousView = 0; try { - for (final HyperwalletField field : fields) { + + + //TODO adjust groupings + for (final HyperwalletField field : fields.get(0).getFields()) { AbstractWidget widget = WidgetFactory .newWidget(field, this, getContext(), mWidgetInputStateHashMap.containsKey(field.getName()) ? @@ -318,7 +322,8 @@ public void showTransferMethodFields(@NonNull final List field } @Override - public void showTransactionInformation(@NonNull final List fees, @Nullable final String processingTime) { + public void showTransactionInformation(@NonNull final List fees, + @Nullable final String processingTime) { View header = getView().findViewById(R.id.add_transfer_method_static_container_header); View container = getView().findViewById(R.id.add_transfer_method_static_container); View feeLabel = getView().findViewById(R.id.add_transfer_method_fee_label); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java index dc048c1d1..7b6885bfc 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenter.java @@ -17,11 +17,12 @@ package com.hyperwallet.android.ui.transfermethod; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.hyperwallet.android.model.HyperwalletErrors; import com.hyperwallet.android.model.HyperwalletTransferMethod; -import com.hyperwallet.android.model.meta.Fee; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult; +import com.hyperwallet.android.model.meta.HyperwalletFee; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationField; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; import com.hyperwallet.android.ui.repository.TransferMethodRepository; @@ -85,20 +86,17 @@ public void loadTransferMethodConfigurationFields(final boolean forceUpdate, @No mTransferMethodConfigurationRepository.getFields( country, currency, transferMethodType, new TransferMethodConfigurationRepository.LoadFieldsCallback() { @Override - public void onFieldsLoaded( - HyperwalletTransferMethodConfigurationFieldResult transferMethodConfigurationFieldResult) { + public void onFieldsLoaded(HyperwalletTransferMethodConfigurationField field, + @Nullable final String processingType) { if (!mView.isActive()) { return; } mView.hideProgressBar(); - mView.showTransferMethodFields(transferMethodConfigurationFieldResult.getFields()); + mView.showTransferMethodFields(field.getFields().getFieldGroups()); // there can be multiple fees when we have flat fee + percentage fees - List fees = transferMethodConfigurationFieldResult - .getFees(country, currency, transferMethodType, "INDIVIDUAL"); - mView.showTransactionInformation(fees, - transferMethodConfigurationFieldResult - .getProcessingTime(country, currency, transferMethodType, "INDIVIDUAL")); + List fees = field.getFees(); + mView.showTransactionInformation(fees, processingType); } @Override diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/FeeFormatter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/FeeFormatter.java index 95cf1cf22..095c218c7 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/FeeFormatter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/FeeFormatter.java @@ -23,13 +23,13 @@ import androidx.annotation.NonNull; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.Fee; +import com.hyperwallet.android.model.meta.HyperwalletFee; import java.util.List; public class FeeFormatter { - public static String getFormattedFee(@NonNull final Context context, @NonNull final List fees) { + public static String getFormattedFee(@NonNull final Context context, @NonNull final List fees) { String formattedString = context.getResources().getString(R.string.unknown); if (fees.size() == 1) { formattedString = getSingleFormattedFee(context, fees, formattedString); @@ -39,13 +39,13 @@ public static String getFormattedFee(@NonNull final Context context, @NonNull fi return formattedString; } - private static String getSingleFormattedFee(@NonNull Context context, @NonNull List fees, + private static String getSingleFormattedFee(@NonNull Context context, @NonNull List fees, String formattedString) { - Fee fee = fees.get(0); - if (Fee.FeeRate.FLAT.equals(fee.getFeeRateType())) { + HyperwalletFee fee = fees.get(0); + if (HyperwalletFee.FeeRate.FLAT.equals(fee.getFeeRateType())) { formattedString = context.getResources().getString(R.string.fee_flat_formatter, fee.getCurrency(), fee.getValue()); - } else if (Fee.FeeRate.PERCENT.equals(fee.getFeeRateType())) { + } else if (HyperwalletFee.FeeRate.PERCENT.equals(fee.getFeeRateType())) { formattedString = getPercentFormattedFee(context, fee); } return formattedString; @@ -53,20 +53,20 @@ private static String getSingleFormattedFee(@NonNull Context context, @NonNull L // we expect at the most 2 fees and in that case one should be flat and other percent // which will be formatted to USD 3.00 + 3% (Min: USD 1.00, Max: USD 15.00) - private static String getMixFormattedFee(@NonNull Context context, @NonNull List fees, + private static String getMixFormattedFee(@NonNull Context context, @NonNull List fees, String formattedString) { - Fee flatFee = null; - Fee percentFee = null; - for (Fee fee : fees) { - if (Fee.FeeRate.FLAT.equals(fee.getFeeRateType())) { + HyperwalletFee flatFee = null; + HyperwalletFee percentFee = null; + for (HyperwalletFee fee : fees) { + if (HyperwalletFee.FeeRate.FLAT.equals(fee.getFeeRateType())) { flatFee = fee; - } else if (Fee.FeeRate.PERCENT.equals(fee.getFeeRateType())) { + } else if (HyperwalletFee.FeeRate.PERCENT.equals(fee.getFeeRateType())) { percentFee = fee; } } if (flatFee != null && percentFee != null) { - String minimumAmount = percentFee.getMinimum(); - String maximumAmount = percentFee.getMaximum(); + String minimumAmount = percentFee.getMin(); + String maximumAmount = percentFee.getMax(); if (maximumAmount.isEmpty() && minimumAmount.isEmpty()) { formattedString = context.getResources().getString(R.string.fee_mix_no_min_and_max_formatter, flatFee.getCurrency(), flatFee.getValue(), percentFee.getValue()); @@ -85,10 +85,10 @@ private static String getMixFormattedFee(@NonNull Context context, @NonNull List } - private static String getPercentFormattedFee(@NonNull final Context context, @NonNull final Fee fee) { + private static String getPercentFormattedFee(@NonNull final Context context, @NonNull final HyperwalletFee fee) { String formattedFee; - String minimumAmount = fee.getMinimum(); - String maximumAmount = fee.getMaximum(); + String minimumAmount = fee.getMin(); + String maximumAmount = fee.getMax(); if (maximumAmount.isEmpty() && minimumAmount.isEmpty()) { formattedFee = context.getResources().getString(R.string.fee_percent_no_min_and_max_formatter, fee.getValue()); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java index 8abdb1ce1..999548eed 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java @@ -15,25 +15,25 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ - package com.hyperwallet.android.ui.transfermethod; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.hyperwallet.android.model.HyperwalletErrors; -import com.hyperwallet.android.model.meta.Fee; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKey; +import com.hyperwallet.android.model.meta.keyed.Country; +import com.hyperwallet.android.model.meta.keyed.HyperwalletTransferMethodType; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; import java.util.ArrayList; import java.util.Currency; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.TreeMap; public class SelectTransferMethodPresenter implements SelectTransferMethodContract.Presenter { - private static final String TAG = SelectTransferMethodPresenter.class.getName(); private static final String INDIVIDUAL = "INDIVIDUAL"; private final TransferMethodConfigurationRepository mTransferMethodConfigurationRepository; @@ -58,19 +58,19 @@ public void loadTransferMethodConfigurationKeys(final boolean forceUpdate, @NonN mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { @Override public void onKeysLoaded( - @Nullable final HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult) { + @Nullable final HyperwalletTransferMethodConfigurationKey key) { if (!mView.isActive()) { return; } mView.hideProgressBar(); - List transferMethodTypes = - transferMethodConfigurationKeyResult.getTransferMethods(countryCode, currencyCode, INDIVIDUAL); + Set transferMethodTypes = + key.getTransferMethodType(countryCode, currencyCode); mView.showTransferMethodCountry(countryCode); mView.showTransferMethodCurrency(currencyCode); mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, currencyCode, - transferMethodTypes, transferMethodConfigurationKeyResult)); + transferMethodTypes)); } @Override @@ -93,18 +93,19 @@ public void loadCurrency(final boolean forceUpdate, @NonNull final String countr mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { @Override - public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKeyResult result) { + public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKey key) { if (!mView.isActive()) { return; } - List transferMethodCurrencies = result.getCurrencies(countryCode); - List transferMethodTypes = result.getTransferMethods( - countryCode, transferMethodCurrencies.get(0), INDIVIDUAL); + List transferMethodCurrencies = + new ArrayList<>(key.getCurrencies(countryCode)); + Set transferMethodTypes = key + .getTransferMethodType(countryCode, transferMethodCurrencies.get(0).getCode()); mView.showTransferMethodCountry(countryCode); - mView.showTransferMethodCurrency(transferMethodCurrencies.get(0)); + mView.showTransferMethodCurrency(transferMethodCurrencies.get(0).getCode()); mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, - transferMethodCurrencies.get(0), transferMethodTypes, result)); + transferMethodCurrencies.get(0).getCode(), transferMethodTypes)); } @Override @@ -126,19 +127,18 @@ public void loadTransferMethodTypes(final boolean forceUpdate, mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { @Override - public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKeyResult - transferMethodConfigurationKeyResult) { + public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKey key) { if (!mView.isActive()) { return; } - List transferMethodTypes = transferMethodConfigurationKeyResult.getTransferMethods( - countryCode, currencyCode, INDIVIDUAL); + Set transferMethodTypes = key + .getTransferMethodType(countryCode, currencyCode); mView.showTransferMethodCountry(countryCode); mView.showTransferMethodCurrency(currencyCode); mView.showTransferMethodTypes(getTransferMethodSelectionItems(countryCode, currencyCode, - transferMethodTypes, transferMethodConfigurationKeyResult)); + transferMethodTypes)); } @Override @@ -161,18 +161,17 @@ public void openAddTransferMethod(@NonNull final String country, @NonNull final public void loadCountrySelection(@NonNull final String countryCode) { mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { @Override - public void onKeysLoaded( - @Nullable final HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult) { + public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationKey key) { if (!mView.isActive()) { return; } - List countryCodes = transferMethodConfigurationKeyResult.getCountries(); + Set countryCodes = key.getCountries(); TreeMap countryNameCodeMap = new TreeMap<>(); Locale.Builder builder = new Locale.Builder(); - for (String countryCode : countryCodes) { - Locale locale = builder.setRegion(countryCode).build(); - countryNameCodeMap.put(locale.getDisplayName(), countryCode); + for (Country countryCode : countryCodes) { + Locale locale = builder.setRegion(countryCode.getCode()).build(); + countryNameCodeMap.put(locale.getDisplayName(), countryCode.getCode()); } Locale locale = new Locale.Builder().setRegion(countryCode).build(); mView.showCountrySelectionDialog(countryNameCodeMap, locale.getDisplayName()); @@ -191,17 +190,16 @@ public void onError(@NonNull final HyperwalletErrors errors) { public void loadCurrencySelection(@NonNull final String countryCode, @NonNull final String currencyCode) { mTransferMethodConfigurationRepository.getKeys(new TransferMethodConfigurationRepository.LoadKeysCallback() { @Override - public void onKeysLoaded( - @Nullable HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult) { + public void onKeysLoaded(@Nullable HyperwalletTransferMethodConfigurationKey key) { if (!mView.isActive()) { return; } - List currencyCodes = transferMethodConfigurationKeyResult.getCurrencies(countryCode); + Set currencyCodes = key.getCurrencies(countryCode); TreeMap currencyNameCodeMap = new TreeMap<>(); - for (String currencyCode : currencyCodes) { - Currency currency = Currency.getInstance(currencyCode); - currencyNameCodeMap.put(currency.getDisplayName(), currencyCode); + for (com.hyperwallet.android.model.meta.keyed.Currency currencyCode : currencyCodes) { + Currency currency = Currency.getInstance(currencyCode.getCode()); + currencyNameCodeMap.put(currency.getDisplayName(), currencyCode.getCode()); } mView.showCurrencySelectionDialog(currencyNameCodeMap, Currency.getInstance(currencyCode).getDisplayName()); @@ -219,15 +217,12 @@ public void onError(@NonNull final HyperwalletErrors errors) { private List getTransferMethodSelectionItems( @NonNull final String country, @NonNull final String currency, - @NonNull final List transferMethodTypes, - @NonNull final HyperwalletTransferMethodConfigurationKeyResult result) { + @NonNull final Set transferMethodTypes) { List selectionItems = new ArrayList<>(); - for (String transferMethodType : transferMethodTypes) { - List fees = result.getFees(country, currency, transferMethodType, INDIVIDUAL); - String processingTime = result.getProcessingTime(country, currency, transferMethodType, INDIVIDUAL); + for (HyperwalletTransferMethodType transferMethodType : transferMethodTypes) { TransferMethodSelectionItem data = new TransferMethodSelectionItem(country, currency, INDIVIDUAL, - transferMethodType, processingTime, fees); + transferMethodType.getName(), transferMethodType.getProcessingTime(), transferMethodType.getFees()); selectionItems.add(data); } return selectionItems; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java index ca5e04c9e..283884b12 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java @@ -16,28 +16,30 @@ */ package com.hyperwallet.android.ui.transfermethod; -import com.hyperwallet.android.model.meta.Fee; +import com.hyperwallet.android.model.meta.HyperwalletFee; +import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Set; public class TransferMethodSelectionItem { private final String mCountry; private final String mCurrency; - private final List mFees; + private final List mFees; private final String mProcessingTime; private final String mProfile; private final String mTransferMethodType; public TransferMethodSelectionItem(String country, String currency, String profile, String transferMethodType, - String processingTime, List fees) { + String processingTime, Set fees) { mCountry = country; mCurrency = currency; mProfile = profile; mTransferMethodType = transferMethodType; mProcessingTime = processingTime; - mFees = fees; + mFees = new ArrayList<>(fees); } public String getCountry() { @@ -60,7 +62,7 @@ public String getProcessingTime() { return mProcessingTime; } - public List getFees() { + public List getFees() { return mFees; } diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/AbstractWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/AbstractWidget.java index 9ec0cec5d..65d644144 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/AbstractWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/AbstractWidget.java @@ -27,7 +27,7 @@ import androidx.annotation.Nullable; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletField; public abstract class AbstractWidget { diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java index a3ba9d932..f0580262d 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java @@ -32,7 +32,7 @@ import com.google.android.material.textfield.TextInputLayout; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletField; public class DateWidget extends AbstractWidget { diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java index d6f5b00ed..69c48bea4 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java @@ -39,7 +39,7 @@ import com.google.android.material.textfield.TextInputLayout; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletField; public class ExpiryDateWidget extends AbstractWidget { private ViewGroup mContainer; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java index cafa5e9c2..15836dddb 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java @@ -32,7 +32,7 @@ import com.google.android.material.textfield.TextInputLayout; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletField; public class NumberWidget extends AbstractWidget { private ViewGroup mContainer; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java index 7bce341f7..ccded629d 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java @@ -32,7 +32,7 @@ import com.google.android.material.textfield.TextInputLayout; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletField; public class PhoneWidget extends AbstractWidget { private ViewGroup mContainer; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java index a9f34045a..24a1a34ea 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java @@ -33,8 +33,8 @@ import com.google.android.material.textfield.TextInputLayout; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; -import com.hyperwallet.android.model.meta.HyperwalletFieldSelectionOption; +import com.hyperwallet.android.model.meta.field.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletFieldSelectionOption; import com.hyperwallet.android.ui.view.WidgetSelectionDialogFragment; import java.util.Locale; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java index fb8e322ec..afcb674f6 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java @@ -32,7 +32,7 @@ import com.google.android.material.textfield.TextInputLayout; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.HyperwalletField; public class TextWidget extends AbstractWidget { private ViewGroup mContainer; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/WidgetFactory.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/WidgetFactory.java index 405cd2df9..2e96db97f 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/WidgetFactory.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/WidgetFactory.java @@ -23,8 +23,8 @@ import androidx.annotation.Nullable; import com.hyperwallet.android.exception.HyperwalletException; -import com.hyperwallet.android.model.meta.EDataType; -import com.hyperwallet.android.model.meta.HyperwalletField; +import com.hyperwallet.android.model.meta.field.EDataType; +import com.hyperwallet.android.model.meta.field.HyperwalletField; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; diff --git a/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java b/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java index c89e2d298..304777748 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImplTest.java @@ -1,10 +1,12 @@ package com.hyperwallet.android.ui.repository; - import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; @@ -19,15 +21,20 @@ import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletErrors; import com.hyperwallet.android.model.TypeReference; -import com.hyperwallet.android.model.meta.HyperwalletField; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKeyResult; -import com.hyperwallet.android.model.meta.TransferMethodConfigurationResult; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationField; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKey; +import com.hyperwallet.android.model.meta.field.HyperwalletFieldGroup; +import com.hyperwallet.android.model.meta.field.HyperwalletTransferMethodConfiguration; +import com.hyperwallet.android.model.meta.field.HyperwalletTransferMethodConfigurationFieldResult; +import com.hyperwallet.android.model.meta.keyed.Country; +import com.hyperwallet.android.model.meta.keyed.Currency; +import com.hyperwallet.android.model.meta.keyed.HyperwalletTransferMethodConfigurationKeyResult; import com.hyperwallet.android.model.meta.query.HyperwalletTransferMethodConfigurationFieldQuery; import com.hyperwallet.android.model.meta.query.HyperwalletTransferMethodConfigurationKeysQuery; import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager; import com.hyperwallet.android.util.JsonUtils; +import org.hamcrest.collection.IsEmptyCollection; import org.json.JSONException; import org.json.JSONObject; import org.junit.Before; @@ -47,9 +54,9 @@ import org.robolectric.RobolectricTestRunner; import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Set; @RunWith(RobolectricTestRunner.class) public class TransferMethodConfigurationRepositoryImplTest { @@ -65,15 +72,17 @@ public class TransferMethodConfigurationRepositoryImplTest { @Mock private TransferMethodConfigurationRepository.LoadFieldsCallback loadFieldsCallback; @Captor - private ArgumentCaptor keyResultArgumentCaptor; + private ArgumentCaptor keyResultArgumentCaptor; @Captor - private ArgumentCaptor fieldResultArgumentCaptor; + private ArgumentCaptor fieldResultArgumentCaptor; @Captor private ArgumentCaptor mErrorsArgumentCaptor; + @Captor + private ArgumentCaptor mStringArgumentCaptor; @Mock private Hyperwallet mHyperwallet; @Mock - private HashMap mFieldsMap; + private HashMap mFieldsMap; @Spy @InjectMocks private TransferMethodConfigurationRepositoryImpl mTransferMethodConfigurationRepositoryImplMock; @@ -88,8 +97,8 @@ public void testGetKeys_callsListenerWithKeyResultOnSuccess() throws NoSuchMethodException, InstantiationException, IllegalAccessException, JSONException, InvocationTargetException { String responseBody = externalResourceManager.getResourceContent("successful_tmc_keys_response.json"); - final HyperwalletTransferMethodConfigurationKeyResult result = JsonUtils.fromJsonString(responseBody, - new TypeReference() { + final HyperwalletTransferMethodConfigurationKey result = JsonUtils.fromJsonString(responseBody, + new TypeReference() { }); doAnswer(new Answer() { @Override @@ -100,22 +109,20 @@ public Object answer(InvocationOnMock invocation) { } }).when(mHyperwallet).retrieveTransferMethodConfigurationKeys( ArgumentMatchers.any(), - ArgumentMatchers.>any()); + ArgumentMatchers.>any()); mTransferMethodConfigurationRepositoryImplMock.getKeys(loadKeysCallback); verify(loadKeysCallback).onKeysLoaded(keyResultArgumentCaptor.capture()); verify(loadKeysCallback, never()).onError(any(HyperwalletErrors.class)); - HyperwalletTransferMethodConfigurationKeyResult transferMethodConfigurationKeyResult = + HyperwalletTransferMethodConfigurationKey transferMethodConfigurationKeyResult = keyResultArgumentCaptor.getValue(); assertNotNull(transferMethodConfigurationKeyResult); - List countriesReturned = transferMethodConfigurationKeyResult.getCountries(); + Set countriesReturned = transferMethodConfigurationKeyResult.getCountries(); assertNotNull(countriesReturned); - assertThat(countriesReturned, is(Arrays.asList("CA", "US"))); - List currenciesReturned = transferMethodConfigurationKeyResult.getCurrencies("US"); + Set currenciesReturned = transferMethodConfigurationKeyResult.getCurrencies("US"); assertNotNull(currenciesReturned); - assertThat(currenciesReturned, is(Arrays.asList("USD"))); } @Test @@ -135,11 +142,11 @@ public Object answer(InvocationOnMock invocation) { } }).when(mHyperwallet).retrieveTransferMethodConfigurationKeys( ArgumentMatchers.any(), - ArgumentMatchers.>any()); + ArgumentMatchers.>any()); mTransferMethodConfigurationRepositoryImplMock.getKeys(loadKeysCallback); - verify(loadKeysCallback, never()).onKeysLoaded(any(HyperwalletTransferMethodConfigurationKeyResult.class)); + verify(loadKeysCallback, never()).onKeysLoaded(any(HyperwalletTransferMethodConfigurationKey.class)); verify(loadKeysCallback).onError(mErrorsArgumentCaptor.capture()); HyperwalletErrors hyperwalletErrors = mErrorsArgumentCaptor.getValue(); @@ -155,7 +162,7 @@ public void testGetFields_callsListenerWithFieldResultOnSuccess() InvocationTargetException { String responseBody = externalResourceManager.getResourceContent("successful_tmc_fields_response.json"); final HyperwalletTransferMethodConfigurationFieldResult result = JsonUtils.fromJsonString(responseBody, - new TypeReference() { + new TypeReference() { }); doAnswer(new Answer() { @Override @@ -166,20 +173,22 @@ public Object answer(InvocationOnMock invocation) { } }).when(mHyperwallet).retrieveTransferMethodConfigurationFields( ArgumentMatchers.any(), - ArgumentMatchers.>any()); + ArgumentMatchers.>any()); mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, loadFieldsCallback); - verify(loadFieldsCallback).onFieldsLoaded(fieldResultArgumentCaptor.capture()); + verify(loadFieldsCallback).onFieldsLoaded(fieldResultArgumentCaptor.capture(), mStringArgumentCaptor.capture()); verify(loadFieldsCallback, never()).onError(any(HyperwalletErrors.class)); - HyperwalletTransferMethodConfigurationFieldResult transferMethodConfigurationFieldResult = + HyperwalletTransferMethodConfigurationField transferMethodConfigurationFieldResult = fieldResultArgumentCaptor.getValue(); assertNotNull(transferMethodConfigurationFieldResult); - List fields = transferMethodConfigurationFieldResult.getFields(); - assertNotNull(fields); - assertThat(fields.size(), is(3)); + HyperwalletTransferMethodConfiguration transferMethodConfiguration = + transferMethodConfigurationFieldResult.getFields(); + assertThat(transferMethodConfiguration, is(notNullValue())); + assertThat(transferMethodConfiguration.getFieldGroups(), + is(not(IsEmptyCollection.empty()))); } @Test @@ -201,14 +210,14 @@ public Object answer(InvocationOnMock invocation) { } }).when(mHyperwallet).retrieveTransferMethodConfigurationFields( ArgumentMatchers.any(), - ArgumentMatchers.>any()); + ArgumentMatchers.>any()); mTransferMethodConfigurationRepositoryImplMock.getFields(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE, loadFieldsCallback); verify(loadFieldsCallback, never()).onFieldsLoaded( - any(HyperwalletTransferMethodConfigurationFieldResult.class)); + any(HyperwalletTransferMethodConfigurationField.class), anyString()); verify(loadFieldsCallback).onError(mErrorsArgumentCaptor.capture()); HyperwalletErrors hyperwalletErrors = mErrorsArgumentCaptor.getValue(); @@ -222,14 +231,14 @@ public Object answer(InvocationOnMock invocation) { @Test public void testGetKeys_callsListenerWithKeyResultFromCacheWhenNotNull() throws Exception { String responseBody = externalResourceManager.getResourceContent("successful_tmc_keys_response.json"); - final TransferMethodConfigurationResult transferMethodConfigurationResult = JsonUtils.fromJsonString( + final HyperwalletTransferMethodConfigurationKey transferMethodConfigurationResult = JsonUtils.fromJsonString( responseBody, - new TypeReference() { + new TypeReference() { }); TransferMethodConfigurationRepositoryImpl repositoryWithCache = spy( new TransferMethodConfigurationRepositoryImpl(null, transferMethodConfigurationResult, new HashMap())); + HyperwalletTransferMethodConfigurationField>())); repositoryWithCache.getKeys(loadKeysCallback); verify(repositoryWithCache, never()).getTransferMethodConfigurationKeyResult( @@ -241,8 +250,8 @@ public void testGetKeys_callsListenerWithKeyResultFromCacheWhenNotNull() throws @Test public void testGetFields_callsListenerWithFieldResultFromCacheWhenNotNull() throws Exception { String responseBody = externalResourceManager.getResourceContent("successful_tmc_fields_response.json"); - final TransferMethodConfigurationResult result = JsonUtils.fromJsonString(responseBody, - new TypeReference() { + final HyperwalletTransferMethodConfigurationFieldResult result = JsonUtils.fromJsonString(responseBody, + new TypeReference() { }); FieldMapKey fieldMapKey = new FieldMapKey(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE); @@ -256,7 +265,7 @@ public void testGetFields_callsListenerWithFieldResultFromCacheWhenNotNull() thr any(String.class), any(String.class), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); - verify(loadFieldsCallback).onFieldsLoaded(fieldResultArgumentCaptor.capture()); + verify(loadFieldsCallback).onFieldsLoaded(fieldResultArgumentCaptor.capture(), mStringArgumentCaptor.capture()); verify(loadFieldsCallback, never()).onError(any(HyperwalletErrors.class)); } @@ -265,8 +274,8 @@ public void testRefreshFields_clearsFieldMapWhenNotEmpty() throws Exception { String responseBody = externalResourceManager.getResourceContent("successful_tmc_fields_response.json"); JSONObject jsonObject = new JSONObject(responseBody); FieldMapKey fieldMapKey = new FieldMapKey(COUNTRY, CURRENCY, TRANSFER_METHOD_TYPE); - HashMap fieldMap = new HashMap<>(); - fieldMap.put(fieldMapKey, new TransferMethodConfigurationResult(jsonObject)); + HashMap fieldMap = new HashMap<>(); + fieldMap.put(fieldMapKey, new HyperwalletTransferMethodConfigurationFieldResult(jsonObject)); TransferMethodConfigurationRepositoryImpl repositoryWithCache = new TransferMethodConfigurationRepositoryImpl( null, null, fieldMap); repositoryWithCache.refreshFields(); diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java index 4169726f8..89311fc08 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodPresenterTest.java @@ -17,9 +17,10 @@ import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletErrors; import com.hyperwallet.android.model.HyperwalletTransferMethod; -import com.hyperwallet.android.model.meta.Fee; -import com.hyperwallet.android.model.meta.HyperwalletField; -import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationFieldResult; +import com.hyperwallet.android.model.meta.HyperwalletFee; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationField; +import com.hyperwallet.android.model.meta.field.HyperwalletFieldGroup; +import com.hyperwallet.android.model.meta.field.HyperwalletTransferMethodConfiguration; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; import com.hyperwallet.android.ui.repository.TransferMethodRepository; import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager; @@ -63,7 +64,7 @@ public class AddTransferMethodPresenterTest { @Mock private AddTransferMethodContract.View view; @Captor - private ArgumentCaptor> fieldArgumentCaptor; + private ArgumentCaptor> fieldArgumentCaptor; @Captor private ArgumentCaptor> mErrorListArgumentCaptor; @Rule @@ -131,26 +132,24 @@ public Object answer(InvocationOnMock invocation) { public void testLoadTransferMethodConfigurationFields_loadsTransferMethodFieldsIntoViewOnSuccess() throws Exception { // Given - final HyperwalletTransferMethodConfigurationFieldResult result = mock( - HyperwalletTransferMethodConfigurationFieldResult.class); + final HyperwalletTransferMethodConfigurationField result = mock( + HyperwalletTransferMethodConfigurationField.class); JSONObject jsonObject = new JSONObject( externalResourceManager.getResourceContent("add_transfer_method_presenter_test.json")); - final HyperwalletField field = new HyperwalletField(jsonObject); - List fields = new ArrayList() {{ - add(field); - }}; + final HyperwalletTransferMethodConfiguration configuration = new HyperwalletTransferMethodConfiguration( + jsonObject); // When when(view.isActive()).thenReturn(true); - when(result.getFields()).thenReturn(fields); + when(result.getFields()).thenReturn(configuration); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) { TransferMethodConfigurationRepository.LoadFieldsCallback callback = (TransferMethodConfigurationRepository.LoadFieldsCallback) invocation.getArguments()[3]; - callback.onFieldsLoaded(result); + callback.onFieldsLoaded(result, ""); return callback; } }).when(tmcRepository).getFields(anyString(), anyString(), anyString(), @@ -164,8 +163,8 @@ public Object answer(InvocationOnMock invocation) { verify(view, never()).showErrorLoadTransferMethodConfigurationFields( ArgumentMatchers.anyList()); verify(view, never()).showErrorAddTransferMethod(ArgumentMatchers.anyList()); - List responseFields = fieldArgumentCaptor.getValue(); - assertThat(responseFields, hasItem(field)); + List responseFields = fieldArgumentCaptor.getValue(); + assertThat(responseFields, hasItem(configuration.getFieldGroups().get(0))); } @Test @@ -188,7 +187,7 @@ public Object answer(InvocationOnMock invocation) { presenter.loadTransferMethodConfigurationFields(false, "CA", "CAD", "BANK_ACCOUNT"); LATCH.await(AWAIT_TIME_MS, TimeUnit.MILLISECONDS); - verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); + verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); verify(view, atLeastOnce()).showErrorLoadTransferMethodConfigurationFields(mErrorListArgumentCaptor.capture()); assertThat(mErrorListArgumentCaptor.getValue(), hasItem(errors.getErrors().get(0))); } @@ -200,7 +199,7 @@ public void testLoadTransferMethodConfigurationFields_updatesFieldsWhenForceUpda verify(tmcRepository, atLeastOnce()).refreshFields(); verify(tmcRepository, atLeastOnce()).getFields(anyString(), anyString(), anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); - verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); + verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationFields( ArgumentMatchers.anyList()); verify(view, never()).showErrorAddTransferMethod(ArgumentMatchers.anyList()); @@ -218,8 +217,8 @@ public void testLoadTransferMethodConfigurationFields_loadsTransferMethodFieldsI verify(tmcRepository, atLeastOnce()).getFields(anyString(), anyString(), anyString(), any(TransferMethodConfigurationRepository.LoadFieldsCallback.class)); verify(view, never()).hideProgressBar(); - verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); - verify(view, never()).showTransactionInformation(ArgumentMatchers.anyList(), anyString()); + verify(view, never()).showTransferMethodFields(ArgumentMatchers.anyList()); + verify(view, never()).showTransactionInformation(ArgumentMatchers.anyList(), anyString()); } @Test diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/FeeFormatterTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/FeeFormatterTest.java index 2b228aecf..664dac517 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/FeeFormatterTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/FeeFormatterTest.java @@ -9,8 +9,11 @@ import android.content.res.Resources; import com.hyperwallet.android.hyperwallet_ui.R; -import com.hyperwallet.android.model.meta.Fee; +import com.hyperwallet.android.model.meta.HyperwalletFee; +import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager; +import org.json.JSONException; +import org.json.JSONObject; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,104 +36,115 @@ public class FeeFormatterTest { @Captor private ArgumentCaptor resourceIdCaptor; @Captor - private ArgumentCaptor formatterArugmentCapture; + private ArgumentCaptor formatterArgumentCapture; @Mock private Context context; @Mock private Resources resources; + @Rule + public HyperwalletExternalResourceManager externalResourceManager = new HyperwalletExternalResourceManager(); - private final Fee flatFee = new Fee("", null, "USD", "FLAT", "3.00", null, null); + private HyperwalletFee mFlatFee; + private JSONObject mJSONObject; @Before - public void setUp() { + public void setUp() throws JSONException { + mJSONObject = new JSONObject(externalResourceManager.getResourceContent("fee_information.json")); + mFlatFee = new HyperwalletFee(mJSONObject.getJSONObject("FEE_ONE").getJSONArray("nodes") + .getJSONObject(0)); when(context.getResources()).thenReturn(resources); } @Test public void testGetFormattedFee_returnsFlatFormattedFee() { - FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee)); + FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_flat_formatter)); assertThat(argumentList.size(), is(2)); } @Test public void testGetFormattedFee_returnsPercentFormattedFeeWithMinAndMax() { - Fee fee = new Fee("", null, "USD", "PERCENT", "3", "4.00", "10.00"); + HyperwalletFee fee = new HyperwalletFee(mJSONObject.optJSONObject("FEE_TWO").optJSONArray("nodes") + .optJSONObject(0)); FeeFormatter.getFormattedFee(context, Arrays.asList(fee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_percent_formatter)); assertThat(argumentList.size(), is(4)); } @Test public void testGetFormattedFee_returnsPercentFormattedFeeWithMinOnly() { - Fee fee = new Fee("", null, "USD", "PERCENT", "3", "4.00", ""); + HyperwalletFee fee = new HyperwalletFee(mJSONObject.optJSONObject("FEE_THREE").optJSONArray("nodes") + .optJSONObject(0)); FeeFormatter.getFormattedFee(context, Arrays.asList(fee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_percent_only_min_formatter)); assertThat(argumentList.size(), is(3)); } @Test public void testGetFormattedFee_returnsPercentFormattedFeeWithMaxOnly() { - Fee fee = new Fee("", null, "USD", "PERCENT", "3", "", "10.00"); - + HyperwalletFee fee = new HyperwalletFee(mJSONObject.optJSONObject("FEE_FOUR").optJSONArray("nodes") + .optJSONObject(0)); FeeFormatter.getFormattedFee(context, Arrays.asList(fee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_percent_only_max_formatter)); assertThat(argumentList.size(), is(3)); } @Test public void testGetFormattedFee_returnsPercentFormattedFeeWithoutMinAndMax() { - Fee fee = new Fee("", null, "USD", "PERCENT", "3", "", ""); + HyperwalletFee fee = new HyperwalletFee(mJSONObject.optJSONObject("FEE_FIVE").optJSONArray("nodes") + .optJSONObject(0)); FeeFormatter.getFormattedFee(context, Arrays.asList(fee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_percent_no_min_and_max_formatter)); assertThat(argumentList.size(), is(1)); } @Test public void testGetFormattedFee_returnsPercentAndFlatFormattedFeeWithMinAndMax() { - Fee percentFee = new Fee("", null, "USD", "PERCENT", "3", "4.00", "10.00"); + HyperwalletFee percentFee = new HyperwalletFee(mJSONObject.optJSONObject("FEE_SIX").optJSONArray("nodes") + .optJSONObject(0)); - FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee, percentFee)); + FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee, percentFee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_mix_formatter)); assertThat(argumentList.size(), is(5)); } @Test public void testGetFormattedFee_returnsPercentAndFlatFormattedFeeWithMinOnly() { - Fee percentFee = new Fee("", null, "USD", "PERCENT", "3.00", "10.00", ""); + HyperwalletFee percentFee = new HyperwalletFee(mJSONObject.optJSONObject("FEE_SEVEN").optJSONArray("nodes") + .optJSONObject(0)); - FeeFormatter.getFormattedFee(context, Arrays.asList(flatFee, percentFee)); + FeeFormatter.getFormattedFee(context, Arrays.asList(mFlatFee, percentFee)); - verify(resources).getString(resourceIdCaptor.capture(), formatterArugmentCapture.capture()); + verify(resources).getString(resourceIdCaptor.capture(), formatterArgumentCapture.capture()); int resourceIdCaptorValue = resourceIdCaptor.getValue(); - List argumentList = formatterArugmentCapture.getAllValues(); + List argumentList = formatterArgumentCapture.getAllValues(); assertThat(resourceIdCaptorValue, is(R.string.fee_mix_only_min_formatter)); assertThat(argumentList.size(), is(4)); } diff --git a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java index 5a666ec6e..256261cc6 100644 --- a/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java +++ b/ui/src/test/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenterTest.java @@ -13,7 +13,8 @@ import com.hyperwallet.android.model.HyperwalletError; import com.hyperwallet.android.model.HyperwalletErrors; -import com.hyperwallet.android.model.meta.TransferMethodConfigurationResult; +import com.hyperwallet.android.model.meta.HyperwalletTransferMethodConfigurationKey; +import com.hyperwallet.android.model.meta.keyed.HyperwalletTransferMethodConfigurationKeyResult; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepository; import com.hyperwallet.android.ui.repository.TransferMethodConfigurationRepositoryImpl; import com.hyperwallet.android.ui.rule.HyperwalletExternalResourceManager; @@ -46,7 +47,7 @@ public class SelectTransferMethodPresenterTest { @Rule public HyperwalletExternalResourceManager externalResourceManager = new HyperwalletExternalResourceManager(); - private TransferMethodConfigurationResult result; + private HyperwalletTransferMethodConfigurationKey result; private SelectTransferMethodPresenter selectTransferMethodPresenter; private final HyperwalletErrors errors = createErrors(); @@ -55,7 +56,7 @@ public void initialize() throws Exception { initMocks(this); String responseBody = externalResourceManager.getResourceContent("successful_tmc_keys_response.json"); final JSONObject jsonObject = new JSONObject(responseBody); - result = new TransferMethodConfigurationResult(jsonObject); + result = new HyperwalletTransferMethodConfigurationKeyResult(jsonObject); selectTransferMethodPresenter = new SelectTransferMethodPresenter(view, transferMethodConfigurationRepository); } @@ -164,7 +165,7 @@ public Object answer(InvocationOnMock invocation) { // Then selectTransferMethodPresenter.loadCurrency(false, "CA"); - verify(view).showTransferMethodCurrency("USD"); + verify(view).showTransferMethodCurrency("CAD"); verify(view).showTransferMethodTypes(ArgumentMatchers.anyList()); verify(view, never()).showErrorLoadTransferMethodConfigurationKeys( ArgumentMatchers.anyList()); diff --git a/ui/src/test/resources/add_transfer_method_presenter_test.json b/ui/src/test/resources/add_transfer_method_presenter_test.json index 11d5a7e31..8ee731550 100644 --- a/ui/src/test/resources/add_transfer_method_presenter_test.json +++ b/ui/src/test/resources/add_transfer_method_presenter_test.json @@ -1,11 +1,30 @@ { - "category": "ACCOUNT", - "dataType": "NUMBER", - "isRequired": true, - "label": "Account Number", - "maxLength": 17, - "minLength": 4, - "name": "bankAccountId", - "placeholder": "", - "regularExpression": "^(?![0-]+$)[0-9-]{4,17}$" + "country": "US", + "currency": "USD", + "transferMethodType": "BANK_ACCOUNT", + "profile": "INDIVIDUAL", + "fieldGroups": { + "nodes": [ + { + "group": "BUSINESS_INFORMATION", + "fields": [ + { + "category": "ACCOUNT", + "dataType": "NUMBER", + "isRequired": true, + "isEditable": true, + "name": "branchId", + "label": "Routing Number", + "placeholder": "", + "regularExpression": "^[0-9]{9}$", + "validationMessage": { + "length": "The exact length of this field is 9.", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + } + ] + } + ] + } } \ No newline at end of file diff --git a/ui/src/test/resources/fee_information.json b/ui/src/test/resources/fee_information.json new file mode 100644 index 000000000..01ceedeef --- /dev/null +++ b/ui/src/test/resources/fee_information.json @@ -0,0 +1,77 @@ +{ + "FEE_ONE": { + "nodes": [ + { + "currency": "USD", + "value": "3.00", + "feeRateType": "FLAT" + } + ] + }, + "FEE_TWO": { + "nodes": [ + { + "currency": "USD", + "value": "3.00", + "feeRateType": "PERCENT", + "minimum": "4.00", + "maximum": "10.00" + } + ] + }, + "FEE_THREE": { + "nodes": [ + { + "currency": "USD", + "feeRateType": "PERCENT", + "value": "3", + "minimum": "4.00", + "maximum": "" + } + ] + }, + "FEE_FOUR": { + "nodes": [ + { + "currency": "USD", + "feeRateType": "PERCENT", + "value": "3", + "minimum": "", + "maximum": "10.00" + } + ] + }, + "FEE_FIVE": { + "nodes": [ + { + "currency": "USD", + "feeRateType": "PERCENT", + "value": "3", + "minimum": "", + "maximum": "" + } + ] + }, + "FEE_SIX": { + "nodes": [ + { + "currency": "USD", + "feeRateType": "PERCENT", + "value": "3", + "minimum": "4.00", + "maximum": "10.00" + } + ] + }, + "FEE_SEVEN": { + "nodes": [ + { + "currency": "USD", + "feeRateType": "PERCENT", + "value": "3.00", + "minimum": "10.00", + "maximum": "" + } + ] + } +} \ No newline at end of file diff --git a/ui/src/test/resources/successful_tmc_fields_response.json b/ui/src/test/resources/successful_tmc_fields_response.json index 110fe2b47..6fc9915d5 100644 --- a/ui/src/test/resources/successful_tmc_fields_response.json +++ b/ui/src/test/resources/successful_tmc_fields_response.json @@ -1,87 +1,157 @@ { "data": { - "transferMethodConfigurations": { + "transferMethodUIConfigurations": { + "count": 1, + "pageInfo": { + "limit": 10, + "offset": 0 + }, "nodes": [ { - "countries": [ - "US" - ], - "currencies": [ - "USD" - ], + "country": "US", + "currency": "USD", "transferMethodType": "BANK_ACCOUNT", "profile": "INDIVIDUAL", - "fees": { + "fieldGroups": { "nodes": [ { - "transferMethodType": "BANK_ACCOUNT", - "country": "US", - "currency": "USD", - "feeRateType": "FLAT", - "value": "2.00" + "group": "BUSINESS_INFORMATION", + "fields": [ + { + "category": "ACCOUNT", + "dataType": "NUMBER", + "isRequired": true, + "isEditable": true, + "name": "branchId", + "label": "Routing Number", + "placeholder": "", + "regularExpression": "^[0-9]{9}$", + "validationMessage": { + "length": "The exact length of this field is 9.", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + }, + { + "category": "ACCOUNT", + "dataType": "NUMBER", + "isRequired": true, + "isEditable": true, + "name": "bankAccountId", + "label": "Account Number", + "placeholder": "", + "regularExpression": "^(?![0-]+$)[0-9-]{4,17}$", + "validationMessage": { + "length": "The minimum length of this field is 4 and maximum length is 17.", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + }, + { + "category": "ACCOUNT", + "dataType": "SELECTION", + "isRequired": true, + "isEditable": true, + "name": "bankAccountPurpose", + "label": "Account Type", + "placeholder": "", + "fieldSelectionOptions": [ + { + "label": "CHECKING", + "value": "CHECKING" + }, + { + "label": "SAVINGS", + "value": "SAVINGS" + } + ], + "validationMessage": { + "length": "", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + } + ] + }, + { + "group": "PERSONAL_INFORMATION", + "fields": [ + { + "category": "ACCOUNT", + "dataType": "NUMBER", + "isRequired": true, + "isEditable": true, + "name": "branchId", + "label": "Routing Number", + "placeholder": "", + "regularExpression": "^[0-9]{9}$", + "validationMessage": { + "length": "The exact length of this field is 9.", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + }, + { + "category": "ACCOUNT", + "dataType": "NUMBER", + "isRequired": true, + "isEditable": true, + "name": "bankAccountId", + "label": "Account Number", + "placeholder": "", + "regularExpression": "^(?![0-]+$)[0-9-]{4,17}$", + "validationMessage": { + "length": "The minimum length of this field is 4 and maximum length is 17.", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + }, + { + "category": "ACCOUNT", + "dataType": "SELECTION", + "isRequired": true, + "isEditable": true, + "name": "bankAccountPurpose", + "label": "Account Type", + "placeholder": "", + "fieldSelectionOptions": [ + { + "label": "CHECKING", + "value": "CHECKING" + }, + { + "label": "SAVINGS", + "value": "SAVINGS" + } + ], + "validationMessage": { + "length": "", + "pattern": "is invalid length or format.", + "empty": "You must provide a value for this field" + } + } + ] } ] - }, - "processingTime": "1-2 Business days", - "fields": [ - { - "category": "ACCOUNT", - "dataType": "NUMBER", - "isRequired": true, - "label": "Routing Number", - "maxLength": 9, - "minLength": 9, - "name": "branchId", - "placeholder": "", - "regularExpression": "^[0-9]{9}$", - "validationMessage": { - "length": "The exact length of this field is 9.", - "pattern": "Routing Number is invalid format.", - "empty": "You must provide a value for this field." - } - }, - { - "category": "ACCOUNT", - "dataType": "NUMBER", - "isRequired": true, - "label": "Account Number", - "maxLength": 17, - "minLength": 4, - "name": "bankAccountId", - "placeholder": "", - "regularExpression": "^(?![0-]+$)[0-9-]{4,17}$", - "validationMessage": { - "length": "The minimum length of this field is 4 and maximum length is 17.", - "pattern": "Account Number is invalid format.", - "empty": "You must provide a value for this field." - } - }, - { - "category": "ACCOUNT", - "dataType": "SELECTION", - "isRequired": true, - "label": "Account Type", - "name": "bankAccountPurpose", - "placeholder": "", - "fieldSelectionOptions": [ - { - "label": "CHECKING", - "value": "CHECKING" - }, - { - "label": "SAVINGS", - "value": "SAVINGS" - } - ], - "validationMessage": { - "length": "", - "pattern": "Account Type is invalid format.", - "empty": "You must provide a value for this field." - } - } - ] + } + } + ] + }, + "fees": { + "nodes": [ + { + "value": "5.00", + "feeRateType": "FLAT" + } + ] + }, + "fees": { + "nodes": [ + { + "value": "5.00", + "feeRateType": "FLAT" } ] } } -} +} \ No newline at end of file diff --git a/ui/src/test/resources/successful_tmc_keys_response.json b/ui/src/test/resources/successful_tmc_keys_response.json index e1f107d6b..b47ab5426 100644 --- a/ui/src/test/resources/successful_tmc_keys_response.json +++ b/ui/src/test/resources/successful_tmc_keys_response.json @@ -1,177 +1,151 @@ { "data": { - "transferMethodConfigurations": { + "countries": { "nodes": [ { - "countries": [ - "CA" - ], - "currencies": [ - "USD" - ], - "transferMethodType": "BANK_ACCOUNT", - "profile": "INDIVIDUAL", - "processingTime": "1-3 Business days", - "fees": { + "code": "CA", + "name": "CANADA", + "currencies": { "nodes": [ { - "transferMethodType": "BANK_ACCOUNT", - "country": "CA", - "currency": "USD", - "feeRateType": "FLAT", - "value": "2.00" - } - ] - } - }, - { - "countries": [ - "CA" - ], - "currencies": [ - "USD" - ], - "transferMethodType": "BANK_ACCOUNT", - "profile": "BUSINESS", - "processingTime": "1-3 Business days", - "fees": { - "nodes": [ - { - "transferMethodType": "BANK_ACCOUNT", - "country": "CA", - "currency": "USD", - "feeRateType": "FLAT", - "value": "2.00" - } - ] - } - }, - { - "countries": [ - "CA" - ], - "currencies": [ - "CAD" - ], - "transferMethodType": "BANK_ACCOUNT", - "profile": "INDIVIDUAL", - "processingTime": "1-3 Business days", - "fees": { - "nodes": [ - { - "transferMethodType": "BANK_ACCOUNT", - "country": "CA", - "currency": "CAD", - "feeRateType": "FLAT", - "value": "2.20" - } - ] - } - }, - { - "countries": [ - "CA" - ], - "currencies": [ - "CAD" - ], - "transferMethodType": "BANK_ACCOUNT", - "profile": "BUSINESS", - "processingTime": "1-3 Business days", - "fees": { - "nodes": [ + "code": "CAD", + "name": "CAD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "fees": { + "nodes": [ + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + } + ] + } + } + ] + } + }, { - "transferMethodType": "BANK_ACCOUNT", - "country": "CA", - "currency": "CAD", - "feeRateType": "FLAT", - "value": "2.20" + "code": "USD", + "name": "USD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "fees": { + "nodes": [ + { + "transferMethodType": "BANK_CARD", + "value": "2.00", + "feeRateType": "FLAT" + }, + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + }, + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + }, + { + "transferMethodType": "PAYPAL_ACCOUNT", + "value": "0.25", + "feeRateType": "FLAT" + } + ] + } + }, + { + "code": "BANK_CARD", + "name": "Debit Card", + "fees": { + "nodes": [ + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + }, + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + } + ] + } + }, + { + "code": "PAYPAL_ACCOUNT", + "name": "PayPal Account", + "fees": { + "nodes": [ + { + "transferMethodType": "BANK_CARD", + "value": "2.00", + "feeRateType": "FLAT" + } + ] + } + } + ] + } } ] } }, { - "countries": [ - "US" - ], - "currencies": [ - "USD" - ], - "transferMethodType": "BANK_ACCOUNT", - "profile": "INDIVIDUAL", - "processingTime": "1-2 Business days", - "fees": { + "code": "US", + "name": "UNITED STATES", + "currencies": { "nodes": [ { - "transferMethodType": "BANK_ACCOUNT", - "country": "US", - "currency": "USD", - "feeRateType": "FLAT", - "value": "2.00" - } - ] - } - }, - { - "countries": [ - "US" - ], - "currencies": [ - "USD" - ], - "transferMethodType": "BANK_ACCOUNT", - "profile": "BUSINESS", - "processingTime": "1-2 Business days", - "fees": { - "nodes": [ - { - "transferMethodType": "BANK_ACCOUNT", - "country": "US", - "currency": "USD", - "feeRateType": "FLAT", - "value": "2.00" - } - ] - } - }, - { - "countries": [ - "US" - ], - "currencies": [ - "USD" - ], - "transferMethodType": "BANK_CARD", - "profile": "INDIVIDUAL", - "fees": { - "nodes": [ - { - "transferMethodType": "BANK_CARD", - "country": "US", - "currency": "USD", - "feeRateType": "FLAT", - "value": "1.75" - } - ] - } - }, - { - "countries": [ - "US" - ], - "currencies": [ - "USD" - ], - "transferMethodType": "BANK_CARD", - "profile": "BUSINESS", - "fees": { - "nodes": [ + "code": "CAD", + "name": "CAD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "processingTime": "1-3", + "fees": { + "nodes": [ + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + } + ] + } + } + ] + } + }, { - "transferMethodType": "BANK_CARD", - "country": "US", - "currency": "USD", - "feeRateType": "FLAT", - "value": "1.75" + "code": "USD", + "name": "USD", + "transferMethodTypes": { + "nodes": [ + { + "code": "BANK_ACCOUNT", + "name": "Bank Account", + "processingTime": "1-3", + "fees": { + "nodes": [ + { + "transferMethodType": "BANK_ACCOUNT", + "value": "5.00", + "feeRateType": "FLAT" + } + ] + } + } + ] + } } ] } From b6ebf346962dd5b03163127b39af77ccfa56cabb Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Mon, 6 May 2019 15:58:07 -0700 Subject: [PATCH 03/27] fixed fee integration --- .../ui/transfermethod/SelectTransferMethodFragment.java | 4 +--- .../ui/transfermethod/SelectTransferMethodPresenter.java | 3 ++- .../ui/transfermethod/TransferMethodSelectionItem.java | 8 +++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java index ec2f3c9ba..f022d0fbb 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodFragment.java @@ -19,7 +19,6 @@ package com.hyperwallet.android.ui.transfermethod; import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getStringFontIcon; -import static com.hyperwallet.android.ui.transfermethod.TransferMethodUtils.getStringResourceByName; import android.annotation.SuppressLint; import android.content.Context; @@ -452,8 +451,7 @@ class ViewHolder extends RecyclerView.ViewHolder { @SuppressLint("StringFormatInvalid") void bind(TransferMethodSelectionItem selectionItem) { - mTitle.setText( - getStringResourceByName(mTitle.getContext(), selectionItem.getTransferMethodType())); + mTitle.setText(selectionItem.getTransferMethodName()); mIcon.setText( getStringFontIcon(mIcon.getContext(), selectionItem.getTransferMethodType())); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java index 999548eed..2f9618239 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/SelectTransferMethodPresenter.java @@ -222,7 +222,8 @@ private List getTransferMethodSelectionItems( List selectionItems = new ArrayList<>(); for (HyperwalletTransferMethodType transferMethodType : transferMethodTypes) { TransferMethodSelectionItem data = new TransferMethodSelectionItem(country, currency, INDIVIDUAL, - transferMethodType.getName(), transferMethodType.getProcessingTime(), transferMethodType.getFees()); + transferMethodType.getCode(), transferMethodType.getName(), transferMethodType.getProcessingTime(), + transferMethodType.getFees()); selectionItems.add(data); } return selectionItems; diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java index 283884b12..98c730f00 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/TransferMethodSelectionItem.java @@ -31,13 +31,15 @@ public class TransferMethodSelectionItem { private final String mProcessingTime; private final String mProfile; private final String mTransferMethodType; + private final String mTransferMethodName; public TransferMethodSelectionItem(String country, String currency, String profile, String transferMethodType, - String processingTime, Set fees) { + String transferMethodName, String processingTime, Set fees) { mCountry = country; mCurrency = currency; mProfile = profile; mTransferMethodType = transferMethodType; + mTransferMethodName = transferMethodName; mProcessingTime = processingTime; mFees = new ArrayList<>(fees); } @@ -54,6 +56,10 @@ public String getProfile() { return mProfile; } + public String getTransferMethodName() { + return mTransferMethodName; + } + public String getTransferMethodType() { return mTransferMethodType; } From aa9d31fe2f65201ec9f353ee662f72cd6d1f0db7 Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Fri, 10 May 2019 11:39:31 -0700 Subject: [PATCH 04/27] added initial grouping --- .../AddTransferMethodFragment.java | 44 ++++++++++++------- .../res/layout/item_widget_section_header.xml | 15 +++++++ 2 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 ui/src/main/res/layout/item_widget_section_header.xml diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java index 31e565882..c274bd8b4 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java @@ -290,27 +290,37 @@ public void notifyTransferMethodAdded(@NonNull final HyperwalletTransferMethod t @Override public void showTransferMethodFields(@NonNull final List fields) { mDynamicContainer.removeAllViews(); - int previousView = 0; + int previousView; try { + // group + for (HyperwalletFieldGroup group : fields) { + View sectionHeader = LayoutInflater.from(mDynamicContainer.getContext()) + .inflate(R.layout.item_widget_section_header, mDynamicContainer, false); + TextView sectionTitle = sectionHeader.findViewById(R.id.section_header_title); + sectionTitle.setText(group.getGroupName()); + sectionHeader.setId(View.generateViewId()); + previousView = sectionHeader.getId(); + mDynamicContainer.addView(sectionHeader); + + // group fields + for (final HyperwalletField field : group.getFields()) { + AbstractWidget widget = WidgetFactory + .newWidget(field, this, getContext(), + mWidgetInputStateHashMap.containsKey(field.getName()) ? + mWidgetInputStateHashMap.get(field.getName()).getValue() : "", + mCreateTransferMethodButton); + if (mWidgetInputStateHashMap.isEmpty() || !mWidgetInputStateHashMap.containsKey(widget.getName())) { + mWidgetInputStateHashMap.put(widget.getName(), widget.getWidgetInputState()); + } - //TODO adjust groupings - for (final HyperwalletField field : fields.get(0).getFields()) { - AbstractWidget widget = WidgetFactory - .newWidget(field, this, getContext(), - mWidgetInputStateHashMap.containsKey(field.getName()) ? - mWidgetInputStateHashMap.get(field.getName()).getValue() : "", - mCreateTransferMethodButton); - if (mWidgetInputStateHashMap.isEmpty() || !mWidgetInputStateHashMap.containsKey(widget.getName())) { - mWidgetInputStateHashMap.put(widget.getName(), widget.getWidgetInputState()); + View widgetView = widget.getView(); + widgetView.setTag(widget); + previousView = placeBelow(widgetView, previousView, true); + final String error = mWidgetInputStateHashMap.get(widget.getName()).getErrorMessage(); + widget.showValidationError(error); + mDynamicContainer.addView(widgetView); } - - View widgetView = widget.getView(); - widgetView.setTag(widget); - previousView = placeBelow(widgetView, previousView, true); - final String error = mWidgetInputStateHashMap.get(widget.getName()).getErrorMessage(); - widget.showValidationError(error); - mDynamicContainer.addView(widgetView); } if (mShowCreateProgressBar) { diff --git a/ui/src/main/res/layout/item_widget_section_header.xml b/ui/src/main/res/layout/item_widget_section_header.xml new file mode 100644 index 000000000..10e63e4ab --- /dev/null +++ b/ui/src/main/res/layout/item_widget_section_header.xml @@ -0,0 +1,15 @@ + + + + From 2ab68d2a35e5abd71cb39e978bcef6636239849a Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Mon, 13 May 2019 14:15:28 -0700 Subject: [PATCH 05/27] added section header title information --- .../AddTransferMethodFragment.java | 22 +++++++++++-------- .../layout/fragment_add_transfer_method.xml | 15 ------------- ui/src/main/res/values/strings.xml | 7 ++++++ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java index 0f8337032..2993c7940 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/transfermethod/AddTransferMethodFragment.java @@ -91,7 +91,6 @@ public class AddTransferMethodFragment extends Fragment implements WidgetEventLi private String mTransferMethodType; private HyperwalletTransferMethod mTransferMethod; private HashMap mWidgetInputStateHashMap; - private TextView sectionHeaderTextView; /** * Please do not use this to have instance of AddTransferMethodFragment this is reserved for android framework @@ -170,8 +169,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); mDynamicContainer = view.findViewById(R.id.add_transfer_method_dynamic_container); - sectionHeaderTextView = view.findViewById(R.id.account_information_section_header); - mCreateButtonProgressBar = view.findViewById(R.id.add_transfer_method_create_button_progress_bar); mProgressBar = view.findViewById(R.id.add_transfer_method_progress_bar_layout); @@ -214,10 +211,6 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) { mTransferMethodType = getArguments().getString(ARGUMENT_TRANSFER_METHOD_TYPE); mTransferMethod = getArguments().getParcelable(ARGUMENT_TRANSFER_METHOD); } - - Locale locale = new Locale.Builder().setRegion(mCountry).build(); - sectionHeaderTextView.setText(requireContext().getResources() - .getString(R.string.account_information_section_header, locale.getDisplayName(), mCurrency)); } @Override @@ -293,14 +286,25 @@ public void notifyTransferMethodAdded(@NonNull final HyperwalletTransferMethod t public void showTransferMethodFields(@NonNull final List fields) { mDynamicContainer.removeAllViews(); int previousView; - try { + try { + Locale locale = new Locale.Builder().setRegion(mCountry).build(); // group for (HyperwalletFieldGroup group : fields) { + String sectionHeaderText; + if (group.getGroupName().equals(HyperwalletFieldGroup.GroupTypes.ACCOUNT_INFORMATION)) { + sectionHeaderText = requireContext().getResources() + .getString(R.string.account_information_section_header, locale.getDisplayName(), mCurrency); + } else { + sectionHeaderText = requireContext().getString(requireContext().getResources() + .getIdentifier(group.getGroupName().toLowerCase(Locale.ROOT), "string", + requireContext().getPackageName())); + } + View sectionHeader = LayoutInflater.from(mDynamicContainer.getContext()) .inflate(R.layout.item_widget_section_header, mDynamicContainer, false); TextView sectionTitle = sectionHeader.findViewById(R.id.section_header_title); - sectionTitle.setText(group.getGroupName()); + sectionTitle.setText(sectionHeaderText); sectionHeader.setId(View.generateViewId()); previousView = sectionHeader.getId(); mDynamicContainer.addView(sectionHeader); diff --git a/ui/src/main/res/layout/fragment_add_transfer_method.xml b/ui/src/main/res/layout/fragment_add_transfer_method.xml index d7d00c13d..861e1bdcd 100644 --- a/ui/src/main/res/layout/fragment_add_transfer_method.xml +++ b/ui/src/main/res/layout/fragment_add_transfer_method.xml @@ -36,21 +36,6 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - \uE00A \uE021 + Account Holder + Account Information + Address + Contact Information + Identification + Intermediary Account + Search Hint Search Country Search Currency From d3b30d462bb05f2b5ce80327c09a17b1a9f1bd64 Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Mon, 13 May 2019 15:08:29 -0700 Subject: [PATCH 06/27] added search capability --- .../view/WidgetSelectionDialogFragment.java | 92 ++++++++++++++++++- .../main/res/menu/menu_widget_selection.xml | 10 ++ ui/src/main/res/values/strings.xml | 1 + 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 ui/src/main/res/menu/menu_widget_selection.xml diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/WidgetSelectionDialogFragment.java b/ui/src/main/java/com/hyperwallet/android/ui/view/WidgetSelectionDialogFragment.java index 7bed35b21..5dab1341b 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/WidgetSelectionDialogFragment.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/WidgetSelectionDialogFragment.java @@ -16,19 +16,27 @@ */ package com.hyperwallet.android.ui.view; +import android.app.SearchManager; import android.content.Context; import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.inputmethod.EditorInfo; +import android.widget.Filter; +import android.widget.Filterable; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; @@ -41,19 +49,23 @@ import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.TreeMap; public class WidgetSelectionDialogFragment extends DialogFragment implements ToolbarEventListener { public static final String TAG = WidgetSelectionDialogFragment.class.getName(); private static final String ARGUMENT_NAME_VALUE_MAP = "ARGUMENT_NAME_VALUE_MAP"; + private static final String ARGUMENT_SEARCH_SELECTED_NAME_QUERY = "ARGUMENT_SEARCH_SELECTED_NAME_QUERY"; private static final String ARGUMENT_SELECTED_NAME = "ARGUMENT_SELECTED_NAME"; private static final String ARGUMENT_SELECTION_LABEL = "ARGUMENT_SELECTION_LABEL"; private static final String ARGUMENT_SELECTION_FIELD_NAME = "ARGUMENT_SELECTION_FIELD_NAME"; + private static final int MAX_NO_SEARCH_COUNT = 20; private Adapter mAdapter; private String mFieldName; private TreeMap mNameValueMap; + private String mSearchNameQuery; private String mSelectedName; private String mSelectionLabel; private WidgetSelectionItemListener mWidgetSelectionItemListener; @@ -66,12 +78,14 @@ public static WidgetSelectionDialogFragment newInstance(@NonNull final TreeMap MAX_NO_SEARCH_COUNT); + } + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + menu.clear(); + inflater.inflate(R.menu.menu_widget_selection, menu); + + SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); + MenuItem searchItem = menu.findItem(R.id.widget_selection_search_item); + SearchView searchView = (SearchView) searchItem.getActionView(); + searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName())); + searchView.setMaxWidth(Integer.MAX_VALUE); + searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + mSearchNameQuery = query; + mAdapter.getFilter().filter(query); + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + mSearchNameQuery = newText; + mAdapter.getFilter().filter(newText); + return false; + } + }); + + if (!mSearchNameQuery.isEmpty()) { + searchView.clearFocus(); + searchItem.expandActionView(); + searchView.setQuery(mSearchNameQuery, true); } } @@ -181,15 +232,16 @@ public interface WidgetSelectionItemListener { void onWidgetSelectionItemClicked(@NonNull final String selectedValue, @NonNull final String fieldName); } - private static class Adapter extends RecyclerView.Adapter { + private static class Adapter extends RecyclerView.Adapter implements Filterable { + private final Fragment mFragment; + private final String mFieldName; private final TreeMap mNameValueMap; private final String mSelectedName; - private final List mSelectionList; private final ToolbarEventListener mToolbarEventListener; - private final Fragment mFragment; - private final String mFieldName; private final WidgetSelectionItemListener mWidgetSelectionItemListener; + private TreeMap mNameValueFilteredMap; + private List mSelectionList; Adapter(@NonNull final TreeMap nameValueMap, @NonNull final String selectedName, @NonNull final Fragment fragment, @NonNull final ToolbarEventListener toolbarEventListener, @@ -198,6 +250,7 @@ private static class Adapter extends RecyclerView.Adapter { mSelectionList = new ArrayList<>(nameValueMap.keySet()); mSelectedName = selectedName; mNameValueMap = nameValueMap; + mNameValueFilteredMap = nameValueMap; mToolbarEventListener = toolbarEventListener; mFragment = fragment; mFieldName = fieldName; @@ -243,6 +296,37 @@ String getItemValue(int position) { return mNameValueMap.get(mSelectionList.get(position)); } + @Override + public Filter getFilter() { + return new Filter() { + @Override + protected FilterResults performFiltering(CharSequence constraint) { + if (constraint.length() == 0) { + mSelectionList = new ArrayList<>(mNameValueMap.keySet()); + mNameValueFilteredMap = mNameValueMap; + } else { + mNameValueFilteredMap = new TreeMap<>(); + for (String selection : mNameValueMap.keySet()) { + if (selection.toLowerCase(Locale.ROOT) + .contains(constraint.toString().toLowerCase(Locale.ROOT))) { + mNameValueFilteredMap.put(selection, mNameValueMap.get(selection)); + } + } + mSelectionList = new ArrayList<>(mNameValueFilteredMap.keySet()); + } + FilterResults filterResults = new FilterResults(); + filterResults.values = mNameValueFilteredMap; + return filterResults; + } + + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + mNameValueFilteredMap = (TreeMap) results.values; + notifyDataSetChanged(); + } + }; + } + class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { final TextView mSelectName; final ImageView mSelectItemImage; diff --git a/ui/src/main/res/menu/menu_widget_selection.xml b/ui/src/main/res/menu/menu_widget_selection.xml new file mode 100644 index 000000000..41b5f332e --- /dev/null +++ b/ui/src/main/res/menu/menu_widget_selection.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 54539ab7b..0d68918e8 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -91,6 +91,7 @@ Search Hint Search Country Search Currency + Search Account Information - %s (%s) Transfer Method Information From 9713c7205d02a69c25f9ea8955e85aa322ac6372 Mon Sep 17 00:00:00 2001 From: Peter Olamit Date: Tue, 14 May 2019 14:22:52 -0700 Subject: [PATCH 07/27] Support editability enabled / disabled --- ...sferMethodConfigurationRepositoryImpl.java | 2 ++ .../android/ui/view/widget/DateWidget.java | 10 ++++++--- .../ui/view/widget/ExpiryDateWidget.java | 8 +++++-- .../android/ui/view/widget/NumberWidget.java | 10 ++++++--- .../android/ui/view/widget/PhoneWidget.java | 9 ++++++-- .../ui/view/widget/SelectionWidget.java | 22 +++++++++++-------- .../android/ui/view/widget/TextWidget.java | 10 ++++++--- ui/src/main/res/values/styles.xml | 11 ++++++++++ 8 files changed, 60 insertions(+), 22 deletions(-) diff --git a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java index 2d1d10d85..1f51ca614 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/repository/TransferMethodConfigurationRepositoryImpl.java @@ -171,6 +171,8 @@ public void refreshFields() { mFieldMap.clear(); } + //TODO this method is just temporary, placed to get the processing time + //Next iteration from API will have ProcessingTime as a separate node @Nullable private String getProcessingTime(String country, String currency, String transferMethodType) { if (mTransferMethodConfigurationKey != null) { diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java index f0580262d..d93b624a8 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/DateWidget.java @@ -37,7 +37,7 @@ public class DateWidget extends AbstractWidget { private ViewGroup mContainer; - private String mValue = ""; + private String mValue; private TextInputLayout mTextInputLayout; public DateWidget(@NonNull HyperwalletField field, @NonNull WidgetEventListener listener, @NonNull Context context, @@ -50,11 +50,15 @@ public DateWidget(@NonNull HyperwalletField field, @NonNull WidgetEventListener public View getView() { if (mContainer == null) { mContainer = new RelativeLayout(mContext); - mTextInputLayout = new TextInputLayout( - new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout)); + mTextInputLayout = mField.isEditable() ? new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout)) + : new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout_Disabled)); // input control final EditText editText = new EditText( new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText)); + + editText.setEnabled(mField.isEditable()); setIdFromFieldName(editText); mTextInputLayout.setHint(mField.getLabel()); mTextInputLayout.addView(editText); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java index 69c48bea4..b89bf10a8 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/ExpiryDateWidget.java @@ -60,10 +60,14 @@ public View getView() { mContainer = new RelativeLayout(mContext); // input control - mTextInputLayout = new TextInputLayout( - new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout)); + mTextInputLayout = mField.isEditable() ? new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout)) + : new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout_Disabled)); + final EditText editText = new EditText( new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText)); + editText.setEnabled(mField.isEditable()); setIdFromFieldLabel(mTextInputLayout); setIdFromFieldName(editText); editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java index 15836dddb..8985b520e 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/NumberWidget.java @@ -37,7 +37,7 @@ public class NumberWidget extends AbstractWidget { private ViewGroup mContainer; private TextInputLayout mTextInputLayout; - private String mValue = ""; + private String mValue; public NumberWidget(@NonNull HyperwalletField field, @NonNull WidgetEventListener listener, @NonNull Context context, @Nullable String defaultValue, @NonNull View defaultFocusView) { @@ -50,11 +50,15 @@ public View getView() { if (mContainer == null) { mContainer = new RelativeLayout(mContext); // number input text - mTextInputLayout = new TextInputLayout( - new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout)); + mTextInputLayout = mField.isEditable() ? new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout)) + : new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout_Disabled)); mTextInputLayout.setHint(mField.getLabel()); + final EditText editText = new EditText( new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText)); + editText.setEnabled(mField.isEditable()); setIdFromFieldLabel(mTextInputLayout); setIdFromFieldName(editText); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java index ccded629d..c235e86f9 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/PhoneWidget.java @@ -49,11 +49,16 @@ public PhoneWidget(@NonNull HyperwalletField field, @NonNull WidgetEventListener public View getView() { if (mContainer == null) { mContainer = new RelativeLayout(mContext); - mTextInputLayout = new TextInputLayout( - new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout)); + mTextInputLayout = mField.isEditable() ? new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout)) + : new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout_Disabled)); + // input control final EditText editText = new EditText( new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText)); + editText.setEnabled(mField.isEditable()); + mTextInputLayout.addView(editText); mTextInputLayout.setHint(mField.getLabel()); setIdFromFieldName(editText); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java index 24a1a34ea..2e9a87775 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/SelectionWidget.java @@ -71,8 +71,10 @@ public View getView() { mContainer.setFocusable(true); mContainer.setFocusableInTouchMode(true); - mTextInputLayout = new TextInputLayout( - new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout)); + mTextInputLayout = mField.isEditable() ? new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout)) + : new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout_Disabled)); mEditText = new EditText( new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText)); if (!TextUtils.isEmpty(mDefaultValue)) { @@ -104,13 +106,15 @@ public void onFocusChange(View v, boolean hasFocus) { } }); - mEditText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - hideSoftKey(v); - showSelectionFragmentDialog(); - } - }); + if (mField.isEditable()) { + mEditText.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + hideSoftKey(v); + showSelectionFragmentDialog(); + } + }); + } mTextInputLayout.setHint(mField.getLabel()); mTextInputLayout.addView(mEditText); diff --git a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java index afcb674f6..8a11f546b 100644 --- a/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java +++ b/ui/src/main/java/com/hyperwallet/android/ui/view/widget/TextWidget.java @@ -50,12 +50,16 @@ public View getView() { if (mContainer == null) { mContainer = new RelativeLayout(mContext); mContainer.setTag(mField.getName()); - mTextInputLayout = new TextInputLayout( - new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout)); + mTextInputLayout = mField.isEditable() ? new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout)) + : new TextInputLayout(new ContextThemeWrapper(mContext, + R.style.Widget_Hyperwallet_TextInputLayout_Disabled)); + final EditText editText = new EditText( new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText)); - mTextInputLayout.setHint(mField.getLabel()); + editText.setEnabled(mField.isEditable()); + mTextInputLayout.setHint(mField.getLabel()); setIdFromFieldLabel(mTextInputLayout); setIdFromFieldName(editText); editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { diff --git a/ui/src/main/res/values/styles.xml b/ui/src/main/res/values/styles.xml index b61828efc..b29886651 100644 --- a/ui/src/main/res/values/styles.xml +++ b/ui/src/main/res/values/styles.xml @@ -118,6 +118,17 @@ @color/colorPrimary + + + + + + - - + + + +