Allow ignoring individual messages

This commit is contained in:
M66B 2018-10-16 11:29:12 +00:00
parent 3d5e4ca4a2
commit 1527208327
8 changed files with 1049 additions and 13 deletions

File diff suppressed because it is too large Load Diff

View File

@ -437,6 +437,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
draft.ui_flagged = false; draft.ui_flagged = false;
draft.ui_hide = false; draft.ui_hide = false;
draft.ui_found = false; draft.ui_found = false;
draft.ui_ignored = false;
draft.id = db.message().insertMessage(draft); draft.id = db.message().insertMessage(draft);
draft.write(context, body); draft.write(context, body);
} }

View File

@ -45,7 +45,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 20, version = 21,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -257,6 +257,14 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll_interval` INTEGER"); db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll_interval` INTEGER");
} }
}) })
.addMigrations(new Migration(20, 21) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i(Helper.TAG, "DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_ignored` INTEGER NOT NULL DEFAULT 0");
db.execSQL("CREATE INDEX `index_message_ui_ignored` ON `message` (`ui_ignored`)");
}
})
.build(); .build();
} }

View File

@ -159,7 +159,9 @@ public interface DaoMessage {
" JOIN folder ON folder.id = message.folder" + " JOIN folder ON folder.id = message.folder" +
" WHERE account.`synchronize`" + " WHERE account.`synchronize`" +
" AND folder.unified" + " AND folder.unified" +
" AND NOT message.ui_seen AND NOT message.ui_hide" + " AND NOT message.ui_seen" +
" AND NOT message.ui_hide" +
" AND NOT message.ui_ignored" +
" ORDER BY message.received") " ORDER BY message.received")
LiveData<List<EntityMessage>> liveUnseenUnified(); LiveData<List<EntityMessage>> liveUnseenUnified();
@ -194,6 +196,9 @@ public interface DaoMessage {
@Query("UPDATE message SET ui_hide = :ui_hide WHERE id = :id") @Query("UPDATE message SET ui_hide = :ui_hide WHERE id = :id")
int setMessageUiHide(long id, boolean ui_hide); int setMessageUiHide(long id, boolean ui_hide);
@Query("UPDATE message SET ui_ignored = :ui_ignored WHERE id = :id")
int setMessageUiIgnored(long id, boolean ui_ignored);
@Query("UPDATE message SET error = :error WHERE id = :id") @Query("UPDATE message SET error = :error WHERE id = :id")
int setMessageError(long id, String error); int setMessageError(long id, String error);

View File

@ -64,7 +64,8 @@ import static androidx.room.ForeignKey.CASCADE;
@Index(value = {"received"}), @Index(value = {"received"}),
@Index(value = {"ui_seen"}), @Index(value = {"ui_seen"}),
@Index(value = {"ui_hide"}), @Index(value = {"ui_hide"}),
@Index(value = {"ui_found"}) @Index(value = {"ui_found"}),
@Index(value = {"ui_ignored"})
} }
) )
public class EntityMessage implements Serializable { public class EntityMessage implements Serializable {
@ -111,6 +112,8 @@ public class EntityMessage implements Serializable {
public Boolean ui_hide; public Boolean ui_hide;
@NonNull @NonNull
public Boolean ui_found; public Boolean ui_found;
@NonNull
public Boolean ui_ignored;
public String error; public String error;
@Ignore @Ignore
@ -211,6 +214,7 @@ public class EntityMessage implements Serializable {
this.ui_flagged.equals(other.ui_flagged) && this.ui_flagged.equals(other.ui_flagged) &&
this.ui_hide.equals(other.ui_hide) && this.ui_hide.equals(other.ui_hide) &&
this.ui_found.equals(other.ui_found) && this.ui_found.equals(other.ui_found) &&
this.ui_ignored.equals(other.ui_ignored) &&
(this.error == null ? other.error == null : this.error.equals(other.error))); (this.error == null ? other.error == null : this.error.equals(other.error)));
} }
return false; return false;

View File

@ -152,6 +152,7 @@ public class FragmentAbout extends FragmentEx {
draft.ui_flagged = false; draft.ui_flagged = false;
draft.ui_hide = false; draft.ui_hide = false;
draft.ui_found = false; draft.ui_found = false;
draft.ui_ignored = false;
draft.id = db.message().insertMessage(draft); draft.id = db.message().insertMessage(draft);
draft.write(context, body); draft.write(context, body);

View File

@ -959,6 +959,7 @@ public class FragmentCompose extends FragmentEx {
draft.ui_flagged = false; draft.ui_flagged = false;
draft.ui_hide = false; draft.ui_hide = false;
draft.ui_found = false; draft.ui_found = false;
draft.ui_ignored = false;
draft.id = db.message().insertMessage(draft); draft.id = db.message().insertMessage(draft);
draft.write(context, body == null ? "" : body); draft.write(context, body == null ? "" : body);

View File

@ -137,6 +137,7 @@ public class ServiceSynchronize extends LifecycleService {
static final int PI_SEEN = 1; static final int PI_SEEN = 1;
static final int PI_TRASH = 2; static final int PI_TRASH = 2;
static final int PI_IGNORED = 3;
static final String ACTION_SYNCHRONIZE_FOLDER = BuildConfig.APPLICATION_ID + ".SYNCHRONIZE_FOLDER"; static final String ACTION_SYNCHRONIZE_FOLDER = BuildConfig.APPLICATION_ID + ".SYNCHRONIZE_FOLDER";
static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS"; static final String ACTION_PROCESS_OPERATIONS = BuildConfig.APPLICATION_ID + ".PROCESS_OPERATIONS";
@ -237,7 +238,7 @@ public class ServiceSynchronize extends LifecycleService {
serviceManager.queue_stop(); serviceManager.queue_stop();
else if ("reload".equals(action)) else if ("reload".equals(action))
serviceManager.queue_reload(); serviceManager.queue_reload();
else if (action.startsWith("seen:") || action.startsWith("trash:")) { else if (action.startsWith("seen:") || action.startsWith("trash:") || action.startsWith("ignored:")) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", Long.parseLong(action.split(":")[1])); args.putLong("id", Long.parseLong(action.split(":")[1]));
args.putString("action", action.split(":")[0]); args.putString("action", action.split(":")[0]);
@ -261,7 +262,8 @@ public class ServiceSynchronize extends LifecycleService {
EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH); EntityFolder trash = db.folder().getFolderByType(message.account, EntityFolder.TRASH);
if (trash != null) if (trash != null)
EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id); EntityOperation.queue(db, message, EntityOperation.MOVE, trash.id);
} } else if ("ignored".equals(action))
db.message().setMessageUiIgnored(message.id, true);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -272,11 +274,6 @@ public class ServiceSynchronize extends LifecycleService {
return null; return null;
} }
@Override
protected void onLoaded(Bundle args, Void data) {
Log.i(Helper.TAG, "Set seen");
}
}.load(this, args); }.load(this, args);
} }
} }
@ -391,9 +388,13 @@ public class ServiceSynchronize extends LifecycleService {
Intent thread = new Intent(this, ActivityView.class); Intent thread = new Intent(this, ActivityView.class);
thread.setAction("thread:" + message.id); thread.setAction("thread:" + message.id);
thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent piThread = PendingIntent.getActivity( PendingIntent piContent = PendingIntent.getActivity(
this, ActivityView.REQUEST_THREAD, thread, PendingIntent.FLAG_UPDATE_CURRENT); this, ActivityView.REQUEST_THREAD, thread, PendingIntent.FLAG_UPDATE_CURRENT);
Intent ignored = new Intent(this, ServiceSynchronize.class);
ignored.setAction("ignored:" + message.id);
PendingIntent piDelete = PendingIntent.getService(this, PI_IGNORED, ignored, PendingIntent.FLAG_UPDATE_CURRENT);
Intent seen = new Intent(this, ServiceSynchronize.class); Intent seen = new Intent(this, ServiceSynchronize.class);
seen.setAction("seen:" + message.id); seen.setAction("seen:" + message.id);
PendingIntent piSeen = PendingIntent.getService(this, PI_SEEN, seen, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent piSeen = PendingIntent.getService(this, PI_SEEN, seen, PendingIntent.FLAG_UPDATE_CURRENT);
@ -422,10 +423,10 @@ public class ServiceSynchronize extends LifecycleService {
.addExtras(args) .addExtras(args)
.setSmallIcon(R.drawable.baseline_mail_24) .setSmallIcon(R.drawable.baseline_mail_24)
.setContentTitle(MessageHelper.getFormattedAddresses(message.from, true)) .setContentTitle(MessageHelper.getFormattedAddresses(message.from, true))
.setContentIntent(piThread) .setContentIntent(piContent)
.setSound(uri) .setSound(uri)
.setWhen(message.sent == null ? message.received : message.sent) .setWhen(message.sent == null ? message.received : message.sent)
.setOngoing(true) .setDeleteIntent(piDelete)
.setPriority(Notification.PRIORITY_DEFAULT) .setPriority(Notification.PRIORITY_DEFAULT)
.setCategory(Notification.CATEGORY_STATUS) .setCategory(Notification.CATEGORY_STATUS)
.setVisibility(Notification.VISIBILITY_PRIVATE) .setVisibility(Notification.VISIBILITY_PRIVATE)
@ -1694,6 +1695,7 @@ public class ServiceSynchronize extends LifecycleService {
message.ui_flagged = false; message.ui_flagged = false;
message.ui_hide = false; message.ui_hide = false;
message.ui_found = found; message.ui_found = found;
message.ui_ignored = false;
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS) if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED) { == PackageManager.PERMISSION_GRANTED) {