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/>.
|
|
|
|
|
|
|
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
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.CompoundButton;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swPull;
|
|
|
|
private SwitchCompat swAutoScroll;
|
|
|
|
private SwitchCompat swSwipeNav;
|
|
|
|
private SwitchCompat swAutoExpand;
|
|
|
|
private SwitchCompat swAutoClose;
|
|
|
|
private SwitchCompat swAutoNext;
|
|
|
|
private SwitchCompat swCollapse;
|
|
|
|
private SwitchCompat swAutoRead;
|
|
|
|
private SwitchCompat swAutoMove;
|
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
private final static String[] RESET_OPTIONS = new String[]{
|
|
|
|
"pull", "autoscroll", "swipenav", "autoexpand", "autoclose", "autonext",
|
2019-05-09 16:04:18 +00:00
|
|
|
"collapse", "autoread", "automove"
|
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
|
|
|
|
|
|
|
View view = inflater.inflate(R.layout.fragment_options_behavior, container, false);
|
|
|
|
|
|
|
|
// Get controls
|
|
|
|
|
|
|
|
swPull = view.findViewById(R.id.swPull);
|
|
|
|
swAutoScroll = view.findViewById(R.id.swAutoScroll);
|
|
|
|
swSwipeNav = view.findViewById(R.id.swSwipeNav);
|
|
|
|
swAutoExpand = view.findViewById(R.id.swAutoExpand);
|
|
|
|
swAutoClose = view.findViewById(R.id.swAutoClose);
|
|
|
|
swAutoNext = view.findViewById(R.id.swAutoNext);
|
|
|
|
swCollapse = view.findViewById(R.id.swCollapse);
|
|
|
|
swAutoRead = view.findViewById(R.id.swAutoRead);
|
|
|
|
swAutoMove = view.findViewById(R.id.swAutoMove);
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swSwipeNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("swipenav", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swAutoExpand.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoexpand", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swAutoClose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoclose", checked).apply();
|
|
|
|
swAutoNext.setEnabled(!checked);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swAutoNext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autonext", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swCollapse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("collapse", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swAutoRead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("autoread", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swAutoMove.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("automove", !checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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) {
|
|
|
|
setOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_default:
|
|
|
|
onMenuDefault();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onMenuDefault() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
for (String option : RESET_OPTIONS)
|
|
|
|
editor.remove(option);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
private void setOptions() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
|
|
|
swPull.setChecked(prefs.getBoolean("pull", true));
|
|
|
|
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", false));
|
|
|
|
swSwipeNav.setChecked(prefs.getBoolean("swipenav", true));
|
|
|
|
swAutoExpand.setChecked(prefs.getBoolean("autoexpand", true));
|
|
|
|
swAutoClose.setChecked(prefs.getBoolean("autoclose", true));
|
|
|
|
swAutoNext.setChecked(prefs.getBoolean("autonext", false));
|
|
|
|
swAutoNext.setEnabled(!swAutoClose.isChecked());
|
|
|
|
swCollapse.setChecked(prefs.getBoolean("collapse", false));
|
|
|
|
swAutoRead.setChecked(prefs.getBoolean("autoread", false));
|
|
|
|
swAutoMove.setChecked(!prefs.getBoolean("automove", false));
|
|
|
|
}
|
|
|
|
}
|