Optimize message display
This commit is contained in:
parent
87f93e10d1
commit
a8e2c2e990
|
@ -18,6 +18,8 @@ require("messages").pushMessage({"t":"add","id":1575479849,"src":"Clock","title"
|
||||||
require("messages").pushMessage({"t":"add","id":1,"src":"Maps","title":"0 yd - High St","body":"Campton - 11:48 ETA","img":"GhqBAAAMAAAHgAAD8AAB/gAA/8AAf/gAP/8AH//gD/98B//Pg/4B8f8Afv+PP//n3/f5//j+f/wfn/4D5/8Aef+AD//AAf/gAD/wAAf4AAD8AAAeAAADAAA="});
|
require("messages").pushMessage({"t":"add","id":1,"src":"Maps","title":"0 yd - High St","body":"Campton - 11:48 ETA","img":"GhqBAAAMAAAHgAAD8AAB/gAA/8AAf/gAP/8AH//gD/98B//Pg/4B8f8Afv+PP//n3/f5//j+f/wfn/4D5/8Aef+AD//AAf/gAD/wAAf4AAD8AAAeAAADAAA="});
|
||||||
// call
|
// call
|
||||||
require("messages").pushMessage({"t":"add","id":"call","src":"Phone","title":"Bob","body":"12421312",positive:true,negative:true})
|
require("messages").pushMessage({"t":"add","id":"call","src":"Phone","title":"Bob","body":"12421312",positive:true,negative:true})
|
||||||
|
// message
|
||||||
|
require("messages").pushMessage({"t":"add","id":"1234","src":"Telegram","title":"testing","body":"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.",positive:true,negative:true})
|
||||||
*/
|
*/
|
||||||
var Layout = require("Layout");
|
var Layout = require("Layout");
|
||||||
var settings = require('Storage').readJSON("messages.settings.json", true) || {};
|
var settings = require('Storage').readJSON("messages.settings.json", true) || {};
|
||||||
|
@ -190,13 +192,14 @@ function showMusicMessage(msg) {
|
||||||
|
|
||||||
function showMessageScroller(msg) {
|
function showMessageScroller(msg) {
|
||||||
active = "scroller";
|
active = "scroller";
|
||||||
var bodyFont = fontBig;
|
var bodyFont = fontLarge;
|
||||||
g.setFont(bodyFont);
|
g.setFont(bodyFont);
|
||||||
var lines = [];
|
var lines = [];
|
||||||
if (msg.title) lines = g.wrapString(msg.title, g.getWidth()-10)
|
if (msg.title) lines = g.wrapString(msg.title, g.getWidth()-10)
|
||||||
|
lines = [lines[0]];
|
||||||
var titleCnt = lines.length;
|
var titleCnt = lines.length;
|
||||||
if (titleCnt) lines.push(""); // add blank line after title
|
//if (titleCnt) lines.push(""); // add blank line after title
|
||||||
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10),["",/*LANG*/"< Back"]);
|
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10)); //,["",/*LANG*/"< Back"]);
|
||||||
E.showScroller({
|
E.showScroller({
|
||||||
h : g.getFontHeight(), // height of each menu item in pixels
|
h : g.getFontHeight(), // height of each menu item in pixels
|
||||||
c : lines.length, // number of menu items
|
c : lines.length, // number of menu items
|
||||||
|
@ -207,11 +210,13 @@ function showMessageScroller(msg) {
|
||||||
setColor(idx<titleCnt ? g.theme.fg2 : g.theme.fg).
|
setColor(idx<titleCnt ? g.theme.fg2 : g.theme.fg).
|
||||||
clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
|
clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
|
||||||
g.setFont(bodyFont).drawString(lines[idx], r.x, r.y);
|
g.setFont(bodyFont).drawString(lines[idx], r.x, r.y);
|
||||||
}, select : function(idx) {
|
//}, select : function(idx) {
|
||||||
if (idx>=lines.length-2)
|
// if (idx>=lines.length-2)
|
||||||
showMessage(msg.id);
|
// showMessage(msg.id);
|
||||||
},
|
//},
|
||||||
back : () => showMessage(msg.id)
|
//back : () => showMessage(msg.id)
|
||||||
|
}, select : () => load(),
|
||||||
|
back : () => load()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,90 +267,92 @@ function showMessage(msgid) {
|
||||||
}
|
}
|
||||||
active = "message";
|
active = "message";
|
||||||
// Normal text message display
|
// Normal text message display
|
||||||
var title=msg.title, titleFont = fontLarge, lines;
|
//var title=msg.title, titleFont = fontLarge, lines;
|
||||||
var body=msg.body, bodyFont = fontLarge;
|
//var body=msg.body, bodyFont = fontLarge;
|
||||||
// If no body, use the title text instead...
|
//// If no body, use the title text instead...
|
||||||
if (body===undefined) {
|
//if (body===undefined) {
|
||||||
body = title;
|
// body = title;
|
||||||
title = undefined;
|
// title = undefined;
|
||||||
}
|
//}
|
||||||
if (title) {
|
//if (title) {
|
||||||
var w = g.getWidth()-48;
|
// var w = g.getWidth()-48;
|
||||||
if (g.setFont(titleFont).stringWidth(title) > w) {
|
// if (g.setFont(titleFont).stringWidth(title) > w) {
|
||||||
titleFont = fontBig;
|
// titleFont = fontBig;
|
||||||
if (settings.fontSize!=1 && g.setFont(titleFont).stringWidth(title) > w)
|
// if (settings.fontSize!=1 && g.setFont(titleFont).stringWidth(title) > w)
|
||||||
titleFont = fontMedium;
|
// titleFont = fontMedium;
|
||||||
}
|
// }
|
||||||
if (g.setFont(titleFont).stringWidth(title) > w) {
|
// if (g.setFont(titleFont).stringWidth(title) > w) {
|
||||||
lines = g.wrapString(title, w);
|
// lines = g.wrapString(title, w);
|
||||||
title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
|
// title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
// If body of message is only two lines long w/ large font, use large font.
|
//// If body of message is only two lines long w/ large font, use large font.
|
||||||
|
|
||||||
if (body) {
|
//if (body) {
|
||||||
var w = g.getWidth()-10;
|
// var w = g.getWidth()-10;
|
||||||
if (false && g.setFont(bodyFont).stringWidth(body) > w * 2) {
|
// if (false && g.setFont(bodyFont).stringWidth(body) > w * 2) {
|
||||||
bodyFont = fontBig;
|
// bodyFont = fontBig;
|
||||||
if (settings.fontSize!=1 && g.setFont(bodyFont).stringWidth(body) > w * 3)
|
// if (settings.fontSize!=1 && g.setFont(bodyFont).stringWidth(body) > w * 3)
|
||||||
bodyFont = fontMedium;
|
// bodyFont = fontMedium;
|
||||||
}
|
// }
|
||||||
if (g.setFont(bodyFont).stringWidth(body) > w) {
|
// if (g.setFont(bodyFont).stringWidth(body) > w) {
|
||||||
lines = g.setFont(bodyFont).wrapString(msg.body, w);
|
// lines = g.setFont(bodyFont).wrapString(msg.body, w);
|
||||||
var maxLines = Math.floor((g.getHeight()-75) / g.getFontHeight());
|
// var maxLines = Math.floor((g.getHeight()-75) / g.getFontHeight());
|
||||||
body = (lines.length>maxLines) ? lines.slice(0,maxLines).join("\n")+"..." : lines.join("\n");
|
// body = (lines.length>maxLines) ? lines.slice(0,maxLines).join("\n")+"..." : lines.join("\n");
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
function goBack() {
|
//function goBack() {
|
||||||
layout = undefined;
|
// layout = undefined;
|
||||||
msg.new = false; // read mail
|
// msg.new = false; // read mail
|
||||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
// cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
|
// checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
|
||||||
}
|
//}
|
||||||
var buttons = [
|
//var buttons = [
|
||||||
];
|
//];
|
||||||
if (false && msg.positive) {
|
//if (false && msg.positive) {
|
||||||
buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
|
// buttons.push({type:"btn", src:atob("GRSBAAAAAYAAAcAAAeAAAfAAAfAAAfAAAfAAAfAAAfBgAfA4AfAeAfAPgfAD4fAA+fAAP/AAD/AAA/AAAPAAADAAAA=="), cb:()=>{
|
||||||
msg.new = false;
|
// msg.new = false;
|
||||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
// cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
Bangle.messageResponse(msg,true);
|
// Bangle.messageResponse(msg,true);
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
// checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
||||||
}});
|
// }});
|
||||||
}
|
//}
|
||||||
if (false && msg.negative) {
|
//if (false && msg.negative) {
|
||||||
if (buttons.length) buttons.push({width:32}); // nasty hack...
|
// if (buttons.length) buttons.push({width:32}); // nasty hack...
|
||||||
buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{
|
// buttons.push({type:"btn", src:atob("FhaBADAAMeAB78AP/4B/fwP4/h/B/P4D//AH/4AP/AAf4AB/gAP/AB/+AP/8B/P4P4fx/A/v4B//AD94AHjAAMA="), cb:()=>{
|
||||||
msg.new = false;
|
// msg.new = false;
|
||||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
// cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
Bangle.messageResponse(msg,false);
|
// Bangle.messageResponse(msg,false);
|
||||||
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
// checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
|
||||||
}});
|
// }});
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
layout = new Layout({ type:"v", c: [
|
//layout = new Layout({ type:"v", c: [
|
||||||
{type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, c: [
|
// {type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, c: [
|
||||||
{ type:"v", fillx:1, c: [
|
// { type:"v", fillx:1, c: [
|
||||||
{type:"txt", font:fontSmall, label:msg.src||/*LANG*/"Message", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2, halign:1 },
|
// {type:"txt", font:fontSmall, label:msg.src||/*LANG*/"Message", bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2, halign:1 },
|
||||||
title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{},
|
// title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{},
|
||||||
]},
|
// ]},
|
||||||
{ type:"btn",
|
// { type:"btn",
|
||||||
src:require("messageicons").getImage(msg),
|
// src:require("messageicons").getImage(msg),
|
||||||
col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}),
|
// col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}),
|
||||||
pad: 3, cb:()=>{
|
// pad: 3, cb:()=>{
|
||||||
cancelReloadTimeout(); // don't auto-reload to clock now
|
// cancelReloadTimeout(); // don't auto-reload to clock now
|
||||||
showMessageSettings(msg);
|
// showMessageSettings(msg);
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
]},
|
// ]},
|
||||||
{type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
|
// {type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
|
||||||
// allow tapping to show a larger version
|
// // allow tapping to show a larger version
|
||||||
showMessageScroller(msg);
|
// showMessageScroller(msg);
|
||||||
} },
|
// } },
|
||||||
{type:"h",fillx:1, c: buttons}
|
// {type:"h",fillx:1, c: buttons}
|
||||||
]},{back:goBack});
|
//]},{back:goBack});
|
||||||
g.reset().clearRect(Bangle.appRect);
|
//g.reset().clearRect(Bangle.appRect);
|
||||||
layout.render();
|
//layout.render();
|
||||||
|
|
||||||
|
showMessageScroller(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user