Fix some crashes

This commit is contained in:
Thomas 2020-09-12 10:37:11 +02:00
parent 2f909d5ffa
commit c4c745dbc0
1 changed files with 13 additions and 4 deletions

View File

@ -235,7 +235,9 @@ public class PeertubeAPI {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
return null; if (!resobj.has("name")) {
return null;
}
} }
try { try {
peertube.setId(resobj.getString("id")); peertube.setId(resobj.getString("id"));
@ -243,6 +245,7 @@ public class PeertubeAPI {
if (resobj.has("uuid")) { if (resobj.has("uuid")) {
peertube.setUuid(resobj.getString("uuid")); peertube.setUuid(resobj.getString("uuid"));
} }
peertube.setName(resobj.getString("name")); peertube.setName(resobj.getString("name"));
peertube.setDescription(resobj.getString("description")); peertube.setDescription(resobj.getString("description"));
peertube.setEmbedPath(resobj.getString("embedPath")); peertube.setEmbedPath(resobj.getString("embedPath"));
@ -272,11 +275,16 @@ public class PeertubeAPI {
LinkedHashMap<Integer, String> category = new LinkedHashMap<>(); LinkedHashMap<Integer, String> category = new LinkedHashMap<>();
LinkedHashMap<Integer, String> license = new LinkedHashMap<>(); LinkedHashMap<Integer, String> license = new LinkedHashMap<>();
LinkedHashMap<Integer, String> privacy = new LinkedHashMap<>(); LinkedHashMap<Integer, String> privacy = new LinkedHashMap<>();
category.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
if (!resobj.getJSONObject("category").isNull("id")) {
license.put(resobj.getJSONObject("category").getInt("id"), resobj.getJSONObject("category").getString("label"));
} else {
license.put(1, resobj.getJSONObject("category").getString("label"));
}
if (!resobj.getJSONObject("licence").isNull("id")) { if (!resobj.getJSONObject("licence").isNull("id")) {
license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").getString("label")); license.put(resobj.getJSONObject("licence").getInt("id"), resobj.getJSONObject("licence").getString("label"));
} else { } else {
license.put(1, "Unknown"); license.put(1, resobj.getJSONObject("licence").getString("label"));
} }
privacy.put(resobj.getJSONObject("privacy").getInt("id"), resobj.getJSONObject("privacy").getString("label")); privacy.put(resobj.getJSONObject("privacy").getInt("id"), resobj.getJSONObject("privacy").getString("label"));
langue.put(resobj.getJSONObject("language").getString("id"), resobj.getJSONObject("language").getString("label")); langue.put(resobj.getJSONObject("language").getString("id"), resobj.getJSONObject("language").getString("label"));
@ -284,7 +292,8 @@ public class PeertubeAPI {
peertube.setLicense(license); peertube.setLicense(license);
peertube.setLanguage(langue); peertube.setLanguage(langue);
peertube.setPrivacy(privacy); peertube.setPrivacy(privacy);
} catch (Exception ignored) { } catch (Exception e) {
e.printStackTrace();
} }
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();