messages 0.08: Fix rendering of long messages (fix #969)

buzz on new message (fix #999)
pull/1017/head
Gordon Williams 2021-12-06 11:08:26 +00:00
parent 8cccf74213
commit 1c9e9725fb
4 changed files with 22 additions and 10 deletions

View File

@ -57,7 +57,7 @@
{
"id": "messages",
"name": "Messages",
"version": "0.07",
"version": "0.08",
"description": "App to display notifications from iOS and Gadgetbridge",
"icon": "app.png",
"type": "app",
@ -4771,7 +4771,7 @@
"name": "Charging Status",
"shortName":"ChargingStatus",
"icon": "widget.png",
"version":"0.1",
"version":"0.1",
"type": "widget",
"description": "A simple widget that shows a yellow lightning icon to indicate whenever the watch is charging. This way one can see the charging status at a glance, no matter which battery widget is being used.",
"tags": "widget",

View File

@ -8,3 +8,5 @@
Back now marks a message as read
Clicking top-left opens a menu which allows you to delete a message or mark unread
0.07: Added settings menu with option to choose vibrate pattern and frequency (fix #909)
0.08: Fix rendering of long messages (fix #969)
buzz on new message (fix #999)

View File

@ -21,6 +21,7 @@
*/
var Layout = require("Layout");
var fontSmall = "6x8";
var fontMedium = g.getFonts().includes("6x15")?"6x15":"6x8:2";
var fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2";
var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4";
@ -173,13 +174,15 @@ function showMessage(msgid) {
if (msg.src=="Maps") return showMapMessage(msg);
if (msg.id=="music") return showMusicMessage(msg);
// Normal text message display
var title=msg.title, titleFont = fontLarge;
var title=msg.title, titleFont = fontLarge, lines;
if (title) {
var w = g.getWidth()-40;
var w = g.getWidth()-48;
if (g.setFont(titleFont).stringWidth(title) > w)
titleFont = fontMedium;
if (g.setFont(titleFont).stringWidth(title) > w)
title = g.wrapString(title, w).join("\n");
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");
}
}
var buttons = [
{type:"btn", src:getBackImage(), cb:()=>{
@ -203,15 +206,17 @@ function showMessage(msgid) {
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1});
}});
}
lines = g.wrapString(msg.body, g.getWidth()-10);
var body = (lines.length>4) ? lines.slice(0,4).join("\n")+"..." : lines.join("\n");
layout = new Layout({ type:"v", c: [
{type:"h", fillx:1, bgCol:colBg, c: [
{ type:"btn", src:getMessageImage(msg), cb:()=>showMessageSettings(msg) },
{ type:"v", fillx:1, c: [
{type:"txt", font:fontMedium, label:msg.src||"Message", bgCol:colBg, fillx:1, pad:2 },
{type:"txt", font:fontSmall, label:msg.src||"Message", bgCol:colBg, fillx:1, pad:2, halign:1 },
title?{type:"txt", font:titleFont, label:title, bgCol:colBg, fillx:1, pad:2 }:{},
]},
]},
{type:"txt", font:fontMedium, label:msg.body||"", wrap:true, fillx:1, filly:1, pad:2 },
{type:"txt", font:fontMedium, label:body, fillx:1, filly:1, pad:2 },
{type:"h",fillx:1, c: buttons}
]});
g.clearRect(Bangle.appRect);

View File

@ -28,12 +28,17 @@ exports.pushMessage = function(event) {
if (inApp) return onMessagesModified(mIdx<0 ? {id:event.id} : messages[mIdx]);
// ok, saved now - we only care if it's new
if (event.t!="add") return;
// otherwise load after a delay, to ensure we have all the messages
// otherwise load messages/show widget
var loadMessages = Bangle.CLOCK || event.important;
// first, buzz
if (loadMessages && global.WIDGETS && WIDGETS.messages)
WIDGETS.messages.buzz();
// after a delay load the app, to ensure we have all the messages
if (exports.messageTimeout) clearTimeout(exports.messageTimeout);
exports.messageTimeout = setTimeout(function() {
exports.messageTimeout = undefined;
// if we're in a clock or it's important, go straight to messages app
if (Bangle.CLOCK || event.important) return load("messages.app.js");
if (loadMessages) return load("messages.app.js");
if (!global.WIDGETS || !WIDGETS.messages) return Bangle.buzz(); // no widgets - just buzz to let someone know
WIDGETS.messages.show();
}, 500);