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

Commit 9911cce9 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

refactor: rewrite if to check account type in BootCompleteReceiver

and update coding style
parent 4cf4e36c
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -16,21 +16,18 @@ class ReLoginWithOidcActivity : AppCompatActivity() {

        val accountRemovalCallback: (AliasFuture) -> Unit =  { future ->
            val success = future.result.getBoolean(KEY_BOOLEAN_RESULT)
            Logger.log.info("$accountName removal succeed ?  $success")

            if (success) {
                Logger.log.info("Vincent: $accountName removed")
                loginAccount(accountManager)
            } else {
                Logger.log.info("failed to remove account: ${accountName} ")
                Logger.log.info("failed to remove account: $accountName ")
            }
        }


        logoutAccount(accountName, accountManager, accountRemovalCallback)


    }


    private fun logoutAccount(accountName: String,
                              accountManager: AccountManager,
                              callback : (AliasFuture) -> Unit)
@@ -39,9 +36,8 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
        val activity = this

        eAccounts.first { it.name == accountName }.run {
            Logger.log.info("try to remove account: ${this.name} ") //todo remove this before merge
            Logger.log.info("Vincent: try to remove account: ${this.name} ") //todo remove this before merge
            accountManager.removeAccount(this, activity, callback, null)

        } ?: finish()
    }

@@ -49,6 +45,7 @@ class ReLoginWithOidcActivity : AppCompatActivity() {
        val eAccountType = applicationContext.getString(R.string.eelo_account_type)
        val authTokenType = null

        Logger.log.info("Vincent: Will start add Account Session")
        accountManager.startAddAccountSession(eAccountType,
            authTokenType,
            arrayOf(),
+5 −6
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import at.bitfire.davdroid.R
import at.bitfire.davdroid.ReLoginWithOidcActivity
@@ -44,7 +43,8 @@ class BootCompletedReceiver: BroadcastReceiver() {
                val accountSettings = AccountSettings(context, it)
                accountSettings.initSync()

                if (it.type.equals(eAccountType) && !isLoggedWithOpenId(it, accountManager)) {
                if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) {
                    Logger.log.info("Vincent: eAccountFound. Will notify")
                    notifySwitchToOpenId(it, context)
                }
            }
@@ -62,7 +62,6 @@ class BootCompletedReceiver: BroadcastReceiver() {
        val notifText = context.getString(R.string.notification_switch_to_openId_text)
        val notifIntent = generateLogoutIntent(account.name, context)


        val notification = NotificationUtils.newBuilder(context, CHANNEL_GENERAL)
            .setContentTitle(notifTitle)
            .setContentText(notifText)
@@ -76,14 +75,14 @@ class BootCompletedReceiver: BroadcastReceiver() {
    }

    private fun generateLogoutIntent(accountName: String, context: Context): PendingIntent {
        val reloginIntent = Intent(context, ReLoginWithOidcActivity::class.java).apply {
        val reLoginIntent = Intent(context, ReLoginWithOidcActivity::class.java).apply {
            flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
            putExtra(AccountManager.KEY_ACCOUNT_NAME, accountName)
        }

        return  PendingIntent.getActivity(context,
            0,
            reloginIntent,
            reLoginIntent,
            PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
    }
}