Reverting main page of ZIM webserver

Replace it with a simple hello world webserver.
This commit is contained in:
Adeel Zafar 2019-08-02 02:28:03 +05:00
parent 2aa0af3148
commit b459886e9d
3 changed files with 12 additions and 23 deletions

View File

@ -184,8 +184,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
private static final String HOME_URL = "file:///android_asset/home.html"; private static final String HOME_URL = "file:///android_asset/home.html";
public static final String ACTION_TURN_ON_AFTER_O = "Turn_on_hotspot_after_oreo"; public static final String ACTION_TURN_ON_AFTER_O = "Turn_on_hotspot_after_oreo";
public static final String ACTION_TURN_OFF_AFTER_O = "Turn_off_hotspot_after_oreo"; public static final String ACTION_TURN_OFF_AFTER_O = "Turn_off_hotspot_after_oreo";
public static final String MAIN_PAGE_STORAGE_PATH =
"/storage/emulated/0/Download/outputDang.html";
private static final int MY_PERMISSIONS_ACCESS_FINE_LOCATION = 102; private static final int MY_PERMISSIONS_ACCESS_FINE_LOCATION = 102;
public static boolean isFullscreenOpened; public static boolean isFullscreenOpened;
public static boolean refresh; public static boolean refresh;

View File

@ -2,33 +2,25 @@ package org.kiwix.kiwixmobile.webserver;
import android.util.Log; import android.util.Log;
import fi.iki.elonen.NanoHTTPD; import fi.iki.elonen.NanoHTTPD;
import java.io.BufferedReader; import java.util.Map;
import java.io.FileReader;
import java.io.IOException;
public class WebServer extends NanoHTTPD { public class WebServer extends NanoHTTPD {
private String selectedFilePath;
public WebServer(int port, String selectedFilePath) { public WebServer(int port) {
super(port); super(port);
this.selectedFilePath = selectedFilePath;
} }
@Override @Override
public Response serve(IHTTPSession session) { public Response serve(IHTTPSession session) {
String answer = ""; String msg = "<html><body><h1>Hello server</h1>\n";
try { Map<String, String> parms = session.getParms();
FileReader index = new FileReader(selectedFilePath); if (parms.get("username") == null) {
BufferedReader reader = new BufferedReader(index); msg +=
String line = ""; "<form action='?' method='get'>\n <p>Your name: <input type='text' name='username'></p>\n"
while ((line = reader.readLine()) != null) { + "</form>\n";
answer += line; } else {
msg += "<p>Hello, " + parms.get("username") + "!</p>";
} }
reader.close(); return newFixedLengthResponse(msg + "</body></html>\n");
} catch (IOException ioe) {
Log.w("Httpd", ioe.toString());
}
return newFixedLengthResponse(answer);
} }
} }

View File

@ -17,7 +17,6 @@ import java.net.SocketException;
import java.util.Enumeration; import java.util.Enumeration;
import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.R;
import static org.kiwix.kiwixmobile.main.MainActivity.MAIN_PAGE_STORAGE_PATH;
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle; import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
/** /**
@ -105,7 +104,7 @@ public class WebServerHelper {
if (port == 0) { if (port == 0) {
throw new Exception(); throw new Exception();
} }
webServer = new WebServer(port, MAIN_PAGE_STORAGE_PATH); webServer = new WebServer(port);
webServer.start(); webServer.start();
return true; return true;
} catch (Exception e) { } catch (Exception e) {