Skip to content

Commit 35ed328

Browse files
committed
ANDROID: Removes path navigation to show unified view of available folders
1 parent 33a45cf commit 35ed328

File tree

3 files changed

+41
-47
lines changed

3 files changed

+41
-47
lines changed

src/platform/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
applicationId 'net.sourceforge.smallbasic'
1010
minSdkVersion 16
1111
targetSdkVersion 30
12-
versionCode 44
12+
versionCode 45
1313
versionName "12.22"
1414
resConfigs "en"
1515
}

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

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ const aboutId = "_about"
3434
const backId = "_back"
3535
const scratchId = "_scratch"
3636
const scratch_file = HOME + "/scratch.bas"
37-
const labelTemp = chr(183) + "Temporary Files" + chr(183)
38-
const labelProj = chr(183) + "Project Files" + chr(183)
3937

4038
func mk_menu(value, lab, x)
4139
local bn
@@ -256,7 +254,7 @@ end
256254

257255
sub loadFileList(path, byref basList)
258256
erase basList
259-
local emptyNode, ext_storage, int_storage
257+
local emptyNode
260258

261259
func walker(node)
262260
if (node.depth==0) then
@@ -270,38 +268,43 @@ sub loadFileList(path, byref basList)
270268
endif
271269
return node.depth == 0
272270
end
273-
dirwalk path, "", use walker(x)
274-
275-
if (path = "/" && is_android) then
276-
ext_storage = env("EXTERNAL_DIR")
277-
if (len(ext_storage) > 0) then
278-
emptyNode.name = mid(ext_storage, 2)
279-
emptyNode.dir = true
280-
emptyNode.size = ""
281-
emptyNode.mtime = 0
282-
basList << emptyNode
283-
endif
284-
int_storage = env("INTERNAL_DIR")
285-
if (len(int_storage) > 0 && int_storage != ext_storage) then
286-
emptyNode.name = mid(int_storage, 2)
287-
emptyNode.dir = true
288-
emptyNode.size = ""
289-
emptyNode.mtime = 0
290-
basList << emptyNode
291-
endif
271+
272+
func androidWalker(node)
273+
if (node.depth == 0 && node.dir == 0 && lower(right(node.name, 4)) == ".bas") then
274+
basList << node
275+
endif
276+
return node.depth == 0
277+
end
278+
279+
if (is_android) then
280+
path = env("EXTERNAL_DIR")
281+
if (len(path) > 0) then
282+
dirwalk path, "", use androidWalker(x)
283+
endif
284+
path = env("INTERNAL_DIR")
285+
if (len(path) > 0) then
286+
dirwalk path, "", use androidWalker(x)
287+
endif
288+
path = env("LEGACY_DIR")
289+
if (len(path) > 0) then
290+
dirwalk path, "", use androidWalker(x)
291+
endif
292+
else
293+
dirwalk path, "", use walker(x)
292294
endif
293295
end
294296

295297
sub listFiles(byref frm, path, sortDir, byref basList)
296-
local lastItem, bn, abbr, gap, n, lab, name, txtcol, i, pathx
298+
local lastItem, bn, abbr, gap, n, lab, name, txtcol, i
297299
local name_col = colNav
298300
local size_col = colNav
299301
local date_col = colNav
300302

301-
if (right(path, 1) != "/") then
302-
path += "/"
303-
endif
303+
sub fix_path
304+
if (right(path, 1) != "/") then path += "/"
305+
end
304306

307+
fix_path
305308
loadFileList(path, basList)
306309
select case sortDir
307310
case 0
@@ -323,9 +326,9 @@ sub listFiles(byref frm, path, sortDir, byref basList)
323326
date_col = colNav2
324327
end select
325328

326-
func mk_bn(id, labText, labCol)
329+
func mk_bn(value, labText, labCol)
327330
local bn
328-
bn.value = id
331+
bn.value = value
329332
bn.label = labText
330333
bn.color = labCol
331334
bn.x = 3
@@ -341,28 +344,15 @@ sub listFiles(byref frm, path, sortDir, byref basList)
341344
frm.inputs << bn
342345
end
343346

344-
sub mk_link(id, labText, labCol, x, y)
345-
local bn = mk_bn(id, labText, labCol)
347+
sub mk_link(value, labText, labCol, x, y)
348+
local bn = mk_bn(value, labText, labCol)
346349
bn.type = "link"
347350
bn.x = x
348351
bn.y = y
349352
frm.inputs << bn
350353
end
351354

352355
if (is_android) then
353-
pathx = mid(path, 1, len(path) - 1)
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)
357-
elseif (pathx == env("EXTERNAL_DIR")) then
358-
mk_label(labelProj, colText, 3, -lineSpacing)
359-
mk_link(env("INTERNAL_DIR"), "[Temporary Files]", colDir, -char_w, -1)
360-
else
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)
365-
endif
366356
mk_link(sortNameId, "[Name]", name_col, 0, -linespacing)
367357
else
368358
mk_label("Files in " + path, colText, 3, -lineSpacing)
@@ -381,6 +371,10 @@ sub listFiles(byref frm, path, sortDir, byref basList)
381371
node = basList(i)
382372
txtcol = iff(node.dir, colDir, colFile)
383373
name = node.name
374+
if (node.path) then
375+
path = node.path
376+
fix_path
377+
endif
384378
if (abbr) then
385379
bn = mk_bn(path + name, name, txtcol)
386380
bn.type = "link"

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ private void copy(File src, File dst) throws IOException {
729729
}
730730

731731
private String execBuffer(final String buffer, final String name, boolean run) throws IOException {
732-
File outputFile = getApplication().getFileStreamPath(name);
732+
File outputFile = new File(getInternalStorage(), name);
733733
BufferedWriter output = new BufferedWriter(new FileWriter(outputFile));
734734
output.write(buffer);
735735
output.close();
@@ -767,7 +767,7 @@ private void execScheme(final String data) {
767767
}
768768

769769
private void execStream(final String line, DataInputStream inputStream) throws IOException {
770-
File outputFile = getApplication().getFileStreamPath(WEB_BAS);
770+
File outputFile = new File(getInternalStorage(), WEB_BAS);
771771
BufferedWriter output = new BufferedWriter(new FileWriter(outputFile));
772772
Log.i(TAG, "execStream() entered");
773773
String nextLine = line;
@@ -992,7 +992,7 @@ private void runServer(final int socketNum, final String token) throws IOExcepti
992992
execBuffer(buffer, WEB_BAS, postData.get("run") != null);
993993
sendResponse(socket, buildRunForm(buffer, token));
994994
} else {
995-
File inputFile = getApplication().getFileStreamPath(WEB_BAS);
995+
File inputFile = new File(getInternalStorage(), WEB_BAS);
996996
sendResponse(socket, buildRunForm(readBuffer(inputFile), token));
997997
}
998998
} else {

0 commit comments

Comments
 (0)