1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-27 11:05:49 +01:00

Pebble: simplify AppMessageHandler

This commit is contained in:
Andreas Shimokawa 2017-01-24 18:38:26 +01:00
parent 3dd058cf81
commit 3233432ee1
2 changed files with 17 additions and 67 deletions

View File

@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Objects; import java.util.Objects;
import java.util.SimpleTimeZone; import java.util.SimpleTimeZone;
import java.util.TimeZone; import java.util.TimeZone;
@ -63,46 +62,17 @@ class AppMessageHandlerMorpheuz extends AppMessageHandler {
messageKeys = new HashMap<>(); messageKeys = new HashMap<>();
try { try {
JSONObject appKeys = getAppKeys(); JSONObject appKeys = getAppKeys();
Iterator<String> appKeysIterator = appKeys.keys(); keyPoint = appKeys.getInt("keyPoint");
while (appKeysIterator.hasNext()) { keyCtrl = appKeys.getInt("keyCtrl");
String current = appKeysIterator.next(); keyFrom = appKeys.getInt("keyFrom");
int appKey = appKeys.getInt(current); keyTo = appKeys.getInt("keyTo");
switch (current) { keyBase = appKeys.getInt("keyBase");
case "keyPoint": keyVersion = appKeys.getInt("keyVersion");
keyPoint = appKey; keyGoneoff = appKeys.getInt("keyGoneoff");
break; keyTransmit = appKeys.getInt("keyTransmit");
case "keyCtrl": keyAutoReset = appKeys.getInt("keyAutoReset");
keyCtrl = appKey; keySnoozes = appKeys.getInt("keySnoozes");
break; keyFault = appKeys.getInt("keyFault");
case "keyFrom":
keyFrom = appKey;
break;
case "keyTo":
keyTo = appKey;
break;
case "keyBase":
keyBase = appKey;
break;
case "keyVersion":
keyVersion = appKey;
break;
case "keyGoneoff":
keyGoneoff = appKey;
break;
case "keyTransmit":
keyTransmit = appKey;
break;
case "keyAutoReset":
keyAutoReset = appKey;
break;
case "keySnoozes":
keySnoozes = appKey;
break;
case "keyFault":
keyFault = appKey;
break;
}
}
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
GB.toast("There was an error accessing the watchface configuration.", Toast.LENGTH_LONG, GB.ERROR); GB.toast("There was an error accessing the watchface configuration.", Toast.LENGTH_LONG, GB.ERROR);
} }

View File

@ -9,7 +9,6 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent; import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
@ -32,31 +31,12 @@ class AppMessageHandlerTrekVolle extends AppMessageHandler {
messageKeys = new HashMap<>(); messageKeys = new HashMap<>();
try { try {
JSONObject appKeys = getAppKeys(); JSONObject appKeys = getAppKeys();
Iterator<String> appKeysIterator = appKeys.keys(); MESSAGE_KEY_WEATHER_TEMPERATURE = appKeys.getInt("WEATHER_TEMPERATURE");
while (appKeysIterator.hasNext()) { MESSAGE_KEY_WEATHER_CONDITIONS = appKeys.getInt("WEATHER_CONDITIONS");
String current = appKeysIterator.next(); MESSAGE_KEY_WEATHER_ICON = appKeys.getInt("WEATHER_ICON");
int appKey = appKeys.getInt(current); MESSAGE_KEY_WEATHER_TEMPERATURE_MIN = appKeys.getInt("WEATHER_TEMPERATURE_MIN");
switch (current) { MESSAGE_KEY_WEATHER_TEMPERATURE_MAX = appKeys.getInt("WEATHER_TEMPERATURE_MAX");
case "WEATHER_TEMPERATURE": MESSAGE_KEY_WEATHER_LOCATION = appKeys.getInt("WEATHER_LOCATION");
MESSAGE_KEY_WEATHER_TEMPERATURE = appKey;
break;
case "WEATHER_CONDITIONS":
MESSAGE_KEY_WEATHER_CONDITIONS = appKey;
break;
case "WEATHER_ICON":
MESSAGE_KEY_WEATHER_ICON = appKey;
break;
case "WEATHER_TEMPERATURE_MIN":
MESSAGE_KEY_WEATHER_TEMPERATURE_MIN = appKey;
break;
case "WEATHER_TEMPERATURE_MAX":
MESSAGE_KEY_WEATHER_TEMPERATURE_MAX = appKey;
break;
case "WEATHER_LOCATION":
MESSAGE_KEY_WEATHER_LOCATION = appKey;
break;
}
}
} catch (IOException | JSONException e) { } catch (IOException | JSONException e) {
GB.toast("There was an error accessing the watchface configuration.", Toast.LENGTH_LONG, GB.ERROR); GB.toast("There was an error accessing the watchface configuration.", Toast.LENGTH_LONG, GB.ERROR);
} }