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,13 +289,8 @@ 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 gesture = payload.gesture;
// actually RIGHT, because gesture sensor is built in upside down
if(gesture == "LEFT"){
Log.info(this.name + " - received right");
var before = this.activeItem; var before = this.activeItem;
this.activeItem++; this.activeItem++;
if (this.activeItem >= this.newsItems.length) { if (this.activeItem >= this.newsItems.length) {
@ -306,12 +301,9 @@ Module.register("newsfeed",{
if(!timer){ if(!timer){
this.scheduleUpdateInterval(); this.scheduleUpdateInterval();
} }
Log.info(this.name + " - going from " + before + " to " + this.activeItem + " (of " + this.newsItems.length + ")"); Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100); this.updateDom(100);
} } else if(notification == "ARTICLE_PREVIOUS"){
// actually LEFT, because gesture sensor is built in upside down
else if(gesture == "RIGHT"){
Log.info(this.name + " - received left");
var before = this.activeItem; var before = this.activeItem;
this.activeItem--; this.activeItem--;
if (this.activeItem < 0) { if (this.activeItem < 0) {
@ -322,41 +314,37 @@ Module.register("newsfeed",{
if(!timer){ if(!timer){
this.scheduleUpdateInterval(); this.scheduleUpdateInterval();
} }
Log.info(this.name + " - going from " + before + " to " + this.activeItem + " (of " + this.newsItems.length + ")"); Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100); this.updateDom(100);
} }
// actually UP, because gesture sensor is built in upside down // received "more details" the first time, so showing article summary
else if(gesture == "DOWN" && !this.config.showDescription){ else if(notification == "ARTICLE_MORE_DETAILS" && !this.config.showDescription){
Log.info(this.name + " - received up");
this.config.showDescription = true; this.config.showDescription = true;
this.config.showFullArticle = false; this.config.showFullArticle = false;
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
Log.info(this.name + " - showing article description");
this.updateDom(100); this.updateDom(100);
} } else if(notification == "ARTICLE_LESS_DETAILS"){
// actually DOWN, because gesture sensor is built in upside down
else if(gesture == "UP"){
Log.info(this.name + " - received down");
this.config.showDescription = false; this.config.showDescription = false;
this.config.showFullArticle = false; this.config.showFullArticle = false;
if(!timer){ if(!timer){
this.scheduleUpdateInterval(); this.scheduleUpdateInterval();
} }
Log.info(this.name + " - showing only article titles again");
this.updateDom(100); this.updateDom(100);
} }
// actually UP, because gesture sensor is built in upside down // received "more details" a second time, so showing full article
else if(gesture == "DOWN" && this.config.showDescription){ else if(notification == "ARTICLE_MORE_DETAILS" && this.config.showDescription){
Log.info(this.name + " - received up again");
this.config.showFullArticle = true; this.config.showFullArticle = true;
this.config.showDescription = false; this.config.showDescription = false;
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
Log.info(this.name + " - showing full article");
this.updateDom(100); this.updateDom(100);
} else { } else {
Log.info(this.name + " - received other: " + gesture); Log.info(this.name + " - unknown notification, ignoring: " + notification);
}
} }
}, },
}); });