diff options
author | tom79 <tschneider.ac@gmail.com> | 2020-03-08 11:19:23 +0100 |
---|---|---|
committer | tom79 <tschneider.ac@gmail.com> | 2020-03-08 11:19:23 +0100 |
commit | d3bb1ad93f3f1626fbd490c5e244e32832646926 (patch) | |
tree | cd2385dcf70e831a1aa79971b41725e450b22a80 | |
parent | d65fb252283752c43aefab7d2ce392f80a3957f4 (diff) |
Cleanup API Class
-rw-r--r-- | app/src/main/java/app/fedilab/android/client/API.java | 1064 |
1 files changed, 231 insertions, 833 deletions
diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index e3d7367fd..4af1e9b8c 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -57,7 +57,6 @@ import java.util.regex.Pattern; import app.fedilab.android.R; import app.fedilab.android.activities.MainActivity; -import app.fedilab.android.asynctasks.RetrieveOpenCollectiveAsyncTask; import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask; import app.fedilab.android.client.Entities.Account; import app.fedilab.android.client.Entities.AccountAdmin; @@ -113,7 +112,6 @@ public class API { private Attachment attachment; private List<Account> accounts; private List<Status> statuses; - private List<Conversation> conversations; private int tootPerPage, accountPerPage, notificationPerPage; private int actionCode; private String instance; @@ -415,9 +413,7 @@ public class API { i++; statuses.add(status); } - } catch (JSONException e) { - e.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } return statuses; @@ -429,7 +425,7 @@ public class API { * @param resobj JSONObject * @return HowToVideo */ - private static HowToVideo parseHowTo(Context context, JSONObject resobj) { + private static HowToVideo parseHowTo(JSONObject resobj) { HowToVideo howToVideo = new HowToVideo(); try { howToVideo.setId(resobj.get("id").toString()); @@ -463,9 +459,7 @@ public class API { schedule.setAttachmentList(attachements); schedule.setId(jsonObject.get("id").toString()); schedule.setScheduled_at(Helper.mstStringToDate(context, jsonObject.get("scheduled_at").toString())); - } catch (JSONException e) { - e.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } return schedule; @@ -495,9 +489,7 @@ public class API { schedule.setScheduled_at(Helper.mstStringToDate(context, jsonArray.getJSONObject(i).get("scheduled_at").toString())); i++; } - } catch (JSONException e) { - e.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } return schedules; @@ -519,9 +511,7 @@ public class API { JSONObject resobj = jsonArray.getJSONObject(i); Status status = parseStatuses(context, resobj); i++; - if (status != null) { - statuses.add(status); - } + statuses.add(status); } } catch (JSONException e) { @@ -532,10 +522,9 @@ public class API { /** * Parse a poll - * - * @param context - * @param resobj - * @return + * @param context Context + * @param resobj JSONObject + * @return Poll */ private static Poll parsePoll(Context context, JSONObject resobj) { Poll poll = new Poll(); @@ -608,22 +597,20 @@ public class API { if (resobj.has("media_attachments")) { JSONArray arrayAttachement = resobj.getJSONArray("media_attachments"); - if (arrayAttachement != null) { - 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()); - try { - attachment.setDescription(attObj.get("description").toString()); - } catch (JSONException ignore) { - } - attachments.add(attachment); + 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()); + try { + attachment.setDescription(attObj.get("description").toString()); + } catch (JSONException ignore) { } + attachments.add(attachment); } } try { @@ -636,41 +623,35 @@ public class API { //Retrieves mentions List<Mention> mentions = new ArrayList<>(); JSONArray arrayMention = resobj.getJSONArray("mentions"); - if (arrayMention != null) { - 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()); - mentions.add(mention); - } + 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()); + mentions.add(mention); } status.setMentions(mentions); //Retrieves tags List<Tag> tags = new ArrayList<>(); JSONArray arrayTag = resobj.getJSONArray("tags"); - if (arrayTag != null) { - 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()); - tags.add(tag); - } + 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()); + tags.add(tag); } status.setTags(tags); //Retrieves emjis List<Emojis> emojiList = new ArrayList<>(); try { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseEmojis(emojisObj); + emojiList.add(emojis); } status.setEmojis(emojiList); } catch (Exception e) { @@ -679,10 +660,9 @@ public class API { //Retrieve Application Application application = new Application(); try { - if (resobj.getJSONObject("application") != null) { - application.setName(resobj.getJSONObject("application").getString("name")); - application.setWebsite(resobj.getJSONObject("application").getString("website")); - } + resobj.getJSONObject("application"); + application.setName(resobj.getJSONObject("application").getString("name")); + application.setWebsite(resobj.getJSONObject("application").getString("website")); } catch (Exception e) { application = new Application(); } @@ -691,38 +671,38 @@ public class API { status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account"))); status.setContent(context, resobj.get("content").toString()); if (!resobj.isNull("favourites_count")) { - status.setFavourites_count(Integer.valueOf(resobj.get("favourites_count").toString())); + status.setFavourites_count(resobj.getInt("favourites_count")); } else { status.setFavourites_count(0); } if (!resobj.isNull("reblogs_count")) { - status.setReblogs_count(Integer.valueOf(resobj.get("reblogs_count").toString())); + status.setReblogs_count(resobj.getInt("reblogs_count")); } else { status.setReblogs_count(0); } try { - status.setReplies_count(Integer.valueOf(resobj.get("replies_count").toString())); + status.setReplies_count(resobj.getInt("replies_count")); } catch (Exception e) { status.setReplies_count(-1); } try { - status.setReblogged(Boolean.valueOf(resobj.get("reblogged").toString())); + status.setReblogged(resobj.getBoolean("reblogged")); } catch (Exception e) { status.setReblogged(false); } try { - status.setFavourited(Boolean.valueOf(resobj.get("favourited").toString())); + status.setFavourited(resobj.getBoolean("favourited")); } catch (Exception e) { status.setFavourited(false); } try { - status.setMuted(Boolean.valueOf(resobj.get("muted").toString())); + status.setMuted(resobj.getBoolean("muted")); } catch (Exception e) { status.setMuted(false); } try { - status.setPinned(Boolean.valueOf(resobj.get("pinned").toString())); + status.setPinned(resobj.getBoolean("pinned")); } catch (JSONException e) { status.setPinned(false); } @@ -761,9 +741,7 @@ public class API { status.setPoll(poll); } - } catch (JSONException ignored) { - ignored.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } status.setViewType(context); @@ -776,7 +754,6 @@ public class API { * @param resobj JSONObject * @return Status */ - @SuppressWarnings("InfiniteRecursion") private static Status parseSchedule(Context context, JSONObject resobj) { Status status = new Status(); try { @@ -800,7 +777,7 @@ public class API { * @param jsonArray JSONArray * @return List<Status> */ - public static List<Status> parseNotes(Context context, String instance, JSONArray jsonArray) { + private static List<Status> parseNotes(Context context, String instance, JSONArray jsonArray) { List<Status> statuses = new ArrayList<>(); try { @@ -825,8 +802,7 @@ public class API { * @param resobj JSONObject * @return Status */ - @SuppressWarnings("InfiniteRecursion") - public static Status parseNotes(Context context, String instance, JSONObject resobj) { + private static Status parseNotes(Context context, String instance, JSONObject resobj) { Status status = new Status(); try { @@ -835,7 +811,8 @@ public class API { status.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString())); status.setIn_reply_to_id(resobj.get("replyId").toString()); status.setSensitive(false); - if (resobj.get("cw") != null && !resobj.get("cw").toString().equals("null")) + resobj.get("cw"); + if (!resobj.get("cw").toString().equals("null")) status.setSpoiler_text(resobj.get("cw").toString()); try { status.setVisibility(resobj.get("visibility").toString()); @@ -848,29 +825,27 @@ public class API { if (resobj.has("media")) { JSONArray arrayAttachement = resobj.getJSONArray("media"); ArrayList<Attachment> attachments = new ArrayList<>(); - if (arrayAttachement != null) { - 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]); - } 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")) { - status.setSensitive(true); - } - try { - attachment.setDescription(attObj.get("comment").toString()); - } catch (JSONException ignore) { - ignore.printStackTrace(); - } - attachments.add(attachment); + 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]); + } 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")) { + status.setSensitive(true); + } + try { + attachment.setDescription(attObj.get("comment").toString()); + } catch (JSONException e) { + e.printStackTrace(); } + attachments.add(attachment); } status.setMedia_attachments(attachments); } else { @@ -886,16 +861,16 @@ public class API { //Retrieves mentions List<Mention> mentions = new ArrayList<>(); - status.setAccount(parseMisskeyAccountResponse(context, instance, resobj.getJSONObject("user"))); + status.setAccount(parseMisskeyAccountResponse(instance, resobj.getJSONObject("user"))); status.setContent(context, resobj.get("text").toString()); try { - status.setReplies_count(Integer.valueOf(resobj.get("repliesCount").toString())); + status.setReplies_count(resobj.getInt("repliesCount")); } catch (Exception e) { status.setReplies_count(-1); } try { - status.setFavourited(Boolean.valueOf(resobj.get("isFavorited").toString())); + status.setFavourited(resobj.getBoolean("isFavorited")); } catch (Exception e) { status.setFavourited(false); } @@ -905,7 +880,8 @@ public class API { status.setBookmarked(false); } try { - if (resobj.getJSONObject("renoteId") != null && !resobj.getJSONObject("renoteId").toString().equals("null")) + resobj.getJSONObject("renoteId"); + if (!resobj.getJSONObject("renoteId").toString().equals("null")) status.setReblog(parseStatuses(context, resobj.getJSONObject("renote"))); } catch (Exception ignored) { } @@ -915,14 +891,12 @@ public class API { List<Tag> tags = new ArrayList<>(); if (resobj.has("tags")) { JSONArray arrayTag = resobj.getJSONArray("tags"); - if (arrayTag != null) { - 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()); - tags.add(tag); - } + 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()); + tags.add(tag); } } status.setTags(tags); @@ -931,12 +905,10 @@ public class API { List<Emojis> emojiList = new ArrayList<>(); if (resobj.has("emojis")) { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseMisskeyEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseMisskeyEmojis(emojisObj); + emojiList.add(emojis); } status.setEmojis(emojiList); } @@ -944,10 +916,9 @@ public class API { //Retrieve Application Application application = new Application(); try { - if (resobj.getJSONObject("application") != null) { - application.setName(resobj.getJSONObject("application").getString("name")); - application.setWebsite(resobj.getJSONObject("application").getString("website")); - } + resobj.getJSONObject("application"); + application.setName(resobj.getJSONObject("application").getString("name")); + application.setWebsite(resobj.getJSONObject("application").getString("website")); } catch (Exception e) { application = new Application(); } @@ -1036,11 +1007,11 @@ public class API { account.setCreated_at(new Date()); if (resobj.has("followersCount")) - account.setFollowers_count(Integer.valueOf(resobj.get("followersCount").toString())); + account.setFollowers_count(resobj.getInt("followersCount")); else account.setFollowers_count(0); if (resobj.has("followingCount")) - account.setFollowing_count(Integer.valueOf(resobj.get("followingCount").toString())); + account.setFollowing_count(resobj.getInt("followingCount")); else account.setFollowing_count(0); account.setStatuses_count(0); @@ -1125,8 +1096,8 @@ public class API { report.setAction_taken_by_account(parseAccountAdminResponse(context, resobj.getJSONObject("action_taken_by_account"))); } report.setStatuses(parseStatuses(context, resobj.getJSONArray("statuses"))); - } catch (Exception ignored) { - ignored.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } return report; } @@ -1212,8 +1183,8 @@ public class API { } else { accountAdmin.setApproved(true); } - } catch (Exception ignored) { - ignored.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } return accountAdmin; } @@ -1241,17 +1212,17 @@ public class API { account.setCreated_at(new Date()); } if (!resobj.isNull("followers_count")) { - account.setFollowers_count(Integer.valueOf(resobj.get("followers_count").toString())); + account.setFollowers_count(resobj.getInt("followers_count")); } else { account.setFollowers_count(0); } if (!resobj.isNull("following_count")) { - account.setFollowing_count(Integer.valueOf(resobj.get("following_count").toString())); + account.setFollowing_count(resobj.getInt("following_count")); } else { account.setFollowing_count(0); } if (!resobj.isNull("statuses_count")) { - account.setStatuses_count(Integer.valueOf(resobj.get("statuses_count").toString())); + account.setStatuses_count(resobj.getInt("statuses_count")); } else { account.setStatuses_count(0); } @@ -1289,16 +1260,15 @@ public class API { JSONArray fields = resobj.getJSONArray("fields"); LinkedHashMap<String, String> fieldsMap = new LinkedHashMap<>(); LinkedHashMap<String, Boolean> fieldsMapVerified = new LinkedHashMap<>(); - if (fields != null) { - for (int j = 0; j < fields.length(); j++) { - fieldsMap.put(fields.getJSONObject(j).getString("name"), fields.getJSONObject(j).getString("value")); - try { - fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), (fields.getJSONObject(j).getString("verified_at") != null && !fields.getJSONObject(j).getString("verified_at").equals("null"))); - } catch (Exception e) { - fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), false); - } - + for (int j = 0; j < fields.length(); j++) { + fieldsMap.put(fields.getJSONObject(j).getString("name"), fields.getJSONObject(j).getString("value")); + try { + fields.getJSONObject(j).getString("verified_at"); + fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), !fields.getJSONObject(j).getString("verified_at").equals("null")); + } catch (Exception e) { + fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), false); } + } account.setFields(fieldsMap); account.setFieldsVerified(fieldsMapVerified); @@ -1310,12 +1280,10 @@ public class API { List<Emojis> emojiList = new ArrayList<>(); try { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseEmojis(emojisObj); + emojiList.add(emojis); } account.setEmojis(emojiList); } catch (Exception e) { @@ -1347,48 +1315,6 @@ public class API { return account; } - /** - * Parse json response an unique account - * - * @param resobj JSONObject - * @return Account - */ - @SuppressWarnings("InfiniteRecursion") - private static Account parseOpencollectiveAccountResponse(Context context, RetrieveOpenCollectiveAsyncTask.Type type, JSONObject resobj) { - - Account account = new Account(); - try { - account.setId(resobj.get("MemberId").toString()); - account.setUuid(resobj.get("MemberId").toString()); - account.setUsername(resobj.get("name").toString()); - account.setAcct(resobj.get("tier").toString()); - account.setDisplay_name(resobj.get("name").toString()); - account.setLocked(false); - account.setCreated_at(Helper.opencollectivetStringToDate(context, resobj.get("createdAt").toString())); - account.setFollowers_count(0); - account.setFollowing_count(0); - account.setStatuses_count(0); - account.setNote(resobj.get("description").toString()); - account.setBot(false); - account.setMoved_to_account(null); - account.setUrl(resobj.get("profile").toString()); - account.setAvatar(resobj.get("image").toString()); - account.setAvatar_static(resobj.get("image").toString()); - account.setHeader(null); - account.setHeader_static(null); - if (resobj.get("role").toString().equals("BACKER")) - account.setSocial("OPENCOLLECTIVE_BACKER"); - else if (resobj.get("role").toString().equals("SPONSOR")) - account.setSocial("OPENCOLLECTIVE_SPONSOR"); - else - account.setSocial("OPENCOLLECTIVE"); - - } catch (JSONException ignored) { - } catch (ParseException e) { - e.printStackTrace(); - } - return account; - } /** * Parse json response an unique account @@ -1396,14 +1322,13 @@ public class API { * @param resobj JSONObject * @return Account */ - @SuppressWarnings("InfiniteRecursion") - private static Account parseMisskeyAccountResponse(Context context, String instance, JSONObject resobj) { + private static Account parseMisskeyAccountResponse(String instance, JSONObject resobj) { Account account = new Account(); try { account.setId(resobj.get("id").toString()); account.setUsername(resobj.get("username").toString()); - String host = null; + String host; String acct; if (resobj.isNull("host")) { acct = resobj.get("username").toString(); @@ -1427,17 +1352,15 @@ public class API { List<Emojis> emojiList = new ArrayList<>(); if (resobj.has("emojis")) { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseEmojis(emojisObj); + emojiList.add(emojis); } } account.setEmojis(emojiList); - } catch (JSONException ignored) { - ignored.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); } return account; } @@ -1611,7 +1534,7 @@ public class API { if (eventType == XmlPullParser.TEXT && status != null) { if (xpp.getText() != null) { try { - DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); Date date = formatter.parse(xpp.getText()); status.setCreated_at(date); } catch (ParseException e) { @@ -1626,12 +1549,9 @@ public class API { String description = xpp.getText(); Pattern imgPattern = Pattern.compile("<img [^>]*src=\"([^\"]+)\"[^>]*>"); Matcher matcher = imgPattern.matcher(description); - List<String> imgs = new ArrayList<>(); - int i = 1; ArrayList<Attachment> attachments = new ArrayList<>(); while (matcher.find()) { description = description.replaceAll(Pattern.quote(matcher.group()), ""); - imgs.add("[media_" + i + "]|" + matcher.group(1)); Attachment attachment = new Attachment(); attachment.setType("image"); attachment.setDescription(""); @@ -1691,9 +1611,7 @@ public class API { JSONObject resobj = jsonArray.getJSONObject(i); IdentityProof identityProof = parseIdentityProof(context, resobj); i++; - if (identityProof != null) { - identityProofs.add(identityProof); - } + identityProofs.add(identityProof); } } catch (JSONException e) { @@ -1766,8 +1684,7 @@ public class API { } else { try { id = URLEncoder.encode(id, "UTF-8"); - } catch (UnsupportedEncodingException e) { - } + } catch (UnsupportedEncodingException ignored) {} params = new HashMap<>(); params.put("query", id); endpoint = "/admin/users"; @@ -1826,7 +1743,7 @@ public class API { if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { accountAdmins = parseAccountAdminResponse(new JSONArray(response)); - if (accountAdmins != null && accountAdmins.size() > 0) { + if (accountAdmins.size() > 0) { Account accountpleroma = getAccount(accountAdmins.get(0).getId()); if (accountpleroma != null) { accountAdmins.get(0).setAccount(accountpleroma); @@ -1850,17 +1767,11 @@ public class API { apiResponse.setReports(reports); break; } - } catch (IOException e) { - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e) { e.printStackTrace(); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); } return apiResponse; } @@ -1987,15 +1898,19 @@ public class API { String response = null; switch (http_action) { case "POST": + assert url_action != null; response = new HttpsConnection(context, this.instance).post(url_action, 10, params, prefKeyOauthTokenT); break; case "PATCH": - response = new HttpsConnection(context, this.instance).patch(url_action, 10, params, null, null, null, null, prefKeyOauthTokenT); + assert url_action != null; + response = new HttpsConnection(context, this.instance).patch(url_action, 10, null, null, null, null, null, prefKeyOauthTokenT); break; case "PUT": + assert url_action != null; response = new HttpsConnection(context, this.instance).put(url_action, 10, params, prefKeyOauthTokenT); break; case "DELETE": + assert url_action != null; new HttpsConnection(context, this.instance).delete(url_action, 10, params, prefKeyOauthTokenT); break; } @@ -2104,14 +2019,13 @@ public class API { response = new HttpsConnection(context, this.instance).get(nodeInfo.getHref(), 30, null, null); JSONObject resobj = new JSONObject(response); JSONObject jsonObject = resobj.getJSONObject("software"); - String name = null; - name = jsonObject.getString("name").toUpperCase(); + String name = jsonObject.getString("name").toUpperCase(); instanceNodeInfo.setName(name); instanceNodeInfo.setVersion(jsonObject.getString("version")); instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations")); } } catch (JSONException e) { - + e.printStackTrace(); } } catch (IOException | JSONException | NoSuchAlgorithmException | KeyManagementException e) { e.printStackTrace(); @@ -2347,11 +2261,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { e.printStackTrace(); setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return apiResponse; @@ -2447,15 +2357,7 @@ public class API { newValues.put("access_token", token); newValues.put("refresh_token", refresh_token); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } catch (HttpsConnection.HttpsConnectionException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) { e.printStackTrace(); } return newValues; @@ -2489,48 +2391,12 @@ public class API { params.put("password", accountCreation.getPassword()); params.put("agreement", "true"); params.put("locale", Locale.getDefault().getLanguage()); - response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/accounts"), 30, params, app_token); - - /*res = new JSONObject(response); - String access_token = res.getString("access_token"); - prefKeyOauthTokenT = access_token; - - response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, prefKeyOauthTokenT); - account = parseAccountResponse(context, new JSONObject(response)); - if( account.getSocial().equals("PLEROMA")){ - isPleromaAdmin(account.getAcct()); - } - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - account.setToken(access_token); - account.setClient_id(client_id); - account.setClient_secret(client_secret); - account.setRefresh_token(null); - account.setInstance(instance); - SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - boolean userExists = new AccountDAO(context, db).userExist(account); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.PREF_KEY_ID, account.getId()); - editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); - editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); - editor.putString(Helper.PREF_INSTANCE, instance); - editor.apply(); - if( userExists) - new AccountDAO(context, db).updateAccountCredential(account); - else { - if( account.getUsername() != null && account.getCreated_at() != null) - new AccountDAO(context, db).insertAccount(account); - }*/ - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + new HttpsConnection(context, t |