moves json readout to seperate function with callback
- adds function to get device fingerprint - adds readJsonFromFile function with file name in 'wgt-private' and callback function
This commit is contained in:
57
js/app.js
57
js/app.js
@ -14,7 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var events;
|
||||
var events = null;
|
||||
var deviceId = null;
|
||||
var eventsTimeStamp = 0;
|
||||
|
||||
(function() {
|
||||
@ -24,22 +25,25 @@ var eventsTimeStamp = 0;
|
||||
ctxContent,
|
||||
center,
|
||||
watchRadius;
|
||||
|
||||
|
||||
function readJSON(path) {
|
||||
/* - requests permission to view media storage
|
||||
* - resolves the file 'calendarevents'
|
||||
* - opens stream and reads entire file as json
|
||||
*/
|
||||
function getJsonFile(name, callback) {
|
||||
|
||||
/* successful resolution of wgt-private */
|
||||
function onsuccess(dir){
|
||||
var dirfile = dir.resolve("calendarevents");
|
||||
console.log(dirfile);
|
||||
|
||||
/* for tizen 4.0, should work on 5.5 aswell but tizen 5.5 uses 'openFile' for Filereading */
|
||||
var dirfile = null;
|
||||
try {
|
||||
dirfile = dir.resolve(name);
|
||||
} catch (exc) {
|
||||
console.log(exc.message)
|
||||
}
|
||||
|
||||
if(dirfile == null)
|
||||
return null;
|
||||
dirfile.openStream("r", function(fs) {
|
||||
events = JSON.parse(fs.read(dirfile.fileSize));
|
||||
fs.close();
|
||||
})
|
||||
callback(JSON.parse(fs.read(dirfile.fileSize)));
|
||||
fs.close();
|
||||
});
|
||||
}
|
||||
|
||||
function onerror(e){
|
||||
@ -56,8 +60,34 @@ var eventsTimeStamp = 0;
|
||||
|
||||
tizen.ppm.requestPermission("http://tizen.org/privilege/mediastorage", onsuccessPermission, onErrorPermission);
|
||||
}
|
||||
|
||||
function readJSON(path) {
|
||||
/* - requests permission to view media storage
|
||||
* - resolves the file 'calendarevents'
|
||||
* - opens stream and reads entire file as json
|
||||
*/
|
||||
|
||||
getJsonFile("calendarevents", function(eventlist) {events = eventlist;});
|
||||
console.log(events);
|
||||
}
|
||||
|
||||
function getDeviceID() {
|
||||
// check if device id set already as global, if it is return
|
||||
if(deviceId != null)
|
||||
return;
|
||||
|
||||
// otherwise, check if there is a devicefingerprint file in wft-private
|
||||
getJsonFile("devicefingerprint", function(df) {deviceId = df;})
|
||||
// if there is, open it up and get your device ID from it
|
||||
|
||||
// otherwise, ask the longitude server for a device fingerprint file
|
||||
}
|
||||
|
||||
function getJSON() {
|
||||
|
||||
/*if(deviceId == null)
|
||||
return;
|
||||
*/
|
||||
var downloadRequest = new tizen.DownloadRequest('https://longitudecalendar.com/userinfo/107971745944668140075/calendarevents.json', 'wgt-private');
|
||||
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
|
||||
if (networkInfo.networkType === 'NONE') {
|
||||
@ -360,6 +390,7 @@ var eventsTimeStamp = 0;
|
||||
// Draw the text for date
|
||||
// renderText(ctxContent, date, center.x, center.y + (watchRadius * 0.5), 25, "#999999");
|
||||
|
||||
console.log(events);
|
||||
if(events == null)
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user