Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #747 : Added Checks for empty Edittexts and for validity of Url in Update Endpoints Setting #765

Merged
merged 1 commit into from
Jun 4, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import android.content.Context;
import android.content.Intent;
import android.support.design.widget.TextInputLayout;
import android.support.v7.preference.DialogPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceDialogFragmentCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
Expand All @@ -17,19 +20,28 @@
import butterknife.BindView;
import butterknife.ButterKnife;

import java.net.MalformedURLException;
import java.net.URL;

/**
* Created by dilpreet on 11/03/18.
*/

public class ConfigurationDialogFragmentCompat extends PreferenceDialogFragmentCompat implements
DialogPreference.TargetFragment {
DialogPreference.TargetFragment, TextWatcher {

@BindView(R.id.et_tenant)
EditText etTenant;

@BindView(R.id.et_base_url)
EditText etBaseUrl;

@BindView(R.id.til_tenant)
TextInputLayout tilTenant;

@BindView(R.id.til_base_url)
TextInputLayout tilBaseUrl;

private PreferencesHelper preferencesHelper;

@Override
Expand All @@ -47,13 +59,15 @@ protected void onBindDialogView(View view) {

etBaseUrl.setText(preference.getBaseUrl());
etTenant.setText(preference.getTenant());

etBaseUrl.setSelection(etBaseUrl.getText().length());
etTenant.addTextChangedListener(this);
etBaseUrl.addTextChangedListener(this);
}

@Override
public void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
if (positiveResult && !isFieldEmpty() && isUrlValid()) {
ConfigurationPreference preference = (ConfigurationPreference) getPreference();
preference.updateConfigurations(etBaseUrl.getText().toString(), etTenant.getText().
toString());
Expand All @@ -74,4 +88,55 @@ public void onDialogClosed(boolean positiveResult) {
public Preference findPreference(CharSequence key) {
return getPreference();
}
}

public boolean isFieldEmpty() {
if (etBaseUrl.getText().toString().trim().length() == 0) {
return true;
}
if (etTenant.getText().toString().trim().length() == 0) {
return true;
}
return false;
}

public boolean isUrlValid() {
try {
new URL(etBaseUrl.getText().toString());
return true;
} catch (MalformedURLException e) {
return false;
}
}


@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().length() == 0) {
if (etBaseUrl.getText().toString().length() == 0) {
tilBaseUrl.setErrorEnabled(true);
tilBaseUrl.setError(getString(R.string.error_validation_blank,
getString(R.string.base_url)));
}
if (etTenant.getText().toString().length() == 0) {
tilTenant.setErrorEnabled(true);
tilTenant.setError(getString(R.string.error_validation_blank,
getString(R.string.tenant)));
}
} else {
if (etBaseUrl.getText().toString().length() != 0) {
tilBaseUrl.setErrorEnabled(false);
}
if (etTenant.getText().toString().length() != 0) {
tilTenant.setErrorEnabled(false);
}
}
}

@Override
public void afterTextChanged(Editable s) {
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/layout/preference_configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:orientation="vertical">

<android.support.design.widget.TextInputLayout
android:id="@+id/til_base_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_margin"
Expand All @@ -25,6 +26,7 @@
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:id="@+id/til_tenant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/default_margin"
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@
<string name="language">Language</string>
<string name="choose_language">Choose your language</string>
<string name="notification">Notifications</string>
<string name="base_url">Base URL</string>
<string name="tenant">Tenant</string>

<string-array name="faq_qs">
<item>How do I apply for new loan account?</item>
Expand Down Expand Up @@ -469,7 +471,7 @@
<string name="pref_base_url_title">Update Endpoint</string>
<string name="pref_base_url_desc">Click here to change your Endpoint Configurations</string>
<string name="pref_configuration">pref_configuration</string>
<string name="enter_base_url">Enter the Base Url</string>
<string name="enter_base_url">Enter the Base URL</string>
<string name="enter_tenant">Enter the Tenant</string>
<string name="account_type_loan" translatable="false">accountType.loan</string>
<string-array name="languages" translatable="false">
Expand Down