Scroll to top after recreate

pull/175/head
M66B 5 years ago
parent c552142458
commit 1e2d0be945

@ -124,6 +124,8 @@ import static androidx.core.app.NotificationCompat.DEFAULT_SOUND;
import static javax.mail.Folder.READ_WRITE; import static javax.mail.Folder.READ_WRITE;
class Core { class Core {
static final Map<Long, EntityFolder> newMessages = new HashMap<>();
private static final int MAX_NOTIFICATION_COUNT = 25; // per group private static final int MAX_NOTIFICATION_COUNT = 25; // per group
private static final long AFTER_SEND_DELAY = 15 * 1000L; // milliseconds private static final long AFTER_SEND_DELAY = 15 * 1000L; // milliseconds
private static final int SYNC_CHUNCK_SIZE = 200; private static final int SYNC_CHUNCK_SIZE = 200;
@ -2301,6 +2303,10 @@ class Core {
// Prepare scroll to top // Prepare scroll to top
if (!message.ui_seen && message.received > account.created) { if (!message.ui_seen && message.received > account.created) {
synchronized (newMessages) {
newMessages.put(folder.id, folder);
}
Intent report = new Intent(FragmentMessages.ACTION_NEW_MESSAGE); Intent report = new Intent(FragmentMessages.ACTION_NEW_MESSAGE);
report.putExtra("folder", folder.id); report.putExtra("folder", folder.id);
report.putExtra("unified", folder.unified); report.putExtra("unified", folder.unified);

@ -3751,6 +3751,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (handleThreadActions(messages)) if (handleThreadActions(messages))
return; return;
checkNewMessages();
Log.i("Submit messages=" + messages.size()); Log.i("Submit messages=" + messages.size());
adapter.submitList(messages); adapter.submitList(messages);
@ -4476,6 +4478,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
long fid = intent.getLongExtra("folder", -1); long fid = intent.getLongExtra("folder", -1);
boolean unified = intent.getBooleanExtra("unified", false); boolean unified = intent.getBooleanExtra("unified", false);
synchronized (Core.newMessages) {
Core.newMessages.remove(fid);
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean autoscroll = prefs.getBoolean("autoscroll", true); boolean autoscroll = prefs.getBoolean("autoscroll", true);
@ -4485,6 +4491,27 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
adapter.gotoTop(); adapter.gotoTop();
} }
private void checkNewMessages() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean autoscroll = prefs.getBoolean("autoscroll", true);
boolean newMessages = false;
synchronized (Core.newMessages) {
for (long fid : new ArrayList<>(Core.newMessages.keySet())) {
EntityFolder f = Core.newMessages.get(fid);
if (f != null &&
((viewType == AdapterMessage.ViewType.UNIFIED && f.unified) ||
(viewType == AdapterMessage.ViewType.FOLDER && folder == f.id))) {
newMessages = true;
Core.newMessages.remove(fid);
}
}
}
if (autoscroll && newMessages)
adapter.gotoTop();
}
private void onStoreRaw(Intent intent) { private void onStoreRaw(Intent intent) {
message = intent.getLongExtra("id", -1); message = intent.getLongExtra("id", -1);
Intent create = new Intent(Intent.ACTION_CREATE_DOCUMENT); Intent create = new Intent(Intent.ACTION_CREATE_DOCUMENT);

Loading…
Cancel
Save