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

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

Init adding accounts

parent 2d37ecfa
Loading
Loading
Loading
Loading
+44 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import android.content.Intent
import android.content.res.Configuration
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
@@ -48,6 +49,9 @@ import com.fsck.k9.K9.PostRemoveNavigation
import com.fsck.k9.K9.SplitViewMode
import com.fsck.k9.Preferences
import com.fsck.k9.account.BackgroundAccountRemover
import com.fsck.k9.activity.accountmanager.AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY
import com.fsck.k9.activity.accountmanager.AccountManagerConstants.EELO_ACCOUNT_TYPE
import com.fsck.k9.activity.accountmanager.EeloAccountCreator
import com.fsck.k9.activity.compose.MessageActions
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.helper.ParcelableUtil
@@ -112,6 +116,8 @@ open class MessageList :

    private var messageListActivityConfig: MessageListActivityConfig? = null

    private lateinit var accountMngr: android.accounts.AccountManager

    /**
     * `true` if the message list should be displayed as flat list (i.e. no threading)
     * regardless whether or not message threading was enabled in the settings. This is used for
@@ -144,7 +150,13 @@ open class MessageList :
            return
        }

        val accounts = accountManager.getAccounts()
        var accounts = accountManager.getAccounts()

        accountMngr = android.accounts.AccountManager.get(this)
        if (addNewAccountsAutomatically(accounts)) {
            accounts = preferences.getAccounts()
        }

        deleteIncompleteAccounts(accounts)
        val hasAccountSetup = accounts.any { it.isFinishedSetup }
        if (!hasAccountSetup) {
@@ -191,6 +203,37 @@ open class MessageList :
        initializeFunding()
    }

    private fun addNewAccountsAutomatically(accounts: List<Account>): Boolean {
        return try {
            val eeloAccounts: Array<android.accounts.Account> = getEeloAccountsOnDevice()
            var accountWasAdded = false
            for (eeloAccount in eeloAccounts) {
                val emailId: String = accountMngr.getUserData(eeloAccount, ACCOUNT_EMAIL_ADDRESS_KEY)
                if (!emailId.contains("@")) continue
                var accountIsSignedIn = false
                for (account in accounts) {
                    if (emailId == account.email) {
                        accountIsSignedIn = true
                        break
                    }
                }
                if (!accountIsSignedIn) {
                    val password: String = accountMngr.getPassword(eeloAccount)
                    EeloAccountCreator.createAccount(this, emailId, password)
                    accountWasAdded = true
                }
            }
            accountWasAdded
        } catch (e: SecurityException) {
            Log.e("blah", "e $e")
            false
        }
    }

    private fun getEeloAccountsOnDevice(): Array<android.accounts.Account> {
        return accountMngr.getAccountsByType(EELO_ACCOUNT_TYPE)
    }

    private fun initializeFunding() {
        fundingManager.addFundingReminder(this) {
            FeatureLauncherActivity.launch(
+6 −0
Original line number Diff line number Diff line
package com.fsck.k9.activity.accountmanager

object AccountManagerConstants {
    const val EELO_ACCOUNT_TYPE = "e.foundation.webdav.eelo"
    const val ACCOUNT_EMAIL_ADDRESS_KEY = "email_address"
}
+23 −0
Original line number Diff line number Diff line
package com.fsck.k9.activity.accountmanager

import android.content.Context
import com.fsck.k9.Core.setServicesEnabled
import com.fsck.k9.Preferences.Companion.getPreferences

object EeloAccountCreator {
    fun createAccount(context: Context, emailId: String, password: String?) {
        val preferences = getPreferences()
        val account = preferences.newAccount()
        account.email = emailId
        val incomingSettings = account.incomingServerSettings
        incomingSettings.newPassword(password)
        val outgoingSettings = account.outgoingServerSettings
        outgoingSettings.newPassword(password)
        account.incomingServerSettings = incomingSettings
        account.outgoingServerSettings = outgoingSettings
        val deletePolicy = account.deletePolicy
        account.deletePolicy = deletePolicy
        preferences.saveAccount(account)
        setServicesEnabled(context)
    }
}