New app!
parent
9b224171e1
commit
f5e6842019
|
|
@ -0,0 +1 @@
|
||||||
|
0.01: New App!
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
# txtreader
|
||||||
|
|
||||||
|
Very basic text reader with an integrated file selector.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- select files from storage (.txt)
|
||||||
|
- display their contents
|
||||||
|
- browse pages
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
|
Bangle.js 2
|
||||||
|
- tap the right side of the screen to flip to the next page
|
||||||
|
- tap the left side of the screen to flip to the previous page
|
||||||
|
- exit by pressing the physical button
|
||||||
|
|
||||||
|
## Creator
|
||||||
|
|
||||||
|
<https://topkekker.rip/>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
require("heatshrink").decompress(atob("mEwwkCkQA/AH4A/AAcosd2m9jw04AQlyC5WL1e63YCG3lUC5WPj/x/8f+H/h4CBj/3jYXLv/3/4CCt4FC/IXM/4AI/YXk/WZzOfCgWfAoIXN/F3u9/C4V/AoIvUI6H3F4p3oC6/73e734XTR4wXQ/vd7vfC6f85gAG55HQAAppBC5n5xAAGz4vmzIAGF/33F49/C5v6F4+vC5rrFd6JHCv4XTI4WfF6lms1vF6mq1WvC6Z3WxfdABHVugXKlFUogAHoVCC5QA/AH4A6A"))
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
function showFileSelector() {
|
||||||
|
let files = require("Storage").list().filter(f => f.endsWith('.txt'));
|
||||||
|
|
||||||
|
let menuItems = {};
|
||||||
|
files.forEach(file => {
|
||||||
|
menuItems[file] = () => {
|
||||||
|
E.showPrompt(`Select ${file}?`).then(confirm => {
|
||||||
|
if (confirm) {
|
||||||
|
onFileSelected(file);
|
||||||
|
} else {
|
||||||
|
showFileSelector();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
menuItems['< Back'] = () => { load(); }; // Go back to the launcher or previous screen
|
||||||
|
E.showMenu(menuItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFileSelected(file) {
|
||||||
|
|
||||||
|
var text = require("Storage").read(file);
|
||||||
|
|
||||||
|
function displayText(text, startLine, pageNumber) {
|
||||||
|
g.clear();
|
||||||
|
g.setFont("6x8", 1);
|
||||||
|
g.setColor(1);
|
||||||
|
g.drawString("Page " + pageNumber, 10, 2);
|
||||||
|
g.drawString(file, g.getWidth()-file.length*6, 2);
|
||||||
|
|
||||||
|
var lines = text.split("\n");
|
||||||
|
var y = 15; // Text start, top row reserved for page number
|
||||||
|
var currentLine = startLine || 0;
|
||||||
|
var linesDisplayed = 0; //Per page
|
||||||
|
|
||||||
|
for (var i = currentLine; i < lines.length; i++) {
|
||||||
|
var wrappedLines = g.wrapString(lines[i], g.getWidth() - 20);
|
||||||
|
for (var j = 0; j < wrappedLines.length; j++) {
|
||||||
|
g.drawString(wrappedLines[j], 10, y);
|
||||||
|
y += 10; // Move down for the next line
|
||||||
|
linesDisplayed++;
|
||||||
|
if (y >= g.getHeight() - 10) {
|
||||||
|
// If we run out of space, stop drawing
|
||||||
|
return { nextStartLine: i , linesDisplayed: linesDisplayed };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null; // No more lines to display
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentStartLine = 0;
|
||||||
|
var currentPage = 1;
|
||||||
|
var history = []; // Track the start line and lines displayed for each page
|
||||||
|
|
||||||
|
// Initial display
|
||||||
|
var result = displayText(text, currentStartLine, currentPage);
|
||||||
|
history.push({ startLine: currentStartLine, linesDisplayed: result.linesDisplayed });
|
||||||
|
|
||||||
|
// Handle touch events
|
||||||
|
Bangle.on('touch', function(button) {
|
||||||
|
if (button === 2) { // Right side of the screen (next page)
|
||||||
|
var nextStartLine = displayText(text, currentStartLine, currentPage + 1);
|
||||||
|
if (nextStartLine !== null) {
|
||||||
|
currentStartLine = nextStartLine.nextStartLine;
|
||||||
|
currentPage++;
|
||||||
|
history.push({ startLine: currentStartLine, linesDisplayed: nextStartLine.linesDisplayed });
|
||||||
|
displayText(text, currentStartLine, currentPage);
|
||||||
|
} else {
|
||||||
|
currentStartLine = 0;
|
||||||
|
currentPage = 1;
|
||||||
|
history = [{ startLine: currentStartLine, linesDisplayed: result.linesDisplayed }];
|
||||||
|
displayText(text, currentStartLine, currentPage);
|
||||||
|
}
|
||||||
|
} else if (button === 1) { // Left side of the screen (previous page)
|
||||||
|
if (currentPage > 1) {
|
||||||
|
// Go back to the previous page
|
||||||
|
history.pop(); // Remove the current page from history
|
||||||
|
var previousPage = history[history.length - 1];
|
||||||
|
currentStartLine = previousPage.startLine;
|
||||||
|
currentPage--;
|
||||||
|
displayText(text, currentStartLine, currentPage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
showFileSelector();
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"id": "txtreader",
|
||||||
|
"name": "txtreader",
|
||||||
|
"shortName": "txtreader",
|
||||||
|
"version": "0.01",
|
||||||
|
"description": "Basic text reader with pages and a file selector.",
|
||||||
|
"icon": "txtreader.png",
|
||||||
|
"screenshots": [{"url":"screenshot_txtreader.png"}],
|
||||||
|
"tags": "app,tool",
|
||||||
|
"supports": ["BANGLEJS2"],
|
||||||
|
"readme": "README.md",
|
||||||
|
"storage": [
|
||||||
|
{"name":"txtreader.app.js","url":"app.js"},
|
||||||
|
{"name":"txtreader.img","url":"app-icon.js","evaluate":true}
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in New Issue