Skip to content

Commit 88ae44e

Browse files
Fix #511 - Prevent preload of videos
1 parent d1f425a commit 88ae44e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
import java.util.ArrayList;
6060
import java.util.Date;
6161
import java.util.List;
62+
import java.util.regex.Matcher;
63+
import java.util.regex.Pattern;
6264

6365
import butterknife.Bind;
6466
import butterknife.ButterKnife;
@@ -405,8 +407,9 @@ public static String getHtmlPage(Context context, RssItem rssItem, boolean showH
405407
String body_id;
406408
if(ThemeChooser.isDarkTheme(context)) {
407409
body_id = "darkTheme";
408-
} else
410+
} else {
409411
body_id = "lightTheme";
412+
}
410413

411414
boolean isRightToLeft = context.getResources().getBoolean(R.bool.is_right_to_left);
412415
String rtlClass = isRightToLeft ? "rtl" : "";
@@ -461,8 +464,15 @@ public static String getHtmlPage(Context context, RssItem rssItem, boolean showH
461464
}
462465

463466
String description = rssItem.getBody();
467+
description = getDescriptionWithCachedImages(description).trim();
468+
//StopWatch stopWatch = new StopWatch();
469+
// stopWatch.start();
470+
description = removePreloadAttributeFromVideos(description);
471+
//stopWatch.stop();
472+
//Log.d("NewsDetailFragment", "Time needed for removing preload attribute: " + stopWatch.toString() + " - " + feedTitle);
473+
464474
builder.append("<div id=\"content\">");
465-
builder.append(getDescriptionWithCachedImages(description).trim());
475+
builder.append(description);
466476
builder.append("</div>");
467477

468478
builder.append("</body></html>");
@@ -473,6 +483,21 @@ public static String getHtmlPage(Context context, RssItem rssItem, boolean showH
473483
}
474484

475485

486+
private static Pattern PATTERN_PRELOAD_VIDEOS = Pattern.compile("(<video[^>]*)(preload=\".*?\")");
487+
private static String removePreloadAttributeFromVideos(String text) {
488+
Matcher m = PATTERN_PRELOAD_VIDEOS.matcher(text);
489+
if(m.find()) {
490+
StringBuffer sb = new StringBuffer();
491+
do {
492+
//$1 represents the 1st group
493+
m.appendReplacement(sb, "$1" + "preload=\"none\"");
494+
} while (m.find());
495+
m.appendTail(sb);
496+
text = sb.toString();
497+
}
498+
return text;
499+
}
500+
476501
private static String getDescriptionWithCachedImages(String text)
477502
{
478503
List<String> links = ImageHandler.getImageLinksFromText(text);

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Updates
9292
0.9.9.3 (Google Play)
9393
---------------------
9494
- Critical bug fix - <a href="https://github.com/owncloud/News-Android-App/issues/539">#539 Can not sync with Nextcloud 11 beta 1</a>
95+
- Bug fix - <a href="https://github.com/owncloud/News-Android-App/issues/511">#511 Prevent preload of videos</a>
9596
9697
9798
0.9.9.2 (Google Play)

0 commit comments

Comments
 (0)