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

Commit 397255c2 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Mail: Add account from exported settings at first screen when no account set up

parent ff9ce90d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -75,6 +75,11 @@
            android:configChanges="locale"
            android:label="@string/account_setup_basics_title"/>

        <activity
            android:name=".activity.setup.AccountSetupImportSettings"
            android:configChanges="locale"
            android:label="@string/settings_import_title"/>

        <activity
            android:name=".activity.setup.AccountSetupAccountType"
            android:configChanges="locale"
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import com.fsck.k9.ui.base.K9Activity
import org.koin.android.ext.android.inject

/**
 * Prompts the user to select an account type. The account type, along with the
 * Prompts the user to select an account type (IMAP or POP3). The account type, along with the
 * passed in email address, password and makeDefault are then passed on to the
 * AccountSetupIncoming activity.
 */
+9 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.text.Editable
import android.view.View
import android.view.ViewGroup
@@ -17,7 +16,6 @@ import com.fsck.k9.Account
import com.fsck.k9.Core
import com.fsck.k9.EmailAddressValidator
import com.fsck.k9.Preferences
import com.fsck.k9.account.AccountCreationAction
import com.fsck.k9.account.AccountCreator
import com.fsck.k9.activity.MessageList
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection
@@ -69,6 +67,7 @@ class AccountSetupBasics : K9Activity() {
    private lateinit var advancedOptionsContainer: View
    private lateinit var nextButton: Button
    private lateinit var manualSetupButton: Button
    private lateinit var importSettingsButton: Button
    private lateinit var allowClientCertificateView: ViewGroup

    private var uiState = UiState.EMAIL_ADDRESS_ONLY
@@ -89,8 +88,10 @@ class AccountSetupBasics : K9Activity() {
        advancedOptionsContainer = findViewById(R.id.foldable_advanced_options)
        nextButton = findViewById(R.id.next)
        manualSetupButton = findViewById(R.id.manual_setup)
        importSettingsButton = findViewById(R.id.import_settings)

        manualSetupButton.setOnClickListener { onManualSetup() }
        importSettingsButton.setOnClickListener { onImportSettings() }
    }

    override fun onPostCreate(savedInstanceState: Bundle?) {
@@ -338,6 +339,12 @@ class AccountSetupBasics : K9Activity() {
        AccountSetupAccountType.actionSelectAccountType(this, account, makeDefault = false, initialAccountSettings)
    }

    private fun onImportSettings() {
        val intent = Intent(this, AccountSetupImportSettings::class.java)
        startActivity(intent)
        finish()
    }

    private fun initAccount(email: String): Account {
        val account = this.account ?: createAccount().also { this.account = it }

+78 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package com.fsck.k9.activity.setup

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import com.fsck.k9.activity.MessageList
import com.fsck.k9.ui.R
import com.fsck.k9.ui.base.K9Activity
import com.fsck.k9.ui.settings.import.SettingsImportResultViewModel
import com.fsck.k9.ui.settings.import.SettingsImportSuccess
import org.koin.androidx.viewmodel.ext.android.viewModel

/**
 * Prompts the user to select a exported settings file
 *
 */
class AccountSetupImportSettings : K9Activity() {

    private val resultViewModel: SettingsImportResultViewModel by viewModel()

    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLayout(R.layout.account_setup_import_settings)
        setUpActionBar()

        handleOnSuccessCallback()
    }

    private fun handleOnSuccessCallback() {
        resultViewModel.settingsImportResult.observe(this) {
            if (it == SettingsImportSuccess) {
                startActivityClearTop(MessageList::class.java)
            }
        }
    }

    private fun <T : Activity> startActivityClearTop(clazz: Class<T>) {
        val intent = Intent(this@AccountSetupImportSettings, clazz)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
        startActivity(intent)
        finish()
    }

    private fun setUpActionBar() {
        setTitle(R.string.settings_import_title)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (item.itemId == android.R.id.home) {
            onBackPressed()
            return true
        }

        return super.onOptionsItemSelected(item)
    }

    override fun onBackPressed() {
        startActivityClearTop(AccountSetupBasics::class.java)
    }
}
+33 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright MURENA SAS 2023
  ~ This program is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ This program is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~  along with this program.  If not, see <https://www.gnu.org/licenses/>.
  -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    tools:context="com.fsck.k9.activity.setup.AccountSetupImportSettings">
    
    <include layout="@layout/toolbar" />

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragment_container_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.fsck.k9.ui.settings.import.SettingsImportFragment" />

</LinearLayout>
Loading