From 8ba0c5177c9b1a179f9101326283a7ec55db0fa3 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 17 Jun 2024 15:17:25 +0530 Subject: [PATCH] fix - prevent sending broadcast everytime on opening App Lounge --- app/src/main/java/foundation/e/apps/MainActivity.kt | 8 ++++++-- .../java/foundation/e/apps/ui/MainActivityViewModel.kt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index 88496dfac..c655e6cfc 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -335,6 +335,7 @@ class MainActivity : AppCompatActivity() { it.isEmpty() -> { // No auth type defined means user has not logged in yet // Pop back stack to prevent showing TOSFragment on pressing back button. + viewModel.wasLoggedOut = true navController.popBackStack() navController.navigate(R.id.signInFragment) if (viewModel.gPlayLoginRequested) viewModel.closeAfterLogin = true @@ -360,12 +361,15 @@ class MainActivity : AppCompatActivity() { } } + if (it.none { it.result.isSuccess() }) return@observe + // Broadcast if not gplay type login or successful gplay login - if (gPlayAuthObject == null || gPlayAuthObject.result.isSuccess()) { + if (viewModel.wasLoggedOut) { + viewModel.wasLoggedOut = false broadcastGPlayLogin() } - if (viewModel.closeAfterLogin && it.isNotEmpty() && it.all { it.result.isSuccess() }) { + if (viewModel.closeAfterLogin) { finishAndRemoveTask() } } diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt index 4787b8e91..86e6305ba 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt @@ -84,6 +84,7 @@ class MainActivityViewModel @Inject constructor( var gPlayLoginRequested = false var closeAfterLogin = false + var wasLoggedOut = false lateinit var connectivityManager: ConnectivityManager -- GitLab