diff --git a/apps/messagegui/ChangeLog b/apps/messagegui/ChangeLog index 8df1075558..c6e7be674d 100644 --- a/apps/messagegui/ChangeLog +++ b/apps/messagegui/ChangeLog @@ -113,3 +113,4 @@ 0.82: Stop buzzing when a message is removed (e.g. call answered) 0.83: Add option to not open the first unread message 0.84: Fix: Assign show message entry to the settings menu and not the message itself. +0.85: (WIP) refactor to display a scroller with three messages loaded. When scrolling to the top or end new/older messages are loaded in. diff --git a/apps/messagegui/app.js b/apps/messagegui/app.js index 21cd1c3e1a..243b96e8f3 100644 --- a/apps/messagegui/app.js +++ b/apps/messagegui/app.js @@ -45,7 +45,7 @@ if (Graphics.prototype.setFontIntl) { fontVLarge = noScale?"Intl":"Intl:3"; } -var active; // active screen (undefined/"list"/"music"/"map"/"message"/"scroller"/"settings") +var active; // active screen (undefined/"list"/"music"/"map"/"overview"/"scroller"/"settings") var openMusic = false; // go back to music screen after we handle something else? var replying = false; // If we're replying to a message, don't interrupt // hack for 2v10 firmware's lack of ':size' font handling @@ -90,7 +90,8 @@ var onMessagesModified = function(type,msg) { } if (msg && msg.id=="nav" && msg.t=="modify" && active!="map") return; // don't show an updated nav message if we're just in the menu - showMessage(msg&&msg.id, false); + let persist = "messagegui.new.js"===global.__FILE__?false:true; + showMessageRouter(msg, persist, "dependsOnActive"); }; Bangle.on("message", onMessagesModified); @@ -99,6 +100,39 @@ function saveMessages() { } E.on("kill", saveMessages); +function showMessageRouter(msg, persist, explicitDestnation) { + //explicitDestnation (undefined/"scroller"/"overview"/"dependsOnActive") + + ////var active; // active screen (undefined/"list"/"music"/"map"/"overview"/"scroller"/"settings") + //if (active==undefined) { } else if (active=="list") ... //and so on. + + if (persist) {cancelReloadTimeout()} + + if (msg.id=="music") { + cancelReloadTimeout(); // don't auto-reload to clock now + return showMusicMessage(msg); + } + if (msg.id=="nav") { + cancelReloadTimeout(); // don't auto-reload to clock now + return showMapMessage(msg); + } + if (msg.id=="call") { + return showMessageOverview(msg.id, persist); + } + if ("scroller"===explicitDestnation) { + return showMessagesScroller(msg, persist); + } + if ("overview"===explicitDestnation) { + return showMessageOverview(msg.id, persist); + } + if ("dependsOnActive"===explicitDestnation) { + if ("scroller"===active) {return showMessagesScroller(msg, persist);} // reinit scroller with updated messages list. + if ("list"===active) {return returnToMain();} + if ("settings"===active || "overview"===active) {return;} + } + //if (false) {showMessageSettings(msg);} +} + function showMapMessage(msg) { active = "map"; require("messages").stopBuzz(); // stop repeated buzzing while the map is showing @@ -246,44 +280,136 @@ function showMusicMessage(msg) { }, 400); } -function showMessageScroller(msg) { - cancelReloadTimeout(); +function showMessagesScroller(msg, persist) { + if (persist===undefined) {persist = true;} + const MSG_IDX = msg ? MESSAGES.findIndex((m)=>m.id==msg.id) : undefined; + + if (replying) { return; } active = "scroller"; + if (persist) {cancelReloadTimeout();} else {resetReloadTimeout();} + + const WU = require("widget_utils"); + WU.hide(); + const APP_RECT = Bangle.appRect; + var bodyFont = fontBig; g.setFont(bodyFont); - var lines = []; - if (msg.title) lines = g.wrapString(msg.title, g.getWidth()-10); - var titleCnt = lines.length; - if (titleCnt) lines.push(""); // add blank line after title - lines = lines.concat(g.wrapString(msg.body, g.getWidth()-10),["",/*LANG*/"< Back"]); + const FONT_HEIGHT = g.getFontHeight(); + let initScroll; + var titleLines = []; + let allLines = []; + let firstTitleLinePerMsg = []; + for (let i=0 ; i=lines.length-2) - showMessage(msg.id, true); + draw : function(scrollIdx, r) {"ram"; + //print(scrollIdx) + g.setBgColor(titleLines.find(e=>e==scrollIdx)!==undefined ? g.theme.bg2 : g.theme.bg). + setColor(titleLines.find(e=>e==scrollIdx)!==undefined ? g.theme.fg2 : g.theme.fg). + clearRect(r); + g.setFont(bodyFont).setFontAlign(0,-1).drawString(allLines[scrollIdx], r.x+r.w/2, r.y); + if (scrollIdxshownIdxLast) {shownIdxLast = scrollIdx;} + if (!persist) {resetReloadTimeout();} }, - back : () => showMessage(msg.id, true) + select : function(scrollIdx, touch) { + WU.show(); + for (let i=firstTitleLinePerMsg.length-1; i>=0 ; i--) { + if (scrollIdx>=firstTitleLinePerMsg[i]) { + if (!touch || touch.type===0) { + showMessageRouter(MESSAGES[i], true, "overview") + } else if (touch.type == 2) { + showMessageSettings(MESSAGES[i]); + } + break; + } + } + clearBtnHandler(); + updateReadMessages(); + } }); + + + // If Bangle.js 2 add an external select hw button handler. + let btnHandler = ((2===process.env.HWVERSION) && (setWatch(()=>{ + Bangle.emit("drag", {dy:0}); // Compatibility with `kineticscroll`, stopping the scroller so it doesn't continue scrolling when the `showMessageOverview` screen is loaded. + // Zero ms timeout as to not move on before the scroller has registered the emitted drag event. + setTimeout(()=>{ + if ("messagegui.new.js"===global.__FILE__) {return load();} + Bangle.emit("touch", 1, {x:APP_RECT.x2/2, y:APP_RECT.y2/2, type:0}); + },0); + }, BTN, {edge:'rising', repeat:true}))); + + function clearBtnHandler() { + if (btnHandler) {clearWatch(btnHandler); btnHandler=undefined;} + } + + function updateReadMessages() { + let shownMsgIdxFirst, shownMsgIdxLast; + const LINES_PER_SCREEN = APP_RECT.h/FONT_HEIGHT; + //print(firstTitleLinePerMsg) + //print(shownIdxFirst, shownIdxLast) + + for (let i=0; ifirstTitleLinePerMsg[i]) { + shownMsgIdxFirst = i; + } + + if (shownIdxLast>=firstTitleLinePerMsg[i+1] && shownIdxLast-LINES_PER_SCREEN showMessage(msg.id, true) + back:() => showMessageOverview(msg.id, true) }, }; if (msg.id!="music") - menu[/*LANG*/"View Message"] = () => showMessageScroller(msg); + menu[/*LANG*/"View Message"] = () => showMessagesScroller(msg); if (msg.reply && reply) { menu[/*LANG*/"Reply"] = () => { @@ -292,11 +418,11 @@ function showMessageSettings(msg) { .then(result => { Bluetooth.println(JSON.stringify(result)); replying = false; - showMessage(msg.id); + showMessageOverview(msg.id); }) .catch(() => { replying = false; - showMessage(msg.id); + showMessageOverview(msg.id); }); }; } @@ -340,7 +466,7 @@ function showMessageSettings(msg) { E.showMenu(menu); } -function showMessage(msgid, persist) { +function showMessageOverview(msgid, persist) { if (replying) { return; } if(!persist) resetReloadTimeout(); let idx = MESSAGES.findIndex(m=>m.id==msgid); @@ -350,15 +476,7 @@ function showMessage(msgid, persist) { updateLabelsInterval=undefined; } if (!msg) return returnToClockIfEmpty(); // go home if no message found - if (msg.id=="music") { - cancelReloadTimeout(); // don't auto-reload to clock now - return showMusicMessage(msg); - } - if (msg.id=="nav") { - cancelReloadTimeout(); // don't auto-reload to clock now - return showMapMessage(msg); - } - active = "message"; + active = "overview"; // Normal text message display var title=msg.title, titleFont = fontLarge, lines; var body=msg.body, bodyFont = fontLarge; @@ -426,7 +544,7 @@ function showMessage(msgid, persist) { .catch(() => { replying = false; layout.render(); - showMessage(msg.id); + showMessageOverview(msg.id); }); }; footer.push({type:"img",src:atob("QRABAAAAAAAH//+AAAAABgP//8AAAAADgf//4AAAAAHg4ABwAAAAAPh8APgAAAAAfj+B////////geHv///////hf+f///////GPw///////8cGBwAAAAAPx/gDgAAAAAfD/gHAAAAAA8DngOAAAAABwDHP8AAAAADACGf4AAAAAAAAM/w=="),col:"#0f0", cb:posHandler}); } @@ -456,7 +574,7 @@ function showMessage(msgid, persist) { ]}, {type:"txt", font:bodyFont, label:body, fillx:1, filly:1, pad:2, cb:()=>{ // allow tapping to show a larger version - showMessageScroller(msg); + showMessagesScroller(msg); } }, {type:"h",fillx:1, c: footer} ]},{back:goBack}); @@ -464,8 +582,8 @@ function showMessage(msgid, persist) { Bangle.swipeHandler = (lr,ud) => { if (lr>0 && posHandler) posHandler(); if (lr<0 && negHandler) negHandler(); - if (ud>0 && idx0) showMessage(MESSAGES[idx-1].id, true); + if (ud>0 && idx0) showMessageOverview(MESSAGES[idx-1].id, true); }; Bangle.on("swipe", Bangle.swipeHandler); g.reset().clearRect(Bangle.appRect); @@ -502,8 +620,8 @@ function checkMessages(options) { // If we have a new message, show it if (!options.ignoreUnread && newMessages.length) { delete newMessages[0].show; // stop us getting stuck here if we're called a second time - showMessage(newMessages[0].id, false); - // buzz after showMessage, so being busy during layout doesn't affect the buzz pattern + showMessagesScroller(newMessages[0], false); + // buzz after showMessagesScroller, so being busy during scroller setup doesn't affect the buzz pattern if (global.BUZZ_ON_NEW_MESSAGE) { // this is set if we entered the messages app by loading `messagegui.new.js` // ... but only buzz the first time we view a new message @@ -515,7 +633,7 @@ function checkMessages(options) { } // no new messages: show playing music? Only if we have playing music, or state=="show" (set by messagesmusic) if (options.openMusic && MESSAGES.some(m=>m.id=="music" && ((m.track && m.state=="play") || m.state=="show"))) - return showMessage('music', true); + return showMessageOverview('music', true); // no new messages - go to clock? if (options.clockIfAllRead && newMessages.length==0) return load(); @@ -524,7 +642,7 @@ function checkMessages(options) { E.showScroller({ h : 48, c : Math.max(MESSAGES.length,3), // workaround for 2v10.219 firmware (min 3 not needed for 2v11) - draw : function(idx, r) {"ram" + draw : function(idx, r) {"ram"; var msg = MESSAGES[idx]; if (msg && msg.new) g.setBgColor(g.theme.bgH).setColor(g.theme.fgH); else g.setBgColor(g.theme.bg).setColor(g.theme.fg); @@ -564,13 +682,13 @@ function checkMessages(options) { }, select : idx => { if (idx < MESSAGES.length) - showMessage(MESSAGES[idx].id, true); + showMessageRouter(MESSAGES[idx], true, "overview"); }, back : () => load() }); } -function returnToCheckMessages(clock) { +function returnToCheckMessages() { checkMessages({clockIfNoMsg:1,clockIfAllRead:1,ignoreUnread:settings.ignoreUnread,openMusic}); } @@ -611,8 +729,14 @@ setTimeout(() => { }, 10); // if checkMessages wants to 'load', do that /* If the Bangle is unlocked by the user, treat that -as a queue to stop repeated buzzing */ +as a queue to stop repeated buzzing. +Also suspend the reload timeout while the watch is unlocked. */ Bangle.on('lock',locked => { - if (!locked) + if (!locked) { require("messages").stopBuzz(); + cancelReloadTimeout(); + } + if (locked) { + if ("messagegui.new.js"===global.__FILE__) {resetReloadTimeout();} + } }); diff --git a/apps/messagegui/metadata.json b/apps/messagegui/metadata.json index 3e0538d9e6..e0f47c6bc3 100644 --- a/apps/messagegui/metadata.json +++ b/apps/messagegui/metadata.json @@ -2,7 +2,7 @@ "id": "messagegui", "name": "Message UI", "shortName": "Messages", - "version": "0.84", + "version": "0.85", "description": "Default app to display notifications from iOS and Gadgetbridge/Android", "icon": "app.png", "type": "app",