Bangle.js:actTrk: refactor function names

This commit is contained in:
Ganblejs 2024-03-05 02:10:18 +01:00 committed by José Rebelo
parent 945a28c279
commit 49c4f34f42
2 changed files with 20 additions and 15 deletions

View File

@ -19,6 +19,8 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.R;
@ -42,21 +44,21 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
private static final Logger LOG = LoggerFactory.getLogger(BangleJSActivityTrack.class); private static final Logger LOG = LoggerFactory.getLogger(BangleJSActivityTrack.class);
private static void signalStartFetching(GBDevice device, Context context) { private static void signalFetchingStarted(GBDevice device, Context context) {
GB.updateTransferNotification(context.getString(R.string.activity_detail_start_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details),"", true, 0, context); GB.updateTransferNotification(context.getString(R.string.activity_detail_start_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details),"", true, 0, context);
device.setBusyTask(context.getString(R.string.busy_task_fetch_sports_details)); device.setBusyTask(context.getString(R.string.busy_task_fetch_sports_details));
GB.toast(context.getString(R.string.activity_detail_start_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details), Toast.LENGTH_SHORT, GB.INFO); GB.toast(context.getString(R.string.activity_detail_start_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details), Toast.LENGTH_SHORT, GB.INFO);
} }
private static void signalDoneFetching(GBDevice device, Context context) { private static void signalFetchingEnded(GBDevice device, Context context) {
device.unsetBusyTask(); device.unsetBusyTask();
device.sendDeviceUpdateIntent(context); device.sendDeviceUpdateIntent(context);
GB.updateTransferNotification(null, "", false, 100, context); GB.updateTransferNotification(null, "", false, 100, context);
GB.toast(context.getString(R.string.activity_detail_end_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details), Toast.LENGTH_SHORT, GB.INFO); GB.toast(context.getString(R.string.activity_detail_end_label) + " : " + context.getString(R.string.busy_task_fetch_sports_details), Toast.LENGTH_SHORT, GB.INFO);
} }
public static JSONObject compileTrackListRequest(GBDevice device, Context context) { public static JSONObject compileTracksListRequest(GBDevice device, Context context) {
signalStartFetching(device, context); signalFetchingStarted(device, context);
//GB.toast("TYPE_GPS_TRACKS says hi!", Toast.LENGTH_LONG, GB.INFO); //GB.toast("TYPE_GPS_TRACKS says hi!", Toast.LENGTH_LONG, GB.INFO);
File dir; File dir;
try { try {
@ -88,13 +90,13 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
return o; return o;
} }
public static JSONArray handleTrksList(JSONObject json, GBDevice device, Context context) throws JSONException { public static JSONArray handleActTrksList(JSONObject json, GBDevice device, Context context) throws JSONException {
LOG.info("trksList says hi!"); LOG.info("trksList says hi!");
//GB.toast(getContext(), "trksList says hi!", Toast.LENGTH_LONG, GB.INFO); //GB.toast(getContext(), "trksList says hi!", Toast.LENGTH_LONG, GB.INFO);
JSONArray tracksList = json.getJSONArray("list"); JSONArray tracksList = json.getJSONArray("list");
LOG.info("New recorder logs since last fetch: " + String.valueOf(tracksList)); LOG.info("New recorder logs since last fetch: " + String.valueOf(tracksList));
if (tracksList.length()==0) { if (tracksList.length()==0) {
signalDoneFetching(device, context); signalFetchingEnded(device, context);
return null; return null;
} else { } else {
return tracksList; return tracksList;
@ -107,7 +109,6 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
o.put("t", "fetchRec"); o.put("t", "fetchRec");
o.put("id", id); o.put("id", id);
o.put("last", String.valueOf(isLastId)); o.put("last", String.valueOf(isLastId));
//uartTxJSON("requestActivityTrackLog", o);
} catch (JSONException e) { } catch (JSONException e) {
LOG.info("JSONException: " + e.getLocalizedMessage()); LOG.info("JSONException: " + e.getLocalizedMessage());
} }
@ -128,7 +129,7 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
LOG.error("Activity Track Packets came out of order - aborting."); LOG.error("Activity Track Packets came out of order - aborting.");
LOG.info("packetCount Aborting: " + prevPacketCount); LOG.info("packetCount Aborting: " + prevPacketCount);
returnArray = new JSONArray().put(stopObj).put(tracksList).put(prevPacketCount); returnArray = new JSONArray().put(stopObj).put(tracksList).put(prevPacketCount);
signalDoneFetching(device, context); signalFetchingEnded(device, context);
return returnArray; return returnArray;
} }
@ -148,7 +149,7 @@ public 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. if (!json.has("lines")) { // if no lines were sent with this json object, it signifies that the whole recorder log has been transmitted.
parseFetchedRecorderCSV(dir, filename, log, device, context); parseFetchedRecorderCSV(dir, filename, log, device, context);
if (tracksList.length()==0) { if (tracksList.length()==0) {
signalDoneFetching(device, context); signalFetchingEnded(device, context);
int resetPacketCount = -1; int resetPacketCount = -1;
LOG.info("packetCount reset1: " + resetPacketCount); LOG.info("packetCount reset1: " + resetPacketCount);
returnArray = new JSONArray().put(null).put(tracksList).put(resetPacketCount); returnArray = new JSONArray().put(null).put(tracksList).put(resetPacketCount);
@ -196,7 +197,7 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
File inputFile = new File(dir, filename); File inputFile = new File(dir, filename);
try { // FIXME: There is maybe code inside this try-statement that should be outside of it. try { // FIXME: There is maybe code inside this try-statement that should be outside of it.
// Read from the previously stored log (see the else-statement below) into a string. // Read from the previously stored log into a string.
BufferedReader reader = new BufferedReader(new FileReader(inputFile)); BufferedReader reader = new BufferedReader(new FileReader(inputFile));
StringBuilder storedLogBuilder = new StringBuilder(reader.readLine() + "\n"); StringBuilder storedLogBuilder = new StringBuilder(reader.readLine() + "\n");
String line; String line;
@ -427,6 +428,11 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
summary.setStartTime(startTime); summary.setStartTime(startTime);
summary.setEndTime(endTime); summary.setEndTime(endTime);
summary.setActivityKind(ActivityKind.TYPE_RUNNING); // TODO: Make this depend on info from watch (currently this info isn't supplied in Bangle.js recorder logs). summary.setActivityKind(ActivityKind.TYPE_RUNNING); // TODO: Make this depend on info from watch (currently this info isn't supplied in Bangle.js recorder logs).
if (analyticsObject.has("speed")) {
if (3 > averageOfJSONArray(analyticsObject.getJSONArray("Speed"))) {
summary.setActivityKind(ActivityKind.TYPE_WALKING);
}
}
summary.setRawDetailsPath(String.valueOf(inputFile)); summary.setRawDetailsPath(String.valueOf(inputFile));
JSONObject summaryData = new JSONObject(); JSONObject summaryData = new JSONObject();

View File

@ -564,9 +564,8 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
case "act": case "act":
handleActivity(json); handleActivity(json);
break; break;
case "trksList": case "actTrksList":
//handleTrksList(json); tracksList = BangleJSActivityTrack.handleActTrksList(json, getDevice(), getContext());
tracksList = BangleJSActivityTrack.handleTrksList(json, getDevice(), getContext());
if (tracksList!=null) { if (tracksList!=null) {
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length()); JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
uartTxJSON("requestActivityTrackLog", requestTrackObj); uartTxJSON("requestActivityTrackLog", requestTrackObj);
@ -1409,7 +1408,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
} }
if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) { if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) {
JSONObject requestTracksListObj = BangleJSActivityTrack.compileTrackListRequest(getDevice(), getContext()); JSONObject requestTracksListObj = BangleJSActivityTrack.compileTracksListRequest(getDevice(), getContext());
uartTxJSON("requestActivityTracksList", requestTracksListObj); uartTxJSON("requestActivityTracksList", requestTracksListObj);
} }
if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) { if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) {