diff --git a/js/App.js b/js/App.js index c874b84..37fb558 100644 --- a/js/App.js +++ b/js/App.js @@ -7,6 +7,13 @@ function App() { if(!color) color = "red"; this.setColor(color); this.fontChange(); + + var numArticles = localStorage.numArticles; + if(!numArticles) numArticles = 50; + this.numArticles(numArticles); + var maxDownload = localStorage.maxDownload; + if(!maxDownload) maxDownload = 500000; + this.maxDownload(maxDownload); }; App.prototype.authenticate = function() { @@ -99,6 +106,14 @@ App.prototype.after_login = function(backend) { } else { this.backend = new TinyTinyRSS(this, localStorage.server_url, localStorage.session_id); } + + var numArticles = localStorage.numArticles; + if(!numArticles) numArticles = 50; + this.numArticles(numArticles); + var maxDownload = localStorage.maxDownload; + if(!maxDownload) maxDownload = 500000; + this.maxDownload(maxDownload); + this.reload(); }; @@ -137,7 +152,8 @@ App.prototype.setColor = function(color) { App.prototype.reload = function() { this.unread_articles = []; $("#all-read").innerHTML = "❌"; - this.backend.reload(this.gotUnreadFeeds.bind(this)); + var number=parseInt(localStorage.numArticles); + this.backend.reload(this.gotUnreadFeeds.bind(this),number); }; App.prototype.gotUnreadFeeds = function(new_articles) { @@ -155,11 +171,25 @@ App.prototype.gotUnreadFeeds = function(new_articles) { this.unread_articles = this.unread_articles.concat(new_articles); if(new_articles.length > 0) { - this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles); - } else { - localStorage.unread_articles = JSON.stringify(this.unread_articles); + try { + //To check if when it fails it is the same + localStorage.unread_articles = JSON.stringify(this.unread_articles); + //alert("Size probando:"+probando.length) + var size = parseInt(localStorage.maxDownload); + if(localStorage.unread_articles.length < size) { + var num = parseInt(localStorage.numArticles); + this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles,num); + } else { + alert("Limit size reached: Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length +" bytes"); + } + } + catch (e) { + alert("Reached maximum memory by app" + e.name + " " +e.message +". We will keep working in anycase with:" + localStorage.unread_articles.length); + } this.populateList(); - } + } else { + alert("Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length + " bytes"); + } } }; @@ -445,5 +475,22 @@ App.prototype.fontChange = function(size) { document.body.addClass("f" + i); } - +}; + +App.prototype.numArticles= function(askfor) { + if(askfor < 200 && askfor > 0) { + localStorage.numArticles=askfor; + } + else { + localStorage.numArticles=100; + } +}; + +App.prototype.maxDownload= function(maxdata) { + if(maxdata < 5000000 && maxdata > 100000) { + localStorage.maxDownload=maxdata; + } + else { + localStorage.maxDownload=500000; + } }; diff --git a/js/OwnCloud.js b/js/OwnCloud.js index 15776f1..25519eb 100644 --- a/js/OwnCloud.js +++ b/js/OwnCloud.js @@ -65,18 +65,18 @@ OwnCloud.prototype.doOperation = function(method, operation, new_options, callba xhr.send(body); } -OwnCloud.prototype.reload = function(callback) { +OwnCloud.prototype.reload = function(callback,limit) { var _this = this; - this.getFeeds(function() { _this.getUnreadFeeds(callback); }); + this.getFeeds(function() { _this.getUnreadFeeds(callback,0,limit); }); }; -OwnCloud.prototype.getUnreadFeeds = function(callback, skip) { +OwnCloud.prototype.getUnreadFeeds = function(callback, skip, limit) { if(skip) { skip = skip[skip.length - 1].id; } var options = { - batchSize: 700, + batchSize: limit || 700, offset: skip || 0, type: 3, id: 0, diff --git a/js/Pond.js b/js/Pond.js index 501494c..47cc5a5 100644 --- a/js/Pond.js +++ b/js/Pond.js @@ -69,15 +69,15 @@ Pond.prototype.doOperation = function(method, operation, new_options, callback) }; -Pond.prototype.reload = function(callback) { +Pond.prototype.reload = function(callback,limit) { var _this = this; - this.getFeeds(function() { _this.getUnreadFeeds(callback); }); + this.getFeeds(function() { _this.getUnreadFeeds(callback,0,limit); }); }; -Pond.prototype.getUnreadFeeds = function(callback, skip) { +Pond.prototype.getUnreadFeeds = function(callback, skip, limit) { var options = { status: "unread", - limit: 100 + limit: limit || 100 }; if(skip && skip.length > 0) { @@ -222,4 +222,4 @@ Pond.login = function(server_url, user, password, callback) { xhr.setRequestHeader("Content-Length", options.length); xhr.setRequestHeader("Connection", "close"); xhr.send(options); -} \ No newline at end of file +} diff --git a/js/TinyTinyRSS.js b/js/TinyTinyRSS.js index 4479f49..1fd2813 100644 --- a/js/TinyTinyRSS.js +++ b/js/TinyTinyRSS.js @@ -54,17 +54,18 @@ TinyTinyRSS.prototype.doOperation = function(operation, new_options, callback) { xhr.send(JSON.stringify(options)); } -TinyTinyRSS.prototype.reload = function(callback) { - this.getUnreadFeeds(callback, []); +TinyTinyRSS.prototype.reload = function(callback,limit) { + this.getUnreadFeeds(callback, 0, limit); }; -TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip) { +TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip, limit) { skip = skip.length; var options = { show_excerpt: false, view_mode: "unread", show_content: true, feed_id: -4, + limit: limit || 0, skip: skip || 0 }; diff --git a/manifest.webapp b/manifest.webapp index 2149404..c4926f4 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -19,5 +19,5 @@ } }, "installs_allowed_from": ["*"], - "version": "0.3.0" -} \ No newline at end of file + "version": "0.3.0_iss30" +}