1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 22:43:00 +01:00

Fossil HR: splitted button config and menu config

This commit is contained in:
Daniel Dakhno 2021-02-03 22:25:11 +01:00
parent 6ca3424035
commit 1981998fc7
3 changed files with 65 additions and 12 deletions

View File

@ -95,6 +95,7 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.authentication.VerifyPrivateKeyRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.commute.CommuteConfigPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.configuration.ConfigurationGetRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.configuration.ConfigurationGetRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.configuration.ConfigurationPutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.configuration.ConfigurationPutRequest;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.AssetFilePutRequest; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.AssetFilePutRequest;
@ -1147,12 +1148,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
@Override @Override
public void overwriteButtons(String jsonConfigString) { public void overwriteButtons(String jsonConfigString) {
try { try {
JSONArray jsonArray = new JSONArray(
GBApplication.getPrefs().getString(HRConfigActivity.CONFIG_KEY_Q_ACTIONS, "[]")
);
String[] menuItems = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) menuItems[i] = jsonArray.getString(i);
SharedPreferences prefs = getDeviceSpecificPreferences(); SharedPreferences prefs = getDeviceSpecificPreferences();
String singlePressEvent = "short_press_release"; String singlePressEvent = "short_press_release";
@ -1187,12 +1182,22 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
} }
} }
queueWrite(new ButtonConfigurationPutRequest( queueWrite(new ButtonConfigurationPutRequest(
menuItems,
availableConfigs.toArray(new ButtonConfiguration[0]), availableConfigs.toArray(new ButtonConfiguration[0]),
this this
)); ));
for(ApplicationInformation info : installedApplications){
if(info.getAppName().equals("commuteApp")){
JSONArray jsonArray = new JSONArray(
GBApplication.getPrefs().getString(HRConfigActivity.CONFIG_KEY_Q_ACTIONS, "[]")
);
String[] menuItems = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) menuItems[i] = jsonArray.getString(i);
queueWrite(new CommuteConfigPutRequest(menuItems, this));
break;
}
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -28,11 +28,11 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fos
import nodomain.freeyourgadget.gadgetbridge.util.GB; import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class ButtonConfigurationPutRequest extends JsonPutRequest { public class ButtonConfigurationPutRequest extends JsonPutRequest {
public ButtonConfigurationPutRequest(String[] menuItems, ButtonConfiguration[] buttonConfigurations, FossilHRWatchAdapter adapter) { public ButtonConfigurationPutRequest(ButtonConfiguration[] buttonConfigurations, FossilHRWatchAdapter adapter) {
super(createObject(menuItems, buttonConfigurations), adapter); super(createObject(buttonConfigurations), adapter);
} }
private static JSONObject createObject(String[] menuItems, ButtonConfiguration[] buttonConfigurations) { private static JSONObject createObject(ButtonConfiguration[] buttonConfigurations) {
try { try {
JSONArray configuration = new JSONArray(); JSONArray configuration = new JSONArray();
for(ButtonConfiguration buttonConfiguration : buttonConfigurations){ for(ButtonConfiguration buttonConfiguration : buttonConfigurations){
@ -41,7 +41,6 @@ public class ButtonConfigurationPutRequest extends JsonPutRequest {
return new JSONObject() return new JSONObject()
.put("push", new JSONObject() .put("push", new JSONObject()
.put("set", new JSONObject() .put("set", new JSONObject()
.put("commuteApp._.config.destinations", new JSONArray(menuItems))
.put("master._.config.buttons", configuration) .put("master._.config.buttons", configuration)
) )
); );

View File

@ -0,0 +1,49 @@
/* Copyright (C) 2019-2021 Andreas Shimokawa, Daniel Dakhno
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.commute;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil_hr.FossilHRWatchAdapter;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration;
import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.json.JsonPutRequest;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class CommuteConfigPutRequest extends JsonPutRequest {
public CommuteConfigPutRequest(String[] menuItems, FossilHRWatchAdapter adapter) {
super(createObject(menuItems), adapter);
}
private static JSONObject createObject(String[] menuItems) {
try {
return new JSONObject()
.put("push", new JSONObject()
.put("set", new JSONObject()
.put("commuteApp._.config.destinations", new JSONArray(menuItems))
)
);
} catch (JSONException e) {
GB.toast("error creating json", Toast.LENGTH_LONG, GB.ERROR, e);
}
return null;
}
}