Expand only one message at a time

This commit is contained in:
M66B 2019-09-14 18:51:51 +02:00
parent 765150d709
commit 8f4e488993
4 changed files with 38 additions and 2 deletions

View File

@ -1196,6 +1196,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public void setValue(String name, long id, boolean enabled) {
if (!values.containsKey(name))
values.put(name, new ArrayList<Long>());
if (enabled) {
if (!values.get(name).contains(id))
values.get(name).add(id);
@ -1203,6 +1204,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
values.get(name).remove(id);
if ("expanded".equals(name)) {
// Collapse other messages
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean expand_one = prefs.getBoolean("expand_one", false);
if (expand_one) {
for (Long other : new ArrayList<>(values.get(name)))
if (!other.equals(id)) {
values.get(name).remove(other);
int pos = adapter.getPositionForKey(other);
if (pos != RecyclerView.NO_POSITION)
adapter.notifyItemChanged(pos);
}
}
updateExpanded();
if (enabled)
handleExpand(id);

View File

@ -47,6 +47,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swDoubleTap;
private SwitchCompat swExpandRead;
private SwitchCompat swAutoExpand;
private SwitchCompat swExpandOne;
private SwitchCompat swAutoClose;
private Spinner spOnClose;
private SwitchCompat swCollapse;
@ -56,7 +57,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swDisableTracking;
private final static String[] RESET_OPTIONS = new String[]{
"pull", "autoscroll", "swipenav", "swipe_reversed", "doubletap", "expand_read", "autoexpand", "autoclose", "onclose",
"pull", "autoscroll", "swipenav", "swipe_reversed", "doubletap", "expand_read", "autoexpand", "expand_one", "autoclose", "onclose",
"collapse", "autoread", "automove", "discard_delete", "disable_tracking"
};
@ -77,6 +78,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swDoubleTap = view.findViewById(R.id.swDoubleTap);
swExpandRead = view.findViewById(R.id.swExpandRead);
swAutoExpand = view.findViewById(R.id.swAutoExpand);
swExpandOne = view.findViewById(R.id.swExpandOne);
swAutoClose = view.findViewById(R.id.swAutoClose);
spOnClose = view.findViewById(R.id.spOnClose);
swCollapse = view.findViewById(R.id.swCollapse);
@ -141,6 +143,13 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
}
});
swExpandOne.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("expand_one", checked).apply();
}
});
swAutoClose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -255,6 +264,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swDoubleTap.setChecked(prefs.getBoolean("doubletap", false));
swExpandRead.setChecked(prefs.getBoolean("expand_read", true));
swAutoExpand.setChecked(prefs.getBoolean("autoexpand", true));
swExpandOne.setChecked(prefs.getBoolean("expand_one", false));
swAutoClose.setChecked(prefs.getBoolean("autoclose", true));
String onClose = prefs.getString("onclose", "");

View File

@ -105,6 +105,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoExpand" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swExpandOne"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_expand_one"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutoExpandHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCollapse"
android:layout_width="0dp"
@ -113,7 +124,7 @@
android:text="@string/title_advanced_collapse"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutoExpandHint"
app:layout_constraintTop_toBottomOf="@id/swExpandOne"
app:switchPadding="12dp" />
<TextView

View File

@ -267,6 +267,7 @@
<string name="title_advanced_double_tap">Double tap to mark message read/unread</string>
<string name="title_advanced_expand_read">Mark messages read on expanding</string>
<string name="title_advanced_autoexpand">Automatically expand messages</string>
<string name="title_advanced_expand_one">Expand only one message at a time</string>
<string name="title_advanced_collapse">Collapse messages in conversations on \'back\'</string>
<string name="title_advanced_autoclose">Automatically close conversations</string>
<string name="title_advanced_onclose">On closing a conversation</string>