Quick setup improvements

This commit is contained in:
M66B 2021-06-20 22:00:17 +02:00
parent 1b56fd32bc
commit 592f0460c4
3 changed files with 33 additions and 22 deletions

View File

@ -32,6 +32,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -50,7 +51,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
public class EmailProvider { public class EmailProvider implements Serializable {
public String id; public String id;
public String name; public String name;
public String description; public String description;
@ -723,7 +724,7 @@ public class EmailProvider {
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return host + ":" + port; return host + ":" + port + (starttls ? " starttls" : " ssl/tls");
} }
} }

View File

@ -191,6 +191,7 @@ public class FragmentQuickSetup extends FragmentBase {
btnHelp.setVisibility(View.GONE); btnHelp.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE); tvInstructions.setVisibility(View.GONE);
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance()); tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
btnSave.setVisibility(View.GONE);
grpSetup.setVisibility(View.GONE); grpSetup.setVisibility(View.GONE);
grpError.setVisibility(View.GONE); grpError.setVisibility(View.GONE);
@ -241,6 +242,7 @@ public class FragmentQuickSetup extends FragmentBase {
grpError.setVisibility(View.GONE); grpError.setVisibility(View.GONE);
btnHelp.setVisibility(View.GONE); btnHelp.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE); tvInstructions.setVisibility(View.GONE);
btnSave.setVisibility(check ? View.GONE : View.VISIBLE);
grpSetup.setVisibility(check ? View.GONE : View.VISIBLE); grpSetup.setVisibility(check ? View.GONE : View.VISIBLE);
} }
@ -279,12 +281,7 @@ public class FragmentQuickSetup extends FragmentBase {
throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
EmailProvider provider = EmailProvider.fromEmail(context, email, EmailProvider.Discover.ALL); EmailProvider provider = EmailProvider.fromEmail(context, email, EmailProvider.Discover.ALL);
args.putBoolean("appPassword", provider.appPassword); args.putSerializable("provider", provider);
if (provider.link != null)
args.putString("link", provider.link);
if (provider.documentation != null)
args.putString("documentation", provider.documentation.toString());
int at = email.indexOf('@'); int at = email.indexOf('@');
String username = email.substring(0, at); String username = email.substring(0, at);
@ -459,12 +456,11 @@ public class FragmentQuickSetup extends FragmentBase {
protected void onExecuted(Bundle args, EmailProvider result) { protected void onExecuted(Bundle args, EmailProvider result) {
boolean check = args.getBoolean("check"); boolean check = args.getBoolean("check");
if (check) { if (check) {
tvImap.setText(result == null ? null tvImap.setText(result == null ? null : result.imap.toString());
: result.imap.host + ":" + result.imap.port + (result.imap.starttls ? " starttls" : " ssl"));
tvImapFingerprint.setText(args.getString("imap_fingerprint")); tvImapFingerprint.setText(args.getString("imap_fingerprint"));
tvSmtp.setText(result == null ? null tvSmtp.setText(result == null ? null : result.smtp.toString());
: result.smtp.host + ":" + result.smtp.port + (result.smtp.starttls ? " starttls" : " ssl"));
tvSmtpFingerprint.setText(args.getString("smtp_fingerprint")); tvSmtpFingerprint.setText(args.getString("smtp_fingerprint"));
btnSave.setVisibility(result == null ? View.GONE : View.VISIBLE);
grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE); grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE);
} else { } else {
FragmentDialogAccount fragment = new FragmentDialogAccount(); FragmentDialogAccount fragment = new FragmentDialogAccount();
@ -477,12 +473,12 @@ public class FragmentQuickSetup extends FragmentBase {
@Override @Override
protected void onException(final Bundle args, Throwable ex) { protected void onException(final Bundle args, Throwable ex) {
Log.e(ex); Log.e(ex);
EmailProvider provider = (EmailProvider) args.getSerializable("provider");
if (ex instanceof AuthenticationFailedException) { if (ex instanceof AuthenticationFailedException) {
boolean appPassword = args.getBoolean("appPassword");
String message = getString(R.string.title_setup_no_auth_hint); String message = getString(R.string.title_setup_no_auth_hint);
if (appPassword) if (provider != null && provider.appPassword)
message += "\n" + getString(R.string.title_setup_app_password_hint); message += "\n\n" + getString(R.string.title_setup_app_password_hint);
tvErrorHint.setText(message); tvErrorHint.setText(message);
} else } else
tvErrorHint.setText(R.string.title_setup_no_settings_hint); tvErrorHint.setText(R.string.title_setup_no_settings_hint);
@ -501,21 +497,30 @@ public class FragmentQuickSetup extends FragmentBase {
tvError.setText(Log.formatThrowable(ex, false)); tvError.setText(Log.formatThrowable(ex, false));
grpError.setVisibility(View.VISIBLE); grpError.setVisibility(View.VISIBLE);
if (args.containsKey("link")) { if (provider != null && provider.link != null) {
Uri uri = Uri.parse(args.getString("link")); Uri uri = Uri.parse(provider.link);
btnHelp.setTag(uri); btnHelp.setTag(uri);
btnHelp.setVisibility(View.VISIBLE); btnHelp.setVisibility(View.VISIBLE);
} }
if (args.containsKey("documentation")) { if (provider != null && provider.documentation != null) {
tvInstructions.setText(HtmlHelper.fromHtml(args.getString("documentation"), getContext())); tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), getContext()));
tvInstructions.setVisibility(View.VISIBLE); tvInstructions.setVisibility(View.VISIBLE);
} }
if (provider != null &&
provider.imap != null && provider.smtp != null) {
tvImap.setText(provider.imap.toString());
tvImapFingerprint.setText(null);
tvSmtp.setText(provider.smtp.toString());
tvSmtpFingerprint.setText(null);
grpSetup.setVisibility(View.VISIBLE);
}
getMainHandler().post(new Runnable() { getMainHandler().post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (args.containsKey("documentation")) if (provider != null && provider.documentation != null)
scroll.smoothScrollTo(0, tvInstructions.getBottom()); scroll.smoothScrollTo(0, tvInstructions.getBottom());
else else
scroll.smoothScrollTo(0, btnSupport.getBottom()); scroll.smoothScrollTo(0, btnSupport.getBottom());

View File

@ -78,6 +78,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_case_sensitive" android:text="@string/title_case_sensitive"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="italic" android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCharacters" /> app:layout_constraintTop_toBottomOf="@id/tvCharacters" />
@ -157,6 +158,7 @@
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:text="@string/title_setup_quick_support" android:text="@string/title_setup_quick_support"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="italic" android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvErrorHint" /> app:layout_constraintTop_toBottomOf="@id/tvErrorHint" />
@ -212,6 +214,7 @@
android:text="imap.domain.tld:993" android:text="imap.domain.tld:993"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="true"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImapTitle" /> app:layout_constraintTop_toBottomOf="@id/tvImapTitle" />
@ -222,6 +225,7 @@
android:text="fingerprint" android:text="fingerprint"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning" android:textColor="?attr/colorWarning"
android:textIsSelectable="true"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImap" /> app:layout_constraintTop_toBottomOf="@id/tvImap" />
@ -242,6 +246,7 @@
android:text="smtp.domain.tld:993" android:text="smtp.domain.tld:993"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="true"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSmtpTitle" /> app:layout_constraintTop_toBottomOf="@id/tvSmtpTitle" />
@ -252,6 +257,7 @@
android:text="fingerprint" android:text="fingerprint"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning" android:textColor="?attr/colorWarning"
android:textIsSelectable="true"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSmtp" /> app:layout_constraintTop_toBottomOf="@id/tvSmtp" />
@ -282,8 +288,7 @@
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids=" app:constraint_referenced_ids="
tvImapTitle,tvImap,tvImapFingerprint,tvSmtpTitle, tvImapTitle,tvImap,tvImapFingerprint,tvSmtpTitle,
tvSmtp,tvSmtpFingerprint, tvSmtp,tvSmtpFingerprint" />
btnSave" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpError" android:id="@+id/grpError"