Loading app/build.gradle +6 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,8 @@ allOpen { dependencies { implementation project(':modules') // TODO: Add splitinstall-lib to a repo https://gitlab.e.foundation/e/os/backlog/-/issues/628 api files('libs/splitinstall-lib.jar') Loading Loading @@ -250,4 +252,8 @@ dependencies { // elib implementation 'foundation.e:elib:0.0.1-alpha11' testImplementation 'org.mockito:mockito-core:5.0.0' testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0' testImplementation 'org.robolectric:robolectric:4.9' } app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepository.kt 0 → 100644 +29 −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.domain.login.repository import app.lounge.model.AnonymousAuthDataRequestBody import com.aurora.gplayapi.data.models.AuthData interface LoginRepository { suspend fun anonymousUser( authDataRequestBody: AnonymousAuthDataRequestBody ): AuthData } app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepositoryImpl.kt 0 → 100644 +49 −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.domain.login.repository import android.content.Context import app.lounge.login.anonymous.AnonymousUser import app.lounge.model.AnonymousAuthDataRequestBody import app.lounge.networking.NetworkResult import app.lounge.storage.cache.configurations import com.aurora.gplayapi.data.models.AuthData import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject class LoginRepositoryImpl @Inject constructor( private val networkFetching: AnonymousUser, @ApplicationContext val applicationContext: Context ) : LoginRepository { override suspend fun anonymousUser(authDataRequestBody: AnonymousAuthDataRequestBody): AuthData { val result = networkFetching.requestAuthData( anonymousAuthDataRequestBody = authDataRequestBody ) when (result) { is NetworkResult.Error -> throw Exception(result.errorMessage, result.exception) is NetworkResult.Success -> { applicationContext.configurations.authData = result.data.toString() return result.data } } } } app/src/main/java/foundation/e/apps/domain/login/usecase/UserLoginUseCase.kt 0 → 100644 +51 −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.domain.login.usecase import app.lounge.model.AnonymousAuthDataRequestBody import com.aurora.gplayapi.data.models.AuthData import foundation.e.apps.domain.login.repository.LoginRepository import foundation.e.apps.utils.Resource import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.single import java.util.Properties import javax.inject.Inject class UserLoginUseCase @Inject constructor( private val loginRepository: LoginRepository, ) { suspend operator fun invoke( properties: Properties, userAgent: String ): Resource<AuthData> = flow { try { emit(Resource.Loading()) val userResponse = loginRepository.anonymousUser( authDataRequestBody = AnonymousAuthDataRequestBody( properties = properties, userAgent = userAgent ) ) emit(Resource.Success(userResponse)) } catch (e: Exception) { emit(Resource.Error(e.localizedMessage)) } }.single() } app/src/main/java/foundation/e/apps/utils/Resource.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.utils sealed class Resource<T>(val data: T? = null, val message: String? = null) { class Success<T>(data: T) : Resource<T>(data) class Error<T>(message: String, data: T? = null) : Resource<T>(data, message) class Loading<T>(data: T? = null) : Resource<T>(data) } Loading
app/build.gradle +6 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,8 @@ allOpen { dependencies { implementation project(':modules') // TODO: Add splitinstall-lib to a repo https://gitlab.e.foundation/e/os/backlog/-/issues/628 api files('libs/splitinstall-lib.jar') Loading Loading @@ -250,4 +252,8 @@ dependencies { // elib implementation 'foundation.e:elib:0.0.1-alpha11' testImplementation 'org.mockito:mockito-core:5.0.0' testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0' testImplementation 'org.robolectric:robolectric:4.9' }
app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepository.kt 0 → 100644 +29 −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.domain.login.repository import app.lounge.model.AnonymousAuthDataRequestBody import com.aurora.gplayapi.data.models.AuthData interface LoginRepository { suspend fun anonymousUser( authDataRequestBody: AnonymousAuthDataRequestBody ): AuthData }
app/src/main/java/foundation/e/apps/domain/login/repository/LoginRepositoryImpl.kt 0 → 100644 +49 −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.domain.login.repository import android.content.Context import app.lounge.login.anonymous.AnonymousUser import app.lounge.model.AnonymousAuthDataRequestBody import app.lounge.networking.NetworkResult import app.lounge.storage.cache.configurations import com.aurora.gplayapi.data.models.AuthData import dagger.hilt.android.qualifiers.ApplicationContext import javax.inject.Inject class LoginRepositoryImpl @Inject constructor( private val networkFetching: AnonymousUser, @ApplicationContext val applicationContext: Context ) : LoginRepository { override suspend fun anonymousUser(authDataRequestBody: AnonymousAuthDataRequestBody): AuthData { val result = networkFetching.requestAuthData( anonymousAuthDataRequestBody = authDataRequestBody ) when (result) { is NetworkResult.Error -> throw Exception(result.errorMessage, result.exception) is NetworkResult.Success -> { applicationContext.configurations.authData = result.data.toString() return result.data } } } }
app/src/main/java/foundation/e/apps/domain/login/usecase/UserLoginUseCase.kt 0 → 100644 +51 −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.domain.login.usecase import app.lounge.model.AnonymousAuthDataRequestBody import com.aurora.gplayapi.data.models.AuthData import foundation.e.apps.domain.login.repository.LoginRepository import foundation.e.apps.utils.Resource import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.single import java.util.Properties import javax.inject.Inject class UserLoginUseCase @Inject constructor( private val loginRepository: LoginRepository, ) { suspend operator fun invoke( properties: Properties, userAgent: String ): Resource<AuthData> = flow { try { emit(Resource.Loading()) val userResponse = loginRepository.anonymousUser( authDataRequestBody = AnonymousAuthDataRequestBody( properties = properties, userAgent = userAgent ) ) emit(Resource.Success(userResponse)) } catch (e: Exception) { emit(Resource.Error(e.localizedMessage)) } }.single() }
app/src/main/java/foundation/e/apps/utils/Resource.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.utils sealed class Resource<T>(val data: T? = null, val message: String? = null) { class Success<T>(data: T) : Resource<T>(data) class Error<T>(message: String, data: T? = null) : Resource<T>(data, message) class Loading<T>(data: T? = null) : Resource<T>(data) }