mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-06 12:54:11 +01:00
Added message importance/rule
This commit is contained in:
2121
app/schemas/eu.faircode.email.DB/138.json
Normal file
2121
app/schemas/eu.faircode.email.DB/138.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -878,9 +878,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
ibAvatar.setVisibility(avatars ? View.INVISIBLE : View.GONE);
|
||||
|
||||
// Line 1
|
||||
Integer priority = (message.importance == null ? message.priority : message.importance);
|
||||
ibAuth.setVisibility(authentication && !authenticated ? View.VISIBLE : View.GONE);
|
||||
ivPriorityHigh.setVisibility(EntityMessage.PRIORITIY_HIGH.equals(message.priority) ? View.VISIBLE : View.GONE);
|
||||
ivPriorityLow.setVisibility(EntityMessage.PRIORITIY_LOW.equals(message.priority) ? View.VISIBLE : View.GONE);
|
||||
ivPriorityHigh.setVisibility(EntityMessage.PRIORITIY_HIGH.equals(priority) ? View.VISIBLE : View.GONE);
|
||||
ivPriorityLow.setVisibility(EntityMessage.PRIORITIY_LOW.equals(priority) ? View.VISIBLE : View.GONE);
|
||||
ivSigned.setVisibility(message.signed > 0 ? View.VISIBLE : View.GONE);
|
||||
ivEncrypted.setVisibility(message.encrypted > 0 ? View.VISIBLE : View.GONE);
|
||||
tvFrom.setText(MessageHelper.formatAddresses(addresses, name_email, false));
|
||||
@@ -4287,6 +4288,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
same = false;
|
||||
Log.i("priority changed id=" + next.id);
|
||||
}
|
||||
if (!Objects.equals(prev.importance, next.importance)) {
|
||||
same = false;
|
||||
Log.i("importance changed id=" + next.id);
|
||||
}
|
||||
if (!Objects.equals(prev.receipt_request, next.receipt_request)) {
|
||||
same = false;
|
||||
Log.i("receipt_request changed id=" + next.id);
|
||||
|
||||
@@ -150,6 +150,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||
case EntityRule.TYPE_FLAG:
|
||||
tvAction.setText(R.string.title_rule_flag);
|
||||
break;
|
||||
case EntityRule.TYPE_IMPORTANCE:
|
||||
tvAction.setText(R.string.title_rule_importance);
|
||||
break;
|
||||
case EntityRule.TYPE_KEYWORD:
|
||||
tvAction.setText(R.string.title_rule_keyword);
|
||||
break;
|
||||
|
||||
@@ -60,7 +60,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 137,
|
||||
version = 138,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
@@ -1335,6 +1335,13 @@ public abstract class DB extends RoomDatabase {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `submitter` TEXT");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(137, 138) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `importance` INTEGER");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -76,17 +76,19 @@ public interface DaoMessage {
|
||||
" AND (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0)" +
|
||||
" AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0)" +
|
||||
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_drafts + ")" +
|
||||
" ORDER BY CASE" +
|
||||
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
|
||||
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +
|
||||
" WHEN 'priority' = :sort THEN -MAX(IFNULL(message.priority, 1))" +
|
||||
" WHEN 'sender' = :sort THEN LOWER(message.sender)" +
|
||||
" WHEN 'subject' = :sort THEN LOWER(message.subject)" +
|
||||
" WHEN 'size' = :sort THEN -SUM(message.total)" +
|
||||
" WHEN 'attachments' = :sort THEN -SUM(message.attachments)" +
|
||||
" WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
|
||||
" ELSE 0" +
|
||||
" END, CASE WHEN :ascending THEN message.received ELSE -message.received END")
|
||||
" ORDER BY -IFNULL(MAX(message.importance), 1)" +
|
||||
", CASE" +
|
||||
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
|
||||
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +
|
||||
" WHEN 'priority' = :sort THEN -MAX(IFNULL(message.priority, 1))" +
|
||||
" WHEN 'sender' = :sort THEN LOWER(message.sender)" +
|
||||
" WHEN 'subject' = :sort THEN LOWER(message.subject)" +
|
||||
" WHEN 'size' = :sort THEN -SUM(message.total)" +
|
||||
" WHEN 'attachments' = :sort THEN -SUM(message.attachments)" +
|
||||
" WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
|
||||
" ELSE 0" +
|
||||
" END" +
|
||||
", CASE WHEN :ascending THEN message.received ELSE -message.received END")
|
||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
|
||||
DataSource.Factory<Integer, TupleMessageEx> pagedUnified(
|
||||
String type,
|
||||
@@ -125,17 +127,19 @@ public interface DaoMessage {
|
||||
" AND (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" +
|
||||
" AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" +
|
||||
" AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_outbox + " OR " + is_drafts + ")" +
|
||||
" ORDER BY CASE" +
|
||||
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
|
||||
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +
|
||||
" WHEN 'priority' = :sort THEN -MAX(IFNULL(message.priority, 1))" +
|
||||
" WHEN 'sender' = :sort THEN LOWER(message.sender)" +
|
||||
" WHEN 'subject' = :sort THEN LOWER(message.subject)" +
|
||||
" WHEN 'size' = :sort THEN -SUM(message.total)" +
|
||||
" WHEN 'attachments' = :sort THEN -SUM(message.attachments)" +
|
||||
" WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
|
||||
" ELSE 0" +
|
||||
" END, CASE WHEN :ascending THEN message.received ELSE -message.received END")
|
||||
" ORDER BY -IFNULL(MAX(message.importance), 1)" +
|
||||
", CASE" +
|
||||
" WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
|
||||
" WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +
|
||||
" WHEN 'priority' = :sort THEN -MAX(IFNULL(message.priority, 1))" +
|
||||
" WHEN 'sender' = :sort THEN LOWER(message.sender)" +
|
||||
" WHEN 'subject' = :sort THEN LOWER(message.subject)" +
|
||||
" WHEN 'size' = :sort THEN -SUM(message.total)" +
|
||||
" WHEN 'attachments' = :sort THEN -SUM(message.attachments)" +
|
||||
" WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
|
||||
" ELSE 0" +
|
||||
" END" +
|
||||
", CASE WHEN :ascending THEN message.received ELSE -message.received END")
|
||||
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
|
||||
DataSource.Factory<Integer, TupleMessageEx> pagedFolder(
|
||||
long folder, boolean threading,
|
||||
@@ -456,6 +460,9 @@ public interface DaoMessage {
|
||||
@Query("UPDATE message SET priority = :priority WHERE id = :id")
|
||||
int setMessagePriority(long id, Integer priority);
|
||||
|
||||
@Query("UPDATE message SET importance = :importance WHERE id = :id")
|
||||
int setMessageImportance(long id, Integer importance);
|
||||
|
||||
@Query("UPDATE message SET receipt_request = :receipt_request WHERE id = :id")
|
||||
int setMessageReceiptRequest(long id, Boolean receipt_request);
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ public class EntityMessage implements Serializable {
|
||||
public String inreplyto;
|
||||
public String thread; // compose = null
|
||||
public Integer priority;
|
||||
public Integer importance;
|
||||
public Boolean receipt; // is receipt
|
||||
public Boolean receipt_request;
|
||||
public Address[] receipt_to;
|
||||
|
||||
@@ -100,6 +100,7 @@ public class EntityRule {
|
||||
static final int TYPE_NOOP = 10;
|
||||
static final int TYPE_KEYWORD = 11;
|
||||
static final int TYPE_HIDE = 12;
|
||||
static final int TYPE_IMPORTANCE = 13;
|
||||
|
||||
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
|
||||
static final String EXTRA_RULE = "rule";
|
||||
@@ -306,6 +307,8 @@ public class EntityRule {
|
||||
return onActionSnooze(context, message, jaction);
|
||||
case TYPE_FLAG:
|
||||
return onActionFlag(context, message, jaction);
|
||||
case TYPE_IMPORTANCE:
|
||||
return onActionImportance(context, message, jaction);
|
||||
case TYPE_KEYWORD:
|
||||
return onActionKeyword(context, message, jaction);
|
||||
case TYPE_MOVE:
|
||||
@@ -495,6 +498,19 @@ public class EntityRule {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onActionImportance(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
|
||||
Integer importance = jargs.getInt("value");
|
||||
if (importance == EntityMessage.PRIORITIY_NORMAL)
|
||||
importance = null;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.message().setMessageImportance(message.id, importance);
|
||||
|
||||
message.importance = importance;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean onActionKeyword(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
|
||||
String keyword = jargs.getString("keyword");
|
||||
if (TextUtils.isEmpty(keyword)) {
|
||||
|
||||
@@ -116,6 +116,8 @@ public class FragmentRule extends FragmentBase {
|
||||
|
||||
private ViewButtonColor btnColor;
|
||||
|
||||
private Spinner spImportance;
|
||||
|
||||
private EditText etKeyword;
|
||||
|
||||
private Spinner spTarget;
|
||||
@@ -135,6 +137,7 @@ public class FragmentRule extends FragmentBase {
|
||||
private Group grpReady;
|
||||
private Group grpSnooze;
|
||||
private Group grpFlag;
|
||||
private Group grpImportance;
|
||||
private Group grpKeyword;
|
||||
private Group grpMove;
|
||||
private Group grpMoveProp;
|
||||
@@ -223,6 +226,8 @@ public class FragmentRule extends FragmentBase {
|
||||
|
||||
btnColor = view.findViewById(R.id.btnColor);
|
||||
|
||||
spImportance = view.findViewById(R.id.spImportance);
|
||||
|
||||
etKeyword = view.findViewById(R.id.etKeyword);
|
||||
|
||||
spTarget = view.findViewById(R.id.spTarget);
|
||||
@@ -243,6 +248,7 @@ public class FragmentRule extends FragmentBase {
|
||||
grpReady = view.findViewById(R.id.grpReady);
|
||||
grpSnooze = view.findViewById(R.id.grpSnooze);
|
||||
grpFlag = view.findViewById(R.id.grpFlag);
|
||||
grpImportance = view.findViewById(R.id.grpImportance);
|
||||
grpKeyword = view.findViewById(R.id.grpKeyword);
|
||||
grpMove = view.findViewById(R.id.grpMove);
|
||||
grpMoveProp = view.findViewById(R.id.grpMoveProp);
|
||||
@@ -339,6 +345,7 @@ public class FragmentRule extends FragmentBase {
|
||||
actions.add(new Action(EntityRule.TYPE_IGNORE, getString(R.string.title_rule_ignore)));
|
||||
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_IMPORTANCE, getString(R.string.title_rule_importance)));
|
||||
actions.add(new Action(EntityRule.TYPE_KEYWORD, getString(R.string.title_rule_keyword)));
|
||||
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)));
|
||||
@@ -426,6 +433,7 @@ public class FragmentRule extends FragmentBase {
|
||||
grpReady.setVisibility(View.GONE);
|
||||
grpSnooze.setVisibility(View.GONE);
|
||||
grpFlag.setVisibility(View.GONE);
|
||||
grpImportance.setVisibility(View.GONE);
|
||||
grpKeyword.setVisibility(View.GONE);
|
||||
grpMove.setVisibility(View.GONE);
|
||||
grpMoveProp.setVisibility(View.GONE);
|
||||
@@ -693,6 +701,10 @@ public class FragmentRule extends FragmentBase {
|
||||
? null : jaction.getInt("color"));
|
||||
break;
|
||||
|
||||
case EntityRule.TYPE_IMPORTANCE:
|
||||
spImportance.setSelection(jaction.optInt("value"));
|
||||
break;
|
||||
|
||||
case EntityRule.TYPE_KEYWORD:
|
||||
etKeyword.setText(jaction.getString("keyword"));
|
||||
break;
|
||||
@@ -759,6 +771,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);
|
||||
grpImportance.setVisibility(type == EntityRule.TYPE_IMPORTANCE ? View.VISIBLE : View.GONE);
|
||||
grpKeyword.setVisibility(type == EntityRule.TYPE_KEYWORD ? View.VISIBLE : View.GONE);
|
||||
grpMove.setVisibility(type == EntityRule.TYPE_MOVE || type == EntityRule.TYPE_COPY ? View.VISIBLE : View.GONE);
|
||||
grpMoveProp.setVisibility(type == EntityRule.TYPE_MOVE ? View.VISIBLE : View.GONE);
|
||||
@@ -987,6 +1000,10 @@ public class FragmentRule extends FragmentBase {
|
||||
jaction.put("color", color);
|
||||
break;
|
||||
|
||||
case EntityRule.TYPE_IMPORTANCE:
|
||||
jaction.put("value", spImportance.getSelectedItemPosition());
|
||||
break;
|
||||
|
||||
case EntityRule.TYPE_KEYWORD:
|
||||
jaction.put("keyword", MessageHelper.sanitizeKeyword(etKeyword.getText().toString()));
|
||||
break;
|
||||
|
||||
@@ -547,6 +547,16 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvColor" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spImportance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:entries="@array/priorityNames"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnColor" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvKeyword"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -555,7 +565,7 @@
|
||||
android:text="@string/title_rule_keyword"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnColor" />
|
||||
app:layout_constraintTop_toBottomOf="@id/spImportance" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etKeyword"
|
||||
@@ -685,6 +695,12 @@
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvColor,btnColor" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpImportance"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="spImportance" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpKeyword"
|
||||
android:layout_width="0dp"
|
||||
|
||||
@@ -855,6 +855,7 @@
|
||||
<string name="title_rule_ignore">Suppress notification</string>
|
||||
<string name="title_rule_snooze">Snooze</string>
|
||||
<string name="title_rule_flag">Add star</string>
|
||||
<string name="title_rule_importance">Set importance</string>
|
||||
<string name="title_rule_keyword">Add keyword</string>
|
||||
<string name="title_rule_move">Move</string>
|
||||
<string name="title_rule_copy">Copy (label)</string>
|
||||
|
||||
Reference in New Issue
Block a user