Skip to content

Commit

Permalink
New app!
Browse files Browse the repository at this point in the history
  • Loading branch information
tonykakuuu committed Feb 4, 2025
1 parent 9b22417 commit f5e6842
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/txtreader/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: New App!
20 changes: 20 additions & 0 deletions apps/txtreader/README.md
Original file line number Diff line number Diff line change
@@ -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/>
1 change: 1 addition & 0 deletions apps/txtreader/app-icon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions apps/txtreader/app.js
Original file line number Diff line number Diff line change
@@ -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();
16 changes: 16 additions & 0 deletions apps/txtreader/metadata.json
Original file line number Diff line number Diff line change
@@ -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 added apps/txtreader/screenshot_txtreader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/txtreader/txtreader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/txtreader/txtreader_transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f5e6842

Please sign in to comment.