1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-29 19:25:34 +00:00

Load next once

This reverts commit f645c8b396.
This commit is contained in:
M66B 2019-01-30 15:31:34 +00:00
parent f645c8b396
commit 9ec35c4487
5 changed files with 82 additions and 22 deletions

1
FAQ.md
View file

@ -36,7 +36,6 @@ Anything on this list is in random order and *might* be added in the near future
## Frequently requested features
* Swipe left/right to go to previous/next message: besides that swiping left/right is already being used to move messages to archive/trash, swiping also selects message text, so this will not work reliably. You can use the bottom navigation bar instead.
* Automatically go to next message: after closing a conversation thread it is not possible anymore to reliably determine the next conversation thread without delays. Note that most apps implementing something similar work with individual messages instead of conversations and don't support two way synchronization.
* Rich text editor: besides that very few people would use this on a small mobile device, Android doesn't support a rich text editor and most rich text editor open source projects are abandoned.
* Widget to read e-mail: widgets can have limited user interaction only, so a widget to read e-mail would not be very useful. Moreover, it would be not very useful to duplicate functions which are already available in the app.
* Badge count: there is no standard Android API for this and third party solutions might stop working anytime. For example *ShortcutBadger* [has lots of problems](https://github.com/leolin310148/ShortcutBadger/issues). You can use the provided widget instead.

View file

@ -117,6 +117,7 @@ public class FragmentMessages extends FragmentBase {
private boolean pull;
private boolean actionbar;
private boolean autoclose;
private boolean autonext;
private boolean addresses;
private long primary = -1;
@ -128,6 +129,7 @@ public class FragmentMessages extends FragmentBase {
private AdapterMessage.ViewType viewType;
private SelectionTracker<Long> selectionTracker = null;
private Long next = null;
private int autoCloseCount = 0;
private boolean autoExpand = true;
private Map<String, List<Long>> values = new HashMap<>();
@ -186,6 +188,7 @@ public class FragmentMessages extends FragmentBase {
threading = prefs.getBoolean("threading", true);
actionbar = prefs.getBoolean("actionbar", true);
autoclose = prefs.getBoolean("autoclose", true);
autonext = prefs.getBoolean("autonext", false);
addresses = prefs.getBoolean("addresses", true);
}
@ -292,12 +295,6 @@ public class FragmentMessages extends FragmentBase {
bottom_navigation.getMenu().findItem(R.id.action_next).setIntent(new Intent().putExtra("id", id));
bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(id != null);
}
@Override
public void onDeleted() {
bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(false);
bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(false);
}
});
}
} else {
@ -1754,6 +1751,32 @@ public class FragmentMessages extends FragmentBase {
}
private void loadMessages() {
if (viewType == AdapterMessage.ViewType.THREAD && autonext) {
ViewModelMessages model = ViewModelProviders.of(getActivity()).get(ViewModelMessages.class);
model.observePrevNext(getViewLifecycleOwner(), thread, new ViewModelMessages.IPrevNext() {
boolean once = false;
@Override
public void onPrevious(boolean exists, Long id) {
// Do nothing
}
@Override
public void onNext(boolean exists, Long id) {
if (!exists || id != null) {
next = id;
if (!once) {
once = true;
loadMessagesNext();
}
}
}
});
} else
loadMessagesNext();
}
private void loadMessagesNext() {
ViewModelBrowse modelBrowse = ViewModelProviders.of(getActivity()).get(ViewModelBrowse.class);
modelBrowse.set(getContext(), folder, search, REMOTE_PAGE_SIZE);
@ -1847,8 +1870,9 @@ public class FragmentMessages extends FragmentBase {
@Override
public void onChanged(@Nullable PagedList<TupleMessageEx> messages) {
if (messages == null ||
(viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 && autoclose)) {
finish();
(viewType == AdapterMessage.ViewType.THREAD && messages.size() == 0 &&
(autoclose || autonext))) {
handleAutoClose();
return;
}
@ -1947,7 +1971,7 @@ public class FragmentMessages extends FragmentBase {
handleExpand(expand.id);
}
} else {
if (autoCloseCount > 0 && autoclose) {
if (autoCloseCount > 0 && (autoclose || autonext)) {
int count = 0;
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i);
@ -1964,7 +1988,7 @@ public class FragmentMessages extends FragmentBase {
// - no more non archived/trashed/sent messages
if (count == 0) {
finish();
handleAutoClose();
return;
}
}
@ -2079,6 +2103,19 @@ public class FragmentMessages extends FragmentBase {
}.execute(this, args, "messages:expand");
}
private void handleAutoClose() {
if (autoclose)
finish();
else if (autonext) {
if (next == null)
finish();
else {
Log.i("Navigating to last next=" + next);
navigate(next);
}
}
}
private void navigate(long id) {
Bundle args = new Bundle();
args.putLong("id", id);
@ -2091,14 +2128,17 @@ public class FragmentMessages extends FragmentBase {
@Override
protected void onExecuted(Bundle args, EntityMessage message) {
if (message != null) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", message.account)
.putExtra("thread", message.thread)
.putExtra("id", message.id));
if (message == null) {
finish();
return;
}
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_VIEW_THREAD)
.putExtra("account", message.account)
.putExtra("thread", message.thread)
.putExtra("id", message.id));
}
@Override

View file

@ -74,6 +74,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swPull;
private SwitchCompat swActionbar;
private SwitchCompat swAutoClose;
private SwitchCompat swAutoNext;
private SwitchCompat swAutoRead;
private SwitchCompat swCollapse;
private SwitchCompat swAutoMove;
@ -133,6 +134,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swPull = view.findViewById(R.id.swPull);
swActionbar = view.findViewById(R.id.swActionbar);
swAutoClose = view.findViewById(R.id.swAutoClose);
swAutoNext = view.findViewById(R.id.swAutoNext);
swAutoRead = view.findViewById(R.id.swAutoRead);
swCollapse = view.findViewById(R.id.swCollapse);
swAutoMove = view.findViewById(R.id.swAutoMove);
@ -289,6 +291,14 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("autoclose", checked).apply();
swAutoNext.setEnabled(!checked);
}
});
swAutoNext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("autonext", checked).apply();
}
});
@ -449,6 +459,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swPull.setChecked(prefs.getBoolean("pull", true));
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
swAutoClose.setChecked(prefs.getBoolean("autoclose", true));
swAutoNext.setChecked(prefs.getBoolean("autonext", false));
swAutoNext.setEnabled(!swAutoClose.isChecked());
swAutoRead.setChecked(prefs.getBoolean("autoread", false));
swCollapse.setChecked(prefs.getBoolean("collapse", false));
swAutoMove.setChecked(!prefs.getBoolean("automove", false));

View file

@ -117,7 +117,6 @@ public class ViewModelMessages extends ViewModel {
}
Log.w("Observe previous/next gone thread=" + thread);
intf.onDeleted();
}
});
}
@ -136,7 +135,5 @@ public class ViewModelMessages extends ViewModel {
void onPrevious(boolean exists, Long id);
void onNext(boolean exists, Long id);
void onDeleted();
}
}

View file

@ -386,6 +386,18 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoClose" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoNext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_autonext"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutocloseHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoRead"
android:layout_width="match_parent"
@ -395,7 +407,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_autoread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutocloseHint"
app:layout_constraintTop_toBottomOf="@id/swAutoNext"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat