Skip to content

Commit 774356c

Browse files
committed
Add option to filter only launchable apps
1 parent f476b4b commit 774356c

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

app/src/main/java/com/drdisagree/colorblendr/common/Const.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public static void saveWorkingMethod(WORK_METHOD workMethod) {
100100
public enum AppType {
101101
SYSTEM,
102102
USER,
103-
BOTH
103+
LAUNCHABLE,
104+
ALL
104105
}
105106
}

app/src/main/java/com/drdisagree/colorblendr/ui/fragments/PerAppThemeFragment.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class PerAppThemeFragment extends Fragment {
5353
@Override
5454
public void onReceive(Context context, Intent intent) {
5555
AppType appType = AppType.values()[
56-
RPrefs.getInt(APP_LIST_FILTER_METHOD, AppType.BOTH.ordinal())
56+
RPrefs.getInt(APP_LIST_FILTER_METHOD, AppType.ALL.ordinal())
5757
];
5858

5959
initAppList(appType);
@@ -107,7 +107,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
107107
binding.searchBox.filter.setOnClickListener(v -> showFilterDialog());
108108

109109
AppType appType = AppType.values()[
110-
RPrefs.getInt(APP_LIST_FILTER_METHOD, AppType.BOTH.ordinal())
110+
RPrefs.getInt(APP_LIST_FILTER_METHOD, AppType.ALL.ordinal())
111111
];
112112

113113
initAppList(appType);
@@ -186,8 +186,16 @@ private static List<AppInfoModel> getAllInstalledApps(Context context, AppType a
186186
List<ApplicationInfo> applications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
187187

188188
for (ApplicationInfo appInfo : applications) {
189-
String appName = appInfo.loadLabel(packageManager).toString();
190189
String packageName = appInfo.packageName;
190+
191+
if (appType == AppType.LAUNCHABLE) {
192+
Intent launchIntent = packageManager.getLaunchIntentForPackage(packageName);
193+
if (launchIntent == null) {
194+
continue;
195+
}
196+
}
197+
198+
String appName = appInfo.loadLabel(packageManager).toString();
191199
Drawable appIcon = appInfo.loadIcon(packageManager);
192200
boolean isSelected = OverlayManager.isOverlayEnabled(
193201
String.format(FABRICATED_OVERLAY_NAME_APPS, packageName)
@@ -198,7 +206,7 @@ private static List<AppInfoModel> getAllInstalledApps(Context context, AppType a
198206
boolean includeApp = switch (appType) {
199207
case SYSTEM -> isSystemApp;
200208
case USER -> !isSystemApp;
201-
case BOTH -> true;
209+
case LAUNCHABLE, ALL -> true;
202210
};
203211

204212
if (includeApp) {
@@ -234,10 +242,11 @@ private void showFilterDialog() {
234242
String[] items = {
235243
getString(R.string.filter_system_apps),
236244
getString(R.string.filter_user_apps),
237-
getString(R.string.filter_both)
245+
getString(R.string.filter_launchable_apps),
246+
getString(R.string.filter_all)
238247
};
239248

240-
int selectedFilterIndex = RPrefs.getInt(APP_LIST_FILTER_METHOD, AppType.BOTH.ordinal());
249+
int selectedFilterIndex = RPrefs.getInt(APP_LIST_FILTER_METHOD, AppType.ALL.ordinal());
241250

242251
new MaterialAlertDialogBuilder(requireContext())
243252
.setTitle(getString(R.string.filter_app_category))

app/src/main/res/values/strings.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,6 @@
157157
<string name="filter_app_category">Select app category</string>
158158
<string name="filter_system_apps">System apps</string>
159159
<string name="filter_user_apps">User apps</string>
160-
<string name="filter_both">Both</string>
160+
<string name="filter_launchable_apps">Launchable apps</string>
161+
<string name="filter_all">All apps</string>
161162
</resources>

0 commit comments

Comments
 (0)