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) { } catch (JSONException e) {
// if stored node is old string format, try parse and upgrade, if fail then remove
try { try {
String nodeString = jsonArray.getString(i); String nodeString = jsonArray.getString(i);
Node node = Node.fromString(nodeString); Node node = Node.fromString(nodeString);

View file

@ -45,6 +45,12 @@ public class PrefService extends ServiceBase {
JSONObject nodeJson = new JSONObject(nodeString); JSONObject nodeJson = new JSONObject(nodeString);
return Node.fromJson(nodeJson); return Node.fromJson(nodeJson);
} catch (JSONException e) { } catch (JSONException e) {
// stored node is not json format, upgrade if possible
return upgradeOldNode(nodeString);
}
}
private Node upgradeOldNode(String nodeString) {
if(!nodeString.isEmpty()) { if(!nodeString.isEmpty()) {
Node node = Node.fromString(nodeString); Node node = Node.fromString(nodeString);
if(node != null) { if(node != null) {
@ -52,7 +58,6 @@ public class PrefService extends ServiceBase {
return node; return node;
} }
} }
}
return null; return null;
} }