Skip to content

Commit

Permalink
Use display customisation and fix various bugs
Browse files Browse the repository at this point in the history
Bugs fixed include:

* Crash when creating Position.Info() on Fenix 5X devices
* Altitude not being available due to missing locationInfo object

Use configuration variables to show/hide various UI elements
  • Loading branch information
kelnage committed Sep 10, 2019
1 parent 3c979ab commit 5914af0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 38 deletions.
52 changes: 21 additions & 31 deletions source/DigitalSimplicityView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DigitalSimplicityView extends WatchUi.WatchFace {
}

// state
var locationInfo = null;
var geo = null;
var sunEvent = null;
var is24Hour = false;

Expand Down Expand Up @@ -242,20 +242,25 @@ class DigitalSimplicityView extends WatchUi.WatchFace {
var dateString = getDate(now);

// Format notification count
var nc = settings.notificationCount;
var ncs = "";
if(nc == 0) {
ncs = "";
} else {
ncs = nc.format("%d");
if(app.getProperty("DisplayNC")) {
var nc = settings.notificationCount;
if(nc == 0) {
ncs = "";
} else {
ncs = nc.format("%d");
}
}

// Format battery percentage
var batteryString = Math.round(stats.battery).format("%d") + "%";
var batteryString = "";
if(app.getProperty("DisplayBattery")) {
batteryString = Math.round(stats.battery).format("%d") + "%";
}

// Load appropriate stats
var topStatString = StatOptions.getStatString(app.getProperty("TopBarStat"), topFormat, sunEvent, activity, settings);
var bottomStatString = StatOptions.getStatString(app.getProperty("BottomBarStat"), bottomFormat, sunEvent, activity, settings);
var topStatString = StatOptions.getStatString(app.getProperty("TopBarStat"), topFormat, geo, sunEvent, activity, settings);
var bottomStatString = StatOptions.getStatString(app.getProperty("BottomBarStat"), bottomFormat, geo, sunEvent, activity, settings);

// Update the views
var dateView = View.findDrawableById("DateLabel");
Expand All @@ -279,7 +284,7 @@ class DigitalSimplicityView extends WatchUi.WatchFace {
if(app.getProperty("DisplayMoveBar")) {
drawMoveBar(dc, activity.moveBarLevel);
}
if(settings.alarmCount > 0) {
if(app.getProperty("DisplayAlarm") && settings.alarmCount > 0) {
alarmIcon.draw(dc);
}
if(settings.phoneConnected) {
Expand Down Expand Up @@ -362,42 +367,27 @@ class DigitalSimplicityView extends WatchUi.WatchFace {
return Lang.format("$1$ $2$", [days[time.day_of_week - 1], time.day]);
}

function parseActivityInfo(activityInfo) {
var locationInfo = new Position.Info();
if(Activity.Info has :currentLocationAccuracy && activityInfo.currentLocationAccuracy != null) {
locationInfo.accuracy = activityInfo.currentLocationAccuracy;
if(Position.Info has :position && Activity.Info has :currentLocation) {
locationInfo.position = activityInfo.currentLocation;
}
if(Position.Info has :altitude && Activity.Info has :altitude) {
locationInfo.altitude = activityInfo.altitude;
}
} else {
locationInfo.accuracy = Position.QUALITY_NOT_AVAILABLE;
}
return locationInfo;
}

function updatePosition() {
// System.println("Entering updatePosition");
var top = Application.getApp().getProperty("TopBarStat");
var bottom = Application.getApp().getProperty("BottomBarStat");
if(StatOptions.requiresLocation(top) || StatOptions.requiresLocation(bottom)) {
if(Position has :getInfo) {
locationInfo = Position.getInfo();
geo = GeoData.parsePositionInfo(Position.getInfo());
}
if((locationInfo == null || locationInfo.accuracy == Position.QUALITY_NOT_AVAILABLE) && Activity has :getActivityInfo && Activity.Info has :currentLocation) {
locationInfo = parseActivityInfo(Activity.getActivityInfo());
if((geo == null || geo.accuracy == Position.QUALITY_NOT_AVAILABLE) &&
Activity has :getActivityInfo && Activity.Info has :currentLocation) {
geo = GeoData.parseActivityInfo(Activity.getActivityInfo());
}
if(locationInfo != null && locationInfo.accuracy != Position.QUALITY_NOT_AVAILABLE &&
if(geo != null && geo.accuracy != Position.QUALITY_NOT_AVAILABLE &&
(StatOptions.requiresSunData(top) || StatOptions.requiresSunData(bottom))) {
var now = Time.now();
if(sunEvent == null || // if there is no previous reading, definitely calculate the sunrise/set data
(now.compare(sunEvent.eventTime) > 0 || now.compare(sunEvent.eventTime) < -43200) // time based checks
// TODO: location based checks?
) {
// Using Time.today() rather than Time.now()
sunEvent = SunData.calculateSunriseSunset(Time.today(), locationInfo, false, sunEvent);
sunEvent = SunData.calculateSunriseSunset(Time.today(), geo, false, sunEvent);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions source/StatOptions.mc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class StatOptions {
return "";
}

static function getStatString(index, formatString, sunEvent, activity, settings) {
static function getStatString(index, formatString, geo, sunEvent, activity, settings) {
// System.println("Entering getStatString");
if(formatString == null) {
System.println("Did not receive a format string");
Expand Down Expand Up @@ -256,9 +256,9 @@ class StatOptions {
args = [sample.data.format("%d")];
}
}
} else if(Position.Info has :altitude) {
if(locationInfo != null && locationInfo.accuracy != Position.QUALITY_NOT_AVAILABLE) {
args = [locationInfo.altitude.format("%d")];
} else if((Position has :Info) && (Position.Info has :altitude)) {
if(geo != null && geo.accuracy != Position.QUALITY_NOT_AVAILABLE) {
args = [geo.altitude.format("%d")];
}
} else {
return "N/S";
Expand All @@ -273,9 +273,9 @@ class StatOptions {
args = [(sample.data * 3.281).format("%d")];
}
}
} else if(Position.Info has :altitude) {
if(locationInfo != null && locationInfo.accuracy != Position.QUALITY_NOT_AVAILABLE) {
args = [locationInfo.altitude.format("%d")];
} else if((Position has :Info) && (Position.Info has :altitude)) {
if(geo != null && geo != Position.QUALITY_NOT_AVAILABLE) {
args = [geo.altitude.format("%d")];
}
} else {
return "N/S";
Expand Down

0 comments on commit 5914af0

Please sign in to comment.