1
0
Fork 0

Add double tap to save positions

master
stweedo 2023-06-17 00:54:40 -05:00
parent e94fc4368a
commit a87e867681
1 changed files with 42 additions and 18 deletions

View File

@ -4,13 +4,18 @@
let locale = require("locale"); let locale = require("locale");
let date = new Date(); let date = new Date();
let bgImage; let bgImage;
let configNumber = (storage.readJSON("boxclk.json", 1) || {}).selectedConfig || 0; let configNumber = (storage.readJSON("boxclk.json", 1) || {}).selectedConfig || 0;
let fileName = 'boxclk' + (configNumber > 0 ? `-${configNumber}` : '') + '.json'; let fileName = 'boxclk' + (configNumber > 0 ? `-${configNumber}` : '') + '.json';
let boxesConfig = storage.readJSON(fileName, 1) || {}; let boxesConfig = storage.readJSON(fileName, 1) || {};
let boxes = {}; let boxes = {};
let boxPos = {}; let boxPos = {};
let isDragging = {}; let isDragging = {};
let wasDragging = {}; let wasDragging = {};
let doubleTapTimer = null;
let saveIcon = require("heatshrink").decompress(atob("mEwwkEogA/AHdP/4AK+gWVDBQWNAAIuVGBAIB+UQdhMfGBAHBCxUAgIXHIwPyCxQwEJAgXB+MAl/zBwQGBn8ggQjBGAQXG+EA/4XI/8gBIQXTGAMPC6n/C6HzkREBC6YACC6QAFC57aHCYIXOOgLsEn4XPABIX/C6vykQAEl6/WgCQBC5imFAAT2BC5gCBI4oUCC5x0IC/4X/C4K8Bl4XJ+TCCC4wKBABkvC4tEEoMQCxcBB4IWEC4XyDBUBFwIXGJAIAOIwowDABoWGGB4uHDBwWJAH4AzA"));
// 2. Graphical and visual configurations // 2. Graphical and visual configurations
let w = g.getWidth(); let w = g.getWidth();
@ -19,7 +24,7 @@
let enableSuffix = true; let enableSuffix = true;
let drawTimeout; let drawTimeout;
// 3. Handlers // 3. Touchscreen Handlers
let touchHandler; let touchHandler;
let dragHandler; let dragHandler;
@ -170,25 +175,44 @@
let setup = function() { let setup = function() {
// Define the touchHandler function // Define the touchHandler function
touchHandler = function(zone, e) { touchHandler = function(zone, e) {
wasDragging = Object.assign({}, isDragging); if (doubleTapTimer) {
let boxTouched = false; clearTimeout(doubleTapTimer);
Object.keys(boxes).forEach((boxKey) => { doubleTapTimer = null;
if (touchInText(e, boxes[boxKey], boxKey)) { Object.keys(boxPos).forEach((boxKey) => {
isDragging[boxKey] = true; boxesConfig[boxKey].boxPos.x = boxPos[boxKey].x / w;
wasDragging[boxKey] = true; boxesConfig[boxKey].boxPos.y = boxPos[boxKey].y / h;
boxTouched = true;
}
});
if (!boxTouched) {
Object.keys(isDragging).forEach((boxKey) => {
isDragging[boxKey] = false;
}); });
require("widget_utils").show(); storage.write(fileName, JSON.stringify(boxesConfig));
require("widget_utils").swipeOn(); g.drawImage(saveIcon, w / 2 - 24, h / 2 - 24);
} // Display save icon for 2 seconds
if (Object.values(wasDragging).some(Boolean) || !boxTouched) { setTimeout(() => {
draw(boxes); g.clearRect(w / 2 - 24, h / 2 - 24, w / 2 + 24, h / 2 + 24);
draw(boxes);
}, 2000);
return;
} }
doubleTapTimer = setTimeout(() => {
doubleTapTimer = null;
wasDragging = Object.assign({}, isDragging);
let boxTouched = false;
Object.keys(boxes).forEach((boxKey) => {
if (touchInText(e, boxes[boxKey], boxKey)) {
isDragging[boxKey] = true;
wasDragging[boxKey] = true;
boxTouched = true;
}
});
if (!boxTouched) {
Object.keys(isDragging).forEach((boxKey) => {
isDragging[boxKey] = false;
});
require("widget_utils").show();
require("widget_utils").swipeOn();
}
if (Object.values(wasDragging).some(Boolean) || !boxTouched) {
draw(boxes);
}
}, 300); // Increase or decrease this value based on the desired double tap timing
}; };
// Define the dragHandler function // Define the dragHandler function