Resolve lint warnings in WebServerHelper.java

This commit is contained in:
Adeel Zafar 2019-07-26 18:16:09 +05:00
parent eefeaed069
commit 48d9978f6a
5 changed files with 19 additions and 23 deletions

View File

@ -125,7 +125,6 @@ import org.kiwix.kiwixmobile.utils.LanguageUtils;
import org.kiwix.kiwixmobile.utils.NetworkUtils;
import org.kiwix.kiwixmobile.utils.StyleUtils;
import org.kiwix.kiwixmobile.utils.files.FileUtils;
import org.kiwix.kiwixmobile.webserver.WebServerHelper;
import org.kiwix.kiwixmobile.wifi_hotspot.HotspotService;
import org.kiwix.kiwixmobile.wifi_hotspot.WifiHotspotManager;
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
@ -172,6 +171,7 @@ import static org.kiwix.kiwixmobile.utils.LanguageUtils.getResourceString;
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
import static org.kiwix.kiwixmobile.utils.UpdateUtils.reformatProviderUrl;
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.isStarted;
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.stopAndroidWebServer;
import static org.kiwix.kiwixmobile.wifi_hotspot.HotspotService.checkHotspotState;
public class MainActivity extends BaseActivity implements WebViewCallback,
@ -194,7 +194,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
private final List<KiwixWebView> webViewList = new ArrayList<>();
private Intent serviceIntent;
private BroadcastReceiver broadcastReceiverNetworkState;
public static WebServerHelper webServerHelper;
@BindView(R.id.activity_main_root)
ConstraintLayout root;
@BindView(R.id.activity_main_toolbar)
@ -772,7 +771,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
// TODO create a base Activity class that class this.
FileUtils.deleteCachedFiles(this);
tts.shutdown();
webServerHelper.stopAndroidWebServer();
stopAndroidWebServer();
isStarted = false;
//if (broadcastReceiverNetworkState != null) {
// unregisterReceiver(broadcastReceiverNetworkState);
@ -1096,7 +1095,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
if (isMobileDataEnabled(this)) {
mobileDataDialog();
} else {
webServerHelper = new WebServerHelper(getApplicationContext());
startService(ACTION_TURN_ON_BEFORE_O);
}
}
@ -2348,8 +2346,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
// All location settings are satisfied. The client can initialize location
// requests here.
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//webServerHelper = new WebServerHelper(this);
startService(ACTION_TURN_ON_AFTER_O);
//}

View File

@ -18,20 +18,20 @@ import java.util.Enumeration;
import org.kiwix.kiwixmobile.R;
public class WebServerHelper {
private static Context context;
private static TextView textViewIpAccess;
private static EditText editTextPort;
private Context context;
private TextView textViewIpAccess;
private EditText editTextPort;
public static boolean isStarted;
private static int port;
private int port;
private static WebServer webServer;
private static final int DEFAULT_PORT = 8080;
private static CoordinatorLayout coordinatorLayout;
private final int DEFAULT_PORT = 8080;
private CoordinatorLayout coordinatorLayout;
public WebServerHelper(Context context) {
this.context = context;
}
public static void startServerDialog(Context context) {
public void startServerDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Start the server");
alert.setMessage("Happy sharing");
@ -40,7 +40,7 @@ public class WebServerHelper {
layout.setOrientation(LinearLayout.HORIZONTAL);
textViewIpAccess = new TextView(context);
textViewIpAccess.setText("http://000.000.000.000");
textViewIpAccess.setText(context.getString(R.string.sample_ip_address));
textViewIpAccess.setTextSize(20);
layout.addView(textViewIpAccess);
@ -88,7 +88,7 @@ public class WebServerHelper {
return false;
}
private static boolean startAndroidWebServer() {
private boolean startAndroidWebServer() {
if (!isStarted) {
port = getPortFromEditText();
try {
@ -108,17 +108,17 @@ public class WebServerHelper {
return false;
}
private static int getPortFromEditText() {
private int getPortFromEditText() {
String valueEditText = editTextPort.getText().toString();
return (valueEditText.length() > 0) ? Integer.parseInt(valueEditText) : DEFAULT_PORT;
}
private static void setIpAccess() {
private void setIpAccess() {
textViewIpAccess.setText(getIpAddress());
}
// get Ip address of the device's wireless access point i.e. wifi hotspot OR wifi network
private static String getIpAddress() {
private String getIpAddress() {
Log.v("DANG", "Inside getIpAdress()");
String ip = "";
try {

View File

@ -10,7 +10,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
@ -25,7 +24,6 @@ import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_OFF_BEFORE_O;
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_ON_AFTER_O;
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_ON_BEFORE_O;
import static org.kiwix.kiwixmobile.main.MainActivity.startHotspotDetails;
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.startServerDialog;
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.stopAndroidWebServer;
/**

View File

@ -10,9 +10,9 @@ import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import java.lang.reflect.Method;
import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.webserver.WebServerHelper;
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.startServerDialog;
/**
* WifiHotstopManager class makes use of the Android's WifiManager and WifiConfiguration class
@ -153,10 +153,11 @@ public class WifiHotspotManager {
public void hotspotDetailsDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
WebServerHelper webServerHelper = new WebServerHelper(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
startServerDialog(context);
webServerHelper.startServerDialog();
});
} else {
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
@ -164,7 +165,7 @@ public class WifiHotspotManager {
handler.postDelayed(new Runnable() {
@Override
public void run() {
startServerDialog(context);
webServerHelper.startServerDialog();
}
}, 6000);
});

View File

@ -34,6 +34,7 @@
<string name="mobile_data_enabled">Warning: Mobile data enabled</string>
<string name="mobile_data_message">You\'re about to turn on your wifi hotspot. This feature can work without data usage.</string>
<string name="mobile_data_message_confirmation">Do you want to disable your data?</string>
<string name="sample_ip_address">http://000.000.000.000</string>
<string name="error_filenotfound">Error: The selected ZIM file could not be found.</string>
<string name="error_fileinvalid">Error: The selected file is not a valid ZIM file.</string>
<string name="error_articleurlnotfound">Error: Loading article (Url: %1$s) failed.</string>