Some fixes
This commit is contained in:
parent
87c0fcfd1b
commit
bf9b3a6fac
|
@ -2380,11 +2380,11 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
}
|
||||
final NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
if( navigationView == null) {
|
||||
if (navigationView == null) {
|
||||
return;
|
||||
}
|
||||
MenuItem item = navigationView.getMenu().findItem(R.id.nav_announcements);
|
||||
if( item == null || item.getActionView() == null) {
|
||||
if (item == null || item.getActionView() == null) {
|
||||
return;
|
||||
}
|
||||
TextView actionView = item.getActionView().findViewById(R.id.counter);
|
||||
|
|
|
@ -690,11 +690,10 @@ public class API {
|
|||
/**
|
||||
* Parse a poll
|
||||
*
|
||||
* @param context Context
|
||||
* @param resobj JSONObject
|
||||
* @param resobj JSONObject
|
||||
* @return Poll
|
||||
*/
|
||||
private static Poll parsePoll(Context context, JSONObject resobj) {
|
||||
private static Poll parsePoll(JSONObject resobj) {
|
||||
Poll poll = new Poll();
|
||||
try {
|
||||
poll.setId(resobj.getString("id"));
|
||||
|
@ -743,6 +742,7 @@ public class API {
|
|||
return poll;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response for unique status
|
||||
*
|
||||
|
@ -750,6 +750,18 @@ public class API {
|
|||
* @return Status
|
||||
*/
|
||||
public static Status parseStatuses(Context context, JSONObject resobj) {
|
||||
return parseStatuses(context, resobj, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for unique status
|
||||
*
|
||||
* @param context Context
|
||||
* @param resobj JSONObject
|
||||
* @param recursive boolean
|
||||
* @return Status
|
||||
*/
|
||||
private static Status parseStatuses(Context context, JSONObject resobj, boolean recursive) {
|
||||
Status status = new Status();
|
||||
try {
|
||||
status.setId(resobj.get("id").toString());
|
||||
|
@ -882,7 +894,7 @@ public class API {
|
|||
}
|
||||
status.setApplication(application);
|
||||
|
||||
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
|
||||
status.setAccount(parseAccountResponse(resobj.getJSONObject("account")));
|
||||
status.setContent(context, resobj.get("content").toString());
|
||||
if (!resobj.isNull("favourites_count")) {
|
||||
status.setFavourites_count(resobj.getInt("favourites_count"));
|
||||
|
@ -921,12 +933,14 @@ public class API {
|
|||
status.setPinned(false);
|
||||
}
|
||||
try {
|
||||
status.setReblog(parseStatuses(context, resobj.getJSONObject("reblog")));
|
||||
if (recursive) {
|
||||
status.setReblog(parseStatuses(context, resobj.getJSONObject("reblog"), false));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
if (resobj.has("poll") && !resobj.isNull("poll")) {
|
||||
Poll poll = parsePoll(context, resobj.getJSONObject("poll"));
|
||||
Poll poll = parsePoll(resobj.getJSONObject("poll"));
|
||||
status.setPoll(poll);
|
||||
}
|
||||
|
||||
|
@ -1254,18 +1268,18 @@ public class API {
|
|||
}
|
||||
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
|
||||
if (!resobj.isNull("account")) {
|
||||
report.setAccount(parseAccountAdminResponse(context, resobj.getJSONObject("account")));
|
||||
report.setAccount(parseAccountAdminResponse(resobj.getJSONObject("account")));
|
||||
}
|
||||
if (!resobj.isNull("target_account")) {
|
||||
report.setTarget_account(parseAccountAdminResponse(context, resobj.getJSONObject("target_account")));
|
||||
report.setTarget_account(parseAccountAdminResponse(resobj.getJSONObject("target_account")));
|
||||
}
|
||||
if (!resobj.isNull("assigned_account")) {
|
||||
report.setAssigned_account(parseAccountAdminResponse(context, resobj.getJSONObject("assigned_account")));
|
||||
report.setAssigned_account(parseAccountAdminResponse(resobj.getJSONObject("assigned_account")));
|
||||
}
|
||||
} else if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
|
||||
|
||||
if (!resobj.isNull("account")) {
|
||||
Account account = parseAccountResponse(context, resobj.getJSONObject("account"));
|
||||
Account account = parseAccountResponse(resobj.getJSONObject("account"));
|
||||
AccountAdmin accountAdmin = new AccountAdmin();
|
||||
accountAdmin.setId(account.getId());
|
||||
accountAdmin.setUsername(account.getAcct());
|
||||
|
@ -1274,7 +1288,7 @@ public class API {
|
|||
}
|
||||
|
||||
if (!resobj.isNull("actor")) {
|
||||
Account account = parseAccountResponse(context, resobj.getJSONObject("actor"));
|
||||
Account account = parseAccountResponse(resobj.getJSONObject("actor"));
|
||||
AccountAdmin accountAdmin = new AccountAdmin();
|
||||
accountAdmin.setId(account.getId());
|
||||
accountAdmin.setUsername(account.getAcct());
|
||||
|
@ -1285,7 +1299,7 @@ public class API {
|
|||
}
|
||||
|
||||
if (!resobj.isNull("action_taken_by_account")) {
|
||||
report.setAction_taken_by_account(parseAccountAdminResponse(context, resobj.getJSONObject("action_taken_by_account")));
|
||||
report.setAction_taken_by_account(parseAccountAdminResponse(resobj.getJSONObject("action_taken_by_account")));
|
||||
}
|
||||
report.setStatuses(parseStatuses(context, resobj.getJSONArray("statuses")));
|
||||
} catch (Exception e) {
|
||||
|
@ -1300,7 +1314,7 @@ public class API {
|
|||
* @param resobj JSONObject
|
||||
* @return Account
|
||||
*/
|
||||
private static AccountAdmin parseAccountAdminResponse(Context context, JSONObject resobj) {
|
||||
private static AccountAdmin parseAccountAdminResponse(JSONObject resobj) {
|
||||
|
||||
AccountAdmin accountAdmin = new AccountAdmin();
|
||||
try {
|
||||
|
@ -1337,7 +1351,7 @@ public class API {
|
|||
}
|
||||
|
||||
if (!resobj.isNull("account")) {
|
||||
accountAdmin.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
|
||||
accountAdmin.setAccount(parseAccountResponse(resobj.getJSONObject("account")));
|
||||
} else {
|
||||
Account account = new Account();
|
||||
account.setId(accountAdmin.getId());
|
||||
|
@ -1381,13 +1395,25 @@ public class API {
|
|||
return accountAdmin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response an unique account
|
||||
*
|
||||
* @param resobj JSONObject
|
||||
* @return Account
|
||||
*/
|
||||
private static Account parseAccountResponse(Context context, JSONObject resobj) {
|
||||
private static Account parseAccountResponse(JSONObject resobj) {
|
||||
return parseAccountResponse(resobj, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique account
|
||||
*
|
||||
* @param resobj JSONObject
|
||||
* @param recursive boolean
|
||||
* @return Account
|
||||
*/
|
||||
private static Account parseAccountResponse(JSONObject resobj, boolean recursive) {
|
||||
|
||||
Account account = new Account();
|
||||
try {
|
||||
|
@ -1427,7 +1453,9 @@ public class API {
|
|||
account.setBot(false);
|
||||
}
|
||||
try {
|
||||
account.setMoved_to_account(parseAccountResponse(context, resobj.getJSONObject("moved")));
|
||||
if(recursive) {
|
||||
account.setMoved_to_account(parseAccountResponse(resobj.getJSONObject("moved"), false));
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
account.setMoved_to_account(null);
|
||||
}
|
||||
|
@ -1638,7 +1666,7 @@ public class API {
|
|||
notification.setId(resobj.get("id").toString());
|
||||
notification.setType(resobj.get("type").toString());
|
||||
notification.setCreated_at(Helper.mstStringToDate(resobj.get("created_at").toString()));
|
||||
notification.setAccount(parseAccountResponse(context, resobj.getJSONObject("account")));
|
||||
notification.setAccount(parseAccountResponse(resobj.getJSONObject("account")));
|
||||
if (resobj.has("status")) {
|
||||
try {
|
||||
notification.setStatus(parseStatuses(context, resobj.getJSONObject("status")));
|
||||
|
@ -1951,7 +1979,7 @@ public class API {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
AccountAdmin accountAdmin = parseAccountAdminResponse(context, new JSONObject(response));
|
||||
AccountAdmin accountAdmin = parseAccountAdminResponse(new JSONObject(response));
|
||||
accountAdmins = new ArrayList<>();
|
||||
accountAdmins.add(accountAdmin);
|
||||
}
|
||||
|
@ -2124,7 +2152,7 @@ public class API {
|
|||
case UNSUSPEND:
|
||||
List<AccountAdmin> accountAdmins = null;
|
||||
try {
|
||||
AccountAdmin accountAdmin = parseAccountAdminResponse(context, new JSONObject(response));
|
||||
AccountAdmin accountAdmin = parseAccountAdminResponse(new JSONObject(response));
|
||||
accountAdmin.setAction(action);
|
||||
accountAdmins = new ArrayList<>();
|
||||
accountAdmins.add(accountAdmin);
|
||||
|
@ -2487,7 +2515,7 @@ public class API {
|
|||
return null;
|
||||
}
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, prefKeyOauthTokenT);
|
||||
account = parseAccountResponse(context, new JSONObject(response));
|
||||
account = parseAccountResponse(new JSONObject(response));
|
||||
if (social != null) {
|
||||
account.setSocial(social.toUpperCase());
|
||||
}
|
||||
|
@ -2519,7 +2547,7 @@ public class API {
|
|||
String response;
|
||||
try {
|
||||
response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, targetedAccount.getToken());
|
||||
account = parseAccountResponse(context, new JSONObject(response));
|
||||
account = parseAccountResponse(new JSONObject(response));
|
||||
if (social != null) {
|
||||
account.setSocial(social.toUpperCase());
|
||||
}
|
||||
|
@ -2615,7 +2643,7 @@ public class API {
|
|||
account = new Account();
|
||||
try {
|
||||
String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl(String.format("/accounts/%s", accountId)), 10, null, prefKeyOauthTokenT);
|
||||
account = parseAccountResponse(context, new JSONObject(response));
|
||||
account = parseAccountResponse(new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
|
@ -3099,11 +3127,10 @@ public class API {
|
|||
} else {
|
||||
if (statuses.get(0).getId().matches("\\d+")) {
|
||||
apiResponse.setSince_id(String.valueOf(statuses.get(0).getId()));
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
} else {
|
||||
apiResponse.setSince_id(statuses.get(0).getId());
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
}
|
||||
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
@ -4554,7 +4581,7 @@ public class API {
|
|||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.postJson(getAbsoluteUrl(String.format("/polls/%s/votes", pollId)), 10, jsonObject, prefKeyOauthTokenT);
|
||||
return parsePoll(context, new JSONObject(response));
|
||||
return parsePoll(new JSONObject(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
e.printStackTrace();
|
||||
|
@ -4575,7 +4602,7 @@ public class API {
|
|||
Poll _p = (status.getReblog() != null) ? status.getReblog().getPoll() : status.getPoll();
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.get(getAbsoluteUrl(String.format("/polls/%s", _p.getId())), 10, null, prefKeyOauthTokenT);
|
||||
Poll poll = parsePoll(context, new JSONObject(response));
|
||||
Poll poll = parsePoll(new JSONObject(response));
|
||||
Bundle b = new Bundle();
|
||||
status.setPoll(poll);
|
||||
b.putParcelable("status", status);
|
||||
|
@ -4585,7 +4612,7 @@ public class API {
|
|||
Status alreadyCached = new TimelineCacheDAO(context, db).getSingle(status.getId());
|
||||
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
if (alreadyCached != null) {
|
||||
poll = parsePoll(context, new JSONObject(response));
|
||||
poll = parsePoll(new JSONObject(response));
|
||||
status.setPoll(poll);
|
||||
new TimelineCacheDAO(context, db).update(status.getId(), Helper.statusToStringStorage(status), account.getId(), account.getInstance());
|
||||
}
|
||||
|
@ -5779,7 +5806,7 @@ public class API {
|
|||
}
|
||||
}
|
||||
if (resobj.has("contact_account")) {
|
||||
instance.setContactAccount(parseAccountResponse(context, resobj.getJSONObject("contact_account")));
|
||||
instance.setContactAccount(parseAccountResponse(resobj.getJSONObject("contact_account")));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -5988,7 +6015,7 @@ public class API {
|
|||
int i = 0;
|
||||
while (i < jsonArray.length()) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
AccountAdmin accountAdmin = parseAccountAdminResponse(context, resobj);
|
||||
AccountAdmin accountAdmin = parseAccountAdminResponse(resobj);
|
||||
accountAdmins.add(accountAdmin);
|
||||
i++;
|
||||
}
|
||||
|
@ -6011,7 +6038,7 @@ public class API {
|
|||
int i = 0;
|
||||
while (i < jsonArray.length()) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Account account = parseAccountResponse(context, resobj);
|
||||
Account account = parseAccountResponse(resobj);
|
||||
accounts.add(account);
|
||||
i++;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue