Skip to content

Commit

Permalink
feat(): choose if you want to show UI or not and add actions with the…
Browse files Browse the repository at this point in the history
… text at the end of the request.
  • Loading branch information
Caul58 committed Oct 13, 2018
1 parent cc2bc13 commit 3ee1f05
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
6 changes: 5 additions & 1 deletion BarrioPilarMetroTimming.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ let fmLocal = FileManager.local();

eval(fmLocal.readString(libraryPath));

metroTiming("902");
let completionCallback = function(text){
Speech.speak(text)
}

metroTiming("902", false, completionCallback);
6 changes: 5 additions & 1 deletion PuertaArgandaMetroTimming.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ let fmLocal = FileManager.local();

eval(fmLocal.readString(libraryPath));

metroTiming("922");
let completionCallback = function(text){
Speech.speak(text)
}

metroTiming("922", false, completionCallback);
65 changes: 38 additions & 27 deletions libs/TransportTiming.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: red; icon-glyph: bus-alt; share-sheet-inputs: plain-text;
var metroTiming = function (station) {
var metroTiming = async function (station, presentUI, callback) {

let req = new Request("https://serviciosapp.metromadrid.es/servicios/rest/teleindicadores/" + station + "?")
let promiseResponse = req.loadJSON()
promiseResponse.then(json => {

let array = json["Vtelindicadores"]
let table = new UITable()

for (item of array) {

let row = new UITableRow()
let title = item["nombreest"] + " sentido " + item["sentido"]
let subtitle = ""
if (item["proximo"]["@nil"] == "true") {
subtitle = "1 -> " + item["siguiente"] + " minutos"
} else if (item["siguiente"]["@nil"] == "true") {
subtitle = "1 -> " + item["proximo"] + " minutos"
} else {
subtitle = "1 -> " + item["proximo"] + " minutos, 2 -> " + item["siguiente"] + " minutos"
}

let titleCell = row.addText(title, subtitle)
titleCell.widthWeight = 80

row.height = 60
row.cellSpacing = 10
table.addRow(row)
let json = await req.loadJSON()

let array = json["Vtelindicadores"]
let table = new UITable()
let speaksText = ""

for (item of array) {

let row = new UITableRow()
let title = item["nombreest"] + " sentido " + item["sentido"]
speaksText = speaksText + "Tren desde " + item["nombreest"] + " sentido " + item["sentido"] + ". "
let subtitle = ""
if (item["proximo"]["@nil"] == "true") {
subtitle = "1 -> " + item["siguiente"] + " minutos"
speaksText = speaksText + "El primero pasará en " + item["siguiente"] + " minutos. "
} else if (item["siguiente"]["@nil"] == "true") {
subtitle = "1 -> " + item["proximo"] + " minutos"
speaksText = speaksText + "El primero pasará en " + item["proximo"] + " minutos. "
} else {
subtitle = "1 -> " + item["proximo"] + " minutos, 2 -> " + item["siguiente"] + " minutos"
speaksText = speaksText + "El primero pasará en " + item["proximo"] + " minutos y el segundo en " + item["siguiente"] + " minutos. "
}

let titleCell = row.addText(title, subtitle)
titleCell.widthWeight = 80

row.height = 60
row.cellSpacing = 10
table.addRow(row)

}

if (presentUI) {
QuickLook.present(table)
})
}

callback(speaksText)

};

0 comments on commit 3ee1f05

Please sign in to comment.