Upload + new api endpoints

This commit is contained in:
Thomas 2021-01-26 18:47:15 +01:00
parent 043beeecaf
commit 025f78994c
10 changed files with 476 additions and 289 deletions

View File

@ -541,9 +541,9 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
String scheme = sharedpreferences.getString(Helper.SET_ONION_SCHEME + Helper.getLiveInstance(activity), "https");
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3);
String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/v1/media";
String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/pixelfed/v1/media";
if (pixelfedStory) {
url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/stories/v1/add";
url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/pixelfed/stories/v1/add";
}
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig
@ -551,7 +551,11 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
uploadConfig.getProgress().message = activity.getString(R.string.uploading);
uploadConfig.getCompleted().autoClear = true;
MultipartUploadRequest request = new MultipartUploadRequest(activity, uploadId, url);
request.addHeader("Authorization", "Bearer " + token);
String cookie = token.split("\\|")[1];
request.addHeader("cookie", cookie);
String[] tokens = token.split("\\|")[0].split(";");
request.addHeader("x-xsrf-token", tokens[0].replace("X-XSRF-TOKEN= ", ""));
request.addHeader("x-csrf-token", tokens[1].replace("X-CSRF-TOKEN= ", ""));
request.setNotificationConfig(uploadConfig);
request.addFileToUpload(uri.toString().replace("file://", ""), "file");
if (!pixelfedStory) {

View File

@ -81,7 +81,7 @@ public class UpdateAccountInfoByIDAsyncTask {
account.setClient_secret(accountOld.getClient_secret());
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
}
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
new API(contextReference.get()).refreshToken(account);
}
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {

View File

@ -22,9 +22,11 @@ import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@ -40,6 +42,7 @@ import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
@ -1463,6 +1466,8 @@ public class API {
account.setAvatar(resobj.getString("avatar"));
if (resobj.has("avatar_static"))
account.setAvatar_static(resobj.getString("avatar_static"));
else
account.setAvatar_static(resobj.getString("avatar"));
if (resobj.has("header"))
account.setHeader(resobj.getString("header"));
if (resobj.has("header_static"))
@ -1507,17 +1512,21 @@ public class API {
//Retrieves emjis
List<Emojis> emojiList = new ArrayList<>();
try {
JSONArray emojisTag = resobj.getJSONArray("emojis");
for (int j = 0; j < emojisTag.length(); j++) {
JSONObject emojisObj = emojisTag.getJSONObject(j);
Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
if (resobj.has("emojis")) {
try {
JSONArray emojisTag = resobj.getJSONArray("emojis");
for (int j = 0; j < emojisTag.length(); j++) {
JSONObject emojisObj = emojisTag.getJSONObject(j);
Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
}
account.setEmojis(emojiList);
} catch (Exception e) {
account.setEmojis(new ArrayList<>());
e.printStackTrace();
}
account.setEmojis(emojiList);
} catch (Exception e) {
} else {
account.setEmojis(new ArrayList<>());
e.printStackTrace();
}
if (resobj.has("source")) {
JSONObject source = resobj.getJSONObject("source");
@ -2473,7 +2482,7 @@ public class API {
} catch (UnsupportedEncodingException e) {
requestParams.put("display_name", display_name);
}
if (note != null)
if (note != null && MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
try {
requestParams.put("note", URLEncoder.encode(note, "UTF-8"));
} catch (UnsupportedEncodingException e) {
@ -2780,13 +2789,20 @@ public class API {
params.put("max_id", max_id);
if (since_id != null)
params.put("since_id", since_id);
//noinspection ConstantConditions
if (0 < limit || limit > 40)
limit = 40;
if (onlyMedia)
params.put("only_media", Boolean.toString(true));
if (pinned)
params.put("pinned", Boolean.toString(true));
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
limit = 20;
params.put("only_media", Boolean.toString(true));
if (max_id == null) {
params.put("min_id", "1");
}
} else {
if (onlyMedia)
params.put("only_media", Boolean.toString(true));
}
params.put("exclude_replies", Boolean.toString(exclude_replies));
params.put("limit", String.valueOf(limit));
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -2795,12 +2811,12 @@ public class API {
params.put("tagged", tag.toLowerCase());
}
statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/statuses", accountId)), 10, params, prefKeyOauthTokenT);
statuses = parseStatuses(context, new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -2831,8 +2847,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/reblogged_by", statusId)), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
setAccountsMaxId(httpsConnection, accounts);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -2862,8 +2877,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/favourited_by", statusId)), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
setAccountsMaxId(httpsConnection, accounts);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -2952,9 +2966,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUr2l(String.format("/status/%s/replies", statusId)), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -3058,9 +3071,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/timelines/direct"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -3159,13 +3171,12 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/timelines/home"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
if (since_id == null) {
statuses = parseStatusesForCache(context, new JSONArray(response));
} else {
statuses = parseStatuses(context, new JSONArray(response));
}
setStatusesMaxId(httpsConnection, statuses);
} catch (UnknownHostException e) {
if (since_id == null) {
getHomeTimelineCache(max_id);
@ -3252,9 +3263,9 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrlRemote(remoteInstance, "/timelines/public/"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
}
@ -3262,6 +3273,58 @@ public class API {
return apiResponse;
}
private void setStatusesMaxId(HttpsConnection httpsConnection, List<Status> statuses) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} else {
if (statuses.size() > 0) {
if (statuses.get(0).getId() != null && statuses.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setSince_id(String.valueOf(statuses.get(0).getId()));
apiResponse.setMax_id(String.valueOf(statuses.get(statuses.size() - 1).getId()));
} else {
apiResponse.setSince_id(statuses.get(0).getId());
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
}
}
}
}
private void setNotificationsMaxId(HttpsConnection httpsConnection, List<Notification> notifications) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} else {
if (notifications.size() > 0) {
if (notifications.get(0).getId() != null && notifications.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setSince_id(String.valueOf(notifications.get(0).getId()));
apiResponse.setMax_id(String.valueOf(notifications.get(notifications.size() - 1).getId()));
} else {
apiResponse.setSince_id(notifications.get(0).getId());
apiResponse.setMax_id(notifications.get(notifications.size() - 1).getId());
}
}
}
}
private void setAccountsMaxId(HttpsConnection httpsConnection, List<Account> accounts) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} else {
if (accounts.size() > 0) {
if (accounts.get(0).getId() != null && accounts.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setSince_id(String.valueOf(accounts.get(0).getId()));
apiResponse.setMax_id(String.valueOf(accounts.get(accounts.size() - 1).getId()));
} else {
apiResponse.setSince_id(accounts.get(0).getId());
apiResponse.setMax_id(accounts.get(accounts.size() - 1).getId());
}
}
}
}
/**
* Retrieves Peertube videos from an instance *synchronously*
*
@ -3608,9 +3671,8 @@ public class API {
else
url = getAbsoluteUrlRemoteInstance(instanceName);
String response = httpsConnection.get(url, 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -3640,9 +3702,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get("https://toot.fedilab.app/api/v1/timelines/tag/fedilab", 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
List<Status> tmp_status = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, tmp_status);
if (tmp_status.size() > 0) {
for (Status status : tmp_status) {
if (status.getAccount().getAcct().equals("apps")) {
@ -3696,9 +3757,8 @@ public class API {
String url;
url = getAbsoluteUr2l("/discover/posts");
String response = httpsConnection.get(url, 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -3879,9 +3939,8 @@ public class API {
response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/tag/%s", query)), 10, params, prefKeyOauthTokenT);
else
response = httpsConnection.get(getAbsoluteUrlRemote(instance, String.format("/timelines/tag/%s", query)), 10, params, null);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -3957,9 +4016,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
accounts = parseAccountResponse(new JSONArray(response));
setAccountsMaxId(httpsConnection, accounts);
if (accounts.size() == 1) {
if (accounts.get(0).getAcct() == null) {
Throwable error = new Throwable(context.getString(R.string.toast_error));
@ -4061,9 +4119,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/follow_requests"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
accounts = parseAccountResponse(new JSONArray(response));
setAccountsMaxId(httpsConnection, accounts);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4106,9 +4163,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/favourites"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4156,9 +4212,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/bookmarks"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4257,10 +4312,22 @@ public class API {
HashMap<String, String> params = null;
switch (statusAction) {
case FAVOURITE:
action = String.format("/statuses/%s/favourite", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/favourite", targetedId);
} else {
action = "/i/like";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case UNFAVOURITE:
action = String.format("/statuses/%s/unfavourite", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/unfavourite", targetedId);
} else {
action = "/i/like";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case BOOKMARK:
action = String.format("/statuses/%s/bookmark", targetedId);
@ -4269,13 +4336,32 @@ public class API {
action = String.format("/statuses/%s/unbookmark", targetedId);
break;
case REBLOG:
action = String.format("/statuses/%s/reblog", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/reblog", targetedId);
} else {
action = "/i/share";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case UNREBLOG:
action = String.format("/statuses/%s/unreblog", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/unreblog", targetedId);
} else {
action = "/i/share";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case FOLLOW:
action = String.format("/accounts/%s/follow", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/follow", targetedId);
} else {
action = "/i/follow";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case NOTIFY_FOR_ACCOUNT:
params = new HashMap<>();
@ -4293,10 +4379,22 @@ public class API {
params.put("uri", targetedId);
break;
case UNFOLLOW:
action = String.format("/accounts/%s/unfollow", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/unfollow", targetedId);
} else {
action = "/i/follow";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case BLOCK:
action = String.format("/accounts/%s/block", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/block", targetedId);
} else {
action = "/i/block";
params = new HashMap<>();
params.put("item", targetedId);
}
break;
case BLOCK_DOMAIN:
action = "/domain_blocks";
@ -4307,10 +4405,24 @@ public class API {
action = String.format("/accounts/%s/unblock", targetedId);
break;
case MUTE:
action = String.format("/accounts/%s/mute", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/mute", targetedId);
} else {
action = "/i/mute";
params = new HashMap<>();
params.put("item", targetedId);
params.put("type", "user");
}
break;
case UNMUTE:
action = String.format("/accounts/%s/unmute", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/unmute", targetedId);
} else {
action = "/i/unmute";
params = new HashMap<>();
params.put("item", targetedId);
params.put("type", "user");
}
break;
case MUTE_CONVERSATION:
action = String.format("/statuses/%s/mute", targetedId);
@ -4347,7 +4459,14 @@ public class API {
action = String.format("/accounts/%s/follow", targetedId);
break;
case UNSTATUS:
action = String.format("/statuses/%s", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s", targetedId);
} else {
action = "/i/delete";
params = new HashMap<>();
params.put("item", targetedId);
params.put("type", "status");
}
break;
case REMOVE_REACTION:
case ADD_REACTION:
@ -4415,7 +4534,13 @@ public class API {
&& statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String resp = httpsConnection.post(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT);
String url;
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
url = getAbsoluteUrl(action);
} else {
url = "https://" + Helper.getLiveInstance(context) + action;
}
String resp = httpsConnection.post(getAbsoluteUrl(url), 10, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
if (statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) {
Bundle b = new Bundle();
@ -4647,45 +4772,66 @@ public class API {
public APIResponse postStatusAction(Status status) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("status", status.getContent());
if (status.getContentType() != null)
jsonObject.addProperty("content_type", status.getContentType());
if (status.getIn_reply_to_id() != null)
jsonObject.addProperty("in_reply_to_id", status.getIn_reply_to_id());
if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) {
JsonArray mediaArray = new JsonArray();
for (Attachment attachment : status.getMedia_attachments())
mediaArray.add(attachment.getId());
jsonObject.add("media_ids", mediaArray);
}
if (status.getScheduled_at() != null)
jsonObject.addProperty("scheduled_at", status.getScheduled_at());
if (status.isSensitive())
jsonObject.addProperty("sensitive", status.isSensitive());
if (status.getSpoiler_text() != null)
jsonObject.addProperty("spoiler_text", status.getSpoiler_text());
String url;
url = getAbsoluteUrl("/statuses");
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
jsonObject.addProperty("status", status.getContent());
if (status.getContentType() != null)
jsonObject.addProperty("content_type", status.getContentType());
if (status.getIn_reply_to_id() != null)
jsonObject.addProperty("in_reply_to_id", status.getIn_reply_to_id());
if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) {
JsonArray mediaArray = new JsonArray();
for (Attachment attachment : status.getMedia_attachments())
mediaArray.add(attachment.getId());
jsonObject.add("media_ids", mediaArray);
}
if (status.getScheduled_at() != null)
jsonObject.addProperty("scheduled_at", status.getScheduled_at());
if (status.isSensitive())
jsonObject.addProperty("sensitive", status.isSensitive());
if (status.getSpoiler_text() != null)
jsonObject.addProperty("spoiler_text", status.getSpoiler_text());
if (status.getPoll() != null) {
JsonObject poll = new JsonObject();
JsonArray options = new JsonArray();
for (PollOptions option : status.getPoll().getOptionsList()) {
if (!option.getTitle().isEmpty())
options.add(option.getTitle());
}
poll.add("options", options);
poll.addProperty("expires_in", status.getPoll().getExpires_in());
poll.addProperty("multiple", status.getPoll().isMultiple());
jsonObject.add("poll", poll);
}
jsonObject.addProperty("visibility", status.getVisibility());
} else {
if (status.getIn_reply_to_id() != null) {
url = "https://" + Helper.getLiveInstance(context) + "/i/comment";
jsonObject.addProperty("comment", status.getContent());
jsonObject.addProperty("item", status.getIn_reply_to_id());
jsonObject.addProperty("sensitive", status.isSensitive());
} else {
url = "https://" + Helper.getLiveInstance(context) + "/api/local/status/compose";
jsonObject.addProperty("caption", status.getContent());
jsonObject.addProperty("comments_disabled", status.getContent());
jsonObject.addProperty("cw", status.isSensitive());
jsonObject.addProperty("visibility", status.getVisibility());
String attachments = new Gson().toJson(status.getMedia_attachments());
jsonObject.addProperty("media", attachments);
if (status.getPoll() != null) {
JsonObject poll = new JsonObject();
JsonArray options = new JsonArray();
for (PollOptions option : status.getPoll().getOptionsList()) {
if (!option.getTitle().isEmpty())
options.add(option.getTitle());
}
poll.add("options", options);
poll.addProperty("expires_in", status.getPoll().getExpires_in());
poll.addProperty("multiple", status.getPoll().isMultiple());
jsonObject.add("poll", poll);
}
jsonObject.addProperty("visibility", status.getVisibility());
statuses = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.postJson(getAbsoluteUrl("/statuses"), 10, jsonObject, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
String response = httpsConnection.postJson(url, 10, jsonObject, prefKeyOauthTokenT);
Status statusreturned = parseStatuses(context, new JSONObject(response));
statuses.add(statusreturned);
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -4776,9 +4922,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 15, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
notifications = parseNotificationResponse(new JSONArray(response));
setNotificationsMaxId(httpsConnection, notifications);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4799,13 +4944,19 @@ public class API {
private APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, String since_id, int limit, boolean display) {
HashMap<String, String> params = new HashMap<>();
if (max_id != null)
params.put("max_id", max_id);
if (since_id != null)
params.put("since_id", since_id);
if (0 > limit || limit > 30)
limit = 30;
params.put("limit", String.valueOf(limit));
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
params.put("pg", "true");
params.put("page", max_id);
} else {
if (max_id != null)
params.put("max_id", max_id);
if (since_id != null)
params.put("since_id", since_id);
if (0 > limit || limit > 30)
limit = 30;
params.put("limit", String.valueOf(limit));
}
if (context == null) {
apiResponse = new APIResponse();
@ -4908,13 +5059,11 @@ public class API {
}
List<Notification> notifications = new ArrayList<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
notifications = parseNotificationResponse(new JSONArray(response));
setNotificationsMaxId(httpsConnection, notifications);
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
setError(e.getStatusCode(), e);
@ -5096,8 +5245,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/accounts/search"), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
setAccountsMaxId(httpsConnection, accounts);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -5329,9 +5477,8 @@ public class API {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/list/%s", list_id)), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -5362,8 +5509,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/lists/%s/accounts", listId)), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
setAccountsMaxId(httpsConnection, accounts);
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -6117,7 +6263,9 @@ public class API {
} catch (Exception ignored) {
relationship.setDomain_blocking(false);
}
relationship.setNote(resobj.getString("note"));
if (resobj.has("note")) {
relationship.setNote(resobj.getString("note"));
}
try {
relationship.setNotifying(resobj.getBoolean("notifying"));
} catch (Exception ignored) {

View File

@ -22,7 +22,7 @@ import android.os.Parcelable;
* Manages Media
*/
@SuppressWarnings("unused")
public class Attachment implements Parcelable {
public static final Creator<Attachment> CREATOR = new Creator<Attachment>() {
@ -46,6 +46,7 @@ public class Attachment implements Parcelable {
private String text_url;
private String description;
private String local_path;
private boolean is_nsfw = false;
public Attachment() {
@ -62,6 +63,7 @@ public class Attachment implements Parcelable {
this.text_url = in.readString();
this.description = in.readString();
this.local_path = in.readString();
this.is_nsfw = in.readByte() != 0;
}
public int getViewId() {
@ -144,6 +146,14 @@ public class Attachment implements Parcelable {
this.local_path = local_path;
}
public boolean isIs_nsfw() {
return is_nsfw;
}
public void setIs_nsfw(boolean is_nsfw) {
this.is_nsfw = is_nsfw;
}
@Override
public int describeContents() {
return 0;
@ -161,5 +171,6 @@ public class Attachment implements Parcelable {
dest.writeString(this.text_url);
dest.writeString(this.description);
dest.writeString(this.local_path);
dest.writeByte(this.is_nsfw ? (byte) 1 : (byte) 0);
}
}

View File

@ -59,8 +59,10 @@ import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection;
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.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.helper.FileNameCleaner;
import app.fedilab.android.helper.Helper;
@ -128,6 +130,22 @@ public class HttpsConnection {
}
private void setToken(MultipartUploadRequest multipartUploadRequest, String token) {
if (token != null) {
if (token.startsWith("Basic "))
multipartUploadRequest.addHeader("Authorization", token);
else if (token.startsWith("X-XSRF-TOKEN")) {
String cookie = token.split("\\|")[1];
multipartUploadRequest.addHeader("cookie", cookie);
String[] tokens = token.split("\\|")[0].split(";");
multipartUploadRequest.addHeader("x-xsrf-token", tokens[0].replace("X-XSRF-TOKEN= ", ""));
multipartUploadRequest.addHeader("x-csrf-token", tokens[1].replace("X-CSRF-TOKEN= ", ""));
} else
multipartUploadRequest.addHeader("Authorization", "Bearer " + token);
}
}
private void setToken(String token) {
if (token != null) {
@ -145,16 +163,6 @@ public class HttpsConnection {
}
}
private String getToken(String token) {
if (token != null) {
if (token.startsWith("Basic "))
return token;
else if (token.startsWith("X-XSRF-TOKEN"))
return token;
else
return "Bearer " + token;
} else return null;
}
/**
* Get calls
@ -658,9 +666,9 @@ public class HttpsConnection {
} else {
m.addFileToUpload(file.getPath(), "header");
}
m.addParameter("name", filename)
.addHeader("Authorization", getToken(token))
.setNotificationConfig(uploadConfig)
MultipartUploadRequest multipartUploadRequest = m.addParameter("name", filename);
setToken(multipartUploadRequest, token);
multipartUploadRequest.setNotificationConfig(uploadConfig)
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo) {
@ -724,10 +732,7 @@ public class HttpsConnection {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
}
httpURLConnection.setRequestMethod("PATCH");
if (token != null && !token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", getToken(token));
else if (token != null && token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", token);
setToken(token);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpURLConnection.setDoOutput(true);
@ -805,10 +810,7 @@ public class HttpsConnection {
if (httpURLConnection instanceof HttpsURLConnection) {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
}
if (token != null && !token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", getToken(token));
else if (token != null && token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", token);
setToken(token);
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpURLConnection.setRequestMethod("PUT");
@ -878,10 +880,7 @@ public class HttpsConnection {
if (httpURLConnection instanceof HttpsURLConnection) {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
}
if (token != null && !token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", getToken(token));
else if (token != null && token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", token);
setToken(token);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setRequestMethod("DELETE");
httpURLConnection.setConnectTimeout(timeout * 1000);
@ -932,27 +931,28 @@ public class HttpsConnection {
if (httpURLConnection == null)
return;
Map<String, List<String>> map = httpURLConnection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1);
}
if (entry.toString().startsWith("Link")) {
Pattern patternSinceId = Pattern.compile("since_id=([0-9a-zA-Z]+).*");
Matcher matcherSinceId = patternSinceId.matcher(entry.toString());
if (matcherSinceId.find()) {
since_id = matcherSinceId.group(1);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1);
}
if (entry.toString().startsWith("Link")) {
Pattern patternSinceId = Pattern.compile("since_id=([0-9a-zA-Z]+).*");
Matcher matcherSinceId = patternSinceId.matcher(entry.toString());
if (matcherSinceId.find()) {
since_id = matcherSinceId.group(1);
}
}
} else if (entry.toString().startsWith("Min-Id") || entry.toString().startsWith("min-id")) {
Pattern patternMaxId = Pattern.compile("min-id=\\[([0-9a-zA-Z]+).*]");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1);
}
} else if (entry.toString().startsWith("Min-Id") || entry.toString().startsWith("min-id")) {
Pattern patternMaxId = Pattern.compile("min-id=\\[([0-9a-zA-Z]+).*]");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1);
}
}
}
}

View File

@ -33,6 +33,7 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -825,131 +826,130 @@ public abstract class BaseNotificationsListAdapter extends RecyclerView.Adapter<
popup.setOnMenuItemClickListener(item -> {
AlertDialog.Builder builderInner;
final API.StatusAction doAction;
switch (item.getItemId()) {
case R.id.action_remove:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_mute:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.MUTE;
break;
case R.id.action_mute_conversation:
if (status.isMuted())
doAction = API.StatusAction.UNMUTE_CONVERSATION;
else
doAction = API.StatusAction.MUTE_CONVERSATION;
new PostActionAsyncTask(context, doAction, status.getId(), BaseNotificationsListAdapter.this);
return true;
case R.id.action_open_browser:
Helper.openBrowser(context, status.getUrl());
return true;
case R.id.action_admin:
String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId();
Intent intent = new Intent(context, AccountReportActivity.class);
Bundle b = new Bundle();
b.putString("account_id", account_id);
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_stats:
notificationStatusChart(status);
return true;
case R.id.action_info:
intent = new Intent(context, TootInfoActivity.class);
b = new Bundle();
if (status.getReblog() != null) {
b.putString("toot_id", status.getReblog().getId());
b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count());
b.putInt("toot_favorites_count", status.getReblog().getFavourites_count());
} else {
b.putString("toot_id", status.getId());
b.putInt("toot_reblogs_count", status.getReblogs_count());
b.putInt("toot_favorites_count", status.getFavourites_count());
}
intent.putExtras(b);
context.startActivity(intent);
return true;
case R.id.action_block_domain:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[3]);
doAction = API.StatusAction.BLOCK_DOMAIN;
String domain = status.getAccount().getAcct().split("@")[1];
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
break;
case R.id.action_block:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]);
doAction = API.StatusAction.BLOCK;
break;
case R.id.action_report:
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[2]);
doAction = API.StatusAction.REPORT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_copy:
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
content = Html.fromHtml(status.getContent()).toString();
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
assert clipboard != null;
int itemId = item.getItemId();
if (itemId == R.id.action_remove) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
} else if (itemId == R.id.action_mute) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.MUTE;
} else if (itemId == R.id.action_mute_conversation) {
if (status.isMuted())
doAction = API.StatusAction.UNMUTE_CONVERSATION;
else
doAction = API.StatusAction.MUTE_CONVERSATION;
new PostActionAsyncTask(context, doAction, status.getId(), BaseNotificationsListAdapter.this);
return true;
} else if (itemId == R.id.action_open_browser) {
Helper.openBrowser(context, status.getUrl());
return true;
} else if (itemId == R.id.action_admin) {
String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId();
Intent intent = new Intent(context, AccountReportActivity.class);
Bundle b = new Bundle();
b.putString("account_id", account_id);
intent.putExtras(b);
context.startActivity(intent);
return true;
} else if (itemId == R.id.action_stats) {
notificationStatusChart(status);
return true;
} else if (itemId == R.id.action_info) {
Bundle b;
Intent intent;
intent = new Intent(context, TootInfoActivity.class);
b = new Bundle();
if (status.getReblog() != null) {
b.putString("toot_id", status.getReblog().getId());
b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count());
b.putInt("toot_favorites_count", status.getReblog().getFavourites_count());
} else {
b.putString("toot_id", status.getId());
b.putInt("toot_reblogs_count", status.getReblogs_count());
b.putInt("toot_favorites_count", status.getFavourites_count());
}
intent.putExtras(b);
context.startActivity(intent);
return true;
} else if (itemId == R.id.action_block_domain) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[3]);
doAction = API.StatusAction.BLOCK_DOMAIN;
String domain = status.getAccount().getAcct().split("@")[1];
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
} else if (itemId == R.id.action_block) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]);
doAction = API.StatusAction.BLOCK;
} else if (itemId == R.id.action_report) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[2]);
doAction = API.StatusAction.REPORT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
} else if (itemId == R.id.action_copy) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
content = Html.fromHtml(status.getContent()).toString();
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show();
return true;
} else if (itemId == R.id.action_copy_link) {
ClipData clip;
ClipboardManager clipboard;
clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show();
return true;
case R.id.action_copy_link:
clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show();
}
return true;
} else if (itemId == R.id.action_share) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl());
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
} else if (itemId == R.id.action_custom_sharing) {
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle();
if (status.getReblog() != null) {
bCustomSharing.putParcelable("status", status.getReblog());
} else {
bCustomSharing.putParcelable("status", status);
clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
if (clipboard != null) {
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show();
}
return true;
case R.id.action_share:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl());
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
case R.id.action_custom_sharing:
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle();
if (status.getReblog() != null) {
bCustomSharing.putParcelable("status", status.getReblog());
} else {
bCustomSharing.putParcelable("status", status);
}
intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing);
return true;
case R.id.action_mention:
Handler handler = new Handler();
handler.postDelayed(() -> {
Intent intent1 = new Intent(context, TootActivity.class);
Bundle b1 = new Bundle();
b1.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct());
b1.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl());
intent1.putExtras(b1);
context.startActivity(intent1);
}, 500);
return true;
default:
return true;
}
intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing);
return true;
} else if (itemId == R.id.action_mention) {
Handler handler = new Handler();
handler.postDelayed(() -> {
Intent intent1 = new Intent(context, TootActivity.class);
Bundle b1 = new Bundle();
b1.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct());
b1.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl());
intent1.putExtras(b1);
context.startActivity(intent1);
}, 500);
return true;
} else {
return true;
}
//Text for report

View File

@ -24,6 +24,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.InputFilter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -39,6 +40,9 @@ import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityOptionsCompat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaderFactory;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
@ -115,15 +119,19 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
} else {
url = attachments.get(position).getPreview_url();
}
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String cookie = token.split("\\|")[1];
LazyHeaders.Builder builder = new LazyHeaders.Builder()
.addHeader("Cookie", cookie);
GlideUrl glideUrl = new GlideUrl(url, builder.build());
if (expand_media || !isSensitive || (status != null && status.isAttachmentShown())) {
Glide.with(viewHolder.imageViewBackground.getContext())
.load(url)
.load(glideUrl)
.thumbnail(0.1f)
.into(viewHolder.imageViewBackground);
} else {
Glide.with(viewHolder.imageViewBackground.getContext())
.load(url)
.load(glideUrl)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
.into(viewHolder.imageViewBackground);
@ -198,9 +206,14 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
final EditText input = popup_media_description.findViewById(R.id.media_description);
input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)});
final ImageView media_picture = popup_media_description.findViewById(R.id.media_picture);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String cookie = token.split("\\|")[1];
LazyHeaders.Builder builder = new LazyHeaders.Builder()
.addHeader("Cookie", cookie);
GlideUrl glideUrl = new GlideUrl(attachment.getUrl(), builder.build());
Glide.with(contextWeakReference.get())
.asBitmap()
.load(attachment.getUrl())
.load(glideUrl)
.into(new CustomTarget<Bitmap>() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override

View File

@ -24,6 +24,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -96,7 +97,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_notifications, container, false);
max_id = null;
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
max_id = null;
} else {
max_id = "1";
}
context = getContext();
firstLoad = true;
flag_loading = true;
@ -288,7 +293,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
}
int previousPosition = notifications.size();
max_id = apiResponse.getMax_id();
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
max_id = apiResponse.getMax_id();
} else {
max_id = String.valueOf(Integer.parseInt(max_id) + 1);
}
List<Notification> notifications = apiResponse.getNotifications();
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
@ -381,7 +390,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
void refreshAll() {
if (context == null)
return;
max_id = null;
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
max_id = null;
} else {
max_id = "1";
}
firstLoad = true;
flag_loading = true;
swiped = true;

View File

@ -632,12 +632,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
//At this point all statuses are in "List<Status> statuses"
//Pagination for Pixelfed
if (instanceType.equals("PIXELFED")) {
if (max_id == null)
max_id = "1";
//max_id needs to work like an offset
max_id = String.valueOf(Integer.parseInt(max_id) + 1);
} else if (type == RetrieveFeedsAsyncTask.Type.SEARCH && !tag.contains("_cache_")) {
if (type == RetrieveFeedsAsyncTask.Type.SEARCH && !tag.contains("_cache_")) {
if (max_id == null)
max_id = "0";
max_id = String.valueOf(Integer.parseInt(max_id) + 20);

View File

@ -3013,6 +3013,9 @@ public class BaseHelper {
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
String url = disableGif ? account.getAvatar_static() : account.getAvatar();
if (account.getAvatar_static() == null || account.getAvatar_static().toLowerCase().trim().compareTo("null") == 0) {
url = account.getAvatar();
}
if (url != null && url.startsWith("/")) {
url = getLiveInstanceWithProtocol(context) + url;
}