Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Radko Najman committed Oct 11, 2022
1 parent 96e10a7 commit 8292202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.19">
<iq:application entry="SmartArcsApp" id="2eafd80f81794ced90db35ccfcb29945" launcherIcon="@Drawables.LauncherIcon" minSdkVersion="3.0.0" name="@Strings.AppName" type="watchface" version="1.7.20">
<iq:products>
<iq:product id="approachs62"/>
<iq:product id="d2air"/>
Expand Down
25 changes: 14 additions & 11 deletions source/SmartArcsView.mc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class SmartArcsView extends WatchUi.WatchFace {
var sunsetEndAngle = 0;
var locationLatitude;
var locationLongitude;
var dateInfo;

//user settings
var bgColor;
Expand Down Expand Up @@ -168,6 +169,8 @@ class SmartArcsView extends WatchUi.WatchFace {
//recompute sunrise/sunset constants every hour - to address new location when traveling
if (clockTime.min == 0) {
computeSunConstants();
//not needed to get date on every refresh event
dateInfo = Gregorian.info(Time.today(), Time.FORMAT_MEDIUM);
}

//we always want to refresh the full screen when we get a regular onUpdate call.
Expand Down Expand Up @@ -243,11 +246,11 @@ class SmartArcsView extends WatchUi.WatchFace {
}

if (eventColor != offSettingFlag) {
if (clockTime.hour == 0 && clockTime.min == 0) {
if (clockTime.hour == 0 && clockTime.min == 0) {
//compute days to event
var eventDateMoment = new Time.Moment(eventDate);
daysToEvent = (eventDateMoment.value() - Time.today().value()) / Gregorian.SECONDS_PER_DAY.toFloat();
}
}
if (daysToEvent < 0) {
//hide event when it is over
eventColor = offSettingFlag;
Expand All @@ -262,7 +265,7 @@ class SmartArcsView extends WatchUi.WatchFace {
}

if (dateColor != offSettingFlag) {
drawDate(targetDc, Time.today());
drawDate(targetDc);
}

if (handsOnTop) {
Expand Down Expand Up @@ -486,6 +489,8 @@ class SmartArcsView extends WatchUi.WatchFace {
}
}

dateInfo = Gregorian.info(Time.today(), Time.FORMAT_MEDIUM);

computeSunConstants();

//constants pre-computed, doesn't need to be computed again
Expand Down Expand Up @@ -882,20 +887,18 @@ class SmartArcsView extends WatchUi.WatchFace {
}
}

function drawDate(dc, today) {
var info = Gregorian.info(today, Time.FORMAT_MEDIUM);

function drawDate(dc) {
var dateString;
switch (dateFormat) {
case 0: dateString = info.day;
case 0: dateString = dateInfo.day;
break;
case 1: dateString = Lang.format("$1$ $2$", [info.day_of_week.substring(0, 3), info.day]);
case 1: dateString = Lang.format("$1$ $2$", [dateInfo.day_of_week.substring(0, 3), dateInfo.day]);
break;
case 2: dateString = Lang.format("$1$ $2$", [info.day, info.day_of_week.substring(0, 3)]);
case 2: dateString = Lang.format("$1$ $2$", [dateInfo.day, dateInfo.day_of_week.substring(0, 3)]);
break;
case 3: dateString = Lang.format("$1$ $2$", [info.day, info.month.substring(0, 3)]);
case 3: dateString = Lang.format("$1$ $2$", [dateInfo.day, dateInfo.month.substring(0, 3)]);
break;
case 4: dateString = Lang.format("$1$ $2$", [info.month.substring(0, 3), info.day]);
case 4: dateString = Lang.format("$1$ $2$", [dateInfo.month.substring(0, 3), dateInfo.day]);
break;
}
dc.setColor(dateColor, Graphics.COLOR_TRANSPARENT);
Expand Down

0 comments on commit 8292202

Please sign in to comment.