2019-05-09 06:15:10 +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/>.
|
|
|
|
|
2020-01-05 17:32:53 +00:00
|
|
|
Copyright 2018-2020 by Marcel Bokhorst (M66B)
|
2019-05-09 06:15:10 +00:00
|
|
|
*/
|
|
|
|
|
2019-10-16 13:12:39 +00:00
|
|
|
import android.content.Intent;
|
2019-05-09 06:15:10 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
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.AdapterView;
|
2019-10-16 13:12:39 +00:00
|
|
|
import android.widget.Button;
|
2019-05-09 06:15:10 +00:00
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.Spinner;
|
2019-05-09 16:04:18 +00:00
|
|
|
import android.widget.TextView;
|
2019-07-14 10:32:32 +00:00
|
|
|
import android.widget.Toast;
|
2019-05-09 06:15:10 +00:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
2019-09-10 06:53:07 +00:00
|
|
|
import androidx.lifecycle.Lifecycle;
|
2019-10-16 13:12:39 +00:00
|
|
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
2019-05-09 06:15:10 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
public class FragmentOptionsSend extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2019-06-15 06:49:46 +00:00
|
|
|
private SwitchCompat swKeyboard;
|
2019-09-12 15:33:33 +00:00
|
|
|
private SwitchCompat swSuggestSent;
|
|
|
|
private SwitchCompat swSuggestReceived;
|
2019-10-16 13:12:39 +00:00
|
|
|
private Button btnLocalContacts;
|
2019-05-09 06:15:10 +00:00
|
|
|
private SwitchCompat swPrefixOnce;
|
2019-11-07 07:56:54 +00:00
|
|
|
private SwitchCompat swExtendedReply;
|
2019-11-07 10:15:02 +00:00
|
|
|
private SwitchCompat swQuoteReply;
|
2019-06-14 15:58:09 +00:00
|
|
|
private SwitchCompat swPlainOnly;
|
2019-08-22 16:09:52 +00:00
|
|
|
private SwitchCompat swUsenetSignature;
|
2020-01-07 14:49:34 +00:00
|
|
|
private SwitchCompat swResizeImages;
|
|
|
|
private SwitchCompat swResizeAttachments;
|
2019-05-09 16:04:18 +00:00
|
|
|
private Spinner spAutoResize;
|
|
|
|
private TextView tvAutoResize;
|
2020-01-18 09:54:19 +00:00
|
|
|
private SwitchCompat swSendReminders;
|
2019-10-02 07:26:32 +00:00
|
|
|
private SwitchCompat swReceipt;
|
2019-07-14 11:35:52 +00:00
|
|
|
private SwitchCompat swLookupMx;
|
2019-05-09 06:15:10 +00:00
|
|
|
private Spinner spSendDelayed;
|
|
|
|
|
|
|
|
private final static String[] RESET_OPTIONS = new String[]{
|
2019-11-07 10:15:02 +00:00
|
|
|
"keyboard", "suggest_sent", "suggested_received",
|
|
|
|
"prefix_once", "extended_reply", "quote_reply",
|
|
|
|
"plain_only", "usenet_signature",
|
2020-01-18 09:54:19 +00:00
|
|
|
"resize_images", "resize_attachments", "send_reminders", "receipt_default", "resize", "lookup_mx", "send_delayed"
|
2019-05-09 06:15:10 +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-09 06:15:10 +00:00
|
|
|
setHasOptionsMenu(true);
|
|
|
|
|
|
|
|
View view = inflater.inflate(R.layout.fragment_options_send, container, false);
|
|
|
|
|
|
|
|
// Get controls
|
|
|
|
|
2019-06-15 06:49:46 +00:00
|
|
|
swKeyboard = view.findViewById(R.id.swKeyboard);
|
2019-09-12 15:33:33 +00:00
|
|
|
swSuggestSent = view.findViewById(R.id.swSuggestSent);
|
|
|
|
swSuggestReceived = view.findViewById(R.id.swSuggestReceived);
|
2019-10-16 13:12:39 +00:00
|
|
|
btnLocalContacts = view.findViewById(R.id.btnLocalContacts);
|
2019-05-09 06:15:10 +00:00
|
|
|
swPrefixOnce = view.findViewById(R.id.swPrefixOnce);
|
2019-11-07 07:56:54 +00:00
|
|
|
swExtendedReply = view.findViewById(R.id.swExtendedReply);
|
2019-11-07 10:15:02 +00:00
|
|
|
swQuoteReply = view.findViewById(R.id.swQuoteReply);
|
2019-06-14 15:58:09 +00:00
|
|
|
swPlainOnly = view.findViewById(R.id.swPlainOnly);
|
2019-08-22 16:09:52 +00:00
|
|
|
swUsenetSignature = view.findViewById(R.id.swUsenetSignature);
|
2020-01-07 14:49:34 +00:00
|
|
|
swResizeImages = view.findViewById(R.id.swResizeImages);
|
|
|
|
swResizeAttachments = view.findViewById(R.id.swResizeAttachments);
|
2019-05-09 16:04:18 +00:00
|
|
|
spAutoResize = view.findViewById(R.id.spAutoResize);
|
|
|
|
tvAutoResize = view.findViewById(R.id.tvAutoResize);
|
2020-01-18 09:54:19 +00:00
|
|
|
swSendReminders = view.findViewById(R.id.swSendReminders);
|
2019-10-02 07:26:32 +00:00
|
|
|
swReceipt = view.findViewById(R.id.swReceipt);
|
2019-07-14 11:35:52 +00:00
|
|
|
swLookupMx = view.findViewById(R.id.swLookupMx);
|
2019-05-09 06:15:10 +00:00
|
|
|
spSendDelayed = view.findViewById(R.id.spSendDelayed);
|
|
|
|
|
|
|
|
setOptions();
|
|
|
|
|
|
|
|
// Wire controls
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
2019-06-15 06:49:46 +00:00
|
|
|
swKeyboard.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("keyboard", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-12 15:33:33 +00:00
|
|
|
swSuggestSent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2019-08-23 13:06:59 +00:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
2019-09-12 15:33:33 +00:00
|
|
|
prefs.edit().putBoolean("suggest_sent", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swSuggestReceived.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("suggest_received", checked).apply();
|
2019-08-23 13:06:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-16 13:12:39 +00:00
|
|
|
btnLocalContacts.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
|
|
|
|
lbm.sendBroadcast(new Intent(ActivitySetup.ACTION_MANAGE_LOCAL_CONTACTS));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-09 06:15:10 +00:00
|
|
|
swPrefixOnce.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("prefix_once", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-07 07:56:54 +00:00
|
|
|
swExtendedReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("extended_reply", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-07 10:15:02 +00:00
|
|
|
swQuoteReply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("quote_reply", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-14 15:58:09 +00:00
|
|
|
swPlainOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("plain_only", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-22 16:09:52 +00:00
|
|
|
swUsenetSignature.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("usenet_signature", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-07 14:49:34 +00:00
|
|
|
swResizeImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
2019-05-09 16:04:18 +00:00
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
2020-01-07 14:49:34 +00:00
|
|
|
prefs.edit().putBoolean("resize_images", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swResizeAttachments.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("resize_attachments", checked).apply();
|
|
|
|
spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked());
|
2019-05-09 16:04:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
spAutoResize.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
int[] values = getResources().getIntArray(R.array.resizeValues);
|
|
|
|
prefs.edit().putInt("resize", values[position]).apply();
|
|
|
|
tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, values[position]));
|
2020-01-07 14:49:34 +00:00
|
|
|
spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked());
|
2019-05-09 16:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
prefs.edit().remove("resize").apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-02 07:26:32 +00:00
|
|
|
swReceipt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("receipt_default", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-18 09:54:19 +00:00
|
|
|
swSendReminders.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("send_reminders", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-14 11:35:52 +00:00
|
|
|
swLookupMx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("lookup_mx", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-09 06:15:10 +00:00
|
|
|
spSendDelayed.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
int[] values = getResources().getIntArray(R.array.sendDelayedValues);
|
|
|
|
prefs.edit().putInt("send_delayed", values[position]).apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
prefs.edit().remove("send_delayed").apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2019-09-10 06:53:07 +00:00
|
|
|
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
|
|
|
setOptions();
|
2019-05-09 06:15:10 +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) {
|
|
|
|
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-07-14 10:32:32 +00:00
|
|
|
ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
2019-05-09 06:15:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setOptions() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
2019-06-15 06:49:46 +00:00
|
|
|
swKeyboard.setChecked(prefs.getBoolean("keyboard", true));
|
2019-11-08 18:42:35 +00:00
|
|
|
swSuggestSent.setChecked(prefs.getBoolean("suggest_sent", true));
|
2019-09-12 15:33:33 +00:00
|
|
|
swSuggestReceived.setChecked(prefs.getBoolean("suggest_received", false));
|
2019-08-03 12:39:26 +00:00
|
|
|
swPrefixOnce.setChecked(prefs.getBoolean("prefix_once", true));
|
2019-11-07 07:56:54 +00:00
|
|
|
swExtendedReply.setChecked(prefs.getBoolean("extended_reply", false));
|
2019-11-07 10:15:02 +00:00
|
|
|
swQuoteReply.setChecked(prefs.getBoolean("quote_reply", true));
|
2019-06-14 15:58:09 +00:00
|
|
|
swPlainOnly.setChecked(prefs.getBoolean("plain_only", false));
|
2019-08-22 16:09:52 +00:00
|
|
|
swUsenetSignature.setChecked(prefs.getBoolean("usenet_signature", false));
|
2019-05-09 16:04:18 +00:00
|
|
|
|
2020-01-07 14:49:34 +00:00
|
|
|
swResizeImages.setChecked(prefs.getBoolean("resize_images", true));
|
|
|
|
swResizeAttachments.setChecked(prefs.getBoolean("resize_attachments", true));
|
2019-05-09 16:04:18 +00:00
|
|
|
|
|
|
|
int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE);
|
|
|
|
int[] resizeValues = getResources().getIntArray(R.array.resizeValues);
|
|
|
|
for (int pos = 0; pos < resizeValues.length; pos++)
|
|
|
|
if (resizeValues[pos] == resize) {
|
|
|
|
spAutoResize.setSelection(pos);
|
|
|
|
tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, resizeValues[pos]));
|
|
|
|
break;
|
|
|
|
}
|
2020-01-07 14:49:34 +00:00
|
|
|
spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked());
|
2019-05-09 16:04:18 +00:00
|
|
|
|
2020-01-18 09:54:19 +00:00
|
|
|
swSendReminders.setChecked(prefs.getBoolean("send_reminders", true));
|
2019-10-02 07:26:32 +00:00
|
|
|
swReceipt.setChecked(prefs.getBoolean("receipt_default", false));
|
2019-07-14 11:35:52 +00:00
|
|
|
swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false));
|
2019-05-09 06:15:10 +00:00
|
|
|
|
|
|
|
int send_delayed = prefs.getInt("send_delayed", 0);
|
|
|
|
int[] sendDelayedValues = getResources().getIntArray(R.array.sendDelayedValues);
|
|
|
|
for (int pos = 0; pos < sendDelayedValues.length; pos++)
|
|
|
|
if (sendDelayedValues[pos] == send_delayed) {
|
|
|
|
spSendDelayed.setSelection(pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|