mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 20:54:13 -04:00
Remove start server dialog
Start server without asking for port from user dialog
This commit is contained in:
parent
d6d79b2cf7
commit
93c71e79f1
@ -37,57 +37,19 @@ public class WebServerHelper {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dialog to start the server where user is shown the hotspot ip address can edit the port no.
|
public void startServerHelper() {
|
||||||
public void startServerDialog() {
|
//TO DO:
|
||||||
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
//1. Get port from settings screen
|
||||||
alert.setTitle(R.string.start_server_dialog_title);
|
//2. Ask user to change port in settings if port is in use.
|
||||||
alert.setMessage(R.string.start_server_dialog_message);
|
//OR
|
||||||
|
//Always use 8080 and when its not available then iterate this number.
|
||||||
LinearLayout layout = new LinearLayout(context);
|
|
||||||
layout.setOrientation(LinearLayout.HORIZONTAL);
|
|
||||||
|
|
||||||
coordinatorLayout = new CoordinatorLayout(context);
|
|
||||||
|
|
||||||
textViewIpAccess = new TextView(context);
|
|
||||||
textViewIpAccess.setText(context.getString(R.string.sample_ip_address));
|
|
||||||
textViewIpAccess.setTextSize(20);
|
|
||||||
layout.addView(textViewIpAccess);
|
|
||||||
|
|
||||||
TextView colonTextView = new TextView(context);
|
|
||||||
colonTextView.setTextSize(20);
|
|
||||||
colonTextView.setText(":");
|
|
||||||
layout.addView(colonTextView);
|
|
||||||
|
|
||||||
editTextPort = new EditText(context);
|
|
||||||
editTextPort.setInputType(InputType.TYPE_CLASS_NUMBER);
|
|
||||||
editTextPort.setHint(R.string.port_hint);
|
|
||||||
editTextPort.setText(R.string.port_hint);
|
|
||||||
editTextPort.setFilters(new InputFilter[] { new InputFilter.LengthFilter(4) });
|
|
||||||
editTextPort.setTextSize(20);
|
|
||||||
layout.addView(editTextPort);
|
|
||||||
|
|
||||||
alert.setView(layout);
|
|
||||||
|
|
||||||
alert.setPositiveButton("START SERVER", new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
|
||||||
if (!isStarted && startAndroidWebServer()) {
|
if (!isStarted && startAndroidWebServer()) {
|
||||||
isStarted = true;
|
isStarted = true;
|
||||||
listener = (ServerStateListener) context;
|
listener = (ServerStateListener) context;
|
||||||
listener.serverStarted(getIpAddress()+port);
|
listener.serverStarted(getIpAddress() + port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
|
|
||||||
public void onClick(DialogInterface dialog, int whichButton) {
|
|
||||||
// Canceled.
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
alert.show();
|
|
||||||
|
|
||||||
setIpAccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean stopAndroidWebServer() {
|
public static boolean stopAndroidWebServer() {
|
||||||
if (isStarted && webServer != null) {
|
if (isStarted && webServer != null) {
|
||||||
@ -100,7 +62,7 @@ public class WebServerHelper {
|
|||||||
|
|
||||||
boolean startAndroidWebServer() {
|
boolean startAndroidWebServer() {
|
||||||
if (!isStarted) {
|
if (!isStarted) {
|
||||||
port = getPortFromEditText();
|
port = 8080;
|
||||||
try {
|
try {
|
||||||
if (port == 0) {
|
if (port == 0) {
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
@ -118,16 +80,6 @@ public class WebServerHelper {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPortFromEditText() {
|
|
||||||
String valueEditText = editTextPort.getText().toString();
|
|
||||||
int DEFAULT_PORT = 8080;
|
|
||||||
return (valueEditText.length() > 0) ? Integer.parseInt(valueEditText) : DEFAULT_PORT;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setIpAccess() {
|
|
||||||
textViewIpAccess.setText(getIpAddress());
|
|
||||||
}
|
|
||||||
|
|
||||||
// get Ip address of the device's wireless access point i.e. wifi hotspot OR wifi network
|
// get Ip address of the device's wireless access point i.e. wifi hotspot OR wifi network
|
||||||
String getIpAddress() {
|
String getIpAddress() {
|
||||||
Log.v("DANG", "Inside getIpAdress()");
|
Log.v("DANG", "Inside getIpAdress()");
|
||||||
|
@ -304,7 +304,7 @@ public class ZimHostActivity extends AppCompatActivity implements
|
|||||||
handler.postDelayed(new Runnable() {
|
handler.postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
webServerHelper.startServerDialog();
|
webServerHelper.startServerHelper();
|
||||||
}
|
}
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
@ -94,7 +94,7 @@ public class WifiHotspotManager {
|
|||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
|
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
|
||||||
WebServerHelper webServerHelper = new WebServerHelper(context);
|
WebServerHelper webServerHelper = new WebServerHelper(context);
|
||||||
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
||||||
webServerHelper.startServerDialog();
|
webServerHelper.startServerHelper();
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.setTitle(context.getString(R.string.hotspot_turned_on));
|
builder.setTitle(context.getString(R.string.hotspot_turned_on));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user