fix going back to clock when there is a single message and it is removed
parent
136c73a85f
commit
fddf64fff2
|
|
@ -57,7 +57,6 @@ const clearTimeouts = function() {
|
|||
};
|
||||
|
||||
const showNoMessages = function() {
|
||||
|
||||
g.reset().clear();
|
||||
g.setFont("12x20").setFontAlign(0,0);
|
||||
g.drawString("No Messages!", Bangle.appRect.x + (Bangle.appRect.w / 2), Bangle.appRect.y + (Bangle.appRect.h / 2));
|
||||
|
|
@ -67,39 +66,42 @@ const showNoMessages = function() {
|
|||
btn: _e => goBack(),
|
||||
remove: cleanup
|
||||
});
|
||||
|
||||
goBack();
|
||||
};
|
||||
|
||||
const showMusic = function(music) {
|
||||
const showMusic = function() {
|
||||
active = "music";
|
||||
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
btn: _e => goBack()
|
||||
btn: _e => goBack(),
|
||||
remove: cleanup
|
||||
});
|
||||
};
|
||||
|
||||
const showMap = function(map) {
|
||||
const showMap = function() {
|
||||
active = "map";
|
||||
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
btn: _e => goBack()
|
||||
btn: _e => goBack(),
|
||||
remove: cleanup
|
||||
});
|
||||
};
|
||||
|
||||
const showAlarm = function(alarm) {
|
||||
const showAlarm = function() {
|
||||
active = "alarm";
|
||||
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
btn: _e => goBack()
|
||||
btn: _e => goBack(),
|
||||
remove: cleanup
|
||||
});
|
||||
};
|
||||
|
||||
const showCall = function(call) {
|
||||
const showCall = function() {
|
||||
if (!call) return goBack();
|
||||
const incomingImg = require("heatshrink").decompress(atob("j0ewIQNgwDCnEAh0B4EAvEOgEB+F//kP4P/+E/weAgH+g8Agf4CQMH8EYgEfEYU8AYV4AQIhBAYMD8ADBg4vBgEPzwDBj/+AYM/AYV//ADCC4X/EwQiCABo="));
|
||||
const outgoingImg = require("heatshrink").decompress(atob("j0ewIRO4ACBgeAh0Ag8AvEAh0B+F//kP4P/+E/wASB/0AjkD/EA8EH8EDgEfEwU8AYQhBgAhBFwXgAYMHGwUPzwDBj4mBgE/AYV/FQIDBC4X/EwQiCABoA=="));
|
||||
const ringingImg = require("heatshrink").decompress(atob("mUywIlimAFEhgFEgYSF4AWEAIYWBAIYWBAIcAsAYBgOAgEYCwQJBBwIWBHIXAA4YSC4EGAoICCDwQ8DAQUgAQMQVtsD///AoU/AoIGCv5BBh/4gF+B4UfwF4Dgd4nAFDg8cB4P/8EA9gFC/wgBBwIzBwEDSQaOB+BzCRAM8SQSQBDAKSCTAPADwMAGoPwh4eBg+An0/SQX/jv/TwUH/wlBAAQkBADwA="));
|
||||
|
|
@ -139,7 +141,7 @@ const showCall = function(call) {
|
|||
|
||||
if (cmd === "end") {
|
||||
console.log("end");
|
||||
if (timeouts.timer) clearTimeout(timeouts.timer);
|
||||
if (timeouts["timer"]) clearTimeout(timeouts["timer"]);
|
||||
let elapsedString = Bangle.elapsedString;
|
||||
delete Bangle.elapsedString;
|
||||
g.setColor(g.theme.fg).setFont("6x15:2").setFontAlign(0, -1);
|
||||
|
|
@ -195,7 +197,7 @@ const showCall = function(call) {
|
|||
swipeAnimation();
|
||||
});
|
||||
animate.then(() => {
|
||||
if (timeouts.timer) clearTimeout(timeouts["timer"]);
|
||||
if (timeouts["timer"]) clearTimeout(timeouts["timer"]);
|
||||
Bangle.messageResponse(msg, false);
|
||||
goBack();
|
||||
});
|
||||
|
|
@ -214,12 +216,11 @@ const showCall = function(call) {
|
|||
swipeAnimation();
|
||||
});
|
||||
animate.then(() => {
|
||||
if (timeouts.timer) clearTimeout(timeouts["timer"]);
|
||||
if (timeouts["timer"]) clearTimeout(timeouts["timer"]);
|
||||
Bangle.messageResponse(msg, true);
|
||||
goBack();
|
||||
});
|
||||
};
|
||||
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
touch: () => {if (buzzing) return require("messages").stopBuzz()},
|
||||
|
|
@ -230,8 +231,8 @@ const showCall = function(call) {
|
|||
};
|
||||
|
||||
const showText = function(messageNum) {
|
||||
g.reset().clear();
|
||||
if (!Bangle.MESSAGES.length) return goBack(); // no messages
|
||||
g.reset().clear();
|
||||
setBusy(); // busy until everything is set up
|
||||
//let showAll = false;
|
||||
if (messageNum === undefined) {messageNum = 0;} //showAll = true;}
|
||||
|
|
@ -340,9 +341,9 @@ const showText = function(messageNum) {
|
|||
|
||||
const toNext = function(removeCurrent) {
|
||||
if (removeCurrent == undefined) removeCurrent = false;
|
||||
if (timeouts.animID){
|
||||
clearTimeout(timeouts.animID);
|
||||
timeouts.animID = undefined;
|
||||
if (timeouts["animID"]){
|
||||
clearTimeout(timeouts["animID"]);
|
||||
timeouts["animID"] = undefined;
|
||||
}
|
||||
firstTouch = true;
|
||||
return new Promise((resolve, _reject) => {
|
||||
|
|
@ -375,9 +376,9 @@ const showText = function(messageNum) {
|
|||
|
||||
const toPrev = function(removeCurrent) {
|
||||
if (removeCurrent == undefined) removeCurrent = false;
|
||||
if (timeouts.animID){
|
||||
clearTimeout(timeouts.animID);
|
||||
timeouts.animID = undefined;
|
||||
if (timeouts["animID"]){
|
||||
clearTimeout(timeouts["animID"]);
|
||||
timeouts["animID"] = undefined;
|
||||
}
|
||||
firstTouch = true;
|
||||
return new Promise((resolve, _reject) => {
|
||||
|
|
@ -425,9 +426,9 @@ const showText = function(messageNum) {
|
|||
};
|
||||
|
||||
const animateToLeft = function() {
|
||||
if (timeouts.animID) {
|
||||
clearTimeout(timeouts.animID);
|
||||
timeouts.animID = undefined;
|
||||
if (timeouts["animID"]) {
|
||||
clearTimeout(timeouts["animID"]);
|
||||
timeouts["animID"] = undefined;
|
||||
}
|
||||
let multiplier = 1;
|
||||
const endX = Bangle.appRect.x - Bangle.appRect.w; //+ (Bangle.appRect.w / 2);
|
||||
|
|
@ -450,9 +451,9 @@ const showText = function(messageNum) {
|
|||
};
|
||||
|
||||
const animateToRight = function() {
|
||||
if (timeouts.animID) {
|
||||
clearTimeout(timeouts.animID);
|
||||
timeouts.animID = undefined;
|
||||
if (timeouts["animID"]) {
|
||||
clearTimeout(timeouts["animID"]);
|
||||
timeouts["animID"] = undefined;
|
||||
}
|
||||
let multiplier = 1;
|
||||
const endX = Bangle.appRect.x2; // - (Bangle.appRect.w / 2);
|
||||
|
|
@ -601,6 +602,10 @@ const showText = function(messageNum) {
|
|||
msgBoxes[messageNum].scroll(e.dy);
|
||||
};
|
||||
|
||||
msgBoxes[messageNum].draw();
|
||||
drawFooter();
|
||||
idle = true;
|
||||
checkForNewMessages();
|
||||
Bangle.setUI({
|
||||
mode: "custom",
|
||||
drag: e => dragHandler(e),
|
||||
|
|
@ -608,20 +613,16 @@ const showText = function(messageNum) {
|
|||
btn: _e => goBack(),
|
||||
remove: cleanup
|
||||
});
|
||||
|
||||
msgBoxes[messageNum].draw();
|
||||
drawFooter();
|
||||
idle = true;
|
||||
checkForNewMessages();
|
||||
}; // function showText
|
||||
}; // showText
|
||||
|
||||
// Check for new messages, wait until there is no interaction for `idleTime` ms
|
||||
const checkForNewMessages = function(idleTime) {
|
||||
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle
|
||||
idleTime = idleTime ?? 250; // how much time without interaction before we are considered idle
|
||||
idle = false;
|
||||
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer);
|
||||
if (timeouts["idleTimer"]) clearTimeout(timeouts["idleTimer"]);
|
||||
timeouts["idleTimer"] = setTimeout(() => {
|
||||
if (haveNewMessage) {
|
||||
if (!Bangle.MESSAGES.length) return goBack();
|
||||
haveNewMessage = false;
|
||||
let idx = Bangle.MESSAGES.findIndex(m => !m.handled);
|
||||
if (idx >= 0) {
|
||||
|
|
@ -639,8 +640,8 @@ const checkForNewMessages = function(idleTime) {
|
|||
|
||||
const setBusy = function() {
|
||||
idle = false;
|
||||
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer);
|
||||
timeouts.idleTimer = undefined;
|
||||
if (timeouts["idleTimer"]) clearTimeout(timeouts["idleTimer"]);
|
||||
timeouts["idleTimer"] = undefined;
|
||||
};
|
||||
|
||||
const goBack = function(timedOut) {
|
||||
|
|
@ -655,7 +656,8 @@ const goBack = function(timedOut) {
|
|||
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
|
||||
require("messages").write(Bangle.MESSAGES);
|
||||
cleanup = _cleanup;
|
||||
Bangle.load();
|
||||
cleanup();
|
||||
Bangle.showClock();
|
||||
}
|
||||
//console.log("backTo = ", backTo);
|
||||
switch (backTo) {
|
||||
|
|
@ -669,21 +671,21 @@ const goBack = function(timedOut) {
|
|||
else return showText(0);
|
||||
}
|
||||
}
|
||||
}; // function goBack
|
||||
}; // goBack
|
||||
|
||||
const newMessage = (type, msg) => {
|
||||
filterMessages();
|
||||
// if (!previous.includes(active) && type != active) previous.push(active);
|
||||
switch (type) {
|
||||
case "text":
|
||||
if (msg.t === "remove") {
|
||||
let idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id);
|
||||
if (idx >= 0) Bangle.MESSAGES.splice(idx, 1); // remove 'remove' from Bangle.MESSAGES
|
||||
idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id && m.t !== "remove");
|
||||
if (active === "text" && buzzing && idx === msgIdx) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
|
||||
// if (idx >= 0) Bangle.MESSAGES.splice(idx, 1); // remove 'remove' from Bangle.MESSAGES
|
||||
// idx = Bangle.MESSAGES.findIndex(m => m.id === msg.id && m.t !== "remove");
|
||||
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id != msg.id);
|
||||
if (active === "text" && buzzing && idx === msgIdx) require("messages").stopBuzz(); // if the message being viewed is removed stop buzzing
|
||||
require("messages").write(Bangle.MESSAGES); // write removal to flash
|
||||
if (active === "text") {
|
||||
//if (!Bangle.MESSAGES.length) goBack();
|
||||
if (idle) showText(msgIdx); // we are idle so updated messages right away
|
||||
else haveNewMessage = true; // otherwise set new message flag and wait until idle
|
||||
}
|
||||
|
|
@ -704,7 +706,7 @@ const newMessage = (type, msg) => {
|
|||
break;
|
||||
|
||||
case "call":
|
||||
if (call && call.t === "remove") {call = undefined; goBack();}
|
||||
//if (call && call.t === "remove") {call = undefined; goBack();}
|
||||
if (call) {setActive("call"); showCall(call);}
|
||||
break;
|
||||
case "alarm":
|
||||
|
|
@ -733,10 +735,10 @@ const filterMessages = function() {
|
|||
};
|
||||
|
||||
const showMessage = function() {
|
||||
if (call) {setActive("call"); return showCall(call);}
|
||||
else if (alarm) {setActive("alarm"); return showAlarm(alarm);}
|
||||
else if (map) {setActive("map"); return showMap(map);}
|
||||
else if (music) {setActive("music"); return showMusic(music);}
|
||||
if (call) {setActive("call"); return showCall();}
|
||||
else if (alarm) {setActive("alarm"); return showAlarm();}
|
||||
else if (map) {setActive("map"); return showMap();}
|
||||
else if (music) {setActive("music"); return showMusic();}
|
||||
else {
|
||||
idx = Bangle.MESSAGES.findIndex(m => !m.handled);
|
||||
if (idx >= 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue