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,53 +4351,30 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void onActionDelete(TupleMessageEx message) { private void onActionDelete(TupleMessageEx message) {
Bundle args = new Bundle(); Bundle aargs = new Bundle();
args.putLong("account", message.account == null ? -1 : message.account); aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark());
new SimpleTask<EntityAccount>() { aargs.putLong("id", message.id);
@Override aargs.putInt("faq", 160);
protected EntityAccount onExecute(Context context, Bundle args) throws Throwable { aargs.putString("notagain", "delete_asked");
long aid = args.getLong("account"); aargs.putString("accept", context.getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
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();
aargs.putString("question", context.getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark());
aargs.putLong("id", message.id);
aargs.putInt("faq", 160);
aargs.putString("notagain", "delete_asked");
aargs.putString("accept", context.getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean delete_asked = prefs.getBoolean("delete_asked", false);
if (delete_asked || leave_deleted) {
Intent data = new Intent();
data.putExtra("args", aargs);
parentFragment.onActivityResult(FragmentMessages.REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return;
}
FragmentDialogAsk ask = new FragmentDialogAsk(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
ask.setArguments(aargs); boolean delete_asked = prefs.getBoolean("delete_asked", false);
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE); if (delete_asked ||
ask.show(parentFragment.getParentFragmentManager(), "message:delete"); (message.accountProtocol == EntityAccount.TYPE_POP &&
} message.accountLeaveDeleted)) {
Intent data = new Intent();
data.putExtra("args", aargs);
parentFragment.onActivityResult(FragmentMessages.REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return;
}
@Override FragmentDialogAsk ask = new FragmentDialogAsk();
protected void onException(Bundle args, Throwable ex) { ask.setArguments(aargs);
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_DELETE);
} ask.show(parentFragment.getParentFragmentManager(), "message:delete");
}.execute(context, owner, args, "message:delete");
} }
private void onActionJunk(TupleMessageEx message) { private void onActionJunk(TupleMessageEx message) {

@ -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,53 +2436,30 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onSwipeDelete(@NonNull TupleMessageEx message) { private void onSwipeDelete(@NonNull TupleMessageEx message) {
Bundle args = new Bundle(); Bundle aargs = new Bundle();
args.putLong("account", message.account == null ? -1 : message.account); aargs.putString("question", getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark());
new SimpleTask<EntityAccount>() { aargs.putLong("id", message.id);
@Override aargs.putInt("faq", 160);
protected EntityAccount onExecute(Context context, Bundle args) throws Throwable { aargs.putString("notagain", "delete_asked");
long aid = args.getLong("account"); aargs.putString("accept", getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
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();
aargs.putString("question", getString(R.string.title_ask_delete));
aargs.putString("remark", message.getRemark());
aargs.putLong("id", message.id);
aargs.putInt("faq", 160);
aargs.putString("notagain", "delete_asked");
aargs.putString("accept", getString(R.string.title_ask_delete_accept));
aargs.putBoolean("warning", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean delete_asked = prefs.getBoolean("delete_asked", false);
if (delete_asked || leave_deleted) {
Intent data = new Intent();
data.putExtra("args", aargs);
onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return;
}
FragmentDialogAsk ask = new FragmentDialogAsk(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
ask.setArguments(aargs); boolean delete_asked = prefs.getBoolean("delete_asked", false);
ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGE_DELETE); if (delete_asked ||
ask.show(getParentFragmentManager(), "swipe:delete"); (message.accountProtocol == EntityAccount.TYPE_POP &&
} message.accountLeaveDeleted)) {
Intent data = new Intent();
data.putExtra("args", aargs);
onActivityResult(REQUEST_MESSAGE_DELETE, RESULT_OK, data);
return;
}
@Override FragmentDialogAsk ask = new FragmentDialogAsk();
protected void onException(Bundle args, Throwable ex) { ask.setArguments(aargs);
Log.unexpectedError(getParentFragmentManager(), ex); ask.setTargetFragment(FragmentMessages.this, REQUEST_MESSAGE_DELETE);
} ask.show(getParentFragmentManager(), "swipe:delete");
}.execute(FragmentMessages.this, args, "message:delete");
} }
private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) { private void swipeFolder(@NonNull TupleMessageEx message, @NonNull Long target) {

@ -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