Add setting to select swipe guesture type

pull/2866/head
v-crispadvice 2023-07-09 19:29:00 +03:00
parent 8d2c14f5b8
commit 40c90ffb9d
4 changed files with 51 additions and 25 deletions

View File

@ -10,7 +10,7 @@ Configuration:
4. Add ".json" to the end of the Trello board URL and refresh page 4. Add ".json" to the end of the Trello board URL and refresh page
5. Find your list ID 5. Find your list ID
6. Save list ID to the "flashcards.settings.json" file on your watch, e.g.: 6. Save list ID to the "flashcards.settings.json" file on your watch, e.g.:
{"listId":"65942f7b27z68000996ddc00","fontSize":1,"textSize":9} {"listId":"65942f7b27z68000996ddc00","fontSize":1,"cardWidth":9,"swipeGesture":0}
7. Connect phone with Gadgetbridge to the watch 7. Connect phone with Gadgetbridge to the watch
8. Enable "Allow Internet Access" in Gadgetbridge 8. Enable "Allow Internet Access" in Gadgetbridge
9. On the watch go to Settings -> Apps -> Flash Cards -> Get from Trello 9. On the watch go to Settings -> Apps -> Flash Cards -> Get from Trello

View File

@ -18,17 +18,20 @@ let cardIndex = 0;
let backSide = false; let backSide = false;
let drawTimeout = undefined; let drawTimeout = undefined;
let fontSizes = ["15%","20%","25%"]; let fontSizes = ["15%","20%","25%"];
let lastDragX = 0;
let lastDragY = 0;
let settings = Object.assign({ let settings = Object.assign({
listId: "", listId: "",
fontSize: 1, fontSize: 1,
textSize: 9 cardWidth: 9,
swipeGesture: 0
}, storage.readJSON(CARD_SETTINGS_FILE, true) || {}); }, storage.readJSON(CARD_SETTINGS_FILE, true) || {});
// Cards data // Cards data
function wordWrap(str, maxLength) { function wordWrap(str, maxLength) {
if (maxLength == undefined) { if (maxLength == undefined) {
maxLength = settings.textSize; maxLength = settings.cardWidth;
} }
let res = ''; let res = '';
while (str.length > maxLength) { while (str.length > maxLength) {
@ -116,6 +119,17 @@ function draw() {
queueDraw(); queueDraw();
} }
function swipeCard(forward)
{
if(forward) {
cardIndex = (cardIndex + 1) % cards.length;
}
else if(--cardIndex < 0) {
cardIndex = cards.length - 1;
}
drawCard();
}
// Handle a touch: swap card side // Handle a touch: swap card side
function handleTouch(zone, event) { function handleTouch(zone, event) {
backSide = !backSide; backSide = !backSide;
@ -123,23 +137,27 @@ function handleTouch(zone, event) {
Bangle.buzz(SWAP_SIDE_BUZZ_MILLISECONDS); Bangle.buzz(SWAP_SIDE_BUZZ_MILLISECONDS);
} }
// Handle a drag event: cycle cards // Handle a stroke event: cycle cards
function handleDrag(event) { function handleStroke(event) {
let first_x = event.xy[0]; let first_x = event.xy[0];
let last_x = event.xy[event.xy.length - 2]; let last_x = event.xy[event.xy.length - 2];
let xdiff = last_x - first_x; swipeCard((last_x - first_x) > 0);
/* }
let first_y = event.xy[1];
let last_y = event.xy[event.xy.length - 1]; // Handle a drag event: cycle cards
let ydiff = last_y - first_y; function handleDrag(event) {
*/ let isFingerReleased = (event.b === 0);
if(xdiff > 0) { if(isFingerReleased) {
cardIndex = (cardIndex + 1) % cards.length; let isHorizontalDrag = (Math.abs(lastDragX) >= Math.abs(lastDragY)) &&
(lastDragX !== 0);
if(isHorizontalDrag) {
swipeCard(lastDragX > 0);
}
} }
else if(--cardIndex < 0) { else {
cardIndex = cards.length - 1; lastDragX = event.dx;
lastDragY = event.dy;
} }
drawCard();
} }
@ -149,7 +167,7 @@ Bangle.loadWidgets();
loadLocalCards(); loadLocalCards();
Bangle.on("touch", handleTouch); Bangle.on("touch", handleTouch);
Bangle.on("stroke", handleDrag); if (settings.swipeGesture) { Bangle.on("drag", handleDrag); } else { Bangle.on("stroke", handleStroke); }
// On start: display the first card // On start: display the first card
g.clear(); g.clear();
@ -160,5 +178,5 @@ Bangle.setUI({mode:"clock", remove:function() {
if (drawTimeout) clearTimeout(drawTimeout); if (drawTimeout) clearTimeout(drawTimeout);
drawTimeout = undefined; drawTimeout = undefined;
Bangle.removeListener("touch", handleTouch); Bangle.removeListener("touch", handleTouch);
Bangle.removeListener("stroke", handleDrag); if (settings.swipeGesture) { Bangle.removeListener("drag", handleDrag);} else { Bangle.removeListener("stroke", handleStroke); }
}}); }});

View File

@ -1 +1 @@
{"listId":"","fontSize":1,"textSize":9} {"listId":"","fontSize":1,"cardWidth":9,"swipeGesture":0}

View File

@ -9,27 +9,35 @@
var settings = Object.assign({ var settings = Object.assign({
listId: "", listId: "",
fontSize: 1, fontSize: 1,
textSize: 9 cardWidth: 9,
swipeGesture: 0
}, storage.readJSON(settingsFile, true) || {}); }, storage.readJSON(settingsFile, true) || {});
function writeSettings() { function writeSettings() {
storage.writeJSON(settingsFile, settings); storage.writeJSON(settingsFile, settings);
} }
const fontSizes = ["15%","20%","25%"]; const fontSizes = [/*LANG*/"Small",/*LANG*/"Medium",/*LANG*/"Large"];
const swipeGestures = [/*LANG*/"Stroke",/*LANG*/"Drag"];
var settingsMenu = { var settingsMenu = {
"" : { "title" : "Flash Cards" }, "" : { "title" : "Flash Cards" },
"< Back" : () => back(), "< Back" : () => back(),
/*LANG*/"Font Size": { /*LANG*/"Font size": {
value: settings.fontSize, value: settings.fontSize,
min: 0, max: 2, wrap: true, min: 0, max: 2, wrap: true,
format: v => fontSizes[v], format: v => fontSizes[v],
onchange: v => { settings.fontSize = v; writeSettings(); } onchange: v => { settings.fontSize = v; writeSettings(); }
}, },
/*LANG*/"Text Size": { /*LANG*/"Card width": {
value: settings.textSize, value: settings.cardWidth,
min: 5, max: 14, min: 5, max: 14,
onchange: v => { settings.textSize = v; writeSettings(); } onchange: v => { settings.cardWidth = v; writeSettings(); }
},
/*LANG*/"Swipe gesture": {
value: settings.swipeGesture,
min: 0, max: 1, wrap: true,
format: v => swipeGestures[v],
onchange: v => { settings.swipeGesture = v; writeSettings(); }
}, },
/*LANG*/"Get from Trello": () => { /*LANG*/"Get from Trello": () => {
if (!storage.read(settingsFile)) { writeSettings();} if (!storage.read(settingsFile)) { writeSettings();}