mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 03:54:18 -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,58 +37,20 @@ public class WebServerHelper {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
//Dialog to start the server where user is shown the hotspot ip address can edit the port no.
|
||||
public void startServerDialog() {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
||||
alert.setTitle(R.string.start_server_dialog_title);
|
||||
alert.setMessage(R.string.start_server_dialog_message);
|
||||
|
||||
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()) {
|
||||
isStarted = true;
|
||||
listener = (ServerStateListener) context;
|
||||
listener.serverStarted(getIpAddress()+port);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
// Canceled.
|
||||
}
|
||||
});
|
||||
|
||||
alert.show();
|
||||
|
||||
setIpAccess();
|
||||
public void startServerHelper() {
|
||||
//TO DO:
|
||||
//1. Get port from settings screen
|
||||
//2. Ask user to change port in settings if port is in use.
|
||||
//OR
|
||||
//Always use 8080 and when its not available then iterate this number.
|
||||
if (!isStarted && startAndroidWebServer()) {
|
||||
isStarted = true;
|
||||
listener = (ServerStateListener) context;
|
||||
listener.serverStarted(getIpAddress() + port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean stopAndroidWebServer() {
|
||||
if (isStarted && webServer != null) {
|
||||
webServer.stop();
|
||||
@ -100,7 +62,7 @@ public class WebServerHelper {
|
||||
|
||||
boolean startAndroidWebServer() {
|
||||
if (!isStarted) {
|
||||
port = getPortFromEditText();
|
||||
port = 8080;
|
||||
try {
|
||||
if (port == 0) {
|
||||
throw new Exception();
|
||||
@ -118,16 +80,6 @@ public class WebServerHelper {
|
||||
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
|
||||
String getIpAddress() {
|
||||
Log.v("DANG", "Inside getIpAdress()");
|
||||
|
@ -304,7 +304,7 @@ public class ZimHostActivity extends AppCompatActivity implements
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
webServerHelper.startServerDialog();
|
||||
webServerHelper.startServerHelper();
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
|
@ -94,7 +94,7 @@ public class HotspotService extends Service {
|
||||
.setSmallIcon(R.mipmap.kiwix_icon)
|
||||
.setWhen(System.currentTimeMillis());
|
||||
|
||||
hotspotNotificationChannel();
|
||||
hotspotNotificationChannel();
|
||||
|
||||
if (showStopButton) {
|
||||
Intent stopIntent = new Intent(ACTION_STOP);
|
||||
@ -112,7 +112,7 @@ public class HotspotService extends Service {
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
void stopHotspot() {
|
||||
hotspotManager.turnOffHotspot();
|
||||
hotspotManager.turnOffHotspot();
|
||||
stopForeground(true);
|
||||
stopSelf();
|
||||
stopAndroidWebServer();
|
||||
|
@ -94,7 +94,7 @@ public class WifiHotspotManager {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
|
||||
WebServerHelper webServerHelper = new WebServerHelper(context);
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
||||
webServerHelper.startServerDialog();
|
||||
webServerHelper.startServerHelper();
|
||||
});
|
||||
|
||||
builder.setTitle(context.getString(R.string.hotspot_turned_on));
|
||||
|
Loading…
x
Reference in New Issue
Block a user