Moved snooze to action bar

pull/156/head
M66B 6 years ago
parent 340b22897a
commit 2135d9bfa5

@ -2137,71 +2137,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:unseen");
}
private void onMenuSnooze(final ActionData data) {
DialogDuration.show(context, owner, R.string.title_snooze,
new DialogDuration.IDialogDuration() {
@Override
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<Long>() {
@Override
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) {
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 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:snooze");
}
@Override
public void onDismiss() {
}
});
}
private void onMenuCopy(final ActionData data) {
Bundle args = new Bundle();
args.putLong("id", data.message.id);
@ -2753,9 +2688,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_unseen:
onMenuUnseen(data);
return true;
case R.id.menu_snooze:
onMenuSnooze(data);
return true;
case R.id.menu_copy:
onMenuCopy(data);
return true;

@ -446,6 +446,10 @@ public class FragmentMessages extends FragmentBase {
onActionMove(EntityFolder.TRASH);
return true;
case R.id.action_snooze:
onActionSnooze();
return true;
case R.id.action_archive:
onActionMove(EntityFolder.ARCHIVE);
return true;
@ -1093,6 +1097,72 @@ public class FragmentMessages extends FragmentBase {
}.execute(FragmentMessages.this, args, "messages:move");
}
private void onActionSnooze() {
DialogDuration.show(getContext(), getViewLifecycleOwner(), R.string.title_snooze,
new DialogDuration.IDialogDuration() {
@Override
public void onDurationSelected(long duration, long time) {
if (!Helper.isPro(getContext())) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
return;
}
Bundle args = new Bundle();
args.putLong("account", account);
args.putString("thread", thread);
args.putLong("id", id);
args.putLong("wakeup", duration == 0 ? -1 : time);
new SimpleTask<Long>() {
@Override
protected Long onExecute(Context context, Bundle args) {
long account = args.getLong("account");
String thread = args.getString("thread");
long id = args.getLong("id");
Long wakeup = args.getLong("wakeup");
if (wakeup < 0)
wakeup = null;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
List<EntityMessage> messages = db.message().getMessageByThread(
account, thread, threading ? null : id, null);
for (EntityMessage threaded : messages) {
db.message().setMessageSnoozed(threaded.id, wakeup);
EntityMessage.snooze(context, threaded.id, wakeup);
EntityOperation.queue(context, db, threaded, EntityOperation.SEEN, true);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return wakeup;
}
@Override
protected void onExecuted(Bundle args, Long wakeup) {
if (wakeup != null)
finish();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
}.execute(getContext(), getViewLifecycleOwner(), args, "message:snooze");
}
@Override
public void onDismiss() {
}
});
}
private void onMore() {
Bundle args = new Bundle();
args.putLongArray("ids", getSelection());
@ -2530,6 +2600,7 @@ public class FragmentMessages extends FragmentBase {
account, thread, threading ? null : id, null);
boolean trashable = false;
boolean snoozable = false;
boolean archivable = false;
for (EntityMessage message : messages) {
EntityFolder folder = db.folder().getFolder(message.folder);
@ -2539,6 +2610,10 @@ public class FragmentMessages extends FragmentBase {
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type))
trashable = true;
if (!EntityFolder.OUTBOX.equals(folder.type))
snoozable = true;
if (!EntityFolder.isOutgoing(folder.type) &&
!EntityFolder.TRASH.equals(folder.type) &&
!EntityFolder.JUNK.equals(folder.type) &&
@ -2552,13 +2627,14 @@ public class FragmentMessages extends FragmentBase {
trashable = (trashable && trash != null);
archivable = (archivable && archive != null);
return new Boolean[]{trashable, archivable};
return new Boolean[]{trashable, snoozable, archivable};
}
@Override
protected void onExecuted(Bundle args, Boolean[] data) {
bottom_navigation.getMenu().findItem(R.id.action_delete).setVisible(data[0]);
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data[1]);
bottom_navigation.getMenu().findItem(R.id.action_snooze).setVisible(data[1]);
bottom_navigation.getMenu().findItem(R.id.action_archive).setVisible(data[2]);
bottom_navigation.setVisibility(View.VISIBLE);
}

@ -11,6 +11,11 @@
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_trash" />
<item
android:id="@+id/action_snooze"
android:icon="@drawable/baseline_timelapse_24"
android:title="@string/title_snooze" />
<item
android:id="@+id/action_archive"
android:icon="@drawable/baseline_archive_24"

@ -11,6 +11,11 @@
android:icon="@drawable/baseline_delete_24"
android:title="@string/title_trash" />
<item
android:id="@+id/action_snooze"
android:icon="@drawable/baseline_timelapse_24"
android:title="@string/title_snooze" />
<item
android:id="@+id/action_archive"
android:icon="@drawable/baseline_archive_24"

@ -8,10 +8,6 @@
android:id="@+id/menu_unseen"
android:title="@string/title_unseen" />
<item
android:id="@+id/menu_snooze"
android:title="@string/title_snooze" />
<item
android:id="@+id/menu_copy"
android:title="@string/title_copy" />

Loading…
Cancel
Save