1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-30 11:45:36 +00:00

Show rule target folder name

This commit is contained in:
M66B 2022-03-22 11:19:31 +01:00
parent 729994a984
commit 22778ca685
2 changed files with 83 additions and 52 deletions

View file

@ -164,57 +164,50 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
try { try {
JSONObject jaction = new JSONObject(rule.action); JSONObject jaction = new JSONObject(rule.action);
int type = jaction.getInt("type"); int type = jaction.getInt("type");
switch (type) { tvAction.setText(getActionTitle(type));
case EntityRule.TYPE_NOOP:
tvAction.setText(R.string.title_rule_noop); if (type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY) {
break; Bundle args = new Bundle();
case EntityRule.TYPE_SEEN: args.putLong("id", rule.id);
tvAction.setText(R.string.title_rule_seen); args.putInt("type", type);
break; args.putLong("target", jaction.optLong("target", -1));
case EntityRule.TYPE_UNSEEN:
tvAction.setText(R.string.title_rule_unseen); new SimpleTask<EntityFolder>() {
break; @Override
case EntityRule.TYPE_HIDE: protected EntityFolder onExecute(Context context, Bundle args) throws Throwable {
tvAction.setText(R.string.title_rule_hide); long target = args.getLong("target");
break;
case EntityRule.TYPE_IGNORE: DB db = DB.getInstance(context);
tvAction.setText(R.string.title_rule_ignore); return db.folder().getFolder(target);
break; }
case EntityRule.TYPE_SNOOZE:
tvAction.setText(R.string.title_rule_snooze); @Override
break; protected void onExecuted(Bundle args, EntityFolder folder) {
case EntityRule.TYPE_FLAG: int pos = getAdapterPosition();
tvAction.setText(R.string.title_rule_flag); if (pos == RecyclerView.NO_POSITION)
break; return;
case EntityRule.TYPE_IMPORTANCE:
tvAction.setText(R.string.title_rule_importance); long id = args.getLong("id");
break; if (id != AdapterRule.this.getItemId(pos))
case EntityRule.TYPE_KEYWORD: return;
tvAction.setText(R.string.title_rule_keyword);
break; int type = args.getInt("type");
case EntityRule.TYPE_MOVE: SpannableStringBuilder ssb = new SpannableStringBuilderEx();
tvAction.setText(R.string.title_rule_move); ssb.append(context.getString(getActionTitle(type)));
break; ssb.append(" \"");
case EntityRule.TYPE_COPY: int start = ssb.length();
tvAction.setText(R.string.title_rule_copy); ssb.append(folder == null ? "???" : folder.name);
break; ssb.setSpan(new StyleSpan(Typeface.ITALIC), start, ssb.length(), 0);
case EntityRule.TYPE_ANSWER: ssb.append("\"");
tvAction.setText(R.string.title_rule_answer);
break; tvAction.setText(ssb);
case EntityRule.TYPE_TTS: }
tvAction.setText(R.string.title_rule_tts);
break; @Override
case EntityRule.TYPE_AUTOMATION: protected void onException(Bundle args, Throwable ex) {
tvAction.setText(R.string.title_rule_automation); // Ignored
break; }
case EntityRule.TYPE_DELETE: }.execute(context, owner, args, "rule:folder");
tvAction.setText(R.string.title_rule_delete);
break;
case EntityRule.TYPE_SOUND:
tvAction.setText(R.string.title_rule_sound);
break;
default:
throw new IllegalArgumentException("Unknown action type=" + type);
} }
} catch (Throwable ex) { } catch (Throwable ex) {
tvAction.setText(ex.getMessage()); tvAction.setText(ex.getMessage());
@ -431,6 +424,45 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
return true; return true;
} }
private int getActionTitle(int type) {
switch (type) {
case EntityRule.TYPE_NOOP:
return R.string.title_rule_noop;
case EntityRule.TYPE_SEEN:
return R.string.title_rule_seen;
case EntityRule.TYPE_UNSEEN:
return R.string.title_rule_unseen;
case EntityRule.TYPE_HIDE:
return R.string.title_rule_hide;
case EntityRule.TYPE_IGNORE:
return R.string.title_rule_ignore;
case EntityRule.TYPE_SNOOZE:
return R.string.title_rule_snooze;
case EntityRule.TYPE_FLAG:
return R.string.title_rule_flag;
case EntityRule.TYPE_IMPORTANCE:
return R.string.title_rule_importance;
case EntityRule.TYPE_KEYWORD:
return R.string.title_rule_keyword;
case EntityRule.TYPE_MOVE:
return R.string.title_rule_move;
case EntityRule.TYPE_COPY:
return R.string.title_rule_copy;
case EntityRule.TYPE_ANSWER:
return R.string.title_rule_answer;
case EntityRule.TYPE_TTS:
return R.string.title_rule_tts;
case EntityRule.TYPE_AUTOMATION:
return R.string.title_rule_automation;
case EntityRule.TYPE_DELETE:
return R.string.title_rule_delete;
case EntityRule.TYPE_SOUND:
return R.string.title_rule_sound;
default:
throw new IllegalArgumentException("Unknown action type=" + type);
}
}
} }
AdapterRule(Fragment parentFragment) { AdapterRule(Fragment parentFragment) {

View file

@ -67,7 +67,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Action" android:text="Action"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCondition" /> app:layout_constraintTop_toBottomOf="@id/tvCondition" />