Loading app/src/main/java/foundation/e/apps/di/LoginModule.kt +10 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -36,4 +38,12 @@ object LoginModule { ): List<LoginSourceInterface> { return listOf(gPlay, cleanApk) } @Provides fun provideLoginUserCase( loginRepositoryImpl: LoginRepositoryImpl ): UserLoginUseCase { return UserLoginUseCase(loginRepositoryImpl) } } app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepository.kt 0 → 100644 +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 app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepositoryImpl.kt 0 → 100644 +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 ) } } app/src/main/java/foundation/e/apps/domain/login/usecase/UserLoginUseCase.kt 0 → 100644 +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 app/src/main/java/foundation/e/apps/presentation/login/LoginState.kt 0 → 100644 +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
app/src/main/java/foundation/e/apps/di/LoginModule.kt +10 −0 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -36,4 +38,12 @@ object LoginModule { ): List<LoginSourceInterface> { return listOf(gPlay, cleanApk) } @Provides fun provideLoginUserCase( loginRepositoryImpl: LoginRepositoryImpl ): UserLoginUseCase { return UserLoginUseCase(loginRepositoryImpl) } }
app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepository.kt 0 → 100644 +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
app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepositoryImpl.kt 0 → 100644 +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 ) } }
app/src/main/java/foundation/e/apps/domain/login/usecase/UserLoginUseCase.kt 0 → 100644 +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
app/src/main/java/foundation/e/apps/presentation/login/LoginState.kt 0 → 100644 +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 = "" )