Skip to content

Commit

Permalink
Merge remote-tracking branch 'tonykakuuu/master' into app-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
thyttan committed Feb 7, 2025
2 parents 25c9ece + a339c9f commit 248cb88
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(); };
E.showMenu(menuItems);
}

function onFileSelected(file) {
const chunkSize = 1024;
let currentOffset = 0;
let currentPage = 1;
let history = [];

function displayText(offset, pageNumber) {
g.clear();
g.setFont("6x8", 1);
g.setColor(1);
g.drawString("Page " + pageNumber, 10, 2);
//g.drawString("Offset " + offset, 60, 2);
g.drawString(file, g.getWidth() - file.length * 6, 2);

var text = require("Storage").read(file, offset, chunkSize);
var lines = text.split("\n");
var y = 15; // Text start, top row reserved for page number
var linesDisplayed = 0; // Lines per page
var totalCharsDisplayed = 0; // Total characters per page

for (var i = 0; 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++;
totalCharsDisplayed += wrappedLines[j].length + (j < wrappedLines.length - 1 ? 0 : 1); // Add newline character for the last wrapped line
if (y >= g.getHeight() - 10) {
// If we run out of space, stop drawing
return { nextOffset: offset + totalCharsDisplayed, linesDisplayed: linesDisplayed };
}
}
}
return null; // No more lines to display
}

// Initial display
var result = displayText(currentOffset, currentPage);
history.push({ offset: currentOffset, linesDisplayed: result.linesDisplayed });

// Handle touch events
Bangle.on('touch', function(button) {
if (button === 2) { // Right side of the screen (next page)
var nextOffset = displayText(currentOffset, currentPage + 1);
if (nextOffset !== null) {
currentOffset = nextOffset.nextOffset;
currentPage++;
history.push({ offset: currentOffset, linesDisplayed: nextOffset.linesDisplayed });
displayText(currentOffset, currentPage);
} else {
currentOffset = 0;
currentPage = 1;
history = [{ offset: currentOffset, linesDisplayed: result.linesDisplayed }];
displayText(currentOffset, currentPage);
}
} else if (button === 1) { // Left side of the screen (previous page)
if (currentPage > 1) {
history.pop(); // Remove current page from history
var previousPage = history[history.length - 1];
currentOffset = previousPage.offset;
currentPage--;
displayText(currentOffset, 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 248cb88

Please sign in to comment.