mirror of https://github.com/M66B/FairEmail.git
Experiment: rule to set notifications local only
This commit is contained in:
parent
69d2b4f434
commit
3e37f11996
File diff suppressed because it is too large
Load Diff
|
@ -7629,6 +7629,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
log("ui_ignored changed", next.id);
|
||||
}
|
||||
// ui_silent
|
||||
// ui_local_only
|
||||
if (!prev.ui_browsed.equals(next.ui_browsed)) {
|
||||
same = false;
|
||||
log("ui_browsed changed", next.id);
|
||||
|
|
|
@ -528,6 +528,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
|||
return R.string.title_rule_delete;
|
||||
case EntityRule.TYPE_SOUND:
|
||||
return R.string.title_rule_sound;
|
||||
case EntityRule.TYPE_LOCAL_ONLY:
|
||||
return R.string.title_rule_local_only;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown action type=" + type);
|
||||
}
|
||||
|
|
|
@ -5688,6 +5688,10 @@ class Core {
|
|||
mbuilder.setSilent(true);
|
||||
Log.i("Notify silent=" + message.id);
|
||||
}
|
||||
if (message.ui_local_only) {
|
||||
mbuilder.setLocalOnly(true);
|
||||
Log.i("Notify local=" + message.id);
|
||||
}
|
||||
|
||||
if (notify_messaging) {
|
||||
// https://developer.android.com/training/cars/messaging
|
||||
|
|
|
@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 254,
|
||||
version = 255,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -2583,6 +2583,12 @@ public abstract class DB extends RoomDatabase {
|
|||
" WHERE (host = 'imap.mail.yahoo.com' OR host = 'imap.aol.com')" +
|
||||
" AND pop = " + EntityAccount.TYPE_IMAP);
|
||||
}
|
||||
}).addMigrations(new Migration(254, 255) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
logMigration(startVersion, endVersion);
|
||||
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_local_only` INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
}).addMigrations(new Migration(998, 999) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
|
|
|
@ -792,6 +792,9 @@ public interface DaoMessage {
|
|||
@Query("UPDATE message SET ui_silent = :ui_silent WHERE id = :id AND NOT (ui_silent IS :ui_silent)")
|
||||
int setMessageUiSilent(long id, boolean ui_silent);
|
||||
|
||||
@Query("UPDATE message SET ui_local_only = :ui_local_only WHERE id = :id AND NOT (ui_local_only IS :ui_local_only)")
|
||||
int setMessageUiLocalOnly(long id, boolean ui_local_only);
|
||||
|
||||
@Query("UPDATE message SET ui_busy = :busy WHERE id = :id AND NOT (ui_busy IS :busy)")
|
||||
int setMessageUiBusy(long id, Long busy);
|
||||
|
||||
|
|
|
@ -236,6 +236,8 @@ public class EntityMessage implements Serializable {
|
|||
@NonNull
|
||||
public Boolean ui_silent = false;
|
||||
@NonNull
|
||||
public Boolean ui_local_only = false;
|
||||
@NonNull
|
||||
public Boolean ui_browsed = false;
|
||||
public Long ui_busy;
|
||||
public Long ui_snoozed;
|
||||
|
@ -776,6 +778,7 @@ public class EntityMessage implements Serializable {
|
|||
this.ui_found.equals(other.ui_found) &&
|
||||
this.ui_ignored.equals(other.ui_ignored) &&
|
||||
this.ui_silent.equals(other.ui_silent) &&
|
||||
this.ui_local_only.equals(other.ui_local_only) &&
|
||||
this.ui_browsed.equals(other.ui_browsed) &&
|
||||
Objects.equals(this.ui_busy, other.ui_busy) &&
|
||||
Objects.equals(this.ui_snoozed, other.ui_snoozed) &&
|
||||
|
|
|
@ -119,6 +119,7 @@ public class EntityRule {
|
|||
static final int TYPE_TTS = 14;
|
||||
static final int TYPE_DELETE = 15;
|
||||
static final int TYPE_SOUND = 16;
|
||||
static final int TYPE_LOCAL_ONLY = 17;
|
||||
|
||||
static final String ACTION_AUTOMATION = BuildConfig.APPLICATION_ID + ".AUTOMATION";
|
||||
static final String EXTRA_RULE = "rule";
|
||||
|
@ -510,6 +511,8 @@ public class EntityRule {
|
|||
return onActionDelete(context, message, jaction);
|
||||
case TYPE_SOUND:
|
||||
return onActionSound(context, message, jaction);
|
||||
case TYPE_LOCAL_ONLY:
|
||||
return onActionLocalOnly(context, message, jaction);
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown rule type=" + type + " name=" + name);
|
||||
}
|
||||
|
@ -589,6 +592,8 @@ public class EntityRule {
|
|||
if (TextUtils.isEmpty(uri))
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_rule_select_sound));
|
||||
return;
|
||||
case TYPE_LOCAL_ONLY:
|
||||
return;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown rule type=" + type);
|
||||
}
|
||||
|
@ -1127,6 +1132,18 @@ public class EntityRule {
|
|||
return true;
|
||||
}
|
||||
|
||||
private boolean onActionLocalOnly(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
|
||||
if (message.ui_seen)
|
||||
return false;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
message.ui_local_only = true;
|
||||
db.message().setMessageUiLocalOnly(message.id, message.ui_local_only);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Calendar getRelativeCalendar(int minutes, long reference) {
|
||||
int d = minutes / (24 * 60);
|
||||
int h = minutes / 60 % 24;
|
||||
|
|
|
@ -176,6 +176,7 @@ public class FragmentRule extends FragmentBase {
|
|||
private Group grpSound;
|
||||
private Group grpAutomation;
|
||||
private Group grpDelete;
|
||||
private Group grpLocalOnly;
|
||||
|
||||
private ArrayAdapter<String> adapterDay;
|
||||
private ArrayAdapter<Action> adapterAction;
|
||||
|
@ -332,6 +333,7 @@ public class FragmentRule extends FragmentBase {
|
|||
grpSound = view.findViewById(R.id.grpSound);
|
||||
grpAutomation = view.findViewById(R.id.grpAutomation);
|
||||
grpDelete = view.findViewById(R.id.grpDelete);
|
||||
grpLocalOnly = view.findViewById(R.id.grpLocalOnly);
|
||||
|
||||
ibSender.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -541,6 +543,8 @@ public class FragmentRule extends FragmentBase {
|
|||
actions.add(new Action(EntityRule.TYPE_UNSEEN, getString(R.string.title_rule_unseen)));
|
||||
actions.add(new Action(EntityRule.TYPE_HIDE, getString(R.string.title_rule_hide)));
|
||||
actions.add(new Action(EntityRule.TYPE_IGNORE, getString(R.string.title_rule_ignore)));
|
||||
if (BuildConfig.DEBUG)
|
||||
actions.add(new Action(EntityRule.TYPE_LOCAL_ONLY, getString(R.string.title_rule_local_only)));
|
||||
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)));
|
||||
|
@ -737,6 +741,7 @@ public class FragmentRule extends FragmentBase {
|
|||
grpSound.setVisibility(View.GONE);
|
||||
grpAutomation.setVisibility(View.GONE);
|
||||
grpDelete.setVisibility(View.GONE);
|
||||
grpLocalOnly.setVisibility(View.GONE);
|
||||
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
||||
|
@ -1267,6 +1272,7 @@ public class FragmentRule extends FragmentBase {
|
|||
grpSound.setVisibility(type == EntityRule.TYPE_SOUND ? View.VISIBLE : View.GONE);
|
||||
grpAutomation.setVisibility(type == EntityRule.TYPE_AUTOMATION ? View.VISIBLE : View.GONE);
|
||||
grpDelete.setVisibility(type == EntityRule.TYPE_DELETE ? View.VISIBLE : View.GONE);
|
||||
grpLocalOnly.setVisibility(type == EntityRule.TYPE_LOCAL_ONLY ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void onActionDelete() {
|
||||
|
|
|
@ -1213,6 +1213,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
" ui_hide=" + message.ui_hide +
|
||||
" notifying=" + message.notifying +
|
||||
" silent=" + message.ui_silent +
|
||||
" local=" + message.ui_local_only +
|
||||
" received=" + new Date(message.received) +
|
||||
" sent=" + (message.sent == null ? null : new Date(message.sent)) +
|
||||
" created=" + (account.created == null ? null : new Date(account.created)) +
|
||||
|
@ -1228,6 +1229,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
message.id = null;
|
||||
message.fts = false;
|
||||
message.ui_silent = false;
|
||||
message.ui_local_only = false;
|
||||
message.notifying = 0;
|
||||
message.stored = new Date().getTime();
|
||||
message.id = db.message().insertMessage(message);
|
||||
|
|
|
@ -1077,6 +1077,17 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvAutomation" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLocalOnly"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_rule_local_only_hint"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textStyle="italic"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvDelete" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpReady"
|
||||
android:layout_width="0dp"
|
||||
|
@ -1160,6 +1171,12 @@
|
|||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvDelete" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpLocalOnly"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvLocalOnly" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ScrollViewEx>
|
||||
|
||||
|
|
|
@ -1712,6 +1712,7 @@
|
|||
<string name="title_rule_unseen">Mark unread</string>
|
||||
<string name="title_rule_hide">Hide</string>
|
||||
<string name="title_rule_ignore">Suppress notification</string>
|
||||
<string name="title_rule_local_only" translatable="false">Local notification only</string>
|
||||
<string name="title_rule_snooze">Snooze</string>
|
||||
<string name="title_rule_flag">Add star</string>
|
||||
<string name="title_rule_importance">Set importance</string>
|
||||
|
@ -1771,6 +1772,7 @@
|
|||
<string name="title_rule_keyword_missing">Keyword missing</string>
|
||||
<string name="title_rule_automation_hint">This will send the intent \'%1$s\' with the extras \'%2$s\'</string>
|
||||
<string name="title_rule_delete_hint">Permanent deletion is irreversible, so make sure the rule conditions are correct!</string>
|
||||
<string name="title_rule_local_only_hint" translatable="false">Try to avoid bridging notifications to other devices, such as smartwatches. Not all devices support this.</string>
|
||||
|
||||
<string name="title_rule_execute">Execute now</string>
|
||||
<string name="title_rule_applied">Affected messages: %1$d</string>
|
||||
|
|
Loading…
Reference in New Issue