Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {
androidTestImplementation "com.squareup.leakcanary:leakcanary-android-instrumentation:1.6.3"
androidTestImplementation "com.squareup.leakcanary:leakcanary-support-fragment:1.6.3"

testImplementation group: 'org.mockito', name: 'mockito-core', version: "2.23.4"
testImplementation group: 'org.mockito', name: 'mockito-core', version: "2.25.0"
testImplementation group: 'pl.pragmatists', name: 'JUnitParams', version: "1.1.1"
testImplementation "org.robolectric:robolectric:4.1"
testImplementation "com.squareup.okhttp3:mockwebserver:3.11.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ void createTransferMethod(@NonNull HyperwalletTransferMethod transferMethod,
@NonNull LoadTransferMethodCallback callback);

/**
* Load transfe methods available associated with current context
* Load transfer methods available associated with current context
*
* @param callback @see {@link LoadTransferMethodListCallback}
*/
void loadTransferMethod(@NonNull LoadTransferMethodListCallback callback);
void loadTransferMethods(@NonNull LoadTransferMethodListCallback callback);

/**
* Deactivate transfer method specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void createTransferMethod(@NonNull final HyperwalletTransferMethod transf
}

@Override
public void loadTransferMethod(@NonNull final LoadTransferMethodListCallback callback) {
public void loadTransferMethods(@NonNull final LoadTransferMethodListCallback callback) {
getHyperwallet().listTransferMethods(null,
new HyperwalletListener<HyperwalletPageList<HyperwalletTransferMethod>>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ public void notifyTransferMethodAdded(@NonNull final HyperwalletTransferMethod t
@Override
public void showTransferMethodFields(@NonNull final List<HyperwalletFieldGroup> fields) {
mDynamicContainer.removeAllViews();
int previousView;

try {
Locale locale = new Locale.Builder().setRegion(mCountry).build();
Expand All @@ -309,23 +308,21 @@ public void showTransferMethodFields(@NonNull final List<HyperwalletFieldGroup>
TextView sectionTitle = sectionHeader.findViewById(R.id.section_header_title);
sectionTitle.setText(getSectionHeaderText(group, locale));
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()) ?
.newWidget(field, this, 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();
View widgetView = widget.getView(mDynamicContainer);
widgetView.setTag(widget);
previousView = placeBelow(widgetView, previousView, true);
widgetView.setId(View.generateViewId());
final String error = mWidgetInputStateHashMap.get(widget.getName()).getErrorMessage();
widget.showValidationError(error);
mDynamicContainer.addView(widgetView);
Expand Down Expand Up @@ -444,7 +441,7 @@ public void showInputErrors(List<HyperwalletError> errors) {
AbstractWidget widget = (AbstractWidget) view.getTag();
if (widget.getName().equals(error.getFieldName())) {
if (!focusSet) {
widget.getView().requestFocus();
widget.getView(mDynamicContainer).requestFocus();
focusSet = true;
}
widget.showValidationError(error.getMessage());
Expand Down Expand Up @@ -550,25 +547,6 @@ private void setVisibleAndDisableFields() {
mCreateTransferMethodButton.setBackgroundColor(getResources().getColor(R.color.colorSecondaryDark));
}

private int placeBelow(View v, int previousId, boolean matchParentWidth) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
matchParentWidth ? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

if (previousId != 0) {
params.addRule(RelativeLayout.BELOW, previousId);
}

int margin = (int) (getContext().getResources().getDimension(R.dimen.default_margin)
/ getContext().getResources().getDisplayMetrics().density);

params.setMargins(margin, margin, margin, margin);
v.setId(View.generateViewId());
v.setLayoutParams(params);

return v.getId();
}

private boolean performValidation(boolean bypassFocusCheck) {
boolean valid = true;
// this is added since some phones triggers the create button but the widgets are not yet initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ListTransferMethodPresenter(TransferMethodRepository repository, ListTran
@Override
public void loadTransferMethods() {
mView.showProgressBar();
mTransferMethodRepository.loadTransferMethod(new TransferMethodRepository.LoadTransferMethodListCallback() {
mTransferMethodRepository.loadTransferMethods(new TransferMethodRepository.LoadTransferMethodListCallback() {
@Override
public void onTransferMethodListLoaded(List<HyperwalletTransferMethod> transferMethods) {
if (!mView.isActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package com.hyperwallet.android.ui.view.widget;

import android.content.Context;
import android.os.Build;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -26,14 +24,12 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hyperwallet.android.hyperwallet_ui.R;
import com.hyperwallet.android.model.meta.field.HyperwalletField;

public abstract class AbstractWidget {

private static final String LABEL_SUFFIX = "Label";

protected final Context mContext;
protected final View mDefaultFocusView;
protected final String mDefaultValue;
protected final HyperwalletField mField;
Expand All @@ -42,16 +38,15 @@ public abstract class AbstractWidget {
protected WidgetInputState mWidgetInputState;

public AbstractWidget(@Nullable HyperwalletField field, @NonNull WidgetEventListener listener,
@NonNull Context context, @Nullable String defaultValue, @NonNull View defaultFocusView) {
@Nullable String defaultValue, @NonNull View defaultFocusView) {
mField = field;
mListener = listener;
mContext = context;
mDefaultValue = defaultValue;
mDefaultFocusView = defaultFocusView;
mWidgetInputState = new WidgetInputState(getName());
}

public abstract View getView();
public abstract View getView(@NonNull final ViewGroup viewGroup);

public String getName() {
return mField == null ? "" : mField.getName();
Expand Down Expand Up @@ -128,17 +123,6 @@ protected void appendLayout(View v, boolean matchParentWidth) {
params.addRule(RelativeLayout.BELOW, mBottomViewId);
}

int default_margin = (int) (mContext.getResources().getDimension(R.dimen.default_margin)
/ mContext.getResources().getDisplayMetrics().density);
int widget_margin_offset = (int) (mContext.getResources().getDimension(R.dimen.widget_left_margin_offset)
/ mContext.getResources().getDisplayMetrics().density);

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
params.setMargins(default_margin, default_margin, default_margin, default_margin);
} else {
params.setMargins(widget_margin_offset, default_margin, default_margin, default_margin);
}

v.setLayoutParams(params);
mBottomViewId = v.getId();
}
Expand All @@ -148,7 +132,7 @@ protected void setIdFromFieldName(View view) {
if (fieldName.isEmpty()) {
view.setId(View.generateViewId());
} else {
view.setId(getIdByResourceName(fieldName));
view.setId(getIdByResourceName(fieldName, view));
}
}

Expand All @@ -157,17 +141,15 @@ protected void setIdFromFieldLabel(View view) {
if (fieldName.isEmpty()) {
view.setId(View.generateViewId());
} else {
view.setId(getIdByResourceName(fieldName + LABEL_SUFFIX));
view.setId(getIdByResourceName(fieldName + LABEL_SUFFIX, view));
}
}

private int getIdByResourceName(@NonNull final String fieldName) {
int id;
final int idFromResource = mContext.getResources().getIdentifier(fieldName, "id",
mContext.getPackageName());
// Returns 0 if no such resource was found.
id = idFromResource == 0 ? View.generateViewId() : idFromResource;
return id;
private int getIdByResourceName(@NonNull final String fieldName, @NonNull final View view) {
final int idFromResource = view.getContext().getResources().getIdentifier(fieldName, "id",
view.getContext().getPackageName());

return idFromResource == 0 ? View.generateViewId() : idFromResource;
}

protected class DefaultKeyListener implements View.OnKeyListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
*/
package com.hyperwallet.android.ui.view.widget;

import android.content.Context;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -37,24 +37,29 @@
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,
public DateWidget(@NonNull HyperwalletField field, @NonNull WidgetEventListener listener,
@Nullable String defaultValue, @NonNull View defaultFocusView) {
super(field, listener, context, defaultValue, defaultFocusView);
super(field, listener, defaultValue, defaultFocusView);
mValue = defaultValue;
}

@Override
public View getView() {
public View getView(@NonNull final ViewGroup viewGroup) {
if (mContainer == null) {
mContainer = new RelativeLayout(mContext);
mTextInputLayout = new TextInputLayout(
new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputLayout));
mContainer = (ViewGroup) LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.item_widget_layout, viewGroup, false);

// input control
mTextInputLayout = new TextInputLayout(new ContextThemeWrapper(viewGroup.getContext(),
mField.isEditable() ? R.style.Widget_Hyperwallet_TextInputLayout
: R.style.Widget_Hyperwallet_TextInputLayout_Disabled));
final EditText editText = new EditText(
new ContextThemeWrapper(mContext, R.style.Widget_Hyperwallet_TextInputEditText));
new ContextThemeWrapper(viewGroup.getContext(), R.style.Widget_Hyperwallet_TextInputEditText));

editText.setEnabled(mField.isEditable());
setIdFromFieldName(editText);
mTextInputLayout.setHint(mField.getLabel());
mTextInputLayout.addView(editText);
Expand Down Expand Up @@ -88,10 +93,10 @@ public void afterTextChanged(Editable s) {
}
});

editText.setText(TextUtils.isEmpty(mDefaultValue) ? mField.getValue() : mDefaultValue);
editText.setInputType(InputType.TYPE_CLASS_DATETIME);
editText.setOnKeyListener(new DefaultKeyListener(mDefaultFocusView, editText));
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_NEXT);
editText.setText(mDefaultValue);
appendLayout(mTextInputLayout, true);
mContainer.addView(mTextInputLayout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.hyperwallet.android.model.HyperwalletTransferMethod.TransferMethodFields.IS_DEFAULT_TRANSFER_METHOD;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -21,9 +20,9 @@ public class DefaultAccountWidget extends AbstractWidget {
private ViewGroup mContainer;
private String mValue;

public DefaultAccountWidget(@NonNull WidgetEventListener listener, @NonNull Context context,
public DefaultAccountWidget(@NonNull WidgetEventListener listener,
@Nullable String defaultValue, @NonNull View defaultFocusView) {
super(null, listener, context, defaultValue, defaultFocusView);
super(null, listener, defaultValue, defaultFocusView);
}

@Override
Expand All @@ -32,26 +31,26 @@ public String getName() {
}

@Override
public View getView() {
public View getView(@NonNull final ViewGroup viewGroup) {
if (mContainer == null) {
mContainer = new RelativeLayout(mContext);
mContainer = new RelativeLayout(viewGroup.getContext());
// label
TextView label = new TextView(mContext);
label.setText(mContext.getResources().getText(R.string.default_account_label));
TextView label = new TextView(viewGroup.getContext());
label.setText(viewGroup.getContext().getResources().getText(R.string.default_account_label));

label.setTextSize(mContext.getResources().getDimension(R.dimen.font_subtitle2));
label.setTextSize(viewGroup.getContext().getResources().getDimension(R.dimen.font_subtitle2));
setIdFromFieldLabel(label);
label.setTypeface(null, Typeface.BOLD);
label.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
label.setTextColor(viewGroup.getContext().getResources().getColor(R.color.colorPrimary));

appendLayout(label, true);
mContainer.addView(label);

// switch control
Switch toggle = new Switch(mContext);
Switch toggle = new Switch(viewGroup.getContext());
setIdFromFieldName(toggle);
toggle.setText(mContext.getResources().getText(R.string.default_account_sub_label));
toggle.setTextSize(mContext.getResources().getDimension(R.dimen.font_subtitle2));
toggle.setText(viewGroup.getContext().getResources().getText(R.string.default_account_sub_label));
toggle.setTextSize(viewGroup.getContext().getResources().getDimension(R.dimen.font_subtitle2));
if (mDefaultValue == null) {
toggle.setChecked(true); // initial state
mValue = Boolean.TRUE.toString();
Expand Down
Loading