Clean Code

Removing unused imports.
Removing irrelevant comments and logs
This commit is contained in:
Adeel Zafar 2019-07-06 18:44:01 +05:00
parent 35ed0e079d
commit 2053e68926
3 changed files with 1 additions and 30 deletions

View File

@ -1084,17 +1084,13 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
private void switchHotspot() {
if (wifiHotspotManager.isWifiApEnabled()) {
startService(ACTION_TURN_OFF_BEFORE_O);
//hotspotManager.setWifiEnabled(null, false);
} else {
//Check if user's hotspot is enabled
if (isMobileDataEnabled(this)) {
mobileDataDialog();
} else {
// potentially add data to the intent
//i.putExtra("TURN_ON_HOTSPOT_BEFORE_O", "turnOnHotspotBeforeO");
startService(ACTION_TURN_ON_BEFORE_O);
//hotspotManager.setWifiEnabled(null, true);
}
}
}
@ -1132,15 +1128,11 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
private void toggleHotspot() {
boolean check = false;
//Check if location permissions are granted
Log.v("DANG", "Turn off -1");
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
Log.v("DANG", "Turn off 0");
if (checkHotspotState(this)) //If hotspot is already enabled, turn it off
{
Log.v("DANG", "Turn off 1");
startService(ACTION_TURN_OFF_AFTER_O);
//hotspotManager.turnOffHotspot();
} else //If hotspot is not already enabled, then turn it on.
{
setupLocationServices();
@ -1182,7 +1174,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
method.setAccessible(true);
enabled = (Boolean) method.invoke(cm);
} catch (Exception e) {
Log.e("DANG ", e.toString());
Log.e("DANG", e.toString());
}
return enabled;
}
@ -2323,7 +2315,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startService(ACTION_TURN_ON_AFTER_O);
//hotspotManager.turnOnHotspot();
//}
} catch (ApiException exception) {
switch (exception.getStatusCode()) {

View File

@ -58,18 +58,14 @@ public class HotspotService extends Service {
switch (intent.getAction()) {
case ACTION_TURN_ON_BEFORE_O:
if (hotspotManager.setWifiEnabled(null, true)) {
Log.v("DANG", "INSIDE");
startHotspotDetails();
updateNotification(getString(R.string.hotspot_running), true);
}
break;
case ACTION_TURN_ON_AFTER_O:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.v("DANG","Coming after 3");
hotspotManager.turnOnHotspot();
//if(it gets turned on successfully) then it goes to catch in MainActivity
updateNotification(getString(R.string.hotspot_running), true);
Log.v("DANG","Coming after calling updateNotification 8");
}
break;
case ACTION_TURN_OFF_BEFORE_O:
@ -78,7 +74,6 @@ public class HotspotService extends Service {
stopSelf();
break;
case ACTION_TURN_OFF_AFTER_O:
Log.v("DANG","Turn off 3");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
hotspotManager.turnOffHotspot();
}
@ -127,7 +122,6 @@ public class HotspotService extends Service {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
hotspotManager.turnOffHotspot();
} else {
Log.v("DANG", "Coming yes");
hotspotManager.setWifiEnabled(null, false);
}
stopForeground(true);
@ -144,7 +138,6 @@ public class HotspotService extends Service {
private void hotspotNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.v("DANG","Building notification channel start : 1");
NotificationChannel hotspotServiceChannel = new NotificationChannel(
Constants.HOTSPOT_SERVICE_CHANNEL_ID, getString(R.string.hotspot_service_channel_name),
NotificationManager.IMPORTANCE_DEFAULT);
@ -152,7 +145,6 @@ public class HotspotService extends Service {
hotspotServiceChannel.setSound(null, null);
builder.setChannelId(Constants.HOTSPOT_SERVICE_CHANNEL_ID);
notificationManager.createNotificationChannel(hotspotServiceChannel);
Log.v("DANG","Building notification channel end : 1.1");
}
}

View File

@ -9,13 +9,10 @@ import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import com.google.android.material.snackbar.Snackbar;
import java.lang.reflect.Method;
import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.main.MainActivity;
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
@ -108,7 +105,6 @@ public class WifiHotspotManager {
//Workaround to turn off hotspot for Oreo versions
@RequiresApi(api = Build.VERSION_CODES.O)
public void turnOffHotspot() {
Log.v("DANG", "Turn off 4");
if (hotspotReservation != null) {
hotspotReservation.close();
hotspotReservation = null;
@ -118,16 +114,11 @@ public class WifiHotspotManager {
}
//This method checks the state of the hostpot for devices>=Oreo
@RequiresApi(api = Build.VERSION_CODES.O)
public boolean checkHotspotState() {
//Log.v("DANG",(hotspotReservation.getWifiConfiguration()).SSID);
if (hotspotReservation == null) {
Log.v("DANG", "I'm returning false");
return false;
} else {
Log.v("DANG", "I'm returning true");
return true;
}
}
@ -181,8 +172,6 @@ public class WifiHotspotManager {
public void hotspotDetailsDialog() {
Log.v("DANG", "Coming hotspot details dialog :4");
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
@ -203,6 +192,5 @@ public class WifiHotspotManager {
}
AlertDialog dialog = builder.create();
dialog.show();
Log.v("DANG", "Coming end of hotspot details dialog :5");
}
}