diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index cedbf9c84787f3f0c0431d89429520e441ab37f5..c262504537f917938d160b2855465e715f87643e 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -235,6 +235,10 @@ class MainActivity : AppCompatActivity() { launch { observeAgeLimitRestrictionEvent() } + + launch { + observeSuccessfulLogin() + } } } } @@ -360,19 +364,21 @@ class MainActivity : AppCompatActivity() { } } - // Broadcast if not gplay type login or successful gplay login - if (gPlayAuthObject == null || gPlayAuthObject.result.isSuccess()) { - broadcastGPlayLogin() - } - if (viewModel.closeAfterLogin && it.isNotEmpty() && it.all { it.result.isSuccess() }) { finishAndRemoveTask() } } } - private fun broadcastGPlayLogin() { - val user = viewModel.getUser().name + private suspend fun observeSuccessfulLogin() { + EventBus.events.filter { + it is AppEvent.SuccessfulLogin + }.collectLatest { + broadcastGPlayLogin(it.data as User) + } + } + + private fun broadcastGPlayLogin(user: User) { Timber.d("Sending broadcast with login type - $user") val intent = Intent(Constants.ACTION_PARENTAL_CONTROL_APP_LOUNGE_LOGIN).apply { setPackage(BuildConfig.PACKAGE_NAME_PARENTAL_CONTROL) diff --git a/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt b/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt index ddb83635757dbae46b7e589db3af071e61c84e8a..4d013b2f058457ef1b0d7617826c8c586fa3367d 100644 --- a/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt +++ b/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt @@ -24,6 +24,8 @@ import foundation.e.apps.data.enums.User import foundation.e.apps.data.playstore.utils.AC2DMUtil import foundation.e.apps.data.handleNetworkResult import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.utils.eventBus.AppEvent +import foundation.e.apps.utils.eventBus.EventBus import java.util.Locale /** @@ -52,7 +54,10 @@ class PlayStoreLoginWrapper constructor( this.exception = when (result) { is ResultSupreme.Timeout -> GPlayLoginException(true, "GPlay API timeout", user) is ResultSupreme.Error -> GPlayLoginException(false, result.message, user) - else -> null + else -> { + EventBus.invokeEvent(AppEvent.SuccessfulLogin(user)) + null + } } } } diff --git a/app/src/main/java/foundation/e/apps/utils/eventBus/AppEvent.kt b/app/src/main/java/foundation/e/apps/utils/eventBus/AppEvent.kt index e3db13f9fc914158d5b1cc669e95d6659440e477..9c3cd7e5f8c823a2e44ebbf26cd762afd58a039a 100644 --- a/app/src/main/java/foundation/e/apps/utils/eventBus/AppEvent.kt +++ b/app/src/main/java/foundation/e/apps/utils/eventBus/AppEvent.kt @@ -22,6 +22,7 @@ package foundation.e.apps.utils.eventBus import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.enums.ResultStatus +import foundation.e.apps.data.enums.User import foundation.e.apps.data.install.models.AppInstall sealed class AppEvent(val data: Any) { @@ -35,4 +36,5 @@ sealed class AppEvent(val data: Any) { class NoInternetEvent(isInternetAvailable: Boolean) : AppEvent(isInternetAvailable) class TooManyRequests : AppEvent(Unit) class AgeLimitRestrictionEvent(type: String) : AppEvent(type) + class SuccessfulLogin(user: User): AppEvent(user) }