Files
FairEmail/app/src/main/java/eu/faircode/email/FragmentIdentity.java

599 lines
26 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
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.
NetGuard 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 NetGuard. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.content.Context;
2018-08-07 19:35:21 +00:00
import android.content.DialogInterface;
2018-08-02 13:33:06 +00:00
import android.os.Bundle;
import android.text.TextUtils;
2018-09-18 14:22:10 +00:00
import android.util.Log;
2018-08-02 13:33:06 +00:00
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
2018-08-07 19:35:21 +00:00
import android.widget.ImageButton;
2018-08-02 13:33:06 +00:00
import android.widget.ProgressBar;
import android.widget.Spinner;
2018-09-18 14:22:10 +00:00
import com.google.android.material.snackbar.Snackbar;
2018-08-08 06:55:47 +00:00
import com.google.android.material.textfield.TextInputLayout;
2018-09-18 14:22:10 +00:00
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord;
import org.xbill.DNS.Type;
2018-08-13 18:31:42 +00:00
import java.util.ArrayList;
2018-08-02 13:33:06 +00:00
import java.util.List;
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
2018-08-08 06:55:47 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
2018-08-24 16:41:22 +00:00
import androidx.constraintlayout.widget.Group;
2018-08-08 06:55:47 +00:00
import androidx.lifecycle.Observer;
public class FragmentIdentity extends FragmentEx {
private ViewGroup view;
2018-08-02 13:33:06 +00:00
private EditText etName;
2018-09-05 20:04:23 +00:00
private Spinner spAccount;
private Button btnAdvanced;
2018-08-02 13:33:06 +00:00
private EditText etEmail;
private EditText etReplyTo;
2018-08-15 09:50:39 +00:00
private Spinner spProvider;
2018-09-18 14:22:10 +00:00
private EditText etDomain;
private Button btnAutoConfig;
2018-08-02 13:33:06 +00:00
private EditText etHost;
private CheckBox cbStartTls;
private EditText etPort;
private EditText etUser;
private TextInputLayout tilPassword;
2018-08-02 13:33:06 +00:00
private CheckBox cbSynchronize;
2018-08-06 10:02:47 +00:00
private CheckBox cbPrimary;
2018-08-25 14:24:26 +00:00
private CheckBox cbStoreSent;
2018-08-06 10:27:21 +00:00
private Button btnSave;
private ProgressBar pbSave;
2018-08-07 19:35:21 +00:00
private ImageButton ibDelete;
private ProgressBar pbWait;
2018-09-05 20:04:23 +00:00
private Group grpAdvanced;
2018-08-02 13:33:06 +00:00
2018-08-27 14:31:45 +00:00
private long id = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get arguments
Bundle args = getArguments();
id = (args == null ? -1 : args.getLong("id", -1));
}
2018-08-02 13:33:06 +00:00
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_identity);
view = (ViewGroup) inflater.inflate(R.layout.fragment_identity, container, false);
2018-08-02 13:33:06 +00:00
// Get controls
etName = view.findViewById(R.id.etName);
2018-09-05 20:04:23 +00:00
spAccount = view.findViewById(R.id.spAccount);
2018-09-18 14:22:10 +00:00
2018-09-05 20:04:23 +00:00
btnAdvanced = view.findViewById(R.id.btnAdvanced);
2018-08-02 13:33:06 +00:00
etEmail = view.findViewById(R.id.etEmail);
etReplyTo = view.findViewById(R.id.etReplyTo);
2018-09-18 14:22:10 +00:00
2018-08-15 09:50:39 +00:00
spProvider = view.findViewById(R.id.spProvider);
2018-09-18 14:22:10 +00:00
etDomain = view.findViewById(R.id.etDomain);
btnAutoConfig = view.findViewById(R.id.btnAutoConfig);
2018-08-02 13:33:06 +00:00
etHost = view.findViewById(R.id.etHost);
cbStartTls = view.findViewById(R.id.cbStartTls);
etPort = view.findViewById(R.id.etPort);
2018-09-18 14:22:10 +00:00
2018-08-02 13:33:06 +00:00
etUser = view.findViewById(R.id.etUser);
tilPassword = view.findViewById(R.id.tilPassword);
2018-09-18 14:22:10 +00:00
2018-08-02 13:33:06 +00:00
cbSynchronize = view.findViewById(R.id.cbSynchronize);
2018-08-06 10:02:47 +00:00
cbPrimary = view.findViewById(R.id.cbPrimary);
2018-08-25 14:24:26 +00:00
cbStoreSent = view.findViewById(R.id.cbStoreSent);
2018-09-18 14:22:10 +00:00
2018-08-06 10:27:21 +00:00
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
2018-08-07 19:35:21 +00:00
ibDelete = view.findViewById(R.id.ibDelete);
pbWait = view.findViewById(R.id.pbWait);
2018-09-05 20:04:23 +00:00
grpAdvanced = view.findViewById(R.id.grpAdvanced);
2018-08-02 13:33:06 +00:00
// Wire controls
spAccount.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
2018-09-05 20:04:23 +00:00
btnAdvanced.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
2018-09-06 07:29:30 +00:00
if (position == 0)
grpAdvanced.setVisibility(View.GONE);
2018-09-05 20:04:23 +00:00
tilPassword.setPasswordVisibilityToggleEnabled(position == 0);
btnSave.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
2018-08-15 09:50:39 +00:00
Integer tag = (Integer) adapterView.getTag();
if (tag != null && tag.equals(position))
return;
adapterView.setTag(position);
EntityAccount account = (EntityAccount) adapterView.getAdapter().getItem(position);
2018-08-14 07:56:17 +00:00
// Select associated provider
2018-09-06 07:29:30 +00:00
if (position == 0)
spProvider.setSelection(0);
else {
boolean found = false;
for (int pos = 1; pos < spProvider.getAdapter().getCount(); pos++) {
Provider provider = (Provider) spProvider.getItemAtPosition(pos);
if (provider.imap_host.equals(account.host) &&
provider.imap_port == account.port) {
found = true;
spProvider.setSelection(pos);
// This is needed because the spinner might be invisible
etHost.setText(provider.smtp_host);
etPort.setText(Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.starttls);
break;
}
2018-08-14 07:56:17 +00:00
}
2018-09-06 07:29:30 +00:00
if (!found)
grpAdvanced.setVisibility(View.VISIBLE);
2018-08-15 09:50:39 +00:00
}
2018-08-14 07:56:17 +00:00
// Copy account user name
2018-09-05 20:04:23 +00:00
etEmail.setText(account.user);
etUser.setText(account.user);
2018-08-14 07:56:17 +00:00
// Copy account password
tilPassword.getEditText().setText(account.password);
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
2018-09-05 20:04:23 +00:00
btnAdvanced.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int visibility = (grpAdvanced.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
grpAdvanced.setVisibility(visibility);
}
});
2018-08-15 09:50:39 +00:00
spProvider.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2018-08-02 13:33:06 +00:00
@Override
2018-08-15 09:50:39 +00:00
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
Integer tag = (Integer) adapterView.getTag();
if (tag != null && tag.equals(position))
return;
adapterView.setTag(position);
Provider provider = (Provider) adapterView.getSelectedItem();
2018-08-24 16:41:22 +00:00
// Set associated host/port/starttls
etHost.setText(provider.smtp_host);
etPort.setText(position == 0 ? null : Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.starttls);
2018-08-02 13:33:06 +00:00
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
2018-09-18 14:22:10 +00:00
btnAutoConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnAutoConfig.setEnabled(false);
Bundle args = new Bundle();
args.putString("domain", etDomain.getText().toString());
new SimpleTask<SRVRecord>() {
@Override
protected SRVRecord onLoad(Context context, Bundle args) throws Throwable {
String domain = args.getString("domain");
Record[] records = new Lookup("_submission._tcp." + domain, Type.SRV).run();
if (records != null)
for (int i = 0; i < records.length; i++) {
SRVRecord srv = (SRVRecord) records[i];
Log.i(Helper.TAG, "SRV=" + srv);
return srv;
}
throw new IllegalArgumentException(getString(R.string.title_no_settings));
}
@Override
protected void onLoaded(Bundle args, SRVRecord srv) {
btnAutoConfig.setEnabled(true);
if (srv != null) {
etHost.setText(srv.getTarget().toString(true));
etPort.setText(Integer.toString(srv.getPort()));
cbStartTls.setChecked(srv.getPort() == 587);
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
btnAutoConfig.setEnabled(true);
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), ex);
}
}.load(FragmentIdentity.this, args);
}
});
2018-08-08 10:22:12 +00:00
cbStartTls.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
etPort.setHint(checked ? "587" : "465");
}
});
2018-08-02 13:33:06 +00:00
2018-08-06 10:02:47 +00:00
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbPrimary.setEnabled(checked);
}
});
2018-08-06 10:27:21 +00:00
btnSave.setOnClickListener(new View.OnClickListener() {
2018-08-02 13:33:06 +00:00
@Override
public void onClick(View v) {
Helper.setViewsEnabled(view, false);
2018-08-06 10:27:21 +00:00
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
2018-08-02 13:33:06 +00:00
2018-08-08 10:22:12 +00:00
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
2018-08-02 13:33:06 +00:00
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", etName.getText().toString());
args.putString("email", etEmail.getText().toString());
args.putString("replyto", etReplyTo.getText().toString());
2018-08-08 10:22:12 +00:00
args.putLong("account", account == null ? -1 : account.id);
2018-08-28 19:37:44 +00:00
args.putInt("auth_type", account == null || account.auth_type == null ? Helper.AUTH_TYPE_PASSWORD : account.auth_type);
args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked());
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
2018-08-25 14:24:26 +00:00
args.putBoolean("store_sent", cbStoreSent.isChecked());
2018-08-02 13:33:06 +00:00
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
2018-08-12 15:31:43 +00:00
long id = args.getLong("id");
String name = args.getString("name");
2018-09-05 20:04:23 +00:00
long account = args.getLong("account");
2018-08-12 15:31:43 +00:00
String email = args.getString("email");
String replyto = args.getString("replyto");
String host = args.getString("host");
boolean starttls = args.getBoolean("starttls");
String port = args.getString("port");
String user = args.getString("user");
String password = args.getString("password");
2018-08-27 14:31:45 +00:00
int auth_type = args.getInt("auth_type");
2018-08-12 15:31:43 +00:00
boolean synchronize = args.getBoolean("synchronize");
2018-08-25 14:24:26 +00:00
boolean primary = args.getBoolean("primary");
boolean store_sent = args.getBoolean("store_sent");
2018-08-12 15:31:43 +00:00
if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(getContext().getString(R.string.title_no_name));
if (TextUtils.isEmpty(email))
throw new IllegalArgumentException(getContext().getString(R.string.title_no_email));
if (TextUtils.isEmpty(host))
throw new IllegalArgumentException(getContext().getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
2018-09-19 09:09:30 +00:00
port = "465";
2018-08-12 15:31:43 +00:00
if (TextUtils.isEmpty(user))
throw new IllegalArgumentException(getContext().getString(R.string.title_no_user));
if (TextUtils.isEmpty(password))
throw new IllegalArgumentException(getContext().getString(R.string.title_no_password));
if (TextUtils.isEmpty(replyto))
replyto = null;
// Check SMTP server
if (synchronize) {
Properties props = MessageHelper.getSessionProperties(context, auth_type);
2018-08-12 15:31:43 +00:00
Session isession = Session.getInstance(props, null);
2018-08-27 15:08:23 +00:00
isession.setDebug(true);
2018-08-12 15:31:43 +00:00
Transport itransport = isession.getTransport(starttls ? "smtp" : "smtps");
try {
itransport.connect(host, Integer.parseInt(port), user, password);
} finally {
itransport.close();
}
2018-08-12 15:31:43 +00:00
}
2018-08-22 12:30:27 +00:00
DB db = DB.getInstance(getContext());
2018-08-12 15:31:43 +00:00
try {
2018-08-22 12:30:27 +00:00
db.beginTransaction();
EntityIdentity identity = db.identity().getIdentity(id);
boolean update = (identity != null);
if (identity == null)
identity = new EntityIdentity();
identity.name = name;
2018-09-05 20:04:23 +00:00
identity.account = account;
2018-08-22 12:30:27 +00:00
identity.email = email;
identity.replyto = replyto;
identity.host = host;
identity.port = Integer.parseInt(port);
identity.starttls = starttls;
identity.user = user;
identity.password = password;
2018-08-27 14:31:45 +00:00
identity.auth_type = auth_type;
2018-08-22 12:30:27 +00:00
identity.synchronize = synchronize;
2018-08-25 14:24:26 +00:00
identity.primary = (identity.synchronize && primary);
identity.store_sent = store_sent;
2018-08-22 12:30:27 +00:00
if (!identity.synchronize)
identity.error = null;
if (identity.primary)
db.identity().resetPrimary();
if (update)
db.identity().updateIdentity(identity);
else
identity.id = db.identity().insertIdentity(identity);
db.setTransactionSuccessful();
} finally {
2018-08-22 12:30:27 +00:00
db.endTransaction();
}
2018-08-22 12:30:27 +00:00
ServiceSynchronize.reload(getContext(), "save identity");
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
new AlertDialog.Builder(getContext())
.setMessage(Helper.formatThrowable(ex))
2018-09-15 05:49:54 +00:00
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();
}
}.load(FragmentIdentity.this, args);
2018-08-02 13:33:06 +00:00
}
});
2018-08-07 19:35:21 +00:00
ibDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(getContext())
2018-08-07 19:35:21 +00:00
.setMessage(R.string.title_identity_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
2018-08-11 18:16:35 +00:00
@Override
protected Void onLoad(Context context, Bundle args) {
2018-08-22 12:30:27 +00:00
long id = args.getLong("id");
DB.getInstance(context).identity().deleteIdentity(id);
ServiceSynchronize.reload(getContext(), "delete identity");
return null;
2018-08-11 18:16:35 +00:00
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
2018-08-07 19:35:21 +00:00
@Override
protected void onException(Bundle args, Throwable ex) {
2018-09-15 05:49:54 +00:00
Helper.unexpectedError(getContext(), ex);
2018-08-07 19:35:21 +00:00
}
}.load(FragmentIdentity.this, args);
2018-08-07 19:35:21 +00:00
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
2018-08-07 19:35:21 +00:00
}
});
// Initialize
Helper.setViewsEnabled(view, false);
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
2018-09-05 20:04:23 +00:00
btnSave.setVisibility(View.GONE);
btnAdvanced.setVisibility(View.GONE);
grpAdvanced.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
ibDelete.setVisibility(View.GONE);
return view;
}
@Override
2018-08-15 09:50:39 +00:00
public void onSaveInstanceState(Bundle outState) {
2018-08-21 18:00:06 +00:00
super.onSaveInstanceState(outState);
2018-08-15 09:50:39 +00:00
outState.putInt("account", spAccount.getSelectedItemPosition());
outState.putInt("provider", spProvider.getSelectedItemPosition());
outState.putString("password", tilPassword.getEditText().getText().toString());
2018-09-05 20:04:23 +00:00
outState.putInt("advanced", grpAdvanced.getVisibility());
2018-08-15 09:50:39 +00:00
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
2018-08-08 10:22:12 +00:00
final DB db = DB.getInstance(getContext());
// Observe identity
db.identity().liveIdentity(id).observe(getViewLifecycleOwner(), new Observer<EntityIdentity>() {
2018-09-05 20:39:47 +00:00
private boolean once = false;
2018-08-02 13:33:06 +00:00
@Override
2018-08-08 10:22:12 +00:00
public void onChanged(@Nullable final EntityIdentity identity) {
2018-09-05 20:39:47 +00:00
if (once)
return;
once = true;
2018-08-16 11:26:53 +00:00
2018-09-05 20:39:47 +00:00
if (savedInstanceState == null) {
2018-08-16 11:26:53 +00:00
etName.setText(identity == null ? null : identity.name);
etEmail.setText(identity == null ? null : identity.email);
etReplyTo.setText(identity == null ? null : identity.replyto);
etHost.setText(identity == null ? null : identity.host);
cbStartTls.setChecked(identity == null ? false : identity.starttls);
etPort.setText(identity == null ? null : Long.toString(identity.port));
etUser.setText(identity == null ? null : identity.user);
tilPassword.getEditText().setText(identity == null ? null : identity.password);
cbSynchronize.setChecked(identity == null ? true : identity.synchronize);
cbPrimary.setChecked(identity == null ? true : identity.primary);
2018-08-25 14:24:26 +00:00
cbStoreSent.setChecked(identity == null ? false : identity.store_sent);
2018-08-16 11:26:53 +00:00
etName.requestFocus();
if (identity == null)
new SimpleTask<Integer>() {
@Override
protected Integer onLoad(Context context, Bundle args) {
return DB.getInstance(context).identity().getSynchronizingIdentityCount();
}
@Override
protected void onLoaded(Bundle args, Integer count) {
cbPrimary.setChecked(count == 0);
}
}.load(FragmentIdentity.this, new Bundle());
2018-09-05 20:04:23 +00:00
} else {
2018-08-15 09:50:39 +00:00
tilPassword.getEditText().setText(savedInstanceState.getString("password"));
2018-09-05 20:04:23 +00:00
grpAdvanced.setVisibility(savedInstanceState.getInt("advanced"));
}
2018-08-15 09:50:39 +00:00
Helper.setViewsEnabled(view, true);
2018-08-15 09:50:39 +00:00
cbPrimary.setEnabled(cbSynchronize.isChecked());
2018-08-16 11:26:53 +00:00
// Consider previous save/delete as cancelled
ibDelete.setVisibility(identity == null ? View.GONE : View.VISIBLE);
pbWait.setVisibility(View.GONE);
2018-08-08 10:22:12 +00:00
db.account().liveAccounts().removeObservers(getViewLifecycleOwner());
db.account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
2018-09-05 20:39:47 +00:00
private boolean once = false;
2018-08-08 10:22:12 +00:00
@Override
public void onChanged(List<EntityAccount> accounts) {
2018-09-05 20:39:47 +00:00
if (once)
return;
once = true;
2018-08-12 15:31:43 +00:00
if (accounts == null)
2018-08-13 18:31:42 +00:00
accounts = new ArrayList<>();
2018-08-12 15:31:43 +00:00
2018-08-08 10:22:12 +00:00
EntityAccount unselected = new EntityAccount();
unselected.id = -1L;
2018-08-27 14:31:45 +00:00
unselected.name = getString(R.string.title_select);
2018-08-08 10:22:12 +00:00
unselected.primary = false;
accounts.add(0, unselected);
2018-08-15 09:50:39 +00:00
ArrayAdapter<EntityAccount> aa = new ArrayAdapter<>(getContext(), R.layout.spinner_item, accounts);
aa.setDropDownViewResource(R.layout.spinner_dropdown_item);
spAccount.setAdapter(aa);
// Get providers
List<Provider> providers = Provider.loadProfiles(getContext());
providers.add(0, new Provider(getString(R.string.title_custom)));
ArrayAdapter<Provider> adapterProfile = new ArrayAdapter<>(getContext(), R.layout.spinner_item, providers);
adapterProfile.setDropDownViewResource(R.layout.spinner_dropdown_item);
spProvider.setAdapter(adapterProfile);
if (savedInstanceState == null) {
2018-08-27 15:08:23 +00:00
spProvider.setTag(0);
spProvider.setSelection(0);
if (identity != null)
for (int pos = 1; pos < providers.size(); pos++)
if (providers.get(pos).smtp_host.equals(identity.host)) {
spProvider.setTag(pos);
spProvider.setSelection(pos);
break;
}
spAccount.setTag(0);
spAccount.setSelection(0);
2018-08-15 09:50:39 +00:00
for (int pos = 0; pos < accounts.size(); pos++)
if (accounts.get(pos).id == (identity == null ? -1 : identity.account)) {
2018-08-27 15:08:23 +00:00
spAccount.setTag(pos);
2018-08-15 09:50:39 +00:00
spAccount.setSelection(pos);
2018-08-27 15:08:23 +00:00
// OAuth token could be updated
if (pos > 0 && accounts.get(pos).auth_type != Helper.AUTH_TYPE_PASSWORD)
2018-08-27 15:08:23 +00:00
tilPassword.getEditText().setText(accounts.get(pos).password);
2018-08-15 09:50:39 +00:00
break;
}
} else {
int provider = savedInstanceState.getInt("provider");
spProvider.setTag(provider);
spProvider.setSelection(provider);
int account = savedInstanceState.getInt("account");
spAccount.setTag(account);
spAccount.setSelection(account);
}
2018-08-08 10:22:12 +00:00
}
});
2018-08-02 13:33:06 +00:00
}
});
}
}