mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-25 05:51:33 -04:00
Add check for null ip address
Show toast
This commit is contained in:
parent
c0c67e5de9
commit
3f598a4ce6
@ -8,6 +8,8 @@ public interface ServerStateListener {
|
||||
|
||||
void serverStopped();
|
||||
|
||||
void serverFailed();
|
||||
|
||||
void hotspotTurnedOn(WifiConfiguration wifiConfiguration);
|
||||
|
||||
void hotspotFailed();
|
||||
|
@ -30,7 +30,13 @@ public class WebServerHelper {
|
||||
|
||||
if (!isServerStarted && startAndroidWebServer()) {
|
||||
isServerStarted = true;
|
||||
stateListener.serverStarted(getIpAddress() + ":" + port);
|
||||
String ip = getIpAddress();
|
||||
ip = ip.replaceAll("\n", "");
|
||||
if (ip.length() == 0) {
|
||||
stateListener.serverFailed();
|
||||
} else {
|
||||
stateListener.serverStarted("http://" + ip + ":" + port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,10 +91,10 @@ public class WebServerHelper {
|
||||
ip += "Something Wrong! " + e.toString() + "\n";
|
||||
}
|
||||
|
||||
return "http://" + ip;
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static String getAddress() {
|
||||
return getIpAddress() + ":" + port;
|
||||
return "http://" + getIpAddress() + ":" + port;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
@ -375,9 +376,8 @@ public class ZimHostActivity extends BaseActivity implements
|
||||
}
|
||||
|
||||
@Override public void serverStarted(String ip) {
|
||||
ip = ip.replaceAll("\n", "");
|
||||
this.ip = ip;
|
||||
serverTextView.setText(getString(R.string.server_started_message) + " " + ip);
|
||||
serverTextView.setText(getString(R.string.server_started_message) + " " + this.ip);
|
||||
startServerButton.setText(getString(R.string.stop_server_label));
|
||||
startServerButton.setBackgroundColor(getResources().getColor(R.color.stopServer));
|
||||
isServerStarted = true;
|
||||
@ -390,6 +390,11 @@ public class ZimHostActivity extends BaseActivity implements
|
||||
isServerStarted = false;
|
||||
}
|
||||
|
||||
@Override public void serverFailed() {
|
||||
String message = String.format(getString(R.string.server_failed_message));
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override public void hotspotTurnedOn(WifiConfiguration wifiConfiguration) {
|
||||
|
||||
//Show an alert dialog for hotspot details
|
||||
|
@ -31,6 +31,7 @@
|
||||
<string name="hotspot_start">Starting hotspot</string>
|
||||
<string name="hotspot_running">Running Hotspot</string>
|
||||
<string name="stop_hotspot_button">STOP</string>
|
||||
<string name="server_failed_message">Couldn’t start server. Please turn on your hotspot</string>
|
||||
<string name="hotspot_turned_on">Hotspot turned on</string>
|
||||
<string name="hotspot_details_message">Following are the details of your local hotspot.</string>
|
||||
<string name="hotspot_ssid_label">SSID : </string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user