Using generic news feed events as notifications, instead of more implementation specific gestures from sensor

This commit is contained in:
Thomas Bachmann 2017-01-06 21:57:30 +01:00
parent 09531b399a
commit b8a72245dc

View File

@ -89,7 +89,7 @@ Module.register("newsfeed",{
if (this.newsItems.length > 0) { if (this.newsItems.length > 0) {
// this.config.showFullArticle is a run-time configuration, triggered by optional gestures // this.config.showFullArticle is a run-time configuration, triggered by optional notifications
if (!this.config.showFullArticle && (this.config.showSourceTitle || this.config.showPublishDate)) { if (!this.config.showFullArticle && (this.config.showSourceTitle || this.config.showPublishDate)) {
var sourceAndTimestamp = document.createElement("div"); var sourceAndTimestamp = document.createElement("div");
sourceAndTimestamp.className = "light small dimmed"; sourceAndTimestamp.className = "light small dimmed";
@ -289,74 +289,62 @@ Module.register("newsfeed",{
}, },
notificationReceived: function(notification, payload, sender) { notificationReceived: function(notification, payload, sender) {
Log.info(this.name + " - received event"); Log.info(this.name + " - received notification: " + notification);
if(notification == "GESTURE"){ if(notification == "ARTICLE_NEXT"){
Log.info(this.name + " - received gesture"); var before = this.activeItem;
var gesture = payload.gesture; this.activeItem++;
// actually RIGHT, because gesture sensor is built in upside down if (this.activeItem >= this.newsItems.length) {
if(gesture == "LEFT"){ this.activeItem = 0;
Log.info(this.name + " - received right");
var before = this.activeItem;
this.activeItem++;
if (this.activeItem >= this.newsItems.length) {
this.activeItem = 0;
}
this.config.showDescription = false;
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
Log.info(this.name + " - going from " + before + " to " + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100);
} }
// actually LEFT, because gesture sensor is built in upside down this.config.showDescription = false;
else if(gesture == "RIGHT"){ this.config.showFullArticle = false;
Log.info(this.name + " - received left"); if(!timer){
var before = this.activeItem; this.scheduleUpdateInterval();
this.activeItem--;
if (this.activeItem < 0) {
this.activeItem = this.newsItems.length - 1;
}
this.config.showDescription = false;
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
Log.info(this.name + " - going from " + before + " to " + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100);
} }
// actually UP, because gesture sensor is built in upside down Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
else if(gesture == "DOWN" && !this.config.showDescription){ this.updateDom(100);
Log.info(this.name + " - received up"); } else if(notification == "ARTICLE_PREVIOUS"){
this.config.showDescription = true; var before = this.activeItem;
this.config.showFullArticle = false; this.activeItem--;
clearInterval(timer); if (this.activeItem < 0) {
timer = null; this.activeItem = this.newsItems.length - 1;
this.updateDom(100);
} }
// actually DOWN, because gesture sensor is built in upside down this.config.showDescription = false;
else if(gesture == "UP"){ this.config.showFullArticle = false;
Log.info(this.name + " - received down"); if(!timer){
this.config.showDescription = false; this.scheduleUpdateInterval();
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
this.updateDom(100);
} }
// actually UP, because gesture sensor is built in upside down Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
else if(gesture == "DOWN" && this.config.showDescription){ this.updateDom(100);
Log.info(this.name + " - received up again"); }
this.config.showFullArticle = true; // received "more details" the first time, so showing article summary
this.config.showDescription = false; else if(notification == "ARTICLE_MORE_DETAILS" && !this.config.showDescription){
clearInterval(timer); this.config.showDescription = true;
timer = null; this.config.showFullArticle = false;
this.updateDom(100); clearInterval(timer);
} else { timer = null;
Log.info(this.name + " - received other: " + gesture); Log.info(this.name + " - showing article description");
this.updateDom(100);
} else if(notification == "ARTICLE_LESS_DETAILS"){
this.config.showDescription = false;
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
} }
Log.info(this.name + " - showing only article titles again");
this.updateDom(100);
}
// received "more details" a second time, so showing full article
else if(notification == "ARTICLE_MORE_DETAILS" && this.config.showDescription){
this.config.showFullArticle = true;
this.config.showDescription = false;
clearInterval(timer);
timer = null;
Log.info(this.name + " - showing full article");
this.updateDom(100);
} else {
Log.info(this.name + " - unknown notification, ignoring: " + notification);
} }
}, },
}); });