mirror of https://github.com/M66B/FairEmail.git
Added option to go to previous conversation on closing conversation
This commit is contained in:
parent
4d3f19c5b3
commit
f5ca9277c3
|
@ -260,12 +260,12 @@ public class ApplicationEx extends Application {
|
|||
|
||||
static void upgrade(Context 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();
|
||||
|
||||
int version = prefs.getInt("version", BuildConfig.VERSION_CODE);
|
||||
if (version < 468) {
|
||||
Log.i("Upgrading from " + version + " to " + BuildConfig.VERSION_CODE);
|
||||
|
||||
editor.remove("notify_trash");
|
||||
editor.remove("notify_archive");
|
||||
editor.remove("notify_reply");
|
||||
|
@ -273,12 +273,16 @@ public class ApplicationEx extends Application {
|
|||
editor.remove("notify_seen");
|
||||
|
||||
} else if (version < 601) {
|
||||
Log.i("Upgrading from " + version + " to " + BuildConfig.VERSION_CODE);
|
||||
|
||||
editor.putBoolean("contact_images", prefs.getBoolean("autoimages", true));
|
||||
editor.remove("autoimages");
|
||||
|
||||
} else if (version < 612) {
|
||||
if (prefs.getBoolean("autonext", false))
|
||||
editor.putString("onclose", "next");
|
||||
editor.remove("autonext");
|
||||
}
|
||||
|
||||
|
||||
if (BuildConfig.DEBUG && false) {
|
||||
editor.remove("app_support");
|
||||
editor.remove("notify_archive");
|
||||
|
|
|
@ -199,7 +199,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
private boolean actionbar;
|
||||
private boolean autoexpand;
|
||||
private boolean autoclose;
|
||||
private boolean autonext;
|
||||
private String onclose;
|
||||
private boolean addresses;
|
||||
|
||||
private int colorPrimary;
|
||||
|
@ -224,7 +224,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
private Long previous = null;
|
||||
private Long next = null;
|
||||
private Long closeNext = null;
|
||||
private Long closeId = null;
|
||||
private int autoCloseCount = 0;
|
||||
private boolean autoExpanded = true;
|
||||
private Map<String, List<Long>> values = new HashMap<>();
|
||||
|
@ -317,7 +317,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
actionbar = prefs.getBoolean("actionbar", true);
|
||||
autoexpand = prefs.getBoolean("autoexpand", true);
|
||||
autoclose = prefs.getBoolean("autoclose", true);
|
||||
autonext = (!autoclose && prefs.getBoolean("autonext", false));
|
||||
onclose = (autoclose ? null : prefs.getString("onclose", null));
|
||||
addresses = prefs.getBoolean("addresses", false);
|
||||
|
||||
colorPrimary = Helper.resolveColor(getContext(), R.attr.colorPrimary);
|
||||
|
@ -2684,31 +2684,36 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}
|
||||
|
||||
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);
|
||||
model.observePrevNext(getViewLifecycleOwner(), id, new ViewModelMessages.IPrevNext() {
|
||||
boolean once = false;
|
||||
|
||||
@Override
|
||||
public void onPrevious(boolean exists, Long id) {
|
||||
// Do nothing
|
||||
onData(false, exists, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(boolean exists, Long id) {
|
||||
if (!exists || id != null) {
|
||||
closeNext = id;
|
||||
if (!once) {
|
||||
once = true;
|
||||
loadMessagesNext(top);
|
||||
}
|
||||
}
|
||||
onData(true, exists, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFound(int position, int size) {
|
||||
// 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) {
|
||||
new SimpleTask<Void>() {
|
||||
|
@ -2825,7 +2830,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
private boolean handleThreadActions(@NonNull PagedList<TupleMessageEx> messages) {
|
||||
// Auto close / next
|
||||
if (messages.size() == 0 && (autoclose || autonext)) {
|
||||
if (messages.size() == 0 && (autoclose || onclose != null)) {
|
||||
handleAutoClose();
|
||||
return true;
|
||||
}
|
||||
|
@ -2912,7 +2917,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (autoCloseCount > 0 && (autoclose || autonext)) {
|
||||
if (autoCloseCount > 0 && (autoclose || onclose != null)) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
TupleMessageEx message = messages.get(i);
|
||||
|
@ -3058,12 +3063,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
private void handleAutoClose() {
|
||||
if (autoclose)
|
||||
finish();
|
||||
else if (autonext) {
|
||||
if (closeNext == null)
|
||||
else if (onclose != null) {
|
||||
if (closeId == null)
|
||||
finish();
|
||||
else {
|
||||
Log.i("Navigating to last next=" + closeNext);
|
||||
navigate(closeNext, false);
|
||||
Log.i("Navigating to id=" + closeId);
|
||||
navigate(closeId, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class FragmentOptions extends FragmentBase {
|
|||
static String[] OPTIONS_RESTART = new String[]{
|
||||
"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",
|
||||
"autoscroll", "swipenav", "autoexpand", "autoclose", "autonext",
|
||||
"autoscroll", "swipenav", "autoexpand", "autoclose", "onclose",
|
||||
"subscriptions", "debug",
|
||||
"biometrics"
|
||||
};
|
||||
|
|
|
@ -21,13 +21,16 @@ package eu.faircode.email;
|
|||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
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;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -42,7 +45,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
private SwitchCompat swDoubleTap;
|
||||
private SwitchCompat swAutoExpand;
|
||||
private SwitchCompat swAutoClose;
|
||||
private SwitchCompat swAutoNext;
|
||||
private Spinner spOnClose;
|
||||
private SwitchCompat swCollapse;
|
||||
private SwitchCompat swAutoRead;
|
||||
private SwitchCompat swAutoMove;
|
||||
|
@ -50,7 +53,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
private SwitchCompat swDisableTracking;
|
||||
|
||||
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"
|
||||
};
|
||||
|
||||
|
@ -70,7 +73,7 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
swDoubleTap = view.findViewById(R.id.swDoubleTap);
|
||||
swAutoExpand = view.findViewById(R.id.swAutoExpand);
|
||||
swAutoClose = view.findViewById(R.id.swAutoClose);
|
||||
swAutoNext = view.findViewById(R.id.swAutoNext);
|
||||
spOnClose = view.findViewById(R.id.spOnClose);
|
||||
swCollapse = view.findViewById(R.id.swCollapse);
|
||||
swAutoRead = view.findViewById(R.id.swAutoRead);
|
||||
swAutoMove = view.findViewById(R.id.swAutoMove);
|
||||
|
@ -122,14 +125,24 @@ public class FragmentOptionsBehavior extends FragmentBase implements SharedPrefe
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("autoclose", checked).apply();
|
||||
swAutoNext.setEnabled(!checked);
|
||||
spOnClose.setEnabled(!checked);
|
||||
}
|
||||
});
|
||||
|
||||
swAutoNext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
spOnClose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("autonext", checked).apply();
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
||||
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));
|
||||
swAutoExpand.setChecked(prefs.getBoolean("autoexpand", 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));
|
||||
swAutoRead.setChecked(prefs.getBoolean("autoread", false));
|
||||
swAutoMove.setChecked(!prefs.getBoolean("automove", false));
|
||||
|
|
|
@ -135,17 +135,27 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swAutoClose" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swAutoNext"
|
||||
<TextView
|
||||
android:id="@+id/tvOnClose"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:text="@string/title_advanced_autonext"
|
||||
android:layout_marginEnd="48dp"
|
||||
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_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAutoCloseHint"
|
||||
app:switchPadding="12dp" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAutoCloseHint" />
|
||||
|
||||
<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
|
||||
android:id="@+id/swAutoRead"
|
||||
|
@ -155,7 +165,7 @@
|
|||
android:text="@string/title_advanced_autoread"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swAutoNext"
|
||||
app:layout_constraintTop_toBottomOf="@id/spOnClose"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
|
|
|
@ -235,7 +235,7 @@
|
|||
<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_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_automove">Confirm moving messages</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>
|
||||
</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">
|
||||
<item>Small</item>
|
||||
<item>Medium</item>
|
||||
|
|
Loading…
Reference in New Issue