Reorganized behavior settings

pull/176/head
M66B 5 years ago
parent 34285e0416
commit b59626f628

@ -21,7 +21,9 @@ package eu.faircode.email;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
@ -30,7 +32,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.NumberPicker; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
@ -42,8 +44,11 @@ import androidx.preference.PreferenceManager;
public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentOptionsBehavior extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swDoubleBack; private SwitchCompat swDoubleBack;
private EditText etDefaultSnooze;
private SwitchCompat swPull; private SwitchCompat swPull;
private SwitchCompat swAutoScroll; private SwitchCompat swAutoScroll;
private SwitchCompat swQuickFilter;
private SwitchCompat swQuickScroll;
private SwitchCompat swDoubleTap; private SwitchCompat swDoubleTap;
private SwitchCompat swSwipeNav; private SwitchCompat swSwipeNav;
private SwitchCompat swVolumeNav; private SwitchCompat swVolumeNav;
@ -53,8 +58,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swExpandOne; private SwitchCompat swExpandOne;
private SwitchCompat swAutoClose; private SwitchCompat swAutoClose;
private Spinner spOnClose; private Spinner spOnClose;
private SwitchCompat swQuickFilter;
private SwitchCompat swQuickScroll;
private SwitchCompat swCollapseMultiple; private SwitchCompat swCollapseMultiple;
private SwitchCompat swAutoRead; private SwitchCompat swAutoRead;
private SwitchCompat swFlagSnoozed; private SwitchCompat swFlagSnoozed;
@ -62,14 +65,14 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swAutoImportant; private SwitchCompat swAutoImportant;
private SwitchCompat swResetImportance; private SwitchCompat swResetImportance;
private SwitchCompat swDiscardDelete; private SwitchCompat swDiscardDelete;
private NumberPicker npDefaultSnooze;
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"double_back", "pull", "autoscroll", "doubletap", "swipenav", "volumenav", "reversed", "double_back", "default_snooze",
"pull", "autoscroll", "quick_filter", "quick_scroll",
"doubletap", "swipenav", "volumenav", "reversed",
"autoexpand", "expand_all", "expand_one", "collapse_multiple", "autoexpand", "expand_all", "expand_one", "collapse_multiple",
"autoclose", "onclose", "quick_filter", "quick_scroll", "autoclose", "onclose",
"autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance", "discard_delete", "autoread", "flag_snoozed", "autounflag", "auto_important", "reset_importance", "discard_delete",
"default_snooze"
}; };
@Override @Override
@ -83,8 +86,11 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
// Get controls // Get controls
swDoubleBack = view.findViewById(R.id.swDoubleBack); swDoubleBack = view.findViewById(R.id.swDoubleBack);
etDefaultSnooze = view.findViewById(R.id.etDefaultSnooze);
swPull = view.findViewById(R.id.swPull); swPull = view.findViewById(R.id.swPull);
swAutoScroll = view.findViewById(R.id.swAutoScroll); swAutoScroll = view.findViewById(R.id.swAutoScroll);
swQuickFilter = view.findViewById(R.id.swQuickFilter);
swQuickScroll = view.findViewById(R.id.swQuickScroll);
swDoubleTap = view.findViewById(R.id.swDoubleTap); swDoubleTap = view.findViewById(R.id.swDoubleTap);
swSwipeNav = view.findViewById(R.id.swSwipeNav); swSwipeNav = view.findViewById(R.id.swSwipeNav);
swVolumeNav = view.findViewById(R.id.swVolumeNav); swVolumeNav = view.findViewById(R.id.swVolumeNav);
@ -95,18 +101,12 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swCollapseMultiple = view.findViewById(R.id.swCollapseMultiple); swCollapseMultiple = view.findViewById(R.id.swCollapseMultiple);
swAutoClose = view.findViewById(R.id.swAutoClose); swAutoClose = view.findViewById(R.id.swAutoClose);
spOnClose = view.findViewById(R.id.spOnClose); spOnClose = view.findViewById(R.id.spOnClose);
swQuickFilter = view.findViewById(R.id.swQuickFilter);
swQuickScroll = view.findViewById(R.id.swQuickScroll);
swAutoRead = view.findViewById(R.id.swAutoRead); swAutoRead = view.findViewById(R.id.swAutoRead);
swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed); swFlagSnoozed = view.findViewById(R.id.swFlagSnoozed);
swAutoUnflag = view.findViewById(R.id.swAutoUnflag); swAutoUnflag = view.findViewById(R.id.swAutoUnflag);
swAutoImportant = view.findViewById(R.id.swAutoImportant); swAutoImportant = view.findViewById(R.id.swAutoImportant);
swResetImportance = view.findViewById(R.id.swResetImportance); swResetImportance = view.findViewById(R.id.swResetImportance);
swDiscardDelete = view.findViewById(R.id.swDiscardDelete); swDiscardDelete = view.findViewById(R.id.swDiscardDelete);
npDefaultSnooze = view.findViewById(R.id.npDefaultSnooze);
npDefaultSnooze.setMinValue(1);
npDefaultSnooze.setMaxValue(999);
setOptions(); setOptions();
@ -121,6 +121,31 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
} }
}); });
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
}
});
swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swPull.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -135,6 +160,20 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
} }
}); });
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();
}
});
swDoubleTap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swDoubleTap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -219,20 +258,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
} }
}); });
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();
}
});
swAutoRead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swAutoRead.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -275,13 +300,6 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
} }
}); });
npDefaultSnooze.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
prefs.edit().putInt("default_snooze", newVal).apply();
}
});
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
return view; return view;
@ -295,6 +313,9 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("default_snooze".equals(key))
return;
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
setOptions(); setOptions();
} }
@ -329,8 +350,15 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
swDoubleBack.setChecked(prefs.getBoolean("double_back", true)); swDoubleBack.setChecked(prefs.getBoolean("double_back", true));
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)); swPull.setChecked(prefs.getBoolean("pull", true));
swAutoScroll.setChecked(prefs.getBoolean("autoscroll", true)); swAutoScroll.setChecked(prefs.getBoolean("autoscroll", true));
swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false));
swQuickScroll.setChecked(prefs.getBoolean("quick_scroll", true));
swDoubleTap.setChecked(prefs.getBoolean("doubletap", false)); swDoubleTap.setChecked(prefs.getBoolean("doubletap", false));
swSwipeNav.setChecked(prefs.getBoolean("swipenav", true)); swSwipeNav.setChecked(prefs.getBoolean("swipenav", true));
swVolumeNav.setChecked(prefs.getBoolean("volumenav", false)); swVolumeNav.setChecked(prefs.getBoolean("volumenav", false));
@ -355,16 +383,11 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
spOnClose.setEnabled(!swAutoClose.isChecked()); spOnClose.setEnabled(!swAutoClose.isChecked());
swQuickFilter.setChecked(prefs.getBoolean("quick_filter", false));
swQuickScroll.setChecked(prefs.getBoolean("quick_scroll", true));
swAutoRead.setChecked(prefs.getBoolean("autoread", false)); swAutoRead.setChecked(prefs.getBoolean("autoread", false));
swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false)); swFlagSnoozed.setChecked(prefs.getBoolean("flag_snoozed", false));
swAutoUnflag.setChecked(prefs.getBoolean("autounflag", false)); swAutoUnflag.setChecked(prefs.getBoolean("autounflag", false));
swAutoImportant.setChecked(prefs.getBoolean("auto_important", false)); swAutoImportant.setChecked(prefs.getBoolean("auto_important", false));
swResetImportance.setChecked(prefs.getBoolean("reset_importance", false)); swResetImportance.setChecked(prefs.getBoolean("reset_importance", false));
swDiscardDelete.setChecked(prefs.getBoolean("discard_delete", false)); swDiscardDelete.setChecked(prefs.getBoolean("discard_delete", false));
npDefaultSnooze.setValue(prefs.getInt("default_snooze", 1));
} }
} }

@ -40,6 +40,51 @@
app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral" app:layout_constraintTop_toBottomOf="@id/tvCaptionGeneral"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvDefaultSnooze"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_default_snooze"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDoubleBack" />
<EditText
android:id="@+id/etDefaultSnooze"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:hint="20"
android:inputType="number"
android:maxLength="4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDefaultSnooze" />
<eu.faircode.email.FixedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="@string/title_hours"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/etDefaultSnooze"
app:layout_constraintStart_toEndOf="@+id/etDefaultSnooze"
app:layout_constraintTop_toTopOf="@+id/etDefaultSnooze" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvCaptionList"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="@string/title_advanced_caption_list"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etDefaultSnooze" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPull" android:id="@+id/swPull"
android:layout_width="0dp" android:layout_width="0dp"
@ -49,7 +94,7 @@
android:text="@string/title_advanced_pull_refresh" android:text="@string/title_advanced_pull_refresh"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDoubleBack" app:layout_constraintTop_toBottomOf="@id/tvCaptionList"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
@ -64,6 +109,41 @@
app:layout_constraintTop_toBottomOf="@id/swPull" app:layout_constraintTop_toBottomOf="@id/swPull"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuickFilter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_quick_filter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoScroll"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuickScroll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:enabled="true"
android:text="@string/title_advanced_quick_scroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swQuickFilter"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvCaptionConversation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="@string/title_advanced_caption_conversation"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/swQuickScroll" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDoubleTap" android:id="@+id/swDoubleTap"
android:layout_width="0dp" android:layout_width="0dp"
@ -72,7 +152,7 @@
android:text="@string/title_advanced_double_tap" android:text="@string/title_advanced_double_tap"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoScroll" app:layout_constraintTop_toBottomOf="@id/tvCaptionConversation"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
@ -226,29 +306,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOnClose" /> app:layout_constraintTop_toBottomOf="@id/tvOnClose" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuickFilter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_quick_filter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spOnClose"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuickScroll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:enabled="true"
android:text="@string/title_advanced_quick_scroll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swQuickFilter"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoRead" android:id="@+id/swAutoRead"
android:layout_width="0dp" android:layout_width="0dp"
@ -257,7 +314,7 @@
android:text="@string/title_advanced_autoread" android:text="@string/title_advanced_autoread"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swQuickScroll" app:layout_constraintTop_toBottomOf="@id/spOnClose"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
@ -314,35 +371,5 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swResetImportance" app:layout_constraintTop_toBottomOf="@id/swResetImportance"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvDefaultSnooze"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_default_snooze"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swDiscardDelete" />
<NumberPicker
android:id="@+id/npDefaultSnooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvDefaultSnooze" />
<eu.faircode.email.FixedTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="@string/title_hours"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/npDefaultSnooze"
app:layout_constraintStart_toEndOf="@+id/npDefaultSnooze"
app:layout_constraintTop_toTopOf="@+id/npDefaultSnooze" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -300,6 +300,7 @@
<string name="title_advanced_manage_connectivity">Manage connectivity</string> <string name="title_advanced_manage_connectivity">Manage connectivity</string>
<string name="title_advanced_caption_general">General</string> <string name="title_advanced_caption_general">General</string>
<string name="title_advanced_caption_list">List</string>
<string name="title_advanced_caption_conversation">Conversation</string> <string name="title_advanced_caption_conversation">Conversation</string>
<string name="title_advanced_caption_message_header">Message header</string> <string name="title_advanced_caption_message_header">Message header</string>
<string name="title_advanced_caption_message_body">Message body</string> <string name="title_advanced_caption_message_body">Message body</string>

Loading…
Cancel
Save