Skip to content

Commit b6cb43a

Browse files
author
thyttan
committed
messagegui: avoid use of the overview screen
make many tweaks to accommodate that change. Add external back on touch handler to the showMessagesScroller that shows the list of messages. Select a message (touch it on B2, HW button on B1) opens the message settings screen. Going back from message setting screen opens the showMessagesScroller on the current message again. TODO: See if the code for the showMessageOverview can be removed.
1 parent 6a89759 commit b6cb43a

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

apps/messagegui/app.js

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,19 @@ function showMessagesScroller(msg) {
339339
if (touch && touch.type===2) {return;}
340340
const MSG_SELECTED = MESSAGES[i];
341341
WU&&WU.show();
342-
delete titleLines, allLines;
343342
//E.showScroller();
344343
updateReadMessages();
345-
if (!touch || touch.type===0) {
346-
setTimeout(()=>showMessageRouter(MSG_SELECTED, true, "overview"),0);
344+
delete titleLines, allLines;
345+
if (touch && touch.type.back) {
346+
returnToMain();
347+
} else if (!touch || touch.type===0) {
348+
setTimeout(()=>{
349+
showMessageSettings(MSG_SELECTED)
350+
},0);
347351
}
348-
print(touch)
352+
//print(touch)
349353
if (touch && touch.type.swipeLR) {
350-
print("select swipe")
354+
//print("select swipe")
351355
if (touch.type.swipeLR>0 && posHandler) {posHandler(MSG_SELECTED);}
352356
if (touch.type.swipeLR<0 && negHandler) {negHandler(MSG_SELECTED);}
353357
}
@@ -357,28 +361,41 @@ function showMessagesScroller(msg) {
357361
}
358362
});
359363

360-
// If Bangle.js 2 add an external select hw button handler.
364+
// If Bangle.js 2 add an external back hw button handler.
361365
if (2===process.env.HWVERSION) {
362366
setWatch(()=>{
363367
if ("scroller"!==active) {return;}
364368
Bangle.emit("drag", {dy:0}); // Compatibility with `kineticscroll`, stopping the scroller so it doesn't continue scrolling when the `showMessageOverview` screen is loaded.
365369
// Zero ms timeout as to not move on before the scroller has registered the emitted drag event.
366370
setTimeout(()=>{
367371
if (!persist) {return load();}
368-
Bangle.emit("touch", 1, {x:APP_RECT.x2/2, y:APP_RECT.y2/2, type:0});
372+
Bangle.emit("touch", 1, {x:Math.floor(APP_RECT.x2/2), y:Math.floor(APP_RECT.y2/2), type:{back:true}});
369373
},0);
370374
}, BTN);
371375
}
372376

377+
// Add an external back touch handler.
378+
let touchHandler = (button, xy)=>{
379+
// if ((left side of Banlge 1 screen) || (top left corner of Bangle 2 screen))
380+
if ((!xy && 1===button) || (xy && xy.type===0 && xy.x<30 && xy.y<30)) {
381+
if (!persist) {return load();}
382+
returnToMain();
383+
E.stopEventPropagation();
384+
Bangle.removeListener("touch", touchHandler);
385+
}
386+
};
387+
Bangle.prependListener("touch", touchHandler);
388+
373389
function updateReadMessages() {
374390
let shownMsgIdxFirst, shownMsgIdxLast;
375391
const LINES_PER_SCREEN = APP_RECT.h/FONT_HEIGHT;
376392
//print(firstTitleLinePerMsg)
377393
//print(shownIdxFirst, shownIdxLast)
378394

379-
for (let i=0; i<firstTitleLinePerMsg.length-1 ; i++) {
395+
for (let i=0; i<firstTitleLinePerMsg.length ; i++) {
380396
const FIRST_LINE_OF_MSG = firstTitleLinePerMsg[i];
381-
const LAST_LINE_OF_MSG = firstTitleLinePerMsg[i+1]-1 ?? allLines.length-1;
397+
const LAST_LINE_OF_MSG = (firstTitleLinePerMsg[i+1] || allLines.length) - 1;
398+
//print(" ", FIRST_LINE_OF_MSG, LAST_LINE_OF_MSG, allLines.length);
382399

383400
if (
384401
shownScrollIdxFirst
@@ -398,7 +415,7 @@ function showMessagesScroller(msg) {
398415
}
399416
}
400417

401-
//print(shownIdxFirst, shownIdxLast)
418+
//print(shownScrollIdxFirst, shownScrollIdxLast)
402419
//print(shownMsgIdxFirst, shownMsgIdxLast)
403420
//print(MESSAGES)
404421
for (let i=shownMsgIdxFirst; i<shownMsgIdxLast+1; i++) {
@@ -409,7 +426,7 @@ function showMessagesScroller(msg) {
409426
var negHandler,posHandler = [ ];
410427
if (msg.negative) {
411428
negHandler = (msg)=>{
412-
print("negHandler")
429+
//print("negHandler")
413430
msg.new = false;
414431
cancelReloadTimeout(); // don't auto-reload to clock now
415432
Bangle.messageResponse(msg,false);
@@ -418,7 +435,7 @@ function showMessagesScroller(msg) {
418435
//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});
419436
}
420437
if (msg.reply && reply) {
421-
print("posHandler reply")
438+
//print("posHandler reply")
422439
posHandler = (msg)=>{
423440
replying = true;
424441
msg.new = false;
@@ -438,7 +455,7 @@ function showMessagesScroller(msg) {
438455
}
439456
else if (msg.positive) {
440457
posHandler = (msg)=>{
441-
print("posHandler")
458+
//print("posHandler")
442459
msg.new = false;
443460
cancelReloadTimeout(); // don't auto-reload to clock now
444461
Bangle.messageResponse(msg,true);
@@ -447,7 +464,7 @@ function showMessagesScroller(msg) {
447464
//footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler});
448465
}
449466
Bangle.swipeHandler = (lr) => {
450-
if (lr) {Bangle.emit("touch", 1, {x:APP_RECT.x2/2, y:APP_RECT.y2/2, type:{swipeLR:lr}});}
467+
if (lr) {Bangle.emit("touch", 1, {x:Math.floor(APP_RECT.x2/2), y:Math.floor(APP_RECT.y2/2), type:{swipeLR:lr}});}
451468
};
452469
Bangle.on("swipe", Bangle.swipeHandler);
453470
}
@@ -456,7 +473,7 @@ function showMessageSettings(msg) {
456473
active = "settings";
457474
var menu = {"":{
458475
"title":/*LANG*/"Message",
459-
back:() => showMessageOverview(msg.id)
476+
back:() => showMessagesScroller(msg)
460477
},
461478
};
462479

@@ -470,11 +487,11 @@ function showMessageSettings(msg) {
470487
.then(result => {
471488
Bluetooth.println(JSON.stringify(result));
472489
replying = false;
473-
showMessageOverview(msg.id);
490+
showMessagesScroller(msg);
474491
})
475492
.catch(() => {
476493
replying = false;
477-
showMessageOverview(msg.id);
494+
showMessagesScroller(msg);
478495
});
479496
};
480497
}
@@ -595,7 +612,7 @@ function showMessageOverview(msgid) {
595612
.catch(() => {
596613
replying = false;
597614
layout.render();
598-
showMessageOverview(msg.id);
615+
showMessagesScroller(msg);
599616
});
600617
}; footer.push({type:"img",src:atob("QRABAAAAAAAH//+AAAAABgP//8AAAAADgf//4AAAAAHg4ABwAAAAAPh8APgAAAAAfj+B////////geHv///////hf+f///////GPw///////8cGBwAAAAAPx/gDgAAAAAfD/gHAAAAAA8DngOAAAAABwDHP8AAAAADACGf4AAAAAAAAM/w=="),col:"#0f0", cb:posHandler});
601618
}
@@ -733,7 +750,7 @@ function checkMessages(options) {
733750
},
734751
select : idx => {
735752
if (idx < MESSAGES.length)
736-
showMessageRouter(MESSAGES[idx], true, "overview");
753+
showMessageRouter(MESSAGES[idx], true, "scroller");
737754
},
738755
back : () => load()
739756
});

0 commit comments

Comments
 (0)