Finish fixing the large numbers bug by making 99:59:59 the maximum value allowed. Enhance the logging around resetting the StartStop key after a crash.

This commit is contained in:
2025-07-13 10:32:19 -07:00
parent 37e7df98af
commit dbb1af03c4

View File

@@ -93,9 +93,14 @@ public class MainActivity extends AppCompatActivity {
if (DEBUG) Log.d(tag, "Shutting off improper START value"); if (DEBUG) Log.d(tag, "Shutting off improper START value");
// Ensure START is always off if we are creating (not resuming). // Ensure START is always off if we are creating (not resuming).
sharedPreferences.edit().putBoolean(keyStartStop, false).apply(); int count = 0;
while (!sharedPreferences.edit().putBoolean(keyStartStop, false).commit() && count < 50) {
if (DEBUG) Log.d(tag, "Commit failed, trying again. count=" + count);
count++;
}
Log.d(tag, "key=" + key + " value=" + sharedPreferencesAll.get(key)); boolean checkStartStop = sharedPreferences.getBoolean(keyStartStop, false);;
Log.d(tag, "key=" + key + " value=" + checkStartStop);
} }
} }
} }
@@ -203,38 +208,29 @@ public class MainActivity extends AppCompatActivity {
try { try {
hours = Integer.parseInt("0" + etHours.getText().toString()); hours = Integer.parseInt("0" + etHours.getText().toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
etHours.setText(""); hours = 99;
} }
try { try {
minutes = Integer.parseInt("0" + etMinutes.getText().toString()); minutes = Integer.parseInt("0" + etMinutes.getText().toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
etMinutes.setText(""); minutes = 59;
} }
try { try {
seconds = Integer.parseInt("0" + etSeconds.getText().toString()); seconds = Integer.parseInt("0" + etSeconds.getText().toString());
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
etSeconds.setText(""); seconds = 59;
} }
// TODO: Properly handle hours being set to 999, which casues a negative. if ((hours + (minutes/60) + (seconds/60/60)) > 99) {
// TODO: Properly handle time being greater than current time, such as hours = 99;
longLoopInterval = (long) (((hours*60*60) + (minutes*60) + seconds) * 1000); minutes = 59;
if (longLoopInterval > System.currentTimeMillis() || longLoopInterval < 0) { seconds = 59;
if (DEBUG) Log.d(tag, "Got a number larger than current time");
if (DEBUG) Log.d(tag, "Setting to current time value");
longLoopInterval = System.currentTimeMillis();
/* Not quite doing what we want yet.
String sHours = "" + longLoopInterval/1000;
String sMinutes = "" + longLoopInterval/1000/60 % 60;
String sSeconds = "" + longLoopInterval/1000/60/60 % 60;
etHours.setText(sHours);
etMinutes.setText(sMinutes);
etSeconds.setText(sSeconds);
*/
} }
if (hours > 0) etHours.setText("" + hours);
if (minutes > 0) etMinutes.setText("" + minutes);
if (seconds > 0) etSeconds.setText("" + seconds);
if (DEBUG) Log.d(tag, "longLoopInterval=" + longLoopInterval); if (DEBUG) Log.d(tag, "longLoopInterval=" + longLoopInterval);
setChronometer(longLoopInterval); setChronometer(longLoopInterval);