Apply my changes to messagegui app:

- skip the entire message display UI, go directly to
  showMessageScroller()
- modify message scroller font and alignment
- remove extra lines and < Back button
- make tapping the header open message settings
This commit is contained in:
Tanner Collin 2024-09-09 12:38:17 -06:00
parent 6167de7456
commit 0ba99a590a

View File

@ -20,6 +20,9 @@ GB({t:"nav",src:"maps",title:"Navigation",instr:"High St",distance:"12km",action
GB({t:"nav",src:"maps",title:"Navigation",instr:"Main St / I-29 ALT / Centerpoint Dr",distance:12345,action:"left_slight",eta:"08:39"})
// call
require("messages").pushMessage({"t":"add","id":"call","src":"Phone","title":"Bob","body":"12421312",positive:true,negative:true})
// tanner
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; // global var containing the layout for the currently displayed message
@ -238,13 +241,14 @@ function showMusicMessage(msg) {
function showMessageScroller(msg) {
cancelReloadTimeout();
active = "scroller";
var bodyFont = fontBig;
var bodyFont = fontLarge;
g.setFont(bodyFont);
var lines = [];
if (msg.title) lines = g.wrapString(msg.title, g.getWidth()-10);
lines = [lines[0]];
var titleCnt = lines.length;
if (titleCnt) lines.push(""); // add blank line after title
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10),["",/*LANG*/"< Back"]);
//if (titleCnt) lines.push(""); // add blank line after title
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10)) //,["",/*LANG*/"< Back"]);
E.showScroller({
h : g.getFontHeight(), // height of each menu item in pixels
c : lines.length, // number of menu items
@ -254,12 +258,16 @@ function showMessageScroller(msg) {
g.setBgColor(idx<titleCnt ? g.theme.bg2 : g.theme.bg).
setColor(idx<titleCnt ? g.theme.fg2 : g.theme.fg).
clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
g.setFont(bodyFont).setFontAlign(0,-1).drawString(lines[idx], r.x+r.w/2, r.y);
g.setFont(bodyFont).drawString(lines[idx], r.x, r.y);
}, select : function(idx) {
if (idx>=lines.length-2)
showMessage(msg.id, true);
if (idx==0) {
cancelReloadTimeout(); // don't auto-reload to clock now
showMessageSettings(msg);
} else {
load();
}
},
back : () => showMessage(msg.id, true)
back : () => load()
});
}
@ -345,118 +353,120 @@ function showMessage(msgid, persist) {
cancelReloadTimeout(); // don't auto-reload to clock now
return showMapMessage(msg);
}
active = "message";
// Normal text message display
var title=msg.title, titleFont = fontLarge, lines;
var body=msg.body, bodyFont = fontLarge;
// If no body, use the title text instead...
if (body===undefined) {
body = title;
title = undefined;
}
if (title) {
var w = g.getWidth()-48;
if (g.setFont(titleFont).stringWidth(title) > w) {
titleFont = fontBig;
if (settings.fontSize!=1 && g.setFont(titleFont).stringWidth(title) > w)
titleFont = fontMedium;
}
if (g.setFont(titleFont).stringWidth(title) > w) {
lines = g.wrapString(title, w);
title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
}
}
if (body) { // Try and find a font that fits...
var w = g.getWidth()-2, h = Bangle.appRect.h-60;
if (g.setFont(bodyFont).wrapString(body, w).length*g.getFontHeight() > h) {
bodyFont = fontBig;
if (settings.fontSize!=1 && g.setFont(bodyFont).wrapString(body, w).length*g.getFontHeight() > h) {
bodyFont = fontMedium;
}
}
// Now crop, given whatever font we have available
lines = g.setFont(bodyFont).wrapString(body, w);
var maxLines = Math.floor(h / g.getFontHeight());
if (lines.length>maxLines) // if too long, wrap with a bit less spae so we have room for '...'
body = g.setFont(bodyFont).wrapString(body, w-10).slice(0,maxLines).join("\n")+"...";
else
body = lines.join("\n");
}
function goBack() {
layout = undefined;
msg.new = false; // read mail
cancelReloadTimeout(); // don't auto-reload to clock now
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
}
var negHandler,posHandler,footer = [ ];
if (msg.negative) {
negHandler = ()=>{
msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,false);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
}; footer.push({type:"img",src:atob("PhAB4A8AAAAAAAPAfAMAAAAAD4PwHAAAAAA/H4DwAAAAAH78B8AAAAAA/+A/AAAAAAH/Af//////w/gP//////8P4D///////H/Af//////z/4D8AAAAAB+/AfAAAAAA/H4DwAAAAAPg/AcAAAAADwHwDAAAAAA4A8AAAAAAAA=="),col:"#f00",cb:negHandler});
}
footer.push({fillx:1}); // push images to left/right
if (msg.reply && reply) {
posHandler = ()=>{
replying = true;
msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now
reply.reply({msg: msg})
.then(result => {
Bluetooth.println(JSON.stringify(result));
replying = false;
layout.render();
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
})
.catch(() => {
replying = false;
layout.render();
showMessage(msg.id);
});
}; footer.push({type:"img",src:atob("QRABAAAAAAAH//+AAAAABgP//8AAAAADgf//4AAAAAHg4ABwAAAAAPh8APgAAAAAfj+B////////geHv///////hf+f///////GPw///////8cGBwAAAAAPx/gDgAAAAAfD/gHAAAAAA8DngOAAAAABwDHP8AAAAADACGf4AAAAAAAAM/w=="),col:"#0f0", cb:posHandler});
}
else if (msg.positive) {
posHandler = ()=>{
msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,true);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
}; footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler});
}
// active = "message";
// // Normal text message display
// var title=msg.title, titleFont = fontLarge, lines;
// var body=msg.body, bodyFont = fontLarge;
// // If no body, use the title text instead...
// if (body===undefined) {
// body = title;
// title = undefined;
// }
// if (title) {
// var w = g.getWidth()-48;
// if (g.setFont(titleFont).stringWidth(title) > w) {
// titleFont = fontBig;
// if (settings.fontSize!=1 && g.setFont(titleFont).stringWidth(title) > w)
// titleFont = fontMedium;
// }
// if (g.setFont(titleFont).stringWidth(title) > w) {
// lines = g.wrapString(title, w);
// title = (lines.length>2) ? lines.slice(0,2).join("\n")+"..." : lines.join("\n");
// }
// }
// if (body) { // Try and find a font that fits...
// var w = g.getWidth()-2, h = Bangle.appRect.h-60;
// if (g.setFont(bodyFont).wrapString(body, w).length*g.getFontHeight() > h) {
// bodyFont = fontBig;
// if (settings.fontSize!=1 && g.setFont(bodyFont).wrapString(body, w).length*g.getFontHeight() > h) {
// bodyFont = fontMedium;
// }
// }
// // Now crop, given whatever font we have available
// lines = g.setFont(bodyFont).wrapString(body, w);
// var maxLines = Math.floor(h / g.getFontHeight());
// if (lines.length>maxLines) // if too long, wrap with a bit less spae so we have room for '...'
// body = g.setFont(bodyFont).wrapString(body, w-10).slice(0,maxLines).join("\n")+"...";
// else
// body = lines.join("\n");
// }
// function goBack() {
// layout = undefined;
// msg.new = false; // read mail
// cancelReloadTimeout(); // don't auto-reload to clock now
// checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
// }
// var negHandler,posHandler,footer = [ ];
// if (msg.negative) {
// negHandler = ()=>{
// msg.new = false;
// cancelReloadTimeout(); // don't auto-reload to clock now
// Bangle.messageResponse(msg,false);
// checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
// }; footer.push({type:"img",src:atob("PhAB4A8AAAAAAAPAfAMAAAAAD4PwHAAAAAA/H4DwAAAAAH78B8AAAAAA/+A/AAAAAAH/Af//////w/gP//////8P4D///////H/Af//////z/4D8AAAAAB+/AfAAAAAA/H4DwAAAAAPg/AcAAAAADwHwDAAAAAA4A8AAAAAAAA=="),col:"#f00",cb:negHandler});
// }
// footer.push({fillx:1}); // push images to left/right
// if (msg.reply && reply) {
// posHandler = ()=>{
// replying = true;
// msg.new = false;
// cancelReloadTimeout(); // don't auto-reload to clock now
// reply.reply({msg: msg})
// .then(result => {
// Bluetooth.println(JSON.stringify(result));
// replying = false;
// layout.render();
// checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
// })
// .catch(() => {
// replying = false;
// layout.render();
// showMessage(msg.id);
// });
// }; footer.push({type:"img",src:atob("QRABAAAAAAAH//+AAAAABgP//8AAAAADgf//4AAAAAHg4ABwAAAAAPh8APgAAAAAfj+B////////geHv///////hf+f///////GPw///////8cGBwAAAAAPx/gDgAAAAAfD/gHAAAAAA8DngOAAAAABwDHP8AAAAADACGf4AAAAAAAAM/w=="),col:"#0f0", cb:posHandler});
// }
// else if (msg.positive) {
// posHandler = ()=>{
// msg.new = false;
// cancelReloadTimeout(); // don't auto-reload to clock now
// Bangle.messageResponse(msg,true);
// checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
// }; footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler});
// }
//
// layout = new Layout({ type:"v", c: [
// {type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, 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 },
// title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{},
// ]},
// { type:"btn",
// src:require("messageicons").getImage(msg),
// col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}),
// pad: 3, cb:()=>{
// cancelReloadTimeout(); // don't auto-reload to clock now
// showMessageSettings(msg);
// }
// },
// ]},
// {type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
// // allow tapping to show a larger version
// showMessageScroller(msg);
// } },
// {type:"h",fillx:1, c: footer}
// ]},{back:goBack});
//
// Bangle.swipeHandler = (lr,ud) => {
// if (lr>0 && posHandler) posHandler();
// if (lr<0 && negHandler) negHandler();
// if (ud>0 && idx<MESSAGES.length-1) showMessage(MESSAGES[idx+1].id, true);
// if (ud<0 && idx>0) showMessage(MESSAGES[idx-1].id, true);
// };
// Bangle.on("swipe", Bangle.swipeHandler);
// g.reset().clearRect(Bangle.appRect);
// layout.render();
layout = new Layout({ type:"v", c: [
{type:"h", fillx:1, bgCol:g.theme.bg2, col: g.theme.fg2, 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 },
title?{type:"txt", font:titleFont, label:title, bgCol:g.theme.bg2, col: g.theme.fg2, fillx:1, pad:2 }:{},
]},
{ type:"btn",
src:require("messageicons").getImage(msg),
col:require("messageicons").getColor(msg, {settings:settings, default:g.theme.fg2}),
pad: 3, cb:()=>{
cancelReloadTimeout(); // don't auto-reload to clock now
showMessageSettings(msg);
}
},
]},
{type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
// allow tapping to show a larger version
showMessageScroller(msg);
} },
{type:"h",fillx:1, c: footer}
]},{back:goBack});
Bangle.swipeHandler = (lr,ud) => {
if (lr>0 && posHandler) posHandler();
if (lr<0 && negHandler) negHandler();
if (ud>0 && idx<MESSAGES.length-1) showMessage(MESSAGES[idx+1].id, true);
if (ud<0 && idx>0) showMessage(MESSAGES[idx-1].id, true);
};
Bangle.on("swipe", Bangle.swipeHandler);
g.reset().clearRect(Bangle.appRect);
layout.render();
showMessageScroller(msg);
}