Skip to content

Commit

Permalink
Fix #511 - Prevent preload of videos
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Development committed Dec 17, 2016
1 parent d1f425a commit 88ae44e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.Bind;
import butterknife.ButterKnife;
Expand Down Expand Up @@ -405,8 +407,9 @@ public static String getHtmlPage(Context context, RssItem rssItem, boolean showH
String body_id;
if(ThemeChooser.isDarkTheme(context)) {
body_id = "darkTheme";
} else
} else {
body_id = "lightTheme";
}

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

String description = rssItem.getBody();
description = getDescriptionWithCachedImages(description).trim();
//StopWatch stopWatch = new StopWatch();
// stopWatch.start();
description = removePreloadAttributeFromVideos(description);
//stopWatch.stop();
//Log.d("NewsDetailFragment", "Time needed for removing preload attribute: " + stopWatch.toString() + " - " + feedTitle);

builder.append("<div id=\"content\">");
builder.append(getDescriptionWithCachedImages(description).trim());
builder.append(description);
builder.append("</div>");

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


private static Pattern PATTERN_PRELOAD_VIDEOS = Pattern.compile("(<video[^>]*)(preload=\".*?\")");
private static String removePreloadAttributeFromVideos(String text) {
Matcher m = PATTERN_PRELOAD_VIDEOS.matcher(text);
if(m.find()) {
StringBuffer sb = new StringBuffer();
do {
//$1 represents the 1st group
m.appendReplacement(sb, "$1" + "preload=\"none\"");
} while (m.find());
m.appendTail(sb);
text = sb.toString();
}
return text;
}

private static String getDescriptionWithCachedImages(String text)
{
List<String> links = ImageHandler.getImageLinksFromText(text);
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Updates
0.9.9.3 (Google Play)
---------------------
- Critical bug fix - <a href="https://github.com/owncloud/News-Android-App/issues/539">#539 Can not sync with Nextcloud 11 beta 1</a>
- Bug fix - <a href="https://github.com/owncloud/News-Android-App/issues/511">#511 Prevent preload of videos</a>
0.9.9.2 (Google Play)
Expand Down

0 comments on commit 88ae44e

Please sign in to comment.