Commit ea75aab9 authored by Roger Barton's avatar Roger Barton
Browse files

Merge branch 'checkin'

parents 240c8a86 8bcaf2c5
Pipeline #5890 passed with stages
in 11 minutes and 28 seconds
......@@ -20,6 +20,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
......@@ -33,6 +34,7 @@ public class MainActivity extends AppCompatActivity {
private EditText mPinField;
private TextView mInvalidPinLabel;
private Button mOpenRecent;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -54,6 +56,7 @@ public class MainActivity extends AppCompatActivity {
{
mPinField = findViewById(R.id.PinField);
mInvalidPinLabel = findViewById(R.id.InvalidPinLabel);
mOpenRecent = findViewById(R.id.openRecent);
mPinField.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent keyevent) {
......@@ -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);
if(logo != null) {
Animation animation = AnimationUtils.loadAnimation(this, R.anim.item_anim_pop);
......@@ -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
*/
public void SubmitPin(View view)
public void SubmitPin(boolean openRecent)
{
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)
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;
mWaitingOnServer = true;
......@@ -104,7 +121,12 @@ public class MainActivity extends AppCompatActivity {
return;
}
CurrentPin = mPinField.getText().toString();
if(openRecent)
CurrentPin = Settings.GetPref(Settings.recentEventPin, getApplicationContext());
else
CurrentPin = mPinField.getText().toString();
//Create a callback, this is what happens when we get the response
ServerRequests.OnCheckPinReceivedCallback callback = new ServerRequests.OnCheckPinReceivedCallback() {
......@@ -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);
if(statusCode == 200) { //success
Settings.SetPref(Settings.recentEventPin, CurrentPin, getApplicationContext()); //store as last used pin
mOpenRecent.setEnabled(true);
StartScanActivity();
}
else if(statusCode == 401)//invalid pin
......
......@@ -16,6 +16,7 @@ import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
......@@ -525,4 +526,10 @@ public class ScanActivity extends AppCompatActivity {
timeBackPressed = System.currentTimeMillis();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
onBackPressed();
return true;
}
}
......@@ -37,6 +37,9 @@ public class Settings {
public static final String[] specialFoodPrefKey = {"ch.amiv.android_app.special_food_pref", ""};
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---
/**
* Will check that the shared prefs instance is set so we can edit/retrieve values
......
......@@ -15,7 +15,8 @@
android:gravity="center"
android:hint="PIN"
android:inputType="numberPassword"
android:textAlignment="center"
android:textAppearance="@style/Body"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
......@@ -27,10 +28,24 @@
android:id="@+id/SubmitPin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginTop="12dp"
android:onClick="SubmitPin"
android:text="@string/submit"
android:textAppearance="@style/Subheader"
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_constraintTop_toBottomOf="@+id/PinField" />
......@@ -63,7 +78,7 @@
android:gravity="center"
android:onClick="StartSettingsActivity"
android:text="@string/settings_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textAppearance="@style/Subheader"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
......@@ -77,7 +92,7 @@
android:gravity="center"
android:onClick="GoToWebsite"
android:text="@string/open_website"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textAppearance="@style/Subheader"
app:layout_constraintBottom_toTopOf="@+id/SettingsButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
......@@ -91,6 +106,7 @@
android:layout_marginTop="8dp"
android:gravity="center"
android:text="@string/invalid_url"
android:textAppearance="@style/Body"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
......@@ -122,6 +122,7 @@
<string name="check_in">Check-In</string>
<string name="check_out">Check-Out</string>
<string name="submit">Senden</string>
<string name="last_event">Letzter Event</string>
<string name="enter_event_pin">Event PIN Eingeben</string>
<string name="no_barcode_detected">Kein Barcode Gefunden</string>
<string name="invalid_pin">Falscher PIN</string>
......
......@@ -135,6 +135,7 @@
<string name="check_out">Check-Out</string>
<string name="submit">Submit</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="invalid_pin">Invalid PIN</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