Cleanup and add comment

This commit is contained in:
pokkst 2023-05-24 22:15:42 -05:00
parent 9e70f64e39
commit f95683aed2
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
2 changed files with 12 additions and 6 deletions

View File

@ -73,6 +73,7 @@ public class NodeSelectionBottomSheetDialog extends BottomSheetDialogFragment im
}
}
} catch (JSONException e) {
// if stored node is old string format, try parse and upgrade, if fail then remove
try {
String nodeString = jsonArray.getString(i);
Node node = Node.fromString(nodeString);

View File

@ -45,12 +45,17 @@ public class PrefService extends ServiceBase {
JSONObject nodeJson = new JSONObject(nodeString);
return Node.fromJson(nodeJson);
} catch (JSONException e) {
if(!nodeString.isEmpty()) {
Node node = Node.fromString(nodeString);
if(node != null) {
edit().putString(Constants.PREF_NODE_2, node.toJson().toString()).apply();
return node;
}
// stored node is not json format, upgrade if possible
return upgradeOldNode(nodeString);
}
}
private Node upgradeOldNode(String nodeString) {
if(!nodeString.isEmpty()) {
Node node = Node.fromString(nodeString);
if(node != null) {
edit().putString(Constants.PREF_NODE_2, node.toJson().toString()).apply();
return node;
}
}
return null;