Added option to go to previous conversation on closing conversation

pull/159/head
M66B 5 years ago
parent 4d3f19c5b3
commit f5ca9277c3

@ -260,12 +260,12 @@ public class ApplicationEx extends Application {
static void upgrade(Context context) { static void upgrade(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int version = prefs.getInt("version", BuildConfig.VERSION_CODE);
Log.i("Upgrading from " + version + " to " + BuildConfig.VERSION_CODE);
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
int version = prefs.getInt("version", BuildConfig.VERSION_CODE);
if (version < 468) { if (version < 468) {
Log.i("Upgrading from " + version + " to " + BuildConfig.VERSION_CODE);
editor.remove("notify_trash"); editor.remove("notify_trash");
editor.remove("notify_archive"); editor.remove("notify_archive");
editor.remove("notify_reply"); editor.remove("notify_reply");
@ -273,12 +273,16 @@ public class ApplicationEx extends Application {
editor.remove("notify_seen"); editor.remove("notify_seen");
} else if (version < 601) { } else if (version < 601) {
Log.i("Upgrading from " + version + " to " + BuildConfig.VERSION_CODE);
editor.putBoolean("contact_images", prefs.getBoolean("autoimages", true)); editor.putBoolean("contact_images", prefs.getBoolean("autoimages", true));
editor.remove("autoimages"); editor.remove("autoimages");
} else if (version < 612) {
if (prefs.getBoolean("autonext", false))
editor.putString("onclose", "next");
editor.remove("autonext");
} }
if (BuildConfig.DEBUG && false) { if (BuildConfig.DEBUG && false) {
editor.remove("app_support"); editor.remove("app_support");
editor.remove("notify_archive"); editor.remove("notify_archive");

@ -199,7 +199,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private boolean actionbar; private boolean actionbar;
private boolean autoexpand; private boolean autoexpand;
private boolean autoclose; private boolean autoclose;
private boolean autonext; private String onclose;
private boolean addresses; private boolean addresses;
private int colorPrimary; private int colorPrimary;
@ -224,7 +224,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private Long previous = null; private Long previous = null;
private Long next = null; private Long next = null;
private Long closeNext = null; private Long closeId = null;
private int autoCloseCount = 0; private int autoCloseCount = 0;
private boolean autoExpanded = true; private boolean autoExpanded = true;
private Map<String, List<Long>> values = new HashMap<>(); private Map<String, List<Long>> values = new HashMap<>();
@ -317,7 +317,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
actionbar = prefs.getBoolean("actionbar", true); actionbar = prefs.getBoolean("actionbar", true);
autoexpand = prefs.getBoolean("autoexpand", true); autoexpand = prefs.getBoolean("autoexpand", true);
autoclose = prefs.getBoolean("autoclose", true); autoclose = prefs.getBoolean("autoclose", true);
autonext = (!autoclose && prefs.getBoolean("autonext", false)); onclose = (autoclose ? null : prefs.getString("onclose", null));
addresses = prefs.getBoolean("addresses", false); addresses = prefs.getBoolean("addresses", false);
colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary); colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary);
@ -2684,31 +2684,36 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void loadMessages(final boolean top) { private void loadMessages(final boolean top) {
if (viewType == AdapterMessage.ViewType.THREAD && autonext) { if (viewType == AdapterMessage.ViewType.THREAD && onclose != null) {
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class); ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
model.observePrevNext(getViewLifecycleOwner(), id, new ViewModelMessages.IPrevNext() { model.observePrevNext(getViewLifecycleOwner(), id, new ViewModelMessages.IPrevNext() {
boolean once = false; boolean once = false;
@Override @Override
public void onPrevious(boolean exists, Long id) { public void onPrevious(boolean exists, Long id) {
// Do nothing onData(false, exists, id);
} }
@Override @Override
public void onNext(boolean exists, Long id) { public void onNext(boolean exists, Long id) {
if (!exists || id != null) { onData(true, exists, id);
closeNext = id;
if (!once) {
once = true;
loadMessagesNext(top);
}
}
} }
@Override @Override
public void onFound(int position, int size) { public void onFound(int position, int size) {
// Do nothing // Do nothing
} }
private void onData(boolean next, boolean exists, Long id) {
if ((next ? "next" : "previous").equals(onclose))
if (!exists || id != null) {
closeId = id;
if (!once) {
once = true;
loadMessagesNext(top);
}
}
}
}); });
} else if (viewType == AdapterMessage.ViewType.SEARCH && !reset) { } else if (viewType == AdapterMessage.ViewType.SEARCH && !reset) {
new SimpleTask<Void>() { new SimpleTask<Void>() {
@ -2825,7 +2830,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private boolean handleThreadActions(@NonNull PagedList<TupleMessageEx> messages) { private boolean handleThreadActions(@NonNull PagedList<TupleMessageEx> messages) {
// Auto close / next // Auto close / next
if (messages.size() == 0 && (autoclose || autonext)) { if (messages.size() == 0 && (autoclose || onclose != null)) {
handleAutoClose(); handleAutoClose();
return true; return true;
} }
@ -2912,7 +2917,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
} }
} else { } else {
if (autoCloseCount > 0 && (autoclose || autonext)) { if (autoCloseCount > 0 && (autoclose || onclose != null)) {
int count = 0; int count = 0;
for (int i = 0; i < messages.size(); i++) { for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i); TupleMessageEx message = messages.get(i);
@ -3058,12 +3063,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private void handleAutoClose() { private void handleAutoClose() {
if (autoclose) if (autoclose)
finish(); finish();
else if (autonext) { else if (onclose != null) {
if (closeNext == null) if (closeId == null)
finish(); finish();
else { else {
Log.i("Navigating to last next=" + closeNext); Log.i("Navigating to id=" + closeId);
navigate(closeNext, false); navigate(closeId, false);
} }
} }
} }

@ -40,7 +40,7 @@ public class FragmentOptions extends FragmentBase {
static String[] OPTIONS_RESTART = new String[]{ static String[] OPTIONS_RESTART = new String[]{
"startup", "date", "threading", "avatars", "generated_icons", "identicons", "circular", "name_email", "subject_italic", "flags", "preview", "startup", "date", "threading", "avatars", "generated_icons", "identicons", "circular", "name_email", "subject_italic", "flags", "preview",
"addresses", "attachments_alt", "contrast", "monospaced", "inline_images", "contact_images", "all_images", "collapse_quotes", "autocontent", "actionbar", "addresses", "attachments_alt", "contrast", "monospaced", "inline_images", "contact_images", "all_images", "collapse_quotes", "autocontent", "actionbar",
"autoscroll", "swipenav", "autoexpand", "autoclose", "autonext", "autoscroll", "swipenav", "autoexpand", "autoclose", "onclose",
"subscriptions", "debug", "subscriptions", "debug",
"biometrics" "biometrics"
}; };

@ -21,13 +21,16 @@ package eu.faircode.email;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -42,7 +45,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swDoubleTap; private SwitchCompat swDoubleTap;
private SwitchCompat swAutoExpand; private SwitchCompat swAutoExpand;
private SwitchCompat swAutoClose; private SwitchCompat swAutoClose;
private SwitchCompat swAutoNext; private Spinner spOnClose;
private SwitchCompat swCollapse; private SwitchCompat swCollapse;
private SwitchCompat swAutoRead; private SwitchCompat swAutoRead;
private SwitchCompat swAutoMove; private SwitchCompat swAutoMove;
@ -50,7 +53,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
private SwitchCompat swDisableTracking; private SwitchCompat swDisableTracking;
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"pull", "autoscroll", "swipenav", "doubletap", "autoexpand", "autoclose", "autonext", "pull", "autoscroll", "swipenav", "doubletap", "autoexpand", "autoclose", "onclose",
"collapse", "autoread", "automove", "authentication", "disable_tracking" "collapse", "autoread", "automove", "authentication", "disable_tracking"
}; };
@ -70,7 +73,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swDoubleTap = view.findViewById(R.id.swDoubleTap); swDoubleTap = view.findViewById(R.id.swDoubleTap);
swAutoExpand = view.findViewById(R.id.swAutoExpand); swAutoExpand = view.findViewById(R.id.swAutoExpand);
swAutoClose = view.findViewById(R.id.swAutoClose); swAutoClose = view.findViewById(R.id.swAutoClose);
swAutoNext = view.findViewById(R.id.swAutoNext); spOnClose = view.findViewById(R.id.spOnClose);
swCollapse = view.findViewById(R.id.swCollapse); swCollapse = view.findViewById(R.id.swCollapse);
swAutoRead = view.findViewById(R.id.swAutoRead); swAutoRead = view.findViewById(R.id.swAutoRead);
swAutoMove = view.findViewById(R.id.swAutoMove); swAutoMove = view.findViewById(R.id.swAutoMove);
@ -122,14 +125,24 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("autoclose", checked).apply(); prefs.edit().putBoolean("autoclose", checked).apply();
swAutoNext.setEnabled(!checked); spOnClose.setEnabled(!checked);
} }
}); });
swAutoNext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { spOnClose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
prefs.edit().putBoolean("autonext", checked).apply(); String[] values = getResources().getStringArray(R.array.onCloseValues);
String value = values[position];
if (TextUtils.isEmpty(value))
prefs.edit().remove("onclose").apply();
else
prefs.edit().putString("onclose", value).apply();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
prefs.edit().remove("onclose").apply();
} }
}); });
@ -219,8 +232,17 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
swDoubleTap.setChecked(prefs.getBoolean("doubletap", false)); swDoubleTap.setChecked(prefs.getBoolean("doubletap", false));
swAutoExpand.setChecked(prefs.getBoolean("autoexpand", true)); swAutoExpand.setChecked(prefs.getBoolean("autoexpand", true));
swAutoClose.setChecked(prefs.getBoolean("autoclose", true)); swAutoClose.setChecked(prefs.getBoolean("autoclose", true));
swAutoNext.setChecked(prefs.getBoolean("autonext", false));
swAutoNext.setEnabled(!swAutoClose.isChecked()); String onClose = prefs.getString("onclose", "");
String[] onCloseValues = getResources().getStringArray(R.array.onCloseValues);
for (int pos = 0; pos < onCloseValues.length; pos++)
if (onCloseValues[pos].equals(onClose)) {
spOnClose.setSelection(pos);
break;
}
spOnClose.setEnabled(!swAutoClose.isChecked());
swCollapse.setChecked(prefs.getBoolean("collapse", false)); swCollapse.setChecked(prefs.getBoolean("collapse", false));
swAutoRead.setChecked(prefs.getBoolean("autoread", false)); swAutoRead.setChecked(prefs.getBoolean("autoread", false));
swAutoMove.setChecked(!prefs.getBoolean("automove", false)); swAutoMove.setChecked(!prefs.getBoolean("automove", false));

@ -135,17 +135,27 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoClose" /> app:layout_constraintTop_toBottomOf="@id/swAutoClose" />
<androidx.appcompat.widget.SwitchCompat <TextView
android:id="@+id/swAutoNext" android:id="@+id/tvOnClose"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="48dp"
android:text="@string/title_advanced_autonext" android:text="@string/title_advanced_onclose"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
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/tvAutoCloseHint" app:layout_constraintTop_toBottomOf="@id/tvAutoCloseHint" />
app:switchPadding="12dp" />
<Spinner
android:id="@+id/spOnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:entries="@array/onCloseNames"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOnClose" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoRead" android:id="@+id/swAutoRead"
@ -155,7 +165,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/swAutoNext" app:layout_constraintTop_toBottomOf="@id/spOnClose"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -235,7 +235,7 @@
<string name="title_advanced_autoexpand">Automatically expand messages</string> <string name="title_advanced_autoexpand">Automatically expand messages</string>
<string name="title_advanced_collapse">Collapse messages in conversations on \'back\'</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_autoclose">Automatically close conversations</string>
<string name="title_advanced_autonext">Automatically go to next conversation on close conversation</string> <string name="title_advanced_onclose">On closing a conversation</string>
<string name="title_advanced_autoread">Automatically mark messages read on moving messages</string> <string name="title_advanced_autoread">Automatically mark messages read on moving messages</string>
<string name="title_advanced_automove">Confirm moving messages</string> <string name="title_advanced_automove">Confirm moving messages</string>
<string name="title_advanced_authentication">Show a warning when the receiving server could not authenticate the message</string> <string name="title_advanced_authentication">Show a warning when the receiving server could not authenticate the message</string>
@ -865,6 +865,18 @@
<item>0</item> <item>0</item>
</integer-array> </integer-array>
<string-array name="onCloseNames">
<item>Do nothing</item>
<item>Go to previous conversation</item>
<item>Go to next conversation</item>
</string-array>
<string-array name="onCloseValues" translatable="false">
<item></item>
<item>previous</item>
<item>next</item>
</string-array>
<string-array name="resizeNames"> <string-array name="resizeNames">
<item>Small</item> <item>Small</item>
<item>Medium</item> <item>Medium</item>

Loading…
Cancel
Save