Refactoring

This commit is contained in:
M66B 2015-10-26 17:32:03 +01:00
parent 68eb840a11
commit cecbd23cbe
3 changed files with 14 additions and 14 deletions

View File

@ -90,7 +90,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
// Fill application list
fillApplicationList();
// Listen connectivity updates
// Listen for connectivity updates
IntentFilter ifConnectivity = new IntentFilter();
ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(connectivityChangedReceiver, ifConnectivity);
@ -307,14 +307,14 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
}
}
private void reset(String name) {
SharedPreferences other = getSharedPreferences(name, Context.MODE_PRIVATE);
private void reset(String network) {
SharedPreferences other = getSharedPreferences(network, Context.MODE_PRIVATE);
SharedPreferences.Editor edit = other.edit();
for (String key : other.getAll().keySet())
edit.remove(key);
edit.apply();
fillApplicationList();
BlackHoleService.reload(name, ActivityMain.this);
BlackHoleService.reload(network, ActivityMain.this);
}
@Override

View File

@ -145,7 +145,7 @@ public class BlackHoleService extends VpnService {
super.onCreate();
Log.i(TAG, "Create");
// Listen connectivity updates
// Listen for connectivity updates
IntentFilter ifConnectivity = new IntentFilter();
ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(connectivityChangedReceiver, ifConnectivity);
@ -194,8 +194,8 @@ public class BlackHoleService extends VpnService {
context.startService(intent);
}
public static void reload(String name, Context context) {
if (name == null || ("wifi".equals(name) ? Util.isWifiActive(context) : !Util.isWifiActive(context))) {
public static void reload(String network, Context context) {
if (network == null || ("wifi".equals(network) ? Util.isWifiActive(context) : !Util.isWifiActive(context))) {
Intent intent = new Intent(context, BlackHoleService.class);
intent.putExtra(EXTRA_COMMAND, Command.reload);
context.startService(intent);

View File

@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> implements Filterable {
private static final String TAG = "NetGuard.RuleAdapter";
private static final String TAG = "NetGuard.Adapter";
private Context context;
private int colorText;
@ -71,20 +71,20 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
CompoundButton.OnCheckedChangeListener cbListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
String name;
String network;
if (buttonView == holder.cbWifi) {
name = "wifi";
network = "wifi";
rule.wifi_blocked = isChecked;
} else {
name = "other";
network = "other";
rule.other_blocked = isChecked;
}
Log.i(TAG, rule.info.packageName + ": " + name + "=" + isChecked);
Log.i(TAG, rule.info.packageName + ": " + network + "=" + isChecked);
SharedPreferences prefs = context.getSharedPreferences(name, Context.MODE_PRIVATE);
SharedPreferences prefs = context.getSharedPreferences(network, Context.MODE_PRIVATE);
prefs.edit().putBoolean(rule.info.packageName, isChecked).apply();
BlackHoleService.reload(name, context);
BlackHoleService.reload(network, context);
}
};