FairEmail/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java

537 lines
22 KiB
Java
Raw Normal View History

2019-01-14 11:11:03 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail 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.
FairEmail 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 FairEmail. If not, see <http://www.gnu.org/licenses/>.
2020-01-05 17:32:53 +00:00
Copyright 2018-2020 by Marcel Bokhorst (M66B)
2019-01-14 11:11:03 +00:00
*/
import android.content.Context;
import android.content.Intent;
2020-07-29 12:06:40 +00:00
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
2019-07-06 14:24:03 +00:00
import android.net.Uri;
2019-01-14 11:11:03 +00:00
import android.os.Bundle;
2019-07-06 14:24:03 +00:00
import android.os.Handler;
import android.text.Editable;
2019-01-14 11:11:03 +00:00
import android.text.TextUtils;
import android.text.TextWatcher;
2019-01-14 11:11:03 +00:00
import android.text.method.LinkMovementMethod;
2019-03-03 11:16:00 +00:00
import android.view.KeyEvent;
2019-01-14 11:11:03 +00:00
import android.view.LayoutInflater;
2019-02-18 17:00:58 +00:00
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
2019-01-14 11:11:03 +00:00
import android.view.View;
import android.view.ViewGroup;
2019-03-03 11:16:00 +00:00
import android.view.inputmethod.EditorInfo;
2019-01-14 11:11:03 +00:00
import android.widget.Button;
import android.widget.EditText;
2019-07-06 14:24:03 +00:00
import android.widget.ScrollView;
2019-01-14 11:11:03 +00:00
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
2019-01-14 11:11:03 +00:00
import com.google.android.material.textfield.TextInputLayout;
import java.net.UnknownHostException;
2019-01-14 11:11:03 +00:00
import java.util.Date;
import java.util.List;
import javax.mail.AuthenticationFailedException;
2019-01-14 11:11:03 +00:00
2019-01-15 17:41:55 +00:00
public class FragmentQuickSetup extends FragmentBase {
2019-01-14 11:11:03 +00:00
private ViewGroup view;
2019-07-06 14:24:03 +00:00
private ScrollView scroll;
2019-01-14 11:11:03 +00:00
private EditText etName;
private EditText etEmail;
private TextInputLayout tilPassword;
private TextView tvCharacters;
2019-01-14 11:11:03 +00:00
private Button btnCheck;
2019-07-28 12:11:42 +00:00
private ContentLoadingProgressBar pbCheck;
2019-02-18 11:39:43 +00:00
2019-01-14 11:11:03 +00:00
private TextView tvError;
2020-01-31 11:03:23 +00:00
private TextView tvErrorHint;
2019-07-06 14:24:03 +00:00
private Button btnHelp;
2019-09-09 14:44:06 +00:00
private Button btnSupport;
2019-01-14 11:11:03 +00:00
private TextView tvInstructions;
2019-02-18 11:39:43 +00:00
private TextView tvImap;
2020-05-18 19:41:56 +00:00
private TextView tvImapFingerprint;
2019-02-18 11:39:43 +00:00
private TextView tvSmtp;
2020-05-18 19:41:56 +00:00
private TextView tvSmtpFingerprint;
2019-02-18 11:39:43 +00:00
private Button btnSave;
2019-07-28 12:11:42 +00:00
private ContentLoadingProgressBar pbSave;
2019-02-18 11:39:43 +00:00
private Group grpSetup;
2019-11-15 08:33:43 +00:00
private Group grpError;
2019-02-18 11:39:43 +00:00
2019-01-14 11:11:03 +00:00
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
2019-05-21 12:15:43 +00:00
setSubtitle(R.string.title_setup_quick);
2019-02-18 17:00:58 +00:00
setHasOptionsMenu(true);
2019-01-14 11:11:03 +00:00
view = (ViewGroup) inflater.inflate(R.layout.fragment_quick_setup, container, false);
2019-07-06 14:24:03 +00:00
scroll = view.findViewById(R.id.scroll);
2019-01-14 11:11:03 +00:00
// Get controls
etName = view.findViewById(R.id.etName);
etEmail = view.findViewById(R.id.etEmail);
tilPassword = view.findViewById(R.id.tilPassword);
tvCharacters = view.findViewById(R.id.tvCharacters);
2019-01-14 11:11:03 +00:00
btnCheck = view.findViewById(R.id.btnCheck);
2019-07-28 12:11:42 +00:00
pbCheck = view.findViewById(R.id.pbCheck);
2019-02-18 11:39:43 +00:00
2019-01-14 11:11:03 +00:00
tvError = view.findViewById(R.id.tvError);
2020-01-31 11:03:23 +00:00
tvErrorHint = view.findViewById(R.id.tvErrorHint);
2019-07-06 14:24:03 +00:00
btnHelp = view.findViewById(R.id.btnHelp);
2019-09-09 14:44:06 +00:00
btnSupport = view.findViewById(R.id.btnSupport);
2019-01-14 11:11:03 +00:00
tvInstructions = view.findViewById(R.id.tvInstructions);
2019-02-18 11:39:43 +00:00
tvImap = view.findViewById(R.id.tvImap);
2020-05-18 19:41:56 +00:00
tvImapFingerprint = view.findViewById(R.id.tvImapFingerprint);
2019-02-18 11:39:43 +00:00
tvSmtp = view.findViewById(R.id.tvSmtp);
2020-05-18 19:41:56 +00:00
tvSmtpFingerprint = view.findViewById(R.id.tvSmtpFingerprint);
2019-02-18 11:39:43 +00:00
btnSave = view.findViewById(R.id.btnSave);
2019-07-28 12:11:42 +00:00
pbSave = view.findViewById(R.id.pbSave);
2019-02-18 11:39:43 +00:00
grpSetup = view.findViewById(R.id.grpSetup);
2019-11-15 08:33:43 +00:00
grpError = view.findViewById(R.id.grpError);
2019-02-18 11:39:43 +00:00
2019-01-14 11:11:03 +00:00
// Wire controls
tilPassword.setHintEnabled(false);
2019-03-03 11:16:00 +00:00
tilPassword.getEditText().setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
onSave(true);
return true;
}
return false;
}
});
2019-09-21 19:08:50 +00:00
tilPassword.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
String password = s.toString();
boolean warning = (Helper.containsWhiteSpace(password) ||
Helper.containsControlChars(password));
tvCharacters.setVisibility(warning &&
tilPassword.getVisibility() == View.VISIBLE
? View.VISIBLE : View.GONE);
}
});
2019-01-14 11:11:03 +00:00
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2019-02-18 11:39:43 +00:00
onSave(true);
}
});
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onSave(false);
2019-01-17 09:57:01 +00:00
}
});
2019-01-14 11:11:03 +00:00
2019-07-06 14:24:03 +00:00
btnHelp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, (Uri) btnHelp.getTag());
Helper.view(getContext(), intent);
}
});
2019-09-09 14:44:06 +00:00
btnSupport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
2020-01-05 08:27:34 +00:00
Helper.view(getContext(), Uri.parse(Helper.SUPPORT_URI), false);
2019-09-09 14:44:06 +00:00
}
});
2019-01-17 09:57:01 +00:00
// Initialize
tvCharacters.setVisibility(View.GONE);
2020-05-18 19:41:56 +00:00
tvImapFingerprint.setText(null);
tvSmtpFingerprint.setText(null);
2019-07-28 12:11:42 +00:00
pbCheck.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
2019-07-06 14:24:03 +00:00
btnHelp.setVisibility(View.GONE);
2019-09-09 14:44:06 +00:00
btnSupport.setVisibility(View.GONE);
2019-01-17 09:57:01 +00:00
tvInstructions.setVisibility(View.GONE);
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
2019-02-18 11:39:43 +00:00
grpSetup.setVisibility(View.GONE);
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.GONE);
2019-01-14 11:11:03 +00:00
2019-01-17 09:57:01 +00:00
return view;
}
2019-01-14 11:11:03 +00:00
2019-02-18 17:00:58 +00:00
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_quick_setup, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_help:
onMenuHelp();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void onMenuHelp() {
Bundle args = new Bundle();
args.putString("name", "SETUP.md");
2019-09-21 19:08:50 +00:00
FragmentDialogMarkdown fragment = new FragmentDialogMarkdown();
fragment.setArguments(args);
fragment.show(getChildFragmentManager(), "help");
2019-02-18 17:00:58 +00:00
}
2019-02-18 11:39:43 +00:00
private void onSave(boolean check) {
2019-01-17 09:57:01 +00:00
Bundle args = new Bundle();
2019-10-02 16:29:04 +00:00
args.putString("name", etName.getText().toString().trim());
2019-01-17 09:57:01 +00:00
args.putString("email", etEmail.getText().toString().trim());
args.putString("password", tilPassword.getEditText().getText().toString());
2020-05-18 19:41:56 +00:00
args.putString("imap_fingerprint", tvImapFingerprint.getText().toString());
args.putString("smtp_fingerprint", tvSmtpFingerprint.getText().toString());
2019-02-18 11:39:43 +00:00
args.putBoolean("check", check);
2019-01-14 11:11:03 +00:00
2019-02-18 11:39:43 +00:00
new SimpleTask<EmailProvider>() {
2019-01-17 09:57:01 +00:00
@Override
protected void onPreExecute(Bundle args) {
2019-02-18 11:39:43 +00:00
boolean check = args.getBoolean("check");
Helper.setViewsEnabled(view, false);
2019-07-28 12:11:42 +00:00
pbCheck.setVisibility(check ? View.VISIBLE : View.GONE);
pbSave.setVisibility(check ? View.GONE : View.VISIBLE);
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.GONE);
2019-07-06 14:24:03 +00:00
btnHelp.setVisibility(View.GONE);
2019-09-09 14:44:06 +00:00
btnSupport.setVisibility(View.GONE);
2019-01-17 09:57:01 +00:00
tvInstructions.setVisibility(View.GONE);
2019-02-18 11:39:43 +00:00
grpSetup.setVisibility(check ? View.GONE : View.VISIBLE);
2019-01-17 09:57:01 +00:00
}
2019-01-14 11:11:03 +00:00
2019-01-17 09:57:01 +00:00
@Override
protected void onPostExecute(Bundle args) {
2019-02-18 11:39:43 +00:00
Helper.setViewsEnabled(view, true);
2019-07-28 12:11:42 +00:00
pbCheck.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
2019-01-17 09:57:01 +00:00
}
2019-01-14 11:11:03 +00:00
2019-01-17 09:57:01 +00:00
@Override
2019-02-18 11:39:43 +00:00
protected EmailProvider onExecute(Context context, Bundle args) throws Throwable {
2019-10-02 16:29:04 +00:00
String name = args.getString("name");
String email = args.getString("email");
2019-01-17 09:57:01 +00:00
String password = args.getString("password");
2019-02-18 11:39:43 +00:00
boolean check = args.getBoolean("check");
2020-05-18 19:41:56 +00:00
String imap_fingerprint = args.getString("imap_fingerprint");
String smtp_fingerprint = args.getString("smtp_fingerprint");
2019-01-17 09:57:01 +00:00
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name));
if (TextUtils.isEmpty(email))
throw new IllegalArgumentException(context.getString(R.string.title_no_email));
2020-03-05 13:45:29 +00:00
if (!Helper.EMAIL_ADDRESS.matcher(email).matches())
2019-09-08 16:22:48 +00:00
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, email));
2019-10-02 12:54:10 +00:00
if (TextUtils.isEmpty(password))
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
2020-05-18 19:41:56 +00:00
if (TextUtils.isEmpty(imap_fingerprint))
imap_fingerprint = null;
if (TextUtils.isEmpty(smtp_fingerprint))
smtp_fingerprint = null;
2019-01-17 09:57:01 +00:00
2020-07-29 12:06:40 +00:00
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ani = (cm == null ? null : cm.getActiveNetworkInfo());
if (ani == null || !ani.isConnected())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
2019-11-14 17:40:34 +00:00
EmailProvider provider = EmailProvider.fromEmail(context, email, EmailProvider.Discover.ALL);
2020-02-02 18:05:34 +00:00
args.putBoolean("appPassword", provider.appPassword);
2019-01-17 09:57:01 +00:00
2019-08-04 07:10:52 +00:00
if (provider.link != null)
args.putString("link", provider.link);
2019-01-17 09:57:01 +00:00
if (provider.documentation != null)
args.putString("documentation", provider.documentation.toString());
2019-11-14 17:40:34 +00:00
int at = email.indexOf('@');
String username = email.substring(0, at);
String user = (provider.user == EmailProvider.UserType.EMAIL ? email : username);
Log.i("User type=" + provider.user + " name=" + user);
2019-01-17 09:57:01 +00:00
2020-05-19 05:16:31 +00:00
List<EntityFolder> folders;
2019-09-18 14:34:07 +00:00
String aprotocol = provider.imap.starttls ? "imap" : "imaps";
2020-02-06 12:06:10 +00:00
try (EmailService iservice = new EmailService(
context, aprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
2019-09-18 14:34:07 +00:00
try {
2020-02-06 12:06:10 +00:00
iservice.connect(
provider.imap.host, provider.imap.port,
EmailService.AUTH_TYPE_PASSWORD, null,
user, password,
2020-05-18 19:41:56 +00:00
null, imap_fingerprint);
} catch (EmailService.UntrustedException ex) {
2020-05-19 05:16:31 +00:00
if (check) {
2020-05-18 19:41:56 +00:00
imap_fingerprint = ex.getFingerprint();
2020-05-19 05:16:31 +00:00
iservice.connect(
provider.imap.host, provider.imap.port,
EmailService.AUTH_TYPE_PASSWORD, null,
user, password,
null, imap_fingerprint);
} else
2020-05-18 19:41:56 +00:00
throw ex;
2020-05-26 19:08:56 +00:00
} catch (Throwable ex) {
// Why not AuthenticationFailedException?
// Some providers refuse connection with an invalid username
2019-11-14 17:40:34 +00:00
if (!user.equals(username)) {
2019-09-18 14:34:07 +00:00
Log.w(ex);
2019-11-14 17:40:34 +00:00
user = username;
2019-09-18 14:34:07 +00:00
Log.i("Retry with user=" + user);
iservice.connect(
provider.imap.host, provider.imap.port,
EmailService.AUTH_TYPE_PASSWORD, null,
user, password,
2020-02-10 15:35:14 +00:00
null, null);
2019-09-18 14:34:07 +00:00
} else
throw ex;
2019-01-14 11:11:03 +00:00
}
2019-09-18 14:34:07 +00:00
2020-05-19 05:16:31 +00:00
folders = iservice.getFolders();
2019-09-18 14:34:07 +00:00
2020-05-19 05:16:31 +00:00
if (folders == null)
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_system_folders));
2019-01-17 09:57:01 +00:00
}
2020-07-02 11:52:42 +00:00
Long max_size = null;
2019-09-18 14:34:07 +00:00
String iprotocol = provider.smtp.starttls ? "smtp" : "smtps";
2020-02-06 12:06:10 +00:00
try (EmailService iservice = new EmailService(
context, iprotocol, null, false, EmailService.PURPOSE_CHECK, true)) {
iservice.setUseIp(provider.useip, null);
2020-02-06 12:06:10 +00:00
iservice.connect(
provider.smtp.host, provider.smtp.port,
EmailService.AUTH_TYPE_PASSWORD, null,
user, password,
2020-05-18 19:41:56 +00:00
null, smtp_fingerprint);
2020-07-02 11:52:42 +00:00
max_size = iservice.getMaxSize();
2020-05-18 19:41:56 +00:00
} catch (EmailService.UntrustedException ex) {
if (check)
smtp_fingerprint = ex.getFingerprint();
else
throw ex;
2019-01-17 09:57:01 +00:00
}
2020-05-18 19:41:56 +00:00
if (check) {
args.putString("imap_fingerprint", imap_fingerprint);
args.putString("smtp_fingerprint", smtp_fingerprint);
2019-02-18 11:39:43 +00:00
return provider;
2020-05-18 19:41:56 +00:00
}
2019-02-18 11:39:43 +00:00
2019-01-17 09:57:01 +00:00
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2019-09-18 14:34:07 +00:00
2019-01-17 09:57:01 +00:00
EntityAccount primary = db.account().getPrimaryAccount();
// Create account
EntityAccount account = new EntityAccount();
2019-08-17 09:50:33 +00:00
account.host = provider.imap.host;
account.starttls = provider.imap.starttls;
account.port = provider.imap.port;
2020-01-29 20:06:45 +00:00
account.auth_type = EmailService.AUTH_TYPE_PASSWORD;
2019-01-17 09:57:01 +00:00
account.user = user;
account.password = password;
2020-05-18 19:41:56 +00:00
account.fingerprint = imap_fingerprint;
2019-01-17 09:57:01 +00:00
2020-07-14 06:29:52 +00:00
account.name = provider.name + "/" + username;
2019-01-17 09:57:01 +00:00
account.synchronize = true;
account.primary = (primary == null);
2019-12-05 16:48:56 +00:00
if (provider.keepalive > 0)
account.poll_interval = provider.keepalive;
account.partial_fetch = provider.partial;
2019-10-13 17:02:21 +00:00
2019-09-18 14:34:07 +00:00
account.created = new Date().getTime();
account.last_connected = account.created;
2019-01-17 09:57:01 +00:00
account.id = db.account().insertAccount(account);
2019-09-21 10:04:36 +00:00
args.putLong("account", account.id);
2019-02-02 07:28:14 +00:00
EntityLog.log(context, "Quick added account=" + account.name);
2019-01-17 09:57:01 +00:00
// Create folders
for (EntityFolder folder : folders) {
2020-03-09 14:57:58 +00:00
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) {
folder.account = account.id;
folder.id = db.folder().insertFolder(folder);
EntityLog.log(context, "Quick added folder=" + folder.name + " type=" + folder.type);
}
2019-01-14 11:11:03 +00:00
}
2019-01-17 09:57:01 +00:00
// Set swipe left/right folder
for (EntityFolder folder : folders)
if (EntityFolder.TRASH.equals(folder.type))
account.swipe_left = folder.id;
else if (EntityFolder.ARCHIVE.equals(folder.type))
account.swipe_right = folder.id;
db.account().updateAccount(account);
2019-01-17 09:57:01 +00:00
// Create identity
EntityIdentity identity = new EntityIdentity();
identity.name = name;
identity.email = email;
identity.account = account.id;
2019-08-17 09:50:33 +00:00
identity.host = provider.smtp.host;
identity.starttls = provider.smtp.starttls;
identity.port = provider.smtp.port;
2020-01-29 20:06:45 +00:00
identity.auth_type = EmailService.AUTH_TYPE_PASSWORD;
2019-01-17 09:57:01 +00:00
identity.user = user;
identity.password = password;
2020-05-18 19:41:56 +00:00
identity.fingerprint = smtp_fingerprint;
2019-11-06 11:48:12 +00:00
identity.use_ip = provider.useip;
2019-01-17 09:57:01 +00:00
identity.synchronize = true;
identity.primary = true;
2020-07-02 11:52:42 +00:00
identity.max_size = max_size;
2019-01-17 09:57:01 +00:00
identity.id = db.identity().insertIdentity(identity);
2019-02-02 07:28:14 +00:00
EntityLog.log(context, "Quick added identity=" + identity.name + " email=" + identity.email);
2019-01-17 09:57:01 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2019-12-09 18:44:27 +00:00
ServiceSynchronize.eval(context, "quick setup");
2019-01-17 09:57:01 +00:00
return null;
2019-01-14 11:11:03 +00:00
}
2019-01-17 09:57:01 +00:00
@Override
2019-02-18 11:39:43 +00:00
protected void onExecuted(Bundle args, EmailProvider result) {
boolean check = args.getBoolean("check");
if (check) {
2019-02-18 12:57:56 +00:00
tvImap.setText(result == null ? null
2019-08-17 09:50:33 +00:00
: result.imap.host + ":" + result.imap.port + (result.imap.starttls ? " starttls" : " ssl"));
2020-05-18 19:41:56 +00:00
tvImapFingerprint.setText(args.getString("imap_fingerprint"));
2019-02-18 12:57:56 +00:00
tvSmtp.setText(result == null ? null
2019-08-17 09:50:33 +00:00
: result.smtp.host + ":" + result.smtp.port + (result.smtp.starttls ? " starttls" : " ssl"));
2020-05-18 19:41:56 +00:00
tvSmtpFingerprint.setText(args.getString("smtp_fingerprint"));
2019-02-18 11:39:43 +00:00
grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE);
} else {
2019-09-21 20:18:24 +00:00
FragmentReview fragment = new FragmentReview();
2019-09-21 10:04:36 +00:00
fragment.setArguments(args);
2019-09-21 19:53:54 +00:00
fragment.setTargetFragment(FragmentQuickSetup.this, ActivitySetup.REQUEST_DONE);
2019-10-12 15:16:53 +00:00
fragment.show(getParentFragmentManager(), "quick:review");
}
2019-01-17 09:57:01 +00:00
}
2019-01-14 11:11:03 +00:00
2019-01-17 09:57:01 +00:00
@Override
2019-07-06 14:24:03 +00:00
protected void onException(final Bundle args, Throwable ex) {
2019-09-21 19:53:54 +00:00
Log.e(ex);
2019-10-02 12:54:10 +00:00
2020-02-02 18:05:34 +00:00
if (ex instanceof AuthenticationFailedException) {
boolean appPassword = args.getBoolean("appPassword");
String message = getString(R.string.title_setup_no_auth_hint);
if (appPassword)
2020-02-03 15:16:31 +00:00
message += "\n" + getString(R.string.title_setup_app_password_hint);
2020-02-02 18:05:34 +00:00
tvErrorHint.setText(message);
} else
2020-01-31 11:03:23 +00:00
tvErrorHint.setText(R.string.title_setup_no_settings_hint);
2019-10-02 12:54:10 +00:00
if (ex instanceof IllegalArgumentException || ex instanceof UnknownHostException) {
2019-09-13 16:52:09 +00:00
tvError.setText(ex.getMessage());
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.VISIBLE);
2019-10-02 12:54:10 +00:00
new Handler().post(new Runnable() {
@Override
public void run() {
2020-01-31 11:03:23 +00:00
scroll.smoothScrollTo(0, tvErrorHint.getBottom());
2019-10-02 12:54:10 +00:00
}
});
} else {
2019-12-06 07:50:46 +00:00
tvError.setText(Log.formatThrowable(ex, false));
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.VISIBLE);
2019-07-06 14:24:03 +00:00
2019-10-02 12:54:10 +00:00
if (args.containsKey("link")) {
Uri uri = Uri.parse(args.getString("link"));
btnHelp.setTag(uri);
btnHelp.setVisibility(View.VISIBLE);
}
2019-09-09 14:44:06 +00:00
2019-10-02 12:54:10 +00:00
btnSupport.setVisibility(View.VISIBLE);
2019-07-06 14:24:03 +00:00
2019-10-02 12:54:10 +00:00
if (args.containsKey("documentation")) {
2020-06-28 19:23:33 +00:00
tvInstructions.setText(HtmlHelper.fromHtml(args.getString("documentation"), true, getContext()));
2019-10-02 12:54:10 +00:00
tvInstructions.setVisibility(View.VISIBLE);
2019-07-06 14:24:03 +00:00
}
2019-10-02 12:54:10 +00:00
new Handler().post(new Runnable() {
@Override
public void run() {
if (args.containsKey("documentation"))
scroll.smoothScrollTo(0, tvInstructions.getBottom());
else
scroll.smoothScrollTo(0, btnSupport.getBottom());
}
});
}
2019-01-17 09:57:01 +00:00
}
2019-09-11 12:03:59 +00:00
}.execute(this, args, "setup:quick");
2019-01-14 11:11:03 +00:00
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
2019-07-15 12:11:55 +00:00
try {
switch (requestCode) {
2019-09-21 19:53:54 +00:00
case ActivitySetup.REQUEST_DONE:
2019-07-15 12:11:55 +00:00
finish();
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
2019-01-14 11:11:03 +00:00
}