mirror of https://github.com/M66B/FairEmail.git
Broadcast new message to scroll to top
This commit is contained in:
parent
23e311bb80
commit
3747814289
|
@ -37,6 +37,7 @@ import android.util.Pair;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.RemoteInput;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.sun.mail.iap.BadCommandException;
|
||||
|
@ -2178,6 +2179,16 @@ class Core {
|
|||
|
||||
runRules(context, imessage, message, rules);
|
||||
|
||||
// Prepare scroll to top
|
||||
if (!message.ui_seen && message.received > account.created) {
|
||||
Intent report = new Intent(FragmentMessages.ACTION_NEW_MESSAGE);
|
||||
report.putExtra("folder", folder.id);
|
||||
report.putExtra("unified", folder.unified);
|
||||
|
||||
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
|
||||
lbm.sendBroadcast(report);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} catch (SQLiteConstraintException ex) {
|
||||
Log.e(ex);
|
||||
|
|
|
@ -262,6 +262,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
|
||||
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
|
||||
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
|
||||
static final String ACTION_NEW_MESSAGE = BuildConfig.APPLICATION_ID + ".NEW_MESSAGE";
|
||||
|
||||
private static final List<String> DUPLICATE_ORDER = Collections.unmodifiableList(Arrays.asList(
|
||||
EntityFolder.INBOX,
|
||||
|
@ -2560,6 +2561,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
IntentFilter iff = new IntentFilter();
|
||||
iff.addAction(ACTION_STORE_RAW);
|
||||
iff.addAction(ACTION_DECRYPT);
|
||||
iff.addAction(ACTION_NEW_MESSAGE);
|
||||
lbm.registerReceiver(receiver, iff);
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
@ -3184,27 +3186,26 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
if (messages == null)
|
||||
return;
|
||||
|
||||
if (viewType == AdapterMessage.ViewType.THREAD)
|
||||
if (viewType == AdapterMessage.ViewType.THREAD) {
|
||||
if (handleThreadActions(messages))
|
||||
return;
|
||||
|
||||
if (viewType != AdapterMessage.ViewType.SEARCH) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean autoscroll = prefs.getBoolean("autoscroll", true);
|
||||
|
||||
boolean gotoTop = false;
|
||||
for (int i = 0; i < messages.size() && i < ViewModelMessages.LOCAL_PAGE_SIZE; i++) {
|
||||
TupleMessageEx message = messages.get(i);
|
||||
if (message != null && !ids.contains(message.id)) {
|
||||
ids.add(message.id);
|
||||
if (!message.ui_seen && !message.duplicate)
|
||||
gotoTop = true;
|
||||
if (autoscroll) {
|
||||
boolean gotoTop = false;
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
TupleMessageEx message = messages.get(i);
|
||||
if (message != null && !ids.contains(message.id)) {
|
||||
ids.add(message.id);
|
||||
if (!message.ui_seen && !message.duplicate)
|
||||
gotoTop = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gotoTop &&
|
||||
(autoscroll || viewType == AdapterMessage.ViewType.THREAD))
|
||||
adapter.gotoTop();
|
||||
if (gotoTop)
|
||||
adapter.gotoTop();
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("Submit messages=" + messages.size());
|
||||
|
@ -3850,6 +3851,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
onStoreRaw(intent);
|
||||
else if (ACTION_DECRYPT.equals(action))
|
||||
onDecrypt(intent);
|
||||
else if (ACTION_NEW_MESSAGE.equals(action))
|
||||
onNewMessage(intent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -3880,6 +3883,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
Snackbar.make(view, R.string.title_no_openpgp, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void onNewMessage(Intent intent) {
|
||||
long fid = intent.getLongExtra("folder", -1);
|
||||
boolean unified = intent.getBooleanExtra("unified", false);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean autoscroll = prefs.getBoolean("autoscroll", true);
|
||||
|
||||
if (autoscroll &&
|
||||
((viewType == AdapterMessage.ViewType.UNIFIED && unified) ||
|
||||
(viewType == AdapterMessage.ViewType.FOLDER && folder == fid)))
|
||||
adapter.gotoTop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ViewModelMessages extends ViewModel {
|
|||
|
||||
private ExecutorService executor = Helper.getBackgroundExecutor(2, "model");
|
||||
|
||||
static final int LOCAL_PAGE_SIZE = 100;
|
||||
private static final int LOCAL_PAGE_SIZE = 100;
|
||||
private static final int REMOTE_PAGE_SIZE = 10;
|
||||
private static final int SEARCH_PAGE_SIZE = 10;
|
||||
private static final int LOW_MEM_MB = 32;
|
||||
|
|
Loading…
Reference in New Issue