diff --git a/app/src/main/java/uk/org/openseizuredetector/SdServer.java b/app/src/main/java/uk/org/openseizuredetector/SdServer.java index 35af1bb..b6e7fb9 100644 --- a/app/src/main/java/uk/org/openseizuredetector/SdServer.java +++ b/app/src/main/java/uk/org/openseizuredetector/SdServer.java @@ -1137,7 +1137,7 @@ public class SdServer extends Service implements SdDataReceiver { //writeToSD(); mLm.writeDatapointToLocalDb(mSdData); } else { - Log.e(TAG,"logData() - mLm is null - this should not happen"); + Log.e(TAG, "logData() - mLm is null - this should not happen"); } } } @@ -1289,14 +1289,19 @@ public class SdServer extends Service implements SdDataReceiver { public void onFinish() { Log.v(TAG, "SmsTimer.onFinish()"); mTimeLeft = 0; - mLocationFinder.getLocation(this); - Location loc = mLocationFinder.getLastLocation(); - if (loc != null) { - mUtil.showToast(getString(R.string.send_sms_last_location) - + loc.getLongitude() + "," - + loc.getLatitude()); + if (mLocationFinder!=null) { + mLocationFinder.getLocation(this); + Location loc = mLocationFinder.getLastLocation(); + if (loc != null) { + mUtil.showToast(getString(R.string.send_sms_last_location) + + loc.getLongitude() + "," + + loc.getLatitude()); + } else { + Log.i(TAG, "SmsTimer.onFinish() - Last Location is Null so sending first SMS without location."); + } } else { - Log.i(TAG, "SmsTimer.onFinish() - Last Location is Null so sending first SMS without location."); + Log.e(TAG,"SmsTimer.onFinish - mLocationFinder is null - this should not happen!"); + mUtil.showToast("SmsTimer.onFinish - mLocationFinder is null - this should not happen! - Please report this issue!") } Log.i(TAG, "SmsTimer.onFinish() - Sending to " + mSMSNumbers.length + " Numbers"); mUtil.writeToSysLogFile("SdServer.SmsTimer.onFinish()"); @@ -1550,28 +1555,26 @@ public class SdServer extends Service implements SdDataReceiver { // Retrieve events from remote database if (mLm.mWac.getEvents((JSONObject remoteEventsObj) -> { Log.v(TAG, "CheckEvents.getEvents.Callback()"); - long firstUnvalidatedEvent; + Boolean haveUnvalidatedEvent = false; if (remoteEventsObj == null) { Log.e(TAG, "CheckEvents.Callback: Error Retrieving events"); } else { try { JSONArray eventsArray = remoteEventsObj.getJSONArray("events"); // A bit of a hack to display in reverse chronological order - firstUnvalidatedEvent = -1; for (int i = eventsArray.length() - 1; i >= 0; i--) { JSONObject eventObj = eventsArray.getJSONObject(i); - Long id = eventObj.getLong("id"); String typeStr = eventObj.getString("type"); //Log.v(TAG,"CheckEventsTimer: id="+id+", typeStr="+typeStr); - if (typeStr.equals("null")) { - firstUnvalidatedEvent = id; + if (typeStr.equals("null") || typeStr.equals("")) { + haveUnvalidatedEvent = true; //Log.v(TAG,"CheckEventsTimer:setting firstUnvalidatedEvent to "+firstUnvalidatedEvent); } } - Log.v(TAG, "CheckEventsTimer.onFinish.callback - firstUnvalidatedEvent = " + - firstUnvalidatedEvent); - if (firstUnvalidatedEvent >= 0) { - showEventNotification(firstUnvalidatedEvent); + Log.v(TAG, "CheckEventsTimer.onFinish.callback - haveUnvalidatedEvent = " + + haveUnvalidatedEvent); + if (haveUnvalidatedEvent) { + showEventNotification(); mNM.cancel(DATASHARE_NOTIFICATION_ID); } else { mNM.cancel(EVENT_NOTIFICATION_ID); @@ -1622,7 +1625,7 @@ public class SdServer extends Service implements SdDataReceiver { /** * Show a notification to tell the user that we have unvalidated events. */ - private void showEventNotification(long eventId) { + private void showEventNotification() { Log.v(TAG, "showEventNotification()"); int iconId; String titleStr;