diff --git a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java index f14a1a19f..fabfbef7b 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseMainActivity.java @@ -2568,7 +2568,7 @@ public abstract class BaseMainActivity extends BaseActivity return fragment; }else if (position == 3) { DisplayStoriesFragment fragment = new DisplayStoriesFragment(); - bundle.putSerializable("type", RetrieveStoriesAsyncTask.type.FRIENDS); + bundle.putSerializable("type", RetrieveStoriesAsyncTask.type.ME); fragment.setArguments(bundle); return fragment; } diff --git a/app/src/main/java/app/fedilab/android/activities/ListActivity.java b/app/src/main/java/app/fedilab/android/activities/ListActivity.java index c26a93258..87198e94c 100644 --- a/app/src/main/java/app/fedilab/android/activities/ListActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ListActivity.java @@ -257,7 +257,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface nextElementLoader.setVisibility(View.GONE); //Discards 404 - error which can often happen due to toots which have been deleted if (apiResponse.getError() != null) { - if (!apiResponse.getError().getError().startsWith("404 -")) + if (!apiResponse.getError().getError().startsWith("404 -") && !apiResponse.getError().getError().startsWith("501 -")) Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); swipeRefreshLayout.setRefreshing(false); swiped = false; diff --git a/app/src/main/java/app/fedilab/android/activities/OwnerNotificationActivity.java b/app/src/main/java/app/fedilab/android/activities/OwnerNotificationActivity.java index 749759586..774d4652a 100644 --- a/app/src/main/java/app/fedilab/android/activities/OwnerNotificationActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/OwnerNotificationActivity.java @@ -477,7 +477,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev mainLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE); //Discards 404 - error which can often happen due to toots which have been deleted - if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) { + if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404&& apiResponse.getError().getStatusCode() != 501) { Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); swipeRefreshLayout.setRefreshing(false); swiped = false; diff --git a/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java b/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java index db7c71889..cc8a331af 100644 --- a/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/OwnerStatusActivity.java @@ -451,7 +451,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds mainLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE); //Discards 404 - error which can often happen due to toots which have been deleted - if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) { + if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501) { Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); swipeRefreshLayout.setRefreshing(false); swiped = false; diff --git a/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java b/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java index c6ec8fe31..4cc78ffd7 100644 --- a/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/PeertubeActivity.java @@ -745,7 +745,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube @Override public void onRetrievePeertubeComments(APIResponse apiResponse) { - if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404)) { + if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 501)) { if (apiResponse == null) Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); else diff --git a/app/src/main/java/app/fedilab/android/activities/PlaylistsActivity.java b/app/src/main/java/app/fedilab/android/activities/PlaylistsActivity.java index 863406a1a..f225f7c75 100644 --- a/app/src/main/java/app/fedilab/android/activities/PlaylistsActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/PlaylistsActivity.java @@ -216,7 +216,7 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI nextElementLoader.setVisibility(View.GONE); //Discards 404 - error which can often happen due to toots which have been deleted if (apiResponse.getError() != null) { - if (!apiResponse.getError().getError().startsWith("404 -")) + if (!apiResponse.getError().getError().startsWith("404 -")&&!apiResponse.getError().getError().startsWith("501 -")) Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); swipeRefreshLayout.setRefreshing(false); swiped = false; diff --git a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java index 1a7435a66..11957b1c1 100644 --- a/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ShowAccountActivity.java @@ -1530,7 +1530,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt @Override public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) { if (apiResponse.getError() != null) { - if (!apiResponse.getError().getError().startsWith("404 -")) + if (!apiResponse.getError().getError().startsWith("404 -")&&!apiResponse.getError().getError().startsWith("501 -")) Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); return; } 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 e8027ffc4..4c5d971c4 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -581,27 +581,29 @@ public class API { status.setLanguage("ja"); } status.setUrl(resobj.get("url").toString()); - //Retrieves attachments - JSONArray arrayAttachement = resobj.getJSONArray("media_attachments"); ArrayList 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("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) { + //Retrieves attachments + 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); } - attachments.add(attachment); } } - try { status.setCard(parseCardResponse(resobj.getJSONObject("card"))); } catch (Exception e) { @@ -2104,7 +2106,7 @@ public class API { } catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) { e1.printStackTrace(); } catch (HttpsConnection.HttpsConnectionException e1) { - if (e1.getStatusCode() == 404) { + if (e1.getStatusCode() == 404 || e1.getStatusCode() == 501 ) { instanceNodeInfo.setName("GNU"); instanceNodeInfo.setVersion("unknown"); instanceNodeInfo.setOpenRegistrations(true); @@ -2128,7 +2130,7 @@ public class API { } catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) { e1.printStackTrace(); } catch (HttpsConnection.HttpsConnectionException e1) { - if (e1.getStatusCode() == 404) { + if (e1.getStatusCode() == 404|| e1.getStatusCode() == 501) { instanceNodeInfo.setName("GNU"); instanceNodeInfo.setVersion("unknown"); instanceNodeInfo.setOpenRegistrations(true); diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index 350a48397..8cffb9f73 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -463,7 +463,15 @@ public class Status implements Parcelable { uri = new URI(url); instance = uri.getHost(); } catch (URISyntaxException e) { - e.printStackTrace(); + if( url.contains("|")) { + try { + uri = new URI(url.split("\\|")[0]); + instance = uri.getHost(); + } catch (URISyntaxException ex) { + ex.printStackTrace(); + } + + } } if (key.startsWith("@")) acct = key.substring(1).split("\\|")[0]; diff --git a/app/src/main/java/app/fedilab/android/client/GNUAPI.java b/app/src/main/java/app/fedilab/android/client/GNUAPI.java index a7847d636..c602a48e8 100644 --- a/app/src/main/java/app/fedilab/android/client/GNUAPI.java +++ b/app/src/main/java/app/fedilab/android/client/GNUAPI.java @@ -1104,7 +1104,7 @@ public class GNUAPI { } } catch (HttpsConnection.HttpsConnectionException e) { - if (e.getStatusCode() != 404) + if (e.getStatusCode() != 404 && e.getStatusCode() != 501) setError(e.getStatusCode(), e); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); diff --git a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java index 43a10aea3..4d9853973 100644 --- a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java +++ b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java @@ -20,6 +20,7 @@ import android.content.SharedPreferences; import android.os.Build; import android.text.Html; import android.text.SpannableString; +import android.util.Log; import com.google.gson.JsonObject; @@ -64,6 +65,7 @@ import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import app.fedilab.android.R; +import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.SlideMediaActivity; import app.fedilab.android.activities.TootActivity; import app.fedilab.android.client.Entities.Error; @@ -202,11 +204,12 @@ public class HttpsConnection { .url(httpBuider.build()) .build(); + int code = 500; try { Response httpresponse = client.newCall(requesthttp).execute(); assert httpresponse.body() != null; String response = httpresponse.body().string(); - int code = httpresponse.code(); + code = httpresponse.code(); String error = httpresponse.message(); if (code >= 200 && code < 400) { if (!cache.isClosed()) { @@ -231,7 +234,7 @@ public class HttpsConnection { } } } - throw new HttpsConnectionException(500, context.getString(R.string.toast_error)); + throw new HttpsConnectionException(code, context.getString(R.string.toast_error)); }else{ if (proxy != null) diff --git a/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java b/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java index f9297b900..bb5dd4f2d 100644 --- a/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java +++ b/app/src/main/java/app/fedilab/android/client/PixelfedAPI.java @@ -89,6 +89,7 @@ public class PixelfedAPI { pixelFedStories.add(pixelFedStory); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); + e.printStackTrace(); } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } @@ -116,6 +117,7 @@ public class PixelfedAPI { pixelFedStories = parseStories(new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); + e.printStackTrace(); } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayMediaFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayMediaFragment.java index ea980efd3..3895f6564 100644 --- a/app/src/main/java/app/fedilab/android/fragments/DisplayMediaFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/DisplayMediaFragment.java @@ -176,7 +176,7 @@ public class DisplayMediaFragment extends Fragment implements OnRetrieveFeedsInt mainLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE); //Discards 404 - error which can often happen due to toots which have been deleted - if (apiResponse == null || apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) { + if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) { if (apiResponse != null && apiResponse.getError() != null && apiResponse.getError().getError() != null) if (apiResponse.getError().getError().length() < 100) { Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayScheduledTootsFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayScheduledTootsFragment.java index fdf3e0cd9..f068ca213 100644 --- a/app/src/main/java/app/fedilab/android/fragments/DisplayScheduledTootsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/DisplayScheduledTootsFragment.java @@ -108,7 +108,7 @@ public class DisplayScheduledTootsFragment extends Fragment implements OnRetriev @Override public void onRetrieveFeeds(APIResponse apiResponse) { - if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404) { + if (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501) { if (apiResponse.getError().getError().length() < 100) { Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); } else { diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java index 786da6001..2dc0d6007 100644 --- a/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java @@ -519,7 +519,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn nextElementLoader.setVisibility(View.GONE); //handle other API error but discards 404 - error which can often happen due to toots which have been deleted - if (this.peertubes == null || this.statuses == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404)) { + if (this.peertubes == null || this.statuses == null || apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) { if (apiResponse == null) Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); else { @@ -1008,7 +1008,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if (statusListAdapter == null && pixelfedListAdapter == null) return; - if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404)) { + if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) { if (apiResponse == null) Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); else if (apiResponse.getError().getError().length() < 100) { @@ -1151,7 +1151,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn return; } if (apiResponse.getError() != null) { - if (!apiResponse.getError().getError().startsWith("404 -")) + if (!apiResponse.getError().getError().startsWith("404 -")&&!apiResponse.getError().getError().startsWith("501 -")) if (apiResponse.getError().getError().length() < 100) { Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); } else {