Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/res/layout/start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:animateLayoutChanges="true"
android:background="#424242"
android:clickable="true"
android:focusable="true"
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/org/runnerup/db/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,9 @@ public static void purgeDeletedActivities(
() -> {
int currentProgress = 0;
for (Long id : list) {
if (!dialog.isShowing()) {
break;
}
deleteActivity(db, id);
currentProgress++;
final int progressToShow = currentProgress;
Expand All @@ -648,17 +651,23 @@ public static void purgeDeletedActivities(
// Post-execution step (runs on the main thread)
handler.post(
() -> {
db.close();
mDBHelper.close();
try {
db.close();
mDBHelper.close();
} catch (Exception ignored) {
}
if (onComplete != null) {
onComplete.run();
}
});
});
} else {
// No activities to delete, just clean up
db.close();
mDBHelper.close();
try {
db.close();
mDBHelper.close();
} catch (Exception ignored) {
}
if (onComplete != null) {
onComplete.run();
}
Expand Down
32 changes: 19 additions & 13 deletions app/src/main/org/runnerup/export/util/SyncHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -125,24 +124,31 @@ public static void setName(ContentValues c, String string) {
}

public static JSONObject parse(String in) throws JSONException {
final Scanner s = new Scanner(in);
final JSONObject o = new JSONObject(s.useDelimiter("\\A").next());
s.close();
return o;
return new JSONObject(in);
}

public static JSONObject parse(InputStream in) throws JSONException {
final Scanner s = new Scanner(in);
final JSONObject o = new JSONObject(s.useDelimiter("\\A").next());
s.close();
return o;
return parse(
new BufferedReader(new InputStreamReader(in, java.nio.charset.StandardCharsets.UTF_8)));
}

public static JSONObject parse(Reader in) throws JSONException {
final Scanner s = new Scanner(in);
final JSONObject o = new JSONObject(s.useDelimiter("\\A").next());
s.close();
return o;
BufferedReader reader =
in instanceof BufferedReader ? (BufferedReader) in : new BufferedReader(in);
StringBuilder sb = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
}
} catch (IOException e) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
throw new JSONException(e);
} else {
throw new JSONException(e.getMessage());
}
}
return new JSONObject(sb.toString());
}

public static JSONObject parse(HttpURLConnection conn, String name)
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/org/runnerup/tracker/Tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public class Tracker extends Service implements LocationListenerCompat, Constant
private SQLiteDatabase mDB = null;
private PersistentGpsLoggerListener mDBWriter = null;
private PowerManager.WakeLock mWakeLock = null;

public SQLiteDatabase getDatabase() {
if (mDB == null) {
mDB = DBHelper.getWritableDatabase(this);
}
return mDB;
}

private final List<WorkoutObserver> liveLoggers = new ArrayList<>();

private Workout workout = null;
Expand Down Expand Up @@ -574,7 +582,10 @@ public void completeActivity(boolean save, Double manualDistance) {

private void saveActivity(Double manualDistance) {
if (mDB == null) {
Log.e("Tracker", "saveActivity called but mDB is null");
mDB = DBHelper.getWritableDatabase(this);
}
if (mDB == null) {
Log.e("Tracker", "saveActivity: mDB is still null after attempting to reopen");
return;
}
ContentValues tmp = new ContentValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ private void onReceive(Context context, Intent intent) {
Workout workout = tracker.getWorkout();
if (workout == null) return;

// Ensure database is available if we receive an action that might cause activity saving/pausing
tracker.getDatabase();

if (Constants.Intents.PAUSE_RESUME.contentEquals(action)) {
if (workout.isPaused()) workout.onResume(workout);
else workout.onPause(workout);
Expand Down
Loading