Refactor SettingsHelper a little
This commit is contained in:
parent
c7a75f6612
commit
24e55b5dea
1 changed files with 18 additions and 19 deletions
|
@ -58,7 +58,8 @@ public class SettingsHelper {
|
||||||
|
|
||||||
writeFully(new File(context.getFilesDir() + "/" + SETTINGS_FILE), data);
|
writeFully(new File(context.getFilesDir() + "/" + SETTINGS_FILE), data);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception error) {
|
||||||
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +69,8 @@ public class SettingsHelper {
|
||||||
for(Entry e: entries){
|
for(Entry e: entries){
|
||||||
try {
|
try {
|
||||||
a.put(e.toJSON());
|
a.put(e.toJSON());
|
||||||
} catch (JSONException e1) {
|
} catch (Exception error) {
|
||||||
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,19 +81,15 @@ public class SettingsHelper {
|
||||||
ArrayList<Entry> entries = new ArrayList<>();
|
ArrayList<Entry> entries = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] data = readFully(new File(context.getFilesDir() + "/" + SETTINGS_FILE));
|
JSONArray a = readJSON(context);
|
||||||
|
|
||||||
SecretKey key = EncryptionHelper.loadOrGenerateKeys(context, new File(context.getFilesDir() + "/" + KEY_FILE));
|
for (int i = 0; i < a.length(); i++) {
|
||||||
data = EncryptionHelper.decrypt(key, data);
|
entries.add(new Entry(a.getJSONObject(i)));
|
||||||
|
}
|
||||||
|
} catch (Exception error) {
|
||||||
|
error.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
JSONArray a = new JSONArray(new String(data));
|
|
||||||
|
|
||||||
for(int i=0;i< a.length(); i++){
|
|
||||||
entries.add(new Entry(a.getJSONObject(i) ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
}
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +104,8 @@ public class SettingsHelper {
|
||||||
|
|
||||||
json = new JSONArray(new String(data));
|
json = new JSONArray(new String(data));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception error) {
|
||||||
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
|
@ -123,9 +122,9 @@ public class SettingsHelper {
|
||||||
Writer output = new BufferedWriter(new FileWriter(outputFile));
|
Writer output = new BufferedWriter(new FileWriter(outputFile));
|
||||||
output.write(data.toString());
|
output.write(data.toString());
|
||||||
output.close();
|
output.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception error) {
|
||||||
success = false;
|
success = false;
|
||||||
e.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -145,9 +144,9 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception error) {
|
||||||
success = false;
|
success = false;
|
||||||
e.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
String content = stringBuilder.toString();
|
String content = stringBuilder.toString();
|
||||||
|
|
||||||
|
@ -155,9 +154,9 @@ public class SettingsHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = new JSONArray(content);
|
json = new JSONArray(content);
|
||||||
} catch (Exception e) {
|
} catch (Exception error) {
|
||||||
success = false;
|
success = false;
|
||||||
e.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
store(context, json);
|
store(context, json);
|
||||||
|
|
Loading…
Reference in a new issue