2018-08-16 18:19:09 +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.
|
|
|
|
|
|
2018-10-29 10:46:49 +00:00
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
2018-08-16 18:19:09 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-10-29 10:46:49 +00:00
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-16 18:19:09 +00:00
|
|
|
|
|
|
|
|
Copyright 2018 by Marcel Bokhorst (M66B)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.CompoundButton;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
2018-10-31 09:09:07 +00:00
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
2018-08-16 18:19:09 +00:00
|
|
|
|
|
|
|
|
public class FragmentOptions extends FragmentEx {
|
2018-10-31 09:09:07 +00:00
|
|
|
private SwitchCompat swEnabled;
|
|
|
|
|
private SwitchCompat swAvatars;
|
2018-11-03 16:34:35 +00:00
|
|
|
private SwitchCompat swIdenticons;
|
2018-10-31 09:09:07 +00:00
|
|
|
private SwitchCompat swLight;
|
|
|
|
|
private SwitchCompat swBrowse;
|
|
|
|
|
private SwitchCompat swSwipe;
|
|
|
|
|
private SwitchCompat swCompact;
|
2018-11-02 19:37:44 +00:00
|
|
|
private SwitchCompat swNav;
|
2018-10-31 09:09:07 +00:00
|
|
|
private SwitchCompat swInsecure;
|
|
|
|
|
private SwitchCompat swDebug;
|
2018-08-16 18:19:09 +00:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Nullable
|
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
|
|
setSubtitle(R.string.title_advanced);
|
|
|
|
|
|
|
|
|
|
View view = inflater.inflate(R.layout.fragment_options, container, false);
|
|
|
|
|
|
|
|
|
|
// Get controls
|
2018-10-31 09:09:07 +00:00
|
|
|
swEnabled = view.findViewById(R.id.swEnabled);
|
|
|
|
|
swAvatars = view.findViewById(R.id.swAvatars);
|
2018-11-03 16:34:35 +00:00
|
|
|
swIdenticons = view.findViewById(R.id.swIdenticons);
|
2018-10-31 09:09:07 +00:00
|
|
|
swLight = view.findViewById(R.id.swLight);
|
|
|
|
|
swBrowse = view.findViewById(R.id.swBrowse);
|
|
|
|
|
swSwipe = view.findViewById(R.id.swSwipe);
|
|
|
|
|
swCompact = view.findViewById(R.id.swCompact);
|
2018-11-02 19:37:44 +00:00
|
|
|
swNav = view.findViewById(R.id.swNav);
|
2018-10-31 09:09:07 +00:00
|
|
|
swInsecure = view.findViewById(R.id.swInsecure);
|
|
|
|
|
swDebug = view.findViewById(R.id.swDebug);
|
2018-08-16 18:19:09 +00:00
|
|
|
|
|
|
|
|
// Wire controls
|
|
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swEnabled.setChecked(prefs.getBoolean("enabled", true));
|
|
|
|
|
swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-10-11 11:59:56 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("enabled", checked).apply();
|
2018-10-13 13:30:00 +00:00
|
|
|
if (checked)
|
|
|
|
|
ServiceSynchronize.start(getContext());
|
|
|
|
|
else
|
|
|
|
|
ServiceSynchronize.stop(getContext());
|
2018-10-11 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swAvatars.setChecked(prefs.getBoolean("avatars", true));
|
|
|
|
|
swAvatars.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-09-08 15:07:40 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("avatars", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-04 07:14:14 +00:00
|
|
|
swIdenticons.setChecked(prefs.getBoolean("identicons", false));
|
2018-11-03 16:34:35 +00:00
|
|
|
swIdenticons.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("identicons", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swLight.setChecked(prefs.getBoolean("light", false));
|
|
|
|
|
swLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-09-14 13:31:00 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("light", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swBrowse.setChecked(prefs.getBoolean("browse", true));
|
|
|
|
|
swBrowse.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-09-22 08:19:00 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("browse", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swSwipe.setChecked(prefs.getBoolean("swipe", true));
|
|
|
|
|
swSwipe.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-10-13 16:01:35 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("swipe", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swCompact.setChecked(prefs.getBoolean("compact", false));
|
|
|
|
|
swCompact.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-10-21 16:53:56 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("compact", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-11-02 19:37:44 +00:00
|
|
|
swNav.setChecked(prefs.getBoolean("navigation", true));
|
|
|
|
|
swNav.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("navigation", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swInsecure.setChecked(prefs.getBoolean("insecure", false));
|
|
|
|
|
swInsecure.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-10-23 07:52:20 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("insecure", checked).apply();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swDebug.setChecked(prefs.getBoolean("debug", false));
|
|
|
|
|
swDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2018-08-16 18:19:09 +00:00
|
|
|
@Override
|
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
|
prefs.edit().putBoolean("debug", checked).apply();
|
2018-09-18 09:56:34 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), "debug=" + checked);
|
2018-08-16 18:19:09 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-10-31 09:09:07 +00:00
|
|
|
swLight.setVisibility(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
|
2018-09-14 13:31:00 +00:00
|
|
|
|
2018-08-16 18:19:09 +00:00
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
}
|