Changed LogManagerControlActivity to slow down UI updates once the UI is populated, not stop them alltogether

This commit is contained in:
Graham Jones
2022-01-29 20:52:29 +00:00
parent 02510d455d
commit c6a838fe1d
4 changed files with 22 additions and 14 deletions

View File

@@ -39,7 +39,8 @@ public class LogManagerControlActivity extends AppCompatActivity {
private SdServiceConnection mConnection; private SdServiceConnection mConnection;
private OsdUtil mUtil; private OsdUtil mUtil;
final Handler serverStatusHandler = new Handler(); final Handler serverStatusHandler = new Handler();
private Integer mUiTimerPeriodFast = 2000; // 2 seconds - we use fast updating while UI is blank and we are waiting for first data
private Integer mUiTimerPeriodSlow = 60000; // 60 seconds - once data has been received and UI populated we only update once per minute.
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -77,7 +78,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
super.onStart(); super.onStart();
mUtil.bindToServer(getApplicationContext(), mConnection); mUtil.bindToServer(getApplicationContext(), mConnection);
waitForConnection(); waitForConnection();
startUiTimer(); startUiTimer(mUiTimerPeriodFast);
} }
@Override @Override
@@ -129,7 +130,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
private void initialiseServiceConnection() { private void initialiseServiceConnection() {
mLm = mConnection.mSdServer.mLm; mLm = mConnection.mSdServer.mLm;
startUiTimer(); startUiTimer(mUiTimerPeriodFast);
getRemoteEvents(); getRemoteEvents();
// Populate events list - we only do it once when the activity is created because the query might slow down the UI. // Populate events list - we only do it once when the activity is created because the query might slow down the UI.
// We could try this code in updateUI() and see though. // We could try this code in updateUI() and see though.
@@ -244,7 +245,13 @@ public class LogManagerControlActivity extends AppCompatActivity {
} else { } else {
stopUpdating = false; stopUpdating = false;
} }
if (stopUpdating) stopUiTimer();
// Note we do not really stop updating the UI, just change from the fast update period to the slow update period
// to save hammering the databases once the UI has been populated once.
if (stopUpdating) {
stopUiTimer();
startUiTimer(mUiTimerPeriodSlow);
}
} //updateUi(); } //updateUi();
@@ -352,7 +359,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
/* /*
* Start the timer that will update the user interface every 5 seconds.. * Start the timer that will update the user interface every 5 seconds..
*/ */
private void startUiTimer() { private void startUiTimer(Integer uiTimerPeriod) {
if (mUiTimer != null) { if (mUiTimer != null) {
Log.v(TAG, "startUiTimer -timer already running - cancelling it"); Log.v(TAG, "startUiTimer -timer already running - cancelling it");
mUiTimer.cancel(); mUiTimer.cancel();
@@ -360,7 +367,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
} }
Log.v(TAG, "startUiTimer() - starting UiTimer"); Log.v(TAG, "startUiTimer() - starting UiTimer");
mUiTimer = mUiTimer =
new UiTimer(2000, 1000); new UiTimer(uiTimerPeriod, 1000);
mUiTimer.start(); mUiTimer.start();
} }

View File

@@ -1668,7 +1668,7 @@ public class SdServer extends Service implements SdDataReceiver {
PendingIntent contentIntent = PendingIntent contentIntent =
PendingIntent.getActivity(getApplicationContext(), PendingIntent.getActivity(getApplicationContext(),
0, i, PendingIntent.FLAG_UPDATE_CURRENT); 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
String contentStr = "Please Record your Seizure Events"; String contentStr = getString(R.string.please_confirm_seizure_events);
if (mNotificationBuilder != null) { if (mNotificationBuilder != null) {
mNotification = mNotificationBuilder.setContentIntent(contentIntent) mNotification = mNotificationBuilder.setContentIntent(contentIntent)
.setSmallIcon(iconId) .setSmallIcon(iconId)

View File

@@ -294,10 +294,10 @@
<string name="title_activity_authenticate">Log in to OpenSeizureDetector Data Sharing</string> <string name="title_activity_authenticate">Log in to OpenSeizureDetector Data Sharing</string>
<string name="logout">Log Out</string> <string name="logout">Log Out</string>
<string name="logged_in_with_token">Logged in with Token</string> <string name="logged_in_with_token">Logged in with Token</string>
<string name="local_database">Local Database</string> <string name="local_database">Data on Phone</string>
<string name="remote_database">Remote Database</string> <string name="remote_database">Shared Data</string>
<string name="num_local_events">Number of Stored Events: </string> <string name="num_local_events">Number of Events Stored on Phone: </string>
<string name="num_local_datapoints">"Number of Stored Datapoints: "</string> <string name="num_local_datapoints">"Number of Datapoints Stored on Phone: "</string>
<string name="view_remote_db_btn">View Remote DB Data</string> <string name="view_remote_db_btn">View Remote DB Data</string>
<string name="report_seizure">Report Seizure</string> <string name="report_seizure">Report Seizure</string>
<string name="date">"Date: "</string> <string name="date">"Date: "</string>
@@ -305,7 +305,7 @@
<string name="time">"Time: "</string> <string name="time">"Time: "</string>
<string name="cancelBtnTxt">Cancel</string> <string name="cancelBtnTxt">Cancel</string>
<string name="select_time">Select Time</string> <string name="select_time">Select Time</string>
<string name="EventsInLocalDb">Events in Local Database</string> <string name="EventsInLocalDb">Events Stored on Phone</string>
<string name="createdNewEvent">Created new Manual Alarm Event</string> <string name="createdNewEvent">Created new Manual Alarm Event</string>
<string name="DatapointNotFound">Datapoint not found - not doing anything</string> <string name="DatapointNotFound">Datapoint not found - not doing anything</string>
<string name="logging_settings_title">Data Logging Settings</string> <string name="logging_settings_title">Data Logging Settings</string>
@@ -326,7 +326,7 @@
<string name="waitingForData">...waiting for data...</string> <string name="waitingForData">...waiting for data...</string>
<string name="refreshBtn">Refresh</string> <string name="refreshBtn">Refresh</string>
<string name="back">Back</string> <string name="back">Back</string>
<string name="unvalidatedEventsTitle">Unvalidated Seizure Events</string> <string name="unvalidatedEventsTitle">Un-Confirmed Seizure Events</string>
<string name="register">Register New User</string> <string name="register">Register New User</string>
<string name="reset_password">Reset Password</string> <string name="reset_password">Reset Password</string>
<string name="login_to_osdapi">Log in to Share Data</string> <string name="login_to_osdapi">Log in to Share Data</string>
@@ -336,4 +336,5 @@
<string name="not_sharing_logged_data">Not Sharing Logged Data</string> <string name="not_sharing_logged_data">Not Sharing Logged Data</string>
<string name="not_logged_in">Not Logged In</string> <string name="not_logged_in">Not Logged In</string>
<string name="data_sharing_setup_ok">Data Sharing Setup OK</string> <string name="data_sharing_setup_ok">Data Sharing Setup OK</string>
<string name="please_confirm_seizure_events">Please Check your Shared Seizure Events</string>
</resources> </resources>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="true"
android:enabled="true" android:enabled="true"
android:key="advancedMode" android:key="advancedMode"
android:summary="@string/AdvancedModeSummary" android:summary="@string/AdvancedModeSummary"