From 087eb187ad2b340909d7707a2e6ae120a685e721 Mon Sep 17 00:00:00 2001 From: Forrest Guice Date: Fri, 15 Mar 2024 16:31:03 -0700 Subject: [PATCH] lastAutoLocationRequest modifies `lastAutoLocationRequest` so that it tolerates the wrong type (a Long as String because of #783). --- .../getfix/LocationHelperSettings.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/forrestguice/suntimeswidget/getfix/LocationHelperSettings.java b/app/src/main/java/com/forrestguice/suntimeswidget/getfix/LocationHelperSettings.java index 435263a78..cbd2dac2b 100644 --- a/app/src/main/java/com/forrestguice/suntimeswidget/getfix/LocationHelperSettings.java +++ b/app/src/main/java/com/forrestguice/suntimeswidget/getfix/LocationHelperSettings.java @@ -103,7 +103,20 @@ public static long timeSinceLastAutoLocationRequest(Context context) { public static long lastAutoLocationRequest(Context context) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); - return pref.getLong(PREF_KEY_LOCATION_TIME, 0); + long t = 0; + try { + t = pref.getLong(PREF_KEY_LOCATION_TIME, 0); + + } catch (ClassCastException e) { + try { + t = Long.parseLong(pref.getString(PREF_KEY_LOCATION_TIME, "0")); + Log.w("lastAutoLocationRequest", "lastAutoLocationRequest has the wrong type! found Long as String."); + + } catch (NumberFormatException | ClassCastException e1) { + Log.e("lastAutoLocationRequest", "Failed to get last auto location request time: " + e1); + } + } + return t; } public static void saveLastAutoLocationRequest(Context context, long value) {