mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Fetch setup instructions
This commit is contained in:
parent
ef2172f7fb
commit
f054b7c6b4
3 changed files with 106 additions and 14 deletions
|
@ -37,7 +37,9 @@ import android.os.Bundle;
|
|||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.Settings;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Patterns;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -104,6 +106,7 @@ public class FragmentSetup extends FragmentEx {
|
|||
private EditText etEmail;
|
||||
private TextInputLayout tilPassword;
|
||||
private Button btnQuick;
|
||||
private TextView tvInstructions;
|
||||
|
||||
private Button btnAccount;
|
||||
private TextView tvAccountDone;
|
||||
|
@ -153,6 +156,7 @@ public class FragmentSetup extends FragmentEx {
|
|||
etEmail = view.findViewById(R.id.etEmail);
|
||||
tilPassword = view.findViewById(R.id.tilPassword);
|
||||
btnQuick = view.findViewById(R.id.btnQuick);
|
||||
tvInstructions = view.findViewById(R.id.tvInstructions);
|
||||
|
||||
btnAccount = view.findViewById(R.id.btnAccount);
|
||||
tvAccountDone = view.findViewById(R.id.tvAccountDone);
|
||||
|
@ -225,6 +229,9 @@ public class FragmentSetup extends FragmentEx {
|
|||
String[] dparts = email.split("@");
|
||||
Provider provider = Provider.fromDomain(context, dparts[1]);
|
||||
|
||||
if (provider.documentation != null)
|
||||
args.putString("documentation", provider.documentation.toString());
|
||||
|
||||
String user = (provider.user == Provider.UserType.EMAIL ? email : dparts[0]);
|
||||
|
||||
Character separator;
|
||||
|
@ -381,6 +388,11 @@ public class FragmentSetup extends FragmentEx {
|
|||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
if (args.containsKey("documentation")) {
|
||||
tvInstructions.setText(Html.fromHtml(args.getString("documentation")));
|
||||
tvInstructions.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (ex instanceof IllegalArgumentException)
|
||||
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
||||
else
|
||||
|
@ -510,6 +522,8 @@ public class FragmentSetup extends FragmentEx {
|
|||
|
||||
// Initialize
|
||||
ibHelp.setVisibility(View.GONE);
|
||||
tvInstructions.setVisibility(View.GONE);
|
||||
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
tvAccountDone.setText(null);
|
||||
tvAccountDone.setCompoundDrawables(null, null, null, null);
|
||||
|
|
|
@ -57,6 +57,7 @@ public class Provider {
|
|||
public int smtp_port;
|
||||
public boolean smtp_starttls;
|
||||
public UserType user = UserType.EMAIL;
|
||||
public StringBuilder documentation = null; // html
|
||||
|
||||
enum UserType {LOCAL, EMAIL}
|
||||
|
||||
|
@ -75,25 +76,26 @@ public class Provider {
|
|||
int eventType = xml.getEventType();
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if ("providers".equals(xml.getName()))
|
||||
String name = xml.getName();
|
||||
if ("providers".equals(name))
|
||||
result = new ArrayList<>();
|
||||
else if ("provider".equals(xml.getName())) {
|
||||
else if ("provider".equals(name)) {
|
||||
provider = new Provider();
|
||||
provider.name = xml.getAttributeValue(null, "name");
|
||||
provider.order = xml.getAttributeIntValue(null, "order", Integer.MAX_VALUE);
|
||||
provider.link = xml.getAttributeValue(null, "link");
|
||||
provider.type = xml.getAttributeValue(null, "type");
|
||||
provider.prefix = xml.getAttributeValue(null, "prefix");
|
||||
} else if ("imap".equals(xml.getName())) {
|
||||
} else if ("imap".equals(name)) {
|
||||
provider.imap_host = xml.getAttributeValue(null, "host");
|
||||
provider.imap_port = xml.getAttributeIntValue(null, "port", 0);
|
||||
provider.imap_starttls = xml.getAttributeBooleanValue(null, "starttls", false);
|
||||
} else if ("smtp".equals(xml.getName())) {
|
||||
} else if ("smtp".equals(name)) {
|
||||
provider.smtp_host = xml.getAttributeValue(null, "host");
|
||||
provider.smtp_port = xml.getAttributeIntValue(null, "port", 0);
|
||||
provider.smtp_starttls = xml.getAttributeBooleanValue(null, "starttls", false);
|
||||
} else
|
||||
throw new IllegalAccessException(xml.getName());
|
||||
throw new IllegalAccessException(name);
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if ("provider".equals(xml.getName())) {
|
||||
result.add(provider);
|
||||
|
@ -151,17 +153,36 @@ public class Provider {
|
|||
|
||||
boolean imap = false;
|
||||
boolean smtp = false;
|
||||
String href = null;
|
||||
String title = null;
|
||||
Provider provider = new Provider(domain);
|
||||
int eventType = xml.getEventType();
|
||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if ("incomingServer".equals(xml.getName()))
|
||||
String name = xml.getName();
|
||||
if ("incomingServer".equals(name)) {
|
||||
// <incomingServer type="imap">
|
||||
// <hostname>imap.gmail.com</hostname>
|
||||
// <port>993</port>
|
||||
// <socketType>SSL</socketType>
|
||||
// <username>%EMAILADDRESS%</username>
|
||||
// <authentication>OAuth2</authentication>
|
||||
// <authentication>password-cleartext</authentication>
|
||||
// </incomingServer>
|
||||
imap = "imap".equals(xml.getAttributeValue(null, "type"));
|
||||
|
||||
else if ("outgoingServer".equals(xml.getName()))
|
||||
} else if ("outgoingServer".equals(name)) {
|
||||
// <outgoingServer type="smtp">
|
||||
// <hostname>smtp.gmail.com</hostname>
|
||||
// <port>465</port>
|
||||
// <socketType>SSL</socketType>
|
||||
// <username>%EMAILADDRESS%</username>
|
||||
// <authentication>OAuth2</authentication>
|
||||
// <authentication>password-cleartext</authentication>
|
||||
// </outgoingServer>
|
||||
smtp = "smtp".equals(xml.getAttributeValue(null, "type"));
|
||||
|
||||
else if ("hostname".equals(xml.getName())) {
|
||||
} else if ("hostname".equals(name)) {
|
||||
eventType = xml.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
String host = xml.getText();
|
||||
|
@ -173,7 +194,7 @@ public class Provider {
|
|||
}
|
||||
continue;
|
||||
|
||||
} else if ("port".equals(xml.getName())) {
|
||||
} else if ("port".equals(name)) {
|
||||
eventType = xml.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
String port = xml.getText();
|
||||
|
@ -188,7 +209,7 @@ public class Provider {
|
|||
}
|
||||
continue;
|
||||
|
||||
} else if ("socketType".equals(xml.getName())) {
|
||||
} else if ("socketType".equals(name)) {
|
||||
eventType = xml.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
String socket = xml.getText();
|
||||
|
@ -208,7 +229,7 @@ public class Provider {
|
|||
}
|
||||
continue;
|
||||
|
||||
} else if ("username".equals(xml.getName())) {
|
||||
} else if ("username".equals(name)) {
|
||||
eventType = xml.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
String username = xml.getText();
|
||||
|
@ -222,13 +243,59 @@ public class Provider {
|
|||
}
|
||||
continue;
|
||||
|
||||
} else if ("enable".equals(name)) {
|
||||
// <enable visiturl="https://mail.google.com/mail/?ui=2&shva=1#settings/fwdandpop">
|
||||
// <instruction>You need to enable IMAP access</instruction>
|
||||
// </enable>
|
||||
href = xml.getAttributeValue(null, "visiturl");
|
||||
title = null;
|
||||
|
||||
} else if ("documentation".equals(name)) {
|
||||
// <documentation url="http://mail.google.com/support/bin/answer.py?answer=13273">
|
||||
// <descr>How to enable IMAP/POP3 in GMail</descr>
|
||||
// </documentation>
|
||||
href = xml.getAttributeValue(null, "url");
|
||||
title = null;
|
||||
|
||||
} else if ("instruction".equals(name) || "descr".equals(name)) {
|
||||
if (href != null) {
|
||||
eventType = xml.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
if (title == null)
|
||||
title = "";
|
||||
else
|
||||
title += "<br />";
|
||||
title += xml.getText();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
} else if (eventType == XmlPullParser.END_TAG) {
|
||||
if ("incomingServer".equals(xml.getName()))
|
||||
String name = xml.getName();
|
||||
if ("incomingServer".equals(name))
|
||||
imap = false;
|
||||
else if ("outgoingServer".equals(xml.getName()))
|
||||
|
||||
else if ("outgoingServer".equals(name))
|
||||
smtp = false;
|
||||
|
||||
else if ("enable".equals(name) || "documentation".equals(name)) {
|
||||
if (href != null) {
|
||||
if (title == null)
|
||||
title = href;
|
||||
|
||||
if (provider.documentation == null)
|
||||
provider.documentation = new StringBuilder();
|
||||
else
|
||||
provider.documentation.append("<br /><br />");
|
||||
|
||||
provider.documentation
|
||||
.append("<a href=\"").append(href).append("\">").append(title).append("</a>");
|
||||
|
||||
href = null;
|
||||
title = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eventType = xml.next();
|
||||
|
|
|
@ -77,6 +77,17 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvInstructions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="provider instructions"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnQuick" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorQuick"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -84,7 +95,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnQuick" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvInstructions" />
|
||||
|
||||
<!-- account -->
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue