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

Commit bcbdf18d authored by Nishant Dande's avatar Nishant Dande
Browse files

Network module integration

parent 029ac0ba
Loading
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ 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.login.repository.LoginRepositoryImpl
import foundation.e.apps.domain.login.usecase.UserLoginUseCase

@InstallIn(SingletonComponent::class)
@Module
@@ -36,4 +38,12 @@ object LoginModule {
    ): List<LoginSourceInterface> {
        return listOf(gPlay, cleanApk)
    }

    @Provides
    fun provideLoginUserCase(
        loginRepositoryImpl: LoginRepositoryImpl
    ): UserLoginUseCase {
        return UserLoginUseCase(loginRepositoryImpl)
    }

}
+13 −0
Original line number Diff line number Diff line
package foundation.e.apps.domain.login.repository

import app.lounge.model.AnonymousAuthDataRequestBody
import app.lounge.model.AuthDataResponse


interface LoginRepository {

    suspend fun anonymousUser(
        authDataRequestBody: AnonymousAuthDataRequestBody
    ): AuthDataResponse

}
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
package foundation.e.apps.domain.login.repository

import app.lounge.model.AnonymousAuthDataRequestBody
import app.lounge.model.AuthDataResponse
import app.lounge.networking.NetworkFetching
import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(
    private val networkFetching: NetworkFetching
): LoginRepository {

    override suspend fun anonymousUser(authDataRequestBody: AnonymousAuthDataRequestBody): AuthDataResponse {
        return networkFetching.requestAuthData(
            anonymousAuthDataRequestBody = authDataRequestBody
        )
    }

}
+37 −0
Original line number Diff line number Diff line
package foundation.e.apps.domain.login.usecase

import app.lounge.model.AnonymousAuthDataRequestBody
import app.lounge.model.AuthDataResponse
import foundation.e.apps.domain.login.repository.LoginRepository
import foundation.e.apps.utils.Resource
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import retrofit2.HttpException
import java.io.IOException
import java.util.Properties
import javax.inject.Inject

class UserLoginUseCase @Inject constructor(
    private val loginRepository: LoginRepository,
) {

    operator fun invoke(
        properties: Properties,
        userAgent: String
    ): Flow<Resource<AuthDataResponse>> = flow {
        try {
            emit(Resource.Loading())
            val userResponse: AuthDataResponse = loginRepository.anonymousUser(
                authDataRequestBody = AnonymousAuthDataRequestBody(
                    properties = properties,
                    userAgent = userAgent
                )
            )
            emit(Resource.Success(userResponse))
        } catch(e: HttpException) {
            emit(Resource.Error(e.localizedMessage ?: "An unexpected error occured"))
        } catch(e: IOException) {
            emit(Resource.Error("Couldn't reach server. Check your internet connection."))
        }
    }
}
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
package foundation.e.apps.presentation.login


data class LoginState(
    val isLoading: Boolean = false,
    val isLoggedIn: Boolean = false,
    val error: String = ""
)
Loading