Added snooze rule

pull/156/head
M66B 6 years ago
parent 401b2d723a
commit 74004c0829

@ -114,6 +114,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
case EntityRule.TYPE_UNSEEN:
tvAction.setText(R.string.title_rule_unseen);
break;
case EntityRule.TYPE_SNOOZE:
tvAction.setText(R.string.title_rule_snooze);
break;
case EntityRule.TYPE_FLAG:
tvAction.setText(R.string.title_rule_flag);
break;

@ -85,6 +85,7 @@ public class EntityRule {
static final int TYPE_AUTOMATION = 5;
static final int TYPE_FLAG = 6;
static final int TYPE_COPY = 7;
static final int TYPE_SNOOZE = 8;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule";
@ -208,6 +209,9 @@ public class EntityRule {
case TYPE_UNSEEN:
onActionSeen(context, message, false);
break;
case TYPE_SNOOZE:
onActionSnooze(context, message, jaction);
break;
case TYPE_FLAG:
onActionFlag(context, message, jaction);
break;
@ -318,6 +322,16 @@ public class EntityRule {
}
}
private void onActionSnooze(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
int duration = jargs.getInt("duration");
long wakeup = new Date().getTime() + duration * 3600 * 1000L;
DB db = DB.getInstance(context);
db.message().setMessageSnoozed(message.id, wakeup);
EntityMessage.snooze(context, message.id, wakeup);
onActionSeen(context, message, true);
}
private void onActionFlag(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
Integer color = (jargs.has("color") && !jargs.isNull("color")
? jargs.getInt("color") : null);

@ -40,6 +40,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.NumberPicker;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
@ -94,6 +95,8 @@ public class FragmentRule extends FragmentBase {
private Spinner spAction;
private TextView tvActionRemark;
private NumberPicker npDuration;
private Button btnColor;
private View vwColor;
private ImageView ibColorDefault;
@ -111,6 +114,7 @@ public class FragmentRule extends FragmentBase {
private ContentLoadingProgressBar pbWait;
private Group grpReady;
private Group grpSnooze;
private Group grpFlag;
private Group grpMove;
private Group grpAnswer;
@ -173,6 +177,10 @@ public class FragmentRule extends FragmentBase {
spAction = view.findViewById(R.id.spAction);
tvActionRemark = view.findViewById(R.id.tvActionRemark);
npDuration = view.findViewById(R.id.npDuration);
npDuration.setMinValue(1);
npDuration.setMaxValue(99);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
@ -190,6 +198,7 @@ public class FragmentRule extends FragmentBase {
pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady);
grpSnooze = view.findViewById(R.id.grpSnooze);
grpFlag = view.findViewById(R.id.grpFlag);
grpMove = view.findViewById(R.id.grpMove);
grpAnswer = view.findViewById(R.id.grpAnswer);
@ -236,6 +245,7 @@ public class FragmentRule extends FragmentBase {
List<Action> actions = new ArrayList<>();
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_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_MOVE, getString(R.string.title_rule_move)));
actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy)));
@ -329,6 +339,7 @@ public class FragmentRule extends FragmentBase {
tvFolder.setText(null);
bottom_navigation.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
grpSnooze.setVisibility(View.GONE);
grpFlag.setVisibility(View.GONE);
grpMove.setVisibility(View.GONE);
grpAnswer.setVisibility(View.GONE);
@ -478,6 +489,10 @@ public class FragmentRule extends FragmentBase {
} else {
int type = jaction.getInt("type");
switch (type) {
case EntityRule.TYPE_SNOOZE:
npDuration.setValue(jaction.getInt("duration"));
break;
case EntityRule.TYPE_FLAG:
setColor(jaction.isNull("color") ? null : jaction.getInt("color"));
break;
@ -763,6 +778,7 @@ public class FragmentRule extends FragmentBase {
}
private void showActionParameters(int type) {
grpSnooze.setVisibility(type == EntityRule.TYPE_SNOOZE ? View.VISIBLE : View.GONE);
grpFlag.setVisibility(type == EntityRule.TYPE_FLAG ? View.VISIBLE : View.GONE);
grpMove.setVisibility(type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY ? View.VISIBLE : View.GONE);
grpAnswer.setVisibility(type == EntityRule.TYPE_ANSWER ? View.VISIBLE : View.GONE);
@ -826,6 +842,10 @@ public class FragmentRule extends FragmentBase {
if (action != null) {
jaction.put("type", action.type);
switch (action.type) {
case EntityRule.TYPE_SNOOZE:
jaction.put("duration", npDuration.getValue());
break;
case EntityRule.TYPE_FLAG:
jaction.put("color", color);
break;

@ -369,6 +369,23 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvActionRemark" />
<TextView
android:id="@+id/tvHours"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_hours"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorParameters" />
<NumberPicker
android:id="@+id/npDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvHours" />
<Button
android:id="@+id/btnColor"
style="@style/buttonStyleSmall"
@ -380,7 +397,7 @@
android:tag="disable"
android:text="@string/title_account_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorParameters" />
app:layout_constraintTop_toBottomOf="@id/npDuration" />
<View
android:id="@+id/vwColor"
@ -490,6 +507,13 @@
vSeparatorAction,tvAction,spAction,tvActionRemark,
vSeparatorParameters" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpSnooze"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
tvHours,npDuration" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFlag"
android:layout_width="0dp"

@ -541,6 +541,7 @@
<string name="title_rule_seen">Mark read</string>
<string name="title_rule_unseen">Mark unread</string>
<string name="title_rule_snooze">Snooze</string>
<string name="title_rule_flag">Add star</string>
<string name="title_rule_move">Move</string>
<string name="title_rule_copy">Copy (label)</string>
@ -561,6 +562,7 @@
<string name="title_rule_and">AND</string>
<string name="title_rule_action">Action</string>
<string name="title_rule_action_remark">This action will be applied to new messages arriving in the folder %1$s</string>
<string name="title_rule_hours">Hours</string>
<string name="title_rule_folder">Folder</string>
<string name="title_rule_identity">Identity</string>
<string name="title_rule_template">Reply template</string>

Loading…
Cancel
Save