Simplify leave deleted

pull/203/head
M66B 3 years ago
parent 982eeb7043
commit ceacbf13fc

File diff suppressed because it is too large Load Diff

@ -4351,24 +4351,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onActionDelete(TupleMessageEx message) { private void onActionDelete(TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("account", message.account == null ? -1 : message.account);
new SimpleTask<EntityAccount>() {
@Override
protected EntityAccount onExecute(Context context, Bundle args) throws Throwable {
long aid = args.getLong("account");
DB db = DB.getInstance(context);
return db.account().getAccount(aid);
}
@Override
protected void onExecuted(Bundle args, EntityAccount account) {
boolean leave_deleted = (account != null &&
account.protocol == EntityAccount.TYPE_POP &&
account.leave_deleted);
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putString("question", context.getString(R.string.title_ask_delete)); aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark()); aargs.putString("remark", message.getRemark());
@ -4380,7 +4362,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean delete_asked = prefs.getBoolean("delete_asked", false); boolean delete_asked = prefs.getBoolean("delete_asked", false);
if (delete_asked || leave_deleted) { if (delete_asked ||
(message.accountProtocol == EntityAccount.TYPE_POP &&
message.accountLeaveDeleted)) {
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("args", aargs); data.putExtra("args", aargs);
parentFragment.onActivityResult(FragmentMessages.REQUEST_MESSAGE_DELETE, RESULT_OK, data); parentFragment.onActivityResult(FragmentMessages.REQUEST_MESSAGE_DELETE, RESULT_OK, data);
@ -4393,13 +4377,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ask.show(parentFragment.getParentFragmentManager(), "message:delete"); ask.show(parentFragment.getParentFragmentManager(), "message:delete");
} }
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "message:delete");
}
private void onActionJunk(TupleMessageEx message) { private void onActionJunk(TupleMessageEx message) {
boolean canBlock = false; boolean canBlock = false;
if (message.from != null && message.from.length > 0) { if (message.from != null && message.from.length > 0) {

@ -66,7 +66,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 206, version = 207,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2091,6 +2091,13 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion); Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `capabilities` TEXT"); db.execSQL("ALTER TABLE `account` ADD COLUMN `capabilities` TEXT");
} }
}).addMigrations(new Migration(206, 207) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("DROP VIEW `account_view`");
db.execSQL("CREATE VIEW IF NOT EXISTS `account_view` AS " + TupleAccountView.query);
}
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -47,7 +47,7 @@ public interface DaoMessage {
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.leave_deleted AS accountLeaveDeleted, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
@ -125,7 +125,7 @@ public interface DaoMessage {
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.leave_deleted AS accountLeaveDeleted, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", '[' || group_concat(message.`from`, ',') || ']' AS senders" + ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
@ -194,7 +194,7 @@ public interface DaoMessage {
@Transaction @Transaction
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.leave_deleted AS accountLeaveDeleted, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
@ -435,7 +435,7 @@ public interface DaoMessage {
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, identity.color AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, identity.color AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.leave_deleted AS accountLeaveDeleted, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +
@ -467,7 +467,7 @@ public interface DaoMessage {
@Transaction @Transaction
@Query("SELECT message.*" + @Query("SELECT message.*" +
", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" + ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" + ", account.notify AS accountNotify, account.leave_deleted AS accountLeaveDeleted, account.auto_seen AS accountAutoSeen" +
", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" + ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" + ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.color AS identityColor, identity.synchronize AS identitySynchronize" +
", message.`from` AS senders" + ", message.`from` AS senders" +

@ -2436,24 +2436,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onSwipeDelete(@NonNull TupleMessageEx message) { private void onSwipeDelete(@NonNull TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("account", message.account == null ? -1 : message.account);
new SimpleTask<EntityAccount>() {
@Override
protected EntityAccount onExecute(Context context, Bundle args) throws Throwable {
long aid = args.getLong("account");
DB db = DB.getInstance(context);
return db.account().getAccount(aid);
}
@Override
protected void onExecuted(Bundle args, EntityAccount account) {
boolean leave_deleted = (account != null &&
account.protocol == EntityAccount.TYPE_POP &&
account.leave_deleted);
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_ask_delete)); aargs.putString("question", getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark()); aargs.putString("remark", message.getRemark());
@ -2465,7 +2447,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean delete_asked = prefs.getBoolean("delete_asked", false); boolean delete_asked = prefs.getBoolean("delete_asked", false);
if (delete_asked || leave_deleted) { if (delete_asked ||
(message.accountProtocol == EntityAccount.TYPE_POP &&
message.accountLeaveDeleted)) {
Intent data = new Intent(); Intent data = new Intent();
data.putExtra("args", aargs); data.putExtra("args", aargs);
onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data); onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data);
@ -2478,13 +2462,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
ask.show(getParentFragmentManager(), "swipe:delete"); ask.show(getParentFragmentManager(), "swipe:delete");
} }
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "message:delete");
}
private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) { private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);

@ -31,7 +31,7 @@ import java.util.Objects;
value = TupleAccountView.query value = TupleAccountView.query
) )
public class TupleAccountView { public class TupleAccountView {
static final String query = "SELECT id, pop, name, color, synchronize, notify, auto_seen, created FROM account"; static final String query = "SELECT id, pop, name, color, synchronize, notify, leave_deleted, auto_seen, created FROM account";
@NonNull @NonNull
public Long id; public Long id;
@ -45,6 +45,8 @@ public class TupleAccountView {
@NonNull @NonNull
public Boolean notify = false; public Boolean notify = false;
@NonNull @NonNull
public Boolean leave_deleted = false;
@NonNull
public Boolean auto_seen = true; public Boolean auto_seen = true;
public Long created; public Long created;
@ -58,6 +60,7 @@ public class TupleAccountView {
Objects.equals(this.color, other.color) && Objects.equals(this.color, other.color) &&
this.synchronize.equals(other.synchronize) && this.synchronize.equals(other.synchronize) &&
this.notify.equals(other.notify) && this.notify.equals(other.notify) &&
this.leave_deleted.equals(other.leave_deleted) &&
this.auto_seen.equals(other.auto_seen) && this.auto_seen.equals(other.auto_seen) &&
Objects.equals(this.created, other.created)); Objects.equals(this.created, other.created));
} else } else

@ -38,6 +38,7 @@ public class TupleMessageEx extends EntityMessage {
public String accountName; public String accountName;
public Integer accountColor; public Integer accountColor;
public boolean accountNotify; public boolean accountNotify;
public boolean accountLeaveDeleted;
public boolean accountAutoSeen; public boolean accountAutoSeen;
public String folderName; public String folderName;
public Integer folderColor; public Integer folderColor;
@ -123,6 +124,7 @@ public class TupleMessageEx extends EntityMessage {
Objects.equals(this.accountName, other.accountName) && Objects.equals(this.accountName, other.accountName) &&
Objects.equals(this.accountColor, other.accountColor) && Objects.equals(this.accountColor, other.accountColor) &&
this.accountNotify == other.accountNotify && this.accountNotify == other.accountNotify &&
this.accountLeaveDeleted == other.accountLeaveDeleted &&
this.accountAutoSeen == other.accountAutoSeen && this.accountAutoSeen == other.accountAutoSeen &&
this.folderName.equals(other.folderName) && this.folderName.equals(other.folderName) &&
Objects.equals(this.folderDisplay, other.folderDisplay) && Objects.equals(this.folderDisplay, other.folderDisplay) &&

Loading…
Cancel
Save