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

1112 lines
49 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.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
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
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
Copyright 2018 by Marcel Bokhorst (M66B)
*/
2018-08-27 14:31:45 +00:00
import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AccountManagerCallback;
import android.accounts.AccountManagerFuture;
import android.app.Activity;
2018-08-02 13:33:06 +00:00
import android.content.Context;
2018-08-07 19:35:21 +00:00
import android.content.DialogInterface;
2018-08-27 14:31:45 +00:00
import android.content.Intent;
2018-10-23 07:52:20 +00:00
import android.content.SharedPreferences;
2018-08-27 14:31:45 +00:00
import android.content.pm.PackageManager;
2018-09-12 16:54:48 +00:00
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
2018-08-27 14:31:45 +00:00
import android.os.Build;
2018-08-02 13:33:06 +00:00
import android.os.Bundle;
import android.os.Handler;
2018-10-23 07:52:20 +00:00
import android.preference.PreferenceManager;
2018-08-29 06:37:22 +00:00
import android.text.Editable;
2018-08-02 13:33:06 +00:00
import android.text.TextUtils;
2018-08-29 06:37:22 +00:00
import android.text.TextWatcher;
2018-08-02 13:33:06 +00:00
import android.util.Log;
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;
2018-08-06 10:02:47 +00:00
import android.widget.CompoundButton;
2018-08-02 13:33:06 +00:00
import android.widget.EditText;
2018-08-07 19:35:21 +00:00
import android.widget.ImageButton;
2018-09-12 16:54:48 +00:00
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.ScrollView;
2018-08-02 13:33:06 +00:00
import android.widget.Spinner;
2018-09-22 07:51:54 +00:00
import android.widget.TextView;
2018-08-02 13:33:06 +00:00
2018-09-12 16:54:48 +00:00
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
2018-09-05 12:37:27 +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-08-02 13:33:06 +00:00
import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPStore;
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-02 13:33:06 +00:00
import java.util.ArrayList;
import java.util.Date;
2018-08-02 13:33:06 +00:00
import java.util.List;
2018-08-27 14:31:45 +00:00
import java.util.Properties;
2018-08-02 13:33:06 +00:00
2018-09-21 13:09:22 +00:00
import javax.mail.AuthenticationFailedException;
2018-08-02 13:33:06 +00:00
import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.Session;
2018-08-08 06:55:47 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2018-08-10 09:45:36 +00:00
import androidx.constraintlayout.widget.Group;
2018-08-27 14:31:45 +00:00
import androidx.core.content.ContextCompat;
2018-09-07 08:44:48 +00:00
import androidx.fragment.app.FragmentTransaction;
2018-08-08 06:55:47 +00:00
2018-08-27 14:31:45 +00:00
import static android.accounts.AccountManager.newChooseAccountIntent;
public class FragmentAccount extends FragmentEx {
private ViewGroup view;
2018-08-15 09:50:39 +00:00
private Spinner spProvider;
2018-10-23 07:52:20 +00:00
2018-09-18 14:22:10 +00:00
private EditText etDomain;
private Button btnAutoConfig;
2018-10-23 07:52:20 +00:00
private EditText etHost;
private CheckBox cbStartTls;
private CheckBox cbInsecure;
2018-08-02 13:33:06 +00:00
private EditText etPort;
private EditText etUser;
private TextInputLayout tilPassword;
2018-10-23 07:52:20 +00:00
private Button btnAuthorize;
2018-09-05 18:37:20 +00:00
private Button btnAdvanced;
2018-10-07 06:53:09 +00:00
2018-09-22 07:51:54 +00:00
private TextView tvName;
2018-09-05 18:37:20 +00:00
private EditText etName;
private Button btnColor;
private View vwColor;
private ImageView ibColorDefault;
2018-10-07 06:53:09 +00:00
2018-08-02 13:33:06 +00:00
private CheckBox cbSynchronize;
2018-08-06 10:02:47 +00:00
private CheckBox cbPrimary;
2018-09-21 17:19:02 +00:00
private EditText etInterval;
2018-10-07 06:53:09 +00:00
private Button btnCheck;
private ProgressBar pbCheck;
2018-09-22 10:29:35 +00:00
private TextView tvIdle;
2018-09-21 17:36:19 +00:00
private ArrayAdapter<EntityFolder> adapter;
2018-08-10 09:45:36 +00:00
private Spinner spDrafts;
private Spinner spSent;
private Spinner spAll;
private Spinner spTrash;
private Spinner spJunk;
2018-08-10 09:45:36 +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 18:37:20 +00:00
private Group grpServer;
private Group grpAuthorize;
private Group grpAdvanced;
2018-08-10 09:45:36 +00:00
private Group grpFolders;
2018-08-02 13:33:06 +00:00
2018-08-27 14:31:45 +00:00
private long id = -1;
2018-09-12 16:54:48 +00:00
private int color = Color.TRANSPARENT;
2018-08-29 06:37:22 +00:00
private String authorized = null;
2018-08-27 14:31:45 +00:00
@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_account);
2018-10-23 07:52:20 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
final boolean insecure = prefs.getBoolean("insecure", false);
view = (ViewGroup) inflater.inflate(R.layout.fragment_account, container, false);
2018-08-02 13:33:06 +00:00
// Get controls
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);
etPort = view.findViewById(R.id.etPort);
2018-10-23 07:52:20 +00:00
cbStartTls = view.findViewById(R.id.cbStartTls);
cbInsecure = view.findViewById(R.id.cbInsecure);
2018-08-02 13:33:06 +00:00
etUser = view.findViewById(R.id.etUser);
tilPassword = view.findViewById(R.id.tilPassword);
2018-09-05 18:37:20 +00:00
2018-10-23 07:52:20 +00:00
btnAuthorize = view.findViewById(R.id.btnAuthorize);
2018-09-05 18:37:20 +00:00
btnAdvanced = view.findViewById(R.id.btnAdvanced);
2018-10-07 06:53:09 +00:00
2018-09-05 18:37:20 +00:00
etName = view.findViewById(R.id.etName);
2018-09-22 07:51:54 +00:00
tvName = view.findViewById(R.id.tvName);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
2018-09-07 12:34:54 +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-09-21 17:19:02 +00:00
etInterval = view.findViewById(R.id.etInterval);
2018-09-05 18:37:20 +00:00
2018-08-10 09:45:36 +00:00
btnCheck = view.findViewById(R.id.btnCheck);
2018-08-02 13:33:06 +00:00
pbCheck = view.findViewById(R.id.pbCheck);
2018-09-05 18:37:20 +00:00
2018-09-22 10:29:35 +00:00
tvIdle = view.findViewById(R.id.tvIdle);
2018-08-10 09:45:36 +00:00
spDrafts = view.findViewById(R.id.spDrafts);
spSent = view.findViewById(R.id.spSent);
spAll = view.findViewById(R.id.spAll);
spTrash = view.findViewById(R.id.spTrash);
spJunk = view.findViewById(R.id.spJunk);
2018-09-05 18:37:20 +00:00
2018-08-10 09:45:36 +00:00
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
2018-09-05 18:37:20 +00:00
2018-08-07 19:35:21 +00:00
ibDelete = view.findViewById(R.id.ibDelete);
2018-09-05 18:37:20 +00:00
pbWait = view.findViewById(R.id.pbWait);
2018-09-05 18:37:20 +00:00
grpServer = view.findViewById(R.id.grpServer);
grpAuthorize = view.findViewById(R.id.grpAuthorize);
grpAdvanced = view.findViewById(R.id.grpAdvanced);
2018-08-10 09:45:36 +00:00
grpFolders = view.findViewById(R.id.grpFolders);
2018-08-02 13:33:06 +00:00
// Wire controls
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) {
Provider provider = (Provider) adapterView.getSelectedItem();
2018-09-05 18:37:20 +00:00
grpServer.setVisibility(position == 1 ? View.VISIBLE : View.GONE);
2018-10-23 07:52:20 +00:00
cbStartTls.setVisibility(position == 1 && insecure ? View.VISIBLE : View.GONE);
cbInsecure.setVisibility(position == 1 && insecure ? View.VISIBLE : View.GONE);
2018-09-05 18:37:20 +00:00
grpAuthorize.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
btnAuthorize.setVisibility(provider.type == null ? View.GONE : View.VISIBLE);
2018-09-05 18:37:20 +00:00
btnAdvanced.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
if (position == 0)
grpAdvanced.setVisibility(View.GONE);
btnCheck.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
2018-09-22 10:29:35 +00:00
tvIdle.setVisibility(View.GONE);
2018-09-05 18:37:20 +00:00
Object tag = adapterView.getTag();
if (tag != null && (Integer) tag == position)
return;
adapterView.setTag(position);
2018-08-27 14:31:45 +00:00
etHost.setText(provider.imap_host);
2018-09-05 18:37:20 +00:00
etPort.setText(provider.imap_host == null ? null : Integer.toString(provider.imap_port));
2018-11-09 14:48:21 +00:00
cbStartTls.setChecked(provider.imap_starttls);
2018-09-05 18:37:20 +00:00
etUser.setText(null);
tilPassword.getEditText().setText(null);
2018-08-27 15:08:23 +00:00
2018-09-05 18:37:20 +00:00
etName.setText(position > 1 ? provider.name : null);
2018-11-16 09:06:10 +01:00
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
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) {
2018-09-20 14:22:13 +00:00
etDomain.setEnabled(false);
2018-09-18 14:22:10 +00:00
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("_imaps._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) {
2018-09-20 14:22:13 +00:00
etDomain.setEnabled(true);
2018-09-18 14:22:10 +00:00
btnAutoConfig.setEnabled(true);
if (srv != null) {
etHost.setText(srv.getTarget().toString(true));
etPort.setText(Integer.toString(srv.getPort()));
2018-11-09 14:48:21 +00:00
cbStartTls.setChecked(srv.getPort() == 143);
2018-09-18 14:22:10 +00:00
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
2018-09-20 14:22:13 +00:00
etDomain.setEnabled(true);
2018-09-18 14:22:10 +00:00
btnAutoConfig.setEnabled(true);
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), ex);
}
}.load(FragmentAccount.this, args);
}
});
2018-10-23 07:52:20 +00:00
cbStartTls.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
etPort.setHint(checked ? "143" : "993");
}
});
2018-08-29 06:37:22 +00:00
tilPassword.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (authorized != null && !authorized.equals(s.toString()))
authorized = null;
}
@Override
public void afterTextChanged(Editable s) {
}
});
2018-08-27 14:31:45 +00:00
btnAuthorize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-11-10 14:59:31 +00:00
Provider provider = (Provider) spProvider.getSelectedItem();
Log.i(Helper.TAG, "Authorize " + provider);
if ("com.google".equals(provider.type)) {
String permission = Manifest.permission.GET_ACCOUNTS;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) {
Log.i(Helper.TAG, "Requesting " + permission);
requestPermissions(new String[]{permission}, ActivitySetup.REQUEST_PERMISSION);
} else
selectAccount();
}
2018-08-27 14:31:45 +00:00
}
});
2018-09-05 18:37:20 +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);
if (visibility == View.VISIBLE)
new Handler().post(new Runnable() {
@Override
public void run() {
2018-09-22 07:51:54 +00:00
((ScrollView) view).smoothScrollTo(0, tvName.getTop());
2018-09-05 18:37:20 +00:00
}
});
}
});
2018-09-12 16:54:48 +00:00
vwColor.setBackgroundColor(color);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2018-09-26 11:50:45 +00:00
if (Helper.isPro(getContext())) {
2018-09-12 19:19:42 +00:00
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
colorPickerDialog.initialize(R.string.title_account_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
setColor(color);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
} else {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
2018-09-20 19:52:31 +00:00
fragmentTransaction.hide(FragmentAccount.this);
fragmentTransaction.add(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
2018-09-12 19:19:42 +00:00
fragmentTransaction.commit();
}
2018-09-12 16:54:48 +00:00
}
});
ibColorDefault.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setColor(Color.TRANSPARENT);
}
});
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbPrimary.setEnabled(checked);
}
});
2018-08-10 09:45:36 +00:00
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
2018-08-10 09:45:36 +00:00
btnCheck.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
2018-09-22 10:29:35 +00:00
tvIdle.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
2018-09-05 18:37:20 +00:00
btnSave.setVisibility(View.GONE);
2018-08-10 09:45:36 +00:00
Provider provider = (Provider) spProvider.getSelectedItem();
2018-08-10 09:45:36 +00:00
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("host", etHost.getText().toString());
2018-10-23 07:52:20 +00:00
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
2018-08-10 09:45:36 +00:00
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
2018-08-29 06:37:22 +00:00
args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
2018-08-10 09:45:36 +00:00
2018-09-22 10:29:35 +00:00
new SimpleTask<CheckResult>() {
@Override
2018-09-22 10:29:35 +00:00
protected CheckResult onLoad(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
String host = args.getString("host");
2018-10-23 07:52:20 +00:00
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
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");
if (TextUtils.isEmpty(host))
throw new Throwable(getContext().getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
2018-10-23 07:52:20 +00:00
port = (starttls ? "143" : "993");
if (TextUtils.isEmpty(user))
throw new Throwable(getContext().getString(R.string.title_no_user));
2018-10-23 07:52:20 +00:00
if (TextUtils.isEmpty(password) && !insecure)
throw new Throwable(getContext().getString(R.string.title_no_password));
2018-09-22 10:29:35 +00:00
CheckResult result = new CheckResult();
result.folders = new ArrayList<>();
// Check IMAP server / get folders
2018-10-23 07:52:20 +00:00
Properties props = MessageHelper.getSessionProperties(auth_type, insecure);
2018-08-27 14:31:45 +00:00
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
IMAPStore istore = null;
try {
2018-10-23 07:52:20 +00:00
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
2018-09-21 13:09:22 +00:00
try {
istore.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
if (auth_type == Helper.AUTH_TYPE_GMAIL) {
password = Helper.refreshToken(context, "com.google", user, password);
istore.connect(host, Integer.parseInt(port), user, password);
} else
throw ex;
}
if (!istore.hasCapability("UIDPLUS"))
throw new MessagingException(getContext().getString(R.string.title_no_uidplus));
2018-09-22 10:29:35 +00:00
result.idle = istore.hasCapability("IDLE");
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
String type = null;
// First check folder attributes
boolean selectable = true;
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
for (String attr : attrs) {
if ("\\Noselect".equals(attr))
selectable = false;
if (attr.startsWith("\\")) {
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr.substring(1));
if (index >= 0) {
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
break;
}
}
}
if (selectable) {
// Next check folder full name
if (type == null) {
String fullname = ifolder.getFullName();
for (String attr : EntityFolder.SYSTEM_FOLDER_ATTR)
if (attr.equals(fullname)) {
int index = EntityFolder.SYSTEM_FOLDER_ATTR.indexOf(attr);
type = EntityFolder.SYSTEM_FOLDER_TYPE.get(index);
break;
}
}
// Create entry
DB db = DB.getInstance(context);
EntityFolder folder = db.folder().getFolderByName(id, ifolder.getFullName());
if (folder == null) {
folder = new EntityFolder();
folder.name = ifolder.getFullName();
folder.type = (type == null ? EntityFolder.USER : type);
folder.synchronize = (type != null && EntityFolder.SYSTEM_FOLDER_SYNC.contains(type));
2018-11-14 10:49:59 +01:00
folder.sync_days = (type == null ? EntityFolder.DEFAULT_USER_SYNC : EntityFolder.DEFAULT_SYSTEM_SYNC);
folder.keep_days = folder.sync_days;
}
2018-09-22 10:29:35 +00:00
result.folders.add(folder);
Log.i(Helper.TAG, folder.name + " id=" + folder.id +
" type=" + folder.type + " attr=" + TextUtils.join(",", attrs));
}
}
} finally {
if (istore != null)
istore.close();
}
2018-09-22 10:29:35 +00:00
return result;
}
@Override
2018-09-22 10:29:35 +00:00
protected void onLoaded(Bundle args, CheckResult result) {
Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
pbCheck.setVisibility(View.GONE);
2018-09-22 10:29:35 +00:00
tvIdle.setVisibility(result.idle ? View.GONE : View.VISIBLE);
setFolders(result.folders);
new Handler().post(new Runnable() {
@Override
public void run() {
((ScrollView) view).smoothScrollTo(0, btnSave.getBottom());
}
});
}
@Override
protected void onException(Bundle args, Throwable ex) {
2018-08-12 15:31:43 +00:00
Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true);
2018-08-12 15:31:43 +00:00
btnCheck.setEnabled(true);
pbCheck.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
2018-09-20 16:47:28 +00:00
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex))
2018-09-15 05:49:54 +00:00
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();
}
}.load(FragmentAccount.this, args);
2018-08-10 09:45:36 +00:00
}
});
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);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
2018-08-06 10:27:21 +00:00
btnSave.setEnabled(false);
pbSave.setVisibility(View.VISIBLE);
2018-08-10 09:45:36 +00:00
Provider provider = (Provider) spProvider.getSelectedItem();
2018-08-10 09:45:36 +00:00
EntityFolder drafts = (EntityFolder) spDrafts.getSelectedItem();
EntityFolder sent = (EntityFolder) spSent.getSelectedItem();
EntityFolder all = (EntityFolder) spAll.getSelectedItem();
EntityFolder trash = (EntityFolder) spTrash.getSelectedItem();
EntityFolder junk = (EntityFolder) spJunk.getSelectedItem();
if (drafts != null && drafts.type == null)
2018-08-10 09:45:36 +00:00
drafts = null;
if (sent != null && sent.type == null)
2018-08-10 09:45:36 +00:00
sent = null;
if (all != null && all.type == null)
2018-08-10 09:45:36 +00:00
all = null;
if (trash != null && trash.type == null)
2018-08-10 09:45:36 +00:00
trash = null;
if (junk != null && junk.type == null)
2018-08-10 09:45:36 +00:00
junk = null;
2018-08-02 13:33:06 +00:00
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("host", etHost.getText().toString());
2018-10-23 07:52:20 +00:00
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
2018-08-29 06:37:22 +00:00
args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
2018-09-07 08:44:48 +00:00
args.putString("name", etName.getText().toString());
args.putInt("color", color);
2018-10-07 06:53:09 +00:00
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
2018-09-21 17:19:02 +00:00
args.putString("interval", etInterval.getText().toString());
2018-10-06 21:44:34 +00:00
args.putSerializable("drafts", drafts);
args.putSerializable("sent", sent);
args.putSerializable("all", all);
args.putSerializable("trash", trash);
args.putSerializable("junk", junk);
2018-08-02 13:33:06 +00:00
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
2018-11-10 17:58:09 +00:00
long id = args.getLong("id");
2018-08-12 15:31:43 +00:00
String host = args.getString("host");
2018-10-23 07:52:20 +00:00
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
2018-08-12 15:31:43 +00:00
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-09-07 08:44:48 +00:00
String name = args.getString("name");
2018-10-12 06:33:43 +00:00
Integer color = args.getInt("color");
2018-10-07 06:53:09 +00:00
2018-08-12 15:31:43 +00:00
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
2018-09-21 17:19:02 +00:00
String interval = args.getString("interval");
2018-10-06 21:44:34 +00:00
EntityFolder drafts = (EntityFolder) args.getSerializable("drafts");
EntityFolder sent = (EntityFolder) args.getSerializable("sent");
EntityFolder all = (EntityFolder) args.getSerializable("all");
EntityFolder trash = (EntityFolder) args.getSerializable("trash");
EntityFolder junk = (EntityFolder) args.getSerializable("junk");
2018-08-12 15:31:43 +00:00
if (TextUtils.isEmpty(host))
throw new Throwable(getContext().getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
2018-10-23 07:52:20 +00:00
port = (starttls ? "143" : "993");
2018-08-12 15:31:43 +00:00
if (TextUtils.isEmpty(user))
throw new Throwable(getContext().getString(R.string.title_no_user));
if (synchronize && TextUtils.isEmpty(password) && !insecure)
2018-08-12 15:31:43 +00:00
throw new Throwable(getContext().getString(R.string.title_no_password));
2018-09-21 17:19:02 +00:00
if (TextUtils.isEmpty(interval))
2018-10-23 08:07:31 +00:00
interval = "19";
if (synchronize && drafts == null)
2018-08-12 15:31:43 +00:00
throw new Throwable(getContext().getString(R.string.title_no_drafts));
2018-11-10 17:58:09 +00:00
2018-10-12 06:33:43 +00:00
if (Color.TRANSPARENT == color)
color = null;
2018-08-12 15:31:43 +00:00
2018-11-10 17:58:09 +00:00
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id);
2018-11-11 07:20:32 +00:00
boolean check = (synchronize && (account == null ||
!host.equals(account.host) || Integer.parseInt(port) != account.port ||
2018-11-10 17:58:09 +00:00
!user.equals(account.user) || !password.equals(account.password)));
boolean reload = (account == null || account.synchronize != synchronize || check);
2018-11-10 17:58:09 +00:00
2018-08-12 15:31:43 +00:00
// Check IMAP server
2018-11-10 17:58:09 +00:00
if (check) {
2018-10-23 07:52:20 +00:00
Session isession = Session.getInstance(MessageHelper.getSessionProperties(auth_type, insecure), null);
2018-08-27 15:08:23 +00:00
isession.setDebug(true);
IMAPStore istore = null;
try {
2018-10-23 07:52:20 +00:00
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
2018-09-21 13:09:22 +00:00
try {
istore.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
if (auth_type == Helper.AUTH_TYPE_GMAIL) {
password = Helper.refreshToken(context, "com.google", user, password);
istore.connect(host, Integer.parseInt(port), user, password);
} else
throw ex;
}
2018-08-12 15:31:43 +00:00
2018-08-23 09:48:27 +00:00
if (!istore.hasCapability("UIDPLUS"))
throw new MessagingException(getContext().getString(R.string.title_no_uidplus));
} finally {
if (istore != null)
istore.close();
}
2018-08-12 15:31:43 +00:00
}
2018-08-12 15:31:43 +00:00
if (TextUtils.isEmpty(name))
2018-09-08 13:51:04 +00:00
name = user;
2018-08-12 15:31:43 +00:00
try {
2018-08-22 12:30:27 +00:00
db.beginTransaction();
boolean update = (account != null);
if (account == null)
account = new EntityAccount();
2018-10-07 06:53:09 +00:00
2018-08-22 12:30:27 +00:00
account.host = host;
2018-10-23 07:52:20 +00:00
account.starttls = starttls;
account.insecure = insecure;
2018-08-22 12:30:27 +00:00
account.port = Integer.parseInt(port);
account.user = user;
account.password = password;
2018-08-27 14:31:45 +00:00
account.auth_type = auth_type;
2018-10-07 06:53:09 +00:00
account.name = name;
account.color = color;
2018-08-22 12:30:27 +00:00
account.synchronize = synchronize;
account.primary = (account.synchronize && primary);
2018-09-21 17:19:02 +00:00
account.poll_interval = Integer.parseInt(interval);
2018-08-22 12:30:27 +00:00
account.created = new Date().getTime();
2018-10-07 06:53:09 +00:00
2018-08-22 12:30:27 +00:00
if (!synchronize)
account.error = null;
if (account.primary)
db.account().resetPrimary();
if (update)
db.account().updateAccount(account);
else
account.id = db.account().insertAccount(account);
List<EntityFolder> folders = new ArrayList<>();
EntityFolder inbox = new EntityFolder();
inbox.name = "INBOX";
inbox.type = EntityFolder.INBOX;
inbox.synchronize = true;
inbox.unified = true;
2018-11-14 10:49:59 +01:00
inbox.sync_days = EntityFolder.DEFAULT_INBOX_SYNC;
inbox.keep_days = inbox.sync_days;
2018-08-22 12:30:27 +00:00
folders.add(inbox);
if (drafts != null) {
drafts.type = EntityFolder.DRAFTS;
folders.add(drafts);
}
2018-08-22 12:30:27 +00:00
if (sent != null) {
sent.type = EntityFolder.SENT;
folders.add(sent);
}
if (all != null) {
all.type = EntityFolder.ARCHIVE;
folders.add(all);
}
if (trash != null) {
trash.type = EntityFolder.TRASH;
folders.add(trash);
}
if (junk != null) {
junk.type = EntityFolder.JUNK;
folders.add(junk);
}
db.folder().setFoldersUser(account.id);
2018-08-22 12:30:27 +00:00
for (EntityFolder folder : folders) {
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
if (existing == null) {
folder.account = account.id;
Log.i(Helper.TAG, "Creating folder=" + folder.name + " (" + folder.type + ")");
folder.id = db.folder().insertFolder(folder);
} else
db.folder().setFolderType(existing.id, folder.type);
}
2018-08-22 12:30:27 +00:00
db.setTransactionSuccessful();
} finally {
2018-08-22 12:30:27 +00:00
db.endTransaction();
}
2018-08-22 12:30:27 +00:00
if (reload)
2018-11-10 17:58:09 +00:00
ServiceSynchronize.reload(getContext(), "save account");
2018-08-22 12:30:27 +00:00
return null;
}
@Override
protected void onLoaded(Bundle args, Void data) {
getFragmentManager().popBackStack();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.setViewsEnabled(view, true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
btnSave.setEnabled(true);
pbSave.setVisibility(View.GONE);
2018-09-20 16:47:28 +00:00
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(Helper.formatThrowable(ex))
2018-09-15 05:49:54 +00:00
.setPositiveButton(android.R.string.cancel, null)
.create()
.show();
}
}.load(FragmentAccount.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) {
2018-09-20 16:47:28 +00:00
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
2018-08-07 19:35:21 +00:00
.setMessage(R.string.title_account_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
btnSave.setEnabled(false);
pbWait.setVisibility(View.VISIBLE);
2018-08-11 18:16:35 +00:00
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");
2018-11-13 10:27:25 +01:00
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id);
db.account().deleteAccount(id);
if (account.synchronize)
ServiceSynchronize.reload(getContext(), "delete account");
2018-08-22 12:30:27 +00:00
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(FragmentAccount.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
}
});
2018-11-11 14:09:46 +00:00
adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>());
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
2018-09-21 17:36:19 +00:00
spDrafts.setAdapter(adapter);
spSent.setAdapter(adapter);
spAll.setAdapter(adapter);
spTrash.setAdapter(adapter);
spJunk.setAdapter(adapter);
// Initialize
Helper.setViewsEnabled(view, false);
2018-08-27 14:31:45 +00:00
btnAuthorize.setVisibility(View.GONE);
2018-10-23 07:52:20 +00:00
cbStartTls.setVisibility(View.GONE);
cbInsecure.setVisibility(View.GONE);
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
2018-09-05 18:37:20 +00:00
btnAdvanced.setVisibility(View.GONE);
2018-09-22 10:29:35 +00:00
tvIdle.setVisibility(View.GONE);
2018-09-05 18:37:20 +00:00
btnCheck.setVisibility(View.GONE);
pbCheck.setVisibility(View.GONE);
2018-09-05 18:37:20 +00:00
2018-08-10 09:45:36 +00:00
btnSave.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
2018-09-05 18:37:20 +00:00
ibDelete.setVisibility(View.GONE);
2018-09-05 18:37:20 +00:00
grpServer.setVisibility(View.GONE);
grpAuthorize.setVisibility(View.GONE);
grpAdvanced.setVisibility(View.GONE);
grpFolders.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("provider", spProvider.getSelectedItemPosition());
2018-08-29 06:37:22 +00:00
outState.putString("authorized", authorized);
2018-08-15 09:50:39 +00:00
outState.putString("password", tilPassword.getEditText().getText().toString());
2018-09-05 18:37:20 +00:00
outState.putInt("advanced", grpAdvanced.getVisibility());
2018-09-12 17:27:50 +00:00
outState.putInt("color", color);
2018-08-15 09:50:39 +00:00
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
2018-11-14 17:21:53 +01:00
Bundle args = new Bundle();
args.putLong("id", id);
2018-11-14 17:21:53 +01:00
new SimpleTask<EntityAccount>() {
2018-08-02 13:33:06 +00:00
@Override
2018-11-14 17:21:53 +01:00
protected EntityAccount onLoad(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
return DB.getInstance(context).account().getAccount(id);
}
2018-09-05 20:39:47 +00:00
2018-11-14 17:21:53 +01:00
@Override
protected void onLoaded(Bundle args, EntityAccount account) {
2018-08-15 09:50:39 +00:00
// Get providers
List<Provider> providers = Provider.loadProfiles(getContext());
2018-09-05 18:37:20 +00:00
providers.add(0, new Provider(getString(R.string.title_select)));
providers.add(1, new Provider(getString(R.string.title_custom)));
2018-08-15 09:50:39 +00:00
2018-11-11 14:09:46 +00:00
ArrayAdapter<Provider> aaProvider =
new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, providers);
aaProvider.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spProvider.setAdapter(aaProvider);
2018-08-15 09:50:39 +00:00
if (savedInstanceState == null) {
2018-08-27 15:08:23 +00:00
if (account != null) {
2018-09-07 10:45:43 +00:00
boolean found = false;
2018-09-06 07:29:30 +00:00
for (int pos = 2; pos < providers.size(); pos++) {
Provider provider = providers.get(pos);
if (provider.imap_host.equals(account.host) &&
provider.imap_port == account.port) {
2018-09-07 10:45:43 +00:00
found = true;
2018-08-27 15:08:23 +00:00
spProvider.setTag(pos);
spProvider.setSelection(pos);
break;
}
2018-09-06 07:29:30 +00:00
}
2018-09-07 10:45:43 +00:00
if (!found) {
spProvider.setTag(1);
spProvider.setSelection(1);
}
2018-09-05 18:37:20 +00:00
etHost.setText(account.host);
etPort.setText(Long.toString(account.port));
2018-08-27 15:08:23 +00:00
}
2018-08-29 06:37:22 +00:00
authorized = (account != null && account.auth_type != Helper.AUTH_TYPE_PASSWORD ? account.password : null);
2018-08-16 11:26:53 +00:00
etUser.setText(account == null ? null : account.user);
tilPassword.getEditText().setText(account == null ? null : account.password);
2018-08-27 15:08:23 +00:00
2018-09-05 18:37:20 +00:00
etName.setText(account == null ? null : account.name);
2018-08-16 11:26:53 +00:00
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? true : account.primary);
2018-10-23 15:47:29 +00:00
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
2018-09-12 16:54:48 +00:00
color = (account == null || account.color == null ? Color.TRANSPARENT : account.color);
if (account == null)
new SimpleTask<Integer>() {
@Override
protected Integer onLoad(Context context, Bundle args) {
return DB.getInstance(context).account().getSynchronizingAccountCount();
}
@Override
protected void onLoaded(Bundle args, Integer count) {
cbPrimary.setChecked(count == 0);
}
}.load(FragmentAccount.this, new Bundle());
2018-08-15 09:50:39 +00:00
} else {
int provider = savedInstanceState.getInt("provider");
spProvider.setTag(provider);
spProvider.setSelection(provider);
2018-08-27 15:08:23 +00:00
2018-08-29 06:37:22 +00:00
authorized = savedInstanceState.getString("authorized");
2018-08-15 09:50:39 +00:00
tilPassword.getEditText().setText(savedInstanceState.getString("password"));
2018-09-05 18:37:20 +00:00
grpAdvanced.setVisibility(savedInstanceState.getInt("advanced"));
2018-09-12 17:27:50 +00:00
color = savedInstanceState.getInt("color");
2018-08-15 09:50:39 +00:00
}
Helper.setViewsEnabled(view, true);
setColor(color);
cbPrimary.setEnabled(cbSynchronize.isChecked());
2018-08-16 11:26:53 +00:00
// Consider previous check/save/delete as cancelled
ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE);
pbWait.setVisibility(View.GONE);
2018-11-14 17:21:53 +01:00
args.putLong("account", account == null ? -1 : account.id);
new SimpleTask<List<EntityFolder>>() {
@Override
2018-11-16 09:06:10 +01:00
protected List<EntityFolder> onLoad(Context context, Bundle args) {
2018-11-14 17:21:53 +01:00
long account = args.getLong("account");
return DB.getInstance(context).folder().getFolders(account);
}
@Override
protected void onLoaded(Bundle args, List<EntityFolder> folders) {
if (folders == null)
folders = new ArrayList<>();
setFolders(folders);
}
}.load(FragmentAccount.this, args);
2018-08-02 13:33:06 +00:00
}
2018-11-14 17:21:53 +01:00
}.load(this, args);
2018-08-02 13:33:06 +00:00
}
2018-08-27 14:31:45 +00:00
2018-08-29 06:37:22 +00:00
private void selectAccount() {
2018-08-27 14:31:45 +00:00
Log.i(Helper.TAG, "Select account");
Provider provider = (Provider) spProvider.getSelectedItem();
if (provider.type != null)
startActivityForResult(newChooseAccountIntent(
null,
null,
new String[]{provider.type},
null,
null,
null,
null), ActivitySetup.REQUEST_CHOOSE_ACCOUNT);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == ActivitySetup.REQUEST_PERMISSION)
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
selectAccount();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK)
if (requestCode == ActivitySetup.REQUEST_CHOOSE_ACCOUNT) {
String name = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
String type = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
AccountManager am = AccountManager.get(getContext());
Account[] accounts = am.getAccountsByType(type);
Log.i(Helper.TAG, "Accounts=" + accounts.length);
for (final Account account : accounts)
if (name.equals(account.name)) {
2018-09-05 12:37:27 +00:00
final Snackbar snackbar = Snackbar.make(view, R.string.title_authorizing, Snackbar.LENGTH_SHORT);
snackbar.show();
2018-08-27 14:31:45 +00:00
am.getAuthToken(
account,
2018-08-27 16:19:56 +00:00
Helper.getAuthTokenType(type),
2018-08-27 14:31:45 +00:00
new Bundle(),
getActivity(),
new AccountManagerCallback<Bundle>() {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Bundle bundle = future.getResult();
String token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
Log.i(Helper.TAG, "Got token");
2018-08-29 06:37:22 +00:00
authorized = token;
2018-08-27 14:31:45 +00:00
etUser.setText(account.name);
tilPassword.getEditText().setText(token);
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
2018-10-07 12:21:55 +00:00
snackbar.setText(Helper.formatThrowable(ex));
2018-09-05 12:37:27 +00:00
} finally {
snackbar.dismiss();
2018-08-27 14:31:45 +00:00
}
}
},
null);
break;
}
}
}
2018-09-12 16:54:48 +00:00
private void setColor(int color) {
FragmentAccount.this.color = color;
GradientDrawable border = new GradientDrawable();
border.setColor(color);
border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator));
vwColor.setBackground(border);
}
private void setFolders(List<EntityFolder> folders) {
2018-11-15 08:20:48 +01:00
EntityFolder.sort(folders);
EntityFolder none = new EntityFolder();
none.name = "";
folders.add(0, none);
2018-09-21 17:36:19 +00:00
adapter.clear();
adapter.addAll(folders);
for (int pos = 0; pos < folders.size(); pos++) {
if (EntityFolder.DRAFTS.equals(folders.get(pos).type))
spDrafts.setSelection(pos);
else if (EntityFolder.SENT.equals(folders.get(pos).type))
spSent.setSelection(pos);
else if (EntityFolder.ARCHIVE.equals(folders.get(pos).type))
spAll.setSelection(pos);
else if (EntityFolder.TRASH.equals(folders.get(pos).type))
spTrash.setSelection(pos);
else if (EntityFolder.JUNK.equals(folders.get(pos).type))
spJunk.setSelection(pos);
}
grpFolders.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.VISIBLE);
}
2018-09-22 10:29:35 +00:00
private class CheckResult {
List<EntityFolder> folders;
boolean idle;
}
2018-08-02 13:33:06 +00:00
}