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

Commit 46b10a8f authored by Jonathan Klee's avatar Jonathan Klee
Browse files

refactor(core): adopt domain source and store contracts

parent 0c6733aa
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ package foundation.e.apps.data
import foundation.e.apps.data.cleanapk.repositories.CleanApkAppsRepository
import foundation.e.apps.data.cleanapk.repositories.CleanApkPwaRepository
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 foundation.e.apps.data.playstore.PlayStoreRepository
import foundation.e.apps.data.preference.AppLoungePreference
import foundation.e.apps.domain.enums.Source.OPEN_SOURCE
import foundation.e.apps.domain.enums.Source.PLAY_STORE
import foundation.e.apps.domain.enums.Source.PWA
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -40,7 +40,7 @@ class Stores @Inject constructor(
    cleanApkAppsRepository: CleanApkAppsRepository,
    cleanApkPwaRepository: CleanApkPwaRepository,
    appLoungePreference: AppLoungePreference
) {
) : foundation.e.apps.domain.Stores {

    private val storeConfigs: Map<Source, StoreConfig> = buildStoreConfigs(
        playStoreRepository,
@@ -66,28 +66,28 @@ class Stores @Inject constructor(
            .mapValues { it.value.repository }
    }

    fun getEnabledSearchSources(): List<Source> =
    override 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) {
    override fun enableStore(source: Source) {
        storeConfigs[source]?.enable?.invoke()
            ?: error("No matching Store found for $source.")

        _enabledStoresFlow.update { provideEnabledStores() }
    }

    fun disableStore(source: Source) {
    override fun disableStore(source: Source) {
        storeConfigs[source]?.disable?.invoke()
            ?: error("No matching Store found for $source.")

        _enabledStoresFlow.update { provideEnabledStores() }
    }

    fun isStoreEnabled(source: Source): Boolean =
    override fun isStoreEnabled(source: Source): Boolean =
        storeConfigs[source]?.isEnabled?.invoke() == true

    private fun provideEnabledStores(): Set<Source> =
+16 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.di.bindings

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import foundation.e.apps.data.Stores
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface DomainBindingsModule {
    @Binds
    @Singleton
    fun bindStores(impl: Stores): foundation.e.apps.domain.Stores
}
+1 −17
Original line number Diff line number Diff line
@@ -17,20 +17,4 @@

package foundation.e.apps.data.enums

import androidx.annotation.StringRes
import foundation.e.apps.R

enum class Source(@param:StringRes val stringResId: Int?) {
    OPEN_SOURCE(R.string.open_source),
    PWA(R.string.pwa),
    SYSTEM_APP(R.string.system_app),
    PLAY_STORE(null);

    fun toString(getString: (Int) -> String) = stringResId?.let(getString) ?: ""

    companion object {
        fun fromStringResId(@StringRes source: Int): Source {
            return entries.find { it.stringResId == source } ?: PLAY_STORE
        }
    }
}
typealias Source = foundation.e.apps.domain.enums.Source
+2 −1
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import foundation.e.apps.ui.application.ShareButtonVisibilityState.Hidden
import foundation.e.apps.ui.application.ShareButtonVisibilityState.Visible
import foundation.e.apps.ui.application.model.ApplicationScreenshotsRVAdapter
import foundation.e.apps.ui.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.ui.extensions.toDisplayString
import foundation.e.apps.ui.parentFragment.TimeoutFragment
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
@@ -447,7 +448,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
            val source = if (isFdroidDeepLink) Source.OPEN_SOURCE else args.source
            if (source == Source.OPEN_SOURCE || source == Source.PWA) {
                sourceTag.visibility = View.VISIBLE
                sourceTag.text = it.source.toString(::getString)
                sourceTag.text = it.source.toDisplayString(::getString)
            }
            appIcon.load(it.iconUrl)
        }
+2 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import foundation.e.apps.ui.AppProgressViewModel
import foundation.e.apps.ui.MainActivityViewModel
import foundation.e.apps.ui.PrivacyInfoViewModel
import foundation.e.apps.ui.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.ui.extensions.sourceFromStringResId
import foundation.e.apps.ui.parentFragment.TimeoutFragment
import kotlinx.coroutines.launch
import java.util.Locale
@@ -229,7 +230,7 @@ class ApplicationListFragment :
         * Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/478
         */
        showLoadingUI()
        val sourceType = Source.fromStringResId(args.source)
        val sourceType = sourceFromStringResId(args.source)
        viewModel.loadList(args.category, args.source)
        if (sourceType != Source.OPEN_SOURCE && sourceType != Source.PWA) {
            /*
Loading