From c89d02e397000fec16f8c6c338c829671bb29f44 Mon Sep 17 00:00:00 2001 From: Graham Jones Date: Sat, 27 Jan 2024 21:44:42 +0000 Subject: [PATCH] Fixes switching between the two user interfaces without user having to exit app and re-start it. Fixes #138 --- .../org/openseizuredetector/MainActivity.java | 19 +++++++++++++++++++ .../openseizuredetector/MainActivity2.java | 18 ++++++++++++++++++ app/src/main/res/values/strings.xml | 3 ++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java index 603360d..2b98bf8 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity.java @@ -1087,6 +1087,25 @@ public class MainActivity extends AppCompatActivity { super.onResume(); Log.i(TAG, "onResume()"); mUtil.writeToSysLogFile("MainActivity.onResume()"); + + // Check to see if the user has asked for the new user interface to be used instead of this one + // and start that if necessary. + try { + SharedPreferences SP = PreferenceManager + .getDefaultSharedPreferences(getBaseContext()); + boolean useNewUi = SP.getBoolean("UseNewUi", false); + if (useNewUi) { + Log.i(TAG,"onResume() - launching new User Interface"); + Intent intent = new Intent( + getApplicationContext(), + MainActivity2.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + finish(); + } + } catch (Exception ex) { + Log.e(TAG, "exception starting main activity " + ex.toString()); + } } diff --git a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java index a6bd0c2..d711c06 100644 --- a/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java +++ b/app/src/main/java/uk/org/openseizuredetector/MainActivity2.java @@ -136,6 +136,24 @@ public class MainActivity2 extends AppCompatActivity { .add(R.id.fragment_common_container_view, FragmentCommon.class, null) .commit(); + // Check to see if the user has asked for the original user interface to be used instead of this one + // and start that if necessary. + try { + SharedPreferences SP = PreferenceManager + .getDefaultSharedPreferences(getBaseContext()); + boolean useNewUi = SP.getBoolean("UseNewUi", false); + if (!useNewUi) { + Log.i(TAG,"onResume() - launching original User Interface"); + Intent intent = new Intent( + getApplicationContext(), + MainActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); + finish(); + } + } catch (Exception ex) { + Log.e(TAG, "exception starting main activity " + ex.toString()); + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d2179b0..d41503d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,7 +3,8 @@ OpenSeizureDetector "\n - \nV4.2.1 - Added Machine Learning Model Manager so models can be updated easily. + \nV4.2.1 - Added support for PineTime Watches using Bluetooth data source. + \n - Added new, swipeable user interface to simplify the main screen.. " Please enable the new <b>Data Sharing</b> feature to help improve OpenSeizureDetector!<br/>