Skip to content

Commit

Permalink
show change date, de/en i18n, save button, code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Oct 29, 2020
1 parent b34e4f7 commit 8829146
Show file tree
Hide file tree
Showing 57 changed files with 433 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Thumbs.db
/app/android/dist
/app/android/java-sources.txt
/app/android/build.properties
/widget/android/local.properties
/widget/android/.idea
/app/ios/ti.animation.xcodeproj/project.xcworkspace/xcuserdata/*
.DS_Store
/app/ios/Cartfile.resolved
Expand Down
29 changes: 14 additions & 15 deletions app/app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var widgets = require("ti.widget");

$.index.open();

function onClickButton(e) {
function onClickUpdate(e) {
require("/widget").updateData();
}

Expand All @@ -13,20 +13,6 @@ var intent = Titanium.Android.createServiceIntent({
intent.putExtra('interval', MINUTES);
Titanium.Android.startService(intent);


function onChange() {
if ($.tf_town1.value != "") Ti.App.Properties.setString("town1", $.tf_town1.value);
if ($.tf_town2.value != "") Ti.App.Properties.setString("town2", $.tf_town2.value);

if ($.tf_lat1.value != "") Ti.App.Properties.setString("lat1", $.tf_lat1.value);
if ($.tf_lon1.value != "") Ti.App.Properties.setString("lon1", $.tf_lon1.value);

if ($.tf_lat2.value != "") Ti.App.Properties.setString("lat2", $.tf_lat2.value);
if ($.tf_lon2.value != "") Ti.App.Properties.setString("lon2", $.tf_lon2.value);

Ti.App.Properties.setString("icon", $.tf_icon.value);
}

function onOpen(e) {


Expand All @@ -52,3 +38,16 @@ function onOpen(e) {

require("/widget").updateData();
}

function onClickSave(e){
if ($.tf_town1.value != "") Ti.App.Properties.setString("town1", $.tf_town1.value);
if ($.tf_town2.value != "") Ti.App.Properties.setString("town2", $.tf_town2.value);

if ($.tf_lat1.value != "") Ti.App.Properties.setString("lat1", $.tf_lat1.value);
if ($.tf_lon1.value != "") Ti.App.Properties.setString("lon1", $.tf_lon1.value);

if ($.tf_lat2.value != "") Ti.App.Properties.setString("lat2", $.tf_lat2.value);
if ($.tf_lon2.value != "") Ti.App.Properties.setString("lon2", $.tf_lon2.value);

Ti.App.Properties.setString("icon", $.tf_icon.value);
}
8 changes: 8 additions & 0 deletions app/app/i18n/de/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="save">Speichern</string>
<string name="update">man. Update</string>
<string name="title1">Titel der ersten Box</string>
<string name="title2">Titel der zweiten Box</string>
<string name="intro">Die App ruft die Landkreisdaten der RKI Schnittstelle ab.</string>
</resources>
8 changes: 8 additions & 0 deletions app/app/i18n/en/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="save">save</string>
<string name="update">force update</string>
<string name="title1">Title of the first box</string>
<string name="title2">Title of the second box</string>
<string name="intro">The app is fetching the distric data of the RKI API.</string>
</resources>
94 changes: 50 additions & 44 deletions app/app/lib/widget.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,72 @@
var widgets = require("ti.widget");
var moment = require("alloy/moment");

var t = Ti.App.Properties.getObject("widgetData", {
var widgetData = Ti.App.Properties.getObject("widgetData", {
value1: "-",
value2: "-"
})

var dataValue1 = t.value1;
var dataValue2 = t.value2;
// get previous values
var town1 = Ti.App.Properties.getString("town1", "-");
var town2 = Ti.App.Properties.getString("town2", "-");
var icon = Ti.App.Properties.getString("icon", "🦠");


function currentDateTime() {
return moment().format('DD.MM., HH:mm');
}

function downloadData(data) {

var lon = data.lon;
var lat = data.lat;
var dTarget = data.target;

const outputFields = 'GEN,RS,EWZ,EWZ_BL,BL_ID,cases,cases_per_100k,cases7_per_100k,cases7_bl_per_100k,last_update,BL';
const locationUrl = "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=" + outputFields + "&geometry=" + lon + "%2C" + lat + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json"

var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
var json = JSON.parse(this.responseText);
if (json.features && json.features.length > 0) {
if (dTarget == 1) {
widgetData.town1 = town1;
widgetData.value1 = icon + parseFloat(json.features[0].attributes.cases7_per_100k).toFixed(1);
widgetData.updateTime1 = "Stand: " + json.features[0].attributes.last_update;
} else {
widgetData.town2 = town2;
widgetData.value2 = icon + parseFloat(json.features[0].attributes.cases7_per_100k).toFixed(1);
widgetData.updateTime2 = "Stand: " + json.features[0].attributes.last_update;
}
Ti.App.Properties.setObject("widgetData", widgetData)
}

widgets.updateWidgets();
},
onerror: function(e) {},
timeout: 5000
});
xhr.open('GET', locationUrl);
xhr.send();
}

function getData() {

if (Ti.Network.online) {
town1 = Ti.App.Properties.getString("town1", "-");
town2 = Ti.App.Properties.getString("town2", "-");
icon = Ti.App.Properties.getString("icon", "🦠");

var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
var json = JSON.parse(this.responseText);
if (json.features && json.features.length > 0) dataValue1 = parseFloat(json.features[0].attributes.cases7_per_100k).toFixed(1);

Ti.App.Properties.setObject("widgetData", {
town1: town1,
town2: town2,
value1: icon + dataValue1,
value2: icon + dataValue2
})
widgets.updateWidgets();
},
onerror: function(e) {},
timeout: 5000 // milliseconds
downloadData({
lon: Ti.App.Properties.getString("lon1", "13.404954"),
lat: Ti.App.Properties.getString("lat1", "52.520008"),
target: 1
});
var lat1 = Ti.App.Properties.getString("lat1", "52.520008");
var lon1 = Ti.App.Properties.getString("lon1", "13.404954");
xhr.open('GET', "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k&geometry=" + lon1 + "%2C" + lat1 + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json");
xhr.send();

// second data source
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
var json = JSON.parse(this.responseText);
if (json.features && json.features.length > 0) dataValue2 = parseFloat(json.features[0].attributes.cases7_per_100k).toFixed(1);

Ti.App.Properties.setObject("widgetData", {
town1: town1,
town2: town2,
value1: icon + dataValue1,
value2: icon + dataValue2
})
widgets.updateWidgets();
},
onerror: function(e) {},
timeout: 5000
downloadData({
lon: Ti.App.Properties.getString("lon2", "13.404954"),
lat: Ti.App.Properties.getString("lat2", "52.520008"),
target: 2
});

lat1 = Ti.App.Properties.getString("lat2", "48.135124");
lon1 = Ti.App.Properties.getString("lon2", "11.581981");
xhr.open('GET', "https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=GEN,cases7_per_100k&geometry=" + lon1 + "%2C" + lat1 + "&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json");
xhr.send();
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/app/styles/app.tss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"TextField" : {
width: 200,
width: Ti.UI.FILL,
bottom: 10,
borderColor: "text",
borderWidth: 1,
Expand All @@ -10,8 +10,8 @@
fontSize: 14
}
}
'Label' : {
color: 'text',
"Label" : {
color: "text",
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
left: 0,
Expand Down
44 changes: 41 additions & 3 deletions app/app/styles/index.tss
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
"Window" : {
backgroundColor: "windowBackgroundColor",
exitOnClose: false
exitOnClose: false,
layout: "vertical"
}
".content" : {
width: 200,
layout: 'vertical',
width: 260,
layout: "vertical",
height: Ti.UI.SIZE,
top: 20
}
"#view_button_row" : {
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
layout: "horizontal",
top: 10
}
"#btn_save" : {
right: 10
}
".coords" : {
width: Ti.UI.FILL,
height: Ti.UI.SIZE,
layout: "horizontal"
}
".box" : {
width: 120,
height: Ti.UI.SIZE,
layout: "vertical"
}
".box_left" : {
right: 20
}
"#tf_icon" : {
width: 70
}
"#lbl_intro" : {
left: 10,
right: 10,
width: Ti.UI.FILL,
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER
}

"#lbl_virus": {
top: 30,
width: Ti.UI.FILL,
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER
}
47 changes: 32 additions & 15 deletions app/app/views/index.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
<Alloy>
<Window onOpen="onOpen">
<Label textid="intro" id="lbl_intro"/>

<ScrollView class="content">
<Label text="Town 1"/>
<TextField id="tf_town1" onChange="onChange"/>
<Label text="Lat"/>
<TextField id="tf_lat1" onChange="onChange"/>
<Label text="Lon"/>
<TextField id="tf_lon1" onChange="onChange"/>
<Label textid="title1"/>
<TextField id="tf_town1"/>

<Label text="Town 2" top="30"/>
<TextField id="tf_town2" onChange="onChange"/>
<Label text="Lat"/>
<TextField id="tf_lat2" onChange="onChange"/>
<Label text="Lon"/>
<TextField id="tf_lon2" onChange="onChange"/>
<View class="coords">
<View class="box box_left">
<Label text="Lat"/>
<TextField id="tf_lat1"/>
</View>
<View class="box">
<Label text="Lon"/>
<TextField id="tf_lon1"/>
</View>
</View>

<Label text="Virus icon" top="30"/>
<TextField id="tf_icon" onChange="onChange"/>
<Label textid="title2" top="30"/>
<TextField id="tf_town2"/>
<View class="coords">
<View class="box box_left">
<Label text="Lat"/>
<TextField id="tf_lat2"/>
</View>
<View class="box">
<Label text="Lon"/>
<TextField id="tf_lon2"/>
</View>
</View>
<Label text="Virus icon" id="lbl_virus"/>
<TextField id="tf_icon"/>

<Button title="Force Update" onClick="onClickButton"></Button>
<View id="view_button_row">
<Button id="btn_save" titleid="save" onClick="onClickSave"></Button>
<Button id="btn_force" titleid="update" onClick="onClickUpdate"></Button>
</View>
</ScrollView>
</Window>
</Alloy>
1 change: 1 addition & 0 deletions app/modules/android/ti.widget/1.0.2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: place your license here and we'll include it in the module distribution
39 changes: 39 additions & 0 deletions app/modules/android/ti.widget/1.0.2/documentation/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<h1>ti.widget Module</h1>

<h2>Description</h2>

<p>TODO: Enter your module description here</p>

<h2>Accessing the ti.widget Module</h2>

<p>To access this module from JavaScript, you would do the following:</p>

<pre><code>var ti_widget = require(&quot;ti.widget&quot;);</code></pre>

<p>The ti_widget variable is a reference to the Module object.</p>

<h2>Reference</h2>

<p>TODO: If your module has an API, you should document
the reference here.</p>

<h3>ti_widget.function</h3>

<p>TODO: This is an example of a module function.</p>

<h3>ti_widget.property</h3>

<p>TODO: This is an example of a module property.</p>

<h2>Usage</h2>

<p>TODO: Enter your usage example here</p>

<h2>Author</h2>

<p>TODO: Enter your author name, email and other contact
details you want to share here.</p>

<h2>License</h2>

<p>TODO: Enter your license/legal information here.</p>
Loading

0 comments on commit 8829146

Please sign in to comment.