Added sort on uid

This commit is contained in:
M66B 2016-03-09 18:21:38 +01:00
parent 1945412eb0
commit 953169b2e8
4 changed files with 32 additions and 4 deletions

View File

@ -701,6 +701,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
String sort = prefs.getString("sort", "name");
if ("data".equals(sort))
menu.findItem(R.id.menu_sort_data).setChecked(true);
else if ("uid".equals(sort))
menu.findItem(R.id.menu_sort_uid).setChecked(true);
else
menu.findItem(R.id.menu_sort_name).setChecked(true);
@ -739,6 +741,11 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
prefs.edit().putString("sort", "name").apply();
return true;
case R.id.menu_sort_uid:
item.setChecked(true);
prefs.edit().putString("sort", "uid").apply();
return true;
case R.id.menu_sort_data:
item.setChecked(true);
prefs.edit().putString("sort", "data").apply();

View File

@ -278,6 +278,9 @@ public class Rule {
}
}
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
// Sort rule list
String sort = prefs.getString("sort", "name");
if ("data".equals(sort))
@ -288,8 +291,24 @@ public class Rule {
return 1;
else if (rule.totalbytes > other.totalbytes)
return -1;
else
return 0;
else {
int i = collator.compare(rule.name, other.name);
return (i == 0 ? rule.info.packageName.compareTo(other.info.packageName) : i);
}
}
});
else if ("uid".equals(sort))
Collections.sort(listRules, new Comparator<Rule>() {
@Override
public int compare(Rule rule, Rule other) {
if (rule.info.applicationInfo.uid < other.info.applicationInfo.uid)
return -1;
else if (rule.info.applicationInfo.uid > other.info.applicationInfo.uid)
return 1;
else {
int i = collator.compare(rule.name, other.name);
return (i == 0 ? rule.info.packageName.compareTo(other.info.packageName) : i);
}
}
});
else
@ -297,8 +316,6 @@ public class Rule {
@Override
public int compare(Rule rule, Rule other) {
if (all || rule.changed == other.changed) {
Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case sensitive, process accents etc
int i = collator.compare(rule.name, other.name);
return (i == 0 ? rule.info.packageName.compareTo(other.info.packageName) : i);
}

View File

@ -41,6 +41,9 @@
<item
android:id="@+id/menu_sort_name"
android:title="@string/menu_sort_name" />
<item
android:id="@+id/menu_sort_uid"
android:title="@string/menu_sort_uid" />
<item
android:id="@+id/menu_sort_data"
android:title="@string/menu_sort_data" />

View File

@ -15,6 +15,7 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<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_uid">Sort on uid</string>
<string name="menu_sort_data">Sort on data usage</string>
<string name="menu_log">Show log</string>
<string name="menu_settings">Settings</string>