Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit 58dcdb9c authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor: centralize enabled search sources in Stores

Replace the ResolveEnabledSearchSourcesUseCase with a single Stores API so search selection logic stays consistent across use cases and the ViewModel, and update tests accordingly.
parent 6e8d0806
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ class Stores @Inject constructor(
        appLoungePreference
    )

    private val searchEligibleSources = storeConfigs.keys

    private val _enabledStoresFlow = MutableStateFlow(provideEnabledStores())
    val enabledStoresFlow: StateFlow<Set<Source>> = _enabledStoresFlow.asStateFlow()

@@ -64,6 +66,11 @@ class Stores @Inject constructor(
            .mapValues { it.value.repository }
    }

    fun getEnabledSearchSources(): List<Source> =
        storeConfigs
            .filter { (source, config) -> source in searchEligibleSources && config.isEnabled() }
            .map { (source, _) -> source }

    fun getStore(source: Source): StoreRepository? = getStores()[source]

    fun enableStore(source: Source) {
+3 −2
Original line number Diff line number Diff line
@@ -18,11 +18,12 @@

package foundation.e.apps.domain.search

import foundation.e.apps.data.Stores
import foundation.e.apps.data.enums.Source
import javax.inject.Inject

class PrepareSearchSubmissionUseCase @Inject constructor(
    private val resolveEnabledSearchSourcesUseCase: ResolveEnabledSearchSourcesUseCase,
    private val stores: Stores,
) {
    operator fun invoke(
        submittedQuery: String,
@@ -30,7 +31,7 @@ class PrepareSearchSubmissionUseCase @Inject constructor(
        currentVersion: Int,
    ): SearchSubmissionResult {
        val trimmedQuery = submittedQuery.trim()
        val enabledSources = resolveEnabledSearchSourcesUseCase()
        val enabledSources = stores.getEnabledSearchSources()
        val resolvedSelectedSource = selectedSource?.takeIf { enabledSources.contains(it) }
            ?: enabledSources.firstOrNull()
        val shouldIncrementVersion = trimmedQuery.isNotEmpty()
+0 −39
Original line number Diff line number Diff line
/*
 * Copyright (C) 2026 e Foundation
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package foundation.e.apps.domain.search

import foundation.e.apps.data.Stores
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.Source.OPEN_SOURCE
import foundation.e.apps.data.enums.Source.PLAY_STORE
import foundation.e.apps.data.enums.Source.PWA
import javax.inject.Inject

class ResolveEnabledSearchSourcesUseCase @Inject constructor(
    private val stores: Stores,
) {
    operator fun invoke(): List<Source> {
        return stores.getStores().mapNotNull { (key, _) ->
            when (key) {
                PLAY_STORE, OPEN_SOURCE, PWA -> key
                else -> null
            }
        }
    }
}
+3 −2
Original line number Diff line number Diff line
@@ -18,12 +18,13 @@

package foundation.e.apps.domain.search

import foundation.e.apps.data.Stores
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.preference.AppLoungePreference
import javax.inject.Inject

class UpdateSearchForStoreSelectionUseCase @Inject constructor(
    private val resolveEnabledSearchSourcesUseCase: ResolveEnabledSearchSourcesUseCase,
    private val stores: Stores,
    private val appLoungePreference: AppLoungePreference,
) {
    operator fun invoke(
@@ -32,7 +33,7 @@ class UpdateSearchForStoreSelectionUseCase @Inject constructor(
        hasSubmittedSearch: Boolean,
        currentVersion: Int,
    ): StoreSelectionUpdate {
        val enabledSources = resolveEnabledSearchSourcesUseCase()
        val enabledSources = stores.getEnabledSearchSources()
        val resolvedSelectedSource = selectedSource?.takeIf { enabledSources.contains(it) }
            ?: enabledSources.firstOrNull()
        val updatedHasSubmittedSearch = hasSubmittedSearch && enabledSources.isNotEmpty()
+3 −5
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import foundation.e.apps.domain.search.CleanApkSearchPagingUseCase
import foundation.e.apps.domain.search.FetchSearchSuggestionsUseCase
import foundation.e.apps.domain.search.PlayStoreSearchPagingUseCase
import foundation.e.apps.domain.search.PrepareSearchSubmissionUseCase
import foundation.e.apps.domain.search.ResolveEnabledSearchSourcesUseCase
import foundation.e.apps.domain.search.SearchRequest
import foundation.e.apps.domain.search.UpdateSearchForStoreSelectionUseCase
import foundation.e.apps.install.download.data.DownloadProgress
@@ -86,7 +85,6 @@ class SearchViewModelV2 @Inject constructor(
    private val appLoungePreference: AppLoungePreference,
    cleanApkSearchPagingUseCase: CleanApkSearchPagingUseCase,
    playStoreSearchPagingUseCase: PlayStoreSearchPagingUseCase,
    private val resolveEnabledSearchSourcesUseCase: ResolveEnabledSearchSourcesUseCase,
    private val fetchSearchSuggestionsUseCase: FetchSearchSuggestionsUseCase,
    private val prepareSearchSubmissionUseCase: PrepareSearchSubmissionUseCase,
    private val updateSearchForStoreSelectionUseCase: UpdateSearchForStoreSelectionUseCase,
@@ -95,7 +93,7 @@ class SearchViewModelV2 @Inject constructor(
    private val installStatusReconciler: InstallStatusReconciler,
) : ViewModel() {

    private val initialVisibleTabs = resolveEnabledSearchSourcesUseCase().toSearchTabTypes()
    private val initialVisibleTabs = stores.getEnabledSearchSources().toSearchTabTypes()

    private val _uiState = MutableStateFlow(
        SearchUiState(
@@ -150,7 +148,7 @@ class SearchViewModelV2 @Inject constructor(

        suggestionJob?.cancel()
        if (newQuery.isBlank()) {
            val visibleTabs = resolveEnabledSearchSourcesUseCase().toSearchTabTypes()
            val visibleTabs = stores.getEnabledSearchSources().toSearchTabTypes()
            _uiState.update { current ->
                SearchUiStateReducer.reduceQueryCleared(current, visibleTabs)
            }
@@ -185,7 +183,7 @@ class SearchViewModelV2 @Inject constructor(

    fun onQueryCleared() {
        suggestionJob?.cancel()
        val visibleTabs = resolveEnabledSearchSourcesUseCase().toSearchTabTypes()
        val visibleTabs = stores.getEnabledSearchSources().toSearchTabTypes()
        _uiState.update { current ->
            SearchUiStateReducer.reduceQueryCleared(current, visibleTabs)
        }
Loading