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
|
|
|
|
2018-12-31 08:04:33 +00:00
|
|
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
2018-08-02 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
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;
|
2019-01-04 17:13:14 +00:00
|
|
|
import android.accounts.AuthenticatorException;
|
2019-01-04 14:08:38 +00:00
|
|
|
import android.accounts.OperationCanceledException;
|
2018-08-27 14:31:45 +00:00
|
|
|
import android.app.Activity;
|
2018-11-19 17:10:55 +00:00
|
|
|
import android.app.NotificationManager;
|
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;
|
|
|
|
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;
|
2018-08-10 13:32:07 +00:00
|
|
|
import android.os.Handler;
|
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.view.LayoutInflater;
|
2018-12-06 08:51:27 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2018-08-02 13:33:06 +00:00
|
|
|
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-09-12 16:54:48 +00:00
|
|
|
import android.widget.ImageView;
|
2019-03-13 07:17:24 +00:00
|
|
|
import android.widget.RadioGroup;
|
2018-08-10 13:32:07 +00:00
|
|
|
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
|
|
|
|
2019-04-17 18:21:44 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
import androidx.constraintlayout.widget.Group;
|
|
|
|
import androidx.fragment.app.FragmentTransaction;
|
|
|
|
|
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;
|
2019-02-20 16:07:17 +00:00
|
|
|
import com.sun.mail.imap.protocol.IMAPProtocol;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-01-04 17:13:14 +00:00
|
|
|
import java.io.IOException;
|
2018-12-30 09:55:14 +00:00
|
|
|
import java.net.UnknownHostException;
|
2018-08-02 13:33:06 +00:00
|
|
|
import java.util.ArrayList;
|
2018-11-06 16:45:52 +00:00
|
|
|
import java.util.Date;
|
2018-08-02 13:33:06 +00:00
|
|
|
import java.util.List;
|
2019-02-26 10:05:21 +00:00
|
|
|
import java.util.Objects;
|
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.Session;
|
2019-02-09 21:03:53 +00:00
|
|
|
import javax.mail.Store;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-27 14:31:45 +00:00
|
|
|
import static android.accounts.AccountManager.newChooseAccountIntent;
|
|
|
|
|
2019-01-15 17:41:55 +00:00
|
|
|
public class FragmentAccount extends FragmentBase {
|
2018-08-10 11:05:38 +00:00
|
|
|
private ViewGroup view;
|
2019-04-22 18:43:04 +00:00
|
|
|
private ScrollView scroll;
|
2018-09-21 05:36:01 +00:00
|
|
|
|
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
|
|
|
|
2018-12-26 11:34:05 +00:00
|
|
|
private Button btnAuthorize;
|
2019-04-21 06:01:06 +00:00
|
|
|
private TextView tvAuthorizeOptional;
|
2018-10-23 07:52:20 +00:00
|
|
|
private EditText etHost;
|
2019-03-13 07:17:24 +00:00
|
|
|
private RadioGroup rgEncryption;
|
2018-10-23 07:52:20 +00:00
|
|
|
private CheckBox cbInsecure;
|
2018-08-02 13:33:06 +00:00
|
|
|
private EditText etPort;
|
|
|
|
private EditText etUser;
|
2018-08-03 10:56:11 +00:00
|
|
|
private TextInputLayout tilPassword;
|
2019-01-10 18:24:20 +00:00
|
|
|
private EditText etRealm;
|
2018-09-21 05:36:01 +00:00
|
|
|
|
2018-09-05 18:37:20 +00:00
|
|
|
private EditText etName;
|
2018-09-21 05:36:01 +00:00
|
|
|
private Button btnColor;
|
|
|
|
private View vwColor;
|
|
|
|
private ImageView ibColorDefault;
|
2018-10-07 06:53:09 +00:00
|
|
|
|
2018-12-26 11:34:05 +00:00
|
|
|
private Button btnAdvanced;
|
2018-08-02 13:33:06 +00:00
|
|
|
private CheckBox cbSynchronize;
|
2018-08-06 10:02:47 +00:00
|
|
|
private CheckBox cbPrimary;
|
2018-12-26 11:34:05 +00:00
|
|
|
private CheckBox cbNotify;
|
2018-12-23 18:20:08 +00:00
|
|
|
private CheckBox cbBrowse;
|
2018-09-21 17:19:02 +00:00
|
|
|
private EditText etInterval;
|
2018-12-26 11:34:05 +00:00
|
|
|
private EditText etPrefix;
|
2018-09-21 05:36:01 +00:00
|
|
|
|
2018-10-07 06:53:09 +00:00
|
|
|
private Button btnCheck;
|
2018-12-27 12:31:02 +00:00
|
|
|
private ContentLoadingProgressBar pbCheck;
|
2018-09-22 10:29:35 +00:00
|
|
|
private TextView tvIdle;
|
2019-02-20 16:07:17 +00:00
|
|
|
private TextView tvUtf8;
|
2018-09-22 10:29:35 +00:00
|
|
|
|
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;
|
2019-01-20 15:22:21 +00:00
|
|
|
private Spinner spLeft;
|
|
|
|
private Spinner spRight;
|
2018-09-21 05:36:01 +00:00
|
|
|
|
2018-08-10 09:45:36 +00:00
|
|
|
private Button btnSave;
|
2018-12-27 12:31:02 +00:00
|
|
|
private ContentLoadingProgressBar pbSave;
|
2018-12-30 12:35:34 +00:00
|
|
|
private TextView tvError;
|
|
|
|
|
2018-12-27 12:31:02 +00:00
|
|
|
private ContentLoadingProgressBar pbWait;
|
2018-09-21 05:36:01 +00:00
|
|
|
|
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;
|
2019-01-29 09:02:34 +00:00
|
|
|
private boolean saving = false;
|
2019-01-26 11:18:59 +00:00
|
|
|
private int auth_type = Helper.AUTH_TYPE_PASSWORD;
|
2018-09-12 16:54:48 +00:00
|
|
|
private int color = Color.TRANSPARENT;
|
2018-08-27 14:31:45 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
// Get arguments
|
|
|
|
Bundle args = getArguments();
|
2018-12-04 10:40:15 +00:00
|
|
|
id = args.getLong("id", -1);
|
2018-08-27 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2019-02-21 20:17:09 +00:00
|
|
|
setSubtitle(R.string.title_edit_account);
|
2019-03-20 09:47:03 +00:00
|
|
|
setHasOptionsMenu(true);
|
2019-02-21 20:17:09 +00:00
|
|
|
|
2018-08-10 11:05:38 +00:00
|
|
|
view = (ViewGroup) inflater.inflate(R.layout.fragment_account, container, false);
|
2019-04-22 18:43:04 +00:00
|
|
|
scroll = view.findViewById(R.id.scroll);
|
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-12-26 11:34:05 +00:00
|
|
|
btnAuthorize = view.findViewById(R.id.btnAuthorize);
|
2019-04-21 06:01:06 +00:00
|
|
|
tvAuthorizeOptional = view.findViewById(R.id.tvAuthorizeOptional);
|
2018-08-02 13:33:06 +00:00
|
|
|
etHost = view.findViewById(R.id.etHost);
|
|
|
|
etPort = view.findViewById(R.id.etPort);
|
2019-03-13 07:17:24 +00:00
|
|
|
rgEncryption = view.findViewById(R.id.rgEncryption);
|
2018-10-23 07:52:20 +00:00
|
|
|
cbInsecure = view.findViewById(R.id.cbInsecure);
|
2018-08-02 13:33:06 +00:00
|
|
|
etUser = view.findViewById(R.id.etUser);
|
2018-08-03 10:56:11 +00:00
|
|
|
tilPassword = view.findViewById(R.id.tilPassword);
|
2019-01-10 18:24:20 +00:00
|
|
|
etRealm = view.findViewById(R.id.etRealm);
|
2018-09-05 18:37:20 +00:00
|
|
|
|
|
|
|
etName = view.findViewById(R.id.etName);
|
2018-09-21 05:36:01 +00:00
|
|
|
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-12-26 11:34:05 +00:00
|
|
|
btnAdvanced = view.findViewById(R.id.btnAdvanced);
|
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-12-26 11:34:05 +00:00
|
|
|
cbNotify = view.findViewById(R.id.cbNotify);
|
2018-12-23 18:20:08 +00:00
|
|
|
cbBrowse = view.findViewById(R.id.cbBrowse);
|
2018-09-21 17:19:02 +00:00
|
|
|
etInterval = view.findViewById(R.id.etInterval);
|
2018-12-26 11:34:05 +00:00
|
|
|
etPrefix = view.findViewById(R.id.etPrefix);
|
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);
|
2019-02-20 16:07:17 +00:00
|
|
|
tvUtf8 = view.findViewById(R.id.tvUtf8);
|
2018-09-22 10:29:35 +00:00
|
|
|
|
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);
|
2019-01-20 15:22:21 +00:00
|
|
|
spLeft = view.findViewById(R.id.spLeft);
|
|
|
|
spRight = view.findViewById(R.id.spRight);
|
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-12-30 12:35:34 +00:00
|
|
|
tvError = view.findViewById(R.id.tvError);
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2018-08-10 11:05:38 +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-12-04 10:40:15 +00:00
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long itemid) {
|
2019-01-13 15:23:04 +00:00
|
|
|
EmailProvider provider = (EmailProvider) adapterView.getSelectedItem();
|
2018-09-05 18:37:20 +00:00
|
|
|
grpServer.setVisibility(position == 1 ? View.VISIBLE : View.GONE);
|
|
|
|
grpAuthorize.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
|
2018-08-28 06:32:07 +00:00
|
|
|
|
|
|
|
btnAuthorize.setVisibility(provider.type == null ? View.GONE : View.VISIBLE);
|
2019-04-21 06:01:06 +00:00
|
|
|
tvAuthorizeOptional.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);
|
2019-02-21 19:31:28 +00:00
|
|
|
tvUtf8.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
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
auth_type = Helper.AUTH_TYPE_PASSWORD;
|
|
|
|
|
2018-08-28 06:32:07 +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));
|
2019-03-13 07:17:24 +00:00
|
|
|
rgEncryption.check(provider.imap_starttls ? R.id.radio_starttls : R.id.radio_ssl);
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
etUser.setTag(null);
|
2018-09-05 18:37:20 +00:00
|
|
|
etUser.setText(null);
|
|
|
|
tilPassword.getEditText().setText(null);
|
2019-01-10 18:24:20 +00:00
|
|
|
etRealm.setText(null);
|
2019-01-26 11:18:59 +00:00
|
|
|
tilPassword.setEnabled(true);
|
|
|
|
etRealm.setEnabled(true);
|
2018-08-27 15:08:23 +00:00
|
|
|
|
2018-09-05 18:37:20 +00:00
|
|
|
etName.setText(position > 1 ? provider.name : null);
|
2018-12-23 09:52:39 +00:00
|
|
|
etPrefix.setText(provider.prefix);
|
2018-11-16 08:06:10 +00:00
|
|
|
|
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
btnSave.setVisibility(View.GONE);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-12-26 11:34:05 +00:00
|
|
|
etDomain.addTextChangedListener(new TextWatcher() {
|
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence text, int start, int before, int count) {
|
|
|
|
btnAutoConfig.setEnabled(text.length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-09-18 14:22:10 +00:00
|
|
|
btnAutoConfig.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-01-17 09:57:01 +00:00
|
|
|
onAutoConfig();
|
2018-09-18 14:22:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-13 07:17:24 +00:00
|
|
|
rgEncryption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
|
2018-10-23 07:52:20 +00:00
|
|
|
@Override
|
2019-03-13 07:17:24 +00:00
|
|
|
public void onCheckedChanged(RadioGroup group, int id) {
|
|
|
|
etPort.setHint(id == R.id.radio_starttls ? "143" : "993");
|
2018-10-23 07:52:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
etUser.addTextChangedListener(new TextWatcher() {
|
2018-08-29 06:37:22 +00:00
|
|
|
@Override
|
|
|
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
2019-01-26 11:18:59 +00:00
|
|
|
String user = etUser.getText().toString();
|
|
|
|
if (auth_type != Helper.AUTH_TYPE_PASSWORD && !user.equals(etUser.getTag())) {
|
|
|
|
auth_type = Helper.AUTH_TYPE_PASSWORD;
|
|
|
|
tilPassword.getEditText().setText(null);
|
|
|
|
tilPassword.setEnabled(true);
|
2019-02-18 11:39:43 +00:00
|
|
|
tilPassword.setPasswordVisibilityToggleEnabled(true);
|
2019-01-26 11:18:59 +00:00
|
|
|
etRealm.setEnabled(true);
|
|
|
|
}
|
2018-08-29 06:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-12-26 11:34:05 +00:00
|
|
|
vwColor.setBackgroundColor(color);
|
|
|
|
btnColor.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (Helper.isPro(getContext())) {
|
|
|
|
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();
|
2019-02-14 19:42:17 +00:00
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
|
2018-12-26 11:34:05 +00:00
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
ibColorDefault.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
setColor(Color.TRANSPARENT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-08-27 14:31:45 +00:00
|
|
|
btnAuthorize.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-01-13 15:23:04 +00:00
|
|
|
EmailProvider provider = (EmailProvider) spProvider.getSelectedItem();
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Authorize " + provider);
|
2018-11-10 14:59:31 +00:00
|
|
|
|
|
|
|
if ("com.google".equals(provider.type)) {
|
|
|
|
String permission = Manifest.permission.GET_ACCOUNTS;
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O &&
|
2019-02-07 09:02:40 +00:00
|
|
|
!Helper.hasPermission(getContext(), permission)) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Requesting " + permission);
|
2018-11-10 14:59:31 +00:00
|
|
|
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() {
|
2019-04-22 18:43:04 +00:00
|
|
|
scroll.smoothScrollTo(0, btnAdvanced.getTop());
|
2018-09-12 19:19:42 +00:00
|
|
|
}
|
|
|
|
});
|
2018-09-12 16:54:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-12-26 11:34:05 +00:00
|
|
|
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-09-12 16:54:48 +00:00
|
|
|
@Override
|
2018-12-26 11:34:05 +00:00
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
cbPrimary.setEnabled(checked);
|
2018-09-12 16:54:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-24 09:32:21 +00:00
|
|
|
cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
if (isChecked && !Helper.isPro(getContext())) {
|
|
|
|
cbNotify.setChecked(false);
|
|
|
|
|
|
|
|
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
2019-02-14 19:42:17 +00:00
|
|
|
fragmentTransaction.replace(R.id.content_frame, new FragmentPro()).addToBackStack("pro");
|
2018-11-24 09:32:21 +00:00
|
|
|
fragmentTransaction.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2019-04-10 18:33:51 +00:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
|
|
ConstraintLayout.LayoutParams lparam = (ConstraintLayout.LayoutParams) cbNotify.getLayoutParams();
|
|
|
|
lparam.width = 0;
|
|
|
|
lparam.height = 0;
|
|
|
|
lparam.setMargins(0, 0, 0, 0);
|
|
|
|
cbNotify.setLayoutParams(lparam);
|
|
|
|
}
|
2018-11-24 09:32:21 +00:00
|
|
|
|
2018-08-10 09:45:36 +00:00
|
|
|
btnCheck.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2019-01-17 09:57:01 +00:00
|
|
|
onCheck();
|
|
|
|
}
|
|
|
|
});
|
2018-08-28 06:32:07 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
btnSave.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
onSave();
|
|
|
|
}
|
|
|
|
});
|
2018-12-30 12:35:34 +00:00
|
|
|
|
2019-01-17 09:57:01 +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-12-30 12:35:34 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
spDrafts.setAdapter(adapter);
|
|
|
|
spSent.setAdapter(adapter);
|
|
|
|
spAll.setAdapter(adapter);
|
|
|
|
spTrash.setAdapter(adapter);
|
|
|
|
spJunk.setAdapter(adapter);
|
2019-01-20 15:22:21 +00:00
|
|
|
spLeft.setAdapter(adapter);
|
|
|
|
spRight.setAdapter(adapter);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
// Initialize
|
|
|
|
Helper.setViewsEnabled(view, false);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
btnAutoConfig.setEnabled(false);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
btnAuthorize.setVisibility(View.GONE);
|
2019-04-21 06:01:06 +00:00
|
|
|
tvAuthorizeOptional.setVisibility(View.GONE);
|
2019-03-13 07:17:24 +00:00
|
|
|
rgEncryption.setVisibility(View.GONE);
|
2019-01-17 09:57:01 +00:00
|
|
|
cbInsecure.setVisibility(View.GONE);
|
|
|
|
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
btnAdvanced.setVisibility(View.GONE);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
tvIdle.setVisibility(View.GONE);
|
2019-02-21 19:31:28 +00:00
|
|
|
tvUtf8.setVisibility(View.GONE);
|
2018-09-22 10:29:35 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
btnCheck.setVisibility(View.GONE);
|
|
|
|
pbCheck.setVisibility(View.GONE);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
btnSave.setVisibility(View.GONE);
|
|
|
|
pbSave.setVisibility(View.GONE);
|
|
|
|
tvError.setVisibility(View.GONE);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
grpServer.setVisibility(View.GONE);
|
|
|
|
grpAuthorize.setVisibility(View.GONE);
|
|
|
|
grpAdvanced.setVisibility(View.GONE);
|
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onAutoConfig() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putString("domain", etDomain.getText().toString());
|
|
|
|
|
|
|
|
new SimpleTask<EmailProvider>() {
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute(Bundle args) {
|
|
|
|
etDomain.setEnabled(false);
|
|
|
|
btnAutoConfig.setEnabled(false);
|
2018-08-10 09:45:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
2019-01-17 09:57:01 +00:00
|
|
|
protected void onPostExecute(Bundle args) {
|
|
|
|
etDomain.setEnabled(true);
|
|
|
|
btnAutoConfig.setEnabled(true);
|
|
|
|
}
|
2018-08-28 06:32:07 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected EmailProvider onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
String domain = args.getString("domain");
|
|
|
|
return EmailProvider.fromDomain(context, domain);
|
|
|
|
}
|
2018-12-30 12:35:34 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, EmailProvider provider) {
|
|
|
|
etHost.setText(provider.imap_host);
|
|
|
|
etPort.setText(Integer.toString(provider.imap_port));
|
2019-03-13 07:17:24 +00:00
|
|
|
rgEncryption.check(provider.imap_starttls ? R.id.radio_starttls : R.id.radio_ssl);
|
2019-01-17 09:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
if (ex instanceof IllegalArgumentException || ex instanceof UnknownHostException)
|
|
|
|
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
|
|
|
else
|
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
|
|
|
}
|
|
|
|
}.execute(FragmentAccount.this, args, "account:config");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onCheck() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", id);
|
2019-01-26 11:18:59 +00:00
|
|
|
args.putInt("auth_type", auth_type);
|
2019-01-17 09:57:01 +00:00
|
|
|
args.putString("host", etHost.getText().toString());
|
2019-03-13 07:17:24 +00:00
|
|
|
args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls);
|
2019-01-17 09:57:01 +00:00
|
|
|
args.putBoolean("insecure", cbInsecure.isChecked());
|
|
|
|
args.putString("port", etPort.getText().toString());
|
|
|
|
args.putString("user", etUser.getText().toString());
|
|
|
|
args.putString("password", tilPassword.getEditText().getText().toString());
|
|
|
|
args.putString("realm", etRealm.getText().toString());
|
|
|
|
|
|
|
|
new SimpleTask<CheckResult>() {
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute(Bundle args) {
|
2019-01-29 09:02:34 +00:00
|
|
|
saving = true;
|
|
|
|
getActivity().invalidateOptionsMenu();
|
2019-01-17 09:57:01 +00:00
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
pbCheck.setVisibility(View.VISIBLE);
|
|
|
|
tvIdle.setVisibility(View.GONE);
|
2019-02-20 16:07:17 +00:00
|
|
|
tvUtf8.setVisibility(View.GONE);
|
2019-01-17 09:57:01 +00:00
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
tvError.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Bundle args) {
|
2019-01-29 09:02:34 +00:00
|
|
|
saving = false;
|
|
|
|
getActivity().invalidateOptionsMenu();
|
2019-01-17 09:57:01 +00:00
|
|
|
Helper.setViewsEnabled(view, true);
|
|
|
|
pbCheck.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected CheckResult onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
long id = args.getLong("id");
|
2019-01-26 11:18:59 +00:00
|
|
|
int auth_type = args.getInt("auth_type");
|
2019-01-17 09:57:01 +00:00
|
|
|
String host = args.getString("host");
|
|
|
|
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");
|
|
|
|
String realm = args.getString("realm");
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(host))
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
|
|
|
|
if (TextUtils.isEmpty(port))
|
2019-02-11 21:46:12 +00:00
|
|
|
port = (starttls ? "143" : "993");
|
2019-01-17 09:57:01 +00:00
|
|
|
if (TextUtils.isEmpty(user))
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
|
|
|
if (TextUtils.isEmpty(password) && !insecure)
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(realm))
|
|
|
|
realm = null;
|
|
|
|
|
2019-01-20 15:22:21 +00:00
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
CheckResult result = new CheckResult();
|
2019-01-20 15:22:21 +00:00
|
|
|
result.account = db.account().getAccount(id);
|
2019-01-17 09:57:01 +00:00
|
|
|
result.folders = new ArrayList<>();
|
|
|
|
|
|
|
|
// Check IMAP server / get folders
|
|
|
|
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
|
|
|
|
Session isession = Session.getInstance(props, null);
|
|
|
|
isession.setDebug(true);
|
2019-02-22 15:59:23 +00:00
|
|
|
try (Store istore = isession.getStore("imap" + (starttls ? "" : "s"))) {
|
2019-01-17 09:57:01 +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-12-30 12:35:34 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 21:46:12 +00:00
|
|
|
result.idle = ((IMAPStore) istore).hasCapability("IDLE");
|
2019-01-17 09:57:01 +00:00
|
|
|
|
2019-02-02 07:28:14 +00:00
|
|
|
boolean inbox = false;
|
2019-01-17 09:57:01 +00:00
|
|
|
boolean archive = false;
|
|
|
|
boolean drafts = false;
|
|
|
|
boolean trash = false;
|
|
|
|
boolean sent = false;
|
|
|
|
boolean junk = false;
|
|
|
|
EntityFolder altArchive = null;
|
|
|
|
EntityFolder altDrafts = null;
|
|
|
|
EntityFolder altTrash = null;
|
|
|
|
EntityFolder altSent = null;
|
|
|
|
EntityFolder altJunk = null;
|
|
|
|
|
|
|
|
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
|
|
|
|
// Check folder attributes
|
2019-02-01 21:06:14 +00:00
|
|
|
String fullName = ifolder.getFullName();
|
2019-02-10 16:33:31 +00:00
|
|
|
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
2019-02-01 21:06:14 +00:00
|
|
|
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
|
|
|
|
String type = EntityFolder.getType(attrs, fullName);
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-02-01 21:06:14 +00:00
|
|
|
if (type != null) {
|
2019-01-17 09:57:01 +00:00
|
|
|
// Create entry
|
2019-02-01 21:06:14 +00:00
|
|
|
EntityFolder folder = db.folder().getFolderByName(id, fullName);
|
2019-01-17 09:57:01 +00:00
|
|
|
if (folder == null) {
|
|
|
|
int sync = EntityFolder.SYSTEM_FOLDER_SYNC.indexOf(type);
|
|
|
|
folder = new EntityFolder();
|
2019-02-01 21:06:14 +00:00
|
|
|
folder.name = fullName;
|
|
|
|
folder.type = type;
|
2019-01-17 09:57:01 +00:00
|
|
|
folder.synchronize = (sync >= 0);
|
|
|
|
folder.download = (sync < 0 ? true : EntityFolder.SYSTEM_FOLDER_DOWNLOAD.get(sync));
|
|
|
|
folder.sync_days = EntityFolder.DEFAULT_SYNC;
|
|
|
|
folder.keep_days = EntityFolder.DEFAULT_KEEP;
|
|
|
|
}
|
|
|
|
result.folders.add(folder);
|
|
|
|
|
2019-02-01 21:06:14 +00:00
|
|
|
if (EntityFolder.USER.equals(type)) {
|
2019-01-17 09:57:01 +00:00
|
|
|
if (folder.name.toLowerCase().contains("archive"))
|
|
|
|
altArchive = folder;
|
|
|
|
if (folder.name.toLowerCase().contains("draft"))
|
|
|
|
altDrafts = folder;
|
|
|
|
if (folder.name.toLowerCase().contains("trash"))
|
|
|
|
altTrash = folder;
|
|
|
|
if (folder.name.toLowerCase().contains("sent"))
|
|
|
|
altSent = folder;
|
|
|
|
if (folder.name.toLowerCase().contains("junk"))
|
|
|
|
altJunk = folder;
|
|
|
|
} else {
|
2019-02-02 07:28:14 +00:00
|
|
|
if (EntityFolder.INBOX.equals(type))
|
|
|
|
inbox = true;
|
|
|
|
else if (EntityFolder.ARCHIVE.equals(type))
|
2019-01-17 09:57:01 +00:00
|
|
|
archive = true;
|
|
|
|
else if (EntityFolder.DRAFTS.equals(type))
|
|
|
|
drafts = true;
|
|
|
|
else if (EntityFolder.TRASH.equals(type))
|
|
|
|
trash = true;
|
|
|
|
else if (EntityFolder.SENT.equals(type))
|
|
|
|
sent = true;
|
|
|
|
else if (EntityFolder.JUNK.equals(type))
|
|
|
|
junk = true;
|
|
|
|
}
|
2018-08-12 15:31:43 +00:00
|
|
|
|
2019-02-20 16:07:17 +00:00
|
|
|
if (EntityFolder.INBOX.equals(type))
|
|
|
|
result.utf8 = (Boolean) ((IMAPFolder) ifolder).doCommand(new IMAPFolder.ProtocolCommand() {
|
|
|
|
@Override
|
|
|
|
public Object doCommand(IMAPProtocol protocol) {
|
|
|
|
return protocol.supportsUtf8();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
Log.i(folder.name + " id=" + folder.id +
|
|
|
|
" type=" + folder.type + " attr=" + TextUtils.join(",", attrs));
|
|
|
|
}
|
|
|
|
}
|
2018-08-22 12:30:27 +00:00
|
|
|
|
2019-02-02 07:28:14 +00:00
|
|
|
if (!inbox)
|
2019-02-04 16:10:30 +00:00
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_inbox));
|
2019-01-17 09:57:01 +00:00
|
|
|
if (!archive && altArchive != null)
|
|
|
|
altArchive.type = EntityFolder.ARCHIVE;
|
|
|
|
if (!drafts && altDrafts != null)
|
|
|
|
altDrafts.type = EntityFolder.DRAFTS;
|
|
|
|
if (!trash && altTrash != null)
|
|
|
|
altTrash.type = EntityFolder.TRASH;
|
|
|
|
if (!sent && altSent != null)
|
|
|
|
altSent.type = EntityFolder.SENT;
|
|
|
|
if (!junk && altJunk != null)
|
|
|
|
altJunk.type = EntityFolder.JUNK;
|
|
|
|
|
2019-01-18 11:15:07 +00:00
|
|
|
for (EntityFolder folder : result.folders)
|
|
|
|
folder.display = folder.getDisplayName(getContext());
|
2019-03-04 07:48:36 +00:00
|
|
|
EntityFolder.sort(getContext(), result.folders, true);
|
2019-01-18 11:15:07 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
}
|
2018-10-07 06:53:09 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-10-07 06:53:09 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, CheckResult result) {
|
2019-02-11 21:46:12 +00:00
|
|
|
tvIdle.setVisibility(result.idle ? View.GONE : View.VISIBLE);
|
2019-02-20 16:07:17 +00:00
|
|
|
tvUtf8.setVisibility(result.utf8 == null || result.utf8 ? View.GONE : View.VISIBLE);
|
2019-02-09 21:03:53 +00:00
|
|
|
|
2019-02-11 21:46:12 +00:00
|
|
|
setFolders(result.folders, result.account);
|
2018-08-22 12:30:27 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-04-22 18:43:04 +00:00
|
|
|
scroll.smoothScrollTo(0, btnSave.getBottom());
|
2019-01-17 09:57:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-12-23 08:31:24 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
grpFolders.setVisibility(View.GONE);
|
|
|
|
btnSave.setVisibility(View.GONE);
|
2018-12-23 08:31:24 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (ex instanceof IllegalArgumentException)
|
|
|
|
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
|
|
|
else {
|
|
|
|
tvError.setText(Helper.formatThrowable(ex));
|
|
|
|
tvError.setVisibility(View.VISIBLE);
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-04-22 18:43:04 +00:00
|
|
|
scroll.smoothScrollTo(0, tvError.getBottom());
|
2019-01-17 09:57:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute(FragmentAccount.this, args, "account:check");
|
|
|
|
}
|
2018-10-07 06:53:09 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
private void onSave() {
|
|
|
|
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();
|
2019-01-20 15:22:21 +00:00
|
|
|
EntityFolder left = (EntityFolder) spLeft.getSelectedItem();
|
|
|
|
EntityFolder right = (EntityFolder) spRight.getSelectedItem();
|
2019-01-17 09:57:01 +00:00
|
|
|
|
2019-01-21 07:17:17 +00:00
|
|
|
if (drafts != null && drafts.type == null)
|
2019-01-17 09:57:01 +00:00
|
|
|
drafts = null;
|
2019-01-21 07:17:17 +00:00
|
|
|
if (sent != null && sent.type == null)
|
2019-01-17 09:57:01 +00:00
|
|
|
sent = null;
|
2019-01-21 07:17:17 +00:00
|
|
|
if (all != null && all.type == null)
|
2019-01-17 09:57:01 +00:00
|
|
|
all = null;
|
2019-01-21 07:17:17 +00:00
|
|
|
if (trash != null && trash.type == null)
|
2019-01-17 09:57:01 +00:00
|
|
|
trash = null;
|
2019-01-21 07:17:17 +00:00
|
|
|
if (junk != null && junk.type == null)
|
2019-01-17 09:57:01 +00:00
|
|
|
junk = null;
|
2019-01-21 07:17:17 +00:00
|
|
|
if (left != null && left.type == null)
|
2019-01-20 15:22:21 +00:00
|
|
|
left = null;
|
2019-01-21 07:17:17 +00:00
|
|
|
if (right != null && right.type == null)
|
2019-01-20 15:22:21 +00:00
|
|
|
right = null;
|
2019-01-17 09:57:01 +00:00
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
args.putInt("auth_type", auth_type);
|
2019-01-17 09:57:01 +00:00
|
|
|
args.putString("host", etHost.getText().toString());
|
2019-03-13 07:17:24 +00:00
|
|
|
args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls);
|
2019-01-17 09:57:01 +00:00
|
|
|
args.putBoolean("insecure", cbInsecure.isChecked());
|
|
|
|
args.putString("port", etPort.getText().toString());
|
|
|
|
args.putString("user", etUser.getText().toString());
|
|
|
|
args.putString("password", tilPassword.getEditText().getText().toString());
|
|
|
|
args.putString("realm", etRealm.getText().toString());
|
|
|
|
|
|
|
|
args.putString("name", etName.getText().toString());
|
|
|
|
args.putInt("color", color);
|
|
|
|
|
|
|
|
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
|
|
|
args.putBoolean("primary", cbPrimary.isChecked());
|
|
|
|
args.putBoolean("notify", cbNotify.isChecked());
|
|
|
|
args.putBoolean("browse", cbBrowse.isChecked());
|
|
|
|
args.putString("interval", etInterval.getText().toString());
|
|
|
|
args.putString("prefix", etPrefix.getText().toString());
|
|
|
|
|
|
|
|
args.putSerializable("drafts", drafts);
|
|
|
|
args.putSerializable("sent", sent);
|
|
|
|
args.putSerializable("all", all);
|
|
|
|
args.putSerializable("trash", trash);
|
|
|
|
args.putSerializable("junk", junk);
|
2019-01-21 07:17:17 +00:00
|
|
|
args.putSerializable("left", left);
|
|
|
|
args.putSerializable("right", right);
|
2019-01-17 09:57:01 +00:00
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected void onPreExecute(Bundle args) {
|
2019-01-29 09:02:34 +00:00
|
|
|
saving = true;
|
|
|
|
getActivity().invalidateOptionsMenu();
|
2019-01-17 09:57:01 +00:00
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
pbSave.setVisibility(View.VISIBLE);
|
|
|
|
tvError.setVisibility(View.GONE);
|
|
|
|
}
|
2018-08-22 12:30:27 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Bundle args) {
|
2019-01-29 09:02:34 +00:00
|
|
|
saving = false;
|
|
|
|
getActivity().invalidateOptionsMenu();
|
2019-01-17 09:57:01 +00:00
|
|
|
Helper.setViewsEnabled(view, true);
|
|
|
|
pbSave.setVisibility(View.GONE);
|
|
|
|
}
|
2018-11-24 09:32:21 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
|
|
|
int auth_type = args.getInt("auth_type");
|
|
|
|
String host = args.getString("host");
|
|
|
|
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");
|
|
|
|
String realm = args.getString("realm");
|
|
|
|
|
|
|
|
String name = args.getString("name");
|
|
|
|
Integer color = args.getInt("color");
|
|
|
|
|
|
|
|
boolean synchronize = args.getBoolean("synchronize");
|
|
|
|
boolean primary = args.getBoolean("primary");
|
|
|
|
boolean notify = args.getBoolean("notify");
|
|
|
|
boolean browse = args.getBoolean("browse");
|
|
|
|
String interval = args.getString("interval");
|
|
|
|
String prefix = args.getString("prefix");
|
|
|
|
|
|
|
|
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");
|
2019-01-21 07:17:17 +00:00
|
|
|
EntityFolder left = (EntityFolder) args.getSerializable("left");
|
|
|
|
EntityFolder right = (EntityFolder) args.getSerializable("right");
|
2019-01-17 09:57:01 +00:00
|
|
|
|
|
|
|
if (TextUtils.isEmpty(host))
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
|
|
|
|
if (TextUtils.isEmpty(port))
|
2019-02-11 21:46:12 +00:00
|
|
|
port = (starttls ? "143" : "993");
|
2019-01-17 09:57:01 +00:00
|
|
|
if (TextUtils.isEmpty(user))
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
|
|
|
|
if (synchronize && TextUtils.isEmpty(password) && !insecure)
|
|
|
|
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
|
|
|
|
if (TextUtils.isEmpty(interval))
|
2019-03-14 10:47:19 +00:00
|
|
|
interval = Integer.toString(EntityAccount.DEFAULT_KEEP_ALIVE_INTERVAL);
|
2019-01-17 09:57:01 +00:00
|
|
|
|
|
|
|
if (TextUtils.isEmpty(realm))
|
|
|
|
realm = null;
|
|
|
|
|
|
|
|
if (Color.TRANSPARENT == color)
|
|
|
|
color = null;
|
|
|
|
if (TextUtils.isEmpty(prefix))
|
|
|
|
prefix = null;
|
|
|
|
|
|
|
|
Character separator = null;
|
|
|
|
long now = new Date().getTime();
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
EntityAccount account = db.account().getAccount(id);
|
|
|
|
|
|
|
|
String accountRealm = (account == null ? null : account.realm);
|
|
|
|
|
|
|
|
boolean check = (synchronize && (account == null ||
|
2019-02-02 17:59:40 +00:00
|
|
|
auth_type != account.auth_type ||
|
2019-01-17 09:57:01 +00:00
|
|
|
!host.equals(account.host) || Integer.parseInt(port) != account.port ||
|
2019-03-11 14:19:33 +00:00
|
|
|
!user.equals(account.user) || !password.equals(account.password) ||
|
2019-02-26 10:05:21 +00:00
|
|
|
!Objects.equals(realm, accountRealm)));
|
2019-01-17 09:57:01 +00:00
|
|
|
boolean reload = (check || account == null ||
|
2019-02-26 10:05:21 +00:00
|
|
|
!Objects.equals(account.prefix, prefix) ||
|
2019-01-17 09:57:01 +00:00
|
|
|
account.synchronize != synchronize ||
|
2019-03-10 07:29:24 +00:00
|
|
|
account.notify != notify ||
|
2019-01-17 09:57:01 +00:00
|
|
|
!account.poll_interval.equals(Integer.parseInt(interval)));
|
|
|
|
|
2019-01-25 06:51:44 +00:00
|
|
|
Long last_connected = null;
|
|
|
|
if (account != null && synchronize == account.synchronize)
|
|
|
|
last_connected = account.last_connected;
|
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
// Check IMAP server
|
2019-02-02 07:28:14 +00:00
|
|
|
EntityFolder inbox = null;
|
2019-01-17 09:57:01 +00:00
|
|
|
if (check) {
|
|
|
|
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
|
|
|
|
Session isession = Session.getInstance(props, null);
|
|
|
|
isession.setDebug(true);
|
|
|
|
|
2019-02-22 15:59:23 +00:00
|
|
|
try (Store istore = isession.getStore("imap" + (starttls ? "" : "s"))) {
|
2019-01-17 09:57:01 +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;
|
|
|
|
}
|
|
|
|
separator = istore.getDefaultFolder().getSeparator();
|
2019-02-02 07:28:14 +00:00
|
|
|
|
|
|
|
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
|
|
|
|
// Check folder attributes
|
|
|
|
String fullName = ifolder.getFullName();
|
2019-02-11 21:46:12 +00:00
|
|
|
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
|
2019-02-02 07:28:14 +00:00
|
|
|
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
|
|
|
|
String type = EntityFolder.getType(attrs, fullName);
|
|
|
|
|
|
|
|
if (EntityFolder.INBOX.equals(type)) {
|
|
|
|
inbox = new EntityFolder();
|
|
|
|
inbox.name = fullName;
|
|
|
|
inbox.type = type;
|
|
|
|
inbox.synchronize = true;
|
|
|
|
inbox.unified = true;
|
|
|
|
inbox.notify = true;
|
2019-02-11 21:46:12 +00:00
|
|
|
inbox.sync_days = EntityFolder.DEFAULT_SYNC;
|
|
|
|
inbox.keep_days = EntityFolder.DEFAULT_KEEP;
|
2019-02-02 07:28:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (TextUtils.isEmpty(name))
|
|
|
|
name = user;
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
boolean update = (account != null);
|
|
|
|
if (account == null)
|
|
|
|
account = new EntityAccount();
|
2018-08-22 12:30:27 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
account.auth_type = auth_type;
|
|
|
|
account.host = host;
|
|
|
|
account.starttls = starttls;
|
|
|
|
account.insecure = insecure;
|
|
|
|
account.port = Integer.parseInt(port);
|
|
|
|
account.user = user;
|
2019-03-11 14:19:33 +00:00
|
|
|
account.password = password;
|
2019-01-17 09:57:01 +00:00
|
|
|
account.realm = realm;
|
2018-08-22 12:30:27 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
account.name = name;
|
|
|
|
account.color = color;
|
2018-11-19 17:10:55 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
account.synchronize = synchronize;
|
|
|
|
account.primary = (account.synchronize && primary);
|
|
|
|
account.notify = notify;
|
|
|
|
account.browse = browse;
|
|
|
|
account.poll_interval = Integer.parseInt(interval);
|
|
|
|
account.prefix = prefix;
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (!update)
|
|
|
|
account.created = now;
|
2018-08-12 07:51:33 +00:00
|
|
|
|
2019-03-27 08:31:52 +00:00
|
|
|
account.warning = null;
|
2019-01-17 09:57:01 +00:00
|
|
|
account.error = null;
|
2019-01-25 06:51:44 +00:00
|
|
|
account.last_connected = last_connected;
|
2018-09-21 17:36:19 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (account.primary)
|
|
|
|
db.account().resetPrimary();
|
2018-09-21 17:36:19 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (!Helper.isPro(context)) {
|
|
|
|
account.color = null;
|
|
|
|
account.notify = false;
|
|
|
|
}
|
2018-12-30 12:35:34 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (update)
|
|
|
|
db.account().updateAccount(account);
|
|
|
|
else
|
|
|
|
account.id = db.account().insertAccount(account);
|
2019-02-02 07:28:14 +00:00
|
|
|
EntityLog.log(context, (update ? "Updated" : "Added") + " account=" + account.name);
|
2019-01-17 09:57:01 +00:00
|
|
|
|
|
|
|
// Make sure the channel exists on commit
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
if (account.notify) {
|
|
|
|
// Add or update notification channel
|
|
|
|
account.deleteNotificationChannel(context);
|
|
|
|
account.createNotificationChannel(context);
|
|
|
|
} else if (!account.synchronize)
|
|
|
|
account.deleteNotificationChannel(context);
|
|
|
|
|
|
|
|
List<EntityFolder> folders = new ArrayList<>();
|
|
|
|
|
2019-02-02 07:28:14 +00:00
|
|
|
if (inbox != null)
|
|
|
|
folders.add(inbox);
|
2019-01-17 09:57:01 +00:00
|
|
|
|
|
|
|
if (drafts != null) {
|
|
|
|
drafts.type = EntityFolder.DRAFTS;
|
|
|
|
folders.add(drafts);
|
|
|
|
}
|
2018-12-30 12:35:34 +00:00
|
|
|
|
2019-01-17 09:57:01 +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);
|
|
|
|
}
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2019-01-21 07:17:17 +00:00
|
|
|
if (left != null) {
|
|
|
|
boolean found = false;
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
if (left.name.equals(folder.name)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
left.type = EntityFolder.USER;
|
|
|
|
folders.add(left);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right != null) {
|
|
|
|
boolean found = false;
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
if (right.name.equals(folder.name)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
right.type = EntityFolder.USER;
|
|
|
|
folders.add(right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
db.folder().setFoldersUser(account.id);
|
|
|
|
|
|
|
|
for (EntityFolder folder : folders) {
|
|
|
|
if (account.prefix != null && folder.name.startsWith(account.prefix + separator))
|
|
|
|
folder.display = folder.name.substring(account.prefix.length() + 1);
|
|
|
|
|
|
|
|
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
|
|
|
|
if (existing == null) {
|
|
|
|
folder.account = account.id;
|
2019-02-02 07:28:14 +00:00
|
|
|
EntityLog.log(context, "Added folder=" + folder.name + " type=" + folder.type);
|
2019-01-17 09:57:01 +00:00
|
|
|
folder.id = db.folder().insertFolder(folder);
|
|
|
|
} else {
|
2019-02-02 07:28:14 +00:00
|
|
|
EntityLog.log(context, "Updated folder=" + folder.name + " type=" + folder.type);
|
2019-01-17 09:57:01 +00:00
|
|
|
db.folder().setFolderType(existing.id, folder.type);
|
|
|
|
}
|
|
|
|
}
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2019-01-21 07:17:17 +00:00
|
|
|
account.swipe_left = (left == null ? null : left.id);
|
|
|
|
account.swipe_right = (right == null ? null : right.id);
|
|
|
|
db.account().updateAccount(account);
|
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
2018-09-22 10:29:35 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (reload)
|
|
|
|
ServiceSynchronize.reload(context, "save account");
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
if (!synchronize) {
|
|
|
|
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
nm.cancel("receive", account.id.intValue());
|
|
|
|
}
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
return null;
|
|
|
|
}
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2019-01-17 09:57:01 +00:00
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
getFragmentManager().popBackStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
if (ex instanceof IllegalArgumentException)
|
|
|
|
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
|
|
|
|
else {
|
|
|
|
tvError.setText(Helper.formatThrowable(ex));
|
|
|
|
tvError.setVisibility(View.VISIBLE);
|
|
|
|
new Handler().post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2019-04-22 18:43:04 +00:00
|
|
|
scroll.smoothScrollTo(0, tvError.getBottom());
|
2019-01-17 09:57:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute(FragmentAccount.this, args, "account:save");
|
2018-08-08 05:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-15 09:50:39 +00:00
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
2019-03-02 07:35:12 +00:00
|
|
|
outState.putInt("fair:provider", spProvider.getSelectedItemPosition());
|
|
|
|
outState.putInt("fair:auth_type", auth_type);
|
|
|
|
outState.putString("fair:password", tilPassword.getEditText().getText().toString());
|
|
|
|
outState.putInt("fair:advanced", grpAdvanced.getVisibility());
|
|
|
|
outState.putInt("fair:color", color);
|
2019-04-11 17:30:39 +00:00
|
|
|
super.onSaveInstanceState(outState);
|
2018-08-15 09:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
|
2018-08-08 05:52:57 +00:00
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
|
2018-11-14 16:21:53 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", id);
|
2018-08-15 16:53:34 +00:00
|
|
|
|
2018-11-14 16:21:53 +00:00
|
|
|
new SimpleTask<EntityAccount>() {
|
2018-08-02 13:33:06 +00:00
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected EntityAccount onExecute(Context context, Bundle args) {
|
2018-11-14 16:21:53 +00:00
|
|
|
long id = args.getLong("id");
|
|
|
|
return DB.getInstance(context).account().getAccount(id);
|
|
|
|
}
|
2018-09-05 20:39:47 +00:00
|
|
|
|
2018-11-14 16:21:53 +00:00
|
|
|
@Override
|
2019-01-20 15:22:21 +00:00
|
|
|
protected void onExecuted(Bundle args, final EntityAccount account) {
|
2018-08-15 09:50:39 +00:00
|
|
|
// Get providers
|
2019-01-13 15:23:04 +00:00
|
|
|
List<EmailProvider> providers = EmailProvider.loadProfiles(getContext());
|
|
|
|
providers.add(0, new EmailProvider(getString(R.string.title_select)));
|
|
|
|
providers.add(1, new EmailProvider(getString(R.string.title_custom)));
|
2018-08-15 09:50:39 +00:00
|
|
|
|
2019-01-13 15:23:04 +00:00
|
|
|
ArrayAdapter<EmailProvider> aaProvider =
|
2018-11-11 14:09:46 +00:00
|
|
|
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) {
|
2019-01-26 11:18:59 +00:00
|
|
|
auth_type = (account == null ? Helper.AUTH_TYPE_PASSWORD : account.auth_type);
|
|
|
|
|
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++) {
|
2019-01-13 15:23:04 +00:00
|
|
|
EmailProvider provider = providers.get(pos);
|
2018-09-06 07:29:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-03-13 07:17:24 +00:00
|
|
|
rgEncryption.check(account != null && account.starttls ? R.id.radio_starttls : R.id.radio_ssl);
|
2018-11-29 17:08:57 +00:00
|
|
|
cbInsecure.setChecked(account == null ? false : account.insecure);
|
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
etUser.setTag(account == null || auth_type == Helper.AUTH_TYPE_PASSWORD ? null : account.user);
|
2018-08-16 11:26:53 +00:00
|
|
|
etUser.setText(account == null ? null : account.user);
|
2019-03-11 14:19:33 +00:00
|
|
|
tilPassword.getEditText().setText(account == null ? null : account.password);
|
2019-01-10 18:24:20 +00:00
|
|
|
etRealm.setText(account == null ? null : account.realm);
|
2018-08-27 15:08:23 +00:00
|
|
|
|
2018-09-05 18:37:20 +00:00
|
|
|
etName.setText(account == null ? null : account.name);
|
2018-12-22 17:39:16 +00:00
|
|
|
etPrefix.setText(account == null ? null : account.prefix);
|
2018-11-24 08:26:34 +00:00
|
|
|
cbNotify.setChecked(account == null ? false : account.notify);
|
2018-09-05 18:37:20 +00:00
|
|
|
|
2018-08-16 11:26:53 +00:00
|
|
|
cbSynchronize.setChecked(account == null ? true : account.synchronize);
|
2018-12-20 17:27:38 +00:00
|
|
|
cbPrimary.setChecked(account == null ? false : account.primary);
|
2018-12-23 18:20:08 +00:00
|
|
|
cbBrowse.setChecked(account == null ? true : account.browse);
|
2018-10-23 15:47:29 +00:00
|
|
|
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
|
2018-09-07 06:52:19 +00:00
|
|
|
|
2018-09-12 16:54:48 +00:00
|
|
|
color = (account == null || account.color == null ? Color.TRANSPARENT : account.color);
|
|
|
|
|
2018-12-10 07:48:05 +00:00
|
|
|
new SimpleTask<EntityAccount>() {
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected EntityAccount onExecute(Context context, Bundle args) {
|
2018-12-10 07:48:05 +00:00
|
|
|
return DB.getInstance(context).account().getPrimaryAccount();
|
|
|
|
}
|
2018-09-07 06:52:19 +00:00
|
|
|
|
2018-12-10 07:48:05 +00:00
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected void onExecuted(Bundle args, EntityAccount primary) {
|
2018-12-13 09:43:30 +00:00
|
|
|
if (primary == null)
|
|
|
|
cbPrimary.setChecked(true);
|
2018-12-10 07:48:05 +00:00
|
|
|
}
|
2018-12-01 09:47:08 +00:00
|
|
|
|
2018-12-10 07:48:05 +00:00
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(FragmentAccount.this, new Bundle(), "account:primary");
|
2018-08-15 09:50:39 +00:00
|
|
|
} else {
|
2019-03-02 07:35:12 +00:00
|
|
|
int provider = savedInstanceState.getInt("fair:provider");
|
2018-08-15 09:50:39 +00:00
|
|
|
spProvider.setTag(provider);
|
|
|
|
spProvider.setSelection(provider);
|
2018-08-27 15:08:23 +00:00
|
|
|
|
2019-03-02 07:35:12 +00:00
|
|
|
auth_type = savedInstanceState.getInt("fair:auth_type");
|
|
|
|
tilPassword.getEditText().setText(savedInstanceState.getString("fair:password"));
|
|
|
|
grpAdvanced.setVisibility(savedInstanceState.getInt("fair:advanced"));
|
|
|
|
color = savedInstanceState.getInt("fair:color");
|
2018-08-15 09:50:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 06:40:36 +00:00
|
|
|
Helper.setViewsEnabled(view, true);
|
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
tilPassword.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
|
|
|
|
etRealm.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
|
|
|
|
|
2018-09-21 05:36:01 +00:00
|
|
|
setColor(color);
|
2018-08-15 16:18:14 +00:00
|
|
|
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
2018-08-10 11:05:38 +00:00
|
|
|
|
2018-08-16 11:26:53 +00:00
|
|
|
// Consider previous check/save/delete as cancelled
|
2018-11-05 09:03:02 +00:00
|
|
|
pbWait.setVisibility(View.GONE);
|
2018-09-21 16:09:31 +00:00
|
|
|
|
2018-11-14 16:21:53 +00:00
|
|
|
args.putLong("account", account == null ? -1 : account.id);
|
|
|
|
|
|
|
|
new SimpleTask<List<EntityFolder>>() {
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected List<EntityFolder> onExecute(Context context, Bundle args) {
|
2018-11-14 16:21:53 +00:00
|
|
|
long account = args.getLong("account");
|
2019-01-18 11:15:07 +00:00
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
List<EntityFolder> folders = db.folder().getFolders(account);
|
|
|
|
|
|
|
|
if (folders != null) {
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
folder.display = folder.getDisplayName(getContext());
|
2019-03-04 07:48:36 +00:00
|
|
|
EntityFolder.sort(getContext(), folders, true);
|
2019-01-18 11:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return folders;
|
2018-11-14 16:21:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected void onExecuted(Bundle args, List<EntityFolder> folders) {
|
2018-11-14 16:21:53 +00:00
|
|
|
if (folders == null)
|
|
|
|
folders = new ArrayList<>();
|
2019-01-20 15:22:21 +00:00
|
|
|
setFolders(folders, account);
|
2018-11-14 16:21:53 +00:00
|
|
|
}
|
2018-12-01 09:47:08 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2018-12-01 12:04:41 +00:00
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
2018-12-01 09:47:08 +00:00
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(FragmentAccount.this, args, "account:folders");
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
2018-12-01 09:47:08 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2018-12-01 12:04:41 +00:00
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
2018-12-01 09:47:08 +00:00
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(this, args, "account:get");
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
2018-08-27 14:31:45 +00:00
|
|
|
|
2018-12-06 08:51:27 +00:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_account, menu);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPrepareOptionsMenu(Menu menu) {
|
2019-01-29 09:02:34 +00:00
|
|
|
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving);
|
2018-12-06 08:51:27 +00:00
|
|
|
super.onPrepareOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_delete:
|
|
|
|
onMenuDelete();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onMenuDelete() {
|
|
|
|
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
|
|
|
|
.setMessage(R.string.title_account_delete)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", id);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
2019-01-29 09:02:34 +00:00
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Bundle args) {
|
|
|
|
Helper.setViewsEnabled(view, false);
|
|
|
|
pbWait.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2018-12-06 08:51:27 +00:00
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
2018-12-06 08:51:27 +00:00
|
|
|
long id = args.getLong("id");
|
2018-12-06 12:43:00 +00:00
|
|
|
|
2018-12-06 08:51:27 +00:00
|
|
|
DB db = DB.getInstance(context);
|
2018-12-06 12:43:00 +00:00
|
|
|
db.account().setAccountTbd(id);
|
|
|
|
|
2018-12-26 09:40:28 +00:00
|
|
|
ServiceSynchronize.reload(context, "delete account");
|
2018-12-06 12:43:00 +00:00
|
|
|
|
2018-12-06 08:51:27 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-12-31 07:03:48 +00:00
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
2018-12-06 08:51:27 +00:00
|
|
|
getFragmentManager().popBackStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
|
|
|
}
|
2019-01-12 13:15:15 +00:00
|
|
|
}.execute(FragmentAccount.this, args, "account:delete");
|
2018-12-06 08:51:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.show();
|
2018-08-27 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Accounts=" + accounts.length);
|
2018-08-27 14:31:45 +00:00
|
|
|
for (final Account account : accounts)
|
|
|
|
if (name.equals(account.name)) {
|
2019-01-02 07:37:21 +00:00
|
|
|
btnAuthorize.setEnabled(false);
|
2019-01-02 09:59:57 +00:00
|
|
|
etUser.setEnabled(false);
|
|
|
|
tilPassword.setEnabled(false);
|
2019-01-10 18:24:20 +00:00
|
|
|
etRealm.setEnabled(false);
|
2019-01-02 09:59:57 +00:00
|
|
|
btnCheck.setEnabled(false);
|
|
|
|
btnSave.setEnabled(false);
|
2018-09-05 12:37:27 +00:00
|
|
|
final Snackbar snackbar = Snackbar.make(view, R.string.title_authorizing, Snackbar.LENGTH_SHORT);
|
|
|
|
snackbar.show();
|
2018-12-23 12:18:32 +00:00
|
|
|
|
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);
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Got token");
|
2018-08-27 14:31:45 +00:00
|
|
|
|
2019-01-26 11:18:59 +00:00
|
|
|
auth_type = Helper.AUTH_TYPE_GMAIL;
|
|
|
|
etUser.setTag(account.name);
|
2018-08-27 14:31:45 +00:00
|
|
|
etUser.setText(account.name);
|
2019-01-26 11:18:59 +00:00
|
|
|
etUser.setTag(account.name);
|
2018-08-27 14:31:45 +00:00
|
|
|
tilPassword.getEditText().setText(token);
|
2019-01-10 18:24:20 +00:00
|
|
|
etRealm.setText(null);
|
2019-01-02 07:37:21 +00:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
2019-01-04 17:13:14 +00:00
|
|
|
if (ex instanceof OperationCanceledException ||
|
|
|
|
ex instanceof AuthenticatorException ||
|
|
|
|
ex instanceof IOException)
|
|
|
|
Snackbar.make(view, Helper.formatThrowable(ex), Snackbar.LENGTH_LONG).show();
|
|
|
|
else
|
2019-01-04 14:08:38 +00:00
|
|
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
2019-01-02 07:37:21 +00:00
|
|
|
} finally {
|
|
|
|
btnAuthorize.setEnabled(true);
|
2019-01-02 09:59:57 +00:00
|
|
|
etUser.setEnabled(true);
|
2019-01-26 11:18:59 +00:00
|
|
|
tilPassword.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
|
2019-02-18 11:39:43 +00:00
|
|
|
tilPassword.setPasswordVisibilityToggleEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
|
2019-01-26 11:18:59 +00:00
|
|
|
etRealm.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
|
2019-01-02 09:59:57 +00:00
|
|
|
btnCheck.setEnabled(true);
|
|
|
|
btnSave.setEnabled(true);
|
2018-12-23 12:18:32 +00:00
|
|
|
new Handler().postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
snackbar.dismiss();
|
|
|
|
}
|
|
|
|
}, 1000);
|
2018-08-27 14:31:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
null);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 16:54:48 +00:00
|
|
|
|
2018-12-06 08:51:27 +00:00
|
|
|
private void selectAccount() {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Select account");
|
2019-01-13 15:23:04 +00:00
|
|
|
EmailProvider provider = (EmailProvider) spProvider.getSelectedItem();
|
2018-12-06 08:51:27 +00:00
|
|
|
if (provider.type != null)
|
2018-12-09 10:21:47 +00:00
|
|
|
startActivityForResult(
|
|
|
|
Helper.getChooser(getContext(), newChooseAccountIntent(
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
new String[]{provider.type},
|
2018-12-09 17:49:52 +00:00
|
|
|
false,
|
2018-12-09 10:21:47 +00:00
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null)),
|
|
|
|
ActivitySetup.REQUEST_CHOOSE_ACCOUNT);
|
2018-12-06 08:51:27 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2018-09-21 16:09:31 +00:00
|
|
|
|
2019-01-20 15:22:21 +00:00
|
|
|
private void setFolders(List<EntityFolder> folders, EntityAccount account) {
|
2018-09-21 16:09:31 +00:00
|
|
|
EntityFolder none = new EntityFolder();
|
2019-01-20 15:22:21 +00:00
|
|
|
none.id = -1L;
|
2018-12-27 17:35:41 +00:00
|
|
|
none.name = "-";
|
2018-09-21 16:09:31 +00:00
|
|
|
folders.add(0, none);
|
|
|
|
|
2018-09-21 17:36:19 +00:00
|
|
|
adapter.clear();
|
|
|
|
adapter.addAll(folders);
|
2018-09-21 16:09:31 +00:00
|
|
|
|
2019-01-20 15:22:21 +00:00
|
|
|
Long left = (account == null ? null : account.swipe_left);
|
|
|
|
Long right = (account == null ? null : account.swipe_right);
|
|
|
|
|
2019-02-02 08:43:32 +00:00
|
|
|
String leftDefault = EntityFolder.TRASH;
|
|
|
|
String rightDefault = EntityFolder.TRASH;
|
|
|
|
for (EntityFolder folder : folders)
|
|
|
|
if (EntityFolder.ARCHIVE.equals(folder.type)) {
|
|
|
|
rightDefault = folder.type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-09-21 16:09:31 +00:00
|
|
|
for (int pos = 0; pos < folders.size(); pos++) {
|
2019-01-20 15:22:21 +00:00
|
|
|
EntityFolder folder = folders.get(pos);
|
|
|
|
|
|
|
|
if (EntityFolder.DRAFTS.equals(folder.type))
|
2018-09-21 16:09:31 +00:00
|
|
|
spDrafts.setSelection(pos);
|
2019-01-20 15:22:21 +00:00
|
|
|
else if (EntityFolder.SENT.equals(folder.type))
|
2018-09-21 16:09:31 +00:00
|
|
|
spSent.setSelection(pos);
|
2019-01-20 15:22:21 +00:00
|
|
|
else if (EntityFolder.ARCHIVE.equals(folder.type))
|
2018-09-21 16:09:31 +00:00
|
|
|
spAll.setSelection(pos);
|
2019-01-20 15:22:21 +00:00
|
|
|
else if (EntityFolder.TRASH.equals(folder.type))
|
2018-09-21 16:09:31 +00:00
|
|
|
spTrash.setSelection(pos);
|
2019-01-20 15:22:21 +00:00
|
|
|
else if (EntityFolder.JUNK.equals(folder.type))
|
2018-09-21 16:09:31 +00:00
|
|
|
spJunk.setSelection(pos);
|
2019-01-20 15:22:21 +00:00
|
|
|
|
2019-02-02 08:43:32 +00:00
|
|
|
if (left == null ? (account == null && leftDefault.equals(folder.type)) : left.equals(folder.id))
|
2019-01-20 15:22:21 +00:00
|
|
|
spLeft.setSelection(pos);
|
|
|
|
|
2019-02-02 08:43:32 +00:00
|
|
|
if (right == null ? (account == null && rightDefault.equals(folder.type)) : right.equals(folder.id))
|
2019-01-20 15:22:21 +00:00
|
|
|
spRight.setSelection(pos);
|
2018-09-21 16:09:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 10:40:15 +00:00
|
|
|
grpFolders.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE);
|
|
|
|
btnSave.setVisibility(folders.size() > 1 ? View.VISIBLE : View.GONE);
|
2018-09-21 16:09:31 +00:00
|
|
|
}
|
2018-09-22 10:29:35 +00:00
|
|
|
|
|
|
|
private class CheckResult {
|
2019-01-20 15:22:21 +00:00
|
|
|
EntityAccount account;
|
2018-09-22 10:29:35 +00:00
|
|
|
List<EntityFolder> folders;
|
|
|
|
boolean idle;
|
2019-02-20 16:07:17 +00:00
|
|
|
Boolean utf8;
|
2018-09-22 10:29:35 +00:00
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|