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;
}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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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<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("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);

View File

@ -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];

View File

@ -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();

View File

@ -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)

View File

@ -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();
}

View File

@ -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();

View File

@ -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 {

View File

@ -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 {