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";
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 MAIN_PAGE_STORAGE_PATH =
"/storage/emulated/0/Download/outputDang.html";
private static final int MY_PERMISSIONS_ACCESS_FINE_LOCATION = 102;
public static boolean isFullscreenOpened;
public static boolean refresh;

View File

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

View File

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