diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/common/view/MAutoCompleteTextView.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/common/view/MAutoCompleteTextView.java new file mode 100644 index 00000000..4dbe4c7d --- /dev/null +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/common/view/MAutoCompleteTextView.java @@ -0,0 +1,42 @@ +package com.gmeremit.online.gmeremittance_native.common.view; + +import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.widget.AutoCompleteTextView; + +import androidx.appcompat.widget.AppCompatAutoCompleteTextView; + +import com.gmeremit.online.gmeremittance_native.R; +import com.gmeremit.online.gmeremittance_native.customwidgets.FontCache; + +public class MAutoCompleteTextView extends AppCompatAutoCompleteTextView { + + + public MAutoCompleteTextView(Context context) { + super(context); + init(context,null); + } + + public MAutoCompleteTextView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context,null); + + } + + public MAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context,null); + + } + + private void init(Context context, AttributeSet attrs) { + if (attrs != null) { + TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MAutoCompleteTextView); + String fontName = a.getString(R.styleable.MAutoCompleteTextView_autoTxtViewFontName); + setTypeface(FontCache.getTypeface(fontName, context)); + a.recycle(); + } + } +} diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2Presenter.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2Presenter.java index 34a79743..93d0fbb3 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2Presenter.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2Presenter.java @@ -1,5 +1,8 @@ package com.gmeremit.online.gmeremittance_native.registerV2.presenter; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; + import com.gmeremit.online.gmeremittance_native.GmeApplication; import com.gmeremit.online.gmeremittance_native.R; import com.gmeremit.online.gmeremittance_native.base.BaseViewModel; @@ -38,9 +41,7 @@ public class RegisterV2Presenter extends BaseViewModel implements RegisterV2Pres private final RegisterValidator registerValidator; - private List nativeCountryList; - - + private MutableLiveData> nativeCountryListLiveData; private String registrationSuccessMessage = ""; @@ -54,12 +55,6 @@ public class RegisterV2Presenter extends BaseViewModel implements RegisterV2Pres registerViewLiveData = new RegisterViewLiveData(); registerValidator = new RegisterValidator(); - getDefaultData(); - } - - private void getDefaultData() { - this.useCaseCompositeDisposable.add( - this.registerGateway.getNativeCountryList(view.getContext()).subscribe(nativeCountryList -> this.nativeCountryList = nativeCountryList)); } @@ -133,8 +128,15 @@ public class RegisterV2Presenter extends BaseViewModel implements RegisterV2Pres } - public List getNativeCountryList() { - return nativeCountryList; + @Override + public LiveData> getNativeCountryListLiveData() { + if (nativeCountryListLiveData == null) { + nativeCountryListLiveData = new MutableLiveData<>(); + this.useCaseCompositeDisposable.add( + this.registerGateway.getNativeCountryList(view.getContext()).subscribe(nativeCountryList -> this.nativeCountryListLiveData.setValue(nativeCountryList))); + } + + return nativeCountryListLiveData; } diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2PresenterInterface.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2PresenterInterface.java index e5ce64be..cee3ff06 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2PresenterInterface.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/presenter/RegisterV2PresenterInterface.java @@ -2,8 +2,13 @@ package com.gmeremit.online.gmeremittance_native.registerV2.presenter; import android.content.Context; +import androidx.lifecycle.LiveData; + import com.gmeremit.online.gmeremittance_native.base.BaseContractInterface; import com.gmeremit.online.gmeremittance_native.base.BasePresenterInterface; +import com.gmeremit.online.gmeremittance_native.kycV2.model.kyc.NativeCountry; + +import java.util.List; public interface RegisterV2PresenterInterface extends BasePresenterInterface { @@ -13,6 +18,7 @@ public interface RegisterV2PresenterInterface extends BasePresenterInterface { RegisterViewLiveData getRegisterRelatedViewEvents(RegisterViewLiveData.RegisterViewBinding viewBindings); + LiveData> getNativeCountryListLiveData(); diff --git a/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/view/RegisterV2Activity.java b/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/view/RegisterV2Activity.java index 0d9e8812..72aa1c97 100644 --- a/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/view/RegisterV2Activity.java +++ b/app/src/main/java/com/gmeremit/online/gmeremittance_native/registerV2/view/RegisterV2Activity.java @@ -4,11 +4,13 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ScrollView; import android.widget.TextView; import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatAutoCompleteTextView; import androidx.lifecycle.ViewModelProvider; import com.gmeremit.online.gmeremittance_native.R; @@ -29,6 +31,8 @@ import com.google.android.material.textfield.TextInputEditText; import com.google.android.material.textfield.TextInputLayout; import com.jakewharton.rxbinding3.widget.RxTextView; +import java.util.List; + import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -40,9 +44,6 @@ import static com.gmeremit.online.gmeremittance_native.kycV3.view.KYCV3Activity. public class RegisterV2Activity extends BaseActivity implements RegisterV2PresenterInterface.RegisterV2ContractInterface { - - - @BindView(R.id.usernameId_edTxt) TextInputEditText usernameId; @@ -56,7 +57,7 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen TextInputLayout passwordTxtInputLayout; @BindView(R.id.nativeCountry_edTxt) - TextInputEditText nativeCountryEdTxt; + AppCompatAutoCompleteTextView nativeCountryEdTxt; @BindView(R.id.nativeCountry_TxtInputLayout) TextInputLayout nativeCountryTxtInputLayout; @@ -68,17 +69,14 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen TextInputLayout mobileTxtInputLayout; - @BindView(R.id.btn_submit) Button btn_submit; - @BindView(R.id.tv_login) TextView tv_login; - @BindView(R.id.scrollView) ScrollView scrollView; @@ -90,6 +88,7 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen private Subject selectedNativeCountrySubject; private RegisterViewLiveData registerRelatedViewEvents; + private List nativeCountryList; @Override @@ -105,75 +104,70 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen private void initialize() { - selectedNativeCountrySubject= PublishSubject.create(); - this.presenter = new ViewModelProvider(this,new RegisterViewModelFactory(this)).get(RegisterV2Presenter.class); + selectedNativeCountrySubject = PublishSubject.create(); + this.presenter = new ViewModelProvider(this, new RegisterViewModelFactory(this)).get(RegisterV2Presenter.class); - registerRelatedViewEvents= this.presenter.getRegisterRelatedViewEvents(new RegisterViewLiveData.RegisterViewBinding( + registerRelatedViewEvents = this.presenter.getRegisterRelatedViewEvents(new RegisterViewLiveData.RegisterViewBinding( RxTextView.textChanges(usernameId).skipInitialValue(), selectedNativeCountrySubject, RxTextView.textChanges(mobileEdTxt).skipInitialValue(), RxTextView.textChanges(passwordEdTxt).skipInitialValue() )); - registerRelatedViewEvents.getUserIdInputLiveData().observe(this,this::updateUserId); - registerRelatedViewEvents.getPasswordInputLiveData().observe(this,this::updatePassword); - registerRelatedViewEvents.getNativeCountryInputLiveData().observe(this,this::updateNativeCountry); - registerRelatedViewEvents.getPhoneNumberInputLiveData().observe(this,this::updatePhoneNumber); + registerRelatedViewEvents.getUserIdInputLiveData().observe(this, this::updateUserId); + registerRelatedViewEvents.getPasswordInputLiveData().observe(this, this::updatePassword); + registerRelatedViewEvents.getNativeCountryInputLiveData().observe(this, this::updateNativeCountry); + registerRelatedViewEvents.getPhoneNumberInputLiveData().observe(this, this::updatePhoneNumber); + + presenter.getNativeCountryListLiveData().observe(this, this::updateNativeCountryList); + } + + private void updateNativeCountryList(List nativeCountries) { +// nativeCountryEdTxt.setAdapter(new ArrayAdapter<>(nativeCountryEdTxt.getContext(),R.layout.item_list,nativeCountries)); + this.nativeCountryList = nativeCountries; } private void updatePhoneNumber(FormInputStateDTO data) { - if(data.isValid()) - { + if (data.isValid()) { mobileTxtInputLayout.setError(null); - if(data.hasData()) - { + if (data.hasData()) { mobileEdTxt.setText(data.getData()); } - } - else + } else mobileTxtInputLayout.setError(data.getErrorMessage()); } private void updateNativeCountry(FormInputStateDTO data) { - if(data.isValid()) - { + if (data.isValid()) { nativeCountryTxtInputLayout.setError(null); - if(data.hasData()) - { + if (data.hasData()) { nativeCountryEdTxt.setText(data.getData().getText()); } - } - else + } else nativeCountryTxtInputLayout.setError(data.getErrorMessage()); } private void updatePassword(FormInputStateDTO data) { - if(data.isValid()) - { + if (data.isValid()) { passwordTxtInputLayout.setError(null); - if(data.hasData()) - { + if (data.hasData()) { passwordEdTxt.setText(data.getData()); } - } - else + } else passwordTxtInputLayout.setError(data.getErrorMessage()); } private void updateUserId(FormInputStateDTO data) { - if(data.isValid()) - { + if (data.isValid()) { usernameIdTxtInputLayout.setError(null); - if(data.hasData()) - { + if (data.hasData()) { usernameId.setText(data.getData()); } - } - else + } else usernameIdTxtInputLayout.setError(data.getErrorMessage()); } @@ -197,35 +191,30 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen } + @OnClick(R.id.nativeCountry_edTxt) + public void promptNativeCountrySelection() { + hideKeyBoard(); + if (nativeCountrylListDialog == null) + nativeCountrylListDialog = new GenericTextListingDialog<>(); + nativeCountrylListDialog.setData(nativeCountryList); + nativeCountrylListDialog.setListener(selectedNativeCountry -> + { + selectedNativeCountrySubject.onNext(selectedNativeCountry); + nativeCountryEdTxt.setText(selectedNativeCountry.getText()); + nativeCountrylListDialog.dismiss(); - - - - - public void promptNativeCountrySelection() { -// hideKeyBoard(); -// if (nativeCountrylListDialog == null) -// nativeCountrylListDialog = new GenericTextListingDialog<>(); -// -// nativeCountrylListDialog.setData(this.presenter.getNativeCountryList()); -// nativeCountrylListDialog.setListener(selectedNativeCountry -> -// { -// presenter.updateSelectedNativeCountry(selectedNativeCountry); -// nativeCountrylListDialog.dismiss(); -// -// }); -// nativeCountrylListDialog.setHintAndTitle(getString(R.string.search_country_text), getString(R.string.select_country_text), getString(R.string.no_country_found_text)); -// nativeCountrylListDialog.disableSearch(false); -// if (!nativeCountrylListDialog.isAdded()) -// nativeCountrylListDialog.show(getSupportFragmentManager(), "NATIVECOUNTRYDIALOG"); + }); + nativeCountrylListDialog.setHintAndTitle(getString(R.string.search_country_text), getString(R.string.select_country_text), getString(R.string.no_country_found_text)); + nativeCountrylListDialog.disableSearch(false); + if (!nativeCountrylListDialog.isAdded()) + nativeCountrylListDialog.show(getSupportFragmentManager(), "NATIVECOUNTRYDIALOG"); } @OnClick(R.id.btn_submit) - public void onRegisterBtnClicked() - { + public void onRegisterBtnClicked() { presenter.registerUser(); } @@ -284,7 +273,6 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen } - @Override public void setUserIdFocus(boolean action) { if (action) @@ -301,17 +289,10 @@ public class RegisterV2Activity extends BaseActivity implements RegisterV2Presen } - - @Override public void onBackPressed() { - super.onBackPressed(); + super.onBackPressed(); } - - - - - } diff --git a/app/src/main/res/layout/activity_register_v2.xml b/app/src/main/res/layout/activity_register_v2.xml index 8ae22a73..5b39e70b 100644 --- a/app/src/main/res/layout/activity_register_v2.xml +++ b/app/src/main/res/layout/activity_register_v2.xml @@ -54,7 +54,6 @@ - - + android:layout_height="wrap_content" + android:gravity="start" + android:focusable="false" + android:cursorVisible="false" + android:id="@+id/nativeCountry_edTxt"/> - + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index c1ce2286..af16cabe 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -45,4 +45,7 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 77012faa..2294ef39 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -223,6 +223,10 @@ @dimen/form_input_padding_end + +