bug fix
This commit is contained in:
parent
713766c032
commit
590f0654dc
|
@ -1,6 +1,7 @@
|
|||
package org.nuclearfog.twidda.adapter.holder;
|
||||
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -14,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import com.squareup.picasso.MemoryPolicy;
|
||||
import com.squareup.picasso.NetworkPolicy;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
|
@ -28,6 +30,11 @@ import org.nuclearfog.twidda.model.Card;
|
|||
*/
|
||||
public class CardHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
/**
|
||||
* empty placeholder image color
|
||||
*/
|
||||
private static final int EMPTY_COLOR = 0x1f000000;
|
||||
|
||||
/**
|
||||
* link text background transparency
|
||||
*/
|
||||
|
@ -102,8 +109,10 @@ public class CardHolder extends ViewHolder implements OnClickListener {
|
|||
textSpan.setSpan(new StyleSpan(Typeface.BOLD), 0, Math.min(textStr.length() - 1, TITLE_MAX_LEN), 0);
|
||||
linkText.setText(textSpan);
|
||||
if (settings.imagesEnabled() && !card.getImageUrl().isEmpty()) {
|
||||
picasso.load(card.getImageUrl()).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).into(preview);
|
||||
} // todo add placeholder if image loading is disabled
|
||||
picasso.load(card.getImageUrl()).networkPolicy(NetworkPolicy.NO_STORE).memoryPolicy(MemoryPolicy.NO_STORE).into(preview);
|
||||
} else {
|
||||
preview.setImageDrawable(new ColorDrawable(EMPTY_COLOR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.nuclearfog.twidda.adapter.holder;
|
||||
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -10,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import com.squareup.picasso.MemoryPolicy;
|
||||
import com.squareup.picasso.NetworkPolicy;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
|
@ -23,6 +25,11 @@ import org.nuclearfog.twidda.model.Media;
|
|||
*/
|
||||
public class PreviewHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
/**
|
||||
* empty placeholder image color
|
||||
*/
|
||||
private static final int EMPTY_COLOR = 0x1f000000;
|
||||
|
||||
private ImageView previewImage, playIcon;
|
||||
|
||||
private Picasso picasso;
|
||||
|
@ -32,12 +39,12 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
|
|||
|
||||
public PreviewHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_preview, parent, false));
|
||||
previewImage = itemView.findViewById(R.id.item_preview_image);
|
||||
playIcon = itemView.findViewById(R.id.item_preview_play);
|
||||
previewImage.getLayoutParams().width = parent.getMeasuredHeight();
|
||||
this.picasso = picasso;
|
||||
this.settings = settings;
|
||||
|
||||
previewImage = itemView.findViewById(R.id.item_preview_image);
|
||||
playIcon = itemView.findViewById(R.id.item_preview_play);
|
||||
previewImage.getLayoutParams().width = parent.getMeasuredHeight();
|
||||
previewImage.setOnClickListener(this);
|
||||
}
|
||||
|
||||
|
@ -60,9 +67,9 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
|
|||
public void setContent(Media media) {
|
||||
if (settings.imagesEnabled()) {
|
||||
if (!media.getPreviewUrl().isEmpty()) {
|
||||
picasso.load(media.getPreviewUrl()).memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE).error(R.drawable.no_image).into(previewImage);
|
||||
picasso.load(media.getPreviewUrl()).networkPolicy(NetworkPolicy.NO_STORE).memoryPolicy(MemoryPolicy.NO_STORE).error(R.drawable.no_image).into(previewImage);
|
||||
} else {
|
||||
previewImage.setImageResource(R.drawable.no_image);
|
||||
previewImage.setImageDrawable(new ColorDrawable(EMPTY_COLOR));
|
||||
}
|
||||
}// todo add placeholder if image load is disabled
|
||||
if (media.getMediaType() == Media.VIDEO || media.getMediaType() == Media.GIF) {
|
||||
|
|
|
@ -1183,7 +1183,7 @@ public class Twitter implements Connection {
|
|||
try {
|
||||
params.add(TweetV2.FIELDS_TWEET);
|
||||
params.add(TweetV2.FIELDS_EXPANSION);
|
||||
params.add(UserV2.USER_FIELDS);
|
||||
params.add(UserV2.FIELDS_USER);
|
||||
params.add(MediaV2.FIELDS_MEDIA);
|
||||
params.add(PollV2.FIELDS_POLL);
|
||||
params.add(LocationV2.FIELDS_PLACE);
|
||||
|
@ -1196,9 +1196,12 @@ public class Twitter implements Connection {
|
|||
if (data != null && data.length() > 0) {
|
||||
List<Status> tweets = new ArrayList<>(data.length() + 1);
|
||||
UserV2Map userMap = new UserV2Map(json, settings.getLogin().getId());
|
||||
MediaV2Map mediaMap = new MediaV2Map(json);
|
||||
PollV2Map pollMap = new PollV2Map(json);
|
||||
LocationV2Map locationMap = new LocationV2Map(json);
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
try {
|
||||
Status item = new TweetV2(data.getJSONObject(i), userMap);
|
||||
Status item = new TweetV2(data.getJSONObject(i), userMap, mediaMap, pollMap, locationMap, null);
|
||||
tweets.add(item);
|
||||
} catch (JSONException e) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
@ -1269,7 +1272,7 @@ public class Twitter implements Connection {
|
|||
else
|
||||
params.add(TweetV2.FIELDS_TWEET);
|
||||
params.add(TweetV2.FIELDS_EXPANSION);
|
||||
params.add(UserV2.USER_FIELDS);
|
||||
params.add(UserV2.FIELDS_USER);
|
||||
params.add(MediaV2.FIELDS_MEDIA);
|
||||
params.add(PollV2.FIELDS_POLL);
|
||||
params.add(LocationV2.FIELDS_PLACE);
|
||||
|
@ -1397,7 +1400,7 @@ public class Twitter implements Connection {
|
|||
private Users getUsers2(String endpoint) throws TwitterException {
|
||||
try {
|
||||
List<String> params = new ArrayList<>();
|
||||
params.add("user.fields=" + UserV2.USER_FIELDS);
|
||||
params.add("user.fields=" + UserV2.FIELDS_USER);
|
||||
Response response = get(endpoint, params);
|
||||
ResponseBody body = response.body();
|
||||
if (body != null && response.code() == 200) {
|
||||
|
|
|
@ -23,7 +23,6 @@ public class MediaV1 implements Media {
|
|||
|
||||
private int type = NONE;
|
||||
private String url = "";
|
||||
private String preview;
|
||||
private String key;
|
||||
|
||||
/**
|
||||
|
@ -31,7 +30,6 @@ public class MediaV1 implements Media {
|
|||
*/
|
||||
public MediaV1(JSONObject json) throws JSONException {
|
||||
String type = json.getString("type");
|
||||
preview = json.getString("media_url_https");
|
||||
key = json.getString("id_str");
|
||||
switch (type) {
|
||||
case "photo":
|
||||
|
@ -88,7 +86,7 @@ public class MediaV1 implements Media {
|
|||
|
||||
@Override
|
||||
public String getPreviewUrl() {
|
||||
return preview;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,7 +42,8 @@ public class MediaV2 implements Media {
|
|||
switch (typeStr) {
|
||||
case "photo":
|
||||
url = mediaItem.optString("url");
|
||||
preview = url; // fixme: currently Twitter doesn't support preview for images.
|
||||
if (preview.isEmpty())// fixme: currently Twitter doesn't support preview for images.
|
||||
preview = url;
|
||||
type = PHOTO;
|
||||
break;
|
||||
|
||||
|
|
|
@ -75,14 +75,6 @@ public class TweetV2 implements Status {
|
|||
private Media[] medias = {};
|
||||
private Card[] cards = {};
|
||||
|
||||
/**
|
||||
* @param json tweet json format
|
||||
* @param userMap map containing user instances
|
||||
*/
|
||||
public TweetV2(JSONObject json, UserV2Map userMap) throws JSONException {
|
||||
this(json, userMap, null, null, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param json tweet json format
|
||||
* @param userMap map containing user instances
|
||||
|
@ -219,7 +211,6 @@ public class TweetV2 implements Status {
|
|||
favorited = tweetCompat.isFavorited();
|
||||
// fixme: for any reason Twitter API 2.0 doesn't return the attributes below
|
||||
source = tweetCompat.getSource();
|
||||
medias = tweetCompat.getMedia();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class UserV2 implements User {
|
|||
/**
|
||||
* extra parameters required to fetch additional data
|
||||
*/
|
||||
public static final String USER_FIELDS = "user.fields=created_at%2Cdescription%2Centities%2Cid%2Clocation%2Cname%2Cprofile_image_url" +
|
||||
public static final String FIELDS_USER = "user.fields=created_at%2Cdescription%2Centities%2Cid%2Clocation%2Cname%2Cprofile_image_url" +
|
||||
"%2Cprotected%2Cpublic_metrics%2Curl%2Cusername%2Cverified";
|
||||
|
||||
private long id;
|
||||
|
|
Loading…
Reference in New Issue