From 418f5aed29ab83e06e6508e5c20a072cc3600b5a Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Wed, 27 Dec 2017 22:34:53 +0100 Subject: [PATCH] Don't write the counter and id's to disk Why do I keep changing my mind --- .../main/java/me/impy/aegis/db/Database.java | 19 ++----------------- .../java/me/impy/aegis/db/DatabaseEntry.java | 6 +----- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/me/impy/aegis/db/Database.java b/app/src/main/java/me/impy/aegis/db/Database.java index db79c8e0..4213b6c9 100644 --- a/app/src/main/java/me/impy/aegis/db/Database.java +++ b/app/src/main/java/me/impy/aegis/db/Database.java @@ -22,7 +22,6 @@ public class Database { JSONObject obj = new JSONObject(); obj.put("version", VERSION); obj.put("entries", array); - obj.put("counter", _counter); return obj.toString().getBytes("UTF-8"); } @@ -36,25 +35,11 @@ public class Database { throw new Exception("Unsupported version"); } - // if no counter is present, ignore and reset the id of all entries - boolean ignoreID = false; - if (!obj.has("counter")) { - ignoreID = true; - } else { - _counter = obj.getLong("counter"); - } - JSONArray array = obj.getJSONArray("entries"); for (int i = 0; i < array.length(); i++) { DatabaseEntry entry = new DatabaseEntry(null); - entry.deserialize(array.getJSONObject(i), ignoreID); - - // if the id was ignored, make sure it receives a new one - if (ignoreID) { - addKey(entry); - } else { - _entries.add(entry); - } + entry.deserialize(array.getJSONObject(i)); + addKey(entry); } } diff --git a/app/src/main/java/me/impy/aegis/db/DatabaseEntry.java b/app/src/main/java/me/impy/aegis/db/DatabaseEntry.java index be92b328..54c0480f 100644 --- a/app/src/main/java/me/impy/aegis/db/DatabaseEntry.java +++ b/app/src/main/java/me/impy/aegis/db/DatabaseEntry.java @@ -19,16 +19,12 @@ public class DatabaseEntry implements Serializable { public JSONObject serialize() throws JSONException { JSONObject obj = new JSONObject(); - obj.put("id", _id); obj.put("name", _name); obj.put("url", _info.getURL()); return obj; } - public void deserialize(JSONObject obj, boolean ignoreID) throws Exception { - if (!ignoreID) { - _id = obj.getLong("id"); - } + public void deserialize(JSONObject obj) throws Exception { _name = obj.getString("name"); _info = KeyInfo.fromURL(obj.getString("url")); }