Skip to content

Commit aae386a

Browse files
author
thyttan
committed
messagegui: small refactoring
1 parent cde4c22 commit aae386a

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

apps/messagegui/app.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function showMusicMessage(msg) {
246246
}, 400);
247247
}
248248

249-
function showMessageScroller2(msg, persist, alreadyProcessed) {
249+
function showMessagesScroller(msg, persist, alreadyProcessed) {
250250
if (persist===undefined) {persist = true;}
251251

252252
const WU = require("widget_utils");
@@ -293,8 +293,8 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
293293
g.setFont(bodyFont);
294294
var titleLines = [];
295295
var messagesWrapped = [];
296-
for (let j=startIdx; j<stopIdx; j++) {
297-
let msgLocal = MESSAGES[j];
296+
for (let i=startIdx ; i<stopIdx ; i++) {
297+
let msgLocal = MESSAGES[i];
298298
msgLocal.new = false;
299299

300300
if (msgLocal.id=="music" || msgLocal.source=="maps" || msgLocal.id =="call") {
@@ -312,11 +312,11 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
312312
}
313313
var titleCnt = lines.length;
314314
if (titleCnt) {lines.push("");} // add blank line after title
315-
lines = lines.concat(g.wrapString(msgLocal.body, g.getWidth()-10), ["-".repeat(j+1)]);
315+
lines = lines.concat(g.wrapString(msgLocal.body, g.getWidth()-10), ["-".repeat(i+1)]);
316316
messagesWrapped.push(lines);
317317
}
318318
let allLines = [];
319-
for (let i=0;i<messagesWrapped.length;i++) {
319+
for (let i=0 ; i<messagesWrapped.length ; i++) {
320320
allLines = allLines.concat(messagesWrapped[i]);
321321
}
322322

@@ -330,9 +330,7 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
330330
titleLines = alreadyProcessed.titleLines.concat(titleLines.map((x) => x + alreadyProcessed.lines.length));
331331
}
332332

333-
if (initiatedFrom === "other function"){
334-
// no-op
335-
} else if (initiatedFrom === "scrolling up") {
333+
if (initiatedFrom === "scrolling up") {
336334
allLines = allLines.concat(alreadyProcessed.lines);
337335
} else if (initiatedFrom === "scrolling down"){
338336
allLines = alreadyProcessed.lines.concat(allLines);
@@ -365,34 +363,35 @@ function showMessageScroller2(msg, persist, alreadyProcessed) {
365363
setColor(titleLines.find((e)=>e==scrollIdx)!==undefined ? g.theme.fg2 : g.theme.fg).
366364
clearRect(r);
367365
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines[scrollIdx], r.x+r.w/2, r.y);
366+
// Load in next/previous message on demand by reinitializing showMessagesScroller while passing on the processed messages.
368367
if (scrollIdx>=allLines.length-1 && scrollIdx!=prevScrollIdx && updatedProcessed.stopIdx < MESSAGES.length) {
369368
setTimeout(() => {
370369
E.showScroller();
371-
showMessageScroller2(MESSAGES[updatedProcessed.stopIdx], true, updatedProcessed);
370+
showMessagesScroller(MESSAGES[updatedProcessed.stopIdx], true, updatedProcessed);
372371
}, 40);
373372
}
374373
if (scrollIdx==0 && scrollIdx!=prevScrollIdx && updatedProcessed.startIdx>0) {
375374
setTimeout(() => {
376375
E.showScroller();
377-
showMessageScroller2(MESSAGES[updatedProcessed.startIdx-1], true, updatedProcessed);
376+
showMessagesScroller(MESSAGES[updatedProcessed.startIdx-1], true, updatedProcessed);
378377
}, 40);
379378
}
380379
prevScrollIdx = scrollIdx;
381380
}, select : function(scrollIdx, touch) {
382-
let msgSelectIdx;
381+
let msgSelect;
383382
for (let i = titleLines.length-1; i>=0 ; i--) {
384383
if (scrollIdx>=titleLines[i]) {
385-
msgSelectIdx = i + updatedProcessed.startIdx;
384+
msgSelect = MESSAGES[i + updatedProcessed.startIdx];
386385
break;
387386
}
388387
}
389388
if (touch.type == 0) {
390389
WU.show();
391-
showMessage(MESSAGES[msgSelectIdx].id, true)
390+
showMessage(msgSelect.id, true)
392391
}
393392
if (touch.type == 2) {
394393
WU.show();
395-
showMessageSettings(MESSAGES[msgSelectIdx])
394+
showMessageSettings(msgSelect)
396395
}
397396
},
398397
//back : () => showMessage(messages[idx].id, true)
@@ -408,7 +407,7 @@ function showMessageSettings(msg) {
408407
};
409408

410409
if (msg.id!="music")
411-
menu[/*LANG*/"View Message"] = () => showMessageScroller2(msg);
410+
menu[/*LANG*/"View Message"] = () => showMessagesScroller(msg);
412411

413412
if (msg.reply && reply) {
414413
menu[/*LANG*/"Reply"] = () => {
@@ -581,7 +580,7 @@ function showMessage(msgid, persist) {
581580
]},
582581
{type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{
583582
// allow tapping to show a larger version
584-
showMessageScroller2(msg);
583+
showMessagesScroller(msg);
585584
} },
586585
{type:"h",fillx:1, c: footer}
587586
]},{back:goBack});
@@ -628,9 +627,9 @@ function checkMessages(options) {
628627
if (!options.ignoreUnread && newMessages.length) {
629628
delete newMessages[0].show; // stop us getting stuck here if we're called a second time
630629
//showMessage(newMessages[0].id, false);
631-
showMessageScroller2(newMessages[0], false);
630+
showMessagesScroller(newMessages[0], false);
632631
// buzz after showMessage, so being busy during layout doesn't affect the buzz pattern
633-
if (global.BUZZ_ON_NEW_MESSAGE) {
632+
if (global.BUZZ_ON_NEW_MESSAGE) {espruino
634633
// this is set if we entered the messages app by loading `messagegui.new.js`
635634
// ... but only buzz the first time we view a new message
636635
global.BUZZ_ON_NEW_MESSAGE = false;

0 commit comments

Comments
 (0)