This commit is contained in:
Thomas 2021-01-27 15:59:07 +01:00
parent 539025f495
commit 971fc07bfb
9 changed files with 332 additions and 224 deletions

View File

@ -22,13 +22,13 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.gson.Gson; import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -42,7 +42,6 @@ import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
@ -1646,19 +1645,65 @@ public class API {
attachment.setRemote_url(resobj.getString("remote_url")); attachment.setRemote_url(resobj.getString("remote_url"));
} catch (JSONException ignore) { } catch (JSONException ignore) {
} }
if (attachment.getRemote_url() != null && attachment.getRemote_url().toLowerCase().compareTo("null") == 0) {
attachment.setRemote_url(null);
}
try { try {
attachment.setPreview_url(resobj.getString("preview_url")); attachment.setPreview_url(resobj.getString("preview_url"));
} catch (JSONException ignore) { } catch (JSONException ignore) {
} }
if (attachment.getPreview_url() != null && attachment.getPreview_url().toLowerCase().compareTo("null") == 0) {
attachment.setPreview_url(null);
}
try { try {
attachment.setMeta(resobj.getString("meta")); attachment.setMeta(resobj.getString("meta"));
} catch (JSONException ignore) { } catch (JSONException ignore) {
} }
if (attachment.getMeta() != null && attachment.getMeta().toLowerCase().compareTo("null") == 0) {
attachment.setMeta(null);
}
try { try {
attachment.setText_url(resobj.getString("text_url")); attachment.setText_url(resobj.getString("text_url"));
} catch (JSONException ignore) { } catch (JSONException ignore) {
} }
if (attachment.getText_url() != null && attachment.getText_url().toLowerCase().compareTo("null") == 0) {
attachment.setText_url(null);
}
try {
attachment.setMime(resobj.getString("mime"));
} catch (JSONException ignore) {
}
if (attachment.getMime() != null && attachment.getMime().toLowerCase().compareTo("null") == 0) {
attachment.setMime(null);
}
try {
attachment.setFilter_class(resobj.getString("filter_class"));
} catch (JSONException ignore) {
}
if (attachment.getFilter_class() != null && attachment.getFilter_class().toLowerCase().compareTo("null") == 0) {
attachment.setFilter_class(null);
}
try {
attachment.setFilter_name(resobj.getString("filter_name"));
} catch (JSONException ignore) {
}
if (attachment.getFilter_name() != null && attachment.getFilter_name().toLowerCase().compareTo("null") == 0) {
attachment.setFilter_name(null);
}
try {
attachment.setLicense(resobj.getString("license"));
} catch (JSONException ignore) {
}
if (attachment.getLicense() != null && attachment.getLicense().toLowerCase().compareTo("null") == 0) {
attachment.setLicense(null);
}
try {
attachment.setOrientation(resobj.getString("orientation"));
} catch (JSONException ignore) {
}
if (attachment.getOrientation() != null && attachment.getOrientation().toLowerCase().compareTo("null") == 0) {
attachment.setOrientation(null);
}
} catch (JSONException ignored) { } catch (JSONException ignored) {
} }
return attachment; return attachment;
@ -4529,9 +4574,9 @@ public class API {
default: default:
return -1; return -1;
} }
if (statusAction != StatusAction.UNSTATUS if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED || (statusAction != StatusAction.UNSTATUS
&& statusAction != StatusAction.ADD_REACTION && statusAction != StatusAction.REMOVE_REACTION && statusAction != StatusAction.ADD_REACTION && statusAction != StatusAction.REMOVE_REACTION
&& statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) { && statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION)) {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String url; String url;
@ -4540,25 +4585,23 @@ public class API {
} else { } else {
url = "https://" + Helper.getLiveInstance(context) + action; url = "https://" + Helper.getLiveInstance(context) + action;
} }
String resp = httpsConnection.post(getAbsoluteUrl(url), 10, params, prefKeyOauthTokenT); String resp = httpsConnection.post(url, 10, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode(); actionCode = httpsConnection.getActionCode();
if (statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) { Bundle b = new Bundle();
Bundle b = new Bundle(); try {
try { Status status1 = parseStatuses(context, new JSONObject(resp));
Status status1 = parseStatuses(context, new JSONObject(resp)); b.putParcelable("status", status1);
b.putParcelable("status", status1); } catch (JSONException ignored) {
} catch (JSONException ignored) { }
} Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
Intent intentBC = new Intent(Helper.RECEIVE_ACTION); intentBC.putExtras(b);
intentBC.putExtras(b); LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC); SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT); Status indb = new TimelineCacheDAO(context, db).getSingle(targetedId);
Status indb = new TimelineCacheDAO(context, db).getSingle(targetedId); if (indb != null && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
if (indb != null) { String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT); new TimelineCacheDAO(context, db).update(targetedId, response, account.getId(), account.getInstance());
new TimelineCacheDAO(context, db).update(targetedId, response, account.getId(), account.getInstance());
}
} }
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
@ -4816,22 +4859,38 @@ public class API {
} else { } else {
url = "https://" + Helper.getLiveInstance(context) + "/api/local/status/compose"; url = "https://" + Helper.getLiveInstance(context) + "/api/local/status/compose";
jsonObject.addProperty("caption", status.getContent()); jsonObject.addProperty("caption", status.getContent());
jsonObject.addProperty("comments_disabled", status.getContent()); jsonObject.addProperty("comments_disabled", false);
jsonObject.addProperty("cw", status.isSensitive()); jsonObject.addProperty("cw", status.isSensitive());
jsonObject.addProperty("visibility", status.getVisibility()); jsonObject.addProperty("visibility", status.getVisibility());
String attachments = new Gson().toJson(status.getMedia_attachments()); String attachments = new GsonBuilder().serializeNulls().create().toJson(status.getMedia_attachments());
jsonObject.addProperty("media", attachments); jsonObject.addProperty("place", false);
JsonParser parser = new JsonParser();
JsonArray jsonArrayTags = parser.parse("[]").getAsJsonArray();
jsonObject.add("tagged", jsonArrayTags);
JsonArray jsonArrayMedia = parser.parse(attachments).getAsJsonArray();
jsonObject.add("media", jsonArrayMedia);
} }
} }
statuses = new ArrayList<>(); statuses = new ArrayList<>();
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.postJson(url, 10, jsonObject, prefKeyOauthTokenT); String response = httpsConnection.postJson(url, 10, jsonObject, prefKeyOauthTokenT);
Status statusreturned = parseStatuses(context, new JSONObject(response)); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
statuses.add(statusreturned); Status statusreturned = parseStatuses(context, new JSONObject(response));
setStatusesMaxId(httpsConnection, statuses); statuses.add(statusreturned);
setStatusesMaxId(httpsConnection, statuses);
} else {
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
Account account = new AccountDAO(context, db).getUniqAccount(userId, instance);
status.setAccount(account);
statuses.add(status);
setStatusesMaxId(httpsConnection, statuses);
}
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();

View File

@ -37,8 +37,12 @@ public class Attachment implements Parcelable {
} }
}; };
private String id; private String id;
private int viewId; private transient int viewId;
private String type; private String type;
private String mime;
private String filter_class;
private String filter_name;
private String license;
private String url; private String url;
private String remote_url; private String remote_url;
private String preview_url; private String preview_url;
@ -46,6 +50,7 @@ public class Attachment implements Parcelable {
private String text_url; private String text_url;
private String description; private String description;
private String local_path; private String local_path;
private String orientation;
private boolean is_nsfw = false; private boolean is_nsfw = false;
public Attachment() { public Attachment() {
@ -56,6 +61,10 @@ public class Attachment implements Parcelable {
this.id = in.readString(); this.id = in.readString();
this.viewId = in.readInt(); this.viewId = in.readInt();
this.type = in.readString(); this.type = in.readString();
this.mime = in.readString();
this.filter_class = in.readString();
this.filter_name = in.readString();
this.license = in.readString();
this.url = in.readString(); this.url = in.readString();
this.remote_url = in.readString(); this.remote_url = in.readString();
this.preview_url = in.readString(); this.preview_url = in.readString();
@ -63,6 +72,7 @@ public class Attachment implements Parcelable {
this.text_url = in.readString(); this.text_url = in.readString();
this.description = in.readString(); this.description = in.readString();
this.local_path = in.readString(); this.local_path = in.readString();
this.orientation = in.readString();
this.is_nsfw = in.readByte() != 0; this.is_nsfw = in.readByte() != 0;
} }
@ -154,6 +164,46 @@ public class Attachment implements Parcelable {
this.is_nsfw = is_nsfw; this.is_nsfw = is_nsfw;
} }
public String getFilter_class() {
return filter_class;
}
public void setFilter_class(String filter_class) {
this.filter_class = filter_class;
}
public String getFilter_name() {
return filter_name;
}
public void setFilter_name(String filter_name) {
this.filter_name = filter_name;
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
this.license = license;
}
public String getMime() {
return mime;
}
public void setMime(String mime) {
this.mime = mime;
}
public String getOrientation() {
return orientation;
}
public void setOrientation(String orientation) {
this.orientation = orientation;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@ -164,6 +214,10 @@ public class Attachment implements Parcelable {
dest.writeString(this.id); dest.writeString(this.id);
dest.writeInt(this.viewId); dest.writeInt(this.viewId);
dest.writeString(this.type); dest.writeString(this.type);
dest.writeString(this.mime);
dest.writeString(this.filter_class);
dest.writeString(this.filter_name);
dest.writeString(this.license);
dest.writeString(this.url); dest.writeString(this.url);
dest.writeString(this.remote_url); dest.writeString(this.remote_url);
dest.writeString(this.preview_url); dest.writeString(this.preview_url);
@ -171,6 +225,7 @@ public class Attachment implements Parcelable {
dest.writeString(this.text_url); dest.writeString(this.text_url);
dest.writeString(this.description); dest.writeString(this.description);
dest.writeString(this.local_path); dest.writeString(this.local_path);
dest.writeString(this.orientation);
dest.writeByte(this.is_nsfw ? (byte) 1 : (byte) 0); dest.writeByte(this.is_nsfw ? (byte) 1 : (byte) 0);
} }
} }

View File

@ -624,6 +624,11 @@ public class HttpsConnection {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance)); ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
} }
httpURLConnection.setRequestProperty("User-Agent", USER_AGENT); httpURLConnection.setRequestProperty("User-Agent", USER_AGENT);
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String cookie = token.split("\\|")[1];
httpURLConnection.setRequestProperty("Cookie", cookie);
}
int responseCode = httpURLConnection.getResponseCode(); int responseCode = httpURLConnection.getResponseCode();
// always check HTTP response code first // always check HTTP response code first
if (responseCode >= 200 && responseCode < 400) { if (responseCode >= 200 && responseCode < 400) {

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -107,9 +108,14 @@ public class PixelfedAPI {
pixelFedStory.setName(jsonObject.getString("name")); pixelFedStory.setName(jsonObject.getString("name"));
pixelFedStory.setLink(jsonObject.getString("link")); pixelFedStory.setLink(jsonObject.getString("link"));
pixelFedStory.setLastUpdated(new Date(jsonObject.getLong("lastUpdated"))); pixelFedStory.setLastUpdated(new Date(jsonObject.getLong("lastUpdated")));
pixelFedStory.setSeen(jsonObject.getBoolean("seen")); if (jsonObject.has("seen") && !jsonObject.isNull("seen")) {
pixelFedStory.setSeen(jsonObject.getBoolean("seen"));
} else {
pixelFedStory.setSeen(false);
}
pixelFedStory.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items"))); pixelFedStory.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items")));
} catch (JSONException ignored) { } catch (JSONException ignored) {
ignored.printStackTrace();
} }
return pixelFedStory; return pixelFedStory;
} }
@ -158,6 +164,7 @@ public class PixelfedAPI {
pixelFedStoryItem.setExpires_at(new Date(jsonObject.getLong("expires_at"))); pixelFedStoryItem.setExpires_at(new Date(jsonObject.getLong("expires_at")));
pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen")); pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen"));
} catch (JSONException ignored) { } catch (JSONException ignored) {
ignored.printStackTrace();
} }
return pixelFedStoryItem; return pixelFedStoryItem;
} }
@ -201,7 +208,7 @@ public class PixelfedAPI {
params.put("max_id", max_id); params.put("max_id", max_id);
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/fetch/" + userId), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/profile/" + userId), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id()); apiResponse.setMax_id(httpsConnection.getMax_id());
pixelFedStories = parseStories(new JSONArray(response)); pixelFedStories = parseStories(new JSONArray(response));

View File

@ -33,7 +33,6 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;

View File

@ -732,161 +732,155 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
popup.setOnMenuItemClickListener(item -> { popup.setOnMenuItemClickListener(item -> {
AlertDialog.Builder builderInner; AlertDialog.Builder builderInner;
final API.StatusAction doAction; final API.StatusAction doAction;
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.action_redraft: if (itemId == R.id.action_redraft) {
builderInner = new AlertDialog.Builder(context, style); builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]); builderInner.setTitle(stringArrayConf[1]);
redraft = true; redraft = true;
doAction = API.StatusAction.UNSTATUS; doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else else
builderInner.setMessage(Html.fromHtml(status.getContent())); builderInner.setMessage(Html.fromHtml(status.getContent()));
break; } else if (itemId == R.id.action_schedule_boost) {
case R.id.action_schedule_boost: scheduleBoost(status);
scheduleBoost(status); return true;
return true; } else if (itemId == R.id.action_info) {
case R.id.action_info: tootInformation(status);
tootInformation(status); return true;
return true; } else if (itemId == R.id.action_open_browser) {
case R.id.action_open_browser: Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); return true;
return true; } else if (itemId == R.id.action_remove) {
case R.id.action_remove: builderInner = new AlertDialog.Builder(context, style);
builderInner = new AlertDialog.Builder(context, style); builderInner.setTitle(stringArrayConf[0]);
builderInner.setTitle(stringArrayConf[0]); doAction = API.StatusAction.UNSTATUS;
doAction = API.StatusAction.UNSTATUS; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); else
else builderInner.setMessage(Html.fromHtml(status.getContent()));
builderInner.setMessage(Html.fromHtml(status.getContent())); } else if (itemId == R.id.action_block_domain) {
break; builderInner = new AlertDialog.Builder(context, style);
case R.id.action_block_domain: builderInner.setTitle(stringArrayConf[3]);
builderInner = new AlertDialog.Builder(context, style); doAction = API.StatusAction.BLOCK_DOMAIN;
builderInner.setTitle(stringArrayConf[3]); String domain = status.getAccount().getAcct().split("@")[1];
doAction = API.StatusAction.BLOCK_DOMAIN; builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
String domain = status.getAccount().getAcct().split("@")[1]; } else if (itemId == R.id.action_mute) {
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain)); builderInner = new AlertDialog.Builder(context, style);
break; builderInner.setTitle(stringArrayConf[0]);
case R.id.action_mute: builderInner.setMessage(status.getAccount().getAcct());
builderInner = new AlertDialog.Builder(context, style); doAction = API.StatusAction.MUTE;
builderInner.setTitle(stringArrayConf[0]); } else if (itemId == R.id.action_mute_conversation) {
builderInner.setMessage(status.getAccount().getAcct()); if (status.isMuted())
doAction = API.StatusAction.MUTE; doAction = API.StatusAction.UNMUTE_CONVERSATION;
break; else
case R.id.action_mute_conversation: doAction = API.StatusAction.MUTE_CONVERSATION;
if (status.isMuted())
doAction = API.StatusAction.UNMUTE_CONVERSATION;
else
doAction = API.StatusAction.MUTE_CONVERSATION;
new PostActionAsyncTask(context, doAction, status.getId(), PixelfedListAdapter.this); new PostActionAsyncTask(context, doAction, status.getId(), PixelfedListAdapter.this);
return true; return true;
case R.id.action_bookmark: } else if (itemId == R.id.action_bookmark) {
if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) { if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
status.setBookmarked(!status.isBookmarked()); status.setBookmarked(!status.isBookmarked());
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
try { try {
if (status.isBookmarked()) { if (status.isBookmarked()) {
new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status);
Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show(); Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show();
} else { } else {
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status);
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show();
}
notifyStatusChanged(status);
} catch (Exception e) {
e.printStackTrace();
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
} }
} else { notifyStatusChanged(status);
int position = 0; } catch (Exception e) {
for (Status statustmp : statuses) { e.printStackTrace();
if (statustmp.getId().equals(status.getId())) { Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
statuses.remove(status); }
pixelfedListAdapter.notifyItemRemoved(position); } else {
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); int position = 0;
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp); for (Status statustmp : statuses) {
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); if (statustmp.getId().equals(status.getId())) {
break; statuses.remove(status);
} pixelfedListAdapter.notifyItemRemoved(position);
position++; final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp);
Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show();
break;
} }
position++;
} }
return true; }
case R.id.action_timed_mute: return true;
timedMuteAction(status); } else if (itemId == R.id.action_timed_mute) {
return true; timedMuteAction(status);
case R.id.action_block: return true;
builderInner = new AlertDialog.Builder(context, style); } else if (itemId == R.id.action_block) {
builderInner.setTitle(stringArrayConf[1]); builderInner = new AlertDialog.Builder(context, style);
doAction = API.StatusAction.BLOCK; builderInner.setTitle(stringArrayConf[1]);
break; doAction = API.StatusAction.BLOCK;
case R.id.action_translate: } else if (itemId == R.id.action_translate) {
int translator = sharedpreferences1.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE); int translator = sharedpreferences1.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE);
if (translator == Helper.TRANS_NONE) if (translator == Helper.TRANS_NONE)
Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show(); Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show();
else
translateToot(status);
return true;
} 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_link) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData 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;
} 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));
String url;
if (status.getReblog() != null) {
if (status.getReblog().getUri().startsWith("http"))
url = status.getReblog().getUri();
else else
translateToot(status); url = status.getReblog().getUrl();
return true; } else {
case R.id.action_report: if (status.getUri().startsWith("http"))
builderInner = new AlertDialog.Builder(context, style); url = status.getUri();
builderInner.setTitle(stringArrayConf[2]); else
doAction = API.StatusAction.REPORT; url = status.getUrl();
}
String extra_text;
boolean share_details = sharedpreferences1.getBoolean(Helper.SET_SHARE_DETAILS, true);
if (share_details) {
extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct();
if (extra_text.split("@").length == 1)
extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context);
else
extra_text = "@" + extra_text;
extra_text += " \uD83D\uDD17 " + url + "\r\n-\n";
final String contentToot;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else else
builderInner.setMessage(Html.fromHtml(status.getContent())); contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString();
break; extra_text += contentToot;
case R.id.action_copy_link: } else {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); extra_text = url;
}
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
if (clipboard != null) { sendIntent.setType("text/plain");
clipboard.setPrimaryClip(clip); context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); return true;
} } else {
return true; 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));
String url;
if (status.getReblog() != null) {
if (status.getReblog().getUri().startsWith("http"))
url = status.getReblog().getUri();
else
url = status.getReblog().getUrl();
} else {
if (status.getUri().startsWith("http"))
url = status.getUri();
else
url = status.getUrl();
}
String extra_text;
boolean share_details = sharedpreferences1.getBoolean(Helper.SET_SHARE_DETAILS, true);
if (share_details) {
extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct();
if (extra_text.split("@").length == 1)
extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context);
else
extra_text = "@" + extra_text;
extra_text += " \uD83D\uDD17 " + url + "\r\n-\n";
final String contentToot;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
else
contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString();
extra_text += contentToot;
} else {
extra_text = url;
}
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
default:
return true;
} }
//Text for report //Text for report

View File

@ -108,28 +108,35 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter<RecyclerVie
attachments = new ArrayList<>(); attachments = new ArrayList<>();
if (pixelFedStory != null && pixelFedStory.getPixelFedStoryItems() != null) {
for (PixelFedStoryItem pixelFedStoryItem : pixelFedStory.getPixelFedStoryItems()) {
Attachment attachment = new Attachment();
for (PixelFedStoryItem pixelFedStoryItem : pixelFedStory.getPixelFedStoryItems()) { if (pixelFedStoryItem.getPreview() != null && pixelFedStoryItem.getPreview().toLowerCase().compareTo("null") != 0) {
Attachment attachment = new Attachment(); attachment.setPreview_url(pixelFedStoryItem.getPreview());
} else {
if (pixelFedStoryItem.getPreview() != null) { attachment.setPreview_url(pixelFedStoryItem.getSrc());
attachment.setPreview_url(pixelFedStoryItem.getPreview()); }
} else { attachment.setUrl(pixelFedStoryItem.getSrc());
attachment.setPreview_url(pixelFedStoryItem.getSrc()); attachment.setId(pixelFedStoryItem.getId());
attachment.setId(pixelFedStoryItem.getId());
attachment.setDescription(pixelFedStoryItem.getLinkText());
attachment.setType(pixelFedStoryItem.getType());
attachments.add(attachment);
} }
attachment.setUrl(pixelFedStoryItem.getSrc());
attachment.setId(pixelFedStoryItem.getId()); Glide.with(context)
attachment.setId(pixelFedStoryItem.getId()); .load(pixelFedStory.getPhoto())
attachment.setDescription(pixelFedStoryItem.getLinkText()); .apply(new RequestOptions().transform(new FitCenter(), new RoundedCorners(270)))
attachment.setType(pixelFedStoryItem.getType()); .into(holder.pf_pp);
holder.pf_date.setText(Helper.longDateToString(pixelFedStory.getLastUpdated()));
holder.pf_username.setText(pixelFedStory.getName());
} }
Glide.with(context)
.load(pixelFedStory.getPhoto())
.apply(new RequestOptions().transform(new FitCenter(), new RoundedCorners(270)))
.into(holder.pf_pp);
holder.art_media.setOnClickListener(v -> { holder.art_media.setOnClickListener(v -> {
Intent intent = new Intent(context, SlideMediaActivity.class); Intent intent = new Intent(context, SlideMediaActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();
@ -150,7 +157,6 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter<RecyclerVie
holder.art_media_play.setVisibility(View.GONE); holder.art_media_play.setVisibility(View.GONE);
if (attachments != null && attachments.size() > 1) { if (attachments != null && attachments.size() > 1) {
SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, attachments); SliderAdapter sliderAdapter = new SliderAdapter(new WeakReference<>((Activity) context), false, attachments);
holder.imageSlider.setSliderAdapter(sliderAdapter); holder.imageSlider.setSliderAdapter(sliderAdapter);
@ -158,7 +164,7 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter<RecyclerVie
holder.imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION); holder.imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
holder.art_media.setVisibility(View.GONE); holder.art_media.setVisibility(View.GONE);
holder.imageSlider.setVisibility(View.VISIBLE); holder.imageSlider.setVisibility(View.VISIBLE);
} else if (attachments != null) { } else if (attachments != null && attachments.size() > 0) {
holder.art_media.setVisibility(View.VISIBLE); holder.art_media.setVisibility(View.VISIBLE);
holder.imageSlider.setVisibility(View.GONE); holder.imageSlider.setVisibility(View.GONE);
if (attachments.get(0).getType().toLowerCase().equals("video")) { if (attachments.get(0).getType().toLowerCase().equals("video")) {
@ -177,11 +183,6 @@ public class PixelfedStoriesListAdapter extends RecyclerView.Adapter<RecyclerVie
.into(holder.art_media); .into(holder.art_media);
} }
holder.pf_date.setText(Helper.longDateToString(pixelFedStory.getLastUpdated()));
holder.pf_username.setText(pixelFedStory.getName());
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);

View File

@ -24,7 +24,6 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.text.InputFilter; import android.text.InputFilter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -119,19 +118,14 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
} else { } else {
url = attachments.get(position).getPreview_url(); 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())) { if (expand_media || !isSensitive || (status != null && status.isAttachmentShown())) {
Glide.with(viewHolder.imageViewBackground.getContext()) Glide.with(viewHolder.imageViewBackground.getContext())
.load(glideUrl) .load(url)
.thumbnail(0.1f) .thumbnail(0.1f)
.into(viewHolder.imageViewBackground); .into(viewHolder.imageViewBackground);
} else { } else {
Glide.with(viewHolder.imageViewBackground.getContext()) Glide.with(viewHolder.imageViewBackground.getContext())
.load(glideUrl) .load(url)
.thumbnail(0.1f) .thumbnail(0.1f)
.apply(new RequestOptions().transform(new BlurTransformation(50, 3))) .apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
.into(viewHolder.imageViewBackground); .into(viewHolder.imageViewBackground);
@ -206,14 +200,9 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
final EditText input = popup_media_description.findViewById(R.id.media_description); final EditText input = popup_media_description.findViewById(R.id.media_description);
input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)}); input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)});
final ImageView media_picture = popup_media_description.findViewById(R.id.media_picture); 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()) Glide.with(contextWeakReference.get())
.asBitmap() .asBitmap()
.load(glideUrl) .load(attachment.getUrl())
.into(new CustomTarget<Bitmap>() { .into(new CustomTarget<Bitmap>() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override @Override

View File

@ -24,7 +24,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;