Prepare opening folder / new message notification

This commit is contained in:
M66B 2023-08-02 08:03:00 +02:00
parent e03e5ee160
commit 96032d78a9
6 changed files with 87 additions and 25 deletions

View File

@ -147,7 +147,14 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
}
DB db = DB.getInstance(context);
return db.message().getMessage(id);
EntityMessage message = db.message().getMessage(id);
if (message != null) {
EntityFolder folder = db.folder().getFolder(message.folder);
if (folder != null)
args.putString("type", folder.type);
}
return message;
}
@Override
@ -157,13 +164,16 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
if (message == null)
return;
String type = args.getString("type");
Intent thread = new Intent(ActivityMain.this, ActivityView.class);
thread.setAction("thread:" + message.id);
thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
thread.putExtra("account", message.account);
thread.putExtra("folder", message.folder);
thread.putExtra("type", type);
thread.putExtra("thread", message.thread);
thread.putExtra("filter_archive", true);
thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type));
thread.putExtra("pinned", true);
thread.putExtra("msgid", message.msgid);

View File

@ -1987,11 +1987,31 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
} else if (action.startsWith("thread")) {
long id = Long.parseLong(action.split(":", 2)[1]);
long account = intent.getLongExtra("account", -1);
long folder = intent.getLongExtra("folder", -1);
String type = intent.getStringExtra("type");
boolean ignore = intent.getBooleanExtra("ignore", false);
long group = intent.getLongExtra("group", -1L);
if (ignore)
ServiceUI.ignore(this, id, group);
intent.putExtra("id", id);
if (account > 0 && folder > 0 && !TextUtils.isEmpty(type) && BuildConfig.DEBUG) {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
getSupportFragmentManager().popBackStack("messages", FragmentManager.POP_BACK_STACK_INCLUSIVE);
Bundle args = new Bundle();
args.putLong("account", account);
args.putLong("folder", folder);
args.putString("type", type);
FragmentMessages fragment = new FragmentMessages();
fragment.setArguments(args);
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("messages");
fragmentTransaction.commit();
}
}
onViewThread(intent);
} else if (action.startsWith("widget")) {

View File

@ -5861,6 +5861,7 @@ class Core {
thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
thread.putExtra("account", message.account);
thread.putExtra("folder", message.folder);
thread.putExtra("type", message.folderType);
thread.putExtra("thread", message.thread);
thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(message.folderType));
thread.putExtra("ignore", notify_remove);

View File

@ -278,7 +278,7 @@ public interface DaoMessage {
" AND ui_hide")
LiveData<List<Long>> liveHiddenThread(long account, String thread);
@Query("SELECT message.* FROM message" +
@Query("SELECT message.id FROM message" +
" JOIN folder_view AS folder ON folder.id = message.folder" +
" WHERE message.account = :account" +
" AND message.thread = :thread" +
@ -288,7 +288,7 @@ public interface DaoMessage {
" AND folder.type <> '" + EntityFolder.ARCHIVE + "'" +
" AND NOT ui_seen" +
" AND NOT ui_hide")
LiveData<List<EntityMessage>> liveUnreadThread(long account, String thread);
LiveData<List<Long>> liveUnreadThread(long account, String thread);
static String FTS_STATS = "SELECT SUM(fts) AS fts, COUNT(*) AS total FROM message" +
" JOIN folder_view AS folder ON folder.id = message.folder" +

View File

@ -6337,21 +6337,21 @@ public class FragmentCompose extends FragmentBase {
boolean threading = prefs.getBoolean("threading", true);
if (threading)
db.message().liveUnreadThread(data.draft.account, data.draft.thread).observe(getViewLifecycleOwner(), new Observer<List<EntityMessage>>() {
db.message().liveUnreadThread(data.draft.account, data.draft.thread).observe(getViewLifecycleOwner(), new Observer<List<Long>>() {
private int lastDiff = 0;
private List<EntityMessage> base = null;
private List<Long> base = null;
@Override
public void onChanged(List<EntityMessage> messages) {
if (messages == null)
public void onChanged(List<Long> ids) {
if (ids == null)
return;
if (base == null) {
base = messages;
base = ids;
return;
}
int diff = (messages.size() - base.size());
int diff = (ids.size() - base.size());
if (diff > lastDiff) {
lastDiff = diff;
String msg = getResources().getQuantityString(
@ -6362,21 +6362,51 @@ public class FragmentCompose extends FragmentBase {
snackbar.setAction(R.string.title_show, new View.OnClickListener() {
@Override
public void onClick(View v) {
EntityMessage message = messages.get(0);
boolean notify_remove = prefs.getBoolean("notify_remove", true);
Bundle args = new Bundle();
args.putLong("id", ids.get(0));
Intent thread = new Intent(v.getContext(), ActivityView.class);
thread.setAction("thread:" + message.id);
// No group
thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
thread.putExtra("account", message.account);
thread.putExtra("folder", message.folder);
thread.putExtra("thread", message.thread);
thread.putExtra("filter_archive", true);
thread.putExtra("ignore", notify_remove);
new SimpleTask<EntityMessage>() {
@Override
protected EntityMessage onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
v.getContext().startActivity(thread);
getActivity().finish();
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message != null) {
EntityFolder folder = db.folder().getFolder(message.id);
if (folder != null)
args.putString("type", folder.type);
}
return message;
}
@Override
protected void onExecuted(Bundle args, EntityMessage message) {
boolean notify_remove = prefs.getBoolean("notify_remove", true);
String type = args.getString("type");
Intent thread = new Intent(v.getContext(), ActivityView.class);
thread.setAction("thread:" + message.id);
// No group
thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
thread.putExtra("account", message.account);
thread.putExtra("folder", message.folder);
thread.putExtra("type", type);
thread.putExtra("thread", message.thread);
thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type));
thread.putExtra("ignore", notify_remove);
v.getContext().startActivity(thread);
getActivity().finish();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentCompose.this, args, "compose:unread");
}
});
snackbar.show();

View File

@ -278,14 +278,15 @@ class Shortcuts {
}
@NonNull
static ShortcutInfoCompat.Builder getShortcut(Context context, EntityMessage message, String label, ContactInfo[] contactInfo) {
static ShortcutInfoCompat.Builder getShortcut(Context context, TupleMessageEx message, String label, ContactInfo[] contactInfo) {
Intent thread = new Intent(context, ActivityView.class);
thread.setAction("thread:" + message.id);
thread.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
thread.putExtra("account", message.account);
thread.putExtra("folder", message.folder);
thread.putExtra("type", message.folderType);
thread.putExtra("thread", message.thread);
thread.putExtra("filter_archive", true);
thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(message.folderType));
thread.putExtra("pinned", true);
thread.putExtra("msgid", message.msgid);