mirror of https://github.com/M66B/NetGuard.git
Added sort on name / data usage
This commit is contained in:
parent
d4a4023301
commit
88a1b9a586
|
@ -355,6 +355,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
"show_system".equals(name) ||
|
"show_system".equals(name) ||
|
||||||
"show_nointernet".equals(name) ||
|
"show_nointernet".equals(name) ||
|
||||||
"show_disabled".equals(name) ||
|
"show_disabled".equals(name) ||
|
||||||
|
"sort".equals(name) ||
|
||||||
"imported".equals(name)) {
|
"imported".equals(name)) {
|
||||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
|
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
|
||||||
updateApplicationList(menuSearch.isActionViewExpanded() ? searchView.getQuery().toString() : null);
|
updateApplicationList(menuSearch.isActionViewExpanded() ? searchView.getQuery().toString() : null);
|
||||||
|
@ -503,6 +504,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
menu.findItem(R.id.menu_app_nointernet).setChecked(prefs.getBoolean("show_nointernet", true));
|
menu.findItem(R.id.menu_app_nointernet).setChecked(prefs.getBoolean("show_nointernet", true));
|
||||||
menu.findItem(R.id.menu_app_disabled).setChecked(prefs.getBoolean("show_disabled", true));
|
menu.findItem(R.id.menu_app_disabled).setChecked(prefs.getBoolean("show_disabled", true));
|
||||||
|
|
||||||
|
String sort = prefs.getString("sort", "name");
|
||||||
|
menu.findItem(R.id.menu_sort_name).setChecked("name".equals(sort));
|
||||||
|
menu.findItem(R.id.menu_sort_data).setChecked("data".equals(sort));
|
||||||
|
|
||||||
return super.onPrepareOptionsMenu(menu);
|
return super.onPrepareOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,6 +536,16 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
||||||
prefs.edit().putBoolean("show_disabled", item.isChecked()).apply();
|
prefs.edit().putBoolean("show_disabled", item.isChecked()).apply();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_sort_name:
|
||||||
|
item.setChecked(true);
|
||||||
|
prefs.edit().putString("sort", "name").apply();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.menu_sort_data:
|
||||||
|
item.setChecked(true);
|
||||||
|
prefs.edit().putString("sort", "data").apply();
|
||||||
|
return true;
|
||||||
|
|
||||||
case R.id.menu_settings:
|
case R.id.menu_settings:
|
||||||
startActivity(new Intent(this, ActivitySettings.class));
|
startActivity(new Intent(this, ActivitySettings.class));
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -26,6 +26,8 @@ import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
|
import android.net.TrafficStats;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -34,11 +36,12 @@ import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Rule implements Comparable<Rule> {
|
public class Rule {
|
||||||
private static final String TAG = "NetGuard.Rule";
|
private static final String TAG = "NetGuard.Rule";
|
||||||
|
|
||||||
public PackageInfo info;
|
public PackageInfo info;
|
||||||
|
@ -61,6 +64,10 @@ public class Rule implements Comparable<Rule> {
|
||||||
|
|
||||||
public String[] related = null;
|
public String[] related = null;
|
||||||
|
|
||||||
|
public float upspeed;
|
||||||
|
public float downspeed;
|
||||||
|
public float totalbytes;
|
||||||
|
|
||||||
public boolean changed;
|
public boolean changed;
|
||||||
|
|
||||||
public Intent intent;
|
public Intent intent;
|
||||||
|
@ -112,6 +119,8 @@ public class Rule implements Comparable<Rule> {
|
||||||
boolean show_nointernet = prefs.getBoolean("show_nointernet", true);
|
boolean show_nointernet = prefs.getBoolean("show_nointernet", true);
|
||||||
boolean show_disabled = prefs.getBoolean("show_disabled", true);
|
boolean show_disabled = prefs.getBoolean("show_disabled", true);
|
||||||
|
|
||||||
|
long now = SystemClock.elapsedRealtime();
|
||||||
|
|
||||||
// Get predefined rules
|
// Get predefined rules
|
||||||
Map<String, Boolean> pre_blocked = new HashMap<>();
|
Map<String, Boolean> pre_blocked = new HashMap<>();
|
||||||
Map<String, Boolean> pre_roaming = new HashMap<>();
|
Map<String, Boolean> pre_roaming = new HashMap<>();
|
||||||
|
@ -178,6 +187,12 @@ public class Rule implements Comparable<Rule> {
|
||||||
if (pre_related.containsKey(info.packageName))
|
if (pre_related.containsKey(info.packageName))
|
||||||
rule.related = pre_related.get(info.packageName);
|
rule.related = pre_related.get(info.packageName);
|
||||||
|
|
||||||
|
long up = TrafficStats.getUidTxBytes(rule.info.applicationInfo.uid);
|
||||||
|
long down = TrafficStats.getUidRxBytes(rule.info.applicationInfo.uid);
|
||||||
|
rule.totalbytes = up + down;
|
||||||
|
rule.upspeed = (float) up * 24 * 3600 * 1000 / 1024f / 1024f / now;
|
||||||
|
rule.downspeed = (float) down * 24 * 3600 * 1000 / 1024f / 1024f / now;
|
||||||
|
|
||||||
rule.updateChanged(default_wifi, default_other, default_roaming, haswifi, hastelephony);
|
rule.updateChanged(default_wifi, default_other, default_roaming, haswifi, hastelephony);
|
||||||
|
|
||||||
listRules.add(rule);
|
listRules.add(rule);
|
||||||
|
@ -185,7 +200,30 @@ public class Rule implements Comparable<Rule> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort rule list
|
// Sort rule list
|
||||||
Collections.sort(listRules);
|
String sort = prefs.getString("sort", "name");
|
||||||
|
if ("data".equals(sort))
|
||||||
|
Collections.sort(listRules, new Comparator<Rule>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Rule rule, Rule other) {
|
||||||
|
if (rule.totalbytes < other.totalbytes)
|
||||||
|
return 1;
|
||||||
|
else if (rule.totalbytes > other.totalbytes)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
else
|
||||||
|
Collections.sort(listRules, new Comparator<Rule>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Rule rule, Rule other) {
|
||||||
|
if (rule.changed == other.changed) {
|
||||||
|
int i = rule.name.compareToIgnoreCase(other.name);
|
||||||
|
return (i == 0 ? rule.info.packageName.compareTo(other.info.packageName) : i);
|
||||||
|
}
|
||||||
|
return (rule.changed ? -1 : 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return listRules;
|
return listRules;
|
||||||
}
|
}
|
||||||
|
@ -207,13 +245,4 @@ public class Rule implements Comparable<Rule> {
|
||||||
boolean telephony = Util.hasTelephony(context);
|
boolean telephony = Util.hasTelephony(context);
|
||||||
updateChanged(default_wifi, default_other, default_roaming, wifi, telephony);
|
updateChanged(default_wifi, default_other, default_roaming, wifi, telephony);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Rule other) {
|
|
||||||
if (changed == other.changed) {
|
|
||||||
int i = name.compareToIgnoreCase(other.name);
|
|
||||||
return (i == 0 ? info.packageName.compareTo(other.info.packageName) : i);
|
|
||||||
}
|
|
||||||
return (changed ? -1 : 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,8 @@ import android.content.SharedPreferences;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.net.TrafficStats;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NotificationManagerCompat;
|
import android.support.v4.app.NotificationManagerCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
@ -445,10 +443,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> im
|
||||||
});
|
});
|
||||||
|
|
||||||
// Traffic statistics
|
// Traffic statistics
|
||||||
holder.tvStatistics.setText(context.getString(R.string.msg_mbday,
|
holder.tvStatistics.setText(context.getString(R.string.msg_mbday, rule.upspeed, rule.downspeed));
|
||||||
(float) TrafficStats.getUidTxBytes(rule.info.applicationInfo.uid) * 24 * 3600 * 1000 / 1024f / 1024f / SystemClock.elapsedRealtime(),
|
|
||||||
(float) TrafficStats.getUidRxBytes(rule.info.applicationInfo.uid) * 24 * 3600 * 1000 / 1024f / 1024f / SystemClock.elapsedRealtime()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRule(Rule rule, String network, boolean blocked) {
|
private void updateRule(Rule rule, String network, boolean blocked) {
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 115 B |
Binary file not shown.
After Width: | Height: | Size: 90 B |
Binary file not shown.
After Width: | Height: | Size: 101 B |
Binary file not shown.
After Width: | Height: | Size: 103 B |
Binary file not shown.
After Width: | Height: | Size: 107 B |
|
@ -31,6 +31,22 @@
|
||||||
android:title="@string/menu_app_disabled" />
|
android:title="@string/menu_app_disabled" />
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_sort"
|
||||||
|
android:icon="@drawable/ic_sort_white_24dp"
|
||||||
|
android:title="@string/menu_sort"
|
||||||
|
netguard:showAsAction="always|collapseActionView">
|
||||||
|
<menu>
|
||||||
|
<group android:checkableBehavior="single">
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_sort_name"
|
||||||
|
android:title="@string/menu_sort_name" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_sort_data"
|
||||||
|
android:title="@string/menu_sort_data" />
|
||||||
|
</group>
|
||||||
|
</menu>
|
||||||
|
</item>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_settings"
|
android:id="@+id/menu_settings"
|
||||||
android:title="@string/menu_settings" />
|
android:title="@string/menu_settings" />
|
||||||
|
|
|
@ -15,6 +15,9 @@ These issues are caused by bugs in Android, or in the software provided by the m
|
||||||
<string name="menu_app_system">Show system applications</string>
|
<string name="menu_app_system">Show system applications</string>
|
||||||
<string name="menu_app_nointernet">Show applications without internet</string>
|
<string name="menu_app_nointernet">Show applications without internet</string>
|
||||||
<string name="menu_app_disabled">Show disabled applications</string>
|
<string name="menu_app_disabled">Show disabled applications</string>
|
||||||
|
<string name="menu_sort">Sort applications</string>
|
||||||
|
<string name="menu_sort_name">Sort on name</string>
|
||||||
|
<string name="menu_sort_data">Sort on data usage</string>
|
||||||
<string name="menu_settings">Settings</string>
|
<string name="menu_settings">Settings</string>
|
||||||
<string name="menu_invite">Invite</string>
|
<string name="menu_invite">Invite</string>
|
||||||
<string name="menu_support">Support</string>
|
<string name="menu_support">Support</string>
|
||||||
|
|
Loading…
Reference in New Issue