Auto reselect system folders

pull/210/head
M66B 3 years ago
parent 28782301cc
commit 7b03bb0777

File diff suppressed because it is too large Load Diff

@ -2650,15 +2650,14 @@ class Core {
}
// Reselect system folders once
String key = "updated." + account.id + "." + type;
boolean reselected = prefs.getBoolean(key, false);
if (!reselected) {
prefs.edit().putBoolean(key, true).apply();
String key = "unset." + account.id + "." + type;
boolean unset = prefs.getBoolean(key, false);
if (!unset) {
EntityFolder folder = db.folder().getFolderByType(account.id, type);
if (folder == null) {
folder = db.folder().getFolderByName(account.id, fullName);
if (folder != null && !folder.local) {
Log.e("Updated " + account.host + " " + type + "=" + fullName);
Log.e("Reselected " + account.host + " " + type + "=" + fullName);
folder.type = type;
folder.setProperties();
folder.setSpecials(account);
@ -2668,7 +2667,7 @@ class Core {
account.swipe_left != null && account.swipe_left > 0) {
EntityFolder swipe = db.folder().getFolder(account.swipe_left);
if (swipe == null) {
Log.e("Updated " + account.host + " swipe left");
Log.e("Reselected " + account.host + " swipe left");
account.swipe_left = folder.id;
db.account().setAccountSwipes(account.id,
account.swipe_left, account.swipe_right);
@ -2679,7 +2678,7 @@ class Core {
account.swipe_right != null && account.swipe_right > 0) {
EntityFolder swipe = db.folder().getFolder(account.swipe_right);
if (swipe == null) {
Log.e("Updated " + account.host + " swipe right");
Log.e("Reselected " + account.host + " swipe right");
account.swipe_right = folder.id;
db.account().setAccountSwipes(account.id,
account.swipe_left, account.swipe_right);
@ -2743,7 +2742,6 @@ class Core {
parent = db.folder().getFolderByName(account.id, fullName.substring(0, sep));
if (!EntityFolder.USER.equals(type) && !EntityFolder.SYSTEM.equals(type)) {
prefs.edit().remove("updated." + account.id + "." + type).apply();
EntityFolder has = db.folder().getFolderByType(account.id, type);
if (has != null)
type = EntityFolder.USER;
@ -2874,7 +2872,6 @@ class Core {
EntityLog.log(context, name + " delete");
db.folder().deleteFolder(account.id, name);
EntityLog.log(context, name + " deleted");
prefs.edit().remove("updated." + account.id + "." + folder.type).apply();
} else
Log.w(name + " keep type=" + folder.type);
}

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 252,
version = 253,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -2536,6 +2536,43 @@ public abstract class DB extends RoomDatabase {
public void migrate(@NonNull SupportSQLiteDatabase db) {
db.execSQL("ALTER TABLE `account` ADD COLUMN `calendar` TEXT");
}
}).addMigrations(new Migration(252, 253) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
for (String key : prefs.getAll().keySet())
if (key.startsWith("updated.") || key.startsWith("unset."))
editor.remove(key);
try (Cursor cursor = db.query("SELECT account.id" +
", archive.type AS archive" +
", drafts.type AS drafts" +
", trash.type AS trash" +
", junk.type AS junk" +
", sent.type AS sent" +
" FROM `account`" +
" LEFT JOIN folder AS archive ON archive.account = account.id AND archive.type = 'All'" +
" LEFT JOIN folder AS drafts ON drafts.account = account.id AND drafts.type = 'Drafts'" +
" LEFT JOIN folder AS trash ON trash.account = account.id AND trash.type = 'Trash'" +
" LEFT JOIN folder AS junk ON junk.account = account.id AND junk.type = 'Junk'" +
" LEFT JOIN folder AS sent ON sent.account = account.id AND sent.type = 'Sent'" +
" WHERE account.pop = 0")) {
while (cursor.moveToNext()) {
long id = cursor.getLong(0);
if (cursor.getString(1) == null)
editor.putBoolean("unset." + id + ".All", true);
if (cursor.getString(2) == null)
editor.putBoolean("unset." + id + ".Drafts", true);
if (cursor.getString(3) == null)
editor.putBoolean("unset." + id + ".Trash", true);
if (cursor.getString(4) == null)
editor.putBoolean("unset." + id + ".Junk", true);
if (cursor.getString(5) == null)
editor.putBoolean("unset." + id + ".Sent", true);
}
}
editor.apply();
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -30,6 +30,7 @@ import android.Manifest;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
@ -64,6 +65,7 @@ import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle;
import androidx.preference.PreferenceManager;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputLayout;
@ -1419,6 +1421,15 @@ public class FragmentAccount extends FragmentBase {
args.putBoolean("saved", true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("unset." + account.id + "." + EntityFolder.DRAFTS, drafts == null);
editor.putBoolean("unset." + account.id + "." + EntityFolder.SENT, sent == null);
editor.putBoolean("unset." + account.id + "." + EntityFolder.ARCHIVE, archive == null);
editor.putBoolean("unset." + account.id + "." + EntityFolder.TRASH, trash == null);
editor.putBoolean("unset." + account.id + "." + EntityFolder.JUNK, junk == null);
editor.apply();
return false;
}

Loading…
Cancel
Save