Skip to content

Commit 33a45cf

Browse files
committed
ANDROID: limit file navigation to SB based folders
1 parent 65105b2 commit 33a45cf

File tree

4 files changed

+50
-77
lines changed

4 files changed

+50
-77
lines changed

src/platform/android/app/src/main/assets/main.bas

Lines changed: 45 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,8 @@ const aboutId = "_about"
3434
const backId = "_back"
3535
const scratchId = "_scratch"
3636
const scratch_file = HOME + "/scratch.bas"
37-
38-
func mk_bn(value, lab, fg)
39-
local bn
40-
bn.x = 3
41-
bn.y = -lineSpacing
42-
bn.value = value
43-
bn.label = lab
44-
bn.color = fg
45-
return bn
46-
end
37+
const labelTemp = chr(183) + "Temporary Files" + chr(183)
38+
const labelProj = chr(183) + "Project Files" + chr(183)
4739

4840
func mk_menu(value, lab, x)
4941
local bn
@@ -331,63 +323,57 @@ sub listFiles(byref frm, path, sortDir, byref basList)
331323
date_col = colNav2
332324
end select
333325

334-
sub mk_label(labText, labCol)
335-
bn = mk_bn(0, labText, labCol)
326+
func mk_bn(id, labText, labCol)
327+
local bn
328+
bn.value = id
329+
bn.label = labText
330+
bn.color = labCol
331+
bn.x = 3
332+
bn.y = -lineSpacing
333+
return bn
334+
end
335+
336+
sub mk_label(labText, labCol, x, y)
337+
local bn = mk_bn(0, labText, labCol)
336338
bn.type = "label"
339+
bn.x = x
340+
bn.y = y
341+
frm.inputs << bn
342+
end
343+
344+
sub mk_link(id, labText, labCol, x, y)
345+
local bn = mk_bn(id, labText, labCol)
346+
bn.type = "link"
347+
bn.x = x
348+
bn.y = y
337349
frm.inputs << bn
338350
end
339351

340352
if (is_android) then
341353
pathx = mid(path, 1, len(path) - 1)
342-
if (pathx == env("LEGACY_DIR")) then
343-
mk_label("SmallBASIC legacy project files", colText2)
344-
elseif (pathx == env("INTERNAL_DIR")) then
345-
mk_label("Temporary files", colText2)
354+
if (pathx == env("INTERNAL_DIR") || pathx == "/data/data/net.sourceforge.smallbasic/files") then
355+
mk_link(env("EXTERNAL_DIR"), "[Project Files]", colDir, 3, -lineSpacing)
356+
mk_label(labelTemp, colText, -char_w, -1)
346357
elseif (pathx == env("EXTERNAL_DIR")) then
347-
mk_label("SmallBASIC project files", colText)
358+
mk_label(labelProj, colText, 3, -lineSpacing)
359+
mk_link(env("INTERNAL_DIR"), "[Temporary Files]", colDir, -char_w, -1)
348360
else
349-
mk_label("Files in " + path, colText)
361+
logprint env("EXTERNAL_DIR")
362+
logprint pathx
363+
mk_link(env("EXTERNAL_DIR"), "[Project Files]", colDir, 3, -lineSpacing)
364+
mk_label("Files in " + path, colText, -char_w, -1)
350365
endif
366+
mk_link(sortNameId, "[Name]", name_col, 0, -linespacing)
351367
else
352-
mk_label("Files in " + path, colText)
368+
mk_label("Files in " + path, colText, 3, -lineSpacing)
369+
mk_link(backId, "[Go up]", colNav, 0, -linespacing)
370+
mk_link(sortNameId, "[Name]", name_col, -(char_w * 8), -1)
353371
endif
354372

355-
bn = mk_bn(backId, "[Go up]", colNav)
356-
bn.type = "link"
357-
bn.x = 0
358-
bn.y = -linespacing
359-
frm.inputs << bn
360-
361-
bn = mk_bn(sortNameId, "[Name]", name_col)
362-
bn.type = "link"
363-
bn.x = -(char_w * 8)
364-
bn.y = -1
365-
frm.inputs << bn
366-
367373
abbr = iff(char_w * 38 > xmax, true, false)
368374
if (not abbr) then
369-
bn = mk_bn(sortSizeId, "[Size]", size_col)
370-
bn.type = "link"
371-
bn.x = -(char_w * 8)
372-
bn.y = -1
373-
frm.inputs << bn
374-
375-
bn = mk_bn(sortDateId, "[Date]", date_col)
376-
bn.type = "link"
377-
bn.x = -(char_w * 6)
378-
bn.y = -1
379-
frm.inputs << bn
380-
endif
381-
382-
if (is_android && pathx != env("EXTERNAL_DIR")) then
383-
bn = mk_bn(env("EXTERNAL_DIR"), "SmallBASIC project files", colDir)
384-
bn.type = "link"
385-
frm.inputs << bn
386-
bn = mk_bn(0, datefmt("YYYY-MM-DD", date), colText)
387-
bn.type = "label"
388-
bn.x = txtw(" ") * 41
389-
bn.y = -1
390-
frm.inputs << bn
375+
mk_link(sortSizeId, "[Size]", size_col, -(char_w * iff(is_android, 23, 8)), -1)
376+
mk_link(sortDateId, "[Date]", date_col, -(char_w * 6), -1)
391377
endif
392378

393379
lastItem = len(basList) - 1
@@ -409,7 +395,6 @@ sub listFiles(byref frm, path, sortDir, byref basList)
409395
bn.type = "link"
410396
if (!node.dir) then bn.isExit = true
411397
frm.inputs << bn
412-
413398
gap = 12 - len(str(node.size))
414399
n = iff(gap > 1, gap, 1)
415400
bn = mk_bn(0, node.size + space(n) + timestamp(node.mtime), colText)
@@ -428,7 +413,7 @@ sub manageFiles()
428413
func fileCmpFunc(l, r)
429414
local f1 = lower(l)
430415
local f2 = lower(r)
431-
return IFF(f1 == f2, 0, IFF(f1 > f2, 1, -1))
416+
return iff(f1 == f2, 0, iff(f1 > f2, 1, -1))
432417
end
433418

434419
func getFiles()
@@ -452,10 +437,10 @@ sub manageFiles()
452437
local abbr = char_w * num_chars > xmax
453438
f.inputs << mk_menu(closeId, "<<", 0)
454439
f.inputs << mk_menu(viewId, "View", menu_gap)
455-
f.inputs << mk_menu(renameId, IFF(abbr, "Ren", "Rename"), menu_gap)
440+
f.inputs << mk_menu(renameId, iff(abbr, "Ren", "Rename"), menu_gap)
456441
f.inputs << mk_menu(newId, "New", menu_gap)
457-
f.inputs << mk_menu(deleteId, IFF(abbr, "Del", "Delete"), menu_gap)
458-
f.inputs << mk_menu(saveasId, IFF(abbr, "SavAs", "Save-As"), menu_gap)
442+
f.inputs << mk_menu(deleteId, iff(abbr, "Del", "Delete"), menu_gap)
443+
f.inputs << mk_menu(saveasId, iff(abbr, "SavAs", "Save-As"), menu_gap)
459444
bn_edit.x = 0
460445
bn_edit.y = char_h + 4
461446
bn_edit.width = xmax
@@ -635,17 +620,6 @@ sub manageFiles()
635620
cls
636621
end
637622

638-
func selectDir(s)
639-
local result = s
640-
if (is_android && s != env("EXTERNAL_DIR") && (s == env("LEGACY_DIR") || s == env("INTERNAL_DIR"))) then
641-
wnd.ask("Would you like to navigate to the SmallBASIC folder instead?", "Temporary file location")
642-
if (wnd.answer == 0) then
643-
result = env("EXTERNAL_DIR")
644-
endif
645-
endif
646-
return result
647-
end
648-
649623
func changeDir(s)
650624
try
651625
chdir s
@@ -712,12 +686,11 @@ sub main
712686
frm.doEvents()
713687

714688
if (isdir(frm.value)) then
715-
cls
716-
frm.value = selectDir(frm.value)
717689
if (changeDir(frm.value)) then
690+
cls
718691
path = frm.value
692+
frm = makeUI(path, sortDir)
719693
endif
720-
frm = makeUI(path, sortDir)
721694
elif frm.value == aboutId then
722695
do_about()
723696
frm = makeUI(path, sortDir)

src/platform/android/jni/display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ bool Graphics::loadFont(const char *name, FT_Face &face, FT_Byte **buffer) {
245245
//
246246
// maapi implementation
247247
//
248-
void maUpdateScreen(void) {
248+
void maUpdateScreen() {
249249
((Graphics *)graphics)->redraw();
250250
}
251251

src/ui/ansiwidget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void AnsiWidget::removeHover() {
283283

284284
void AnsiWidget::removeInputs() {
285285
List_each(FormInput *, it, _back->_inputs) {
286-
FormInput *widget = (FormInput *)(*it);
286+
FormInput *widget = *it;
287287
if (widget == _activeButton) {
288288
_activeButton = NULL;
289289
} else if (widget == _hoverInput) {
@@ -627,7 +627,7 @@ bool AnsiWidget::drawHoverLink(MAEvent &event) {
627627
FormInput *active = NULL;
628628
if (_front->overlaps(event.point.x, event.point.y)) {
629629
List_each(FormInput *, it, _front->_inputs) {
630-
FormInput *widget = (FormInput *)(*it);
630+
FormInput *widget = *it;
631631
if (widget->hasHover() &&
632632
widget->overlaps(event.point, dx, dy)) {
633633
active = widget;
@@ -704,7 +704,7 @@ bool AnsiWidget::setActiveButton(MAEvent &event, Screen *screen) {
704704
if (_front != _screens[MENU_SCREEN] &&
705705
screen->overlaps(event.point.x, event.point.y)) {
706706
List_each(FormInput *, it, screen->_inputs) {
707-
FormInput *widget = (FormInput *)(*it);
707+
FormInput *widget = *it;
708708
bool redraw = false;
709709
if (widget->selected(event.point, screen->_x,
710710
screen->_y - screen->_scrollY, redraw)) {

src/ui/screen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Screen::~Screen() {
5757

5858
// converts ANSI colors to MoSync colors
5959
int Screen::ansiToMosync(long c) {
60-
int result = c;
60+
int result;
6161
if (c < 0) {
6262
result = -c;
6363
} else {

0 commit comments

Comments
 (0)