Added hiding messages

pull/163/head
M66B 5 years ago
parent 04adcaf221
commit 5d2a1c4266

@ -793,6 +793,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivType.setImageResource(icon); ivType.setImageResource(icon);
} }
ibSnoozed.setImageResource(
message.ui_snoozed != null && message.ui_snoozed == Long.MAX_VALUE
? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_timelapse_24);
ivPriority.setVisibility(EntityMessage.PRIORITIY_HIGH.equals(message.priority) ? View.VISIBLE : View.GONE); ivPriority.setVisibility(EntityMessage.PRIORITIY_HIGH.equals(message.priority) ? View.VISIBLE : View.GONE);
ibAuth.setVisibility(authentication && !authenticated ? View.VISIBLE : View.GONE); ibAuth.setVisibility(authentication && !authenticated ? View.VISIBLE : View.GONE);
ibSnoozed.setVisibility(message.ui_snoozed == null ? View.GONE : View.VISIBLE); ibSnoozed.setVisibility(message.ui_snoozed == null ? View.GONE : View.VISIBLE);
@ -2126,7 +2130,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onShowSnoozed(TupleMessageEx message) { private void onShowSnoozed(TupleMessageEx message) {
if (message.ui_snoozed != null) { if (message.ui_snoozed != null && message.ui_snoozed != Long.MAX_VALUE) {
DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT); DateFormat DTF = Helper.getDateTimeInstance(context, SimpleDateFormat.MEDIUM, SimpleDateFormat.SHORT);
DateFormat D = new SimpleDateFormat("E"); DateFormat D = new SimpleDateFormat("E");
ToastEx.makeText( ToastEx.makeText(
@ -2866,6 +2870,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled( popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(
(message.uid != null && !message.folderReadOnly) || message.accountPop); (message.uid != null && !message.folderReadOnly) || message.accountPop);
popupMenu.getMenu().findItem(R.id.menu_hide).setTitle(message.ui_snoozed == null ? R.string.title_hide : R.string.title_unhide);
popupMenu.getMenu().findItem(R.id.menu_flag_color).setEnabled( popupMenu.getMenu().findItem(R.id.menu_flag_color).setEnabled(
(message.uid != null && !message.folderReadOnly) || message.accountPop); (message.uid != null && !message.folderReadOnly) || message.accountPop);
@ -2914,6 +2920,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_unseen: case R.id.menu_unseen:
onMenuUnseen(message); onMenuUnseen(message);
return true; return true;
case R.id.menu_hide:
onMenuHide(message);
return true;
case R.id.menu_flag_color: case R.id.menu_flag_color:
onMenuColoredStar(message); onMenuColoredStar(message);
return true; return true;
@ -3124,6 +3133,43 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:unseen"); }.execute(context, owner, args, "message:unseen");
} }
private void onMenuHide(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("hide", message.ui_snoozed == null);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean hide = args.getBoolean("hide");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
db.message().setMessageSnoozed(message.id, hide ? Long.MAX_VALUE : null);
EntityMessage.snooze(context, message.id, hide ? Long.MAX_VALUE : null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(parentFragment.getFragmentManager(), ex);
}
}.execute(context, owner, args, "message:hide");
}
private void onMenuColoredStar(final TupleMessageEx message) { private void onMenuColoredStar(final TupleMessageEx message) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);

@ -130,6 +130,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
case EntityRule.TYPE_UNSEEN: case EntityRule.TYPE_UNSEEN:
tvAction.setText(R.string.title_rule_unseen); tvAction.setText(R.string.title_rule_unseen);
break; break;
case EntityRule.TYPE_HIDE:
tvAction.setText(R.string.title_rule_hide);
break;
case EntityRule.TYPE_IGNORE: case EntityRule.TYPE_IGNORE:
tvAction.setText(R.string.title_rule_ignore); tvAction.setText(R.string.title_rule_ignore);
break; break;

@ -238,7 +238,7 @@ public class EntityMessage implements Serializable {
PendingIntent pi = PendingIntent.getService(context, ServiceUI.PI_WAKEUP, snoozed, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pi = PendingIntent.getService(context, ServiceUI.PI_WAKEUP, snoozed, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (wakeup == null) { if (wakeup == null || wakeup == Long.MAX_VALUE) {
Log.i("Cancel snooze id=" + id); Log.i("Cancel snooze id=" + id);
am.cancel(pi); am.cancel(pi);
} else { } else {

@ -97,6 +97,7 @@ public class EntityRule {
static final int TYPE_IGNORE = 9; static final int TYPE_IGNORE = 9;
static final int TYPE_NOOP = 10; static final int TYPE_NOOP = 10;
static final int TYPE_KEYWORD = 11; static final int TYPE_KEYWORD = 11;
static final int TYPE_HIDE = 12;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION"; static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule"; static final String EXTRA_RULE = "rule";
@ -274,6 +275,8 @@ public class EntityRule {
return onActionSeen(context, message, true); return onActionSeen(context, message, true);
case TYPE_UNSEEN: case TYPE_UNSEEN:
return onActionSeen(context, message, false); return onActionSeen(context, message, false);
case TYPE_HIDE:
return onActionHide(context, message);
case TYPE_IGNORE: case TYPE_IGNORE:
return onActionIgnore(context, message, jaction); return onActionIgnore(context, message, jaction);
case TYPE_SNOOZE: case TYPE_SNOOZE:
@ -304,6 +307,17 @@ public class EntityRule {
return true; return true;
} }
private boolean onActionHide(Context context, EntityMessage message) {
DB db = DB.getInstance(context);
db.message().setMessageSnoozed(message.id, Long.MAX_VALUE);
db.message().setMessageUiIgnored(message.id, true);
EntityMessage.snooze(context, message.id, Long.MAX_VALUE);
message.ui_snoozed = Long.MAX_VALUE;
message.ui_ignored = true;
return true;
}
private boolean onActionIgnore(Context context, EntityMessage message, JSONObject jargs) { private boolean onActionIgnore(Context context, EntityMessage message, JSONObject jargs) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.message().setMessageUiIgnored(message.id, true); db.message().setMessageUiIgnored(message.id, true);

@ -147,6 +147,7 @@ public class FragmentAccount extends FragmentBase {
static final Long SWIPE_ACTION_ASK = -1L; static final Long SWIPE_ACTION_ASK = -1L;
static final Long SWIPE_ACTION_SEEN = -2L; static final Long SWIPE_ACTION_SEEN = -2L;
static final Long SWIPE_ACTION_SNOOZE = -3L; static final Long SWIPE_ACTION_SNOOZE = -3L;
static final Long SWIPE_ACTION_HIDE = -4L;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -1441,6 +1442,11 @@ public class FragmentAccount extends FragmentBase {
snooze.name = getString(R.string.title_snooze_now); snooze.name = getString(R.string.title_snooze_now);
folders.add(snooze); folders.add(snooze);
EntityFolder hide = new EntityFolder();
hide.id = SWIPE_ACTION_HIDE;
hide.name = getString(R.string.title_hide);
folders.add(hide);
folders.addAll(_folders); folders.addAll(_folders);
adapterSwipe.clear(); adapterSwipe.clear();

@ -1434,6 +1434,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
icon = (message.ui_seen ? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_visibility_24); icon = (message.ui_seen ? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_visibility_24);
else if (FragmentAccount.SWIPE_ACTION_SNOOZE.equals(action)) else if (FragmentAccount.SWIPE_ACTION_SNOOZE.equals(action))
icon = (message.ui_snoozed == null ? R.drawable.baseline_timelapse_24 : R.drawable.baseline_timer_off_24); icon = (message.ui_snoozed == null ? R.drawable.baseline_timelapse_24 : R.drawable.baseline_timer_off_24);
else if (FragmentAccount.SWIPE_ACTION_HIDE.equals(action))
icon = (message.ui_snoozed == null ? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_visibility_24);
else else
icon = EntityFolder.getIcon(dX > 0 ? swipes.right_type : swipes.left_type); icon = EntityFolder.getIcon(dX > 0 ? swipes.right_type : swipes.left_type);
Drawable d = getResources().getDrawable(icon, getContext().getTheme()).mutate(); Drawable d = getResources().getDrawable(icon, getContext().getTheme()).mutate();
@ -1496,6 +1498,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onActionSeenSelection(!message.ui_seen, message.id); onActionSeenSelection(!message.ui_seen, message.id);
else if (FragmentAccount.SWIPE_ACTION_SNOOZE.equals(action)) else if (FragmentAccount.SWIPE_ACTION_SNOOZE.equals(action))
onActionSnooze(message); onActionSnooze(message);
else if (FragmentAccount.SWIPE_ACTION_HIDE.equals(action))
onActionHide(message);
else else
swipeFolder(message, action); swipeFolder(message, action);
} }
@ -1928,6 +1932,17 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
onSnooze(args); onSnooze(args);
} }
private void onActionHide(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("account", message.account);
args.putString("thread", message.thread);
args.putLong("id", message.id);
args.putLong("duration", message.ui_snoozed == null ? Long.MAX_VALUE : 0);
args.putLong("time", message.ui_snoozed == null ? Long.MAX_VALUE : 0);
onSnooze(args);
}
private void onActionSnoozeSelection() { private void onActionSnoozeSelection() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("title", getString(R.string.title_snooze)); args.putString("title", getString(R.string.title_snooze));
@ -2648,7 +2663,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
ibSeen.setImageResource(filter_seen ? R.drawable.baseline_drafts_24 : R.drawable.baseline_mail_24); ibSeen.setImageResource(filter_seen ? R.drawable.baseline_drafts_24 : R.drawable.baseline_mail_24);
ibUnflagged.setImageResource(filter_unflagged ? R.drawable.baseline_star_border_24 : R.drawable.baseline_star_24); ibUnflagged.setImageResource(filter_unflagged ? R.drawable.baseline_star_border_24 : R.drawable.baseline_star_24);
ibSnoozed.setImageResource(filter_snoozed ? R.drawable.baseline_timelapse_24 : R.drawable.baseline_timer_off_24); ibSnoozed.setImageResource(filter_snoozed ? R.drawable.baseline_visibility_off_24 : R.drawable.baseline_visibility_24);
ibSeen.setVisibility(experiments && folder ? View.VISIBLE : View.GONE); ibSeen.setVisibility(experiments && folder ? View.VISIBLE : View.GONE);
ibUnflagged.setVisibility(experiments && folder ? View.VISIBLE : View.GONE); ibUnflagged.setVisibility(experiments && folder ? View.VISIBLE : View.GONE);
@ -4235,8 +4250,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
account, thread, threading ? null : id, null); account, thread, threading ? null : id, null);
for (EntityMessage threaded : messages) { for (EntityMessage threaded : messages) {
db.message().setMessageSnoozed(threaded.id, wakeup); db.message().setMessageSnoozed(threaded.id, wakeup);
EntityMessage.snooze(context, threaded.id, wakeup);
EntityOperation.queue(context, threaded, EntityOperation.SEEN, true); EntityOperation.queue(context, threaded, EntityOperation.SEEN, true);
EntityMessage.snooze(context, threaded.id, wakeup);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();

@ -329,6 +329,7 @@ public class FragmentRule extends FragmentBase {
actions.add(new Action(EntityRule.TYPE_NOOP, getString(R.string.title_rule_noop))); actions.add(new Action(EntityRule.TYPE_NOOP, getString(R.string.title_rule_noop)));
actions.add(new Action(EntityRule.TYPE_SEEN, getString(R.string.title_rule_seen))); actions.add(new Action(EntityRule.TYPE_SEEN, getString(R.string.title_rule_seen)));
actions.add(new Action(EntityRule.TYPE_UNSEEN, getString(R.string.title_rule_unseen))); actions.add(new Action(EntityRule.TYPE_UNSEEN, getString(R.string.title_rule_unseen)));
actions.add(new Action(EntityRule.TYPE_HIDE, getString(R.string.title_rule_hide)));
actions.add(new Action(EntityRule.TYPE_IGNORE, getString(R.string.title_rule_ignore))); actions.add(new Action(EntityRule.TYPE_IGNORE, getString(R.string.title_rule_ignore)));
actions.add(new Action(EntityRule.TYPE_SNOOZE, getString(R.string.title_rule_snooze))); actions.add(new Action(EntityRule.TYPE_SNOOZE, getString(R.string.title_rule_snooze)));
actions.add(new Action(EntityRule.TYPE_FLAG, getString(R.string.title_rule_flag))); actions.add(new Action(EntityRule.TYPE_FLAG, getString(R.string.title_rule_flag)));

@ -716,17 +716,6 @@
app:layout_constraintStart_toEndOf="@id/barrier_folders" app:layout_constraintStart_toEndOf="@id/barrier_folders"
app:layout_constraintTop_toBottomOf="@id/spLeft" /> app:layout_constraintTop_toBottomOf="@id/spLeft" />
<TextView
android:id="@+id/tvHideRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_hide_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spRight" />
<!-- save --> <!-- save -->
<Button <Button
@ -737,7 +726,7 @@
android:tag="disable" android:tag="disable"
android:text="@string/title_save" android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHideRemark" /> app:layout_constraintTop_toBottomOf="@id/spRight" />
<eu.faircode.email.ContentLoadingProgressBar <eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbSave" android:id="@+id/pbSave"

@ -42,7 +42,7 @@
android:title="@string/title_sort_on_size" /> android:title="@string/title_sort_on_size" />
<item <item
android:id="@+id/menu_sort_on_snoozed" android:id="@+id/menu_sort_on_snoozed"
android:title="@string/title_sort_on_snoozed" /> android:title="@string/title_sort_on_hidden" />
</group> </group>
<item <item
android:id="@+id/menu_ascending" android:id="@+id/menu_ascending"
@ -71,7 +71,7 @@
<item <item
android:id="@+id/menu_filter_snoozed" android:id="@+id/menu_filter_snoozed"
android:checkable="true" android:checkable="true"
android:title="@string/title_filter_snoozed" /> android:title="@string/title_filter_hidden" />
<item <item
android:id="@+id/menu_filter_duplicates" android:id="@+id/menu_filter_duplicates"

@ -8,6 +8,10 @@
android:id="@+id/menu_unseen" android:id="@+id/menu_unseen"
android:title="@string/title_unseen" /> android:title="@string/title_unseen" />
<item
android:id="@+id/menu_hide"
android:title="@string/title_hide" />
<item <item
android:id="@+id/menu_flag_color" android:id="@+id/menu_flag_color"
android:title="@string/title_flag_color" /> android:title="@string/title_flag_color" />

@ -430,7 +430,6 @@
<string name="title_no_sync">Synchronization errors since %1$s</string> <string name="title_no_sync">Synchronization errors since %1$s</string>
<string name="title_identity_required">An identity is required to send messages</string> <string name="title_identity_required">An identity is required to send messages</string>
<string name="title_drafts_required">A drafts folder is required to send messages</string> <string name="title_drafts_required">A drafts folder is required to send messages</string>
<string name="title_hide_remark">Messages can be hidden by snoozing messages</string>
<string name="title_account_delete">Delete this account permanently?</string> <string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string> <string name="title_identity_delete">Delete this identity permanently?</string>
<string name="title_edit_html">Edit as HTML</string> <string name="title_edit_html">Edit as HTML</string>
@ -507,6 +506,8 @@
<string name="title_seen">Mark read</string> <string name="title_seen">Mark read</string>
<string name="title_unseen">Mark unread</string> <string name="title_unseen">Mark unread</string>
<string name="title_hide">Hide</string>
<string name="title_unhide">Show</string>
<string name="title_flag">Add star</string> <string name="title_flag">Add star</string>
<string name="title_flag_color">Colored star &#8230;</string> <string name="title_flag_color">Colored star &#8230;</string>
<string name="title_unflag">Remove star</string> <string name="title_unflag">Remove star</string>
@ -661,13 +662,13 @@
<string name="title_sort_on_sender">Sender</string> <string name="title_sort_on_sender">Sender</string>
<string name="title_sort_on_subject">Subject</string> <string name="title_sort_on_subject">Subject</string>
<string name="title_sort_on_size">Size</string> <string name="title_sort_on_size">Size</string>
<string name="title_sort_on_snoozed">Snoozed</string> <string name="title_sort_on_hidden">Hidden</string>
<string name="title_sort_ascending">Oldest first</string> <string name="title_sort_ascending">Oldest first</string>
<string name="title_filter">Filter out</string> <string name="title_filter">Filter out</string>
<string name="title_filter_seen">Read</string> <string name="title_filter_seen">Read</string>
<string name="title_filter_unflagged">Unstarred</string> <string name="title_filter_unflagged">Unstarred</string>
<string name="title_filter_snoozed">Snoozed</string> <string name="title_filter_hidden">Hidden</string>
<string name="title_filter_duplicates">Duplicates</string> <string name="title_filter_duplicates">Duplicates</string>
<string name="title_compact">Compact view</string> <string name="title_compact">Compact view</string>
@ -689,6 +690,7 @@
<string name="title_rule_noop">No action</string> <string name="title_rule_noop">No action</string>
<string name="title_rule_seen">Mark read</string> <string name="title_rule_seen">Mark read</string>
<string name="title_rule_unseen">Mark unread</string> <string name="title_rule_unseen">Mark unread</string>
<string name="title_rule_hide">Hide</string>
<string name="title_rule_ignore">Suppress notification</string> <string name="title_rule_ignore">Suppress notification</string>
<string name="title_rule_snooze">Snooze</string> <string name="title_rule_snooze">Snooze</string>
<string name="title_rule_flag">Add star</string> <string name="title_rule_flag">Add star</string>

Loading…
Cancel
Save