Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class RssItemHeadlineThumbnailViewHolder internal constructor(
binding.starImageview.visibility = if (rssItem.starred_temp) View.VISIBLE else View.GONE
binding.imgViewThumbnail.colorFilter = null
val mediaThumbnail = rssItem.mediaThumbnail
if (mediaThumbnail.isNullOrEmpty()) {
if (!mediaThumbnail.isNullOrEmpty()) {
binding.imgViewThumbnail.visibility = View.VISIBLE
mGlide
.load(mediaThumbnail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public class ImageHandler {
private static final Pattern patternHref = Pattern.compile("<a[^>]*>");
private static final Pattern patternHrefLink = Pattern.compile("href=\"(.*?)\"");

public static List<String> getImageLinksFromText(String articleUrl, String text)
{
public static List<String> getImageLinksFromText(String articleUrl, String text) {
List<String> links = new ArrayList<>();

Matcher matcher = patternImg.matcher(text);
Expand All @@ -50,15 +49,18 @@ public static List<String> getImageLinksFromText(String articleUrl, String text)
Matcher matcherSrcLink = patternImgSrcLink.matcher(matcher.group());
if(matcherSrcLink.find()) {
String link = matcherSrcLink.group(1);
if(link != null && link.startsWith("//")) { //Maybe the text contains image urls without http or https prefix.
link = "https:" + link;
}

// the android universal image loader doesn't support svg images. Therefore we don't want to load them through UIL
if(link.endsWith(".svg")) {
Log.d(TAG, "detected unsupported svg image in article: " + articleUrl + " -> " + link);
} else {
links.add(link);
if (link != null) {
if (link.startsWith("//")) { //Maybe the text contains image urls without http or https prefix.
link = "https:" + link;
}

// the android universal image loader doesn't support svg images. Therefore we don't want to load them through UIL
if (link.endsWith(".svg")) {
Log.d(TAG, "detected unsupported svg image in article: " + articleUrl + " -> " + link);
} else {
links.add(link);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ static RssItem parseItem(JsonObject e) {
rssItem.setBody(content);

String mediaThumbnail = getStringOrEmpty("mediaThumbnail", e); // Possible XSS Fields
// in case the server doesn't provide a mediaThumbnail - the app will try to find one
if(mediaThumbnail.isEmpty()) {
List<String> images = ImageHandler.getImageLinksFromText(url, content);
if(images.size() > 0) {
// Log.d(TAG, "extracted mediaThumbnail from body");
if (!images.isEmpty()) {
mediaThumbnail = images.get(0);
// Log.d(TAG, "extracted mediaThumbnail from body" + mediaThumbnail);
} else {
Log.d(TAG, "extracting mediaThumbnail from body failed - no images detected");
Log.d(TAG, "extraction of mediaThumbnail not possible - no images detected");
}
}
rssItem.setMediaThumbnail(mediaThumbnail);
Expand Down