Loading app/build.gradle +8 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,13 @@ android { kotlin.sourceSets.all { languageSettings.optIn("kotlin.RequiresOptIn") } testOptions { unitTests { includeAndroidResources = true returnDefaultValues = true } } } kapt { Loading Loading @@ -256,4 +263,5 @@ dependencies { testImplementation 'org.mockito:mockito-core:5.0.0' testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0' testImplementation 'org.robolectric:robolectric:4.9' testImplementation 'org.json:json:20180813' // Added to avoid SystemInfoProvider.getAppBuildInfo() mock error } app/src/main/java/foundation/e/apps/di/LoginModule.kt +9 −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,11 @@ 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/usecase/UserLoginUseCase.kt +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ class UserLoginUseCase @Inject constructor( fun anonymousUser(): Flow<Resource<AuthData>> = flow { try { emit(Resource.Loading) emit(Resource.Loading()) val userResponse = loginRepository.anonymousUser() emit(Resource.Success(userResponse)) } catch (e: Exception) { Loading app/src/main/java/foundation/e/apps/presentation/login/LoginState.kt 0 → 100644 +25 −0 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.presentation.login data class LoginState( val isLoading: Boolean = false, val isLoggedIn: Boolean = false, val error: String = "" ) app/src/main/java/foundation/e/apps/data/login/LoginViewModel.kt→app/src/main/java/foundation/e/apps/presentation/login/LoginViewModel.kt +32 −1 Original line number Diff line number Diff line Loading @@ -15,14 +15,21 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.apps.data.login package foundation.e.apps.presentation.login import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.data.enums.User import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.login.LoginSourceRepository import foundation.e.apps.domain.login.usecase.UserLoginUseCase import foundation.e.apps.ui.parentFragment.LoadingViewModel import foundation.e.apps.utils.Resource import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import javax.inject.Inject Loading @@ -33,6 +40,7 @@ import javax.inject.Inject @HiltViewModel class LoginViewModel @Inject constructor( private val loginSourceRepository: LoginSourceRepository, private val userLoginUseCase: UserLoginUseCase ) : ViewModel() { /** Loading Loading @@ -131,4 +139,27 @@ class LoginViewModel @Inject constructor( authObjects.postValue(listOf()) } } private val _loginState: MutableLiveData<LoginState> = MutableLiveData() val loginState: LiveData<LoginState> = _loginState fun authenticateAnonymousUser() { viewModelScope.launch { userLoginUseCase.anonymousUser().onEach { result -> when (result) { is Resource.Success -> { _loginState.value = LoginState(isLoggedIn = true) } is Resource.Error -> { _loginState.value = LoginState( error = result.message ?: "An unexpected error occured" ) } is Resource.Loading -> { _loginState.value = LoginState(isLoading = true) } } }.collect() } } } Loading
app/build.gradle +8 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,13 @@ android { kotlin.sourceSets.all { languageSettings.optIn("kotlin.RequiresOptIn") } testOptions { unitTests { includeAndroidResources = true returnDefaultValues = true } } } kapt { Loading Loading @@ -256,4 +263,5 @@ dependencies { testImplementation 'org.mockito:mockito-core:5.0.0' testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0' testImplementation 'org.robolectric:robolectric:4.9' testImplementation 'org.json:json:20180813' // Added to avoid SystemInfoProvider.getAppBuildInfo() mock error }
app/src/main/java/foundation/e/apps/di/LoginModule.kt +9 −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,11 @@ 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/usecase/UserLoginUseCase.kt +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ class UserLoginUseCase @Inject constructor( fun anonymousUser(): Flow<Resource<AuthData>> = flow { try { emit(Resource.Loading) emit(Resource.Loading()) val userResponse = loginRepository.anonymousUser() emit(Resource.Success(userResponse)) } catch (e: Exception) { Loading
app/src/main/java/foundation/e/apps/presentation/login/LoginState.kt 0 → 100644 +25 −0 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.presentation.login data class LoginState( val isLoading: Boolean = false, val isLoggedIn: Boolean = false, val error: String = "" )
app/src/main/java/foundation/e/apps/data/login/LoginViewModel.kt→app/src/main/java/foundation/e/apps/presentation/login/LoginViewModel.kt +32 −1 Original line number Diff line number Diff line Loading @@ -15,14 +15,21 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package foundation.e.apps.data.login package foundation.e.apps.presentation.login import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.data.enums.User import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.login.LoginSourceRepository import foundation.e.apps.domain.login.usecase.UserLoginUseCase import foundation.e.apps.ui.parentFragment.LoadingViewModel import foundation.e.apps.utils.Resource import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import javax.inject.Inject Loading @@ -33,6 +40,7 @@ import javax.inject.Inject @HiltViewModel class LoginViewModel @Inject constructor( private val loginSourceRepository: LoginSourceRepository, private val userLoginUseCase: UserLoginUseCase ) : ViewModel() { /** Loading Loading @@ -131,4 +139,27 @@ class LoginViewModel @Inject constructor( authObjects.postValue(listOf()) } } private val _loginState: MutableLiveData<LoginState> = MutableLiveData() val loginState: LiveData<LoginState> = _loginState fun authenticateAnonymousUser() { viewModelScope.launch { userLoginUseCase.anonymousUser().onEach { result -> when (result) { is Resource.Success -> { _loginState.value = LoginState(isLoggedIn = true) } is Resource.Error -> { _loginState.value = LoginState( error = result.message ?: "An unexpected error occured" ) } is Resource.Loading -> { _loginState.value = LoginState(isLoading = true) } } }.collect() } } }