chanes file read process form xhttp request to tizen api
- tizen 4.0 api usable, some calls depricated since 5.0 - update to 'openFile' only possible when killing 4.0
This commit is contained in:
73
js/app.js
73
js/app.js
@ -11,7 +11,7 @@
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var events;
|
||||
@ -26,47 +26,39 @@ var eventsTimeStamp = 0;
|
||||
watchRadius;
|
||||
|
||||
function readJSON(path) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', path, true);
|
||||
xhr.responseType = 'blob';
|
||||
xhr.onload = function(e) {
|
||||
if (this.status == 0) {
|
||||
var file = new File([this.response], 'temp');
|
||||
var fileReader = new FileReader();
|
||||
fileReader.addEventListener('load', function(){
|
||||
events = JSON.parse(fileReader.result);
|
||||
|
||||
var onError = function(e) {
|
||||
console.log('Error!' + e.message);
|
||||
};
|
||||
|
||||
var onResolveSuccess = function(dir) {
|
||||
var onListFilesSuccess = function(files) {
|
||||
files.forEach(function(file) {
|
||||
if (!file.isDirectory) {
|
||||
dir.deleteFile(file.fullPath, onDeleteSuccess, onError);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
dir.listFiles(onListFilesSuccess, onError);
|
||||
};
|
||||
|
||||
var onDeleteSuccess = function() {};
|
||||
|
||||
tizen.filesystem.resolve('/opt/usr/media/Downloads', onResolveSuccess, onError);
|
||||
|
||||
|
||||
|
||||
});
|
||||
fileReader.readAsText(file);
|
||||
}
|
||||
/* - requests permission to view media storage
|
||||
* - resolves the file 'calendarevents'
|
||||
* - opens stream and reads entire file as json
|
||||
*/
|
||||
|
||||
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 */
|
||||
dirfile.openStream("r", function(fs) {
|
||||
events = JSON.parse(fs.read(dirfile.fileSize));
|
||||
fs.close();
|
||||
})
|
||||
}
|
||||
|
||||
function onerror(e){
|
||||
console.log("error"+e);
|
||||
}
|
||||
xhr.send();
|
||||
|
||||
function onsuccessPermission(){
|
||||
tizen.filesystem.resolve("wgt-private", onsuccess, onerror, "rw");
|
||||
}
|
||||
|
||||
function onErrorPermission(e){
|
||||
console.log("error "+ JSON.stringify(e));
|
||||
}
|
||||
|
||||
tizen.ppm.requestPermission("http://tizen.org/privilege/mediastorage", onsuccessPermission, onErrorPermission);
|
||||
}
|
||||
|
||||
function getJSON() {
|
||||
var downloadRequest = new tizen.DownloadRequest('https://longitudecalendar.com/userinfo/107971745944668140075/calendarevents.json', 'downloads');
|
||||
var downloadRequest = new tizen.DownloadRequest('https://longitudecalendar.com/userinfo/107971745944668140075/calendarevents.json', 'wgt-private');
|
||||
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
|
||||
if (networkInfo.networkType === 'NONE') {
|
||||
console.log('Network connection is not available.Download is not possible.');
|
||||
@ -429,9 +421,7 @@ var eventsTimeStamp = 0;
|
||||
function updateCalendar(offset_ms) {
|
||||
var d = new Date();
|
||||
var currentTime = d.getTime();
|
||||
console.log("current Time: " + currentTime);
|
||||
if(eventsTimeStamp + offset_ms < currentTime){
|
||||
console.log("updating Events");
|
||||
getJSON();
|
||||
eventsTimeStamp = currentTime;
|
||||
}
|
||||
@ -482,6 +472,7 @@ var eventsTimeStamp = 0;
|
||||
* @private
|
||||
*/
|
||||
function init() {
|
||||
|
||||
setDefaultVariables();
|
||||
setDefaultEvents();
|
||||
|
||||
@ -492,7 +483,7 @@ var eventsTimeStamp = 0;
|
||||
// Update the content of the watch every second
|
||||
setInterval(function() {
|
||||
drawWatchContent();
|
||||
// updateCalendar(60000);
|
||||
updateCalendar(600000);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user