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

Commit ce02a442 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

AM: unify re-OAuth flow to ensure consistent behavior

parent 2d77c7f7
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ package at.bitfire.davdroid.ui.account

import android.accounts.Account
import android.app.Activity
import android.content.Intent
import android.security.KeyChain
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -69,6 +69,7 @@ import at.bitfire.davdroid.ui.composable.SettingsHeader
import at.bitfire.davdroid.ui.composable.SwitchSetting
import at.bitfire.davdroid.util.PermissionUtils
import at.bitfire.vcard4android.GroupMethod
import foundation.e.accountmanager.ui.setup.ReOAuthActivity
import kotlinx.coroutines.launch

@Composable
@@ -77,20 +78,13 @@ fun AccountSettingsScreen(
    account: Account,
    onNavWifiPermissionsScreen: () -> Unit
) {
    val context = LocalContext.current
    val model = hiltViewModel { factory: AccountSettingsModel.Factory ->
        factory.create(account)
    }
    val uiState by model.uiState.collectAsState()
    val canAccessWifiSsid by PermissionUtils.rememberCanAccessWifiSsid()

    // contract to open the browser for re-authentication
    val authRequestContract = rememberLauncherForActivityResult(model.authorizationContract()) { authResponse ->
        if (authResponse != null)
            model.authenticate(authResponse)
        else
            model.authCodeFailed()
    }

    AppTheme {
        AccountSettingsScreen(
            accountName = account.name,
@@ -123,9 +117,9 @@ fun AccountSettingsScreen(
            credentials = uiState.credentials,
            onUpdateCredentials = model::updateCredentials,
            onAuthenticateOAuth = {
                val request = model.newAuthorizationRequest()
                if (request != null)
                    authRequestContract.launch(request)
                val intent = Intent(context, ReOAuthActivity::class.java)
                intent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, account)
                context.startActivity(intent)
            },
            isCredentialsUpdateAllowed = uiState.allowCredentialsChange,