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

Commit 38d2f736 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Accept intent extra to login and close App Lounge

parent aa1d4498
Loading
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
import foundation.e.apps.data.Constants
import foundation.e.apps.data.enums.User
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.data.login.LoginViewModel
@@ -76,6 +77,9 @@ class MainActivity : AppCompatActivity() {
        private const val SESSION_DIALOG_TAG = "session_dialog"
    }

    private var gPlayLoginRequested = false
    private var closeAfterLogin = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

@@ -126,6 +130,14 @@ class MainActivity : AppCompatActivity() {
        viewModel.updateContentRatings()

        observeEvents()

        gPlayLoginRequested = intent.getBooleanExtra(Constants.REQUEST_GPLAY_LOGIN, false)

        if (!gPlayLoginRequested) return
        if (!viewModel.getTocStatus()) return
        if (viewModel.getUser() !in listOf(User.GOOGLE, User.ANONYMOUS)) {
            loginViewModel.logout()
        }
    }

    private fun refreshSession() {
@@ -318,6 +330,7 @@ class MainActivity : AppCompatActivity() {
                    // Pop back stack to prevent showing TOSFragment on pressing back button.
                    navController.popBackStack()
                    navController.navigate(R.id.signInFragment)
                    if (gPlayLoginRequested) closeAfterLogin = true
                    return@observe
                }

@@ -344,6 +357,10 @@ class MainActivity : AppCompatActivity() {
            if (gPlayAuthObject == null || gPlayAuthObject.result.isSuccess()) {
                broadcastGPlayLogin()
            }

            if (closeAfterLogin && it.isNotEmpty() && it.all { it.result.isSuccess() }) {
                finishAndRemoveTask()
            }
        }
    }

+2 −0
Original line number Diff line number Diff line
@@ -35,4 +35,6 @@ object Constants {

    const val ACTION_PARENTAL_CONTROL_APP_LOUNGE_LOGIN =
        "${BuildConfig.PACKAGE_NAME_PARENTAL_CONTROL}.action.APP_LOUNGE_LOGIN"

    const val REQUEST_GPLAY_LOGIN = "request_gplay_login"
}
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ class AppLoungeDataStore @Inject constructor(
    }
}

fun Flow<String>.getSync(): String {
fun <T> Flow<T>.getSync(): T {
    return runBlocking {
        this@getSync.first()
    }
+4 −0
Original line number Diff line number Diff line
@@ -86,6 +86,10 @@ class MainActivityViewModel @Inject constructor(

    var shouldIgnoreSessionError = false

    fun getTocStatus(): Boolean {
        return appLoungeDataStore.tocStatus.getSync()
    }

    fun getUser(): User {
        return appLoungeDataStore.getUserType()
    }