Skip to content

Commit

Permalink
Re-worked app sorting
Browse files Browse the repository at this point in the history
Signed-off-by: apk-editor <[email protected]>
  • Loading branch information
apk-editor committed Dec 7, 2023
1 parent 9d69bc5 commit a6a47a9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,72 +179,53 @@ private void sortMenu(Activity activity) {
SubMenu sort = menu.addSubMenu(Menu.NONE, 0, Menu.NONE, getString(R.string.sort_by));

sort.add(0, 1, Menu.NONE, getString(R.string.sort_by_name)).setCheckable(true)
.setChecked(sCommonUtils.getBoolean("sort_name", false, activity));
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 0);
sort.add(0, 2, Menu.NONE, getString(R.string.sort_by_id)).setCheckable(true)
.setChecked(sCommonUtils.getBoolean("sort_id", true, activity));
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sort.add(0, 3, Menu.NONE, getString(R.string.sort_by_installed)).setCheckable(true)
.setChecked(sCommonUtils.getBoolean("sort_installed", false, activity));
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 2);
sort.add(0, 4, Menu.NONE, getString(R.string.sort_by_updated)).setCheckable(true)
.setChecked(sCommonUtils.getBoolean("sort_updated", false, activity));
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 3);
sort.add(0, 5, Menu.NONE, getString(R.string.sort_by_size)).setCheckable(true)
.setChecked(sCommonUtils.getBoolean("sort_size", false, activity));
.setChecked(sCommonUtils.getInt("sort_apps", 1, activity) == 4);
}
menu.add(Menu.NONE, 6, Menu.NONE, getString(sCommonUtils.getBoolean("sort_size", false, activity) ?
R.string.sort_size : R.string.sort_order)).setCheckable(true).setChecked(sCommonUtils.getBoolean(
"az_order", true, activity));
menu.add(Menu.NONE, 6, Menu.NONE, getString(sCommonUtils.getInt("sort_apps", 1, activity) == 4 ?
R.string.sort_size : (sCommonUtils.getInt("sort_apps", 1, activity) == 2 || sCommonUtils
.getInt("sort_apps", 0, activity) == 3) ? R.string.sort_time : R.string.sort_order))
.setCheckable(true).setChecked(sCommonUtils.getBoolean("az_order", true, activity));
sort.setGroupCheckable(0, true, true);
popupMenu.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case 0:
break;
case 1:
if (!sCommonUtils.getBoolean("sort_name", false, activity)) {
sCommonUtils.saveBoolean("sort_name", true, activity);
sCommonUtils.saveBoolean("sort_id", false, activity);
sCommonUtils.saveBoolean("sort_installed", false, activity);
sCommonUtils.saveBoolean("sort_updated", false, activity);
sCommonUtils.saveBoolean("sort_size", false, activity);
if (sCommonUtils.getInt("sort_apps", 1, activity) != 0) {
sCommonUtils.saveInt("sort_apps", 0, activity);
loadApps(activity);
}
break;
case 2:
if (!sCommonUtils.getBoolean("sort_id", true, activity)) {
sCommonUtils.saveBoolean("sort_name", false, activity);
sCommonUtils.saveBoolean("sort_id", true, activity);
sCommonUtils.saveBoolean("sort_installed", false, activity);
sCommonUtils.saveBoolean("sort_updated", false, activity);
sCommonUtils.saveBoolean("sort_size", false, activity);
if (sCommonUtils.getInt("sort_apps", 1, activity) != 1) {
sCommonUtils.saveInt("sort_apps", 1, activity);
loadApps(activity);
}
break;
case 3:
if (!sCommonUtils.getBoolean("sort_installed", false, activity)) {
sCommonUtils.saveBoolean("sort_name", false, activity);
sCommonUtils.saveBoolean("sort_id", false, activity);
sCommonUtils.saveBoolean("sort_installed", true, activity);
sCommonUtils.saveBoolean("sort_updated", false, activity);
sCommonUtils.saveBoolean("sort_size", false, activity);
if (sCommonUtils.getInt("sort_apps", 1, activity) != 2) {
sCommonUtils.saveInt("sort_apps", 2, activity);
loadApps(activity);
}
break;
case 4:
if (!sCommonUtils.getBoolean("sort_updated", false, activity)) {
sCommonUtils.saveBoolean("sort_name", false, activity);
sCommonUtils.saveBoolean("sort_id", false, activity);
sCommonUtils.saveBoolean("sort_installed", false, activity);
sCommonUtils.saveBoolean("sort_updated", true, activity);
sCommonUtils.saveBoolean("sort_size", false, activity);
if (sCommonUtils.getInt("sort_apps", 1, activity) != 3) {
sCommonUtils.saveInt("sort_apps", 3, activity);
loadApps(activity);
}
break;
case 5:
if (!sCommonUtils.getBoolean("sort_size", false, activity)) {
sCommonUtils.saveBoolean("sort_name", false, activity);
sCommonUtils.saveBoolean("sort_id", false, activity);
sCommonUtils.saveBoolean("sort_installed", false, activity);
sCommonUtils.saveBoolean("sort_updated", false, activity);
sCommonUtils.saveBoolean("sort_size", true, activity);
if (sCommonUtils.getInt("sort_apps", 1, activity) != 4) {
sCommonUtils.saveInt("sort_apps", 4, activity);
loadApps(activity);
}
break;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/apk/editor/utils/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ public static List<PackageItems> getData(Context context) {
}
}
}
if (sCommonUtils.getBoolean("sort_name", false, context)) {
if (sCommonUtils.getInt("sort_apps", 1, context) == 0) {
Collections.sort(mData, (lhs, rhs) -> String.CASE_INSENSITIVE_ORDER.compare(lhs.getAppName(), rhs.getAppName()));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && sCommonUtils.getBoolean("sort_size", false, context)) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && sCommonUtils.getInt("sort_apps", 1, context) == 4) {
Collections.sort(mData, Comparator.comparingLong(PackageItems::getAPKSize));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && sCommonUtils.getBoolean("sort_installed", false, context)) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && sCommonUtils.getInt("sort_apps", 1, context) == 2) {
Collections.sort(mData, Comparator.comparingLong(PackageItems::getInstalledTime));
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && sCommonUtils.getBoolean("sort_updated", false, context)) {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && sCommonUtils.getInt("sort_apps", 1, context) == 3) {
Collections.sort(mData, Comparator.comparingLong(PackageItems::getUpdatedTime));
} else {
Collections.sort(mData, (lhs, rhs) -> String.CASE_INSENSITIVE_ORDER.compare(lhs.getPackageName(), rhs.getPackageName()));
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<string name="sort_by_updated">Updated Time</string>
<string name="sort_order">A-Z</string>
<string name="sort_size">Small to Big</string>
<string name="sort_time">Old to New</string>
<string name="source_code">Source Code</string>
<string name="source_code_summary">Checkout the source code of AEE</string>
<string name="split_apk_installer">AEE Split APK Installer</string>
Expand Down

0 comments on commit a6a47a9

Please sign in to comment.