Commit 8bcaf2c5 authored by Roger Barton's avatar Roger Barton
Browse files

Added open last event button for faster login

parent 47dd78f9
Pipeline #5889 passed with stages
in 6 minutes and 9 seconds
...@@ -20,6 +20,7 @@ import android.view.KeyEvent; ...@@ -20,6 +20,7 @@ import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
...@@ -33,6 +34,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -33,6 +34,7 @@ public class MainActivity extends AppCompatActivity {
private EditText mPinField; private EditText mPinField;
private TextView mInvalidPinLabel; private TextView mInvalidPinLabel;
private Button mOpenRecent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -54,6 +56,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -54,6 +56,7 @@ public class MainActivity extends AppCompatActivity {
{ {
mPinField = findViewById(R.id.PinField); mPinField = findViewById(R.id.PinField);
mInvalidPinLabel = findViewById(R.id.InvalidPinLabel); mInvalidPinLabel = findViewById(R.id.InvalidPinLabel);
mOpenRecent = findViewById(R.id.openRecent);
mPinField.setOnKeyListener(new View.OnKeyListener() { mPinField.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent keyevent) { public boolean onKey(View view, int keyCode, KeyEvent keyevent) {
...@@ -65,6 +68,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -65,6 +68,9 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
String lastPin = Settings.GetPref(Settings.recentEventPin, getApplicationContext());
mOpenRecent.setEnabled(!lastPin.isEmpty());
View logo = findViewById(R.id.logoImage); View logo = findViewById(R.id.logoImage);
if(logo != null) { if(logo != null) {
Animation animation = AnimationUtils.loadAnimation(this, R.anim.item_anim_pop); Animation animation = AnimationUtils.loadAnimation(this, R.anim.item_anim_pop);
...@@ -85,17 +91,28 @@ public class MainActivity extends AppCompatActivity { ...@@ -85,17 +91,28 @@ public class MainActivity extends AppCompatActivity {
} }
} }
/**
* Function called by button, set in xml
*/
public void SubmitRecentPin(View view){
SubmitPin(true);
}
public void SubmitPin(View view){
SubmitPin(false);
}
/** /**
* Submit a pin for an event to the server and act on response accordingly, ie open scanActivity if valid, or request pin entry again * Submit a pin for an event to the server and act on response accordingly, ie open scanActivity if valid, or request pin entry again
*/ */
public void SubmitPin(View view) public void SubmitPin(boolean openRecent)
{ {
Settings.Vibrate(Settings.VibrateTime.SHORT, getApplicationContext()); Settings.Vibrate(Settings.VibrateTime.SHORT, getApplicationContext());
View button = findViewById(R.id.SubmitPin); View button = findViewById(openRecent ? R.id.openRecent : R.id.SubmitPin);
if(button != null) if(button != null)
button.startAnimation(AnimationUtils.loadAnimation(this, R.anim.item_anim_pop)); button.startAnimation(AnimationUtils.loadAnimation(this, R.anim.item_anim_pop));
if(mWaitingOnServer || mPinField.getText().toString().isEmpty()) //prevents submitting a second pin while still waiting on the response for the first pin if(mWaitingOnServer || (!openRecent && mPinField.getText().toString().isEmpty())) //prevents submitting a second pin while still waiting on the response for the first pin
return; return;
mWaitingOnServer = true; mWaitingOnServer = true;
...@@ -104,8 +121,13 @@ public class MainActivity extends AppCompatActivity { ...@@ -104,8 +121,13 @@ public class MainActivity extends AppCompatActivity {
return; return;
} }
if(openRecent)
CurrentPin = Settings.GetPref(Settings.recentEventPin, getApplicationContext());
else
CurrentPin = mPinField.getText().toString(); CurrentPin = mPinField.getText().toString();
//Create a callback, this is what happens when we get the response //Create a callback, this is what happens when we get the response
ServerRequests.OnCheckPinReceivedCallback callback = new ServerRequests.OnCheckPinReceivedCallback() { ServerRequests.OnCheckPinReceivedCallback callback = new ServerRequests.OnCheckPinReceivedCallback() {
@Override @Override
...@@ -141,6 +163,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -141,6 +163,8 @@ public class MainActivity extends AppCompatActivity {
Log.e("postrequest", "Response from server for pin submission: " + statusCode + " with text: " + responseText + " on event pin: " + MainActivity.CurrentPin); Log.e("postrequest", "Response from server for pin submission: " + statusCode + " with text: " + responseText + " on event pin: " + MainActivity.CurrentPin);
if(statusCode == 200) { //success if(statusCode == 200) { //success
Settings.SetPref(Settings.recentEventPin, CurrentPin, getApplicationContext()); //store as last used pin
mOpenRecent.setEnabled(true);
StartScanActivity(); StartScanActivity();
} }
else if(statusCode == 401)//invalid pin else if(statusCode == 401)//invalid pin
......
...@@ -16,6 +16,7 @@ import android.support.v7.app.AppCompatActivity; ...@@ -16,6 +16,7 @@ import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.MenuItem;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
...@@ -525,4 +526,10 @@ public class ScanActivity extends AppCompatActivity { ...@@ -525,4 +526,10 @@ public class ScanActivity extends AppCompatActivity {
timeBackPressed = System.currentTimeMillis(); timeBackPressed = System.currentTimeMillis();
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
onBackPressed();
return true;
}
} }
...@@ -37,6 +37,9 @@ public class Settings { ...@@ -37,6 +37,9 @@ public class Settings {
public static final String[] specialFoodPrefKey = {"ch.amiv.android_app.special_food_pref", ""}; public static final String[] specialFoodPrefKey = {"ch.amiv.android_app.special_food_pref", ""};
public static final String[] sbbPrefKey = {"ch.amiv.android_app.sbb_abo", ""}; public static final String[] sbbPrefKey = {"ch.amiv.android_app.sbb_abo", ""};
//---checkin
public static final String[] recentEventPin = {"ch.amiv.android_app.recent_event_pin", ""};
//region ---SharedPrefs--- //region ---SharedPrefs---
/** /**
* Will check that the shared prefs instance is set so we can edit/retrieve values * Will check that the shared prefs instance is set so we can edit/retrieve values
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
android:gravity="center" android:gravity="center"
android:hint="PIN" android:hint="PIN"
android:inputType="numberPassword" android:inputType="numberPassword"
android:textAlignment="center" android:textAppearance="@style/Body"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
...@@ -27,10 +28,24 @@ ...@@ -27,10 +28,24 @@
android:id="@+id/SubmitPin" android:id="@+id/SubmitPin"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:onClick="SubmitPin" android:onClick="SubmitPin"
android:text="@string/submit" android:text="@string/submit"
android:textAppearance="@style/Subheader"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/PinField" />
<Button
android:id="@+id/openRecent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:enabled="false"
android:onClick="SubmitRecentPin"
android:text="@string/last_event"
android:textAppearance="@style/Subheader"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/PinField" /> app:layout_constraintTop_toBottomOf="@+id/PinField" />
...@@ -63,7 +78,7 @@ ...@@ -63,7 +78,7 @@
android:gravity="center" android:gravity="center"
android:onClick="StartSettingsActivity" android:onClick="StartSettingsActivity"
android:text="@string/settings_title" android:text="@string/settings_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/Subheader"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
...@@ -77,7 +92,7 @@ ...@@ -77,7 +92,7 @@
android:gravity="center" android:gravity="center"
android:onClick="GoToWebsite" android:onClick="GoToWebsite"
android:text="@string/open_website" android:text="@string/open_website"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/Subheader"
app:layout_constraintBottom_toTopOf="@+id/SettingsButton" app:layout_constraintBottom_toTopOf="@+id/SettingsButton"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" /> app:layout_constraintStart_toStartOf="parent" />
...@@ -91,6 +106,7 @@ ...@@ -91,6 +106,7 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:gravity="center" android:gravity="center"
android:text="@string/invalid_url" android:text="@string/invalid_url"
android:textAppearance="@style/Body"
android:visibility="invisible" android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
...@@ -122,6 +122,7 @@ ...@@ -122,6 +122,7 @@
<string name="check_in">Check-In</string> <string name="check_in">Check-In</string>
<string name="check_out">Check-Out</string> <string name="check_out">Check-Out</string>
<string name="submit">Senden</string> <string name="submit">Senden</string>
<string name="last_event">Letzter Event</string>
<string name="enter_event_pin">Event PIN Eingeben</string> <string name="enter_event_pin">Event PIN Eingeben</string>
<string name="no_barcode_detected">Kein Barcode Gefunden</string> <string name="no_barcode_detected">Kein Barcode Gefunden</string>
<string name="invalid_pin">Falscher PIN</string> <string name="invalid_pin">Falscher PIN</string>
......
...@@ -135,6 +135,7 @@ ...@@ -135,6 +135,7 @@
<string name="check_out">Check-Out</string> <string name="check_out">Check-Out</string>
<string name="submit">Submit</string> <string name="submit">Submit</string>
<string name="enter_event_pin">Enter Event PIN</string> <string name="enter_event_pin">Enter Event PIN</string>
<string name="last_event">Last Event</string>
<string name="no_barcode_detected">No Barcode Detected</string> <string name="no_barcode_detected">No Barcode Detected</string>
<string name="invalid_pin">Invalid PIN</string> <string name="invalid_pin">Invalid PIN</string>
<string name="invalid_url">Invalid URL</string> <string name="invalid_url">Invalid URL</string>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment