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

Commit a15613e1 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '2247-fix_broadcast' into 'main'

Issue 2247: fix - prevent sending broadcast everytime on opening App Lounge

See merge request !454
parents 1ca98e6e dcff4434
Loading
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -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)
+6 −1
Original line number Diff line number Diff line
@@ -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
                }
            }
        }
    }
+2 −0
Original line number Diff line number Diff line
@@ -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)
}