Skip to content

Commit 30270d3

Browse files
committed
ANDROID: file manager webui (wip)
1 parent f6e8b08 commit 30270d3

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.sourceforge.smallbasic;
22

3-
import javax.xml.ws.Response;
43
import java.io.BufferedOutputStream;
54
import java.io.ByteArrayInputStream;
65
import java.io.ByteArrayOutputStream;
@@ -15,7 +14,6 @@
1514
import java.text.DateFormat;
1615
import java.util.ArrayList;
1716
import java.util.Collection;
18-
import java.util.Collections;
1917
import java.util.HashMap;
2018
import java.util.List;
2119
import java.util.Map;
@@ -65,13 +63,27 @@ public void run() {
6563
protected abstract void renameFile(String from, String to) throws IOException;
6664
protected abstract void saveFile(String fileName, byte[] content) throws IOException;
6765

66+
/**
67+
* Return all file names
68+
*/
69+
private Collection<String> getAllFileNames() throws IOException {
70+
Collection<String> result = new ArrayList<>();
71+
for (FileData fileData : getFileData()) {
72+
result.add(fileData.fileName);
73+
}
74+
return result;
75+
}
76+
6877
/**
6978
* Download files button handler
7079
*/
7180
private Response handleDownload(Map<String, Collection<String>> data) throws IOException {
7281
Collection<String> fileNames = data.get("f");
73-
Response result;
7482
if (fileNames == null || fileNames.size() == 0) {
83+
fileNames = getAllFileNames();
84+
}
85+
Response result;
86+
if (fileNames.size() == 0) {
7587
result = handleStatus(false, "File list is empty");
7688
} else if (fileNames.size() == 1) {
7789
// plain text download single file
@@ -534,13 +546,13 @@ void send(Socket socket, String cookie) throws IOException {
534546
String contentLength = "Content-length: " + length + "\r\n";
535547
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
536548
String code = errorCode == SC_OKAY ? SC_OKAY + " OK" : String.valueOf(errorCode);
537-
out.write(("HTTP/1.0 " + code + "\r\n").getBytes());
538-
out.write("Content-type: text/html\r\n".getBytes());
539-
out.write(contentLength.getBytes());
549+
out.write(("HTTP/1.0 " + code + "\r\n").getBytes(UTF_8));
550+
out.write("Content-type: text/html\r\n".getBytes(UTF_8));
551+
out.write(contentLength.getBytes(UTF_8));
540552
if (cookie != null) {
541-
out.write(("Set-Cookie: " + TOKEN + "=" + cookie + "\r\n").getBytes());
553+
out.write(("Set-Cookie: " + TOKEN + "=" + cookie + "\r\n").getBytes(UTF_8));
542554
}
543-
out.write("Server: SmallBASIC for Android\r\n\r\n".getBytes());
555+
out.write("Server: SmallBASIC for Android\r\n\r\n".getBytes(UTF_8));
544556
socket.setSendBufferSize(SEND_SIZE);
545557
int sent = toStream(out);
546558
log("sent " + sent + " bytes");
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "webui",
3+
"version": "1.0.0",
4+
"private": true,
5+
"proxy": "http://localhost:8080",
6+
"dependencies": {
7+
"@emotion/react": "^11.9.3",
8+
"@emotion/styled": "^11.9.3",
9+
"@mui/icons-material": "^5.8.4",
10+
"@mui/material": "^5.9.1",
11+
"@mui/x-data-grid": "^5.14.0",
12+
"npm-check-updates": "^16.0.0",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"react-scripts": "5.0.1"
16+
},
17+
"scripts": {
18+
"start": "react-scripts start",
19+
"build": "react-scripts build && rm ../app/src/main/assets/webui/static/js/main.* && cp -R build/* ../app/src/main/assets/webui/",
20+
"update": "npm update && ncu"
21+
},
22+
"eslintConfig": {
23+
"extends": [
24+
"react-app",
25+
"react-app/jest"
26+
]
27+
},
28+
"browserslist": {
29+
"production": [
30+
">0.2%",
31+
"not dead",
32+
"not op_mini all"
33+
],
34+
"development": [
35+
"last 1 chrome version",
36+
"last 1 firefox version",
37+
"last 1 safari version"
38+
]
39+
}
40+
}

src/platform/android/webui/src/App.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ function GridToolbarDownload(props) {
121121
args += join + "f=" + encodeURIComponent(props.rows[i].fileName);
122122
join = "&";
123123
});
124+
if (props.selections.length === props.rows.length) {
125+
args = "";
126+
}
124127

125128
return !props.selections.length ? null : (
126129
<a download={download} href={`./api/download?${args}`} style={{color: color, textDecoration: 'none'}}>

0 commit comments

Comments
 (0)