From e0e26f5741bb641aa0167d53a43efb5f4bbbe1af Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Thu, 27 Nov 2025 14:34:53 +0600 Subject: [PATCH] fix: allow maximum 3 open-source apps while common apps are active When common apps are active, users will see maximum 3 open-source apps by default. If users click on a filter, all open-source apps will be visible. When common apps are disabled in the Settings, all open-source apps will be loaded and visible. The logic for replacing common apps with their F-Droid counterparts is removed. Those apps will be visible as part of common apps. Same goes for PWAs. --- .../search/SearchRepositoryImpl.kt | 37 +------------------ .../e/apps/ui/search/SearchFragment.kt | 1 - .../e/apps/ui/search/SearchViewModel.kt | 21 ++++++++++- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/application/search/SearchRepositoryImpl.kt b/app/src/main/java/foundation/e/apps/data/application/search/SearchRepositoryImpl.kt index 09f72fcba..8287790d9 100644 --- a/app/src/main/java/foundation/e/apps/data/application/search/SearchRepositoryImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/application/search/SearchRepositoryImpl.kt @@ -25,7 +25,6 @@ import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.Stores import foundation.e.apps.data.application.ApplicationDataManager import foundation.e.apps.data.application.data.Application -import foundation.e.apps.data.cleanapk.repositories.CleanApkRepository import foundation.e.apps.data.enums.ResultStatus import foundation.e.apps.data.enums.Source import foundation.e.apps.data.handleNetworkResult @@ -254,7 +253,7 @@ class SearchRepositoryImpl @Inject constructor( val searchResults = stores.getStore(source)?.getSearchResults(query) ?: error("Couldn't get Store for Source: $source") - val apps = replaceWithFDroid(searchResults).toMutableList() + val apps = searchResults.toMutableList() if (searchResults.isNotEmpty()) { apps.add(Application(isPlaceHolder = true)) } @@ -269,38 +268,4 @@ class SearchRepositoryImpl @Inject constructor( exception = GPlayIOException("Unable to reach Google Play API") ) } - - /* - * Replaces Play Store apps with their F-Droid counterpart if exist, - * otherwise returns the Play Store apps as-is. - */ - private suspend fun replaceWithFDroid(playStoreApps: List): List { - if (playStoreApps.isEmpty()) { - return emptyList() - } - - val replacedApps = when (val storeRepository = stores.getStore(Source.OPEN_SOURCE)) { - is CleanApkRepository -> { - val packageNames = playStoreApps.map { it.package_name } - val response = storeRepository.checkAvailablePackages(packageNames) - - if (response.isSuccessful) { - val availableApps = response.body()?.apps ?: emptyList() - playStoreApps.map { playStoreApp -> - availableApps.find { it.package_name == playStoreApp.package_name } - ?.apply { - isGplayReplaced = true - source = Source.OPEN_SOURCE - } ?: playStoreApp - } - } else { - playStoreApps - } - } - - else -> playStoreApps - } - - return replacedApps - } } diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt index 962fdb715..530ad5ff8 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt @@ -282,7 +282,6 @@ class SearchFragment : Fragment(R.layout.fragment_search), ApplicationInstaller, binding.filterChipGroup.isSingleSelection = true val listener = OnCheckedChangeListener { _, _ -> - showLoadingUi() searchViewModel.setFilterFlags( flagOpenSource = filterChipOpenSource.isChecked, flagPWA = filterChipPWA.isChecked, diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt index 6e89038e3..b34883055 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt @@ -63,6 +63,9 @@ class SearchViewModel @Inject constructor( companion object { private const val SEARCH_DEBOUNCE_DELAY_MILLIS = 500L + + // Reference hotfix: https://gitlab.e.foundation/e/os/backlog/-/issues/3851 + private const val REDUCED_NUMBER_OF_SEARCH_RESULTS = 3 } private val _searchUiState: MutableStateFlow = @@ -110,6 +113,7 @@ class SearchViewModel @Inject constructor( this.flagPWA = flagPWA viewModelScope.launch(Dispatchers.IO) { + loadData() emitFilteredResults(null) } } @@ -142,10 +146,25 @@ class SearchViewModel @Inject constructor( isCleanApkDataLoading = true val searchResults = searchRepository.getOpenSourceSearchResults(query) + val apps = searchResults.data?.first.orEmpty() + + val shouldShowAllOpenSourceApps = + flagOpenSource || flagPWA || !stores.isStoreEnabled(Source.PLAY_STORE) + + val numberOfSearchResults = if (shouldShowAllOpenSourceApps) { + apps.size + } else { + REDUCED_NUMBER_OF_SEARCH_RESULTS + } + isCleanApkDataLoading = false - emitFilteredResults(searchResults) + val results = ResultSupreme.create( + searchResults.getResultStatus(), + searchResults.data?.copy(first = apps.take(numberOfSearchResults)) + ) + emitFilteredResults(results) } } -- GitLab