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