Added uuid to answers

pull/208/head
M66B 3 years ago
parent 825f800bf9
commit 1d8985cdce

File diff suppressed because it is too large Load Diff

@ -984,6 +984,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
long id = answer.id; long id = answer.id;
answer.id = null; answer.id = null;
EntityAnswer existing = db.answer().getAnswerByUUID(answer.uuid);
if (existing != null)
db.answer().deleteAnswer(existing.id);
answer.id = db.answer().insertAnswer(answer); answer.id = db.answer().insertAnswer(answer);
xAnswer.put(id, answer.id); xAnswer.put(id, answer.id);

@ -71,7 +71,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 = 237, version = 238,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2361,6 +2361,19 @@ public abstract class DB extends RoomDatabase {
} }
} }
} }
}).addMigrations(new Migration(237, 238) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `answer` ADD COLUMN `uuid` TEXT NOT NULL DEFAULT ''");
try (Cursor cursor = db.query("SELECT id FROM answer")) {
while (cursor != null && cursor.moveToNext()) {
long id = cursor.getLong(0);
String uuid = UUID.randomUUID().toString();
db.execSQL("UPDATE answer SET uuid = ? WHERE id = ?", new Object[]{uuid, id});
}
}
}
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -55,6 +55,9 @@ public interface DaoAnswer {
@Query("SELECT * FROM answer WHERE id = :id") @Query("SELECT * FROM answer WHERE id = :id")
EntityAnswer getAnswer(long id); EntityAnswer getAnswer(long id);
@Query("SELECT * FROM answer WHERE uuid = :uuid")
EntityAnswer getAnswerByUUID(String uuid);
@Query("SELECT * FROM answer" + @Query("SELECT * FROM answer" +
" WHERE standard AND NOT hide") " WHERE standard AND NOT hide")
EntityAnswer getStandardAnswer(); EntityAnswer getStandardAnswer();

@ -56,6 +56,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.UUID;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
@ -75,6 +76,8 @@ public class EntityAnswer implements Serializable {
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
public Long id; public Long id;
@NonNull @NonNull
public String uuid = UUID.randomUUID().toString();
@NonNull
public String name; public String name;
public String group; public String group;
@NonNull @NonNull
@ -336,7 +339,7 @@ public class EntityAnswer implements Serializable {
ssb.append(p.link).append("\n\n"); ssb.append(p.link).append("\n\n");
profiles.add(999, profiles.size(), profiles.size() + 1, p.name + profiles.add(999, profiles.size(), profiles.size() + 1, p.name +
(p.appPassword ? "+" : "")) (p.appPassword ? "+" : ""))
.setIntent(new Intent().putExtra("config", ssb)); .setIntent(new Intent().putExtra("config", ssb));
} }
} }
@ -374,6 +377,7 @@ public class EntityAnswer implements Serializable {
public JSONObject toJSON() throws JSONException { public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("id", id); json.put("id", id);
json.put("uuid", uuid);
json.put("name", name); json.put("name", name);
json.put("group", group); json.put("group", group);
json.put("standard", standard); json.put("standard", standard);
@ -392,6 +396,8 @@ public class EntityAnswer implements Serializable {
public static EntityAnswer fromJSON(JSONObject json) throws JSONException { public static EntityAnswer fromJSON(JSONObject json) throws JSONException {
EntityAnswer answer = new EntityAnswer(); EntityAnswer answer = new EntityAnswer();
answer.id = json.getLong("id"); answer.id = json.getLong("id");
if (json.has("uuid"))
answer.uuid = json.getString("uuid");
answer.name = json.getString("name"); answer.name = json.getString("name");
answer.group = json.optString("group"); answer.group = json.optString("group");
if (TextUtils.isEmpty(answer.group)) if (TextUtils.isEmpty(answer.group))
@ -415,7 +421,8 @@ public class EntityAnswer implements Serializable {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EntityAnswer) { if (obj instanceof EntityAnswer) {
EntityAnswer other = (EntityAnswer) obj; EntityAnswer other = (EntityAnswer) obj;
return (this.name.equals(other.name) && return (Objects.equals(this.uuid, other.uuid) &&
this.name.equals(other.name) &&
Objects.equals(this.group, other.group) && Objects.equals(this.group, other.group) &&
this.standard.equals(other.standard) && this.standard.equals(other.standard) &&
this.receipt.equals(other.receipt) && this.receipt.equals(other.receipt) &&

Loading…
Cancel
Save