Added account UUID

This commit is contained in:
M66B
2021-07-29 18:59:05 +02:00
parent 134071850a
commit 9fbb996e69
5 changed files with 2548 additions and 3 deletions

View File

@@ -102,6 +102,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
private TextView tvBackoff;
private TextView tvQuota;
private TextView tvMaxSize;
private TextView tvId;
private TextView tvIdentity;
private TextView tvDrafts;
private TextView tvSent;
@@ -132,6 +133,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
tvBackoff = itemView.findViewById(R.id.tvBackoff);
tvQuota = itemView.findViewById(R.id.tvQuota);
tvMaxSize = itemView.findViewById(R.id.tvMaxSize);
tvId = itemView.findViewById(R.id.tvId);
tvIdentity = itemView.findViewById(R.id.tvIdentity);
tvDrafts = itemView.findViewById(R.id.tvDrafts);
tvSent = itemView.findViewById(R.id.tvSent);
@@ -233,6 +235,9 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
if (tvMaxSize.getVisibility() == View.VISIBLE)
tvQuota.setVisibility(View.VISIBLE);
tvId.setText(account.id + "/" + account.uuid);
tvId.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
tvIdentity.setVisibility(account.identities > 0 || !settings ? View.GONE : View.VISIBLE);
tvDrafts.setVisibility(account.drafts != null || !settings ? View.GONE : View.VISIBLE);
tvSent.setVisibility(account.protocol != EntityAccount.TYPE_IMAP ||

View File

@@ -33,6 +33,7 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import javax.mail.Address;
@@ -65,7 +66,7 @@ import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 203,
version = 204,
entities = {
EntityIdentity.class,
EntityAccount.class,
@@ -2058,6 +2059,26 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `last_sync_count` INTEGER");
}
}).addMigrations(new Migration(203, 204) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT ''");
Cursor cursor = null;
try {
cursor = db.query("SELECT id FROM account");
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(0);
String uuid = UUID.randomUUID().toString();
Log.i("MMM account=" + id + " uuid=" + uuid);
db.execSQL("UPDATE account SET uuid = ? WHERE id = ?",
new Object[]{uuid, id});
}
} catch (Throwable ex) {
if (cursor != null)
cursor.close();
}
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

View File

@@ -42,6 +42,7 @@ import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
@Entity(
tableName = EntityAccount.TABLE_NAME,
@@ -62,6 +63,9 @@ public class EntityAccount extends EntityOrder implements Serializable {
@PrimaryKey(autoGenerate = true)
public Long id;
@NonNull
public String uuid = UUID.randomUUID().toString();
@NonNull
@ColumnInfo(name = "pop")
public Integer protocol = TYPE_IMAP;
@@ -221,6 +225,7 @@ public class EntityAccount extends EntityOrder implements Serializable {
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("uuid", uuid);
json.put("order", order);
json.put("protocol", protocol);
json.put("host", host);
@@ -276,6 +281,9 @@ public class EntityAccount extends EntityOrder implements Serializable {
if (json.has("id"))
account.id = json.getLong("id");
if (json.has("uuid"))
account.uuid = json.getString("uuid");
if (json.has("order"))
account.order = json.getInt("order");
@@ -352,7 +360,8 @@ public class EntityAccount extends EntityOrder implements Serializable {
public boolean equals(Object obj) {
if (obj instanceof EntityAccount) {
EntityAccount other = (EntityAccount) obj;
return (Objects.equals(this.order, other.order) &&
return (Objects.equals(this.uuid, other.uuid) &&
Objects.equals(this.order, other.order) &&
this.protocol.equals(other.protocol) &&
this.host.equals(other.host) &&
this.encryption.equals(other.encryption) &&