Skip to content

Commit

Permalink
Removed combine flags implementation #378
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Dec 19, 2024
1 parent b0223b8 commit 02b480a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ object SortConstant {
const val SPLIT = 1 shl 4
const val UNINSTALLED = 1 shl 5
const val FOSS = 1 shl 6
const val COMBINE_FLAGS = 1 shl 7
const val ALL = DISABLED or ENABLED or APK or SPLIT

const val CATEGORY_UNSPECIFIED = 1L shl 1
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/app/simple/inure/dialogs/apps/AppsSort.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class AppsSort : ScopedBottomSheetFragment() {
sortChipGroup.removeView(view.findViewById(R.id.min_sdk))
}

filterChipGroup.removeView(view.findViewById(R.id.combine_flags))
setAppsCategory()
setAppsFilter()

Expand Down Expand Up @@ -189,12 +188,6 @@ class AppsSort : ScopedBottomSheetFragment() {
FlagUtils.unsetFlag(sourceFlags, SortConstant.FOSS)
}

// sourceFlags = if (checkedIds.contains(R.id.combine_flags)) {
// FlagUtils.setFlag(sourceFlags, SortConstant.COMBINE_FLAGS)
// } else {
// FlagUtils.unsetFlag(sourceFlags, SortConstant.COMBINE_FLAGS)
// }

AppsPreferences.setAppsFilter(sourceFlags)
}

Expand Down Expand Up @@ -335,10 +328,6 @@ class AppsSort : ScopedBottomSheetFragment() {
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.FOSS)) {
filterChipGroup.check(R.id.foss)
}

// if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.COMBINE_FLAGS)) {
// filterChipGroup.check(R.id.combine_flags)
// }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class AppsViewModel(application: Application) : DataGeneratorViewModel(applicati
return appData.value.isNullOrEmpty()
}

@Suppress("UNCHECKED_CAST")
fun loadAppData() {
viewModelScope.launch(Dispatchers.Default) {
var apps = (getInstalledApps() + getUninstalledApps()).toArrayList()
Expand Down Expand Up @@ -148,82 +147,67 @@ class AppsViewModel(application: Application) : DataGeneratorViewModel(applicati

var filteredList = arrayListOf<PackageInfo>()

/**
* We'll treat uninstalled as a separate app state other than disabled
* and enabled, so we'll invert the enabled flag, if the app is not
* installed to have it filtered out in case [SortConstant.UNINSTALLED]
* flag is not set.
*
* Combined flags should check for both enabled and disabled apps, if the
* app is not installed, it should be filtered out
*/
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.COMBINE_FLAGS)) {
filteredList.addAll((apps.clone() as ArrayList<PackageInfo>).parallelStream().filter { packageInfo ->
checkCombinedFlags(packageInfo)
}.collect(Collectors.toList()) as ArrayList<PackageInfo>)
} else {
for (packageInfo in apps) {
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.UNINSTALLED)) {
if (packageInfo.safeApplicationInfo.flags and ApplicationInfo.FLAG_INSTALLED == 0) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
for (packageInfo in apps) {
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.UNINSTALLED)) {
if (packageInfo.safeApplicationInfo.flags and ApplicationInfo.FLAG_INSTALLED == 0) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
}
}

if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.SPLIT)) {
if (packageInfo.safeApplicationInfo.splitSourceDirs?.isNotEmpty() == true) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.SPLIT)) {
if (packageInfo.safeApplicationInfo.splitSourceDirs?.isNotEmpty() == true) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
}
}

if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.DISABLED)) {
if (!packageInfo.safeApplicationInfo.enabled &&
packageInfo.safeApplicationInfo.flags and ApplicationInfo.FLAG_INSTALLED != 0) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.DISABLED)) {
if (!packageInfo.safeApplicationInfo.enabled &&
packageInfo.safeApplicationInfo.flags and ApplicationInfo.FLAG_INSTALLED != 0) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
}
}

if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.APK)) {
if (packageInfo.safeApplicationInfo.splitSourceDirs.isNullOrEmpty()) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.APK)) {
if (packageInfo.safeApplicationInfo.splitSourceDirs.isNullOrEmpty()) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
}
}

if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.ENABLED)) {
if (packageInfo.safeApplicationInfo.enabled &&
packageInfo.safeApplicationInfo.flags and ApplicationInfo.FLAG_INSTALLED != 0) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.ENABLED)) {
if (packageInfo.safeApplicationInfo.enabled &&
packageInfo.safeApplicationInfo.flags and ApplicationInfo.FLAG_INSTALLED != 0) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
}
}

if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.FOSS)) {
if (FOSSParser.isPackageFOSS(packageInfo)) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
if (FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.FOSS)) {
if (FOSSParser.isPackageFOSS(packageInfo)) {
if (!filteredList.contains(packageInfo)) {
filteredList.add(packageInfo)
}
}
}

// Remove duplicate elements
filteredList = filteredList.stream().distinct().collect(Collectors.toList()) as ArrayList<PackageInfo>
}

// Remove duplicate elements
filteredList = filteredList.stream().distinct().collect(Collectors.toList()) as ArrayList<PackageInfo>
filteredList.getSortedList(AppsPreferences.getSortStyle(), AppsPreferences.isReverseSorting())

appData.postValue(filteredList as ArrayList<PackageInfo>?)
}
}

@Suppress("unused")
private fun checkCombinedFlags(packageInfo: PackageInfo): Boolean {
return when {
FlagUtils.isFlagSet(AppsPreferences.getAppsFilter(), SortConstant.DISABLED) -> {
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/layout/dialog_sort_apps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,6 @@
android:layout_height="wrap_content"
android:text="@string/foss" />

<app.simple.inure.decorations.views.Chip
android:id="@+id/combine_flags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/combine_flags" />

</com.google.android.material.chip.ChipGroup>

</app.simple.inure.decorations.corners.DynamicCornerLinearLayout>
Expand Down

0 comments on commit 02b480a

Please sign in to comment.