fix for too small flavor images reloading more than necessary
This commit is contained in:
parent
1c9dbba4f5
commit
3729842e7b
@ -69,6 +69,7 @@ import org.fox.ttrss.types.ArticleList;
|
|||||||
import org.fox.ttrss.types.Feed;
|
import org.fox.ttrss.types.Feed;
|
||||||
import org.fox.ttrss.util.HeadlinesRequest;
|
import org.fox.ttrss.util.HeadlinesRequest;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
@ -687,7 +688,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
public ImageView textImage;
|
public ImageView textImage;
|
||||||
public ImageView textChecked;
|
public ImageView textChecked;
|
||||||
public View headlineHeader;
|
public View headlineHeader;
|
||||||
|
|
||||||
public boolean flavorImageEmbedded;
|
public boolean flavorImageEmbedded;
|
||||||
|
public Document articleDoc;
|
||||||
|
public Element flavorImage;
|
||||||
|
public int flavorImageCount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ArticleListAdapter extends ArrayAdapter<Article> {
|
private class ArticleListAdapter extends ArrayAdapter<Article> {
|
||||||
@ -785,11 +791,11 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
} else {
|
} else {
|
||||||
final Drawable textDrawable = m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title));
|
final Drawable textDrawable = m_drawableBuilder.build(tmp, m_colorGenerator.getColor(item.title));
|
||||||
|
|
||||||
if (item.flavorImage == null) {
|
if (holder.flavorImage == null) {
|
||||||
holder.textImage.setImageDrawable(textDrawable);
|
holder.textImage.setImageDrawable(textDrawable);
|
||||||
holder.textImage.setTag(null);
|
holder.textImage.setTag(null);
|
||||||
} else {
|
} else {
|
||||||
String imgSrc = item.flavorImage.attr("src");
|
String imgSrc = holder.flavorImage.attr("src");
|
||||||
|
|
||||||
// retarded schema-less urls
|
// retarded schema-less urls
|
||||||
if (imgSrc.indexOf("//") == 0)
|
if (imgSrc.indexOf("//") == 0)
|
||||||
@ -915,8 +921,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ?
|
String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ?
|
||||||
articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent;
|
articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent;
|
||||||
|
|
||||||
if (article.articleDoc == null)
|
if (holder.articleDoc == null)
|
||||||
article.articleDoc = Jsoup.parse(articleContentReduced);
|
holder.articleDoc = Jsoup.parse(articleContentReduced);
|
||||||
|
|
||||||
// block footer clicks to make button/selection clicking easier
|
// block footer clicks to make button/selection clicking easier
|
||||||
if (holder.headlineFooter != null) {
|
if (holder.headlineFooter != null) {
|
||||||
@ -928,9 +934,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showFlavorImage && article.flavorImage == null) {
|
if (showFlavorImage && holder.flavorImage == null) {
|
||||||
|
|
||||||
Elements imgs = article.articleDoc.select("img");
|
Elements imgs = holder.articleDoc.select("img");
|
||||||
|
|
||||||
for (Element tmp : imgs) {
|
for (Element tmp : imgs) {
|
||||||
try {
|
try {
|
||||||
@ -939,7 +945,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_SIZE && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_SIZE) {
|
if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_SIZE && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_SIZE) {
|
||||||
article.flavorImage = tmp;
|
holder.flavorImage = tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -948,10 +954,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (article.flavorImage == null)
|
if (holder.flavorImage == null)
|
||||||
article.flavorImage = imgs.first();
|
holder.flavorImage = imgs.first();
|
||||||
|
|
||||||
article.flavorImageCount = imgs.size();
|
holder.flavorImageCount = imgs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (holder.textImage != null) {
|
if (holder.textImage != null) {
|
||||||
@ -973,8 +979,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
});
|
});
|
||||||
ViewCompat.setTransitionName(holder.textImage, "TRANSITION:ARTICLE_IMAGES_PAGER");
|
ViewCompat.setTransitionName(holder.textImage, "TRANSITION:ARTICLE_IMAGES_PAGER");
|
||||||
|
|
||||||
if (article.flavorImage != null) {
|
if (holder.flavorImage != null) {
|
||||||
final String imgSrcFirst = article.flavorImage.attr("src");
|
final String imgSrcFirst = holder.flavorImage.attr("src");
|
||||||
|
|
||||||
holder.textImage.setOnLongClickListener(new View.OnLongClickListener() {
|
holder.textImage.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -1080,7 +1086,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
excerpt = excerpt.replace("]]>", "");
|
excerpt = excerpt.replace("]]>", "");
|
||||||
excerpt = Jsoup.parse(excerpt).text();
|
excerpt = Jsoup.parse(excerpt).text();
|
||||||
} else {
|
} else {
|
||||||
excerpt = article.articleDoc.text();
|
excerpt = holder.articleDoc.text();
|
||||||
|
|
||||||
if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH)
|
if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH)
|
||||||
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…";
|
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…";
|
||||||
@ -1124,9 +1130,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
|
|
||||||
boolean videoFound = false;
|
boolean videoFound = false;
|
||||||
|
|
||||||
if (showFlavorImage && article.articleDoc != null && holder.flavorVideoKindView != null) {
|
if (showFlavorImage && holder.articleDoc != null && holder.flavorVideoKindView != null) {
|
||||||
Element video = article.articleDoc.select("video").first();
|
Element video = holder.articleDoc.select("video").first();
|
||||||
Element ytframe = article.articleDoc.select("iframe[src*=youtube.com/embed/]").first();
|
Element ytframe = holder.articleDoc.select("iframe[src*=youtube.com/embed/]").first();
|
||||||
|
|
||||||
if (video != null) {
|
if (video != null) {
|
||||||
try {
|
try {
|
||||||
@ -1324,10 +1330,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
|
|
||||||
if (!videoFound && showFlavorImage && holder.flavorImageView != null) {
|
if (!videoFound && showFlavorImage && holder.flavorImageView != null) {
|
||||||
|
|
||||||
if (article.articleDoc != null) {
|
if (holder.articleDoc != null) {
|
||||||
|
|
||||||
if (article.flavorImage != null) {
|
if (holder.flavorImage != null) {
|
||||||
String imgSrc = article.flavorImage.attr("src");
|
String imgSrc = holder.flavorImage.attr("src");
|
||||||
final String imgSrcFirst = imgSrc;
|
final String imgSrcFirst = imgSrc;
|
||||||
|
|
||||||
// retarded schema-less urls
|
// retarded schema-less urls
|
||||||
@ -1376,17 +1382,19 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
if (!isAdded() || bitmap == null) return;
|
if (!isAdded() || bitmap == null) return;
|
||||||
|
|
||||||
holder.flavorImageLoadingBar.setVisibility(View.GONE);
|
holder.flavorImageLoadingBar.setVisibility(View.GONE);
|
||||||
|
holder.flavorImageView.setTag(finalImgSrc);
|
||||||
|
|
||||||
if (bitmap.getWidth() > FLAVOR_IMG_MIN_SIZE && bitmap.getHeight() > FLAVOR_IMG_MIN_SIZE) {
|
if (bitmap.getWidth() > FLAVOR_IMG_MIN_SIZE && bitmap.getHeight() > FLAVOR_IMG_MIN_SIZE) {
|
||||||
holder.flavorImageView.setVisibility(View.VISIBLE);
|
holder.flavorImageView.setVisibility(View.VISIBLE);
|
||||||
holder.flavorImageView.setTag(finalImgSrc);
|
|
||||||
|
|
||||||
if (article.flavorImageCount > 1) {
|
if (holder.flavorImageCount > 1) {
|
||||||
holder.flavorVideoKindView.setVisibility(View.VISIBLE);
|
holder.flavorVideoKindView.setVisibility(View.VISIBLE);
|
||||||
holder.flavorVideoKindView.setImageResource(R.drawable.ic_image_album);
|
holder.flavorVideoKindView.setImageResource(R.drawable.ic_image_album);
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeRepositionFlavorImage(view, bitmap, holder);
|
maybeRepositionFlavorImage(view, bitmap, holder);
|
||||||
|
} else {
|
||||||
|
holder.flavorImageView.setImageDrawable(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1421,7 +1429,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
} else {
|
} else {
|
||||||
holder.flavorImageView.setVisibility(View.VISIBLE);
|
holder.flavorImageView.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (article.flavorImageCount > 1) {
|
if (holder.flavorImageCount > 1) {
|
||||||
holder.flavorVideoKindView.setVisibility(View.VISIBLE);
|
holder.flavorVideoKindView.setVisibility(View.VISIBLE);
|
||||||
holder.flavorVideoKindView.setImageResource(R.drawable.ic_image_album);
|
holder.flavorVideoKindView.setImageResource(R.drawable.ic_image_album);
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,6 @@ package org.fox.ttrss.types;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -34,11 +31,6 @@ public class Article implements Parcelable {
|
|||||||
public String note;
|
public String note;
|
||||||
public boolean selected;
|
public boolean selected;
|
||||||
|
|
||||||
/* not serialized */
|
|
||||||
public Document articleDoc;
|
|
||||||
public Element flavorImage;
|
|
||||||
public int flavorImageCount;
|
|
||||||
|
|
||||||
public Article(Parcel in) {
|
public Article(Parcel in) {
|
||||||
readFromParcel(in);
|
readFromParcel(in);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user