Some fixes

This commit is contained in:
tom79 2020-01-18 18:23:09 +01:00
parent 9f711a9be5
commit 06c0b0674d
15 changed files with 50 additions and 35 deletions

View File

@ -2568,7 +2568,7 @@ public abstract class BaseMainActivity extends BaseActivity
return fragment; return fragment;
}else if (position == 3) { }else if (position == 3) {
DisplayStoriesFragment fragment = new DisplayStoriesFragment(); DisplayStoriesFragment fragment = new DisplayStoriesFragment();
bundle.putSerializable("type", RetrieveStoriesAsyncTask.type.FRIENDS); bundle.putSerializable("type", RetrieveStoriesAsyncTask.type.ME);
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
} }

View File

@ -257,7 +257,7 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted //Discards 404 - error which can often happen due to toots which have been deleted
if (apiResponse.getError() != null) { 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(); Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
swiped = false; swiped = false;

View File

@ -477,7 +477,7 @@ public class OwnerNotificationActivity extends BaseActivity implements OnRetriev
mainLoader.setVisibility(View.GONE); mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted //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(); Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
swiped = false; swiped = false;

View File

@ -451,7 +451,7 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
mainLoader.setVisibility(View.GONE); mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted //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(); Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
swiped = false; swiped = false;

View File

@ -745,7 +745,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
@Override @Override
public void onRetrievePeertubeComments(APIResponse apiResponse) { 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) if (apiResponse == null)
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show(); Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
else else

View File

@ -216,7 +216,7 @@ public class PlaylistsActivity extends BaseActivity implements OnPlaylistActionI
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted //Discards 404 - error which can often happen due to toots which have been deleted
if (apiResponse.getError() != null) { 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(); Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
swiped = false; swiped = false;

View File

@ -1530,7 +1530,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
@Override @Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) { public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
if (apiResponse.getError() != null) { 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(); Toasty.error(getApplicationContext(), apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
return; return;
} }

View File

@ -581,27 +581,29 @@ public class API {
status.setLanguage("ja"); status.setLanguage("ja");
} }
status.setUrl(resobj.get("url").toString()); status.setUrl(resobj.get("url").toString());
//Retrieves attachments
JSONArray arrayAttachement = resobj.getJSONArray("media_attachments");
ArrayList<Attachment> attachments = new ArrayList<>(); ArrayList<Attachment> attachments = new ArrayList<>();
if (arrayAttachement != null) { //Retrieves attachments
for (int j = 0; j < arrayAttachement.length(); j++) { if( resobj.has("media_attachments")) {
JSONObject attObj = arrayAttachement.getJSONObject(j); JSONArray arrayAttachement = resobj.getJSONArray("media_attachments");
Attachment attachment = new Attachment();
attachment.setId(attObj.get("id").toString()); if (arrayAttachement != null) {
attachment.setPreview_url(attObj.get("preview_url").toString()); for (int j = 0; j < arrayAttachement.length(); j++) {
attachment.setRemote_url(attObj.get("remote_url").toString()); JSONObject attObj = arrayAttachement.getJSONObject(j);
attachment.setType(attObj.get("type").toString()); Attachment attachment = new Attachment();
attachment.setText_url(attObj.get("text_url").toString()); attachment.setId(attObj.get("id").toString());
attachment.setUrl(attObj.get("url").toString()); attachment.setPreview_url(attObj.get("preview_url").toString());
try { attachment.setRemote_url(attObj.get("remote_url").toString());
attachment.setDescription(attObj.get("description").toString()); attachment.setType(attObj.get("type").toString());
} catch (JSONException ignore) { 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 { try {
status.setCard(parseCardResponse(resobj.getJSONObject("card"))); status.setCard(parseCardResponse(resobj.getJSONObject("card")));
} catch (Exception e) { } catch (Exception e) {
@ -2104,7 +2106,7 @@ public class API {
} catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) { } catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) {
e1.printStackTrace(); e1.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e1) { } catch (HttpsConnection.HttpsConnectionException e1) {
if (e1.getStatusCode() == 404) { if (e1.getStatusCode() == 404 || e1.getStatusCode() == 501 ) {
instanceNodeInfo.setName("GNU"); instanceNodeInfo.setName("GNU");
instanceNodeInfo.setVersion("unknown"); instanceNodeInfo.setVersion("unknown");
instanceNodeInfo.setOpenRegistrations(true); instanceNodeInfo.setOpenRegistrations(true);
@ -2128,7 +2130,7 @@ public class API {
} catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) { } catch (NoSuchAlgorithmException | JSONException | KeyManagementException e1) {
e1.printStackTrace(); e1.printStackTrace();
} catch (HttpsConnection.HttpsConnectionException e1) { } catch (HttpsConnection.HttpsConnectionException e1) {
if (e1.getStatusCode() == 404) { if (e1.getStatusCode() == 404|| e1.getStatusCode() == 501) {
instanceNodeInfo.setName("GNU"); instanceNodeInfo.setName("GNU");
instanceNodeInfo.setVersion("unknown"); instanceNodeInfo.setVersion("unknown");
instanceNodeInfo.setOpenRegistrations(true); instanceNodeInfo.setOpenRegistrations(true);

View File

@ -463,7 +463,15 @@ public class Status implements Parcelable {
uri = new URI(url); uri = new URI(url);
instance = uri.getHost(); instance = uri.getHost();
} catch (URISyntaxException e) { } 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("@")) if (key.startsWith("@"))
acct = key.substring(1).split("\\|")[0]; acct = key.substring(1).split("\\|")[0];

View File

@ -1104,7 +1104,7 @@ public class GNUAPI {
} }
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
if (e.getStatusCode() != 404) if (e.getStatusCode() != 404 && e.getStatusCode() != 501)
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -20,6 +20,7 @@ import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.util.Log;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -64,6 +65,7 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.SlideMediaActivity; import app.fedilab.android.activities.SlideMediaActivity;
import app.fedilab.android.activities.TootActivity; import app.fedilab.android.activities.TootActivity;
import app.fedilab.android.client.Entities.Error; import app.fedilab.android.client.Entities.Error;
@ -202,11 +204,12 @@ public class HttpsConnection {
.url(httpBuider.build()) .url(httpBuider.build())
.build(); .build();
int code = 500;
try { try {
Response httpresponse = client.newCall(requesthttp).execute(); Response httpresponse = client.newCall(requesthttp).execute();
assert httpresponse.body() != null; assert httpresponse.body() != null;
String response = httpresponse.body().string(); String response = httpresponse.body().string();
int code = httpresponse.code(); code = httpresponse.code();
String error = httpresponse.message(); String error = httpresponse.message();
if (code >= 200 && code < 400) { if (code >= 200 && code < 400) {
if (!cache.isClosed()) { 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{ }else{
if (proxy != null) if (proxy != null)

View File

@ -89,6 +89,7 @@ public class PixelfedAPI {
pixelFedStories.add(pixelFedStory); pixelFedStories.add(pixelFedStory);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -116,6 +117,7 @@ public class PixelfedAPI {
pixelFedStories = parseStories(new JSONArray(response)); pixelFedStories = parseStories(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace();
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -176,7 +176,7 @@ public class DisplayMediaFragment extends Fragment implements OnRetrieveFeedsInt
mainLoader.setVisibility(View.GONE); mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//Discards 404 - error which can often happen due to toots which have been deleted //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 != null && apiResponse.getError() != null && apiResponse.getError().getError() != null)
if (apiResponse.getError().getError().length() < 100) { if (apiResponse.getError().getError().length() < 100) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();

View File

@ -108,7 +108,7 @@ public class DisplayScheduledTootsFragment extends Fragment implements OnRetriev
@Override @Override
public void onRetrieveFeeds(APIResponse apiResponse) { 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) { if (apiResponse.getError().getError().length() < 100) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
} else { } else {

View File

@ -519,7 +519,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
nextElementLoader.setVisibility(View.GONE); nextElementLoader.setVisibility(View.GONE);
//handle other API error but discards 404 - error which can often happen due to toots which have been deleted //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) if (apiResponse == null)
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
else { else {
@ -1008,7 +1008,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
if (statusListAdapter == null && pixelfedListAdapter == null) if (statusListAdapter == null && pixelfedListAdapter == null)
return; 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) if (apiResponse == null)
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
else if (apiResponse.getError().getError().length() < 100) { else if (apiResponse.getError().getError().length() < 100) {
@ -1151,7 +1151,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
return; return;
} }
if (apiResponse.getError() != null) { 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) { if (apiResponse.getError().getError().length() < 100) {
Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show();
} else { } else {