2019-05-06 07:10:13 +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/>.
|
|
|
|
|
2022-01-01 08:46:36 +00:00
|
|
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
2019-05-06 07:10:13 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-29 10:05:30 +00:00
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2021-03-25 06:59:13 +00:00
|
|
|
import android.content.Intent;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.content.SharedPreferences;
|
2020-03-20 12:08:12 +00:00
|
|
|
import android.os.Build;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.os.Bundle;
|
2020-03-15 09:52:19 +00:00
|
|
|
import android.text.Editable;
|
2019-07-26 08:23:34 +00:00
|
|
|
import android.text.TextUtils;
|
2020-03-15 09:52:19 +00:00
|
|
|
import android.text.TextWatcher;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.view.LayoutInflater;
|
2019-05-06 12:41:03 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-07-26 08:23:34 +00:00
|
|
|
import android.widget.AdapterView;
|
2020-03-29 10:05:30 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.Button;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.widget.CompoundButton;
|
2020-03-15 09:52:19 +00:00
|
|
|
import android.widget.EditText;
|
2022-05-08 06:20:59 +00:00
|
|
|
import android.widget.ImageButton;
|
2021-07-26 19:12:03 +00:00
|
|
|
import android.widget.SeekBar;
|
2019-07-26 08:23:34 +00:00
|
|
|
import android.widget.Spinner;
|
2021-03-25 06:59:13 +00:00
|
|
|
import android.widget.TextView;
|
2019-07-14 10:32:32 +00:00
|
|
|
import android.widget.Toast;
|
2019-05-06 07:10:13 +00:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2020-03-29 10:05:30 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-05-06 07:10:13 +00:00
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
2022-06-24 20:53:26 +00:00
|
|
|
import androidx.lifecycle.Lifecycle;
|
2021-03-25 06:59:13 +00:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
2019-05-06 07:10:13 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
2020-03-29 10:05:30 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2022-07-14 13:16:55 +00:00
|
|
|
private View view;
|
2022-05-08 06:20:59 +00:00
|
|
|
private ImageButton ibHelp;
|
2022-06-24 10:15:41 +00:00
|
|
|
private SwitchCompat swRestoreOnLaunch;
|
|
|
|
private TextView tvRestoreOnLaunchHint;
|
2020-12-14 17:55:02 +00:00
|
|
|
private SwitchCompat swSyncOnlaunch;
|
2019-10-20 08:22:21 +00:00
|
|
|
private SwitchCompat swDoubleBack;
|
2020-03-20 12:08:12 +00:00
|
|
|
private SwitchCompat swConversationActions;
|
|
|
|
private SwitchCompat swConversationActionsReplies;
|
2020-03-26 14:34:42 +00:00
|
|
|
private SwitchCompat swLanguageDetection;
|
2020-03-15 09:52:19 +00:00
|
|
|
private EditText etDefaultSnooze;
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swPull;
|
|
|
|
private SwitchCompat swAutoScroll;
|
2020-03-15 09:52:19 +00:00
|
|
|
private SwitchCompat swQuickFilter;
|
|
|
|
private SwitchCompat swQuickScroll;
|
2020-03-29 10:05:30 +00:00
|
|
|
private Button btnSwipes;
|
2021-07-26 19:12:03 +00:00
|
|
|
private SeekBar sbSwipeSensitivity;
|
2022-02-19 21:56:19 +00:00
|
|
|
private SwitchCompat swFolderNav;
|
2019-09-29 16:44:59 +00:00
|
|
|
private SwitchCompat swDoubleTap;
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swSwipeNav;
|
2020-01-30 19:52:18 +00:00
|
|
|
private SwitchCompat swVolumeNav;
|
2019-09-17 09:31:28 +00:00
|
|
|
private SwitchCompat swReversed;
|
2020-07-20 14:16:32 +00:00
|
|
|
private SwitchCompat swSwipeClose;
|
2020-08-08 12:01:56 +00:00
|
|
|
private SwitchCompat swSwipeMove;
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swAutoExpand;
|
2021-03-27 07:30:20 +00:00
|
|
|
private SwitchCompat swExpandFirst;
|
2019-10-10 16:06:44 +00:00
|
|
|
private SwitchCompat swExpandAll;
|
2019-09-14 16:51:51 +00:00
|
|
|
private SwitchCompat swExpandOne;
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swAutoClose;
|
2021-03-25 06:59:13 +00:00
|
|
|
private TextView tvAutoSeenHint;
|
2021-06-27 07:31:20 +00:00
|
|
|
private TextView tvOnClose;
|
2019-07-26 08:23:34 +00:00
|
|
|
private Spinner spOnClose;
|
2021-07-30 06:26:37 +00:00
|
|
|
private SwitchCompat swAutoCloseUnseen;
|
2021-09-29 07:41:32 +00:00
|
|
|
private SwitchCompat swCollapseMarked;
|
2020-07-18 09:21:24 +00:00
|
|
|
private Spinner spUndoTimeout;
|
2019-10-09 17:23:03 +00:00
|
|
|
private SwitchCompat swCollapseMultiple;
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swAutoRead;
|
2020-02-16 12:49:05 +00:00
|
|
|
private SwitchCompat swFlagSnoozed;
|
2019-09-28 18:25:19 +00:00
|
|
|
private SwitchCompat swAutoUnflag;
|
2020-02-20 14:50:26 +00:00
|
|
|
private SwitchCompat swAutoImportant;
|
2020-02-03 18:25:46 +00:00
|
|
|
private SwitchCompat swResetImportance;
|
2021-11-22 12:51:40 +00:00
|
|
|
private SwitchCompat swSwipeReply;
|
2019-05-06 07:10:13 +00:00
|
|
|
|
2021-07-27 12:38:08 +00:00
|
|
|
final static int MAX_SWIPE_SENSITIVITY = 10;
|
|
|
|
final static int DEFAULT_SWIPE_SENSITIVITY = 7;
|
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
private final static String[] RESET_OPTIONS = new String[]{
|
2022-06-24 10:15:41 +00:00
|
|
|
"restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection",
|
2020-03-26 14:34:42 +00:00
|
|
|
"default_snooze",
|
2022-02-19 21:56:19 +00:00
|
|
|
"pull", "autoscroll", "quick_filter", "quick_scroll", "swipe_sensitivity", "foldernav",
|
2020-08-08 12:01:56 +00:00
|
|
|
"doubletap", "swipenav", "volumenav", "reversed", "swipe_close", "swipe_move",
|
2021-03-27 07:30:20 +00:00
|
|
|
"autoexpand", "expand_first", "expand_all", "expand_one", "collapse_multiple",
|
2021-09-29 07:41:32 +00:00
|
|
|
"autoclose", "onclose", "autoclose_unseen", "collapse_marked",
|
2021-07-30 06:26:37 +00:00
|
|
|
"undo_timeout",
|
2021-11-22 12:51:40 +00:00
|
|
|
"autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance",
|
|
|
|
"swipe_reply"
|
2019-05-06 12:41:03 +00:00
|
|
|
};
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2019-06-12 14:15:46 +00:00
|
|
|
setSubtitle(R.string.title_setup);
|
2019-05-06 12:41:03 +00:00
|
|
|
setHasOptionsMenu(true);
|
2019-05-06 07:10:13 +00:00
|
|
|
|
2022-07-14 13:16:55 +00:00
|
|
|
view = inflater.inflate(R.layout.fragment_options_behavior, container, false);
|
2019-05-06 07:10:13 +00:00
|
|
|
|
|
|
|
// Get controls
|
|
|
|
|
2022-05-08 06:20:59 +00:00
|
|
|
ibHelp = view.findViewById(R.id.ibHelp);
|
2022-06-24 10:15:41 +00:00
|
|
|
swRestoreOnLaunch = view.findViewById(R.id.swRestoreOnLaunch);
|
|
|
|
tvRestoreOnLaunchHint = view.findViewById(R.id.tvRestoreOnLaunchHint);
|
2020-12-14 17:55:02 +00:00
|
|
|
swSyncOnlaunch = view.findViewById(R.id.swSyncOnlaunch);
|
2019-10-20 08:22:21 +00:00
|
|
|
swDoubleBack = view.findViewById(R.id.swDoubleBack);
|
2020-03-20 12:08:12 +00:00
|
|
|
swConversationActions = view.findViewById(R.id.swConversationActions);
|
|
|
|
swConversationActionsReplies = view.findViewById(R.id.swConversationActionsReplies);
|
2020-03-26 14:34:42 +00:00
|
|
|
swLanguageDetection = view.findViewById(R.id.swLanguageDetection);
|
2020-03-15 09:52:19 +00:00
|
|
|
etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze);
|
2019-05-06 07:10:13 +00:00
|
|
|
swPull = view.findViewById(R.id.swPull);
|
|
|
|
swAutoScroll = view.findViewById(R.id.swAutoScroll);
|
2020-03-15 09:52:19 +00:00
|
|
|
swQuickFilter = view.findViewById(R.id.swQuickFilter);
|
|
|
|
swQuickScroll = view.findViewById(R.id.swQuickScroll);
|
2020-03-29 10:05:30 +00:00
|
|
|
btnSwipes = view.findViewById(R.id.btnSwipes);
|
2021-07-26 19:12:03 +00:00
|
|
|
sbSwipeSensitivity = view.findViewById(R.id.sbSwipeSensitivity);
|
2022-02-19 21:56:19 +00:00
|
|
|
swFolderNav = view.findViewById(R.id.swFolderNav);
|
2019-09-29 16:44:59 +00:00
|
|
|
swDoubleTap = view.findViewById(R.id.swDoubleTap);
|
2019-05-06 07:10:13 +00:00
|
|
|
swSwipeNav = view.findViewById(R.id.swSwipeNav);
|
2020-01-30 19:52:18 +00:00
|
|
|
swVolumeNav = view.findViewById(R.id.swVolumeNav);
|
2019-09-17 09:31:28 +00:00
|
|
|
swReversed = view.findViewById(R.id.swReversed);
|
2020-07-20 14:16:32 +00:00
|
|
|
swSwipeClose = view.findViewById(R.id.swSwipeClose);
|
2020-08-08 12:01:56 +00:00
|
|
|
swSwipeMove = view.findViewById(R.id.swSwipeMove);
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoExpand = view.findViewById(R.id.swAutoExpand);
|
2021-03-27 07:30:20 +00:00
|
|
|
swExpandFirst = view.findViewById(R.id.swExpandFirst);
|
2019-10-10 16:06:44 +00:00
|
|
|
swExpandAll = view.findViewById(R.id.swExpandAll);
|
2019-09-14 16:51:51 +00:00
|
|
|
swExpandOne = view.findViewById(R.id.swExpandOne);
|
2019-10-09 17:23:03 +00:00
|
|
|
swCollapseMultiple = view.findViewById(R.id.swCollapseMultiple);
|
2021-03-25 06:59:13 +00:00
|
|
|
tvAutoSeenHint = view.findViewById(R.id.tvAutoSeenHint);
|
2019-10-11 08:50:55 +00:00
|
|
|
swAutoClose = view.findViewById(R.id.swAutoClose);
|
2021-06-27 07:31:20 +00:00
|
|
|
tvOnClose = view.findViewById(R.id.tvOnClose);
|
2019-10-11 08:50:55 +00:00
|
|
|
spOnClose = view.findViewById(R.id.spOnClose);
|
2021-07-30 06:26:37 +00:00
|
|
|
swAutoCloseUnseen = view.findViewById(R.id.swAutoCloseUnseen);
|
2021-09-29 07:41:32 +00:00
|
|
|
swCollapseMarked = view.findViewById(R.id.swCollapseMarked);
|
2020-07-18 09:21:24 +00:00
|
|
|
spUndoTimeout = view.findViewById(R.id.spUndoTimeout);
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoRead = view.findViewById(R.id.swAutoRead);
|
2020-02-16 12:49:05 +00:00
|
|
|
swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed);
|
2019-09-28 18:25:19 +00:00
|
|
|
swAutoUnflag = view.findViewById(R.id.swAutoUnflag);
|
2020-02-20 14:50:26 +00:00
|
|
|
swAutoImportant = view.findViewById(R.id.swAutoImportant);
|
2020-02-03 18:25:46 +00:00
|
|
|
swResetImportance = view.findViewById(R.id.swResetImportance);
|
2021-11-22 12:51:40 +00:00
|
|
|
swSwipeReply = view.findViewById(R.id.swSwipeReply);
|
2019-05-06 07:10:13 +00:00
|
|
|
|
2019-05-06 13:30:30 +00:00
|
|
|
setOptions();
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
// Wire controls
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
2022-05-08 06:20:59 +00:00
|
|
|
ibHelp.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2022-05-15 08:19:48 +00:00
|
|
|
Helper.view(v.getContext(), Helper.getSupportUri(v.getContext(), "Options:behavior"), false);
|
2022-05-08 06:20:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-20 08:22:21 +00:00
|
|
|
swDoubleBack.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("double_back", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-24 10:15:41 +00:00
|
|
|
tvRestoreOnLaunchHint.setText(getString(R.string.title_advanced_restore_on_launch_hint, ActivityMain.RESTORE_STATE_INTERVAL));
|
|
|
|
swRestoreOnLaunch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("restore_on_launch", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-14 17:55:02 +00:00
|
|
|
swSyncOnlaunch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("sync_on_launch", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-18 11:01:10 +00:00
|
|
|
swConversationActions.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
|
2020-03-20 12:08:12 +00:00
|
|
|
swConversationActions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("conversation_actions", checked).apply();
|
2021-03-19 13:25:22 +00:00
|
|
|
swConversationActionsReplies.setEnabled(checked && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
|
2020-03-20 12:08:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-18 11:01:10 +00:00
|
|
|
swConversationActionsReplies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
|
2020-03-20 12:08:12 +00:00
|
|
|
swConversationActionsReplies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("conversation_actions_replies", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-26 14:34:42 +00:00
|
|
|
swLanguageDetection.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("language_detection", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-15 09:52:19 +00:00
|
|
|
etDefaultSnooze.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) {
|
|
|
|
try {
|
|
|
|
int default_snooze = (s.length() > 0 ? Integer.parseInt(s.toString()) : 1);
|
|
|
|
if (default_snooze == 1)
|
|
|
|
prefs.edit().remove("default_snooze").apply();
|
|
|
|
else
|
|
|
|
prefs.edit().putInt("default_snooze", default_snooze).apply();
|
|
|
|
} catch (NumberFormatException ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void afterTextChanged(Editable s) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("pull", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swAutoScroll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoscroll", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-15 09:52:19 +00:00
|
|
|
swQuickFilter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("quick_filter", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swQuickScroll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("quick_scroll", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-03-29 10:05:30 +00:00
|
|
|
btnSwipes.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
new FragmentDialogSwipes().show(getParentFragmentManager(), "setup:swipe");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-27 12:38:08 +00:00
|
|
|
sbSwipeSensitivity.setMax(MAX_SWIPE_SENSITIVITY);
|
|
|
|
|
2021-07-26 19:12:03 +00:00
|
|
|
sbSwipeSensitivity.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
|
|
prefs.edit().putInt("swipe_sensitivity", progress).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-02-19 21:56:19 +00:00
|
|
|
swFolderNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("foldernav", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-29 16:44:59 +00:00
|
|
|
swDoubleTap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2019-05-06 07:10:13 +00:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
2019-09-29 16:44:59 +00:00
|
|
|
prefs.edit().putBoolean("doubletap", checked).apply();
|
2019-09-14 07:56:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-29 16:44:59 +00:00
|
|
|
swSwipeNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2019-09-14 07:56:09 +00:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
2019-09-29 16:44:59 +00:00
|
|
|
prefs.edit().putBoolean("swipenav", checked).apply();
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-30 19:52:18 +00:00
|
|
|
swVolumeNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("volumenav", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-29 16:44:59 +00:00
|
|
|
swReversed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2019-06-26 11:55:35 +00:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
2019-09-29 16:44:59 +00:00
|
|
|
prefs.edit().putBoolean("reversed", checked).apply();
|
2019-06-26 11:55:35 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-20 14:16:32 +00:00
|
|
|
swSwipeClose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("swipe_close", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-08-08 12:01:56 +00:00
|
|
|
swSwipeMove.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("swipe_move", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoExpand.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoexpand", checked).apply();
|
2021-03-27 07:30:20 +00:00
|
|
|
swExpandFirst.setEnabled(checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swExpandFirst.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("expand_first", checked).apply();
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-10 16:06:44 +00:00
|
|
|
swExpandAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("expand_all", checked).apply();
|
|
|
|
swExpandOne.setEnabled(!checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-14 16:51:51 +00:00
|
|
|
swExpandOne.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("expand_one", checked).apply();
|
2019-10-11 08:50:55 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swCollapseMultiple.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("collapse_multiple", checked).apply();
|
2019-09-14 16:51:51 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-03-25 06:59:13 +00:00
|
|
|
tvAutoSeenHint.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(v.getContext());
|
|
|
|
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_VIEW_ACCOUNTS));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoClose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoclose", checked).apply();
|
2021-06-27 07:31:20 +00:00
|
|
|
tvOnClose.setEnabled(!checked);
|
2019-07-26 08:23:34 +00:00
|
|
|
spOnClose.setEnabled(!checked);
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-26 08:23:34 +00:00
|
|
|
spOnClose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
2019-05-06 07:10:13 +00:00
|
|
|
@Override
|
2019-07-26 08:23:34 +00:00
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
String[] values = getResources().getStringArray(R.array.onCloseValues);
|
|
|
|
String value = values[position];
|
|
|
|
if (TextUtils.isEmpty(value))
|
|
|
|
prefs.edit().remove("onclose").apply();
|
|
|
|
else
|
|
|
|
prefs.edit().putString("onclose", value).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
prefs.edit().remove("onclose").apply();
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-30 06:26:37 +00:00
|
|
|
swAutoCloseUnseen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoclose_unseen", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-09-29 07:41:32 +00:00
|
|
|
swCollapseMarked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("collapse_marked", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-18 09:21:24 +00:00
|
|
|
spUndoTimeout.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
int[] values = getResources().getIntArray(R.array.undoValues);
|
|
|
|
int value = values[position];
|
|
|
|
prefs.edit().putInt("undo_timeout", value).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
prefs.edit().remove("undo_timeout").apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoRead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoread", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-16 12:49:05 +00:00
|
|
|
swFlagSnoozed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("flag_snoozed", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-28 18:25:19 +00:00
|
|
|
swAutoUnflag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autounflag", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-20 14:50:26 +00:00
|
|
|
swAutoImportant.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("auto_important", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-02-03 18:25:46 +00:00
|
|
|
swResetImportance.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("reset_importance", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-22 12:51:40 +00:00
|
|
|
swSwipeReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("swipe_reply", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-05-12 06:45:56 +00:00
|
|
|
// Initialize
|
2021-06-27 06:13:56 +00:00
|
|
|
FragmentDialogTheme.setBackground(getContext(), view, false);
|
2021-05-12 06:45:56 +00:00
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2020-03-15 09:52:19 +00:00
|
|
|
if ("default_snooze".equals(key))
|
|
|
|
return;
|
|
|
|
|
2022-06-13 11:28:29 +00:00
|
|
|
setOptions();
|
2019-05-06 12:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_options, menu);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2021-02-05 10:15:02 +00:00
|
|
|
if (item.getItemId() == R.id.menu_default) {
|
2021-06-26 13:50:20 +00:00
|
|
|
FragmentOptions.reset(getContext(), RESET_OPTIONS, null);
|
2021-02-05 10:15:02 +00:00
|
|
|
return true;
|
2019-05-06 12:41:03 +00:00
|
|
|
}
|
2021-02-05 10:15:02 +00:00
|
|
|
return super.onOptionsItemSelected(item);
|
2019-05-06 12:41:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
private void setOptions() {
|
2022-07-14 13:16:55 +00:00
|
|
|
if (view == null || getContext() == null)
|
2022-06-24 20:53:26 +00:00
|
|
|
return;
|
2022-06-13 11:28:29 +00:00
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
2022-07-01 05:45:42 +00:00
|
|
|
swRestoreOnLaunch.setChecked(prefs.getBoolean("restore_on_launch", false));
|
2020-12-14 17:55:02 +00:00
|
|
|
swSyncOnlaunch.setChecked(prefs.getBoolean("sync_on_launch", false));
|
2021-03-25 16:08:25 +00:00
|
|
|
swDoubleBack.setChecked(prefs.getBoolean("double_back", false));
|
2021-11-04 06:26:37 +00:00
|
|
|
swConversationActions.setChecked(prefs.getBoolean("conversation_actions", Helper.isGoogle()));
|
2020-03-20 12:08:12 +00:00
|
|
|
swConversationActionsReplies.setChecked(prefs.getBoolean("conversation_actions_replies", true));
|
|
|
|
swConversationActionsReplies.setEnabled(swConversationActions.isChecked());
|
2020-03-26 19:28:17 +00:00
|
|
|
swLanguageDetection.setChecked(prefs.getBoolean("language_detection", false));
|
2020-03-26 14:34:42 +00:00
|
|
|
|
2020-03-15 09:52:19 +00:00
|
|
|
int default_snooze = prefs.getInt("default_snooze", 1);
|
|
|
|
etDefaultSnooze.setText(default_snooze == 1 ? null : Integer.toString(default_snooze));
|
|
|
|
etDefaultSnooze.setHint("1");
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swPull.setChecked(prefs.getBoolean("pull", true));
|
2021-01-20 13:03:14 +00:00
|
|
|
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false));
|
2020-03-15 09:52:19 +00:00
|
|
|
swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false));
|
|
|
|
swQuickScroll.setChecked(prefs.getBoolean("quick_scroll", true));
|
|
|
|
|
2021-07-27 12:38:08 +00:00
|
|
|
int swipe_sensitivity = prefs.getInt("swipe_sensitivity", DEFAULT_SWIPE_SENSITIVITY);
|
2021-07-26 19:12:03 +00:00
|
|
|
sbSwipeSensitivity.setProgress(swipe_sensitivity);
|
|
|
|
|
2022-02-19 21:56:19 +00:00
|
|
|
swFolderNav.setChecked(prefs.getBoolean("foldernav", false));
|
|
|
|
|
2021-02-07 10:07:48 +00:00
|
|
|
swDoubleTap.setChecked(prefs.getBoolean("doubletap", true));
|
2019-05-06 07:10:13 +00:00
|
|
|
swSwipeNav.setChecked(prefs.getBoolean("swipenav", true));
|
2020-01-30 19:52:18 +00:00
|
|
|
swVolumeNav.setChecked(prefs.getBoolean("volumenav", false));
|
2019-09-17 09:31:28 +00:00
|
|
|
swReversed.setChecked(prefs.getBoolean("reversed", false));
|
2020-07-20 14:16:32 +00:00
|
|
|
swSwipeClose.setChecked(prefs.getBoolean("swipe_close", false));
|
2020-08-08 12:01:56 +00:00
|
|
|
swSwipeMove.setChecked(prefs.getBoolean("swipe_move", false));
|
2019-10-11 08:50:55 +00:00
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoExpand.setChecked(prefs.getBoolean("autoexpand", true));
|
2021-03-27 07:30:20 +00:00
|
|
|
swExpandFirst.setChecked(prefs.getBoolean("expand_first", true));
|
|
|
|
swExpandFirst.setEnabled(swAutoExpand.isChecked());
|
2019-10-10 16:06:44 +00:00
|
|
|
swExpandAll.setChecked(prefs.getBoolean("expand_all", false));
|
2019-09-17 15:24:11 +00:00
|
|
|
swExpandOne.setChecked(prefs.getBoolean("expand_one", true));
|
2019-10-10 16:06:44 +00:00
|
|
|
swExpandOne.setEnabled(!swExpandAll.isChecked());
|
2019-10-11 08:50:55 +00:00
|
|
|
swCollapseMultiple.setChecked(prefs.getBoolean("collapse_multiple", true));
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoClose.setChecked(prefs.getBoolean("autoclose", true));
|
2019-07-26 08:23:34 +00:00
|
|
|
|
|
|
|
String onClose = prefs.getString("onclose", "");
|
|
|
|
String[] onCloseValues = getResources().getStringArray(R.array.onCloseValues);
|
|
|
|
for (int pos = 0; pos < onCloseValues.length; pos++)
|
|
|
|
if (onCloseValues[pos].equals(onClose)) {
|
|
|
|
spOnClose.setSelection(pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-27 07:31:20 +00:00
|
|
|
tvOnClose.setEnabled(!swAutoClose.isChecked());
|
2019-07-26 08:23:34 +00:00
|
|
|
spOnClose.setEnabled(!swAutoClose.isChecked());
|
|
|
|
|
2021-07-30 06:26:37 +00:00
|
|
|
swAutoCloseUnseen.setChecked(prefs.getBoolean("autoclose_unseen", false));
|
2021-09-29 07:41:32 +00:00
|
|
|
swCollapseMarked.setChecked(prefs.getBoolean("collapse_marked", true));
|
2021-07-30 06:26:37 +00:00
|
|
|
|
2020-07-18 09:21:24 +00:00
|
|
|
int undo_timeout = prefs.getInt("undo_timeout", 5000);
|
|
|
|
int[] undoValues = getResources().getIntArray(R.array.undoValues);
|
|
|
|
for (int pos = 0; pos < undoValues.length; pos++)
|
|
|
|
if (undoValues[pos] == undo_timeout) {
|
|
|
|
spUndoTimeout.setSelection(pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
swAutoRead.setChecked(prefs.getBoolean("autoread", false));
|
2020-02-16 12:49:05 +00:00
|
|
|
swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false));
|
2019-09-28 18:25:19 +00:00
|
|
|
swAutoUnflag.setChecked(prefs.getBoolean("autounflag", false));
|
2020-02-20 14:50:26 +00:00
|
|
|
swAutoImportant.setChecked(prefs.getBoolean("auto_important", false));
|
2020-02-03 18:25:46 +00:00
|
|
|
swResetImportance.setChecked(prefs.getBoolean("reset_importance", false));
|
2021-11-22 12:51:40 +00:00
|
|
|
swSwipeReply.setChecked(prefs.getBoolean("swipe_reply", false));
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
2020-03-29 10:05:30 +00:00
|
|
|
|
|
|
|
public static class FragmentDialogSwipes extends FragmentDialogBase {
|
|
|
|
private Spinner spLeft;
|
|
|
|
private Spinner spRight;
|
|
|
|
private ArrayAdapter<EntityFolder> adapter;
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
2020-10-30 09:36:16 +00:00
|
|
|
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_swipes, null);
|
2020-03-29 10:05:30 +00:00
|
|
|
spLeft = dview.findViewById(R.id.spLeft);
|
|
|
|
spRight = dview.findViewById(R.id.spRight);
|
|
|
|
|
2020-10-30 09:36:16 +00:00
|
|
|
adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityFolder>());
|
2020-03-29 10:05:30 +00:00
|
|
|
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
|
|
|
|
|
|
|
spLeft.setAdapter(adapter);
|
|
|
|
spRight.setAdapter(adapter);
|
|
|
|
|
2020-10-30 09:36:16 +00:00
|
|
|
List<EntityFolder> folders = FragmentAccount.getFolderActions(getContext());
|
2020-03-29 10:05:30 +00:00
|
|
|
|
|
|
|
EntityFolder trash = new EntityFolder();
|
|
|
|
trash.id = 2L;
|
|
|
|
trash.name = getString(R.string.title_trash);
|
|
|
|
folders.add(1, trash);
|
|
|
|
|
|
|
|
EntityFolder archive = new EntityFolder();
|
|
|
|
archive.id = 1L;
|
|
|
|
archive.name = getString(R.string.title_archive);
|
|
|
|
folders.add(1, archive);
|
|
|
|
|
|
|
|
adapter.addAll(folders);
|
|
|
|
|
2020-10-30 09:36:16 +00:00
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
2020-04-01 11:30:33 +00:00
|
|
|
int leftPos = prefs.getInt("swipe_left_default", 2); // Trash
|
|
|
|
int rightPos = prefs.getInt("swipe_right_default", 1); // Archive
|
|
|
|
|
|
|
|
spLeft.setSelection(leftPos);
|
|
|
|
spRight.setSelection(rightPos);
|
2020-03-29 10:05:30 +00:00
|
|
|
|
2020-10-30 09:36:16 +00:00
|
|
|
return new AlertDialog.Builder(getContext())
|
2020-03-29 10:05:30 +00:00
|
|
|
.setView(dview)
|
|
|
|
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2020-04-01 11:30:33 +00:00
|
|
|
prefs.edit()
|
|
|
|
.putInt("swipe_left_default", spLeft.getSelectedItemPosition())
|
|
|
|
.putInt("swipe_right_default", spRight.getSelectedItemPosition())
|
|
|
|
.apply();
|
|
|
|
|
2020-03-29 10:05:30 +00:00
|
|
|
EntityFolder left = (EntityFolder) spLeft.getSelectedItem();
|
|
|
|
EntityFolder right = (EntityFolder) spRight.getSelectedItem();
|
|
|
|
|
2022-04-08 14:36:41 +00:00
|
|
|
if ((left != null && EntityMessage.SWIPE_ACTION_HIDE.equals(left.id)) ||
|
|
|
|
(right != null && EntityMessage.SWIPE_ACTION_HIDE.equals(right.id)))
|
|
|
|
prefs.edit().putBoolean("button_hide", true).apply();
|
2020-10-30 09:36:16 +00:00
|
|
|
|
2020-03-29 10:05:30 +00:00
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("left", left == null ? 0 : left.id);
|
|
|
|
args.putLong("right", right == null ? 0 : right.id);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long left = args.getLong("left");
|
|
|
|
long right = args.getLong("right");
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
|
|
|
|
List<EntityAccount> accounts = db.account().getAccounts();
|
|
|
|
for (EntityAccount account : accounts)
|
|
|
|
if (account.protocol == EntityAccount.TYPE_IMAP)
|
|
|
|
db.account().setAccountSwipes(
|
|
|
|
account.id,
|
|
|
|
getAction(context, left, account.id),
|
|
|
|
getAction(context, right, account.id));
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
2022-04-08 14:36:41 +00:00
|
|
|
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
|
2020-03-29 10:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Log.unexpectedError(getParentFragmentManager(), ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Long getAction(Context context, long selection, long account) {
|
|
|
|
if (selection < 0)
|
|
|
|
return selection;
|
|
|
|
else if (selection == 0)
|
|
|
|
return null;
|
|
|
|
else {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
String type = (selection == 2 ? EntityFolder.TRASH : EntityFolder.ARCHIVE);
|
|
|
|
EntityFolder archive = db.folder().getFolderByType(account, type);
|
|
|
|
return (archive == null ? null : archive.id);
|
|
|
|
}
|
|
|
|
}
|
2020-10-30 09:36:16 +00:00
|
|
|
}.execute(getContext(), getViewLifecycleOwner(), args, "dialog:swipe");
|
2020-03-29 10:05:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.create();
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|