mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-25 00:30:37 +02:00
Fossil Hybrid HR: Move workout request handling to separate class
This commit is contained in:
parent
e188e54622
commit
d2408f77cd
@ -86,7 +86,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.HybridHRActivitySamp
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationHRConfiguration;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.HybridHRActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksController;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
|
||||
@ -145,6 +144,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidgetElement;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.Widget;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.WidgetsPutRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.workout.WorkoutRequestHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.misfit.FactoryResetRequest;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
@ -1571,53 +1571,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
String workoutState = workoutRequest.optString("state");
|
||||
String workoutType = workoutRequest.optString("type");
|
||||
LOG.info("Got workoutApp request, state=" + workoutState + ", type=" + workoutType);
|
||||
JSONObject workoutResponse = new JSONObject();
|
||||
if (workoutRequest.optString("state").equals("started") && workoutRequest.optString("gps").equals("on")) {
|
||||
int activityType = workoutRequest.optInt("activity", -1);
|
||||
LOG.info("Workout started, activity type is " + Integer.toString(activityType));
|
||||
workoutResponse.put("workoutApp._.config.response", new JSONObject()
|
||||
.put("message", "")
|
||||
.put("type", "success")
|
||||
);
|
||||
OpenTracksController.startRecording(getContext());
|
||||
}
|
||||
if (workoutRequest.optString("type").equals("req_distance")) {
|
||||
workoutResponse.put("workoutApp._.config.gps", new JSONObject()
|
||||
.put("distance", -2)
|
||||
.put("duration", 10)
|
||||
);
|
||||
}
|
||||
if (workoutRequest.optString("state").equals("paused")) {
|
||||
LOG.info("Workout paused");
|
||||
workoutResponse.put("workoutApp._.config.response", new JSONObject()
|
||||
.put("message", "")
|
||||
.put("type", "success")
|
||||
);
|
||||
// Pause OpenTracks recording?
|
||||
}
|
||||
if (workoutRequest.optString("state").equals("resumed")) {
|
||||
LOG.info("Workout resumed");
|
||||
workoutResponse.put("workoutApp._.config.response", new JSONObject()
|
||||
.put("message", "")
|
||||
.put("type", "success")
|
||||
);
|
||||
// Resume OpenTracks recording?
|
||||
}
|
||||
if (workoutRequest.optString("state").equals("end")) {
|
||||
LOG.info("Workout stopped");
|
||||
workoutResponse.put("workoutApp._.config.response", new JSONObject()
|
||||
.put("message", "")
|
||||
.put("type", "success")
|
||||
);
|
||||
OpenTracksController.stopRecording(getContext());
|
||||
}
|
||||
if (workoutRequest.optString("type").equals("req_route")) {
|
||||
// Send the traveled route as an RLE encoded image (example name: 58270405)
|
||||
// Send back a JSON packet, example:
|
||||
// {"res":{"id":21,"set":{"workoutApp._.config.images":{"session_id":1213693133,"route":{"name":"58270405"},"layout_type":"vertical"}}}}
|
||||
// or
|
||||
// {"res":{"id":34,"set":{"workoutApp._.config.images":{"session_id":504875,"route":{"name":"211631088"},"layout_type":"horizontal"}}}}
|
||||
}
|
||||
JSONObject workoutResponse = WorkoutRequestHandler.handleRequest(getContext(), requestId, workoutRequest);
|
||||
if (workoutResponse.length() > 0) {
|
||||
JSONObject responseObject = new JSONObject()
|
||||
.put("res", new JSONObject()
|
||||
|
@ -0,0 +1,77 @@
|
||||
/* Copyright (C) 2022 Arjan Schrijver
|
||||
|
||||
This file is part of Gadgetbridge.
|
||||
|
||||
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Gadgetbridge is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.workout;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksController;
|
||||
|
||||
public class WorkoutRequestHandler {
|
||||
public static void addStateResponse(JSONObject workoutResponse, String type) throws JSONException {
|
||||
workoutResponse.put("workoutApp._.config.response", new JSONObject()
|
||||
.put("message", "")
|
||||
.put("type", type)
|
||||
);
|
||||
}
|
||||
|
||||
public static JSONObject handleRequest(Context context, int requestId, JSONObject workoutRequest) throws JSONException {
|
||||
final Logger LOG = LoggerFactory.getLogger(WorkoutRequestHandler.class);
|
||||
|
||||
JSONObject workoutResponse = new JSONObject();
|
||||
if (workoutRequest.optString("state").equals("started") && workoutRequest.optString("gps").equals("on")) {
|
||||
int activityType = workoutRequest.optInt("activity", -1);
|
||||
LOG.info("Workout started, activity type is " + activityType);
|
||||
addStateResponse(workoutResponse, "success");
|
||||
OpenTracksController.startRecording(context);
|
||||
}
|
||||
if (workoutRequest.optString("type").equals("req_distance")) {
|
||||
workoutResponse.put("workoutApp._.config.gps", new JSONObject()
|
||||
.put("distance", -2)
|
||||
.put("duration", 10)
|
||||
);
|
||||
}
|
||||
if (workoutRequest.optString("state").equals("paused")) {
|
||||
LOG.info("Workout paused");
|
||||
addStateResponse(workoutResponse, "success");
|
||||
// Pause OpenTracks recording?
|
||||
}
|
||||
if (workoutRequest.optString("state").equals("resumed")) {
|
||||
LOG.info("Workout resumed");
|
||||
addStateResponse(workoutResponse, "success");
|
||||
// Resume OpenTracks recording?
|
||||
}
|
||||
if (workoutRequest.optString("state").equals("end")) {
|
||||
LOG.info("Workout stopped");
|
||||
addStateResponse(workoutResponse, "success");
|
||||
OpenTracksController.stopRecording(context);
|
||||
}
|
||||
if (workoutRequest.optString("type").equals("req_route")) {
|
||||
// Send the traveled route as an RLE encoded image (example name: 58270405)
|
||||
// Send back a JSON packet, example:
|
||||
// {"res":{"id":21,"set":{"workoutApp._.config.images":{"session_id":1213693133,"route":{"name":"58270405"},"layout_type":"vertical"}}}}
|
||||
// or
|
||||
// {"res":{"id":34,"set":{"workoutApp._.config.images":{"session_id":504875,"route":{"name":"211631088"},"layout_type":"horizontal"}}}}
|
||||
}
|
||||
return workoutResponse;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user