From 3755dc4d3b76cd19b0860e2d2ee566a6f3679d71 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 22 Aug 2021 20:12:13 +0200 Subject: [PATCH] Folder type specific scroll to top --- .../java/eu/faircode/email/ActivityView.java | 30 ++++++++++++++----- app/src/main/java/eu/faircode/email/Core.java | 5 +++- .../eu/faircode/email/FragmentMessages.java | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index ce407e4e14..2d70a19bab 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -41,6 +41,7 @@ import android.net.Uri; import android.os.Bundle; import android.text.TextUtils; import android.util.DisplayMetrics; +import android.util.Pair; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; @@ -1652,23 +1653,36 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB } }; - private List updatedFolders = new ArrayList<>(); + private List> updatedFolders = new ArrayList<>(); - boolean isFolderUpdated(long folder) { - boolean value = updatedFolders.contains(folder); + boolean isFolderUpdated(Long folder, String type) { + Pair key = new Pair<>( + folder == null ? -1L : folder, + folder == null ? type : null); + boolean value = updatedFolders.contains(key); if (value) - updatedFolders.remove(folder); + updatedFolders.remove(key); return value; } private void onNewMessage(Intent intent) { long folder = intent.getLongExtra("folder", -1); + String type = intent.getStringExtra("type"); boolean unified = intent.getBooleanExtra("unified", false); - if (!updatedFolders.contains(folder)) - updatedFolders.add(folder); - if (unified && !updatedFolders.contains(-1L)) - updatedFolders.add(-1L); + Pair pfolder = new Pair<>(folder, null); + if (!updatedFolders.contains(pfolder)) + updatedFolders.add(pfolder); + + Pair ptype = new Pair<>(-1L, type); + if (!updatedFolders.contains(ptype)) + updatedFolders.add(ptype); + + if (unified) { + Pair punified = new Pair<>(-1L, null); + if (!updatedFolders.contains(punified)) + updatedFolders.add(punified); + } } private BroadcastReceiver receiver = new BroadcastReceiver() { diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index c482cc4f10..62dde16d72 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -3918,8 +3918,11 @@ class Core { message.received > account.created) { Intent report = new Intent(ActivityView.ACTION_NEW_MESSAGE); report.putExtra("folder", folder.id); + report.putExtra("type", folder.type); report.putExtra("unified", folder.unified); - Log.i("Report new id=" + message.id + " folder=" + folder.name + " unified=" + folder.unified); + Log.i("Report new id=" + message.id + + " folder=" + folder.type + ":" + folder.name + + " unified=" + folder.unified); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context); lbm.sendBroadcast(report); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 6cbc82a0d2..86b7c572ea 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -5066,7 +5066,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences. if (autoscroll) { ActivityView activity = (ActivityView) getActivity(); if (activity != null && - activity.isFolderUpdated(viewType == AdapterMessage.ViewType.UNIFIED ? -1L : folder)) + activity.isFolderUpdated(viewType == AdapterMessage.ViewType.UNIFIED ? null : folder, type)) adapter.gotoTop(); } }