diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java index bfb0be2..b90ed6e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/PinRequestActivity.java @@ -12,6 +12,7 @@ import android.text.Editable; import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.TextView; import android.widget.Toast; import org.jetbrains.annotations.NotNull; @@ -41,6 +42,19 @@ public class PinRequestActivity extends AppCompatActivity { @BindView(R.id.btnOK) Button btnOK; + @BindView(R.id.txtBadtry) + TextView txtBadtry; + + /* + * Contains the bad tries + * */ + private int tries = 0; + + /* + * Seconds counter + * */ + private int seconds = 15; + @@ -97,11 +111,74 @@ public class PinRequestActivity extends AppCompatActivity { } else{ + /* + * One more bad try + * */ + ++tries; + + final Activity activity = this; + + etPassword.setTextColor(Color.RED); + + /* + * User can not go more up to 5 bad tries + * */ + if(tries==4){ + tries = 0; + + btnOK.setEnabled(false); + etPassword.setEnabled(false); + txtBadtry.setVisibility(View.VISIBLE); + + txtBadtry.setText(txtBadtry.getText().toString().replace("%%",String.valueOf(seconds))); + + final Timer t = new Timer(); + //Set the schedule function and rate + t.scheduleAtFixedRate(new TimerTask() { + + @Override + public void run() { + + --seconds; + + if(seconds==0){ + t.cancel(); + + seconds = 15; + + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + btnOK.setEnabled(true); + etPassword.setEnabled(true); + txtBadtry.setVisibility(View.INVISIBLE); + etPassword.setText(""); + etPassword.setTextColor(Color.WHITE); + } + }); + } + else{ + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + txtBadtry.setText(activity.getResources().getString(R.string.wrong_pin_wait).replace("%%",String.valueOf(seconds))); + } + }); + } + } + + }, + //Set how long before to start calling the TimerTask (in milliseconds) + 1000, + //Set the amount of time between each execution (in milliseconds) + 1000); + + return; + } + /* * Set in red the rext and reset the password after a period of time * */ - final Activity activity = this; - etPassword.setTextColor(Color.RED); final Timer t = new Timer(); //Set the schedule function and rate t.scheduleAtFixedRate(new TimerTask() { diff --git a/app/src/main/res/layout/activity_pin_request.xml b/app/src/main/res/layout/activity_pin_request.xml index aa4c3b3..b569e94 100644 --- a/app/src/main/res/layout/activity_pin_request.xml +++ b/app/src/main/res/layout/activity_pin_request.xml @@ -45,4 +45,16 @@ android:textSize="18dp" android:layout_alignParentRight="true"/> + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index feb1c38..37d0285 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -206,6 +206,8 @@ Fee OK + Wrong PIN you have to wait %% seconds ... + Loading... Pay to