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

1137 lines
47 KiB
Java
Raw Normal View History

2019-09-19 15:41:26 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
2019-09-19 15:41:26 +00:00
*/
2021-07-31 12:31:54 +00:00
import static android.app.Activity.RESULT_OK;
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
import android.Manifest;
2019-09-19 15:41:26 +00:00
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
2021-03-13 09:44:12 +00:00
import android.graphics.Paint;
2020-02-09 08:40:52 +00:00
import android.os.Build;
2019-09-19 15:41:26 +00:00
import android.os.Bundle;
import android.text.Editable;
2019-09-19 15:41:26 +00:00
import android.text.TextUtils;
import android.text.TextWatcher;
2019-09-19 15:41:26 +00:00
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
2023-11-13 08:40:35 +00:00
import android.widget.AutoCompleteTextView;
2019-09-19 15:41:26 +00:00
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.Spinner;
2019-09-19 15:41:26 +00:00
import android.widget.TextView;
2022-06-12 07:22:55 +00:00
import androidx.activity.OnBackPressedCallback;
2019-09-19 15:41:26 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2019-11-15 08:33:43 +00:00
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction;
2019-09-19 15:41:26 +00:00
import androidx.lifecycle.Lifecycle;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;
import org.json.JSONObject;
import java.util.ArrayList;
2019-09-19 15:41:26 +00:00
import java.util.Date;
import java.util.List;
2020-01-08 10:38:45 +00:00
import java.util.Objects;
2019-09-19 15:41:26 +00:00
public class FragmentPop extends FragmentBase {
private ViewGroup view;
private ScrollView scroll;
2024-01-06 15:38:22 +00:00
private CheckBox cbDnsSec;
2019-09-19 15:41:26 +00:00
private EditText etHost;
private RadioGroup rgEncryption;
private CheckBox cbInsecure;
2021-05-07 14:44:39 +00:00
private TextView tvInsecureRemark;
2024-01-06 14:20:05 +00:00
private CheckBox cbDane;
2019-09-19 15:41:26 +00:00
private EditText etPort;
private EditText etUser;
private TextInputLayout tilPassword;
2021-03-13 09:44:12 +00:00
private TextView tvPasswordStorage;
2019-09-19 15:41:26 +00:00
private EditText etName;
2023-11-13 08:40:35 +00:00
private ArrayAdapter<String> adapterCategory;
private AutoCompleteTextView etCategory;
2019-10-01 08:13:22 +00:00
private ViewButtonColor btnColor;
2019-09-19 15:41:26 +00:00
private TextView tvColorPro;
private Button btnCalendar;
2022-11-03 06:59:25 +00:00
private TextView tvCalendarPro;
2019-09-19 15:41:26 +00:00
private CheckBox cbSynchronize;
2022-04-23 10:44:25 +00:00
private CheckBox cbIgnoreSchedule;
2019-12-10 15:51:21 +00:00
private CheckBox cbOnDemand;
2019-09-19 15:41:26 +00:00
private CheckBox cbPrimary;
private CheckBox cbNotify;
private TextView tvNotifyRemark;
private CheckBox cbSummary;
private TextView tvNotifyPro;
private CheckBox cbAutoSeen;
2020-01-21 14:15:48 +00:00
private CheckBox cbLeaveServer;
private CheckBox cbClientDelete;
private CheckBox cbLeaveDeleted;
2020-01-21 14:15:48 +00:00
private CheckBox cbLeaveDevice;
private EditText etMax;
2019-09-19 15:41:26 +00:00
private EditText etInterval;
private CheckBox cbUnmetered;
private CheckBox cbVpnOnly;
2019-09-19 15:41:26 +00:00
private ArrayAdapter<EntityFolder> adapterSwipe;
private Spinner spLeft;
private Spinner spRight;
2019-09-19 15:41:26 +00:00
private Button btnSave;
private ContentLoadingProgressBar pbSave;
private CheckBox cbIdentity;
2019-09-19 15:41:26 +00:00
private TextView tvError;
private Group grpCalendar;
2019-11-15 08:33:43 +00:00
private Group grpError;
2019-09-19 15:41:26 +00:00
private ContentLoadingProgressBar pbWait;
private long id = -1;
2022-04-17 09:44:44 +00:00
private int auth = AUTH_TYPE_PASSWORD;
private String calendar = null;
2019-09-19 15:41:26 +00:00
private boolean saving = false;
private static final int REQUEST_COLOR = 1;
private static final int REQUEST_CALENDAR = 2;
private static final int REQUEST_SAVE = 3;
private static final int REQUEST_DELETE = 4;
2019-09-19 15:41:26 +00:00
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get arguments
Bundle args = getArguments();
id = args.getLong("id", -1);
}
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_account);
setHasOptionsMenu(true);
view = (ViewGroup) inflater.inflate(R.layout.fragment_pop, container, false);
scroll = view.findViewById(R.id.scroll);
// Get controls
2024-01-06 15:38:22 +00:00
cbDnsSec = view.findViewById(R.id.cbDnsSec);
2019-09-19 15:41:26 +00:00
etHost = view.findViewById(R.id.etHost);
etPort = view.findViewById(R.id.etPort);
rgEncryption = view.findViewById(R.id.rgEncryption);
cbInsecure = view.findViewById(R.id.cbInsecure);
2021-05-07 14:44:39 +00:00
tvInsecureRemark = view.findViewById(R.id.tvInsecureRemark);
2024-01-06 14:20:05 +00:00
cbDane = view.findViewById(R.id.cbDane);
2019-09-19 15:41:26 +00:00
etUser = view.findViewById(R.id.etUser);
tilPassword = view.findViewById(R.id.tilPassword);
2021-03-13 09:44:12 +00:00
tvPasswordStorage = view.findViewById(R.id.tvPasswordStorage);
2019-09-19 15:41:26 +00:00
etName = view.findViewById(R.id.etName);
2021-10-03 19:45:18 +00:00
etCategory = view.findViewById(R.id.etCategory);
2019-09-19 15:41:26 +00:00
btnColor = view.findViewById(R.id.btnColor);
tvColorPro = view.findViewById(R.id.tvColorPro);
btnCalendar = view.findViewById(R.id.btnCalendar);
2022-11-03 06:59:25 +00:00
tvCalendarPro = view.findViewById(R.id.tvCalendarPro);
2019-09-19 15:41:26 +00:00
cbSynchronize = view.findViewById(R.id.cbSynchronize);
2022-04-23 10:44:25 +00:00
cbIgnoreSchedule = view.findViewById(R.id.cbIgnoreSchedule);
2019-12-10 15:51:21 +00:00
cbOnDemand = view.findViewById(R.id.cbOnDemand);
2019-09-19 15:41:26 +00:00
cbPrimary = view.findViewById(R.id.cbPrimary);
2020-02-09 08:40:52 +00:00
cbNotify = view.findViewById(R.id.cbNotify);
tvNotifyRemark = view.findViewById(R.id.tvNotifyRemark);
cbSummary = view.findViewById(R.id.cbSummary);
2020-02-09 08:40:52 +00:00
tvNotifyPro = view.findViewById(R.id.tvNotifyPro);
cbAutoSeen = view.findViewById(R.id.cbAutoSeen);
2020-01-21 14:15:48 +00:00
cbLeaveServer = view.findViewById(R.id.cbLeaveServer);
cbClientDelete = view.findViewById(R.id.cbClientDelete);
cbLeaveDeleted = view.findViewById(R.id.cbLeaveDeleted);
2020-01-21 14:15:48 +00:00
cbLeaveDevice = view.findViewById(R.id.cbLeaveDevice);
etMax = view.findViewById(R.id.etMax);
2019-09-19 15:41:26 +00:00
etInterval = view.findViewById(R.id.etInterval);
cbUnmetered = view.findViewById(R.id.cbUnmeteredOnly);
cbVpnOnly = view.findViewById(R.id.cbVpnOnly);
2019-09-19 15:41:26 +00:00
spLeft = view.findViewById(R.id.spLeft);
spRight = view.findViewById(R.id.spRight);
2019-09-19 15:41:26 +00:00
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
cbIdentity = view.findViewById(R.id.cbIdentity);
2019-09-19 15:41:26 +00:00
tvError = view.findViewById(R.id.tvError);
grpCalendar = view.findViewById(R.id.grpCalendar);
2019-11-15 08:33:43 +00:00
grpError = view.findViewById(R.id.grpError);
2019-09-19 15:41:26 +00:00
pbWait = view.findViewById(R.id.pbWait);
2020-08-23 07:28:10 +00:00
rgEncryption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int id) {
etPort.setHint(id == R.id.radio_ssl ? "995" : "110");
}
});
cbInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean checked) {
cbDane.setEnabled(!checked);
}
});
2021-05-07 14:44:39 +00:00
tvInsecureRemark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(v.getContext(), 4);
}
});
tilPassword.getEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// https://github.com/material-components/material-components-android/issues/503
//if (TextUtils.isEmpty(s))
// tilPassword.setEndIconMode(END_ICON_PASSWORD_TOGGLE);
}
@Override
public void afterTextChanged(Editable s) {
2022-04-23 07:56:48 +00:00
if (tilPassword == null)
return;
String password = s.toString();
boolean warning = (Helper.containsWhiteSpace(password) ||
Helper.containsControlChars(password));
2021-07-31 12:31:54 +00:00
tilPassword.setHelperText(
warning ? getString(R.string.title_setup_password_chars) : null);
tilPassword.setHelperTextEnabled(warning);
}
});
2021-03-13 09:44:12 +00:00
tvPasswordStorage.setPaintFlags(tvPasswordStorage.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
tvPasswordStorage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(v.getContext(), 37);
}
});
2023-11-13 08:40:35 +00:00
adapterCategory = new ArrayAdapter<>(getContext(), R.layout.spinner_item1_dropdown, android.R.id.text1);
etCategory.setThreshold(1);
etCategory.setAdapter(adapterCategory);
2019-09-19 15:41:26 +00:00
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2019-09-29 14:31:13 +00:00
Bundle args = new Bundle();
args.putInt("color", btnColor.getColor());
args.putString("title", getString(R.string.title_color));
2019-09-29 17:04:21 +00:00
args.putBoolean("reset", true);
2019-09-29 14:31:13 +00:00
2019-09-19 15:41:26 +00:00
FragmentDialogColor fragment = new FragmentDialogColor();
2019-09-29 14:31:13 +00:00
fragment.setArguments(args);
fragment.setTargetFragment(FragmentPop.this, REQUEST_COLOR);
2019-10-12 15:16:53 +00:00
fragment.show(getParentFragmentManager(), "account:color");
2019-09-19 15:41:26 +00:00
}
});
Helper.linkPro(tvColorPro);
grpCalendar.setVisibility(BuildConfig.PLAY_STORE_RELEASE ? View.GONE : View.VISIBLE);
btnCalendar.setEnabled(Helper.hasPermission(getContext(), Manifest.permission.WRITE_CALENDAR));
btnCalendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
2022-11-03 10:36:34 +00:00
args.putString("calendar", calendar);
FragmentDialogCalendar fragment = new FragmentDialogCalendar();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentPop.this, REQUEST_CALENDAR);
fragment.show(getParentFragmentManager(), "account:calendar");
}
});
2022-11-03 06:59:25 +00:00
Helper.linkPro(tvCalendarPro);
2019-09-19 15:41:26 +00:00
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2022-04-23 10:44:25 +00:00
cbIgnoreSchedule.setEnabled(checked);
2019-12-10 15:51:21 +00:00
cbOnDemand.setEnabled(checked);
2019-09-19 15:41:26 +00:00
cbPrimary.setEnabled(checked);
}
});
2020-02-09 08:40:52 +00:00
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
Helper.hide(cbNotify);
Helper.hide(tvNotifyRemark);
2020-02-09 08:40:52 +00:00
Helper.hide(view.findViewById(R.id.tvNotifyPro));
}
tvNotifyRemark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Helper.viewFAQ(v.getContext(), 145);
}
});
2020-02-09 08:40:52 +00:00
Helper.linkPro(tvNotifyPro);
cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbSummary.setEnabled(cbNotify.isEnabled() && isChecked);
}
});
cbLeaveServer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbClientDelete.setEnabled(!isChecked);
}
});
2019-12-12 13:52:45 +00:00
etInterval.setHint(Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL));
adapterSwipe = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, getSwipeActions());
adapterSwipe.setDropDownViewResource(R.layout.spinner_item1_dropdown);
spLeft.setAdapter(adapterSwipe);
spRight.setAdapter(adapterSwipe);
2019-09-19 15:41:26 +00:00
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2021-02-15 19:54:10 +00:00
onSave(false);
}
});
2022-06-15 14:30:50 +00:00
setBackPressedCallback(new OnBackPressedCallback(true) {
2021-02-15 19:54:10 +00:00
@Override
2022-06-12 07:22:55 +00:00
public void handleOnBackPressed() {
2022-06-12 11:19:38 +00:00
if (Helper.isKeyboardVisible(view))
Helper.hideKeyboard(view);
else
onSave(true);
2019-09-19 15:41:26 +00:00
}
});
// Initialize
Helper.setViewsEnabled(view, false);
2024-01-07 09:36:33 +00:00
FragmentDialogTheme.setBackground(getContext(), view, false);
2019-09-19 15:41:26 +00:00
2024-03-09 19:55:47 +00:00
if (!DnsHelper.hasDnsSec()) {
Helper.hide(cbDnsSec);
Helper.hide(view.findViewById(R.id.tvDnsRemark));
Helper.hide(cbDane);
Helper.hide(view.findViewById(R.id.tvDaneRemark));
}
if (!SSLHelper.customTrustManager()) {
Helper.hide(cbInsecure);
Helper.hide(tvInsecureRemark);
Helper.hide(cbDane);
2024-03-09 19:55:47 +00:00
Helper.hide(view.findViewById(R.id.tvDaneRemark));
}
2023-02-01 18:50:42 +00:00
if (id < 0)
tilPassword.setEndIconMode(END_ICON_PASSWORD_TOGGLE);
else
Helper.setupPasswordToggle(getActivity(), tilPassword);
2019-09-19 15:41:26 +00:00
pbSave.setVisibility(View.GONE);
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.GONE);
2019-09-19 15:41:26 +00:00
return view;
}
2021-02-15 19:54:10 +00:00
private void onSave(boolean should) {
2019-09-19 15:41:26 +00:00
Bundle args = new Bundle();
args.putLong("id", id);
2020-08-23 07:28:10 +00:00
int encryption;
if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls)
encryption = EmailService.ENCRYPTION_STARTTLS;
else if (rgEncryption.getCheckedRadioButtonId() == R.id.radio_none)
encryption = EmailService.ENCRYPTION_NONE;
else
encryption = EmailService.ENCRYPTION_SSL;
2024-01-06 15:38:22 +00:00
args.putBoolean("dnssec", cbDnsSec.isChecked());
2020-10-11 19:34:31 +00:00
args.putString("host", etHost.getText().toString().trim().replace(" ", ""));
2020-08-23 07:28:10 +00:00
args.putInt("encryption", encryption);
2019-09-19 15:41:26 +00:00
args.putBoolean("insecure", cbInsecure.isChecked());
args.putBoolean("dane", cbDane.isChecked());
2019-09-19 15:41:26 +00:00
args.putString("port", etPort.getText().toString());
2022-04-17 09:44:44 +00:00
args.putInt("auth", auth);
2019-09-19 15:41:26 +00:00
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putString("name", etName.getText().toString());
2021-10-03 19:45:18 +00:00
args.putString("category", etCategory.getText().toString());
2019-09-29 12:45:00 +00:00
args.putInt("color", btnColor.getColor());
args.putString("calendar", calendar);
2019-09-19 15:41:26 +00:00
args.putBoolean("synchronize", cbSynchronize.isChecked());
2022-04-23 10:44:25 +00:00
args.putBoolean("ignore_schedule", cbIgnoreSchedule.isChecked());
2019-12-10 15:51:21 +00:00
args.putBoolean("ondemand", cbOnDemand.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
2020-02-09 08:40:52 +00:00
args.putBoolean("notify", cbNotify.isChecked());
args.putBoolean("summary", cbSummary.isChecked());
args.putBoolean("auto_seen", cbAutoSeen.isChecked());
2020-01-21 14:15:48 +00:00
args.putBoolean("leave_server", cbLeaveServer.isChecked());
args.putBoolean("client_delete", cbClientDelete.isChecked());
args.putBoolean("leave_deleted", cbLeaveDeleted.isChecked());
2020-01-21 14:15:48 +00:00
args.putBoolean("leave_device", cbLeaveDevice.isChecked());
args.putString("max", etMax.getText().toString());
2019-09-19 15:41:26 +00:00
args.putString("interval", etInterval.getText().toString());
args.putBoolean("unmetered", cbUnmetered.isChecked());
args.putBoolean("vpn_only", cbVpnOnly.isChecked());
2019-09-19 15:41:26 +00:00
args.putLong("left", ((EntityFolder) spLeft.getSelectedItem()).id);
args.putLong("right", ((EntityFolder) spRight.getSelectedItem()).id);
2021-02-15 19:54:10 +00:00
args.putBoolean("should", should);
2019-09-19 15:41:26 +00:00
new SimpleTask<Boolean>() {
@Override
protected void onPreExecute(Bundle args) {
saving = true;
2021-11-03 17:28:51 +00:00
invalidateOptionsMenu();
2019-09-19 15:41:26 +00:00
Helper.setViewsEnabled(view, false);
2020-08-23 07:28:10 +00:00
pbSave.setVisibility(View.VISIBLE);
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.GONE);
2019-09-19 15:41:26 +00:00
}
@Override
protected void onPostExecute(Bundle args) {
saving = false;
2021-11-03 17:28:51 +00:00
invalidateOptionsMenu();
2019-09-19 15:41:26 +00:00
Helper.setViewsEnabled(view, true);
pbSave.setVisibility(View.GONE);
}
@Override
protected Boolean onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
2024-01-06 15:38:22 +00:00
boolean dnssec = args.getBoolean("dnssec");
2019-09-19 15:41:26 +00:00
String host = args.getString("host");
2020-08-23 07:28:10 +00:00
int encryption = args.getInt("encryption");
2019-09-19 15:41:26 +00:00
boolean insecure = args.getBoolean("insecure");
boolean dane = args.getBoolean("dane");
2019-09-19 15:41:26 +00:00
String port = args.getString("port");
2022-04-17 09:44:44 +00:00
int auth = args.getInt("auth");
2019-09-19 15:41:26 +00:00
String user = args.getString("user").trim();
String password = args.getString("password");
String name = args.getString("name");
2021-10-03 19:45:18 +00:00
String category = args.getString("category");
2019-09-19 15:41:26 +00:00
Integer color = args.getInt("color");
String calendar = args.getString("calendar");
2019-09-19 15:41:26 +00:00
boolean synchronize = args.getBoolean("synchronize");
2022-04-23 10:44:25 +00:00
boolean ignore_schedule = args.getBoolean("ignore_schedule");
2019-12-10 15:51:21 +00:00
boolean ondemand = args.getBoolean("ondemand");
2019-09-19 15:41:26 +00:00
boolean primary = args.getBoolean("primary");
2020-02-09 08:40:52 +00:00
boolean notify = args.getBoolean("notify");
boolean summary = args.getBoolean("summary");
boolean auto_seen = args.getBoolean("auto_seen");
2020-01-21 14:15:48 +00:00
boolean leave_server = args.getBoolean("leave_server");
boolean client_delete = args.getBoolean("client_delete");
boolean leave_deleted = args.getBoolean("leave_deleted");
2020-01-21 14:15:48 +00:00
boolean leave_device = args.getBoolean("leave_device");
String max = args.getString("max");
2019-09-19 15:41:26 +00:00
String interval = args.getString("interval");
boolean unmetered = args.getBoolean("unmetered");
boolean vpn_only = args.getBoolean("vpn_only");
2019-09-19 15:41:26 +00:00
long left = args.getLong("left");
long right = args.getLong("right");
2019-09-19 15:41:26 +00:00
boolean pro = ActivityBilling.isPro(context);
2021-02-15 19:54:10 +00:00
boolean should = args.getBoolean("should");
2019-09-19 15:41:26 +00:00
2021-08-31 05:33:27 +00:00
int semi = host.indexOf(':');
if (semi > 0 && host.indexOf(':', semi + 1) < 0)
host = host.substring(0, semi);
2019-09-19 15:41:26 +00:00
2021-02-15 19:54:10 +00:00
if (TextUtils.isEmpty(host) && !should)
2019-09-19 15:41:26 +00:00
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
2020-08-23 07:28:10 +00:00
port = (encryption == EmailService.ENCRYPTION_SSL ? "995" : "110");
2021-03-11 09:18:04 +00:00
if (TextUtils.isEmpty(user) && !insecure && !should)
2019-09-19 15:41:26 +00:00
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
2021-02-15 19:54:10 +00:00
if (synchronize && TextUtils.isEmpty(password) && !insecure && !should)
2019-09-19 15:41:26 +00:00
throw new IllegalArgumentException(context.getString(R.string.title_no_password));
if (TextUtils.isEmpty(interval))
2019-12-12 13:52:45 +00:00
interval = Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL);
2021-02-15 19:54:10 +00:00
Integer max_messages = (TextUtils.isEmpty(max) ? null : Integer.parseInt(max));
2023-02-15 16:37:15 +00:00
if (max_messages != null && max_messages == 0)
max_messages = null;
2021-02-15 19:54:10 +00:00
int poll_interval = Math.max(1, Integer.parseInt(interval));
2019-09-19 15:41:26 +00:00
if (TextUtils.isEmpty(name))
name = user;
2021-10-03 19:45:18 +00:00
if (TextUtils.isEmpty(category))
category = null;
2019-09-19 15:41:26 +00:00
if (color == Color.TRANSPARENT || !pro)
color = null;
if (!pro) {
2021-02-15 19:54:10 +00:00
notify = false;
summary = false;
}
2019-09-19 15:41:26 +00:00
long now = new Date().getTime();
DB db = DB.getInstance(context);
EntityAccount account = db.account().getAccount(id);
JSONObject jconditions = new JSONObject();
if (account != null && account.conditions != null)
try {
jconditions = new JSONObject(account.conditions);
} catch (Throwable ex) {
Log.e(ex);
}
2021-02-15 19:54:10 +00:00
if (should) {
if (account == null)
return !TextUtils.isEmpty(host) && !TextUtils.isEmpty(user);
2024-01-06 15:38:22 +00:00
if (!Objects.equals(account.dnssec, dnssec))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.host, host))
return true;
if (!Objects.equals(account.encryption, encryption))
return true;
if (!Objects.equals(account.insecure, insecure))
return true;
if (!Objects.equals(account.dane, dane))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.port, Integer.parseInt(port)))
return true;
if (!Objects.equals(account.user, user))
return true;
if (!Objects.equals(account.password, password))
return true;
if (!Objects.equals(account.name, name))
return true;
2021-10-03 19:45:18 +00:00
if (!Objects.equals(account.category, category))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.color, color))
return true;
if (!Objects.equals(account.calendar, calendar))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.synchronize, synchronize))
return true;
2022-04-23 10:44:25 +00:00
if (ignore_schedule != jconditions.optBoolean("ignore_schedule"))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.ondemand, ondemand))
return true;
if (!Objects.equals(account.primary, account.synchronize && primary))
return true;
if (!Objects.equals(account.notify, notify))
return true;
if (!Objects.equals(account.summary, summary))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.auto_seen, auto_seen))
return true;
if (!Objects.equals(account.leave_on_server, leave_server))
return true;
if (!Objects.equals(account.client_delete, client_delete))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.leave_deleted, leave_deleted))
return true;
if (!Objects.equals(account.leave_on_device, leave_device))
return true;
if (!Objects.equals(account.max_messages, max_messages))
return true;
if (!Objects.equals(account.poll_interval, poll_interval))
return true;
if (unmetered != jconditions.optBoolean("unmetered"))
return true;
if (vpn_only != jconditions.optBoolean("vpn_only"))
return true;
2021-02-15 19:54:10 +00:00
if (!Objects.equals(account.swipe_left, left))
return true;
if (!Objects.equals(account.swipe_right, right))
return true;
return false;
}
2019-09-19 15:41:26 +00:00
boolean check = (synchronize && (account == null ||
!account.synchronize ||
account.error != null ||
2024-01-06 15:38:22 +00:00
!account.dnssec.equals(dnssec) ||
!account.host.equals(host) ||
2020-08-23 07:28:10 +00:00
!account.encryption.equals(encryption) ||
2019-09-19 15:41:26 +00:00
!account.insecure.equals(insecure) ||
!account.dane.equals(dane) ||
!account.port.equals(Integer.parseInt(port)) ||
!account.user.equals(user) ||
2022-01-30 12:38:32 +00:00
!account.password.equals(password) ||
BuildConfig.DEBUG));
Log.i("Account check=" + check);
2019-09-19 15:41:26 +00:00
Long last_connected = null;
if (account != null && synchronize == account.synchronize)
last_connected = account.last_connected;
// Check POP3 server
if (check) {
2020-08-23 07:28:10 +00:00
String protocol = "pop3" + (encryption == EmailService.ENCRYPTION_SSL ? "s" : "");
try (EmailService iservice = new EmailService(context,
protocol, null, encryption, insecure, dane, false,
2020-08-23 07:28:10 +00:00
EmailService.PURPOSE_CHECK, true)) {
2020-02-06 12:06:10 +00:00
iservice.connect(
2024-01-06 15:38:22 +00:00
dnssec, host, Integer.parseInt(port),
2022-04-17 09:44:44 +00:00
auth, null,
user, password,
2020-02-10 15:35:14 +00:00
null, null);
2019-09-19 15:41:26 +00:00
}
}
2022-04-23 11:03:51 +00:00
boolean reschedule = (ignore_schedule != jconditions.optBoolean("ignore_schedule"));
2019-09-19 15:41:26 +00:00
try {
db.beginTransaction();
if (account != null && !account.password.equals(password)) {
2022-05-02 07:55:27 +00:00
String root = UriHelper.getRootDomain(context, account.host);
String match = (root == null || root.equals(account.host) ? account.host : "%." + root);
2022-04-17 09:44:44 +00:00
int count = db.identity().setIdentityPassword(account.id, account.user, password, auth, match);
2020-01-08 10:38:45 +00:00
Log.i("Updated passwords=" + count + " match=" + match);
2019-09-19 15:41:26 +00:00
}
boolean update = (account != null);
if (account == null)
account = new EntityAccount();
2019-11-23 12:48:59 +00:00
account.protocol = EntityAccount.TYPE_POP;
2024-01-06 15:38:22 +00:00
account.dnssec = dnssec;
2019-09-19 15:41:26 +00:00
account.host = host;
2020-08-23 07:28:10 +00:00
account.encryption = encryption;
2019-09-19 15:41:26 +00:00
account.insecure = insecure;
account.dane = dane;
2019-09-19 15:41:26 +00:00
account.port = Integer.parseInt(port);
2022-04-17 09:44:44 +00:00
account.auth_type = auth;
2019-09-19 15:41:26 +00:00
account.user = user;
account.password = password;
account.name = name;
2021-10-03 19:45:18 +00:00
account.category = category;
2019-09-19 15:41:26 +00:00
account.color = color;
account.calendar = calendar;
2019-09-19 15:41:26 +00:00
account.synchronize = synchronize;
2022-04-23 10:44:25 +00:00
jconditions.put("ignore_schedule", ignore_schedule);
2019-12-10 15:51:21 +00:00
account.ondemand = ondemand;
2019-09-19 15:41:26 +00:00
account.primary = (account.synchronize && primary);
2020-02-09 08:40:52 +00:00
account.notify = notify;
account.summary = summary;
account.auto_seen = auto_seen;
2020-01-21 14:15:48 +00:00
account.leave_on_server = leave_server;
account.client_delete = client_delete;
account.leave_deleted = leave_deleted;
2020-01-21 14:15:48 +00:00
account.leave_on_device = leave_device;
2021-02-15 19:54:10 +00:00
account.max_messages = max_messages;
account.poll_interval = poll_interval;
2019-09-19 15:41:26 +00:00
jconditions.put("unmetered", unmetered);
jconditions.put("vpn_only", vpn_only);
account.conditions = jconditions.toString();
account.swipe_left = left;
account.swipe_right = right;
2019-09-19 15:41:26 +00:00
if (!update)
account.created = now;
account.warning = null;
account.error = null;
account.last_connected = last_connected;
if (account.primary)
db.account().resetPrimary();
if (update)
2019-09-19 15:41:26 +00:00
db.account().updateAccount(account);
else
2019-09-19 15:41:26 +00:00
account.id = db.account().insertAccount(account);
args.putLong("account", account.id);
2019-09-19 15:41:26 +00:00
EntityLog.log(context, (update ? "Updated" : "Added") + " account=" + account.name);
2020-02-09 08:40:52 +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);
}
2019-09-19 15:41:26 +00:00
2022-04-17 08:18:25 +00:00
for (EntityFolder folder : EntityFolder.getPopFolders(context)) {
EntityFolder existing = db.folder().getFolderByType(account.id, folder.type);
if (existing == null) {
folder.account = account.id;
folder.id = db.folder().insertFolder(folder);
existing = folder;
}
if (account.synchronize && existing.synchronize)
EntityOperation.sync(context, existing.id, true);
2020-04-05 19:35:56 +00:00
}
2019-09-19 15:41:26 +00:00
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
2022-04-23 11:03:51 +00:00
if (reschedule)
ServiceSynchronize.reschedule(context);
else
ServiceSynchronize.eval(context, "POP3");
2019-09-19 15:41:26 +00:00
if (!synchronize) {
2022-04-13 20:27:33 +00:00
NotificationManager nm = Helper.getSystemService(context, NotificationManager.class);
2021-07-15 16:36:39 +00:00
nm.cancel("receive:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
nm.cancel("alert:" + account.id, NotificationHelper.NOTIFICATION_TAGGED);
2019-09-19 15:41:26 +00:00
}
args.putBoolean("saved", true);
2019-09-19 15:41:26 +00:00
return false;
}
@Override
protected void onExecuted(Bundle args, Boolean dirty) {
2021-02-15 19:54:10 +00:00
if (dirty) {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_ask_save));
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(aargs);
fragment.setTargetFragment(FragmentPop.this, REQUEST_SAVE);
fragment.show(getParentFragmentManager(), "account:save");
} else {
Context context = getContext();
if (context != null)
2021-02-15 19:54:10 +00:00
WidgetUnified.updateData(context); // Update color stripe
2022-06-12 07:22:55 +00:00
finish();
2021-02-15 19:54:10 +00:00
2022-06-12 07:22:55 +00:00
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
boolean saved = args.getBoolean("saved");
if (saved && cbIdentity.isChecked()) {
2021-02-15 19:54:10 +00:00
Bundle aargs = new Bundle();
aargs.putLong("account", args.getLong("account"));
FragmentIdentity fragment = new FragmentIdentity();
fragment.setArguments(aargs);
FragmentTransaction fragmentTransaction = getParentFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.enter_from_right, R.anim.leave_to_left);
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("identity");
fragmentTransaction.commit();
}
}
}
2019-09-19 15:41:26 +00:00
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
2023-12-12 19:55:55 +00:00
Snackbar.make(view, new ThrowableWrapper(ex).getSafeMessage(), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
2019-09-19 15:41:26 +00:00
else {
2019-12-06 07:50:46 +00:00
tvError.setText(Log.formatThrowable(ex, false));
2019-11-15 08:33:43 +00:00
grpError.setVisibility(View.VISIBLE);
2019-09-19 15:41:26 +00:00
2020-08-23 15:34:14 +00:00
getMainHandler().post(new Runnable() {
2019-09-19 15:41:26 +00:00
@Override
public void run() {
2021-09-28 19:15:46 +00:00
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
2019-09-19 15:41:26 +00:00
scroll.smoothScrollTo(0, tvError.getBottom());
}
});
}
}
}.execute(this, args, "account:save");
}
@Override
public void onSaveInstanceState(Bundle outState) {
2022-04-21 08:11:04 +00:00
outState.putString("fair:password", tilPassword == null ? null : tilPassword.getEditText().getText().toString());
2022-04-17 09:44:44 +00:00
outState.putInt("fair:auth", auth);
outState.putString("fair:calendar", calendar);
2019-09-19 15:41:26 +00:00
super.onSaveInstanceState(outState);
}
@Override
public void onActivityCreated(@Nullable final Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<EntityAccount>() {
@Override
protected EntityAccount onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
2023-11-13 08:40:35 +00:00
List<String> categories = db.account().getAccountCategories();
if (categories == null)
categories = new ArrayList<>();
args.putStringArrayList("categories", new ArrayList<>(categories));
2019-09-19 15:41:26 +00:00
return db.account().getAccount(id);
}
@Override
protected void onExecuted(Bundle args, final EntityAccount account) {
2023-11-13 08:40:35 +00:00
adapterCategory.clear();
adapterCategory.addAll(args.getStringArrayList("categories"));
2019-09-19 15:41:26 +00:00
if (savedInstanceState == null) {
2022-04-23 10:44:25 +00:00
JSONObject jcondition = new JSONObject();
try {
if (account != null && account.conditions != null)
jcondition = new JSONObject(account.conditions);
} catch (Throwable ex) {
Log.e(ex);
}
2024-01-06 15:38:22 +00:00
cbDnsSec.setChecked(account == null ? false : account.dnssec);
2019-09-19 15:41:26 +00:00
etHost.setText(account == null ? null : account.host);
etPort.setText(account == null ? null : Long.toString(account.port));
2020-08-23 07:28:10 +00:00
if (account != null && account.encryption == EmailService.ENCRYPTION_STARTTLS)
rgEncryption.check(R.id.radio_starttls);
else if (account != null && account.encryption == EmailService.ENCRYPTION_NONE)
rgEncryption.check(R.id.radio_none);
else
rgEncryption.check(R.id.radio_ssl);
2019-09-19 15:41:26 +00:00
cbInsecure.setChecked(account == null ? false : account.insecure);
2024-01-06 14:20:05 +00:00
cbDane.setChecked(account == null ? false : account.dane);
cbDane.setEnabled(!cbInsecure.isChecked());
2019-09-19 15:41:26 +00:00
etUser.setText(account == null ? null : account.user);
tilPassword.getEditText().setText(account == null ? null : account.password);
etName.setText(account == null ? null : account.name);
2021-10-03 19:45:18 +00:00
etCategory.setText(account == null ? null : account.category);
2019-09-29 12:45:00 +00:00
btnColor.setColor(account == null ? null : account.color);
2019-09-19 15:41:26 +00:00
cbSynchronize.setChecked(account == null ? true : account.synchronize);
2022-04-23 10:44:25 +00:00
cbIgnoreSchedule.setChecked(jcondition.optBoolean("ignore_schedule"));
cbOnDemand.setChecked(account == null ? false : account.ondemand);
cbPrimary.setChecked(account == null ? false : account.primary);
cbNotify.setChecked(account != null && account.notify);
cbSummary.setChecked(account != null && account.summary);
2020-02-09 08:40:52 +00:00
cbAutoSeen.setChecked(account == null ? true : account.auto_seen);
2020-01-21 14:15:48 +00:00
cbLeaveServer.setChecked(account == null ? true : account.leave_on_server);
cbClientDelete.setChecked(account == null ? false : account.client_delete);
cbClientDelete.setEnabled(!cbLeaveServer.isChecked());
cbLeaveDeleted.setChecked(account == null ? true : account.leave_deleted);
2020-01-21 14:15:48 +00:00
cbLeaveDevice.setChecked(account == null ? false : account.leave_on_device);
2023-02-15 16:37:15 +00:00
if (account != null && account.max_messages != null)
etMax.setText(Integer.toString(account.max_messages));
2020-05-01 05:47:02 +00:00
else
2023-02-15 16:37:15 +00:00
etMax.setText(null);
2019-09-19 15:41:26 +00:00
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
cbUnmetered.setChecked(jcondition.optBoolean("unmetered"));
cbVpnOnly.setChecked(jcondition.optBoolean("vpn_only"));
2024-01-06 09:03:38 +00:00
cbIdentity.setChecked(account == null);
2019-09-19 15:41:26 +00:00
List<EntityFolder> folders = getSwipeActions();
for (int pos = 0; pos < folders.size(); pos++) {
EntityFolder folder = folders.get(pos);
if (account == null || account.swipe_left == null
2020-07-02 08:10:47 +00:00
? EntityMessage.SWIPE_ACTION_DELETE.equals(folder.id)
: account.swipe_left.equals(folder.id))
spLeft.setSelection(pos);
if (account == null || account.swipe_right == null
2020-07-02 08:10:47 +00:00
? EntityMessage.SWIPE_ACTION_SEEN.equals(folder.id)
: account.swipe_right.equals(folder.id))
spRight.setSelection(pos);
}
2022-04-17 09:44:44 +00:00
auth = (account == null ? AUTH_TYPE_PASSWORD : account.auth_type);
calendar = (account == null ? null : account.calendar);
2022-04-17 09:44:44 +00:00
2019-09-19 15:41:26 +00:00
new SimpleTask<EntityAccount>() {
@Override
protected EntityAccount onExecute(Context context, Bundle args) {
return DB.getInstance(context).account().getPrimaryAccount();
}
@Override
protected void onExecuted(Bundle args, EntityAccount primary) {
if (primary == null)
cbPrimary.setChecked(true);
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
2019-09-19 15:41:26 +00:00
}
}.execute(FragmentPop.this, new Bundle(), "account:primary");
} else {
tilPassword.getEditText().setText(savedInstanceState.getString("fair:password"));
2022-04-17 09:44:44 +00:00
auth = savedInstanceState.getInt("fair:auth");
calendar = savedInstanceState.getString("fair:calendar");
2019-09-19 15:41:26 +00:00
}
Helper.setViewsEnabled(view, true);
boolean pro = ActivityBilling.isPro(getContext());
cbNotify.setEnabled(pro);
cbSummary.setEnabled(pro && cbNotify.isChecked());
2019-09-19 15:41:26 +00:00
2022-04-17 09:44:44 +00:00
if (auth != AUTH_TYPE_PASSWORD) {
etUser.setEnabled(false);
2022-09-17 07:52:08 +00:00
tilPassword.getEditText().setEnabled(false);
2022-04-17 09:44:44 +00:00
}
2022-04-23 10:44:25 +00:00
cbIgnoreSchedule.setEnabled(cbSynchronize.isChecked());
2019-12-10 15:51:21 +00:00
cbOnDemand.setEnabled(cbSynchronize.isChecked());
cbPrimary.setEnabled(cbSynchronize.isChecked());
2019-09-19 15:41:26 +00:00
pbWait.setVisibility(View.GONE);
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
2019-09-19 15:41:26 +00:00
}
}.execute(this, args, "account:get");
}
@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) {
menu.findItem(R.id.menu_delete).setVisible(id > 0 && !saving);
super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
2021-02-05 10:15:02 +00:00
if (item.getItemId() == R.id.menu_delete) {
onMenuDelete();
return true;
2019-09-19 15:41:26 +00:00
}
2021-02-05 10:15:02 +00:00
return super.onOptionsItemSelected(item);
2019-09-19 15:41:26 +00:00
}
private void onMenuDelete() {
Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_account_delete));
2020-10-25 13:55:58 +00:00
aargs.putBoolean("warning", true);
2019-09-19 15:41:26 +00:00
FragmentDialogAsk fragment = new FragmentDialogAsk();
fragment.setArguments(aargs);
fragment.setTargetFragment(FragmentPop.this, REQUEST_DELETE);
2019-10-12 15:16:53 +00:00
fragment.show(getParentFragmentManager(), "account:delete");
2019-09-19 15:41:26 +00:00
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case REQUEST_COLOR:
2019-09-19 15:41:26 +00:00
if (resultCode == RESULT_OK && data != null) {
if (ActivityBilling.isPro(getContext())) {
Bundle args = data.getBundleExtra("args");
2019-09-29 12:45:00 +00:00
btnColor.setColor(args.getInt("color"));
2019-09-19 15:41:26 +00:00
} else
startActivity(new Intent(getContext(), ActivityBilling.class));
}
break;
case REQUEST_CALENDAR:
if (resultCode == RESULT_OK && data != null) {
if (ActivityBilling.isPro(getContext())) {
Bundle args = data.getBundleExtra("args");
2022-11-03 10:36:34 +00:00
JSONObject jobject = new JSONObject();
jobject.put("id", args.getLong("id"));
jobject.put("account", args.getString("account"));
jobject.put("type", args.getString("type"));
jobject.put("name", args.getString("name"));
calendar = jobject.toString();
} else
startActivity(new Intent(getContext(), ActivityBilling.class));
}
break;
2021-02-15 19:54:10 +00:00
case REQUEST_SAVE:
if (resultCode == RESULT_OK) {
getMainHandler().post(new Runnable() {
@Override
public void run() {
2021-09-28 19:15:46 +00:00
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;
2021-02-15 19:54:10 +00:00
scroll.smoothScrollTo(0, btnSave.getBottom());
}
});
onSave(false);
2022-06-12 07:22:55 +00:00
} else
finish();
2021-02-15 19:54:10 +00:00
break;
case REQUEST_DELETE:
2019-09-19 15:41:26 +00:00
if (resultCode == RESULT_OK)
onDelete();
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onDelete() {
Bundle args = new Bundle();
args.putLong("id", id);
new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
Helper.setViewsEnabled(view, false);
pbWait.setVisibility(View.VISIBLE);
}
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
db.account().setAccountTbd(id);
ServiceSynchronize.eval(context, "delete account");
2019-09-19 15:41:26 +00:00
return null;
}
@Override
protected void onExecuted(Bundle args, Void data) {
2022-06-12 07:22:55 +00:00
finish();
2019-09-19 15:41:26 +00:00
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(getParentFragmentManager(), ex);
2019-09-19 15:41:26 +00:00
}
}.execute(this, args, "account:delete");
}
private List<EntityFolder> getSwipeActions() {
List<EntityFolder> folders = new ArrayList<>();
2020-07-01 06:11:28 +00:00
EntityFolder ask = new EntityFolder();
2020-07-02 08:10:47 +00:00
ask.id = EntityMessage.SWIPE_ACTION_ASK;
2020-07-01 06:11:28 +00:00
ask.name = getString(R.string.title_ask_what);
folders.add(ask);
EntityFolder seen = new EntityFolder();
2020-07-02 08:10:47 +00:00
seen.id = EntityMessage.SWIPE_ACTION_SEEN;
seen.name = getString(R.string.title_seen);
folders.add(seen);
EntityFolder flag = new EntityFolder();
2020-07-02 08:10:47 +00:00
flag.id = EntityMessage.SWIPE_ACTION_FLAG;
flag.name = getString(R.string.title_flag);
folders.add(flag);
2023-12-02 16:10:39 +00:00
EntityFolder importance = new EntityFolder();
importance.id = EntityMessage.SWIPE_ACTION_IMPORTANCE;
importance.name = getString(R.string.title_set_importance);
folders.add(importance);
EntityFolder snooze = new EntityFolder();
2020-07-02 08:10:47 +00:00
snooze.id = EntityMessage.SWIPE_ACTION_SNOOZE;
snooze.name = getString(R.string.title_snooze_now);
folders.add(snooze);
EntityFolder hide = new EntityFolder();
2020-07-02 08:10:47 +00:00
hide.id = EntityMessage.SWIPE_ACTION_HIDE;
hide.name = getString(R.string.title_hide);
folders.add(hide);
2022-06-05 08:01:02 +00:00
EntityFolder junk = new EntityFolder();
junk.id = EntityMessage.SWIPE_ACTION_JUNK;
junk.name = getString(R.string.title_report_spam);
folders.add(junk);
EntityFolder delete = new EntityFolder();
2020-07-02 08:10:47 +00:00
delete.id = EntityMessage.SWIPE_ACTION_DELETE;
delete.name = getString(R.string.title_delete_permanently);
folders.add(delete);
return folders;
}
2019-09-19 15:41:26 +00:00
}