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

Commit b07b807d authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Rename LoginSourceInterface to StoreAuthenticator

parent e2dd1688
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.login.LoginSourceGPlay
import foundation.e.apps.data.login.GooglePlayAuthenticator
import foundation.e.apps.data.login.LoginViewModel
import foundation.e.apps.data.login.exceptions.GPlayValidationException
import foundation.e.apps.data.preference.PreferenceManagerModule
@@ -308,7 +308,7 @@ class MainActivity : AppCompatActivity() {
            binding.sessionErrorLayout.visibility = View.VISIBLE
            binding.retrySessionButton.setOnClickListener {
                binding.sessionErrorLayout.visibility = View.GONE
                loginViewModel.startLoginFlow(listOf(LoginSourceGPlay::class.java.simpleName))
                loginViewModel.startLoginFlow(listOf(GooglePlayAuthenticator::class.java.simpleName))
            }
        }
    }
+3 −3
Original line number Diff line number Diff line
@@ -27,14 +27,14 @@ import javax.inject.Singleton
 * https://gitlab.e.foundation/e/backlog/-/issues/5680
 */
@Singleton
class LoginSourceCleanApk @Inject constructor(
class CleanApkAuthenticator @Inject constructor(
    val loginDataStore: LoginDataStore,
) : LoginSourceInterface {
) : StoreAuthenticator {

    private val user: User
        get() = loginDataStore.getUserType()

    override fun isActive(): Boolean {
    override fun isStoreActive(): Boolean {
        if (user == User.UNAVAILABLE) {
            /*
             * UNAVAILABLE user means first login is not completed.
+3 −3
Original line number Diff line number Diff line
@@ -40,11 +40,11 @@ import javax.inject.Singleton
 * https://gitlab.e.foundation/e/backlog/-/issues/5680
 */
@Singleton
class LoginSourceGPlay @Inject constructor(
class GooglePlayAuthenticator @Inject constructor(
    @ApplicationContext private val context: Context,
    private val gson: Gson,
    private val loginDataStore: LoginDataStore,
) : LoginSourceInterface, AuthDataValidator {
) : StoreAuthenticator, AuthDataValidator {

    @Inject
    lateinit var gPlayApiFactory: GPlayApiFactory
@@ -61,7 +61,7 @@ class LoginSourceGPlay @Inject constructor(
    private val locale: Locale
        get() = context.resources.configuration.locales[0]

    override fun isActive(): Boolean {
    override fun isStoreActive(): Boolean {
        if (user == User.UNAVAILABLE) {
            /*
             * UNAVAILABLE user means first login is not completed.
+7 −7
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import javax.inject.Singleton
@Singleton
class LoginSourceRepository @Inject constructor(
    private val loginCommon: LoginCommon,
    private val sources: List<LoginSourceInterface>,
    private val authenticators: List<StoreAuthenticator>,
) {

    var gplayAuth: AuthData? = null
@@ -38,13 +38,13 @@ class LoginSourceRepository @Inject constructor(

        val authObjectsLocal = ArrayList<AuthObject>()

        for (source in sources) {
            if (!source.isActive()) continue
            if (source::class.java.simpleName in clearAuthTypes) {
                source.clearSavedAuth()
        for (authenticator in authenticators) {
            if (!authenticator.isStoreActive()) continue
            if (authenticator::class.java.simpleName in clearAuthTypes) {
                authenticator.clearSavedAuth()
            }

            val authObject = source.getAuthObject()
            val authObject = authenticator.getAuthObject()
            authObjectsLocal.add(authObject)

            if (authObject is AuthObject.GPlayAuth) {
@@ -72,7 +72,7 @@ class LoginSourceRepository @Inject constructor(
    }

    suspend fun getValidatedAuthData(): ResultSupreme<AuthData?> {
        val authDataValidator = (sources.find { it is AuthDataValidator } as AuthDataValidator)
        val authDataValidator = (authenticators.find { it is AuthDataValidator } as AuthDataValidator)
        val validateAuthData = authDataValidator.validateAuthData()
        this.gplayAuth = validateAuthData.data
        return validateAuthData
+3 −6
Original line number Diff line number Diff line
@@ -18,13 +18,10 @@
package foundation.e.apps.data.login

/**
 * Interface that defines what methods a login source must define.
 * Login sources (can also be called - data sources): Google Play, CleanApk.
 *
 * https://gitlab.e.foundation/e/backlog/-/issues/5680
 * Store (Google Play Store, Clean Apk) authenticator.
 */
interface LoginSourceInterface {
interface StoreAuthenticator {
    suspend fun getAuthObject(): AuthObject
    suspend fun clearSavedAuth()
    fun isActive(): Boolean
    fun isStoreActive(): Boolean
}
Loading