5959import java .util .ArrayList ;
6060import java .util .Date ;
6161import java .util .List ;
62+ import java .util .regex .Matcher ;
63+ import java .util .regex .Pattern ;
6264
6365import butterknife .Bind ;
6466import 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 );
0 commit comments