diff --git a/postixdroid/app/src/main/java/de/ccc/events/postixdroid/ui/MainActivity.java b/postixdroid/app/src/main/java/de/ccc/events/postixdroid/ui/MainActivity.java index 1aba83b..928c3dd 100644 --- a/postixdroid/app/src/main/java/de/ccc/events/postixdroid/ui/MainActivity.java +++ b/postixdroid/app/src/main/java/de/ccc/events/postixdroid/ui/MainActivity.java @@ -64,12 +64,21 @@ public enum State { private String lastScanCode; private State state = State.SCANNING; private Handler timeoutHandler; + private Handler timerHandler; + private long timerStart; private MediaPlayer mediaPlayer; private TicketCheckProvider checkProvider; private AppConfig config; private DataWedgeHelper dataWedgeHelper; private AlertDialog dialog; + Runnable timerUpdate = new Runnable() { + @Override + public void run() { + updateTimer(true); + } + }; + private JSONObject options; private String last_secret; @@ -102,6 +111,7 @@ public void onCreate(Bundle savedInstanceState) { mediaPlayer = buildMediaPlayer(this); timeoutHandler = new Handler(); + timerHandler = new Handler(); resetView(); @@ -123,6 +133,7 @@ public void onCreate(Bundle savedInstanceState) { } } } + timerHandler.postDelayed(timerUpdate, 100); } @@ -248,6 +259,7 @@ private void handleTicketScanned(String s) { options = new JSONObject(); state = State.LOADING; findViewById(R.id.tvScanResult).setVisibility(View.GONE); + findViewById(R.id.tvTimer).setVisibility(View.GONE); findViewById(R.id.pbScan).setVisibility(View.VISIBLE); new CheckTask().execute(s); } @@ -256,6 +268,7 @@ private void resetView() { TextView tvScanResult = (TextView) findViewById(R.id.tvScanResult); timeoutHandler.removeCallbacksAndMessages(null); tvScanResult.setVisibility(View.VISIBLE); + findViewById(R.id.tvTimer).setVisibility(View.GONE); ((TextView) findViewById(R.id.tvScanResult)).setText(""); findViewById(R.id.rlScanStatus).setBackgroundColor( ContextCompat.getColor(this, R.color.scan_result_unknown)); @@ -290,9 +303,19 @@ protected void onPostExecute(TicketCheckProvider.CheckResult checkResult) { } } + private void updateTimer(boolean repeat) { + ((TextView) findViewById(R.id.tvTimer)).setText(String.valueOf(Math.round((System.currentTimeMillis() - timerStart) / 1000))); + if (repeat) { + timerHandler.postDelayed(timerUpdate, 500); + } + } + private void displayScanResult(TicketCheckProvider.CheckResult checkResult) { + TextView tvScanResult = findViewById(R.id.tvScanResult); + timerStart = System.currentTimeMillis(); + updateTimer(false); + findViewById(R.id.tvTimer).setVisibility(View.VISIBLE); - TextView tvScanResult = (TextView) findViewById(R.id.tvScanResult); state = State.RESULT; findViewById(R.id.pbScan).setVisibility(View.INVISIBLE); diff --git a/postixdroid/app/src/main/res/layout/activity_main.xml b/postixdroid/app/src/main/res/layout/activity_main.xml index 82ab32b..778d8d7 100644 --- a/postixdroid/app/src/main/res/layout/activity_main.xml +++ b/postixdroid/app/src/main/res/layout/activity_main.xml @@ -7,7 +7,7 @@ + +