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.text.Html;
import android.text.SpannableString;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.json.JSONArray;
import org.json.JSONException;
@ -42,7 +42,6 @@ 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;
@ -1646,19 +1645,65 @@ public class API {
attachment.setRemote_url(resobj.getString("remote_url"));
} catch (JSONException ignore) {
}
if (attachment.getRemote_url() != null && attachment.getRemote_url().toLowerCase().compareTo("null") == 0) {
attachment.setRemote_url(null);
}
try {
attachment.setPreview_url(resobj.getString("preview_url"));
} catch (JSONException ignore) {
}
if (attachment.getPreview_url() != null && attachment.getPreview_url().toLowerCase().compareTo("null") == 0) {
attachment.setPreview_url(null);
}
try {
attachment.setMeta(resobj.getString("meta"));
} catch (JSONException ignore) {
}
if (attachment.getMeta() != null && attachment.getMeta().toLowerCase().compareTo("null") == 0) {
attachment.setMeta(null);
}
try {
attachment.setText_url(resobj.getString("text_url"));
} 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) {
}
return attachment;
@ -4529,9 +4574,9 @@ public class API {
default:
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_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) {
&& statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION)) {
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String url;
@ -4540,9 +4585,8 @@ public class API {
} else {
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();
if (statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) {
Bundle b = new Bundle();
try {
Status status1 = parseStatuses(context, new JSONObject(resp));
@ -4555,11 +4599,10 @@ public class API {
SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
Status indb = new TimelineCacheDAO(context, db).getSingle(targetedId);
if (indb != null) {
if (indb != null && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT);
new TimelineCacheDAO(context, db).update(targetedId, response, account.getId(), account.getInstance());
}
}
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
@ -4816,22 +4859,38 @@ public class API {
} else {
url = "https://" + Helper.getLiveInstance(context) + "/api/local/status/compose";
jsonObject.addProperty("caption", status.getContent());
jsonObject.addProperty("comments_disabled", status.getContent());
jsonObject.addProperty("comments_disabled", false);
jsonObject.addProperty("cw", status.isSensitive());
jsonObject.addProperty("visibility", status.getVisibility());
String attachments = new Gson().toJson(status.getMedia_attachments());
jsonObject.addProperty("media", attachments);
String attachments = new GsonBuilder().serializeNulls().create().toJson(status.getMedia_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<>();
try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.postJson(url, 10, jsonObject, prefKeyOauthTokenT);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
Status statusreturned = parseStatuses(context, new JSONObject(response));
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) {
setError(e.getStatusCode(), e);
e.printStackTrace();

View File

@ -37,8 +37,12 @@ public class Attachment implements Parcelable {
}
};
private String id;
private int viewId;
private transient int viewId;
private String type;
private String mime;
private String filter_class;
private String filter_name;
private String license;
private String url;
private String remote_url;
private String preview_url;
@ -46,6 +50,7 @@ public class Attachment implements Parcelable {
private String text_url;
private String description;
private String local_path;
private String orientation;
private boolean is_nsfw = false;
public Attachment() {
@ -56,6 +61,10 @@ public class Attachment implements Parcelable {
this.id = in.readString();
this.viewId = in.readInt();
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.remote_url = in.readString();
this.preview_url = in.readString();
@ -63,6 +72,7 @@ public class Attachment implements Parcelable {
this.text_url = in.readString();
this.description = in.readString();
this.local_path = in.readString();
this.orientation = in.readString();
this.is_nsfw = in.readByte() != 0;
}
@ -154,6 +164,46 @@ public class Attachment implements Parcelable {
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
public int describeContents() {
return 0;
@ -164,6 +214,10 @@ public class Attachment implements Parcelable {
dest.writeString(this.id);
dest.writeInt(this.viewId);
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.remote_url);
dest.writeString(this.preview_url);
@ -171,6 +225,7 @@ public class Attachment implements Parcelable {
dest.writeString(this.text_url);
dest.writeString(this.description);
dest.writeString(this.local_path);
dest.writeString(this.orientation);
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));
}
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();
// always check HTTP response code first
if (responseCode >= 200 && responseCode < 400) {

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@ -107,9 +108,14 @@ public class PixelfedAPI {
pixelFedStory.setName(jsonObject.getString("name"));
pixelFedStory.setLink(jsonObject.getString("link"));
pixelFedStory.setLastUpdated(new Date(jsonObject.getLong("lastUpdated")));
if (jsonObject.has("seen") && !jsonObject.isNull("seen")) {
pixelFedStory.setSeen(jsonObject.getBoolean("seen"));
} else {
pixelFedStory.setSeen(false);
}
pixelFedStory.setPixelFedStoryItems(parseStoryItems(jsonObject.getJSONArray("items")));
} catch (JSONException ignored) {
ignored.printStackTrace();
}
return pixelFedStory;
}
@ -158,6 +164,7 @@ public class PixelfedAPI {
pixelFedStoryItem.setExpires_at(new Date(jsonObject.getLong("expires_at")));
pixelFedStoryItem.setSeen(jsonObject.getBoolean("seen"));
} catch (JSONException ignored) {
ignored.printStackTrace();
}
return pixelFedStoryItem;
}
@ -201,7 +208,7 @@ public class PixelfedAPI {
params.put("max_id", max_id);
try {
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.setMax_id(httpsConnection.getMax_id());
pixelFedStories = parseStories(new JSONArray(response));

View File

@ -33,7 +33,6 @@ 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;

View File

@ -732,8 +732,8 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
popup.setOnMenuItemClickListener(item -> {
AlertDialog.Builder builderInner;
final API.StatusAction doAction;
switch (item.getItemId()) {
case R.id.action_redraft:
int itemId = item.getItemId();
if (itemId == R.id.action_redraft) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]);
redraft = true;
@ -742,17 +742,16 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_schedule_boost:
} else if (itemId == R.id.action_schedule_boost) {
scheduleBoost(status);
return true;
case R.id.action_info:
} else if (itemId == R.id.action_info) {
tootInformation(status);
return true;
case R.id.action_open_browser:
} else if (itemId == R.id.action_open_browser) {
Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
return true;
case R.id.action_remove:
} else if (itemId == R.id.action_remove) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.UNSTATUS;
@ -760,21 +759,18 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_block_domain:
} 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));
break;
case R.id.action_mute:
} else if (itemId == R.id.action_mute) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]);
builderInner.setMessage(status.getAccount().getAcct());
doAction = API.StatusAction.MUTE;
break;
case R.id.action_mute_conversation:
} else if (itemId == R.id.action_mute_conversation) {
if (status.isMuted())
doAction = API.StatusAction.UNMUTE_CONVERSATION;
else
@ -782,7 +778,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
new PostActionAsyncTask(context, doAction, status.getId(), PixelfedListAdapter.this);
return true;
case R.id.action_bookmark:
} else if (itemId == R.id.action_bookmark) {
if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) {
status.setBookmarked(!status.isBookmarked());
final SQLiteDatabase db = Sqlite.getInstance(context.getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@ -814,22 +810,21 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
}
}
return true;
case R.id.action_timed_mute:
} else if (itemId == R.id.action_timed_mute) {
timedMuteAction(status);
return true;
case R.id.action_block:
} else if (itemId == R.id.action_block) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[1]);
doAction = API.StatusAction.BLOCK;
break;
case R.id.action_translate:
} else if (itemId == R.id.action_translate) {
int translator = sharedpreferences1.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_LIBRETRANSLATE);
if (translator == Helper.TRANS_NONE)
Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show();
else
translateToot(status);
return true;
case R.id.action_report:
} else if (itemId == R.id.action_report) {
builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[2]);
doAction = API.StatusAction.REPORT;
@ -837,8 +832,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else
builderInner.setMessage(Html.fromHtml(status.getContent()));
break;
case R.id.action_copy_link:
} 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());
@ -847,7 +841,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show();
}
return true;
case R.id.action_share:
} 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;
@ -885,7 +879,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
default:
} else {
return true;
}

View File

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

View File

@ -24,7 +24,6 @@ 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;
@ -119,19 +118,14 @@ 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(glideUrl)
.load(url)
.thumbnail(0.1f)
.into(viewHolder.imageViewBackground);
} else {
Glide.with(viewHolder.imageViewBackground.getContext())
.load(glideUrl)
.load(url)
.thumbnail(0.1f)
.apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
.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);
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(glideUrl)
.load(attachment.getUrl())
.into(new CustomTarget<Bitmap>() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override

View File

@ -24,7 +24,6 @@ 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;