Skip to content

Commit cedf23f

Browse files
author
thyttan
committed
Merge branch 'messagegui' into app-loader
2 parents 4528ef6 + 742edbd commit cedf23f

File tree

1 file changed

+142
-3
lines changed

1 file changed

+142
-3
lines changed

apps/messagegui/app.js

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,140 @@ function showMessageScroller(msg) {
274274
});
275275
}
276276

277+
function showMessageScroller2(msg, initAtEndOfMsg) {
278+
279+
cancelReloadTimeout();
280+
281+
let msgIdx = MESSAGES.findIndex((m) => m.id == msg.id)
282+
//print("msgIdx",msgIdx);
283+
284+
let startIdx = Math.max(msgIdx-1, 0);
285+
let endIdx = Math.min(msgIdx+2, MESSAGES.length);
286+
287+
active = "scroller";
288+
var bodyFont = fontBig;
289+
g.setFont(bodyFont);
290+
var allLines = [];
291+
var titleLines = [];
292+
var j = MESSAGES.length-1;
293+
var initScroll = 0;
294+
var messagesWrapped = [];
295+
for (let j=startIdx; j<endIdx; j++) {
296+
let msgLocal = MESSAGES[j];
297+
var lines = [];
298+
if (msgLocal.title) {
299+
lines = g.wrapString(msgLocal.title, g.getWidth()-10);
300+
for (let i=0; i<lines.length; i++) {
301+
titleLines.push(i + (messagesWrapped[0]?messagesWrapped[0].length:0) + (messagesWrapped[1]?messagesWrapped[1].length:0));
302+
}
303+
}
304+
var titleCnt = lines.length;
305+
if (titleCnt) lines.push(""); // add blank line after title
306+
lines = lines.concat(g.wrapString(msgLocal.body, g.getWidth()-10), [ "------" ]);
307+
messagesWrapped.push(lines);
308+
//print(lines);
309+
// allLines = allLines.concat(lines);
310+
};
311+
allLines.push("");
312+
allLines.push("");
313+
let allLines2 = [];
314+
for (let i=0;i<messagesWrapped.length;i++) {
315+
allLines2 = allLines2.concat(messagesWrapped[i]);
316+
}
317+
initScroll = messagesWrapped[0].length;
318+
if (msgIdx==0) initScroll = 0;
319+
if (!!initAtEndOfMsg) {
320+
let i = msgIdx==0?0:1;
321+
initScroll += messagesWrapped[i].length>8?messagesWrapped[i].length-8:0;
322+
}
323+
324+
//print(allLines);
325+
//print("titleLines:\n", titleLines);
326+
//print("allLines2:\n",allLines2);
327+
//print("messagesWrapped:\n",messagesWrapped);
328+
329+
E.showScroller({
330+
scroll : initScroll*g.getFontHeight(),
331+
h : g.getFontHeight(), // height of each menu item in pixels
332+
c : allLines2.length, // number of menu items
333+
// a function to draw a menu item
334+
draw : function(idx, r) {
335+
//print(idx); // FIXME: Remove this print.
336+
// FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12
337+
g.setBgColor(titleLines.find((e)=>e==idx)!==undefined ? g.theme.bg2 : g.theme.bg).
338+
setColor(titleLines.find((e)=>e==idx)!==undefined ? g.theme.fg2 : g.theme.fg).
339+
clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
340+
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines2[idx], r.x+r.w/2, r.y);
341+
if (idx>=allLines2.length-1 && msgIdx<MESSAGES.length-1) {
342+
setTimeout(()=>{
343+
showMessageScroller2(MESSAGES[msgIdx+1], true);
344+
}, 50)
345+
}
346+
if (idx==0 && msgIdx>0) {
347+
setTimeout(()=>{
348+
showMessageScroller2(MESSAGES[msgIdx-1], false);
349+
}, 50)
350+
}
351+
}, select : function(idx, touch) {
352+
if (touch.type == 0) {
353+
showMessage(msg.id, true)
354+
}
355+
if (touch.type == 2) {
356+
showMessageSettings(msg)
357+
}
358+
//showMessage(msg.id, true);
359+
},
360+
back : () => showMessage(messages[idx].id, true)
361+
});
362+
}
363+
364+
function showMessagesScroller(messages, offsetToMessageNumber) {
365+
print(messages);
366+
cancelReloadTimeout();
367+
active = "scroller";
368+
var bodyFont = fontBig;
369+
g.setFont(bodyFont);
370+
var allLines = [];
371+
var titleLines = [];
372+
var j = messages.length-1;
373+
var initScroll = 0;
374+
messages.forEach(msg => {
375+
if (j == offsetToMessageNumber) initScroll = allLines.length;
376+
var lines = [];
377+
if (msg.title) {
378+
lines = g.wrapString(msg.title, g.getWidth()-10);
379+
for (let i=0; i<lines.length; i++) {
380+
titleLines = titleLines.concat(allLines.length + i)
381+
}
382+
}
383+
var titleCnt = lines.length;
384+
if (titleCnt) lines.push(""); // add blank line after title
385+
lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10), [ "------" ]);
386+
print(lines);
387+
allLines = allLines.concat(lines);
388+
print(allLines);
389+
j--;
390+
});
391+
E.showScroller({
392+
scroll : initScroll*g.getFontHeight(),
393+
h : g.getFontHeight(), // height of each menu item in pixels
394+
c : allLines.length, // number of menu items
395+
// a function to draw a menu item
396+
draw : function(idx, r) {
397+
print(idx); // FIXME: Remove this print.
398+
// FIXME: in 2v13 onwards, clearRect(r) will work fine. There's a bug in 2v12
399+
g.setBgColor(titleLines.find((e)=>e==idx)!==undefined ? g.theme.bg2 : g.theme.bg).
400+
setColor(titleLines.find((e)=>e==idx)!==undefined ? g.theme.fg2 : g.theme.fg).
401+
clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
402+
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines[idx], r.x+r.w/2, r.y);
403+
}, select : function(idx) {
404+
if (idx>=allLines.length-2)
405+
showMessage(msg.id, true);
406+
},
407+
back : () => showMessage(msg.id, true)
408+
});
409+
}
410+
277411
function showMessageSettings(msg) {
278412
active = "settings";
279413
var menu = {"":{
@@ -283,7 +417,7 @@ function showMessageSettings(msg) {
283417
};
284418

285419
if (msg.id!="music")
286-
menu[/*LANG*/"View Message"] = () => showMessageScroller(msg);
420+
menu[/*LANG*/"View Message"] = () => showMessageScroller2(msg);
287421

288422
if (msg.reply && reply) {
289423
menu[/*LANG*/"Reply"] = () => {
@@ -456,7 +590,7 @@ function showMessage(msgid, persist) {
456590
]},
457591
{type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
458592
// allow tapping to show a larger version
459-
showMessageScroller(msg);
593+
showMessageScroller2(msg);
460594
} },
461595
{type:"h",fillx:1, c: footer}
462596
]},{back:goBack});
@@ -502,7 +636,8 @@ function checkMessages(options) {
502636
// If we have a new message, show it
503637
if (!options.ignoreUnread && newMessages.length) {
504638
delete newMessages[0].show; // stop us getting stuck here if we're called a second time
505-
showMessage(newMessages[0].id, false);
639+
//showMessage(newMessages[0].id, false);
640+
showMessageScroller2(MESSAGES[2], false);
506641
// buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
507642
if (global.BUZZ_ON_NEW_MESSAGE) {
508643
// this is set if we entered the messages app by loading `messagegui.new.js`
@@ -616,3 +751,7 @@ Bangle.on('lock',locked => {
616751
if (!locked)
617752
require("messages").stopBuzz();
618753
});
754+
755+
//setTimeout(() => {
756+
// showMessageScroller2(MESSAGES[2], false);
757+
//}, 11);

0 commit comments

Comments
 (0)