Added snooze to message view, refactoring

pull/148/head
M66B 5 years ago
parent fa8a081148
commit 00b0d6919f

@ -1099,6 +1099,7 @@ to justify making FairEmail available in the [Google Play Family Library](https:
**(67) How can I snooze conversations?**
Multiple select one of more conversations (long press to start multiple selecting), tap the three dot button and select *Snooze ...*.
Alternatively, use the *Snooze ...* 'more' menu in the expanded message view.
Select the time the conversation(s) should snooze and confirm by tapping OK.
The conversations will be hidden for the selected time and shown again afterwards.
You will receive a new message notification as reminder.

@ -1816,49 +1816,69 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:unseen");
}
private void onMenuJunk(final ActionData data) {
String who = MessageHelper.formatAddresses(data.message.from);
new DialogBuilderLifecycle(context, owner)
.setMessage(context.getString(R.string.title_ask_spam_who, who))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
private void onMenuSnooze(final ActionData data) {
DialogDuration.show(context, owner, R.string.title_snooze,
new DialogDuration.IDialogDuration() {
@Override
public void onClick(DialogInterface dialog, int which) {
public void onDurationSelected(long duration, long time) {
if (!Helper.isPro(context)) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
return;
}
Bundle args = new Bundle();
args.putLong("id", data.message.id);
args.putLong("wakeup", duration == 0 ? -1 : time);
new SimpleTask<Void>() {
new SimpleTask<Long>() {
@Override
protected Void onExecute(Context context, Bundle args) {
protected Long onExecute(Context context, Bundle args) {
long id = args.getLong("id");
Long wakeup = args.getLong("wakeup");
if (wakeup < 0)
wakeup = null;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK);
EntityOperation.queue(context, db, message, EntityOperation.MOVE, junk.id);
if (message != null) {
List<EntityMessage> messages = db.message().getMessageByThread(
message.account, message.thread, threading ? null : id, message.folder);
for (EntityMessage threaded : messages) {
db.message().setMessageSnoozed(threaded.id, wakeup);
EntityMessage.snooze(context, threaded.id, wakeup);
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
return wakeup;
}
@Override
protected void onExecuted(Bundle args, Long wakeup) {
if (wakeup != null)
properties.finish();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "message:spam");
}.execute(context, owner, args, "message:snooze");
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
@Override
public void onDismiss() {
}
});
}
private void onMenuDelete(final ActionData data) {
@ -1882,6 +1902,51 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:delete");
}
private void onMenuJunk(final ActionData data) {
String who = MessageHelper.formatAddresses(data.message.from);
new DialogBuilderLifecycle(context, owner)
.setMessage(context.getString(R.string.title_ask_spam_who, who))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK);
EntityOperation.queue(context, db, message, EntityOperation.MOVE, junk.id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, args, "message:spam");
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
private void onMenuShare(ActionData data) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
@ -2168,12 +2233,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(data.message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_delete).setVisible(debug);
popupMenu.getMenu().findItem(R.id.menu_junk).setEnabled(data.message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_junk).setVisible(
data.hasJunk && !EntityFolder.JUNK.equals(data.message.folderType));
popupMenu.getMenu().findItem(R.id.menu_delete).setVisible(debug);
popupMenu.getMenu().findItem(R.id.menu_share).setEnabled(data.message.content);
popupMenu.getMenu().findItem(R.id.menu_show_headers).setChecked(show_headers);
@ -2206,13 +2271,16 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_unseen:
onMenuUnseen(data);
return true;
case R.id.menu_junk:
onMenuJunk(data);
case R.id.menu_snooze:
onMenuSnooze(data);
return true;
case R.id.menu_delete:
// For emergencies
onMenuDelete(data);
return true;
case R.id.menu_junk:
onMenuJunk(data);
return true;
case R.id.menu_share:
onMenuShare(data);
return true;
@ -2682,5 +2750,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
void scrollTo(int pos, int dy);
void move(long id, String target, boolean type);
void finish();
}
}

@ -664,6 +664,11 @@ public class FragmentMessages extends FragmentBase {
}
}.execute(FragmentMessages.this, args, "messages:move");
}
@Override
public void finish() {
FragmentMessages.this.finish();
}
};
private ItemTouchHelper.Callback touchHelper = new ItemTouchHelper.Callback() {

@ -17,13 +17,17 @@
android:title="@string/title_unseen" />
<item
android:id="@+id/menu_junk"
android:title="@string/title_spam" />
android:id="@+id/menu_snooze"
android:title="@string/title_snooze" />
<item
android:id="@+id/menu_delete"
android:title="@string/title_delete" />
<item
android:id="@+id/menu_junk"
android:title="@string/title_spam" />
<item
android:id="@+id/menu_share"
android:title="@string/title_share" />

Loading…
Cancel
Save