mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 00:23:09 +02:00
Show last applied for rules
This commit is contained in:
@@ -54,6 +54,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -67,6 +68,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
private LifecycleOwner owner;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
private DateFormat DF;
|
||||
private NumberFormat NF = NumberFormat.getNumberInstance();
|
||||
|
||||
private int protocol = -1;
|
||||
private String search = null;
|
||||
private List<TupleRuleEx> all = new ArrayList<>();
|
||||
@@ -79,9 +83,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
private ImageView ivStop;
|
||||
private TextView tvCondition;
|
||||
private TextView tvAction;
|
||||
private TextView tvLastApplied;
|
||||
private TextView tvApplied;
|
||||
|
||||
private NumberFormat NF = NumberFormat.getNumberInstance();
|
||||
private TwoStateOwner powner = new TwoStateOwner(owner, "RulePopup");
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
@@ -93,6 +97,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
ivStop = itemView.findViewById(R.id.ivStop);
|
||||
tvCondition = itemView.findViewById(R.id.tvCondition);
|
||||
tvAction = itemView.findViewById(R.id.tvAction);
|
||||
tvLastApplied = itemView.findViewById(R.id.tvLastApplied);
|
||||
tvApplied = itemView.findViewById(R.id.tvApplied);
|
||||
}
|
||||
|
||||
@@ -183,6 +188,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
tvAction.setText(ex.getMessage());
|
||||
}
|
||||
|
||||
tvLastApplied.setText(rule.last_applied == null ? null : DF.format(rule.last_applied));
|
||||
tvApplied.setText(NF.format(rule.applied));
|
||||
}
|
||||
|
||||
@@ -405,6 +411,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
this.owner = parentFragment.getViewLifecycleOwner();
|
||||
this.inflater = LayoutInflater.from(context);
|
||||
|
||||
this.DF = Helper.getDateTimeInstance(this.context);
|
||||
|
||||
setHasStableIds(true);
|
||||
|
||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
|
||||
@@ -64,7 +64,7 @@ import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 180,
|
||||
version = 181,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
@@ -1774,6 +1774,13 @@ public abstract class DB extends RoomDatabase {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `reply_domain` INTEGER");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(180, 181) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `rule` ADD COLUMN `last_applied` INTEGER");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -59,16 +59,24 @@ public interface DaoRule {
|
||||
@Update
|
||||
int updateRule(EntityRule rule);
|
||||
|
||||
@Query("UPDATE rule SET folder = :folder WHERE id = :id AND NOT (folder IS :folder)")
|
||||
@Query("UPDATE rule" +
|
||||
" SET folder = :folder" +
|
||||
" WHERE id = :id AND NOT (folder IS :folder)")
|
||||
int setRuleFolder(long id, long folder);
|
||||
|
||||
@Query("UPDATE rule SET enabled = :enabled WHERE id = :id AND NOT (enabled IS :enabled)")
|
||||
@Query("UPDATE rule" +
|
||||
" SET enabled = :enabled" +
|
||||
" WHERE id = :id AND NOT (enabled IS :enabled)")
|
||||
int setRuleEnabled(long id, boolean enabled);
|
||||
|
||||
@Query("UPDATE rule SET applied = applied + 1 WHERE id = :id")
|
||||
int applyRule(long id);
|
||||
@Query("UPDATE rule" +
|
||||
" SET applied = applied + 1, last_applied = :time" +
|
||||
" WHERE id = :id")
|
||||
int applyRule(long id, long time);
|
||||
|
||||
@Query("UPDATE rule SET applied = 0 WHERE id = :id AND NOT (applied IS 0)")
|
||||
@Query("UPDATE rule" +
|
||||
" SET applied = 0, last_applied = NULL" +
|
||||
" WHERE id = :id AND NOT (applied IS 0)")
|
||||
int resetRule(long id);
|
||||
|
||||
@Query("DELETE FROM rule WHERE id = :id")
|
||||
|
||||
@@ -52,6 +52,7 @@ import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -95,6 +96,7 @@ public class EntityRule {
|
||||
public String action;
|
||||
@NonNull
|
||||
public Integer applied = 0;
|
||||
public Long last_applied;
|
||||
|
||||
static final int TYPE_SEEN = 1;
|
||||
static final int TYPE_UNSEEN = 2;
|
||||
@@ -304,7 +306,7 @@ public class EntityRule {
|
||||
boolean executed = _execute(context, message);
|
||||
if (id != null && executed) {
|
||||
DB db = DB.getInstance(context);
|
||||
db.rule().applyRule(id);
|
||||
db.rule().applyRule(id, new Date().getTime());
|
||||
}
|
||||
return executed;
|
||||
}
|
||||
@@ -892,7 +894,8 @@ public class EntityRule {
|
||||
this.stop == other.stop &&
|
||||
this.condition.equals(other.condition) &&
|
||||
this.action.equals(other.action) &&
|
||||
this.applied.equals(other.applied);
|
||||
this.applied.equals(other.applied) &&
|
||||
Objects.equals(this.last_applied, other.last_applied);
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
@@ -907,6 +910,7 @@ public class EntityRule {
|
||||
json.put("condition", condition);
|
||||
json.put("action", action);
|
||||
json.put("applied", applied);
|
||||
json.put("last_applied", last_applied);
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -920,6 +924,8 @@ public class EntityRule {
|
||||
rule.condition = json.getString("condition");
|
||||
rule.action = json.getString("action");
|
||||
rule.applied = json.optInt("applied", 0);
|
||||
if (json.has("last_applied") && !json.isNull("last_applied"))
|
||||
rule.last_applied = json.getLong("last_applied");
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,8 +778,10 @@ public class FragmentRule extends FragmentBase {
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, TupleRuleEx rule) {
|
||||
if (copy > 0 && rule != null)
|
||||
if (copy > 0 && rule != null) {
|
||||
rule.applied = 0;
|
||||
rule.last_applied = null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (savedInstanceState == null) {
|
||||
|
||||
@@ -440,6 +440,7 @@ public class FragmentRules extends FragmentBase {
|
||||
|
||||
rule.folder = fid;
|
||||
rule.applied = 0;
|
||||
rule.last_applied = null;
|
||||
rule.id = db.rule().insertRule(rule);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user