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

Commit 98b6d5ae authored by Nishant Dande's avatar Nishant Dande
Browse files

Rename CommonRepository to CacheRepository

parent 90be9cce
Loading
Loading
Loading
Loading
Loading
+11 −11
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import dagger.hilt.components.SingletonComponent
import foundation.e.apps.data.login.LoginSourceCleanApk
import foundation.e.apps.data.login.LoginSourceGPlay
import foundation.e.apps.data.login.LoginSourceInterface
import foundation.e.apps.domain.common.repository.CommonRepositoryImpl
import foundation.e.apps.domain.common.repository.CacheRepositoryImpl
import foundation.e.apps.domain.install.usecase.AppInstallerUseCase
import foundation.e.apps.domain.login.repository.LoginRepositoryImpl
import foundation.e.apps.domain.login.usecase.UserLoginUseCase
@@ -47,36 +47,36 @@ object LoginModule {
    @Provides
    fun provideLoginUserCase(
        loginRepositoryImpl: LoginRepositoryImpl,
        commonRepositoryImpl: CommonRepositoryImpl
        cacheRepositoryImpl: CacheRepositoryImpl
    ): UserLoginUseCase {
        return UserLoginUseCase(loginRepositoryImpl, commonRepositoryImpl)
        return UserLoginUseCase(loginRepositoryImpl, cacheRepositoryImpl)
    }

    @Provides
    fun provideSettingsUserCase(
        commonRepositoryImpl: CommonRepositoryImpl
        cacheRepositoryImpl: CacheRepositoryImpl
    ): SettingsUseCase {
        return SettingsUseCase(commonRepositoryImpl)
        return SettingsUseCase(cacheRepositoryImpl)
    }

    @Provides
    fun provideMainActivityUseCase(
        commonRepositoryImpl: CommonRepositoryImpl
        cacheRepositoryImpl: CacheRepositoryImpl
    ): MainActivityUseCase {
        return MainActivityUseCase(commonRepositoryImpl)
        return MainActivityUseCase(cacheRepositoryImpl)
    }

    @Provides
    fun provideUpdatesUseCase(
        commonRepositoryImpl: CommonRepositoryImpl
        cacheRepositoryImpl: CacheRepositoryImpl
    ): UpdatesUseCase {
        return UpdatesUseCase(commonRepositoryImpl)
        return UpdatesUseCase(cacheRepositoryImpl)
    }

    @Provides
    fun provideAppInstallerUseCase(
        commonRepositoryImpl: CommonRepositoryImpl
        cacheRepositoryImpl: CacheRepositoryImpl
    ): AppInstallerUseCase {
        return AppInstallerUseCase(commonRepositoryImpl)
        return AppInstallerUseCase(cacheRepositoryImpl)
    }
}
+0 −29
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * 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.common.repository

import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.data.enums.User

interface CommonRepository {
    fun currentUser(): User
    fun cacheAuthData(): AuthData
    fun resetCachedData()
    fun clearAuthData()
}
+0 −60
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * Apps  Quickly and easily install Android apps onto your device!
 *
 * 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.common.repository

import android.content.Context
import app.lounge.storage.cache.configurations
import com.aurora.gplayapi.data.models.AuthData
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.data.enums.User
import foundation.e.apps.utils.toAuthData
import javax.inject.Inject

class CommonRepositoryImpl @Inject constructor(
    @ApplicationContext val applicationContext: Context
) : CommonRepository {

    override fun currentUser(): User {
        return applicationContext.configurations.userType.takeIf { it.isNotEmpty() }
            ?.let { User.getUser(it) }
            ?: run { User.UNAVAILABLE }
    }
    override fun resetCachedData() {
        applicationContext.configurations.apply {
            authData = ""
            userType = User.UNAVAILABLE.name
            email = ""
            oauthtoken = ""
            showAllApplications = true
            showFOSSApplications = true
            showPWAApplications = true
            // TODO: reset access token for Google login. It is not defined yet.
        }
    }

    override fun cacheAuthData(): AuthData =
        applicationContext.configurations.authData.let { data ->
            if (data.isEmpty()) throw Exception("Auth Data not available")
            return data.toAuthData()
        }

    override fun clearAuthData() {
        applicationContext.configurations.authData = ""
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -20,19 +20,19 @@ package foundation.e.apps.domain.install.usecase

import com.aurora.gplayapi.data.models.AuthData
import foundation.e.apps.data.enums.User
import foundation.e.apps.domain.common.repository.CommonRepository
import foundation.e.apps.domain.common.repository.CacheRepository
import java.util.Locale
import javax.inject.Inject

class AppInstallerUseCase@Inject constructor(
    private val commonRepository: CommonRepository
    private val cacheRepository: CacheRepository
) {

    fun currentAuthData(): AuthData? {
        return try {
            commonRepository.cacheAuthData()
            cacheRepository.cacheAuthData()
        } catch (e: Exception) {
            if (commonRepository.currentUser() == User.NO_GOOGLE) {
            if (cacheRepository.currentUser() == User.NO_GOOGLE) {
                return AuthData("", "").apply {
                    this.isAnonymous = false
                    this.locale = Locale.getDefault()
+2 −2
Original line number Diff line number Diff line
@@ -60,10 +60,10 @@ class LoginRepositoryImpl @Inject constructor(
    }

    // TODO: Remove function parameter once we refactor Google User APIs
    override suspend fun googleUser(authData: AuthData, token: String) {
    override suspend fun googleUser(authData: AuthData, oauthToken: String) {
        applicationContext.configurations.authData = authData.toJsonString()
        applicationContext.configurations.email = authData.email
        applicationContext.configurations.oauthtoken = token
        applicationContext.configurations.oauthtoken = oauthToken
        applicationContext.configurations.userType = User.GOOGLE.name
    }
}
Loading