Added rule to add (colored) flag

pull/156/head
M66B 6 years ago
parent 90760f9ee8
commit 8b0096f702

@ -83,6 +83,7 @@ public class EntityRule {
static final int TYPE_MOVE = 3;
static final int TYPE_ANSWER = 4;
static final int TYPE_AUTOMATION = 5;
static final int TYPE_FLAG = 6;
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
static final String EXTRA_RULE = "rule";
@ -206,6 +207,9 @@ public class EntityRule {
case TYPE_UNSEEN:
onActionSeen(context, db, message, false);
break;
case TYPE_FLAG:
onActionFlag(context, db, message, jaction);
break;
case TYPE_MOVE:
onActionMove(context, db, message, jaction);
break;
@ -293,6 +297,12 @@ public class EntityRule {
}
}
private void onActionFlag(Context context, DB db, EntityMessage message, JSONObject jargs) throws JSONException {
Integer color = (jargs.has("color") && !jargs.isNull("color")
? jargs.getInt("color") : null);
EntityOperation.queue(context, db, message, EntityOperation.FLAG, true, color);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityRule) {

@ -23,6 +23,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@ -34,6 +36,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
@ -47,6 +50,8 @@ import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction;
import com.android.colorpicker.ColorPickerDialog;
import com.android.colorpicker.ColorPickerSwatch;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.snackbar.Snackbar;
@ -86,16 +91,25 @@ public class FragmentRule extends FragmentBase {
private Spinner spAction;
private TextView tvActionRemark;
private Button btnColor;
private View vwColor;
private ImageView ibColorDefault;
private Spinner spTarget;
private Spinner spIdent;
private Spinner spAnswer;
private CheckBox cbCc;
private TextView tvAutomation;
private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait;
private Group grpReady;
private Group grpFlag;
private Group grpMove;
private Group grpAnswer;
private Group grpAutomation;
@ -108,6 +122,7 @@ public class FragmentRule extends FragmentBase {
private long id = -1;
private long account = -1;
private long folder = -1;
private Integer color = null;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -153,16 +168,25 @@ public class FragmentRule extends FragmentBase {
spAction = view.findViewById(R.id.spAction);
tvActionRemark = view.findViewById(R.id.tvActionRemark);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
spTarget = view.findViewById(R.id.spTarget);
spIdent = view.findViewById(R.id.spIdent);
spAnswer = view.findViewById(R.id.spAnswer);
cbCc = view.findViewById(R.id.cbCc);
tvAutomation = view.findViewById(R.id.tvAutomation);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady);
grpFlag = view.findViewById(R.id.grpFlag);
grpMove = view.findViewById(R.id.grpMove);
grpAnswer = view.findViewById(R.id.grpAnswer);
grpAutomation = view.findViewById(R.id.grpAutomation);
@ -208,6 +232,7 @@ public class FragmentRule extends FragmentBase {
List<Action> actions = new ArrayList<>();
actions.add(new Action(EntityRule.TYPE_SEEN, getString(R.string.title_seen)));
actions.add(new Action(EntityRule.TYPE_UNSEEN, getString(R.string.title_unseen)));
actions.add(new Action(EntityRule.TYPE_FLAG, getString(R.string.title_flag)));
actions.add(new Action(EntityRule.TYPE_MOVE, getString(R.string.title_move)));
actions.add(new Action(EntityRule.TYPE_ANSWER, getString(R.string.title_answer_reply)));
actions.add(new Action(EntityRule.TYPE_AUTOMATION, getString(R.string.title_rule_automation)));
@ -243,6 +268,32 @@ public class FragmentRule extends FragmentBase {
tvActionRemark.setVisibility(View.GONE);
vwColor.setBackgroundColor(color == null ? Color.TRANSPARENT : color);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int color = (FragmentRule.this.color == null ? Color.TRANSPARENT : FragmentRule.this.color);
int[] colors = getContext().getResources().getIntArray(R.array.colorPicker);
ColorPickerDialog colorPickerDialog = new ColorPickerDialog();
colorPickerDialog.initialize(R.string.title_account_color, colors, color, 4, colors.length);
colorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {
@Override
public void onColorSelected(int color) {
setColor(color);
}
});
colorPickerDialog.show(getFragmentManager(), "colorpicker");
}
});
ibColorDefault.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setColor(null);
}
});
tvAutomation.setText(getString(R.string.title_rule_automation_hint,
EntityRule.ACTION_AUTOMATION,
TextUtils.join(",", new String[]{
@ -270,6 +321,7 @@ public class FragmentRule extends FragmentBase {
tvFolder.setText(null);
bottom_navigation.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
grpFlag.setVisibility(View.GONE);
grpMove.setVisibility(View.GONE);
grpAnswer.setVisibility(View.GONE);
grpAutomation.setVisibility(View.GONE);
@ -421,6 +473,10 @@ public class FragmentRule extends FragmentBase {
} else {
int type = jaction.getInt("type");
switch (type) {
case EntityRule.TYPE_FLAG:
setColor(jaction.isNull("color") ? null : jaction.getInt("color"));
break;
case EntityRule.TYPE_MOVE:
long target = jaction.getLong("target");
for (int pos = 0; pos < adapterTarget.getCount(); pos++)
@ -622,11 +678,24 @@ public class FragmentRule extends FragmentBase {
}
private void showActionParameters(int type) {
grpFlag.setVisibility(type == EntityRule.TYPE_FLAG ? View.VISIBLE : View.GONE);
grpMove.setVisibility(type == EntityRule.TYPE_MOVE ? View.VISIBLE : View.GONE);
grpAnswer.setVisibility(type == EntityRule.TYPE_ANSWER ? View.VISIBLE : View.GONE);
grpAutomation.setVisibility(type == EntityRule.TYPE_AUTOMATION ? View.VISIBLE : View.GONE);
}
private void setColor(Integer color) {
this.color = color;
if (color == null)
color = Color.TRANSPARENT;
GradientDrawable border = new GradientDrawable();
border.setColor(color);
border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator));
vwColor.setBackground(border);
}
private JSONObject getCondition() throws JSONException {
JSONObject jcondition = new JSONObject();
@ -672,6 +741,10 @@ public class FragmentRule extends FragmentBase {
if (action != null) {
jaction.put("type", action.type);
switch (action.type) {
case EntityRule.TYPE_FLAG:
jaction.put("color", color);
break;
case EntityRule.TYPE_MOVE:
EntityFolder target = (EntityFolder) spTarget.getSelectedItem();
jaction.put("target", target.id);

@ -369,14 +369,49 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvActionRemark" />
<Button
android:id="@+id/btnColor"
style="@style/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_account_color"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vSeparatorParameters" />
<View
android:id="@+id/vwColor"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:background="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="@id/btnColor"
app:layout_constraintStart_toEndOf="@id/btnColor"
app:layout_constraintTop_toTopOf="@id/btnColor" />
<ImageView
android:id="@+id/ibColorDefault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:contentDescription="@string/title_legend_default_color"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnColor"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toTopOf="@id/btnColor" />
<TextView
android:id="@+id/tvMoveTarget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_folder"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/vSeparatorParameters" />
app:layout_constraintTop_toBottomOf="@+id/btnColor" />
<Spinner
android:id="@+id/spTarget"
@ -390,6 +425,7 @@
android:id="@+id/tvAnswerIdentity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_identity"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
@ -434,6 +470,7 @@
android:id="@+id/tvAutomation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_rule_automation_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textIsSelectable="true"
@ -453,6 +490,13 @@
vSeparatorAction,tvAction,spAction,tvActionRemark,
vSeparatorParameters" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFlag"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
btnColor,vwColor,ibColorDefault" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpMove"
android:layout_width="0dp"

Loading…
Cancel
Save