Skip to content

Commit 447f150

Browse files
author
thyttan
committed
messagegui: improve logic re what messages to be marked new=false
1 parent e6bf0d7 commit 447f150

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

apps/messagegui/app.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ function showMessagesScroller(msg, persist) {
302302
for (let i=0 ; i<MESSAGES.length ; i++) {
303303
if (MSG_IDX === i) {initScroll = allLines.length*FONT_HEIGHT}
304304
let msgIter = MESSAGES[i];
305-
msgIter.new = false; // FIXME: Update "new" status in the scrollers draw method instead. A message should not be marked as read if it has not been displayed on screen.
306305

307306
var lines = [];
308307
const TITLE_STRING = msgIter.title||msgIter.sender||msgIter.subject||msgIter.src||/*LANG*/"No Title";
@@ -321,32 +320,42 @@ function showMessagesScroller(msg, persist) {
321320
returnToClockIfEmpty();
322321
}
323322

323+
let shownIdxFirst = allLines.length
324+
let shownIdxLast = 0;
325+
324326
E.showScroller({
325327
scroll : initScroll,
326328
h : FONT_HEIGHT, // height of each menu item in pixels
327329
c : allLines.length, // number of menu items
328330
// a function to draw a menu item
329331
draw : function(scrollIdx, r) {"ram";
332+
//print(scrollIdx)
330333
g.setBgColor(titleLines.find(e=>e==scrollIdx)!==undefined ? g.theme.bg2 : g.theme.bg).
331334
setColor(titleLines.find(e=>e==scrollIdx)!==undefined ? g.theme.fg2 : g.theme.fg).
332335
clearRect(r);
333336
g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines[scrollIdx], r.x+r.w/2, r.y);
337+
if (scrollIdx<shownIdxFirst) {shownIdxFirst = scrollIdx;}
338+
if (scrollIdx>shownIdxLast) {shownIdxLast = scrollIdx;}
334339
if (!persist) {resetReloadTimeout();}
335340
},
336341
select : function(scrollIdx, touch) {
337342
WU.show();
338-
clearBtnHandler();
339343
for (let i=firstTitleLinePerMsg.length-1; i>=0 ; i--) {
340344
if (scrollIdx>=firstTitleLinePerMsg[i]) {
341-
if (!touch || touch.type===0) {showMessageRouter(MESSAGES[i], true,
342-
"overview"); return;}
343-
if (touch.type == 2) {showMessageSettings(MESSAGES[i]);}
345+
if (!touch || touch.type===0) {
346+
showMessageRouter(MESSAGES[i], true, "overview")
347+
} else if (touch.type == 2) {
348+
showMessageSettings(MESSAGES[i]);
349+
}
344350
break;
345351
}
346352
}
353+
clearBtnHandler();
354+
updateReadMessages();
347355
}
348356
});
349357

358+
350359
// If Bangle.js 2 add an external select hw button handler.
351360
let btnHandler = ((2===process.env.HWVERSION) && (setWatch(()=>{
352361
Bangle.emit("drag", {dy:0}); // Compatibility with `kineticscroll`, stopping the scroller so it doesn't continue scrolling when the `showMessageOverview` screen is loaded.
@@ -360,6 +369,35 @@ function showMessagesScroller(msg, persist) {
360369
function clearBtnHandler() {
361370
if (btnHandler) {clearWatch(btnHandler); btnHandler=undefined;}
362371
}
372+
373+
function updateReadMessages() {
374+
let shownMsgIdxFirst, shownMsgIdxLast;
375+
const LINES_PER_SCREEN = APP_RECT.h/FONT_HEIGHT;
376+
//print(firstTitleLinePerMsg)
377+
//print(shownIdxFirst, shownIdxLast)
378+
379+
for (let i=0; i<firstTitleLinePerMsg.length-1 ; i++) {
380+
381+
if (shownIdxFirst<=firstTitleLinePerMsg[i] && shownIdxFirst+LINES_PER_SCREEN>firstTitleLinePerMsg[i]) {
382+
shownMsgIdxFirst = i;
383+
}
384+
385+
if (shownIdxLast>=firstTitleLinePerMsg[i+1] && shownIdxLast-LINES_PER_SCREEN<firstTitleLinePerMsg[i+1]) {
386+
shownMsgIdxLast = i;
387+
//print(i)
388+
}
389+
390+
}
391+
if (shownIdxLast===allLines.length-1) {shownMsgIdxLast = MESSAGES.length-1;}
392+
393+
//print(shownIdxFirst, shownIdxLast)
394+
//print(shownMsgIdxFirst, shownMsgIdxLast)
395+
//print(MESSAGES)
396+
for (let i=shownMsgIdxFirst; i<shownMsgIdxLast+1; i++) {
397+
MESSAGES[i].new = false;
398+
}
399+
//print(MESSAGES)
400+
}
363401
}
364402

365403
function showMessageSettings(msg) {

0 commit comments

Comments
 (0)