1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-06 13:17:59 +02:00

Revert "Bangle.js:actTrk: try fix parsing after interrupt"

This reverts commit 638f12e96bdb44445902b3bbd477c742e1d88299.
This commit is contained in:
Ganblejs 2024-03-06 12:04:19 +01:00 committed by José Rebelo
parent d93ef074c3
commit 6936053734

View File

@ -6,8 +6,6 @@ import static java.lang.Math.sqrt;
import android.content.Context;
import android.widget.Toast;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@ -91,15 +89,9 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
timeoutTask = new TimerTask() {
public void run() {
try {
parseFetchedRecorderCSVs(getDir(), tracksListIntactPrivate, device, context);
} catch (JSONException e) {
throw new RuntimeException(e);
}
signalFetchingEnded(device, context);
LOG.warn(context.getString(R.string.busy_task_fetch_sports_details_interrupted));
GB.toast(context.getString(R.string.busy_task_fetch_sports_details_interrupted), Toast.LENGTH_LONG, GB.INFO);
signalFetchingEnded(device, context);
LOG.warn(context.getString(R.string.busy_task_fetch_sports_details_interrupted));
GB.toast(context.getString(R.string.busy_task_fetch_sports_details_interrupted), Toast.LENGTH_LONG, GB.INFO);
}
};
}
@ -110,8 +102,12 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
}
private static String getLatestFetchedRecorderLog() {
File dir = getDir();
if (dir == null) return null;
File dir;
try {
dir = FileUtils.getExternalFilesDir();
} catch (IOException e) {
return null;
}
String filename = "latestFetchedRecorderLog.txt";
File inputFile = new File(dir, filename);
String lastSyncedID = "";
@ -127,17 +123,6 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
return lastSyncedID;
}
@Nullable
private static File getDir() {
File dir;
try {
dir = FileUtils.getExternalFilesDir();
} catch (IOException e) {
return null;
}
return dir;
}
private static void setLatestFetchedRecorderLog(File dir, String log) {
String filenameLogID = "latestFetchedRecorderLog.txt";
@ -152,9 +137,8 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
private static void writeToRecorderCSV(String lines, File dir, String filename) {
String mode = "append";
if (lines.equals("erase")) {
if (lines.equals("")) {
mode = "write";
lines = "";
}
File outputFile = new File(dir, filename);
@ -211,14 +195,9 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
return o;
}
private static JSONArray tracksListIntactPrivate;
private static String lastCompletelyFetchedLog = "";
static JSONArray handleActTrk(JSONObject json, JSONArray tracksList, JSONArray tracksListIntact, int prevPacketCount, GBDevice device, Context context) throws JSONException {
stopAndRestartTimeout(device, context);
tracksListIntactPrivate = tracksListIntact;
JSONArray returnArray;
JSONObject stopObj = new JSONObject().put("t","fetchRec").put("id","stop");
@ -252,17 +231,21 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
if (!json.has("lines")) { // if no lines were sent with this json object, it signifies that the whole recorder log has been transmitted.
setLatestFetchedRecorderLog(dir, log);
if (tracksList.length()==0) { // All data from all Recorder logs have been fetched.
parseFetchedRecorderCSVs(dir, tracksListIntact, device, context);
LOG.warn("tracksListIntact:\n" + tracksListIntact);
for (int i = 0; i<tracksListIntact.length(); i++){
String currLog = tracksListIntact.getString(i);
LOG.info("currLog: " + currLog);
String currFilename = "recorder.log" + currLog + ".csv";
parseFetchedRecorderCSV(dir, currFilename, currLog, device, context);
}
signalFetchingEnded(device, context);
int resetPacketCount = -1;
LOG.info("packetCount reset1: " + resetPacketCount);
returnArray = new JSONArray().put(null).put(tracksList).put(resetPacketCount);
} else {
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
lastCompletelyFetchedLog = log;
LOG.info("completelyFetched1: " + lastCompletelyFetchedLog);
tracksList.remove(0);
LOG.warn("tracksListIntact2(String) tracksList.getString(0):\n" + tracksListIntact);
LOG.warn("tracksListIntact2:\n" + tracksListIntact);
int resetPacketCount = -1;
LOG.info("packetCount reset2: " + resetPacketCount);
returnArray = new JSONArray().put(requestTrackObj).put(tracksList).put(resetPacketCount);
@ -281,19 +264,8 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
return returnArray;
}
private static void parseFetchedRecorderCSVs(File dir, JSONArray tracksListIntact, GBDevice device, Context context) throws JSONException {
for (int i = 0; i<tracksListIntact.length(); i++){
String currLog = tracksListIntact.getString(i);
LOG.info("currLog: " + currLog);
String currFilename = "recorder.log" + currLog + ".csv";
parseFetchedRecorderCSV(dir, currFilename, currLog, device, context);
LOG.info("completelyfetched2: "+ lastCompletelyFetchedLog);
if (Objects.equals(currLog, lastCompletelyFetchedLog)) return;
}
}
private static void parseFetchedRecorderCSV(File dir, String filename, String log, GBDevice device, Context context) {
//stopTimeoutTask(); // Parsing can take a while if there are many data. Restart at end of parsing.
stopTimeoutTask(); // Parsing can take a while if there are many data. Restart at end of parsing.
File inputFile = new File(dir, filename);
try { // FIXME: There is maybe code inside this try-statement that should be outside of it.
@ -773,7 +745,7 @@ class BangleJSActivityTrack extends BangleJSDeviceSupport {
throw new RuntimeException(e);
}
// stopAndRestartTimeout(device,context);
stopAndRestartTimeout(device,context);
}