|
|
|
@ -1,37 +1,39 @@
|
|
|
|
Bangle.MESSAGES = [
|
|
|
|
// Bangle.MESSAGES = [
|
|
|
|
{"t":"add","id":1720281666,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
// {"t":"add","id":1720281666,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
"body":"5 * short message *5",
|
|
|
|
// "body":"5 * short message *5",
|
|
|
|
"sender":"","positive":true,"negative":true,"new":true,"handled":true, "show": true},
|
|
|
|
// "sender":"","positive":true,"negative":true,"new":true,"handled":true, "show": true},
|
|
|
|
|
|
|
|
//
|
|
|
|
{"t":"add","id":1720281662,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
// {"t":"add","id":1720281662,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
"body":"1 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****1",
|
|
|
|
// "body":"1 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****1",
|
|
|
|
"sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
// "sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
|
|
|
|
//
|
|
|
|
{"t":"add","id":1720281663,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
// {"t":"add","id":1720281663,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
"body":"2 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****2",
|
|
|
|
// "body":"2 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****2",
|
|
|
|
"sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
// "sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
|
|
|
|
//
|
|
|
|
{"t":"add","id":1720281667,"src":"SMS Message","title":"Hayley Thiessen","subject":"",
|
|
|
|
// {"t":"add","id":1720281667,"src":"SMS Message","title":"Hayley Thiessen","subject":"",
|
|
|
|
"body":"6 * short message *6",
|
|
|
|
// "body":"6 * short message *6",
|
|
|
|
"sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
// "sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
|
|
|
|
//
|
|
|
|
{"t":"add","id":1720281664,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
// {"t":"add","id":1720281664,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
"body":"3 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****3",
|
|
|
|
// "body":"3 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****3",
|
|
|
|
"sender":"","positive":true,"negative":true,"new":true,"handled":true, "show": true},
|
|
|
|
// "sender":"","positive":true,"negative":true,"new":true,"handled":true, "show": true},
|
|
|
|
|
|
|
|
//
|
|
|
|
{"t":"add","id":1720281665,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
// {"t":"add","id":1720281665,"src":"SMS Message","title":"Hayley Thiessen, Wifey","subject":"",
|
|
|
|
"body":"4 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****4",
|
|
|
|
// "body":"4 ***** This is a long message from my wife. I want to make it take up more than a screenful. That way we can test out scrolling. ****4",
|
|
|
|
"sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
// "sender":"","positive":true,"negative":true,"new":false,"handled":true, "show": true},
|
|
|
|
|
|
|
|
//
|
|
|
|
];
|
|
|
|
// ];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let idle = false;
|
|
|
|
let idle = false;
|
|
|
|
let haveNewMessage = false;
|
|
|
|
let haveNewMessage = false;
|
|
|
|
let previousActive;
|
|
|
|
let previousActive;
|
|
|
|
let active;
|
|
|
|
let active;
|
|
|
|
|
|
|
|
let buzzing;
|
|
|
|
let events = {};
|
|
|
|
let events = {};
|
|
|
|
let timeouts = {};
|
|
|
|
let timeouts = {};
|
|
|
|
|
|
|
|
let cleanup = function() {}; // we don't want cleanup function to do anything until we actually need it
|
|
|
|
|
|
|
|
|
|
|
|
const goBack = function(timedOut) {
|
|
|
|
const goBack = function(timedOut) {
|
|
|
|
switch (previousActive) {
|
|
|
|
switch (previousActive) {
|
|
|
|
@ -43,16 +45,32 @@ const goBack = function(timedOut) {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
|
|
|
|
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
|
|
|
|
require("messages").write(Bangle.MESSAGES);
|
|
|
|
require("messages").write(Bangle.MESSAGES);
|
|
|
|
cleanup();
|
|
|
|
cleanup = _cleanup;
|
|
|
|
Bangle.showClock();
|
|
|
|
Bangle.showClock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const cleanup = function() {
|
|
|
|
const setListener = function(event, callback) {
|
|
|
|
|
|
|
|
if (!event || !callback) return;
|
|
|
|
|
|
|
|
console.log("setListener");
|
|
|
|
|
|
|
|
events[event] = callback;
|
|
|
|
|
|
|
|
Bangle.on(event, callback);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
const _cleanup = function() {
|
|
|
|
|
|
|
|
for (let e in events) if (e) Bangle.removeListener(e, events[e]);
|
|
|
|
|
|
|
|
for (let t in timeouts) if (timeouts[t]) clearTimeout(timeouts[t]);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const clearTimeouts = function() {
|
|
|
|
|
|
|
|
for (let t in timeouts) if (timeouts[t]) clearTimeout(timeouts[t]);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// placeholder functions
|
|
|
|
// placeholder functions
|
|
|
|
|
|
|
|
const showNoMessages = function() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const showMusic = function() {
|
|
|
|
const showMusic = function() {
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -87,14 +105,13 @@ const showCall = function() {
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
Bangle.loadWidgets();
|
|
|
|
require("widget_utils").hide();
|
|
|
|
require("widget_utils").hide();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
events.saveMessages = function() {
|
|
|
|
events.saveMessages = function(messages) {
|
|
|
|
require("messages").write(Bangle.MESSAGES);
|
|
|
|
require("messages").write(messages);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
E.on("kill", events.saveMessages);
|
|
|
|
E.on("kill", events.saveMessages);
|
|
|
|
|
|
|
|
|
|
|
|
events.newMessage = (type, msg) => {
|
|
|
|
const newMessage = (type, msg) => {
|
|
|
|
console.log("new message");
|
|
|
|
console.log("new message");
|
|
|
|
if (type === "text" && active === "message") {
|
|
|
|
if (type === "text" && active === "message") {
|
|
|
|
require("messages").apply(msg, Bangle.MESSAGES);
|
|
|
|
require("messages").apply(msg, Bangle.MESSAGES);
|
|
|
|
@ -102,10 +119,10 @@ events.newMessage = (type, msg) => {
|
|
|
|
else haveNewMessage = true; // otherwise set new message flag and wait until idle
|
|
|
|
else haveNewMessage = true; // otherwise set new message flag and wait until idle
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO deal with other types of messages
|
|
|
|
// TODO deal with other types of messages
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Bangle.on("message", events.newMessage);
|
|
|
|
setListener("message", newMessage);
|
|
|
|
|
|
|
|
|
|
|
|
// Check for new messages, wait until there is no interaction for idleTime ms
|
|
|
|
// Check for new messages, wait until there is no interaction for `idleTime` ms
|
|
|
|
const checkForNewMessages = function(idleTime) {
|
|
|
|
const checkForNewMessages = function(idleTime) {
|
|
|
|
console.log("checkForNewMessages");
|
|
|
|
console.log("checkForNewMessages");
|
|
|
|
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle
|
|
|
|
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle
|
|
|
|
@ -130,64 +147,68 @@ const setBusy = function() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param allMessages {array} all messages
|
|
|
|
|
|
|
|
* @param showAll {bool} true to show all messages, false to only show new messages, default: false
|
|
|
|
* @param showAll {bool} true to show all messages, false to only show new messages, default: false
|
|
|
|
* @param num {number}
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
const showText = function(allMessages, showAll) {
|
|
|
|
const showText = function(showAll) {
|
|
|
|
Bangle.setUI(); // make sure to clear setUI from anything previous
|
|
|
|
Bangle.setUI(); // make sure to clear setUI from anything previous
|
|
|
|
|
|
|
|
if (active != "message") previousActive = active;
|
|
|
|
|
|
|
|
active = "message";
|
|
|
|
setBusy(); // busy until everything is set up
|
|
|
|
setBusy(); // busy until everything is set up
|
|
|
|
let switching = false;
|
|
|
|
let switching = false;
|
|
|
|
active = "message";
|
|
|
|
|
|
|
|
let MessageBox = require("messagebox").MessageBox;
|
|
|
|
let MessageBox = require("messagebox").MessageBox;
|
|
|
|
require("messagebox").setOptions({fh: 30});
|
|
|
|
require("messagebox").setOptions({fh: 20});
|
|
|
|
const step = 89;
|
|
|
|
const step = 42;
|
|
|
|
const delay = 30;
|
|
|
|
const delay = 30;
|
|
|
|
const swipeThreshold = 20;
|
|
|
|
const swipeThreshold = 20;
|
|
|
|
let mode = "scroll"; // one of "scroll", "next", "prev" (switch to next/prev message), "swipe" (swipe to delete or archive)
|
|
|
|
let mode = "scroll"; // one of "scroll", "next", "prev" (switch to next/prev message), "swipe" (swipe to delete or archive)
|
|
|
|
let messageNum = 0;
|
|
|
|
let messageNum = 0;
|
|
|
|
// TODO we might have to append array of (m.show && !m.new) to array of m.new so that all new messages are at the beginning of list
|
|
|
|
// TODO we might have to append array of (m.show && !m.new) to array of m.new so that all new messages are at the beginning of list
|
|
|
|
let messageList = showAll ? allMessages : allMessages.filter(m => m.new || m.show);
|
|
|
|
let messageList = showAll ? Bangle.MESSAGES : Bangle.MESSAGES.filter(m => m.new || m.show);
|
|
|
|
if (!messageList.length) {
|
|
|
|
if (!messageList.length) {
|
|
|
|
console.log("No messages")
|
|
|
|
console.log("No messages")
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Bangle.setLocked(false); // TODO make as option
|
|
|
|
// Bangle.setLocked(false); // TODO make as option
|
|
|
|
Bangle.setLCDPower(true); // TODO make as option
|
|
|
|
// Bangle.setLCDPower(true); // TODO make as option
|
|
|
|
|
|
|
|
|
|
|
|
let msgBoxes = [];
|
|
|
|
let msgBoxes = [];
|
|
|
|
let i = 0;
|
|
|
|
let i = 0;
|
|
|
|
for (let msg of messageList) {
|
|
|
|
for (let msg of messageList) {
|
|
|
|
msgBoxes[i] = new MessageBox(msg);
|
|
|
|
msgBoxes[i] = new MessageBox(msg);
|
|
|
|
if (i == messageNum - 1) msgBoxes[i].yOffset = MessageBox.prototype.prevOffset;
|
|
|
|
if (i === messageNum - 1) msgBoxes[i].yOffset = MessageBox.prototype.prevOffset;
|
|
|
|
else if (i == messageNum) msgBoxes[i].yOffset = 0;
|
|
|
|
else if (i === messageNum) {
|
|
|
|
else if ( i == messageNum + 1) msgBoxes[i].yOffset = MessageBox.prototype.nextOffset;
|
|
|
|
msgBoxes[i].yOffset = 0;
|
|
|
|
|
|
|
|
msgBoxes[i].draw();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ( i === messageNum + 1) msgBoxes[i].yOffset = MessageBox.prototype.nextOffset;
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const drawFooter = function() {
|
|
|
|
const drawFooter = function() {
|
|
|
|
let fh = 10; // footer height
|
|
|
|
let fh = 20; // footer height
|
|
|
|
// left hint: swipe from left for main menu
|
|
|
|
// left hint: swipe from left for main menu
|
|
|
|
g.reset().clearRect(Bangle.appRect.x, Bangle.appRect.y2-fh, Bangle.appRect.x2, Bangle.appRect.y2)
|
|
|
|
g.reset().setBgColor(g.theme.bg2).clearRect(Bangle.appRect.x, Bangle.appRect.y2-fh, Bangle.appRect.x2, Bangle.appRect.y2)
|
|
|
|
.setFont(fontTiny)
|
|
|
|
.setFont("6x15") // TODO make as option
|
|
|
|
.setFontAlign(-1, 1) // bottom left
|
|
|
|
.setFontAlign(-1, 1) // bottom left
|
|
|
|
.drawString(
|
|
|
|
.drawString(
|
|
|
|
"\0"+atob("CAiBAEgkEgkSJEgA"), // >>
|
|
|
|
//"\0"+atob("CAiBAEgkEgkSJEgA"), // >>
|
|
|
|
|
|
|
|
">>",
|
|
|
|
Bangle.appRect.x + 1, Bangle.appRect.y2
|
|
|
|
Bangle.appRect.x + 1, Bangle.appRect.y2
|
|
|
|
);
|
|
|
|
);
|
|
|
|
// center message count+hints: swipe up/down for next/prev message
|
|
|
|
// center message count+hints: swipe up/down for next/prev message
|
|
|
|
const footer = ` ${messageNum+1}/${messageList.length} `;
|
|
|
|
const footer = ` ${messageNum + 1}/${msgBoxes.length} `;
|
|
|
|
const fw = g.stringWidth(footer);
|
|
|
|
const fw = g.stringWidth(footer);
|
|
|
|
g.setFontAlign(0, 1); // bottom center
|
|
|
|
g.setFontAlign(0, 1); // bottom center
|
|
|
|
g.drawString(footer, Bangle.appRect.x+Bangle.appRect.w/2, Bangle.appRect.y2);
|
|
|
|
g.drawString(footer, Bangle.appRect.x+Bangle.appRect.w/2, Bangle.appRect.y2);
|
|
|
|
if (messageNum < Bangle.MESSAGES.length - 1 && this.bottom)
|
|
|
|
if (messageNum < Bangle.MESSAGES.length - 1 && msgBoxes[messageNum].bottom)
|
|
|
|
g.drawString("\0"+atob("CAiBAABBIhRJIhQI"), Bangle.appRect.x+Bangle.appRect.w/2-fw/2, Bangle.appRect.y2); // v swipe to next
|
|
|
|
g.drawString("\0"+atob("CAiBAABBIhRJIhQI"), Bangle.appRect.x+Bangle.appRect.w/2-fw/2 - 20, Bangle.appRect.y2); // v swipe to next
|
|
|
|
if (messageNum > 0 && this.top)
|
|
|
|
if (messageNum > 0 && msgBoxes[messageNum].top)
|
|
|
|
g.drawString("\0"+atob("CAiBABAoRJIoRIIA"), Bangle.appRect.x+Bangle.appRect.w/2+fw/2, Bangle.appRect.y2); // ^ swipe to prev
|
|
|
|
g.drawString("\0"+atob("CAiBABAoRJIoRIIA"), Bangle.appRect.x+Bangle.appRect.w/2+fw/2 + 20, Bangle.appRect.y2); // ^ swipe to prev
|
|
|
|
// right hint: swipe from right for message actions
|
|
|
|
// right hint: swipe from right for message actions
|
|
|
|
g.setFontAlign(1, 1) // bottom right
|
|
|
|
g.setFontAlign(1, 1) // bottom right
|
|
|
|
.drawString(
|
|
|
|
.drawString(
|
|
|
|
"\0"+atob("CAiBABIkSJBIJBIA"), // <<
|
|
|
|
//"\0"+atob("CAiBABIkSJBIJBIA"), // <<
|
|
|
|
|
|
|
|
"<<",
|
|
|
|
Bangle.appRect.x2 - 1, Bangle.appRect.y2
|
|
|
|
Bangle.appRect.x2 - 1, Bangle.appRect.y2
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -198,28 +219,33 @@ const showText = function(allMessages, showAll) {
|
|
|
|
if (messageNum > 0) msgBoxes[messageNum - 1].reset(MessageBox.prototype.prevOffset);
|
|
|
|
if (messageNum > 0) msgBoxes[messageNum - 1].reset(MessageBox.prototype.prevOffset);
|
|
|
|
if (messageNum < msgBoxes.length - 1) msgBoxes[messageNum + 1].reset(MessageBox.prototype.nextOffset);
|
|
|
|
if (messageNum < msgBoxes.length - 1) msgBoxes[messageNum + 1].reset(MessageBox.prototype.nextOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const removeMessage = function() {
|
|
|
|
const removeMessage = function() {
|
|
|
|
const removeAndReset = () => {
|
|
|
|
const removeAndReset = () => {
|
|
|
|
allMessages = allMessages.filter((m) => m.id != msgBoxes[messageNum.id]); // remove from messages array
|
|
|
|
let id = msgBoxes[messageNum].id;
|
|
|
|
|
|
|
|
Bangle.MESSAGES.filter(m => m.id !== id);
|
|
|
|
msgBoxes.splice(messageNum, 1); // remove from msgBoxes
|
|
|
|
msgBoxes.splice(messageNum, 1); // remove from msgBoxes
|
|
|
|
if (messageNum == msgBoxes.length) messageNum--; // we removed the last message, go to previous message
|
|
|
|
if (!msgBoxes.length) {
|
|
|
|
// otherwise messageNum is automatically the index of the next message now
|
|
|
|
|
|
|
|
if (messageNum < 0) {
|
|
|
|
|
|
|
|
Bangle.setUI();
|
|
|
|
Bangle.setUI();
|
|
|
|
return goBack(); // no more messages
|
|
|
|
return goBack(); // no more messages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (messageNum == msgBoxes.length) messageNum--; // we removed the last message, go to previous message
|
|
|
|
|
|
|
|
// otherwise messageNum is automatically the index of the next message now
|
|
|
|
refresh();
|
|
|
|
refresh();
|
|
|
|
msgBoxes[messageNum].draw();
|
|
|
|
msgBoxes[messageNum].draw();
|
|
|
|
drawFooter();
|
|
|
|
drawFooter();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (messageNum < msgBoxes.length - 1) {
|
|
|
|
if (messageNum < msgBoxes.length - 1) {
|
|
|
|
|
|
|
|
require("messagebox").setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
|
|
|
|
|
|
g.setBgColor(g.theme.bg).clear();
|
|
|
|
toNext(true).then(() => {
|
|
|
|
toNext(true).then(() => {
|
|
|
|
removeAndReset();
|
|
|
|
removeAndReset();
|
|
|
|
switching = false;
|
|
|
|
switching = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else if (messageNum > 0) {
|
|
|
|
} else if (messageNum > 0) {
|
|
|
|
|
|
|
|
require("messagebox").setClipRect(Bangle.appRect.x, Bangle.appRect.y, Bangle.appRect.x2, Bangle.appRect.y2);
|
|
|
|
|
|
|
|
g.setBgColor(g.theme.bg).clear();
|
|
|
|
toPrev(true).then(() => {
|
|
|
|
toPrev(true).then(() => {
|
|
|
|
removeAndReset();
|
|
|
|
removeAndReset();
|
|
|
|
switching = false;
|
|
|
|
switching = false;
|
|
|
|
@ -316,12 +342,13 @@ const showText = function(allMessages, showAll) {
|
|
|
|
clearTimeout(timeouts.animID);
|
|
|
|
clearTimeout(timeouts.animID);
|
|
|
|
timeouts.animID = undefined;
|
|
|
|
timeouts.animID = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const endX = Bangle.appRect.x + (Bangle.appRect.w / 2);
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
return new Promise((resolve, _reject) => {
|
|
|
|
return new Promise((resolve, _reject) => {
|
|
|
|
let animate = () => {
|
|
|
|
let animate = () => {
|
|
|
|
msgBox.xOffset -= step
|
|
|
|
msgBox.xOffset -= step
|
|
|
|
drawLeftBackground();
|
|
|
|
drawLeftBackground();
|
|
|
|
if (msgBox.xOffset <= Bangle.appRect.x - Bangle.appRect.w) {
|
|
|
|
if (msgBox.xOffset <= endX) {
|
|
|
|
return resolve();
|
|
|
|
return resolve();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msgBox.draw();
|
|
|
|
msgBox.draw();
|
|
|
|
@ -338,12 +365,13 @@ const showText = function(allMessages, showAll) {
|
|
|
|
clearTimeout(timeouts.animID);
|
|
|
|
clearTimeout(timeouts.animID);
|
|
|
|
timeouts.animID = undefined;
|
|
|
|
timeouts.animID = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const endX = Bangle.appRect.x2 - (Bangle.appRect.w / 2);
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
return new Promise((resolve, _reject) => {
|
|
|
|
return new Promise((resolve, _reject) => {
|
|
|
|
let animate = () => {
|
|
|
|
let animate = () => {
|
|
|
|
msgBox.xOffset += step
|
|
|
|
msgBox.xOffset += step;
|
|
|
|
drawRightBackground();
|
|
|
|
drawRightBackground();
|
|
|
|
if (msgBox.xOffset >= Bangle.appRect.x2) {
|
|
|
|
if (msgBox.xOffset >= endX) {
|
|
|
|
return resolve();
|
|
|
|
return resolve();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msgBox.draw();
|
|
|
|
msgBox.draw();
|
|
|
|
@ -357,42 +385,62 @@ const showText = function(allMessages, showAll) {
|
|
|
|
|
|
|
|
|
|
|
|
let firstTouch = true;
|
|
|
|
let firstTouch = true;
|
|
|
|
const handler = function(e) {
|
|
|
|
const handler = function(e) {
|
|
|
|
if (switching) return; // don't repond to touch while we are animating
|
|
|
|
if (e.b === 0) {
|
|
|
|
if (firstTouch) {
|
|
|
|
firstTouch = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("top of handler: first touch = ", firstTouch);
|
|
|
|
|
|
|
|
// console.log("top of handler: e = ", e);
|
|
|
|
|
|
|
|
if (switching) return; // don't respond to touch while we are animating
|
|
|
|
|
|
|
|
if (firstTouch && e.b === 1) {
|
|
|
|
|
|
|
|
if (buzzing) {
|
|
|
|
|
|
|
|
require("messages").stopBuzz();
|
|
|
|
|
|
|
|
buzzing = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
setBusy();
|
|
|
|
setBusy();
|
|
|
|
|
|
|
|
let idx = Bangle.MESSAGES.findIndex(m => m.id === msgBoxes[messageNum].msg.id); // TODO maybe we don't to do this check every time
|
|
|
|
|
|
|
|
if (idx >= 0) delete Bangle.MESSAGES[idx].new;
|
|
|
|
|
|
|
|
msgBoxes[messageNum].clearNew();
|
|
|
|
|
|
|
|
console.log("do tests");
|
|
|
|
|
|
|
|
console.log("dy, dx", e.dy, e.dx);
|
|
|
|
|
|
|
|
console.log("e", e);
|
|
|
|
|
|
|
|
if (Math.abs(e.dy) > Math.abs(e.dx)) {
|
|
|
|
|
|
|
|
firstTouch = false;
|
|
|
|
|
|
|
|
console.log("up down");
|
|
|
|
if (e.dy > 0 && msgBoxes[messageNum].top) {
|
|
|
|
if (e.dy > 0 && msgBoxes[messageNum].top) {
|
|
|
|
firstTouch = false;
|
|
|
|
|
|
|
|
mode = "prev";
|
|
|
|
mode = "prev";
|
|
|
|
} else if (e.dy < 0 && msgBoxes[messageNum].bottom) {
|
|
|
|
} else if (msgBoxes[messageNum].bottom) { // e.dy will be < 0 here
|
|
|
|
firstTouch = false;
|
|
|
|
|
|
|
|
mode = "next";
|
|
|
|
mode = "next";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mode = "scroll";
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if (Math.abs(e.dx) > Math.abs(e.dy)) {
|
|
|
|
} else if (Math.abs(e.dx) > Math.abs(e.dy)) {
|
|
|
|
firstTouch = false;
|
|
|
|
firstTouch = false;
|
|
|
|
if (e.dx < 0) mode = "left";
|
|
|
|
console.log("left right");
|
|
|
|
else mode = "right";
|
|
|
|
if (e.dx < 0) {
|
|
|
|
} else if (Math.abs(e.dy) > 0) {
|
|
|
|
mode = "left";
|
|
|
|
firstTouch = false;
|
|
|
|
} else {
|
|
|
|
mode = "scroll";
|
|
|
|
mode = "right";
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mode = undefined;
|
|
|
|
mode = undefined;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e.b == 0) { // released finger, reset firstTouch for next time
|
|
|
|
if (mode == "scroll") scrollHandler(e);
|
|
|
|
console.log("should call checkForNewMessages()");
|
|
|
|
|
|
|
|
checkForNewMessages();
|
|
|
|
|
|
|
|
firstTouch = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
delete messageList[messageNum].new;
|
|
|
|
|
|
|
|
msgBoxes[messageNum].clearNew();
|
|
|
|
|
|
|
|
if (mode == "scroll") scrollHandler(e.dy);
|
|
|
|
|
|
|
|
else if (mode == "left") leftHandler(e); // remove from phone and watch
|
|
|
|
else if (mode == "left") leftHandler(e); // remove from phone and watch
|
|
|
|
else if (mode == "right") rightHandler(e); // remove from watch only
|
|
|
|
else if (mode == "right") rightHandler(e); // remove from watch only
|
|
|
|
else if (mode == "next") nextHandler(e.dy);
|
|
|
|
else if (mode == "next") nextHandler(e);
|
|
|
|
else if (mode == "prev") prevHandler(e.dy);
|
|
|
|
else if (mode == "prev") prevHandler(e);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const nextHandler = function(dy) {
|
|
|
|
const nextHandler = function(e) {
|
|
|
|
|
|
|
|
console.log("nextHandler");
|
|
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
|
|
if (e.b == 0) {
|
|
|
|
|
|
|
|
console.log("firstTouch = ", firstTouch);
|
|
|
|
|
|
|
|
checkForNewMessages();
|
|
|
|
|
|
|
|
// firstTouch = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (messageNum == msgBoxes.length - 1) return; // already on last message
|
|
|
|
if (messageNum == msgBoxes.length - 1) return; // already on last message
|
|
|
|
switching = true;
|
|
|
|
switching = true;
|
|
|
|
toNext().then(() => {
|
|
|
|
toNext().then(() => {
|
|
|
|
@ -400,7 +448,11 @@ const showText = function(allMessages, showAll) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const prevHandler = function(dy) {
|
|
|
|
const prevHandler = function(e) {
|
|
|
|
|
|
|
|
if (e.b == 0) {
|
|
|
|
|
|
|
|
checkForNewMessages();
|
|
|
|
|
|
|
|
// firstTouch = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (messageNum == 0) return; // already on first message
|
|
|
|
if (messageNum == 0) return; // already on first message
|
|
|
|
switching = true;
|
|
|
|
switching = true;
|
|
|
|
toPrev().then(() => {
|
|
|
|
toPrev().then(() => {
|
|
|
|
@ -411,6 +463,7 @@ const showText = function(allMessages, showAll) {
|
|
|
|
const leftHandler = function(e) {
|
|
|
|
const leftHandler = function(e) {
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
if (e.b == 0) {
|
|
|
|
if (e.b == 0) {
|
|
|
|
|
|
|
|
// firstTouch = true;
|
|
|
|
if (msgBox.xOffset > -swipeThreshold) {
|
|
|
|
if (msgBox.xOffset > -swipeThreshold) {
|
|
|
|
msgBox.xOffset = 0;
|
|
|
|
msgBox.xOffset = 0;
|
|
|
|
msgBox.draw();
|
|
|
|
msgBox.draw();
|
|
|
|
@ -418,9 +471,11 @@ const showText = function(allMessages, showAll) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
switching = true;
|
|
|
|
switching = true;
|
|
|
|
animateToLeft().then(() => {
|
|
|
|
animateToLeft().then(() => {
|
|
|
|
|
|
|
|
g.setBgColor(g.theme.bg);
|
|
|
|
dismissOnPhone();
|
|
|
|
dismissOnPhone();
|
|
|
|
removeMessage();
|
|
|
|
removeMessage();
|
|
|
|
switching = false;
|
|
|
|
switching = false;
|
|
|
|
|
|
|
|
checkForNewMessages();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -435,6 +490,7 @@ const showText = function(allMessages, showAll) {
|
|
|
|
const rightHandler = function(e) {
|
|
|
|
const rightHandler = function(e) {
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
const msgBox = msgBoxes[messageNum];
|
|
|
|
if (e.b == 0) {
|
|
|
|
if (e.b == 0) {
|
|
|
|
|
|
|
|
// firstTouch = true;
|
|
|
|
if (msgBox.xOffset < swipeThreshold) {
|
|
|
|
if (msgBox.xOffset < swipeThreshold) {
|
|
|
|
msgBox.xOffset = 0;
|
|
|
|
msgBox.xOffset = 0;
|
|
|
|
msgBox.draw();
|
|
|
|
msgBox.draw();
|
|
|
|
@ -442,8 +498,10 @@ const showText = function(allMessages, showAll) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
switching = true;
|
|
|
|
switching = true;
|
|
|
|
animateToRight().then(() => {
|
|
|
|
animateToRight().then(() => {
|
|
|
|
|
|
|
|
g.setBgColor(g.theme.bg);
|
|
|
|
removeMessage();
|
|
|
|
removeMessage();
|
|
|
|
switching = false;
|
|
|
|
switching = false;
|
|
|
|
|
|
|
|
checkForNewMessages();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -453,16 +511,21 @@ const showText = function(allMessages, showAll) {
|
|
|
|
drawRightBackground();
|
|
|
|
drawRightBackground();
|
|
|
|
msgBox.draw();
|
|
|
|
msgBox.draw();
|
|
|
|
drawFooter();
|
|
|
|
drawFooter();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const scrollHandler = function(dy) {
|
|
|
|
const scrollHandler = function(e) {
|
|
|
|
msgBoxes[messageNum].scroll(dy);
|
|
|
|
if (e.b === 0) {
|
|
|
|
|
|
|
|
// firstTouch = true;
|
|
|
|
|
|
|
|
checkForNewMessages();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msgBoxes[messageNum].scroll(e.dy);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Bangle.setUI({
|
|
|
|
Bangle.setUI({
|
|
|
|
mode: "custom",
|
|
|
|
mode: "custom",
|
|
|
|
drag: e => handler(e),
|
|
|
|
drag: e => handler(e),
|
|
|
|
btn: _e => goBack(),
|
|
|
|
btn: _e => goBack(),
|
|
|
|
|
|
|
|
remove: cleanup
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
msgBoxes[messageNum].draw();
|
|
|
|
msgBoxes[messageNum].draw();
|
|
|
|
@ -470,4 +533,15 @@ const showText = function(allMessages, showAll) {
|
|
|
|
checkForNewMessages();
|
|
|
|
checkForNewMessages();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
showText(Bangle.MESSAGES);
|
|
|
|
if (!Bangle.MESSAGES || !Bangle.MESSAGES.length) {
|
|
|
|
|
|
|
|
Bangle.MESSAGES = require("messages").getMessages();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Bangle.MESSAGES.length) showNoMessages();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Bangle.notify) { // this is set in messagecenter.notify.js
|
|
|
|
|
|
|
|
buzzing = true;
|
|
|
|
|
|
|
|
require("messages").buzz(Bangle.MESSAGES[0].src);
|
|
|
|
|
|
|
|
delete Bangle.notify;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showText(true);
|
|
|
|
|