Some cleaning

This commit is contained in:
Thomas 2020-07-04 18:16:49 +02:00
parent 6d3a820aff
commit bb15c97721
1 changed files with 207 additions and 207 deletions

View File

@ -195,49 +195,49 @@ public class API {
Card card = new Card();
try {
card.setUrl(resobj.get("url").toString());
card.setTitle(resobj.get("title").toString());
card.setDescription(resobj.get("description").toString());
card.setImage(resobj.get("image").toString());
card.setUrl(resobj.getString("url"));
card.setTitle(resobj.getString("title"));
card.setDescription(resobj.getString("description"));
card.setImage(resobj.getString("image"));
card.setType(resobj.get("type").toString());
card.setType(resobj.getString("type"));
try {
card.setAuthor_name(resobj.get("author_name").toString());
card.setAuthor_name(resobj.getString("author_name"));
} catch (Exception e) {
card.setAuthor_name(null);
}
try {
card.setAuthor_url(resobj.get("author_url").toString());
card.setAuthor_url(resobj.getString("author_url"));
} catch (Exception e) {
card.setAuthor_url(null);
}
try {
card.setHtml(resobj.get("html").toString());
card.setHtml(resobj.getString("html"));
} catch (Exception e) {
card.setHtml(null);
}
try {
card.setEmbed_url(resobj.get("embed_url").toString());
card.setEmbed_url(resobj.getString("embed_url"));
} catch (Exception e) {
card.setEmbed_url(null);
}
try {
card.setProvider_name(resobj.get("provider_name").toString());
card.setProvider_name(resobj.getString("provider_name"));
} catch (Exception e) {
card.setProvider_name(null);
}
try {
card.setProvider_url(resobj.get("provider_url").toString());
card.setProvider_url(resobj.getString("provider_url"));
} catch (Exception e) {
card.setProvider_url(null);
}
try {
card.setHeight(Integer.parseInt(resobj.get("height").toString()));
card.setHeight(resobj.getInt("height"));
} catch (Exception e) {
card.setHeight(0);
}
try {
card.setWidth(Integer.parseInt(resobj.get("width").toString()));
card.setWidth(resobj.getInt("width"));
} catch (Exception e) {
card.setWidth(0);
}
@ -259,34 +259,34 @@ public class API {
try {
instanceSocial.setUptime(Float.parseFloat(resobj.get("uptime").toString()));
instanceSocial.setUp(Boolean.parseBoolean(resobj.get("up").toString()));
instanceSocial.setUptime(Float.parseFloat(resobj.getString("uptime")));
instanceSocial.setUp(resobj.getBoolean("up"));
instanceSocial.setConnections(Long.parseLong(resobj.get("connections").toString()));
instanceSocial.setDead(Boolean.parseBoolean(resobj.get("dead").toString()));
instanceSocial.setConnections(Long.parseLong(resobj.getString("connections")));
instanceSocial.setDead(resobj.getBoolean("dead"));
instanceSocial.setId(resobj.get("id").toString());
instanceSocial.setId(resobj.getString("id"));
instanceSocial.setInfo(resobj.get("info").toString());
instanceSocial.setVersion(resobj.get("version").toString());
instanceSocial.setName(resobj.get("name").toString());
instanceSocial.setObs_rank(resobj.get("obs_rank").toString());
instanceSocial.setThumbnail(resobj.get("thumbnail").toString());
instanceSocial.setIpv6(Boolean.parseBoolean(resobj.get("ipv6").toString()));
instanceSocial.setObs_score(Integer.parseInt(resobj.get("obs_score").toString()));
instanceSocial.setOpen_registrations(Boolean.parseBoolean(resobj.get("open_registrations").toString()));
instanceSocial.setInfo(resobj.getString("info"));
instanceSocial.setVersion(resobj.getString("version"));
instanceSocial.setName(resobj.getString("name"));
instanceSocial.setObs_rank(resobj.getString("obs_rank"));
instanceSocial.setThumbnail(resobj.getString("thumbnail"));
instanceSocial.setIpv6(resobj.getBoolean("ipv6"));
instanceSocial.setObs_score(resobj.getInt("obs_score"));
instanceSocial.setOpen_registrations(resobj.getBoolean("open_registrations"));
instanceSocial.setUsers(Long.parseLong(resobj.get("users").toString()));
instanceSocial.setStatuses(Long.parseLong(resobj.get("statuses").toString()));
instanceSocial.setUsers(Long.parseLong(resobj.getString("users")));
instanceSocial.setStatuses(Long.parseLong(resobj.getString("statuses")));
instanceSocial.setHttps_rank(resobj.get("https_rank").toString());
instanceSocial.setHttps_score(Integer.parseInt(resobj.get("https_score").toString()));
instanceSocial.setHttps_rank(resobj.getString("https_rank"));
instanceSocial.setHttps_score(resobj.getInt("https_score"));
if (!resobj.isNull("added_at")) {
instanceSocial.setAdded_at(Helper.mstStringToDate(resobj.get("added_at").toString()));
instanceSocial.setAdded_at(Helper.mstStringToDate(resobj.getString("added_at")));
}
instanceSocial.setChecked_at(Helper.mstStringToDate(resobj.get("checked_at").toString()));
instanceSocial.setUpdated_at(Helper.mstStringToDate(resobj.get("updated_at").toString()));
instanceSocial.setChecked_at(Helper.mstStringToDate(resobj.getString("checked_at")));
instanceSocial.setUpdated_at(Helper.mstStringToDate(resobj.getString("updated_at")));
} catch (Exception e) {
@ -304,22 +304,22 @@ public class API {
public static Peertube parsePeertube(String instance, JSONObject resobj) {
Peertube peertube = new Peertube();
try {
peertube.setId(resobj.get("id").toString());
peertube.setId(resobj.getString("id"));
peertube.setCache(resobj);
peertube.setUuid(resobj.get("uuid").toString());
peertube.setName(resobj.get("name").toString());
peertube.setDescription(resobj.get("description").toString());
peertube.setEmbedPath(resobj.get("embedPath").toString());
peertube.setPreviewPath(resobj.get("previewPath").toString());
peertube.setThumbnailPath(resobj.get("thumbnailPath").toString());
peertube.setUuid(resobj.getString("uuid"));
peertube.setName(resobj.getString("name"));
peertube.setDescription(resobj.getString("description"));
peertube.setEmbedPath(resobj.getString("embedPath"));
peertube.setPreviewPath(resobj.getString("previewPath"));
peertube.setThumbnailPath(resobj.getString("thumbnailPath"));
peertube.setAccount(parseAccountResponsePeertube(instance, resobj.getJSONObject("account")));
peertube.setInstance(instance);
peertube.setView(Integer.parseInt(resobj.get("views").toString()));
peertube.setLike(Integer.parseInt(resobj.get("likes").toString()));
peertube.setDislike(Integer.parseInt(resobj.get("dislikes").toString()));
peertube.setDuration(Integer.parseInt(resobj.get("duration").toString()));
peertube.setView(resobj.getInt("views"));
peertube.setLike(resobj.getInt("likes"));
peertube.setDislike(resobj.getInt("dislikes"));
peertube.setDuration(resobj.getInt("duration"));
try {
peertube.setCreated_at(Helper.mstStringToDate(resobj.get("createdAt").toString()));
peertube.setCreated_at(Helper.mstStringToDate(resobj.getString("createdAt")));
} catch (ParseException e) {
e.printStackTrace();
}
@ -339,24 +339,24 @@ public class API {
private static Peertube parseSinglePeertube(String instance, JSONObject resobj) {
Peertube peertube = new Peertube();
try {
peertube.setId(resobj.get("id").toString());
peertube.setUuid(resobj.get("uuid").toString());
peertube.setName(resobj.get("name").toString());
peertube.setId(resobj.getString("id"));
peertube.setUuid(resobj.getString("uuid"));
peertube.setName(resobj.getString("name"));
peertube.setCache(resobj);
peertube.setInstance(instance);
peertube.setHost(resobj.getJSONObject("account").get("host").toString());
peertube.setDescription(resobj.get("description").toString());
peertube.setEmbedPath(resobj.get("embedPath").toString());
peertube.setPreviewPath(resobj.get("previewPath").toString());
peertube.setThumbnailPath(resobj.get("thumbnailPath").toString());
peertube.setView(Integer.parseInt(resobj.get("views").toString()));
peertube.setLike(Integer.parseInt(resobj.get("likes").toString()));
peertube.setCommentsEnabled(Boolean.parseBoolean(resobj.get("commentsEnabled").toString()));
peertube.setDislike(Integer.parseInt(resobj.get("dislikes").toString()));
peertube.setDuration(Integer.parseInt(resobj.get("duration").toString()));
peertube.setHost(resobj.getJSONObject("account").getString("host"));
peertube.setDescription(resobj.getString("description"));
peertube.setEmbedPath(resobj.getString("embedPath"));
peertube.setPreviewPath(resobj.getString("previewPath"));
peertube.setThumbnailPath(resobj.getString("thumbnailPath"));
peertube.setView(resobj.getInt("views"));
peertube.setLike(resobj.getInt("likes"));
peertube.setCommentsEnabled(resobj.getBoolean("commentsEnabled"));
peertube.setDislike(resobj.getInt("dislikes"));
peertube.setDuration(resobj.getInt("duration"));
peertube.setAccount(parseAccountResponsePeertube(instance, resobj.getJSONObject("account")));
try {
peertube.setCreated_at(Helper.mstStringToDate(resobj.get("createdAt").toString()));
peertube.setCreated_at(Helper.mstStringToDate(resobj.getString("createdAt")));
} catch (ParseException e) {
e.printStackTrace();
}
@ -367,7 +367,7 @@ public class API {
for (int j = 0; j < files.length(); j++) {
JSONObject attObj = files.getJSONObject(j);
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
resolutions.add(attObj.getJSONObject("resolution").getString("id"));
}
peertube.setResolution(resolutions);
peertube.setStreamService(true);
@ -376,7 +376,7 @@ public class API {
for (int j = 0; j < files.length(); j++) {
JSONObject attObj = files.getJSONObject(j);
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
resolutions.add(attObj.getJSONObject("resolution").getString("id"));
}
peertube.setResolution(resolutions);
peertube.setStreamService(false);
@ -402,15 +402,15 @@ public class API {
while (i < jsonArray.length()) {
Status status = new Status();
JSONObject comment = jsonArray.getJSONObject(i);
status.setId(comment.get("id").toString());
status.setUri(comment.get("url").toString());
status.setUrl(comment.get("url").toString());
status.setId(comment.getString("id"));
status.setUri(comment.getString("url"));
status.setUrl(comment.getString("url"));
status.setSensitive(false);
status.setSpoiler_text("");
status.setContent(context, comment.get("text").toString());
status.setIn_reply_to_id(comment.get("inReplyToCommentId").toString());
status.setContent(context, comment.getString("text"));
status.setIn_reply_to_id(comment.getString("inReplyToCommentId"));
status.setAccount(parseAccountResponsePeertube(instance, comment.getJSONObject("account")));
status.setCreated_at(Helper.mstStringToDate(comment.get("createdAt").toString()));
status.setCreated_at(Helper.mstStringToDate(comment.getString("createdAt")));
status.setMentions(new ArrayList<>());
status.setEmojis(new ArrayList<>());
status.setMedia_attachments(new ArrayList<>());
@ -440,13 +440,13 @@ public class API {
private static HowToVideo parseHowTo(JSONObject resobj) {
HowToVideo howToVideo = new HowToVideo();
try {
howToVideo.setId(resobj.get("id").toString());
howToVideo.setUuid(resobj.get("uuid").toString());
howToVideo.setName(resobj.get("name").toString());
howToVideo.setDescription(resobj.get("description").toString());
howToVideo.setEmbedPath(resobj.get("embedPath").toString());
howToVideo.setPreviewPath(resobj.get("previewPath").toString());
howToVideo.setThumbnailPath(resobj.get("thumbnailPath").toString());
howToVideo.setId(resobj.getString("id"));
howToVideo.setUuid(resobj.getString("uuid"));
howToVideo.setName(resobj.getString("name"));
howToVideo.setDescription(resobj.getString("description"));
howToVideo.setEmbedPath(resobj.getString("embedPath"));
howToVideo.setPreviewPath(resobj.getString("previewPath"));
howToVideo.setThumbnailPath(resobj.getString("thumbnailPath"));
} catch (JSONException e) {
e.printStackTrace();
}
@ -469,8 +469,8 @@ public class API {
status.setMedia_attachments((ArrayList<Attachment>) attachements);
schedule.setStatus(status);
schedule.setAttachmentList(attachements);
schedule.setId(jsonObject.get("id").toString());
schedule.setScheduled_at(Helper.mstStringToDate(jsonObject.get("scheduled_at").toString()));
schedule.setId(jsonObject.getString("id"));
schedule.setScheduled_at(Helper.mstStringToDate(jsonObject.getString("scheduled_at")));
} catch (JSONException | ParseException e) {
e.printStackTrace();
}
@ -497,8 +497,8 @@ public class API {
schedule.setStatus(status);
schedule.setAttachmentList(attachements);
schedules.add(schedule);
schedule.setId(jsonArray.getJSONObject(i).get("id").toString());
schedule.setScheduled_at(Helper.mstStringToDate(jsonArray.getJSONObject(i).get("scheduled_at").toString()));
schedule.setId(jsonArray.getJSONObject(i).getString("id"));
schedule.setScheduled_at(Helper.mstStringToDate(jsonArray.getJSONObject(i).getString("scheduled_at")));
i++;
}
} catch (JSONException | ParseException e) {
@ -643,8 +643,8 @@ public class API {
for (int j = 0; j < arrayTag.length(); j++) {
JSONObject tagObj = arrayTag.getJSONObject(j);
Tag tag = new Tag();
tag.setName(tagObj.get("name").toString());
tag.setUrl(tagObj.get("url").toString());
tag.setName(tagObj.getString("name"));
tag.setUrl(tagObj.getString("url"));
tags.add(tag);
}
announcement.setTags(tags);
@ -669,10 +669,10 @@ public class API {
for (int j = 0; j < arrayMention.length(); j++) {
JSONObject menObj = arrayMention.getJSONObject(j);
Mention mention = new Mention();
mention.setId(menObj.get("id").toString());
mention.setUrl(menObj.get("url").toString());
mention.setAcct(menObj.get("acct").toString());
mention.setUsername(menObj.get("username").toString());
mention.setId(menObj.getString("id"));
mention.setUrl(menObj.getString("url"));
mention.setAcct(menObj.getString("acct"));
mention.setUsername(menObj.getString("username"));
mentions.add(mention);
}
announcement.setMentions(mentions);
@ -764,23 +764,23 @@ public class API {
private static Status parseStatuses(Context context, JSONObject resobj, boolean recursive) {
Status status = new Status();
try {
status.setId(resobj.get("id").toString());
status.setId(resobj.getString("id"));
if (resobj.has("uri")) {
status.setUri(resobj.get("uri").toString());
status.setUri(resobj.getString("uri"));
} else {
status.setUri(resobj.get("id").toString());
status.setUri(resobj.getString("id"));
}
if (resobj.has("created_at")) {
status.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
status.setCreated_at(Helper.mstStringToDate(resobj.getString("created_at")));
} else {
status.setCreated_at(new Date());
}
if (!resobj.isNull("in_reply_to_id")) {
status.setIn_reply_to_id(resobj.get("in_reply_to_id").toString());
status.setIn_reply_to_id(resobj.getString("in_reply_to_id"));
}
if (!resobj.isNull("in_reply_to_account_id")) {
status.setIn_reply_to_account_id(resobj.get("in_reply_to_account_id").toString());
status.setIn_reply_to_account_id(resobj.getString("in_reply_to_account_id"));
}
if (resobj.has("sensitive")) {
status.setSensitive(resobj.getBoolean("sensitive"));
@ -788,15 +788,15 @@ public class API {
status.setSensitive(false);
}
if (resobj.has("spoiler_text")) {
status.setSpoiler_text(resobj.get("spoiler_text").toString());
status.setSpoiler_text(resobj.getString("spoiler_text"));
}
try {
status.setVisibility(resobj.get("visibility").toString());
status.setVisibility(resobj.getString("visibility"));
} catch (Exception e) {
status.setVisibility("public");
}
try {
status.setLanguage(resobj.get("language").toString());
status.setLanguage(resobj.getString("language"));
} catch (Exception e) {
status.setLanguage("ja");
}
@ -811,7 +811,7 @@ public class API {
status.setReactions(reactions);
if (resobj.has("url")) {
status.setUrl(resobj.get("url").toString());
status.setUrl(resobj.getString("url"));
}
ArrayList<Attachment> attachments = new ArrayList<>();
//Retrieves attachments
@ -821,14 +821,14 @@ public class API {
for (int j = 0; j < arrayAttachement.length(); j++) {
JSONObject attObj = arrayAttachement.getJSONObject(j);
Attachment attachment = new Attachment();
attachment.setId(attObj.get("id").toString());
attachment.setPreview_url(attObj.get("preview_url").toString());
attachment.setRemote_url(attObj.get("remote_url").toString());
attachment.setType(attObj.get("type").toString());
attachment.setText_url(attObj.get("text_url").toString());
attachment.setUrl(attObj.get("url").toString());
attachment.setId(attObj.getString("id"));
attachment.setPreview_url(attObj.getString("preview_url"));
attachment.setRemote_url(attObj.getString("remote_url"));
attachment.setType(attObj.getString("type"));
attachment.setText_url(attObj.getString("text_url"));
attachment.setUrl(attObj.getString("url"));
try {
attachment.setDescription(attObj.get("description").toString());
attachment.setDescription(attObj.getString("description"));
} catch (JSONException ignore) {
}
attachments.add(attachment);
@ -848,10 +848,10 @@ public class API {
for (int j = 0; j < arrayMention.length(); j++) {
JSONObject menObj = arrayMention.getJSONObject(j);
Mention mention = new Mention();
mention.setId(menObj.get("id").toString());
mention.setUrl(menObj.get("url").toString());
mention.setAcct(menObj.get("acct").toString());
mention.setUsername(menObj.get("username").toString());
mention.setId(menObj.getString("id"));
mention.setUrl(menObj.getString("url"));
mention.setAcct(menObj.getString("acct"));
mention.setUsername(menObj.getString("username"));
mentions.add(mention);
}
}
@ -863,8 +863,8 @@ public class API {
for (int j = 0; j < arrayTag.length(); j++) {
JSONObject tagObj = arrayTag.getJSONObject(j);
Tag tag = new Tag();
tag.setName(tagObj.get("name").toString());
tag.setUrl(tagObj.get("url").toString());
tag.setName(tagObj.getString("name"));
tag.setUrl(tagObj.getString("url"));
tags.add(tag);
}
}
@ -895,7 +895,7 @@ public class API {
status.setApplication(application);
status.setAccount(parseAccountResponse(resobj.getJSONObject("account")));
status.setContent(context, resobj.get("content").toString());
status.setContent(context, resobj.getString("content"));
if (!resobj.isNull("favourites_count")) {
status.setFavourites_count(resobj.getInt("favourites_count"));
} else {
@ -961,15 +961,15 @@ public class API {
private static Status parseSchedule(Context context, JSONObject resobj) {
Status status = new Status();
try {
status.setIn_reply_to_id(resobj.get("in_reply_to_id").toString());
status.setSensitive(Boolean.parseBoolean(resobj.get("sensitive").toString()));
status.setSpoiler_text(resobj.get("spoiler_text").toString());
status.setIn_reply_to_id(resobj.getString("in_reply_to_id"));
status.setSensitive(resobj.getBoolean("sensitive"));
status.setSpoiler_text(resobj.getString("spoiler_text"));
try {
status.setVisibility(resobj.get("visibility").toString());
status.setVisibility(resobj.getString("visibility"));
} catch (Exception e) {
status.setVisibility("public");
}
status.setContent(context, resobj.get("text").toString());
status.setContent(context, resobj.getString("text"));
} catch (JSONException ignored) {
}
return status;
@ -1010,21 +1010,21 @@ public class API {
Status status = new Status();
try {
status.setId(resobj.get("id").toString());
status.setUri("https://" + instance + "/notes/" + resobj.get("id").toString());
status.setCreated_at(Helper.mstStringToDate(resobj.get("createdAt").toString()));
status.setIn_reply_to_id(resobj.get("replyId").toString());
status.setId(resobj.getString("id"));
status.setUri("https://" + instance + "/notes/" + resobj.getString("id"));
status.setCreated_at(Helper.mstStringToDate(resobj.getString("createdAt")));
status.setIn_reply_to_id(resobj.getString("replyId"));
status.setSensitive(false);
resobj.get("cw");
if (!resobj.get("cw").toString().equals("null"))
status.setSpoiler_text(resobj.get("cw").toString());
if (!resobj.getString("cw").equals("null"))
status.setSpoiler_text(resobj.getString("cw"));
try {
status.setVisibility(resobj.get("visibility").toString());
status.setVisibility(resobj.getString("visibility"));
} catch (Exception e) {
status.setVisibility("public");
e.printStackTrace();
}
status.setUrl("https://" + instance + "/notes/" + resobj.get("id").toString());
status.setUrl("https://" + instance + "/notes/" + resobj.getString("id"));
//Retrieves attachments
if (resobj.has("media")) {
JSONArray arrayAttachement = resobj.getJSONArray("media");
@ -1032,20 +1032,20 @@ public class API {
for (int j = 0; j < arrayAttachement.length(); j++) {
JSONObject attObj = arrayAttachement.getJSONObject(j);
Attachment attachment = new Attachment();
attachment.setId(attObj.get("id").toString());
attachment.setPreview_url(attObj.get("thumbnailUrl").toString());
attachment.setRemote_url(attObj.get("url").toString());
if (attObj.get("type").toString().contains("/")) {
attachment.setType(attObj.get("type").toString().split("/")[0]);
attachment.setId(attObj.getString("id"));
attachment.setPreview_url(attObj.getString("thumbnailUrl"));
attachment.setRemote_url(attObj.getString("url"));
if (attObj.getString("type").contains("/")) {
attachment.setType(attObj.getString("type").split("/")[0]);
} else
attachment.setType(attObj.get("type").toString());
attachment.setText_url(attObj.get("url").toString());
attachment.setUrl(attObj.get("url").toString());
if (attObj.get("isSensitive").toString().equals("true")) {
attachment.setType(attObj.getString("type"));
attachment.setText_url(attObj.getString("url"));
attachment.setUrl(attObj.getString("url"));
if (attObj.getString("isSensitive").equals("true")) {
status.setSensitive(true);
}
try {
attachment.setDescription(attObj.get("comment").toString());
attachment.setDescription(attObj.getString("comment"));
} catch (JSONException e) {
e.printStackTrace();
}
@ -1067,7 +1067,7 @@ public class API {
status.setAccount(parseMisskeyAccountResponse(instance, resobj.getJSONObject("user")));
status.setContent(context, resobj.get("text").toString());
status.setContent(context, resobj.getString("text"));
try {
status.setReplies_count(resobj.getInt("repliesCount"));
} catch (Exception e) {
@ -1098,8 +1098,8 @@ public class API {
for (int j = 0; j < arrayTag.length(); j++) {
JSONObject tagObj = arrayTag.getJSONObject(j);
Tag tag = new Tag();
tag.setName(tagObj.get("name").toString());
tag.setUrl(tagObj.get("url").toString());
tag.setName(tagObj.getString("name"));
tag.setUrl(tagObj.getString("url"));
tags.add(tag);
}
}
@ -1146,9 +1146,9 @@ public class API {
private static Emojis parseEmojis(JSONObject resobj) {
Emojis emojis = new Emojis();
try {
emojis.setShortcode(resobj.get("shortcode").toString());
emojis.setStatic_url(resobj.get("static_url").toString());
emojis.setUrl(resobj.get("url").toString());
emojis.setShortcode(resobj.getString("shortcode"));
emojis.setStatic_url(resobj.getString("static_url"));
emojis.setUrl(resobj.getString("url"));
try {
emojis.setVisible_in_picker((resobj.getBoolean("visible_in_picker")));
} catch (Exception e) {
@ -1168,9 +1168,9 @@ public class API {
private static Emojis parseMisskeyEmojis(JSONObject resobj) {
Emojis emojis = new Emojis();
try {
emojis.setShortcode(resobj.get("name").toString());
emojis.setStatic_url(resobj.get("url").toString());
emojis.setUrl(resobj.get("url").toString());
emojis.setShortcode(resobj.getString("name"));
emojis.setStatic_url(resobj.getString("url"));
emojis.setUrl(resobj.getString("url"));
} catch (Exception ignored) {
}
return emojis;
@ -1185,8 +1185,8 @@ public class API {
private static app.fedilab.android.client.Entities.List parseList(JSONObject resobj) {
app.fedilab.android.client.Entities.List list = new app.fedilab.android.client.Entities.List();
try {
list.setId(resobj.get("id").toString());
list.setTitle(resobj.get("title").toString());
list.setId(resobj.getString("id"));
list.setTitle(resobj.getString("title"));
} catch (Exception ignored) {
}
return list;
@ -1201,13 +1201,13 @@ public class API {
private static Account parseAccountResponsePeertube(String instance, JSONObject resobj) {
Account account = new Account();
try {
account.setId(resobj.get("id").toString());
account.setUsername(resobj.get("name").toString());
account.setAcct(resobj.get("name").toString() + "@" + resobj.get("host").toString());
account.setDisplay_name(resobj.get("displayName").toString());
account.setHost(resobj.get("host").toString());
account.setId(resobj.getString("id"));
account.setUsername(resobj.getString("name"));
account.setAcct(resobj.getString("name") + "@" + resobj.getString("host"));
account.setDisplay_name(resobj.getString("displayName"));
account.setHost(resobj.getString("host"));
if (resobj.has("createdAt"))
account.setCreated_at(Helper.mstStringToDate(resobj.get("createdAt").toString()));
account.setCreated_at(Helper.mstStringToDate(resobj.getString("createdAt")));
else
account.setCreated_at(new Date());
@ -1221,17 +1221,17 @@ public class API {
account.setFollowing_count(0);
account.setStatuses_count(0);
if (resobj.has("description"))
account.setNote(resobj.get("description").toString());
account.setNote(resobj.getString("description"));
else
account.setNote("");
account.setUrl(resobj.get("url").toString());
account.setUrl(resobj.getString("url"));
account.setSocial("PEERTUBE");
if (resobj.has("avatar") && !resobj.get("avatar").toString().equals("null")) {
if (resobj.has("avatar") && !resobj.getString("avatar").equals("null")) {
account.setAvatar("https://" + instance + resobj.getJSONObject("avatar").get("path"));
account.setAvatar_static("https://" + instance + resobj.getJSONObject("avatar").get("path"));
} else
account.setAvatar(null);
account.setAvatar_static(resobj.get("avatar").toString());
account.setAvatar_static(resobj.getString("avatar"));
} catch (JSONException ignored) {
} catch (ParseException e) {
e.printStackTrace();
@ -1318,7 +1318,7 @@ public class API {
AccountAdmin accountAdmin = new AccountAdmin();
try {
accountAdmin.setId(resobj.get("id").toString());
accountAdmin.setId(resobj.getString("id"));
if (!resobj.isNull("username")) {
accountAdmin.setUsername(resobj.getString("username"));
}
@ -1417,17 +1417,17 @@ public class API {
Account account = new Account();
try {
account.setId(resobj.get("id").toString());
account.setUuid(resobj.get("id").toString());
account.setUsername(resobj.get("username").toString());
account.setAcct(resobj.get("acct").toString());
account.setDisplay_name(resobj.get("display_name").toString());
account.setId(resobj.getString("id"));
account.setUuid(resobj.getString("id"));
account.setUsername(resobj.getString("username"));
account.setAcct(resobj.getString("acct"));
account.setDisplay_name(resobj.getString("display_name"));
if (account.getDisplay_name() == null || account.getDisplay_name().compareTo("") == 0) {
account.setDisplay_name(resobj.get("username").toString());
account.setDisplay_name(resobj.getString("username"));
}
account.setLocked(Boolean.parseBoolean(resobj.get("locked").toString()));
account.setLocked(resobj.getBoolean("locked"));
if (resobj.has("created_at") && !resobj.isNull("created_at")) {
account.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
account.setCreated_at(Helper.mstStringToDate(resobj.getString("created_at")));
} else {
account.setCreated_at(new Date());
}
@ -1446,9 +1446,9 @@ public class API {
} else {
account.setStatuses_count(0);
}
account.setNote(resobj.get("note").toString());
account.setNote(resobj.getString("note"));
try {
account.setBot(Boolean.parseBoolean(resobj.get("bot").toString()));
account.setBot(resobj.getBoolean("bot"));
} catch (Exception e) {
account.setBot(false);
}
@ -1459,11 +1459,11 @@ public class API {
} catch (Exception ignored) {
account.setMoved_to_account(null);
}
account.setUrl(resobj.get("url").toString());
account.setAvatar(resobj.get("avatar").toString());
account.setAvatar_static(resobj.get("avatar_static").toString());
account.setHeader(resobj.get("header").toString());
account.setHeader_static(resobj.get("header_static").toString());
account.setUrl(resobj.getString("url"));
account.setAvatar(resobj.getString("avatar"));
account.setAvatar_static(resobj.getString("avatar_static"));
account.setHeader(resobj.getString("header"));
account.setHeader_static(resobj.getString("header_static"));
try {
if (resobj.has("pleroma")) {
account.setSocial("PLEROMA");
@ -1552,25 +1552,25 @@ public class API {
Account account = new Account();
try {
account.setId(resobj.get("id").toString());
account.setUsername(resobj.get("username").toString());
account.setId(resobj.getString("id"));
account.setUsername(resobj.getString("username"));
String host;
String acct;
if (resobj.isNull("host")) {
acct = resobj.get("username").toString();
acct = resobj.getString("username");
} else {
host = resobj.get("host").toString();
acct = resobj.get("username").toString() + "@" + host;
host = resobj.getString("host");
acct = resobj.getString("username") + "@" + host;
}
account.setAcct(acct);
account.setDisplay_name(resobj.get("name").toString());
account.setDisplay_name(resobj.getString("name"));
account.setCreated_at(new Date());
account.setUrl("https://" + instance + "/@" + account.getUsername());
account.setAvatar(resobj.get("avatarUrl").toString());
account.setAvatar_static(resobj.get("avatarUrl").toString());
account.setAvatar(resobj.getString("avatarUrl"));
account.setAvatar_static(resobj.getString("avatarUrl"));
try {
account.setBot(Boolean.parseBoolean(resobj.get("isBot").toString()));
account.setBot(resobj.getBoolean("isBot"));
} catch (Exception e) {
account.setBot(false);
}
@ -1623,27 +1623,27 @@ public class API {
Attachment attachment = new Attachment();
try {
attachment.setId(resobj.get("id").toString());
attachment.setType(resobj.get("type").toString());
attachment.setUrl(resobj.get("url").toString());
attachment.setId(resobj.getString("id"));
attachment.setType(resobj.getString("type"));
attachment.setUrl(resobj.getString("url"));
try {
attachment.setDescription(resobj.get("description").toString());
attachment.setDescription(resobj.getString("description"));
} catch (JSONException ignore) {
}
try {
attachment.setRemote_url(resobj.get("remote_url").toString());
attachment.setRemote_url(resobj.getString("remote_url"));
} catch (JSONException ignore) {
}
try {
attachment.setPreview_url(resobj.get("preview_url").toString());
attachment.setPreview_url(resobj.getString("preview_url"));
} catch (JSONException ignore) {
}
try {
attachment.setMeta(resobj.get("meta").toString());
attachment.setMeta(resobj.getString("meta"));
} catch (JSONException ignore) {
}
try {
attachment.setText_url(resobj.get("text_url").toString());
attachment.setText_url(resobj.getString("text_url"));
} catch (JSONException ignore) {
}
@ -1663,9 +1663,9 @@ public class API {
Notification notification = new Notification();
try {
notification.setId(resobj.get("id").toString());
notification.setType(resobj.get("type").toString());
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
notification.setId(resobj.getString("id"));
notification.setType(resobj.getString("type"));
notification.setCreated_at(Helper.mstStringToDate(resobj.getString("created_at")));
notification.setAccount(parseAccountResponse(resobj.getJSONObject("account")));
if (resobj.has("status")) {
try {
@ -1673,7 +1673,7 @@ public class API {
} catch (Exception ignored) {
}
}
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
notification.setCreated_at(Helper.mstStringToDate(resobj.getString("created_at")));
} catch (JSONException ignored) {
} catch (ParseException e) {
e.printStackTrace();
@ -2582,9 +2582,9 @@ public class API {
try {
String response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/oauth/token"), 10, params, null);
JSONObject resobj = new JSONObject(response);
String token = resobj.get("access_token").toString();
String token = resobj.getString("access_token");
if (resobj.has("refresh_token"))
refresh_token = resobj.get("refresh_token").toString();
refresh_token = resobj.getString("refresh_token");
newValues.put("access_token", token);
newValues.put("refresh_token", refresh_token);
@ -5717,8 +5717,8 @@ public class API {
private Conversation parseConversation(Context context, JSONObject resobj) {
Conversation conversation = new Conversation();
try {
conversation.setId(resobj.get("id").toString());
conversation.setUnread(Boolean.parseBoolean(resobj.get("unread").toString()));
conversation.setId(resobj.getString("id"));
conversation.setUnread(resobj.getBoolean("unread"));
conversation.setAccounts(parseAccountResponse(resobj.getJSONArray("accounts")));
conversation.setLast_status(parseStatuses(context, resobj.getJSONObject("last_status")));
} catch (JSONException ignored) {
@ -5766,11 +5766,11 @@ public class API {
Instance instance = new Instance();
try {
instance.setUri(resobj.get("uri").toString());
instance.setTitle(resobj.get("title").toString());
instance.setDescription(resobj.get("description").toString());
instance.setEmail(resobj.get("email").toString());
instance.setVersion(resobj.get("version").toString());
instance.setUri(resobj.getString("uri"));
instance.setTitle(resobj.getString("title"));
instance.setDescription(resobj.getString("description"));
instance.setEmail(resobj.getString("email"));
instance.setVersion(resobj.getString("version"));
if (resobj.has("registrations")) {
instance.setRegistration(resobj.getBoolean("registrations"));
} else {
@ -5916,14 +5916,14 @@ public class API {
Filters filter = new Filters();
try {
filter.setId(resobj.get("id").toString());
filter.setPhrase(resobj.get("phrase").toString());
filter.setId(resobj.getString("id"));
filter.setPhrase(resobj.getString("phrase"));
resobj.get("expires_at");
if (!resobj.get("expires_at").toString().equals("null"))
filter.setSetExpires_at(Helper.mstStringToDate(resobj.get("expires_at").toString()));
filter.setWhole_word(Boolean.parseBoolean(resobj.get("whole_word").toString()));
filter.setIrreversible(Boolean.parseBoolean(resobj.get("irreversible").toString()));
String contextString = resobj.get("context").toString();
if (!resobj.getString("expires_at").equals("null"))
filter.setSetExpires_at(Helper.mstStringToDate(resobj.getString("expires_at")));
filter.setWhole_word(resobj.getBoolean("whole_word"));
filter.setIrreversible(resobj.getBoolean("irreversible"));
String contextString = resobj.getString("context");
contextString = contextString.replaceAll("\\[", "");
contextString = contextString.replaceAll("]", "");
contextString = contextString.replaceAll("\"", "");
@ -6058,7 +6058,7 @@ public class API {
Relationship relationship = new Relationship();
try {
relationship.setId(resobj.get("id").toString());
relationship.setId(resobj.getString("id"));
relationship.setFollowing(resobj.getBoolean("following"));
relationship.setFollowed_by(resobj.getBoolean("followed_by"));
relationship.setBlocking(resobj.getBoolean("blocking"));
@ -6167,7 +6167,7 @@ public class API {
String message = statusCode + " - " + error.getMessage();
try {
JSONObject jsonObject = new JSONObject(Objects.requireNonNull(error.getMessage()));
String errorM = jsonObject.get("error").toString();
String errorM = jsonObject.getString("error");
message = "Error " + statusCode + " : " + errorM;
} catch (JSONException e) {
if (error.getMessage().split(".").length > 0) {