diff --git a/app/ui/legacy/build.gradle b/app/ui/legacy/build.gradle
index eafb08efa12f8fccf0384890fc73c6f67a426832..7fb11f6c7cd2284021fb7234101672bdebf6e555 100644
--- a/app/ui/legacy/build.gradle
+++ b/app/ui/legacy/build.gradle
@@ -68,6 +68,8 @@ dependencies {
implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
implementation "com.squareup.retrofit2:converter-simplexml:${versions.retrofit}"
+
+ implementation "com.github.fahim44:FullScreenLoadingDialog:1.0.6"
}
android {
diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java
index 03a4ec4c301edab646e0228a73a03b9107352366..b7c6dbf8fe64d20249755a643b1cea7b1a40df75 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java
@@ -1,15 +1,27 @@
+/*
+ * Copyright ECORP SAS 2022
+ * 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 .
+ */
+
package com.fsck.k9.activity.setup;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager.NameNotFoundException;
-import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
-import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -18,16 +30,16 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
+import androidx.annotation.Nullable;
+import androidx.lifecycle.LifecycleOwner;
import com.fsck.k9.Account;
import com.fsck.k9.Core;
import com.fsck.k9.DI;
import com.fsck.k9.EmailAddressValidator;
import com.fsck.k9.Preferences;
import com.fsck.k9.account.AccountCreator;
-import com.fsck.k9.mail.oauth.OAuth2Provider;
-import com.fsck.k9.preferences.AccountManager;
-import com.fsck.k9.ui.base.K9Activity;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
+import com.fsck.k9.activity.setup.accountmanager.MailAutoConfigDiscoveryHelper;
import com.fsck.k9.autodiscovery.api.DiscoveredServerSettings;
import com.fsck.k9.autodiscovery.api.DiscoveryResults;
import com.fsck.k9.autodiscovery.api.DiscoveryTarget;
@@ -35,14 +47,17 @@ import com.fsck.k9.autodiscovery.providersxml.ProvidersXmlDiscovery;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ServerSettings;
+import com.fsck.k9.mail.oauth.OAuth2Provider;
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
-import com.fsck.k9.ui.R;
import com.fsck.k9.ui.ConnectionSettings;
+import com.fsck.k9.ui.R;
+import com.fsck.k9.ui.base.K9Activity;
import com.fsck.k9.ui.settings.ExtraAccountDiscovery;
import com.fsck.k9.view.ClientCertificateSpinner;
import com.fsck.k9.view.ClientCertificateSpinner.OnClientCertificateChangedListener;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
+import com.lamonjush.fullscreenloadingdialog.FullScreenLoadingDialog;
import timber.log.Timber;
/**
@@ -318,22 +333,34 @@ public class AccountSetupBasics extends K9Activity
if(provider != null && provider.toString().trim().equals("GMAIL")){
Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
startActivity(intent);
+ return;
}
- else {
- ConnectionSettings extraConnectionSettings = ExtraAccountDiscovery.discover(email);
- if (extraConnectionSettings != null) {
- finishAutoSetup(extraConnectionSettings);
- return;
- }
- ConnectionSettings connectionSettings = providersXmlDiscoveryDiscover(email, DiscoveryTarget.INCOMING_AND_OUTGOING);
- if (connectionSettings != null) {
- finishAutoSetup(connectionSettings);
- } else {
- // We don't have default settings for this account, start the manual setup process.
- onManualSetup();
- }
+ ConnectionSettings extraConnectionSettings = ExtraAccountDiscovery.discover(email);
+ if (extraConnectionSettings != null) {
+ finishAutoSetup(extraConnectionSettings);
+ return;
+ }
+
+ ConnectionSettings connectionSettings =
+ providersXmlDiscoveryDiscover(email, DiscoveryTarget.INCOMING_AND_OUTGOING);
+ if (connectionSettings != null) {
+ finishAutoSetup(connectionSettings);
+ return;
}
+ // We don't have predefine configuration, try to retrieve it by api call
+ FullScreenLoadingDialog.getInstance()
+ .setSpinKitColor(R.color.color_default_accent)
+ .show(this);
+ MailAutoConfigDiscoveryHelper.INSTANCE.retrieveConfiguration(email, this, config -> {
+ FullScreenLoadingDialog.getInstance().dismiss();
+ if (config != null) {
+ finishAutoSetup(config);
+ return;
+ }
+ // We can't find default settings for this account, start the manual setup process.
+ onManualSetup();
+ });
}
@Override
diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java
index 25f1fbcf30d2aab53a133d0cf2053944f6ad5a69..16627d6565934300a69e0b2d7ef98f7189e09281 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java
@@ -1,5 +1,20 @@
-package com.fsck.k9.activity.setup.accountmanager;
+/*
+ * Copyright ECORP SAS 2022
+ * 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 .
+ */
+package com.fsck.k9.activity.setup.accountmanager;
import android.content.Context;
@@ -38,7 +53,7 @@ public class EeloAccountCreator {
ConnectionSettings connectionSettings = providersXmlDiscoveryDiscover(emailId);
if (connectionSettings == null) {
// connection details not predefined in the xml. Try to load from the api
- connectionSettings = EeloMailAutoConfigDiscovery.retrieveConfigFromApi(emailId);
+ connectionSettings = MailAutoConfigDiscovery.retrieveConfigFromApi(emailId);
}
// providers.xml doesn't have the connection details & can't retrieve details from api
// & it is google account, meaning custom domain for google account is used.
diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigDiscovery.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/MailAutoConfigDiscovery.java
similarity index 87%
rename from app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigDiscovery.java
rename to app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/MailAutoConfigDiscovery.java
index 91c8e4aae1808052f4dfd669e87d8ac6b28c5a6b..96fdb26338d8256bc70c4769787455dd070c8843 100644
--- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloMailAutoConfigDiscovery.java
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/MailAutoConfigDiscovery.java
@@ -1,6 +1,22 @@
-package com.fsck.k9.activity.setup.accountmanager;
+/*
+ * Copyright ECORP SAS 2022
+ * 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 .
+ */
+package com.fsck.k9.activity.setup.accountmanager;
+import androidx.annotation.Nullable;
import com.fsck.k9.autodiscovery.api.DiscoveredServerSettings;
import com.fsck.k9.helper.EmailHelper;
import com.fsck.k9.helper.Utility;
@@ -14,15 +30,14 @@ import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
import timber.log.Timber;
-
-public class EeloMailAutoConfigDiscovery {
+public class MailAutoConfigDiscovery {
/**
- * Try to retrieve /e/ cloud mail info from the api
+ * Try to retrieve mail info from the api
*
- * @param email retrieved from accountManager for /e/ cloud account
* @return mail's incoming & outgoing connection detail, null if failed to retrieve
*/
+ @Nullable
public static ConnectionSettings retrieveConfigFromApi(String email) {
String domain = EmailHelper.getDomainFromEmailAddress(email);
if (domain == null) {
@@ -170,6 +185,6 @@ public class EeloMailAutoConfigDiscovery {
return getAutoConfigSettings(response.getEmailProvider().getOutgoingServer());
}
- private EeloMailAutoConfigDiscovery() {
+ private MailAutoConfigDiscovery() {
}
}
diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/MailAutoConfigDiscoveryHelper.kt b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/MailAutoConfigDiscoveryHelper.kt
new file mode 100644
index 0000000000000000000000000000000000000000..7cf8b8c467c32e16fba33b6469436e0b08db43fd
--- /dev/null
+++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/MailAutoConfigDiscoveryHelper.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright ECORP SAS 2022
+ * 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 .
+ */
+
+package com.fsck.k9.activity.setup.accountmanager
+
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.lifecycleScope
+import com.fsck.k9.ui.ConnectionSettings
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+
+/**
+ * We can't use lifecycleScope from Java class directly.
+ * The main requirement of this class is to use lifecycleScope from java class
+ */
+object MailAutoConfigDiscoveryHelper {
+
+ fun retrieveConfiguration(email: String, lifecycleOwner: LifecycleOwner, callback: ConfigureLoaderCallback) {
+ lifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
+ val config = MailAutoConfigDiscovery.retrieveConfigFromApi(email)
+ lifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
+ callback.onConfigureLoaded(config)
+ }
+ }
+ }
+
+ interface ConfigureLoaderCallback {
+
+ fun onConfigureLoaded(connectionSettings: ConnectionSettings?)
+ }
+}
\ No newline at end of file