diff --git a/app/src/main/assets/index.html b/app/src/main/assets/index.html
new file mode 100644
index 0000000..71d739b
--- /dev/null
+++ b/app/src/main/assets/index.html
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+Application : stock-pignon
+Gestion des stocks
+
+Modifier le catalogue
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/stock/pignon/ControlServer.java b/app/src/main/java/com/stock/pignon/ControlServer.java
index 2338840..93a497e 100644
--- a/app/src/main/java/com/stock/pignon/ControlServer.java
+++ b/app/src/main/java/com/stock/pignon/ControlServer.java
@@ -1,6 +1,7 @@
// ControlServer.java
package com.stock.pignon;
+import android.content.Context;
import android.os.Environment;
import fi.iki.elonen.NanoHTTPD;
@@ -13,6 +14,7 @@ import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
+import java.util.Scanner;
/**
* Create a web server to remote management of app assets.
@@ -20,13 +22,16 @@ import java.util.List;
// Inherit what is needed to build a web server
public class ControlServer extends NanoHTTPD {
+ private final Context context;
+
// Assets folders
private final File storageRoot = Environment.getExternalStorageDirectory();
private final File baseDir = new File(storageRoot, Config.EXTERNAL_DIR_NAME);
private final File imagesDir = new File(baseDir, Config.IMAGES_SUBDIR_NAME);
- public ControlServer(int port) {
+ public ControlServer(Context context, int port) {
super(port);
+ this.context = context;
}
/**
@@ -37,33 +42,29 @@ public class ControlServer extends NanoHTTPD {
// Get requested address
String uri = session.getUri();
- switch (uri) {
- case "/download_input":
- return downloadFile(Config.INPUT_JSON_NAME);
-
- case "/output_json":
- return viewFile(Config.OUTPUT_JSON_NAME);
-
- case "/download_output_json":
- return downloadFile(Config.OUTPUT_JSON_NAME);
-
- case "/output_csv":
- return viewFile(Config.OUTPUT_CSV_NAME);
-
- case "/download_output_csv":
- return downloadFile(Config.OUTPUT_CSV_NAME);
-
- case "/":
- case "/index.html":
- return newFixedLengthResponse(getHtmlResponse());
+ if (session.getMethod() == Method.GET) {
+ switch (uri) {
+ case "/download_input":
+ return downloadFile(Config.INPUT_JSON_NAME);
+ case "/output_json":
+ return viewFile(Config.OUTPUT_JSON_NAME);
+ case "/download_output_json":
+ return downloadFile(Config.OUTPUT_JSON_NAME);
+ case "/output_csv":
+ return viewFile(Config.OUTPUT_CSV_NAME);
+ case "/download_output_csv":
+ return downloadFile(Config.OUTPUT_CSV_NAME);
+ case "/":
+ return newFixedLengthResponse(getHome());
+ }
}
- // File upload management
if (session.getMethod() == Method.POST) {
- if (uri.equals("/upload_json")) {
- return handleJsonUpload(session);
- } else if (uri.equals("/upload_images")) {
- return handleImagesUpload(session);
+ switch (uri) {
+ case "/upload_json":
+ return handleJsonUpload(session);
+ case "/upload_images":
+ return handleImagesUpload(session);
}
}
@@ -73,58 +74,16 @@ public class ControlServer extends NanoHTTPD {
/**
* HTML UI for users
*/
- private String getHtmlResponse() {
- return "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "Application : stock-pignon
" +
-
- "Gestion des stocks
" +
- "" +
-
- "Modifier le catalogue
" +
- "" +
-
- "" +
- "
Gestion des images
" +
- "
" +
- "
" +
-
- "" +
- "";
+ private String getHome() {
+ try {
+ InputStream is = context.getAssets().open("index.html");
+ Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A");
+ String html = s.hasNext() ? s.next() : "";
+ is.close();
+ return html;
+ } catch (IOException e) {
+ return "❌ Erreur de chargement du template";
+ }
}
/**