2424import android .annotation .SuppressLint ;
2525import android .annotation .TargetApi ;
2626import android .content .Context ;
27+ import android .graphics .Bitmap ;
2728import android .os .AsyncTask ;
2829import android .os .Build ;
2930import android .os .Bundle ;
3031import android .support .v4 .app .Fragment ;
3132import android .text .format .DateUtils ;
3233import android .util .Log ;
3334import android .view .LayoutInflater ;
35+ import android .view .MotionEvent ;
3436import android .view .View ;
3537import android .view .ViewGroup ;
38+ import android .webkit .ConsoleMessage ;
3639import android .webkit .WebChromeClient ;
3740import android .webkit .WebSettings ;
3841import android .webkit .WebView ;
4447
4548import java .io .File ;
4649import java .io .InputStream ;
50+ import java .util .ArrayList ;
4751import java .util .Date ;
4852import java .util .List ;
53+ import java .util .Stack ;
4954
5055import butterknife .ButterKnife ;
5156import butterknife .InjectView ;
@@ -68,6 +73,8 @@ public class NewsDetailFragment extends Fragment {
6873 @ InjectView (R .id .progressBarLoading ) ProgressBar mProgressBarLoading ;
6974 @ InjectView (R .id .progressbar_webview ) ProgressBar mProgressbarWebView ;
7075 private int section_number ;
76+ public List <String > urls = new ArrayList <>();
77+
7178
7279 public NewsDetailFragment () {
7380 //setRetainInstance(true);
@@ -196,6 +203,8 @@ public static void SetSoftwareRenderModeForWebView(String htmlPage, WebView webV
196203 }
197204
198205
206+ boolean changedUrl = false ;
207+
199208 @ SuppressLint ("SetJavaScriptEnabled" )
200209 private void init_webView ()
201210 {
@@ -222,6 +231,13 @@ private void init_webView()
222231 mWebView .addJavascriptInterface (new WebViewLinkLongClickInterface (getActivity ()), "Android" );
223232
224233 mWebView .setWebChromeClient (new WebChromeClient () {
234+ @ Override
235+ public boolean onConsoleMessage (ConsoleMessage cm ) {
236+ Log .v (TAG , cm .message () + " at " + cm .sourceId () + ":" + cm .lineNumber ());
237+ return true ;
238+ }
239+
240+ @ Override
225241 public void onProgressChanged (WebView view , int progress ) {
226242 if (progress < 100 && mProgressbarWebView .getVisibility () == ProgressBar .GONE ) {
227243 mProgressbarWebView .setVisibility (ProgressBar .VISIBLE );
@@ -231,12 +247,12 @@ public void onProgressChanged(WebView view, int progress) {
231247 mProgressbarWebView .setVisibility (ProgressBar .GONE );
232248
233249 //The following three lines are a workaround for websites which don't use a background colour
234- NewsDetailActivity ndActivity = ((NewsDetailActivity )getActivity ());
250+ NewsDetailActivity ndActivity = ((NewsDetailActivity ) getActivity ());
235251 mWebView .setBackgroundColor (getResources ().getColor (R .color .slider_listview_text_color_dark_theme ));
236252 ndActivity .mViewPager .setBackgroundColor (getResources ().getColor (R .color .slider_listview_text_color_dark_theme ));
237253
238254
239- if (ThemeChooser .isDarkTheme (getActivity ())) {
255+ if (ThemeChooser .isDarkTheme (getActivity ())) {
240256 mWebView .setBackgroundColor (getResources ().getColor (android .R .color .transparent ));
241257 }
242258
@@ -246,9 +262,36 @@ public void onProgressChanged(WebView view, int progress) {
246262 }
247263 });
248264
265+
249266 mWebView .setWebViewClient (new WebViewClient () {
250267
251- });
268+ @ Override
269+ public void onPageStarted (WebView view , String url , Bitmap favicon ) {
270+ if (changedUrl ) {
271+ changedUrl = false ;
272+
273+ if (!url .equals ("file:///android_asset/" ) && (urls .isEmpty () || !urls .get (0 ).equals (url ))) {
274+ urls .add (0 , url );
275+
276+ Log .v (TAG , "Page finished (added): " + url );
277+ }
278+ }
279+
280+ super .onPageStarted (view , url , favicon );
281+ }
282+ });
283+
284+ mWebView .setOnTouchListener (new View .OnTouchListener () {
285+
286+ @ Override
287+ public boolean onTouch (View v , MotionEvent event ) {
288+ if (v .getId () == R .id .webview && event .getAction () == MotionEvent .ACTION_DOWN ) {
289+ changedUrl = true ;
290+ }
291+
292+ return false ;
293+ }
294+ });
252295 }
253296
254297
@@ -294,7 +337,7 @@ public static String getHtmlPage(Context context, RssItem rssItem, boolean showH
294337 builder .append ("<link rel=\" stylesheet\" type=\" text/css\" href=\" web.css\" />" );
295338 builder .append ("<style type=\" text/css\" >" );
296339 builder .append (String .format (
297- "#top_section { border-left: 4px solid %s; border-bottom: 1px solid %s; background: %s }" ,
340+ "#top_section { border-left: 4px solid %s; border-bottom: 1px solid %s; background: %s }" ,
298341 ColorHelper .getCssColor (feedColor ),
299342 ColorHelper .getCssColor (colors [0 ]),
300343 ColorHelper .getCssColor (colors [1 ]))
0 commit comments