Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Commit

Permalink
changed input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
pinpong committed Nov 13, 2017
1 parent 3c0e26a commit d6044cf
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import com.google.gson.Gson;

import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.iota.wallet.IOTA;
Expand All @@ -58,7 +57,6 @@
import butterknife.Unbinder;
import jota.error.ArgumentException;
import jota.utils.Checksum;
import jota.utils.InputValidator;
import jota.utils.IotaUnits;

public class GenerateQRCodeFragment extends Fragment {
Expand All @@ -81,12 +79,8 @@ public class GenerateQRCodeFragment extends Fragment {
TextInputEditText messageEditText;
@BindView(R.id.generate_qr_code_tag_input)
TextInputEditText tagEditText;
@BindView(R.id.generate_qr_code_address_input_aylout)
@BindView(R.id.generate_qr_code_address_input_layout)
TextInputLayout addressEditTextInputLayout;
@BindView(R.id.generate_qr_code_message_input_aylout)
TextInputLayout messageEditTextInputLayout;
@BindView(R.id.generate_qr_code_tag_input_aylout)
TextInputLayout tagEditTextInputLayout;
@BindView(R.id.generate_qr_code_units_spinner)
Spinner unitsSpinner;

Expand Down Expand Up @@ -138,26 +132,20 @@ public void onGenerateQrCodeClick(FloatingActionButton fab) {
inputManager.hideSoftInputFromWindow(fab.getWindowToken(), 0);
//reset errors
addressEditTextInputLayout.setError(null);
messageEditTextInputLayout.setError(null);
tagEditTextInputLayout.setError(null);

//noinspection StatementWithEmptyBody
if (!isValidAddress()) {

} else if (!InputValidator.isTrytes(getMessage(), getMessage().length()) && !getMessage().equals(getMessage().toUpperCase())) {
messageEditTextInputLayout.setError(getString(R.string.messages_invalid_characters));

} else if (!InputValidator.isTrytes(getTaG(), getTaG().length()) && !getTaG().equals(getTaG().toUpperCase())) {
tagEditTextInputLayout.setError(getString(R.string.messages_invalid_characters));

} else {

QRCode qrCode = new QRCode();
qrCode.setAddress(addressEditText.getText().toString());

if (getAmount().isEmpty())
if (getAmount().isEmpty()) {
qrCode.setAmount("");
else
} else {
qrCode.setAmount(amountInSelectedUnit());
}

qrCode.setMessage(messageEditText.getText().toString());
qrCode.setTag(tagEditText.getText().toString());
Expand Down Expand Up @@ -312,9 +300,6 @@ private String getMessage() {
}

private String getTaG() {
if (tagEditText.getText().toString().length() < 27)
return StringUtils.rightPad(tagEditText.getText().toString(), 27, '9');
else
return tagEditText.getText().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import butterknife.Unbinder;
import jota.error.ArgumentException;
import jota.utils.Checksum;
import jota.utils.InputValidator;
import jota.utils.IotaUnitConverter;
import jota.utils.IotaUnits;

Expand All @@ -92,10 +91,6 @@ public class NewTransferFragment extends Fragment {
TextInputLayout addressEditTextInputLayout;
@BindView(R.id.new_transfer_amount_text_input_layout)
TextInputLayout amountEditTextInputLayout;
@BindView(R.id.new_transfer_message_text_input_layout)
TextInputLayout messageEditTextInputLayout;
@BindView(R.id.new_transfer_tag_input_layout)
TextInputLayout tagEditTextInputLayout;
@BindView(R.id.new_transfer_units_spinner)
Spinner unitsSpinner;

Expand Down Expand Up @@ -171,10 +166,9 @@ public void onNewTransferSendFabClick(FloatingActionButton fab) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

addressEditTextInputLayout.setError(null);
tagEditTextInputLayout.setError(null);
amountEditTextInputLayout.setError(null);
messageEditTextInputLayout.setError(null);

//noinspection StatementWithEmptyBody
if (!isValidAddress()) {

} else if (getAmount().isEmpty() || getAmount().equals("0")) {
Expand All @@ -183,15 +177,6 @@ public void onNewTransferSendFabClick(FloatingActionButton fab) {
} else if (prefs.getLong(Constants.PREFERENCES_CURRENT_IOTA_BALANCE, 0) < Long.parseLong(amountInSelectedUnit())) {
amountEditTextInputLayout.setError(getString(R.string.messages_not_enough_balance));

} else if (!InputValidator.isTrytes(getMessage(), getMessage().length()) && !getMessage().equals(getMessage().toUpperCase())) {
messageEditTextInputLayout.setError(getString(R.string.messages_invalid_characters));

} else if (!InputValidator.isTrytes(getTaG(), getTaG().length()) && !getTaG().equals(getTaG().toUpperCase())) {
tagEditTextInputLayout.setError(getString(R.string.messages_invalid_characters));

} else if (getTaG().length() > 27) {
tagEditTextInputLayout.setError(getString(R.string.messages_tag_to_long));

} else {
AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
.setMessage(R.string.message_confirm_transfer)
Expand Down Expand Up @@ -400,11 +385,10 @@ private String getMessage() {
}

private String getTaG() {
if (tagEditText.getText().toString().isEmpty())
if (tagEditText.getText().toString().isEmpty()) {
return Constants.NEW_TRANSFER_TAG;
else if (tagEditText.getText().toString().length() < 27)
} else if (tagEditText.getText().toString().length() < 27)
return StringUtils.rightPad(tagEditText.getText().toString(), 27, '9');
else
return tagEditText.getText().toString();
return tagEditText.getText().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ public boolean onSeedLoginSeedInputEditorAction(int actionId, KeyEvent event) {

private void loginDialog() {

if (seedEditText.getText().toString().isEmpty()) {
//TODO Only accept seeds that are longer than SeedValidator.SEED_LENGTH_MIN ?

String seed = seedEditText.getText().toString();

if (seed.isEmpty()) {
seedEditTextLayout.setError(getString(R.string.messages_empty_seed));
if (seedEditTextLayout.getError() != null)
return;
}

String seed = seedEditText.getText().toString();

if (SeedValidator.isSeedValid(getActivity(), seed) == null) {
login();

Expand Down
13 changes: 7 additions & 6 deletions app/src/main/res/layout/fragment_generate_qr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<!-- Address Label -->
<android.support.design.widget.TextInputLayout
android:id="@+id/generate_qr_code_address_input_aylout"
android:id="@+id/generate_qr_code_address_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="72dp"
Expand All @@ -47,13 +47,14 @@
android:layout_height="wrap_content"
android:hint="@string/address"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ9"
android:maxLength="90"
android:inputType="text" />

</android.support.design.widget.TextInputLayout>

<!-- Amount Label -->
<android.support.design.widget.TextInputLayout
android:id="@+id/generate_qr_code_amount_input_aylout"
android:id="@+id/generate_qr_code_amount_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline"
Expand All @@ -70,6 +71,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/amount"
android:maxLength="16"
android:inputType="numberSigned" />

<Spinner
Expand All @@ -83,11 +85,10 @@

<!-- Message Label -->
<android.support.design.widget.TextInputLayout
android:id="@+id/generate_qr_code_message_input_aylout"
android:id="@+id/generate_qr_code_message_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline_typo"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextLabel">

<android.support.design.widget.TextInputEditText
Expand All @@ -102,11 +103,10 @@

<!-- Tag Label -->
<android.support.design.widget.TextInputLayout
android:id="@+id/generate_qr_code_tag_input_aylout"
android:id="@+id/generate_qr_code_tag_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline_typo"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextLabel">

<android.support.design.widget.TextInputEditText
Expand All @@ -115,6 +115,7 @@
android:layout_height="wrap_content"
android:hint="@string/tag_optional"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ9"
android:maxLength="27"
android:inputType="text" />

</android.support.design.widget.TextInputLayout>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/fragment_neighbors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
android:paddingRight="@dimen/baseline"
tools:visibility="gone">

<!-- Amount Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/res/layout/fragment_new_transfer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
android:layout_height="wrap_content"
android:hint="@string/address"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ9"
android:maxLength="90"
android:inputType="text" />

</android.support.design.widget.TextInputLayout>
Expand All @@ -74,6 +75,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/amount"
android:maxLength="16"
android:inputType="numberSigned" />

<Spinner
Expand All @@ -91,7 +93,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline_typo"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextLabel">

<android.support.design.widget.TextInputEditText
Expand All @@ -110,7 +111,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/baseline_typo"
app:errorEnabled="true"
app:hintTextAppearance="@style/TextLabel">

<android.support.design.widget.TextInputEditText
Expand All @@ -119,6 +119,7 @@
android:layout_height="wrap_content"
android:hint="@string/tag_optional"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ9"
android:maxLength="27"
android:inputType="text" />

</android.support.design.widget.TextInputLayout>
Expand Down

0 comments on commit d6044cf

Please sign in to comment.