Added option to snooze until end of schedule

pull/160/head
M66B 6 years ago
parent 41bb207724
commit 267a845ac9

@ -349,7 +349,30 @@ public class EntityRule {
private boolean onActionSnooze(Context context, EntityMessage message, JSONObject jargs) throws JSONException { private boolean onActionSnooze(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
int duration = jargs.getInt("duration"); int duration = jargs.getInt("duration");
long wakeup = message.received + duration * 3600 * 1000L; boolean schedule_end = jargs.optBoolean("schedule_end", false);
long wakeup;
if (schedule_end) {
JSONObject jcondition = new JSONObject(condition);
JSONObject jschedule = jcondition.optJSONObject("schedule");
if (jschedule == null)
throw new IllegalArgumentException("Rule snooze schedule not found");
int start = jschedule.optInt("start", 0);
int end = jschedule.optInt("end", 0);
if (end <= start)
end += 24 * 60;
int hour = end / 60;
int minute = end % 60;
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, hour);
cal.set(Calendar.MINUTE, minute);
cal.set(Calendar.SECOND, 0);
wakeup = cal.getTimeInMillis();
} else
wakeup = message.received + duration * 3600 * 1000L;
if (wakeup < new Date().getTime()) if (wakeup < new Date().getTime())
return false; return false;

@ -40,6 +40,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
@ -108,6 +109,7 @@ public class FragmentRule extends FragmentBase {
private TextView tvActionRemark; private TextView tvActionRemark;
private NumberPicker npDuration; private NumberPicker npDuration;
private CheckBox cbScheduleEnd;
private Button btnColor; private Button btnColor;
private View vwColor; private View vwColor;
@ -205,6 +207,7 @@ public class FragmentRule extends FragmentBase {
tvActionRemark = view.findViewById(R.id.tvActionRemark); tvActionRemark = view.findViewById(R.id.tvActionRemark);
npDuration = view.findViewById(R.id.npDuration); npDuration = view.findViewById(R.id.npDuration);
cbScheduleEnd = view.findViewById(R.id.cbScheduleEnd);
btnColor = view.findViewById(R.id.btnColor); btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor); vwColor = view.findViewById(R.id.vwColor);
@ -348,6 +351,13 @@ public class FragmentRule extends FragmentBase {
npDuration.setMinValue(1); npDuration.setMinValue(1);
npDuration.setMaxValue(99); npDuration.setMaxValue(99);
cbScheduleEnd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
npDuration.setEnabled(!checked);
}
});
tvActionRemark.setVisibility(View.GONE); tvActionRemark.setVisibility(View.GONE);
onSelectColor(color); onSelectColor(color);
@ -578,12 +588,14 @@ public class FragmentRule extends FragmentBase {
int minutes = data.getIntExtra("minutes", 0); int minutes = data.getIntExtra("minutes", 0);
tvScheduleStart.setTag(minutes); tvScheduleStart.setTag(minutes);
tvScheduleStart.setText(formatHour(getContext(), minutes)); tvScheduleStart.setText(formatHour(getContext(), minutes));
cbScheduleEnd.setChecked(true);
} }
private void onScheduleEnd(Intent data) { private void onScheduleEnd(Intent data) {
int minutes = data.getIntExtra("minutes", 0); int minutes = data.getIntExtra("minutes", 0);
tvScheduleEnd.setTag(minutes); tvScheduleEnd.setTag(minutes);
tvScheduleEnd.setText(formatHour(getContext(), minutes)); tvScheduleEnd.setText(formatHour(getContext(), minutes));
cbScheduleEnd.setChecked(true);
} }
private void loadRule() { private void loadRule() {
@ -649,6 +661,7 @@ public class FragmentRule extends FragmentBase {
switch (type) { switch (type) {
case EntityRule.TYPE_SNOOZE: case EntityRule.TYPE_SNOOZE:
npDuration.setValue(jaction.getInt("duration")); npDuration.setValue(jaction.getInt("duration"));
cbScheduleEnd.setChecked(jaction.optBoolean("schedule_end", false));
break; break;
case EntityRule.TYPE_FLAG: case EntityRule.TYPE_FLAG:
@ -919,6 +932,7 @@ public class FragmentRule extends FragmentBase {
switch (action.type) { switch (action.type) {
case EntityRule.TYPE_SNOOZE: case EntityRule.TYPE_SNOOZE:
jaction.put("duration", npDuration.getValue()); jaction.put("duration", npDuration.getValue());
jaction.put("schedule_end", cbScheduleEnd.isChecked());
break; break;
case EntityRule.TYPE_FLAG: case EntityRule.TYPE_FLAG:

@ -463,6 +463,15 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvHours" /> app:layout_constraintTop_toBottomOf="@+id/tvHours" />
<CheckBox
android:id="@+id/cbScheduleEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_schedule_end"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/npDuration" />
<TextView <TextView
android:id="@+id/tvColor" android:id="@+id/tvColor"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -471,7 +480,7 @@
android:text="@string/title_color" android:text="@string/title_color"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/npDuration" /> app:layout_constraintTop_toBottomOf="@id/cbScheduleEnd" />
<Button <Button
android:id="@+id/btnColor" android:id="@+id/btnColor"
@ -618,7 +627,7 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids=" app:constraint_referenced_ids="
tvHours,npDuration" /> tvHours,npDuration,cbScheduleEnd" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpFlag" android:id="@+id/grpFlag"

@ -620,6 +620,7 @@
<string name="title_rule_action">Action</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_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_hours">Hours</string>
<string name="title_rule_schedule_end">Until the end of the time condition</string>
<string name="title_rule_folder">Folder</string> <string name="title_rule_folder">Folder</string>
<string name="title_rule_thread">All messages in same conversation and folder</string> <string name="title_rule_thread">All messages in same conversation and folder</string>
<string name="title_rule_identity">Identity</string> <string name="title_rule_identity">Identity</string>

Loading…
Cancel
Save