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

805 lines
35 KiB
Java
Raw Normal View History

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/>.
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
2019-05-06 07:10:13 +00:00
*/
2023-01-27 08:56:32 +00:00
import static android.app.Activity.RESULT_OK;
import android.content.Intent;
2019-05-06 07:10:13 +00:00
import android.content.SharedPreferences;
2023-01-27 08:56:32 +00:00
import android.content.pm.PackageManager;
import android.net.Uri;
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;
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;
import android.widget.AdapterView;
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;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.TextView;
2019-05-06 07:10:13 +00:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
2019-05-06 07:10:13 +00:00
import androidx.preference.PreferenceManager;
2024-01-05 19:49:34 +00:00
import java.util.Arrays;
import java.util.Collections;
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;
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;
private SwitchCompat swConversationActions;
private SwitchCompat swConversationActionsReplies;
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;
2023-06-27 16:50:09 +00:00
private SwitchCompat swPullAll;
2019-05-06 07:10:13 +00:00
private SwitchCompat swAutoScroll;
2020-03-15 09:52:19 +00:00
private SwitchCompat swQuickFilter;
private SwitchCompat swQuickScroll;
2023-01-10 15:09:33 +00:00
private SwitchCompat swQuickActions;
private Button btnSwipes;
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;
private SwitchCompat swUpDown;
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;
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;
private Spinner spSeenDelay;
private TextView tvAutoSeenHint;
2021-06-27 07:31:20 +00:00
private TextView tvOnClose;
private Spinner spOnClose;
private SwitchCompat swAutoCloseUnseen;
private SwitchCompat swAutoCloseSend;
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;
2019-09-28 18:25:19 +00:00
private SwitchCompat swAutoUnflag;
2020-02-03 18:25:46 +00:00
private SwitchCompat swResetImportance;
2023-05-26 19:00:52 +00:00
private SwitchCompat swPhotoPicker;
2023-01-25 10:52:00 +00:00
private SwitchCompat swFlagSnoozed;
private SwitchCompat swAutoImportant;
private SwitchCompat swResetSnooze;
private SwitchCompat swAutoBlockSender;
private SwitchCompat swAutoHideAnswer;
2021-11-22 12:51:40 +00:00
private SwitchCompat swSwipeReply;
2023-07-12 06:31:04 +00:00
private SwitchCompat swMoveThreadAll;
private SwitchCompat swMoveThreadSent;
2023-01-27 08:56:32 +00:00
private Button btnDefaultFolder;
private TextView tvDefaultFolder;
2019-05-06 07:10:13 +00:00
2023-03-05 19:32:32 +00:00
private boolean accessibility;
2021-07-27 12:38:08 +00:00
final static int MAX_SWIPE_SENSITIVITY = 10;
2023-05-05 20:56:45 +00:00
final static int DEFAULT_SWIPE_SENSITIVITY = 6;
2021-07-27 12:38:08 +00:00
2023-01-27 08:56:32 +00:00
final static int REQUEST_DEFAULT_FOLDER = 1;
2024-03-18 12:05:22 +00:00
final static List<String> RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList(
"restore_on_launch", "sync_on_launch", "double_back", "conversation_actions", "conversation_actions_replies", "language_detection",
"photo_picker", "default_snooze",
2023-06-27 16:50:09 +00:00
"pull", "pull_all", "autoscroll", "quick_filter", "quick_scroll", "quick_actions", "swipe_sensitivity", "foldernav",
"doubletap", "swipenav", "volumenav", "updown", "reversed", "swipe_close", "swipe_move",
"autoexpand", "expand_first", "expand_all", "expand_one", "collapse_multiple",
"seen_delay",
"autoclose", "onclose", "autoclose_unseen", "autoclose_send", "collapse_marked",
"undo_timeout",
2023-07-12 05:27:26 +00:00
"autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance",
"reset_snooze", "auto_block_sender", "auto_hide_answer", "swipe_reply",
2023-07-12 06:31:04 +00:00
"move_thread_all", "move_thread_sent",
2023-07-12 05:27:26 +00:00
"default_folder"
2024-01-05 19:49:34 +00:00
));
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);
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);
swConversationActions = view.findViewById(R.id.swConversationActions);
swConversationActionsReplies = view.findViewById(R.id.swConversationActionsReplies);
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);
2023-06-27 16:50:09 +00:00
swPullAll = view.findViewById(R.id.swPullAll);
2019-05-06 07:10:13 +00:00
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);
2023-01-10 15:09:33 +00:00
swQuickActions = view.findViewById(R.id.swQuickActions);
btnSwipes = view.findViewById(R.id.btnSwipes);
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);
swUpDown = view.findViewById(R.id.swUpDown);
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);
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);
spSeenDelay = view.findViewById(R.id.spSeenDelay);
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);
swAutoCloseUnseen = view.findViewById(R.id.swAutoCloseUnseen);
swAutoCloseSend = view.findViewById(R.id.swAutoCloseSend);
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);
2019-09-28 18:25:19 +00:00
swAutoUnflag = view.findViewById(R.id.swAutoUnflag);
2020-02-03 18:25:46 +00:00
swResetImportance = view.findViewById(R.id.swResetImportance);
2023-05-26 19:00:52 +00:00
swPhotoPicker = view.findViewById(R.id.swPhotoPicker);
2023-01-25 10:52:00 +00:00
swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed);
swAutoImportant = view.findViewById(R.id.swAutoImportant);
swResetSnooze = view.findViewById(R.id.swResetSnooze);
swAutoBlockSender = view.findViewById(R.id.swAutoBlockSender);
swAutoHideAnswer = view.findViewById(R.id.swAutoHideAnswer);
2021-11-22 12:51:40 +00:00
swSwipeReply = view.findViewById(R.id.swSwipeReply);
2023-07-12 06:31:04 +00:00
swMoveThreadAll = view.findViewById(R.id.swMoveThreadAll);
swMoveThreadSent = view.findViewById(R.id.swMoveThreadSent);
2023-01-27 08:56:32 +00:00
btnDefaultFolder = view.findViewById(R.id.btnDefaultFolder);
tvDefaultFolder = view.findViewById(R.id.tvDefaultFolder);
2019-05-06 07:10:13 +00:00
2023-03-05 19:32:32 +00:00
accessibility = Helper.isAccessibilityEnabled(getContext());
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());
int[] undoValues = getResources().getIntArray(R.array.undoValues);
2019-05-06 07:10:13 +00:00
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();
}
});
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();
}
});
swConversationActions.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
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);
}
});
swConversationActionsReplies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q);
swConversationActionsReplies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("conversation_actions_replies", checked).apply();
}
});
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();
2023-06-27 16:50:09 +00:00
swPullAll.setEnabled(checked);
}
});
swPullAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("pull_all", checked).apply();
2019-05-06 07:10:13 +00:00
}
});
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();
}
});
2023-01-10 15:09:33 +00:00
swQuickActions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("quick_actions", checked).apply();
}
});
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);
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-29 16:44:59 +00:00
swSwipeNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@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();
}
});
swUpDown.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("updown", 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();
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
}
});
spSeenDelay.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
int value = undoValues[position];
prefs.edit().putInt("seen_delay", value).apply();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
prefs.edit().remove("seen_delay").apply();
}
});
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);
spOnClose.setEnabled(!checked);
2019-05-06 07:10:13 +00:00
}
});
spOnClose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
2019-05-06 07:10:13 +00:00
@Override
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
}
});
swAutoCloseUnseen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("autoclose_unseen", checked).apply();
}
});
swAutoCloseSend.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("autoclose_send", checked).apply();
}
});
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 value = undoValues[position];
2020-07-18 09:21:24 +00:00
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();
}
});
2023-01-25 10:52:00 +00:00
swAutoUnflag.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2020-02-16 12:49:05 +00:00
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2023-01-25 10:52:00 +00:00
prefs.edit().putBoolean("autounflag", checked).apply();
2020-02-16 12:49:05 +00:00
}
});
2023-01-25 10:52:00 +00:00
swResetImportance.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2019-09-28 18:25:19 +00:00
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2023-01-25 10:52:00 +00:00
prefs.edit().putBoolean("reset_importance", checked).apply();
2019-09-28 18:25:19 +00:00
}
});
2023-08-21 16:11:06 +00:00
swPhotoPicker.setVisibility(Helper.hasPhotoPicker() ? View.VISIBLE : View.GONE);
2023-05-26 19:00:52 +00:00
swPhotoPicker.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("photo_picker", checked).apply();
}
});
2023-01-25 10:52:00 +00:00
swFlagSnoozed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2020-02-20 14:50:26 +00:00
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2023-01-25 10:52:00 +00:00
prefs.edit().putBoolean("flag_snoozed", checked).apply();
2020-02-20 14:50:26 +00:00
}
});
2023-01-25 10:52:00 +00:00
swAutoImportant.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2020-02-03 18:25:46 +00:00
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2023-01-25 10:52:00 +00:00
prefs.edit().putBoolean("auto_important", checked).apply();
2020-02-03 18:25:46 +00:00
}
});
swResetSnooze.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("reset_snooze", checked).apply();
}
});
swAutoBlockSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("auto_block_sender", checked).apply();
}
});
swAutoHideAnswer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("auto_hide_answer", 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();
}
});
2023-07-12 06:31:04 +00:00
swMoveThreadAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2023-07-12 06:31:04 +00:00
prefs.edit().putBoolean("move_thread_all", checked).apply();
swMoveThreadSent.setEnabled(!checked);
}
});
2023-07-12 06:31:04 +00:00
swMoveThreadSent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
2023-07-12 05:27:26 +00:00
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
2023-07-12 06:31:04 +00:00
prefs.edit().putBoolean("move_thread_sent", checked).apply();
2023-07-12 05:27:26 +00:00
}
});
2023-01-27 08:56:32 +00:00
Intent tree = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
Helper.openAdvanced(getContext(), tree);
PackageManager pm = getContext().getPackageManager();
btnDefaultFolder.setEnabled(tree.resolveActivity(pm) != null &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O);
btnDefaultFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(Helper.getChooser(getContext(), tree), REQUEST_DEFAULT_FOLDER);
}
});
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();
}
2023-01-27 08:56:32 +00:00
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case REQUEST_DEFAULT_FOLDER:
if (resultCode == RESULT_OK && data != null)
onDefaultFolder(data.getData());
else
onDefaultFolder(null);
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
2019-05-06 12:41:03 +00:00
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
2024-01-05 19:49:34 +00:00
if (!RESET_OPTIONS.contains(key))
return;
2020-03-15 09:52:19 +00:00
if ("default_snooze".equals(key))
return;
2023-09-09 08:10:27 +00:00
getMainHandler().removeCallbacks(update);
getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS);
2019-05-06 12:41:03 +00:00
}
2023-09-09 08:10:27 +00:00
private Runnable update = new RunnableEx("behavior") {
@Override
protected void delegate() {
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() {
2023-04-26 11:32:00 +00:00
try {
if (view == null || getContext() == null)
return;
int[] undoValues = getResources().getIntArray(R.array.undoValues);
2023-04-26 11:32:00 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swRestoreOnLaunch.setChecked(prefs.getBoolean("restore_on_launch", false));
swSyncOnlaunch.setChecked(prefs.getBoolean("sync_on_launch", false));
swDoubleBack.setChecked(prefs.getBoolean("double_back", false));
swConversationActions.setChecked(prefs.getBoolean("conversation_actions", Helper.isGoogle()));
swConversationActionsReplies.setChecked(prefs.getBoolean("conversation_actions_replies", true));
swConversationActionsReplies.setEnabled(swConversationActions.isChecked());
swLanguageDetection.setChecked(prefs.getBoolean("language_detection", false));
int default_snooze = prefs.getInt("default_snooze", 1);
etDefaultSnooze.setText(default_snooze == 1 ? null : Integer.toString(default_snooze));
etDefaultSnooze.setHint("1");
swPull.setChecked(prefs.getBoolean("pull", true));
2023-06-27 16:50:09 +00:00
swPullAll.setChecked(prefs.getBoolean("pull_all", false));
swPullAll.setEnabled(swPull.isChecked());
2023-04-26 11:32:00 +00:00
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false));
swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false));
swQuickScroll.setChecked(prefs.getBoolean("quick_scroll", true));
swQuickActions.setChecked(prefs.getBoolean("quick_actions", true));
int swipe_sensitivity = prefs.getInt("swipe_sensitivity", DEFAULT_SWIPE_SENSITIVITY);
sbSwipeSensitivity.setProgress(swipe_sensitivity);
swFolderNav.setChecked(prefs.getBoolean("foldernav", false));
swDoubleTap.setChecked(prefs.getBoolean("doubletap", false));
swSwipeNav.setChecked(prefs.getBoolean("swipenav", true));
swVolumeNav.setChecked(prefs.getBoolean("volumenav", false));
2023-10-13 06:05:42 +00:00
swUpDown.setChecked(prefs.getBoolean("updown", true));
2023-04-26 11:32:00 +00:00
swReversed.setChecked(prefs.getBoolean("reversed", false));
swSwipeClose.setChecked(prefs.getBoolean("swipe_close", false));
swSwipeMove.setChecked(prefs.getBoolean("swipe_move", false));
swAutoExpand.setChecked(prefs.getBoolean("autoexpand", true));
swExpandFirst.setChecked(prefs.getBoolean("expand_first", true));
swExpandFirst.setEnabled(swAutoExpand.isChecked());
swExpandAll.setChecked(prefs.getBoolean("expand_all", false));
swExpandOne.setChecked(prefs.getBoolean("expand_one", true));
swExpandOne.setEnabled(!swExpandAll.isChecked());
swCollapseMultiple.setChecked(prefs.getBoolean("collapse_multiple", true));
int seen_delay = prefs.getInt("seen_delay", 0);
for (int pos = 0; pos < undoValues.length; pos++)
if (undoValues[pos] == seen_delay) {
spSeenDelay.setSelection(pos);
break;
}
2023-04-26 11:32:00 +00:00
swAutoClose.setChecked(prefs.getBoolean("autoclose", true));
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;
}
2022-06-13 11:28:29 +00:00
2023-04-26 11:32:00 +00:00
tvOnClose.setEnabled(!swAutoClose.isChecked());
spOnClose.setEnabled(!swAutoClose.isChecked());
swAutoCloseUnseen.setChecked(prefs.getBoolean("autoclose_unseen", false));
swAutoCloseSend.setChecked(prefs.getBoolean("autoclose_send", false));
swCollapseMarked.setChecked(prefs.getBoolean("collapse_marked", true));
2019-05-06 07:10:13 +00:00
2023-04-26 11:32:00 +00:00
int undo_timeout = prefs.getInt("undo_timeout", 5000);
for (int pos = 0; pos < undoValues.length; pos++)
if (undoValues[pos] == undo_timeout) {
spUndoTimeout.setSelection(pos);
break;
}
swAutoRead.setChecked(prefs.getBoolean("autoread", false));
swAutoUnflag.setChecked(prefs.getBoolean("autounflag", false));
swResetImportance.setChecked(prefs.getBoolean("reset_importance", false));
2023-05-26 19:00:52 +00:00
swPhotoPicker.setChecked(prefs.getBoolean("photo_picker", true));
2023-04-26 11:32:00 +00:00
swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false));
swAutoImportant.setChecked(prefs.getBoolean("auto_important", false));
swResetSnooze.setChecked(prefs.getBoolean("reset_snooze", true));
swAutoBlockSender.setChecked(prefs.getBoolean("auto_block_sender", true));
2023-07-30 05:25:32 +00:00
swAutoHideAnswer.setChecked(prefs.getBoolean("auto_hide_answer", false));
2023-04-26 11:32:00 +00:00
swSwipeReply.setChecked(prefs.getBoolean("swipe_reply", false));
2023-07-12 05:27:26 +00:00
2023-07-12 06:31:04 +00:00
swMoveThreadAll.setChecked(prefs.getBoolean("move_thread_all", false));
2023-04-26 11:32:00 +00:00
swMoveThreadSent.setChecked(prefs.getBoolean("move_thread_sent", false));
2023-07-12 06:31:04 +00:00
swMoveThreadSent.setEnabled(!swMoveThreadAll.isChecked());
2023-07-12 05:27:26 +00:00
2023-04-26 11:32:00 +00:00
tvDefaultFolder.setText(prefs.getString("default_folder", null));
} catch (Throwable ex) {
Log.e(ex);
}
2023-01-27 08:56:32 +00:00
}
private void onDefaultFolder(Uri uri) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (uri == null)
prefs.edit().remove("default_folder").apply();
else
prefs.edit().putString("default_folder", uri.toString()).apply();
2019-05-06 07:10:13 +00:00
}
}