mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 01:21:56 +01:00
Bangle.js:actTrk: refactor function names
This commit is contained in:
parent
945a28c279
commit
49c4f34f42
@ -19,6 +19,8 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
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 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);
|
||||
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);
|
||||
}
|
||||
|
||||
private static void signalDoneFetching(GBDevice device, Context context) {
|
||||
private static void signalFetchingEnded(GBDevice device, Context context) {
|
||||
device.unsetBusyTask();
|
||||
device.sendDeviceUpdateIntent(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);
|
||||
}
|
||||
|
||||
public static JSONObject compileTrackListRequest(GBDevice device, Context context) {
|
||||
signalStartFetching(device, context);
|
||||
public static JSONObject compileTracksListRequest(GBDevice device, Context context) {
|
||||
signalFetchingStarted(device, context);
|
||||
//GB.toast("TYPE_GPS_TRACKS says hi!", Toast.LENGTH_LONG, GB.INFO);
|
||||
File dir;
|
||||
try {
|
||||
@ -88,13 +90,13 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
|
||||
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!");
|
||||
//GB.toast(getContext(), "trksList says hi!", Toast.LENGTH_LONG, GB.INFO);
|
||||
JSONArray tracksList = json.getJSONArray("list");
|
||||
LOG.info("New recorder logs since last fetch: " + String.valueOf(tracksList));
|
||||
if (tracksList.length()==0) {
|
||||
signalDoneFetching(device, context);
|
||||
signalFetchingEnded(device, context);
|
||||
return null;
|
||||
} else {
|
||||
return tracksList;
|
||||
@ -107,7 +109,6 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
|
||||
o.put("t", "fetchRec");
|
||||
o.put("id", id);
|
||||
o.put("last", String.valueOf(isLastId));
|
||||
//uartTxJSON("requestActivityTrackLog", o);
|
||||
} catch (JSONException e) {
|
||||
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.info("packetCount Aborting: " + prevPacketCount);
|
||||
returnArray = new JSONArray().put(stopObj).put(tracksList).put(prevPacketCount);
|
||||
signalDoneFetching(device, context);
|
||||
signalFetchingEnded(device, context);
|
||||
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.
|
||||
parseFetchedRecorderCSV(dir, filename, log, device, context);
|
||||
if (tracksList.length()==0) {
|
||||
signalDoneFetching(device, context);
|
||||
signalFetchingEnded(device, context);
|
||||
int resetPacketCount = -1;
|
||||
LOG.info("packetCount reset1: " + 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);
|
||||
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));
|
||||
StringBuilder storedLogBuilder = new StringBuilder(reader.readLine() + "\n");
|
||||
String line;
|
||||
@ -427,6 +428,11 @@ public class BangleJSActivityTrack extends BangleJSDeviceSupport {
|
||||
summary.setStartTime(startTime);
|
||||
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).
|
||||
if (analyticsObject.has("speed")) {
|
||||
if (3 > averageOfJSONArray(analyticsObject.getJSONArray("Speed"))) {
|
||||
summary.setActivityKind(ActivityKind.TYPE_WALKING);
|
||||
}
|
||||
}
|
||||
summary.setRawDetailsPath(String.valueOf(inputFile));
|
||||
|
||||
JSONObject summaryData = new JSONObject();
|
||||
|
@ -564,9 +564,8 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
case "act":
|
||||
handleActivity(json);
|
||||
break;
|
||||
case "trksList":
|
||||
//handleTrksList(json);
|
||||
tracksList = BangleJSActivityTrack.handleTrksList(json, getDevice(), getContext());
|
||||
case "actTrksList":
|
||||
tracksList = BangleJSActivityTrack.handleActTrksList(json, getDevice(), getContext());
|
||||
if (tracksList!=null) {
|
||||
JSONObject requestTrackObj = BangleJSActivityTrack.compileTrackRequest(tracksList.getString(0), 1==tracksList.length());
|
||||
uartTxJSON("requestActivityTrackLog", requestTrackObj);
|
||||
@ -1409,7 +1408,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
if (dataTypes == RecordedDataTypes.TYPE_GPS_TRACKS) {
|
||||
JSONObject requestTracksListObj = BangleJSActivityTrack.compileTrackListRequest(getDevice(), getContext());
|
||||
JSONObject requestTracksListObj = BangleJSActivityTrack.compileTracksListRequest(getDevice(), getContext());
|
||||
uartTxJSON("requestActivityTracksList", requestTracksListObj);
|
||||
}
|
||||
if (dataTypes == RecordedDataTypes.TYPE_DEBUGLOGS) {
|
||||
|
Loading…
Reference in New Issue
Block a user