Skip to content

Commit

Permalink
Ability to add custom text
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanDam committed Jun 6, 2020
1 parent 6a123d5 commit e27f852
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
4 changes: 4 additions & 0 deletions resources/settings/properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
<property id="barometer_unit" type="number">0</property>

<property id="openweathermap_api" type="string"></property>

<property id="ctext_input" type="string"></property>


</properties>
5 changes: 5 additions & 0 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
<listEntry value="21">@Strings.countdown</listEntry>
<listEntry value="25">@Strings.weather</listEntry>
<listEntry value="26">@Strings.ampm</listEntry>
<listEntry value="27">@Strings.ctext</listEntry>
</settingConfig>
</setting>
<setting propertyKey="@Properties.compbarb" title="@Strings.compbarb">
Expand Down Expand Up @@ -327,6 +328,7 @@
<listEntry value="21">@Strings.countdown</listEntry>
<listEntry value="25">@Strings.weather</listEntry>
<listEntry value="26">@Strings.ampm</listEntry>
<listEntry value="27">@Strings.ctext</listEntry>
</settingConfig>
</setting>

Expand Down Expand Up @@ -422,4 +424,7 @@
<setting propertyKey="@Properties.openweathermap_api" title="@Strings.openweathermap_api">
<settingConfig type="alphaNumeric" />
</setting>
<setting propertyKey="@Properties.ctext_input" title="@Strings.ctext">
<settingConfig type="alphaNumeric" />
</setting>
</settings>
1 change: 1 addition & 0 deletions resources/strings/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<string id="weeknum">Week of year</string>
<string id="weather">Weather</string>
<string id="ampm">AM/PM indicator</string>
<string id="ctext">Custom text</string>

<string id="date_format">Date format</string>
<string id="datef1">ddd d (TUE 2)</string>
Expand Down
3 changes: 1 addition & 2 deletions source/BackgroundService.mc
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ class BackgroundService extends Sys.ServiceDelegate {
(:background_method)
function onTemporalEvent() {
Sys.println("onTemporalEvent");

var pendingWebRequests = App.getApp().getProperty("PendingWebRequests");
if (pendingWebRequests != null) {
if (pendingWebRequests["OpenWeatherMapCurrent"] != null) {

var api_key = App.getApp().getProperty("openweathermap_api");
if (api_key.length() == 0) {
api_key = "333d6a4283794b870f5c717cc48890b5"; // default apikey
}
Sys.println("Key " + api_key);
makeWebRequest(
"https://api.openweathermap.org/data/2.5/weather",
{
Expand Down
24 changes: 23 additions & 1 deletion source/datafield/DataFactory.mc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ enum /* FIELD_TYPES */ {
FIELD_TYPE_TEMPERATURE_HL,
FIELD_TYPE_WEATHER,

FIELD_TYPE_AMPM_INDICATOR = 26
FIELD_TYPE_AMPM_INDICATOR = 26,
FIELD_TYPE_CTEXT_INDICATOR
}

function buildFieldObject(type) {
Expand Down Expand Up @@ -99,6 +100,8 @@ function buildFieldObject(type) {
return new WeatherField(FIELD_TYPE_WEATHER);
} else if (type==FIELD_TYPE_AMPM_INDICATOR) {
return new AMPMField(FIELD_TYPE_AMPM_INDICATOR);
} else if (type==FIELD_TYPE_CTEXT_INDICATOR) {
return new CTextField(FIELD_TYPE_CTEXT_INDICATOR);
}

return new EmptyDataField(FIELD_TYPE_EMPTY);
Expand Down Expand Up @@ -170,6 +173,25 @@ class EmptyDataField {
}
}

///////////////////////
// custom text stage //
///////////////////////

class CTextField extends BaseDataField {

function initialize(id) {
BaseDataField.initialize(id);
}

function cur_label(value) {
var custom_text = App.getApp().getProperty("ctext_input");
if (custom_text.length() == 0) {
return "--";
}
return custom_text;
}
}

///////////////////
// weather stage //
///////////////////
Expand Down

0 comments on commit e27f852

Please sign in to comment.