diff options
-rw-r--r-- | AndroidManifest.xml | 4 | ||||
-rw-r--r-- | src/org/fox/ttrss/ArticleFragment.java | 494 | ||||
-rw-r--r-- | src/org/fox/ttrss/FeedsFragment.java | 1 | ||||
-rw-r--r-- | src/org/fox/ttrss/HeadlinesActivity.java | 4 | ||||
-rw-r--r-- | src/org/fox/ttrss/HeadlinesFragment.java | 2 | ||||
-rw-r--r-- | src/org/fox/ttrss/offline/OfflineArticleFragment.java | 44 | ||||
-rw-r--r-- | src/org/fox/ttrss/offline/OfflineFeedsFragment.java | 20 | ||||
-rw-r--r-- | src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java | 20 |
8 files changed, 261 insertions, 328 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index aae0eff8..fbd5b369 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.fox.ttrss" - android:versionCode="181" - android:versionName="1.8.1" > + android:versionCode="185" + android:versionName="1.8.5" > <uses-sdk android:minSdkVersion="8" diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index de15d254..4a99377f 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -95,256 +95,245 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl m_article = savedInstanceState.getParcelable("article"); } - final View view = inflater.inflate(R.layout.article_fragment, container, false); - - WebView content = (WebView) view.findViewById(R.id.content); - - if (content != null) content.setVisibility(View.INVISIBLE); + View view = inflater.inflate(R.layout.article_fragment, container, false); - // prevent flicker in ics - if (android.os.Build.VERSION.SDK_INT >= 11) { - content.setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } - - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - if (isAdded()) { + if (m_article != null) { + + TextView title = (TextView)view.findViewById(R.id.title); + + if (title != null) { - if (m_article != null) { - - TextView title = (TextView)view.findViewById(R.id.title); - - if (title != null) { - - String titleStr; - - if (m_article.title.length() > 200) - titleStr = m_article.title.substring(0, 200) + "..."; - else - titleStr = m_article.title; - - - title.setText(Html.fromHtml(titleStr)); - //title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - title.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - try { - URL url = new URL(m_article.link.trim()); - String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), - url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString(); - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); - startActivity(intent); - } catch (Exception e) { - e.printStackTrace(); - m_activity.toast(R.string.error_other_error); - } - } - }); - - registerForContextMenu(title); + String titleStr; + + if (m_article.title.length() > 200) + titleStr = m_article.title.substring(0, 200) + "..."; + else + titleStr = m_article.title; + + + title.setText(Html.fromHtml(titleStr)); + //title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + title.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + try { + URL url = new URL(m_article.link.trim()); + String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), + url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString(); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); + startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + m_activity.toast(R.string.error_other_error); } - - TextView comments = (TextView)view.findViewById(R.id.comments); - - if (comments != null) { - if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) { - String commentsTitle = getString(R.string.article_comments, m_article.comments_count); - comments.setText(commentsTitle); - //comments.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - comments.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - try { - URL url = new URL((m_article.comments_link != null && m_article.comments_link.length() > 0) ? - m_article.comments_link : m_article.link); - String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), - url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString(); - Intent intent = new Intent(Intent.ACTION_VIEW, - Uri.parse(uri)); - startActivity(intent); - } catch (Exception e) { - e.printStackTrace(); - m_activity.toast(R.string.error_other_error); - } - } - }); - - } else { - comments.setVisibility(View.GONE); + } + }); + + registerForContextMenu(title); + } + + TextView comments = (TextView)view.findViewById(R.id.comments); + + if (comments != null) { + if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) { + String commentsTitle = getString(R.string.article_comments, m_article.comments_count); + comments.setText(commentsTitle); + //comments.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + comments.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + try { + URL url = new URL((m_article.comments_link != null && m_article.comments_link.length() > 0) ? + m_article.comments_link : m_article.link); + String uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), + url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString(); + Intent intent = new Intent(Intent.ACTION_VIEW, + Uri.parse(uri)); + startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + m_activity.toast(R.string.error_other_error); } } - - WebView web = (WebView)view.findViewById(R.id.content); - - if (web != null) { - registerForContextMenu(web); - - web.setWebChromeClient(new WebChromeClient() { - @Override - public void onProgressChanged(WebView view, int progress) { - m_activity.setProgress(Math.round(((float)progress / 100f) * 10000)); - if (progress == 100) { - m_activity.setProgressBarVisibility(false); - } - } - }); - - web.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - return m_detector.onTouchEvent(event); - } - }); - - String content; - String cssOverride = ""; - - WebSettings ws = web.getSettings(); - ws.setSupportZoom(true); - ws.setBuiltInZoomControls(false); + }); + + } else { + comments.setVisibility(View.GONE); + } + } + + WebView web = (WebView)view.findViewById(R.id.content); + + if (web != null) { + registerForContextMenu(web); - web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); + // prevent flicker in ics + if (android.os.Build.VERSION.SDK_INT >= 11) { + web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } - TypedValue tv = new TypedValue(); - getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true); - - if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { - cssOverride = "body { background : transparent; color : #e0e0e0}"; - } else if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK_GRAY")) { - cssOverride = "body { background : transparent; color : #e0e0e0}"; - } else { - cssOverride = "body { background : transparent; }"; - } - web.setBackgroundColor(getResources().getColor(android.R.color.transparent)); - - String hexColor = String.format("#%06X", (0xFFFFFF & tv.data)); - cssOverride += " a:link {color: "+hexColor+";} a:visited { color: "+hexColor+";}"; + web.setWebChromeClient(new WebChromeClient() { + @Override + public void onProgressChanged(WebView view, int progress) { + m_activity.setProgress(Math.round(((float)progress / 100f) * 10000)); + if (progress == 100) { + m_activity.setProgressBarVisibility(false); + } + } + }); + + web.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + return m_detector.onTouchEvent(event); + } + }); + + String content; + String cssOverride = ""; + + WebSettings ws = web.getSettings(); + ws.setSupportZoom(true); + ws.setBuiltInZoomControls(true); + + if (!m_activity.isCompatMode()) + ws.setDisplayZoomControls(false); - cssOverride += " table { width : 100%; }"; - - String articleContent = m_article.content != null ? m_article.content : ""; - - Document doc = Jsoup.parse(articleContent); - - if (doc != null) { - // thanks webview for crashing on <video> tag - Elements videos = doc.select("video"); - - for (Element video : videos) - video.remove(); - - articleContent = doc.toString(); - } - - String align = m_prefs.getBoolean("justify_article_text", true) ? "text-align : justify;" : ""; - - switch (Integer.parseInt(m_prefs.getString("font_size", "0"))) { - case 0: - cssOverride += "body { "+align+" font-size : 14px; } "; - break; - case 1: - cssOverride += "body { "+align+" font-size : 18px; } "; - break; - case 2: - cssOverride += "body { "+align+" font-size : 21px; } "; - break; - } - - content = - "<html>" + - "<head>" + - "<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">" + - "<style type=\"text/css\">" + - "body { padding : 0px; margin : 0px; }" + - cssOverride + - /* "img { max-width : 98%; height : auto; }" + */ - "</style>" + - "</head>" + - "<body>" + articleContent; - - if (m_article.attachments != null && m_article.attachments.size() != 0) { - String flatContent = articleContent.replaceAll("[\r\n]", ""); - boolean hasImages = flatContent.matches(".*?<img[^>+].*?"); - - for (Attachment a : m_article.attachments) { - if (a.content_type != null && a.content_url != null) { - try { - if (a.content_type.indexOf("image") != -1 && - (!hasImages || m_article.always_display_attachments)) { - - URL url = new URL(a.content_url.trim()); - String strUrl = url.toString().trim(); + web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); - content += "<p><img src=\"" + strUrl.replace("\"", "\\\"") + "\"></p>"; - } + TypedValue tv = new TypedValue(); + getActivity().getTheme().resolveAttribute(R.attr.linkColor, tv, true); + + if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK")) { + cssOverride = "body { background : transparent; color : #e0e0e0}"; + } else if (m_prefs.getString("theme", "THEME_DARK").equals("THEME_DARK_GRAY")) { + cssOverride = "body { background : transparent; color : #e0e0e0}"; + } else { + cssOverride = "body { background : transparent; }"; + } + web.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + + String hexColor = String.format("#%06X", (0xFFFFFF & tv.data)); + cssOverride += " a:link {color: "+hexColor+";} a:visited { color: "+hexColor+";}"; - } catch (MalformedURLException e) { - // - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - - content += "<p> </p><p> </p><p> </p><p> </p></body></html>"; - + cssOverride += " table { width : 100%; }"; + + String articleContent = m_article.content != null ? m_article.content : ""; + + Document doc = Jsoup.parse(articleContent); + + if (doc != null) { + // thanks webview for crashing on <video> tag + Elements videos = doc.select("video"); + + for (Element video : videos) + video.remove(); + + articleContent = doc.toString(); + } + + String align = m_prefs.getBoolean("justify_article_text", true) ? "text-align : justify;" : ""; + + switch (Integer.parseInt(m_prefs.getString("font_size", "0"))) { + case 0: + cssOverride += "body { "+align+" font-size : 14px; } "; + break; + case 1: + cssOverride += "body { "+align+" font-size : 18px; } "; + break; + case 2: + cssOverride += "body { "+align+" font-size : 21px; } "; + break; + } + + content = + "<html>" + + "<head>" + + "<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\">" + + "<style type=\"text/css\">" + + "body { padding : 0px; margin : 0px; }" + + cssOverride + + /* "img { max-width : 98%; height : auto; }" + */ + "</style>" + + "</head>" + + "<body>" + articleContent; + + if (m_article.attachments != null && m_article.attachments.size() != 0) { + String flatContent = articleContent.replaceAll("[\r\n]", ""); + boolean hasImages = flatContent.matches(".*?<img[^>+].*?"); + + for (Attachment a : m_article.attachments) { + if (a.content_type != null && a.content_url != null) { try { - web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null); - } catch (RuntimeException e) { - e.printStackTrace(); - } - - if (m_activity.isSmallScreen()) - web.setOnTouchListener(m_gestureListener); - - web.setVisibility(View.VISIBLE); - } - - TextView dv = (TextView)view.findViewById(R.id.date); - - if (dv != null) { - Date d = new Date(m_article.updated * 1000L); - DateFormat df = new SimpleDateFormat("MMM dd, HH:mm"); - dv.setText(df.format(d)); - } - - TextView tagv = (TextView)view.findViewById(R.id.tags); + if (a.content_type.indexOf("image") != -1 && + (!hasImages || m_article.always_display_attachments)) { - if (tagv != null) { - if (m_article.feed_title != null) { - tagv.setText(m_article.feed_title); - } else if (m_article.tags != null) { - String tagsStr = ""; - - for (String tag : m_article.tags) - tagsStr += tag + ", "; - - tagsStr = tagsStr.replaceAll(", $", ""); - - tagv.setText(tagsStr); - } else { - tagv.setVisibility(View.GONE); - } - } - - TextView author = (TextView)view.findViewById(R.id.author); + URL url = new URL(a.content_url.trim()); + String strUrl = url.toString().trim(); + + content += "<p><img src=\"" + strUrl.replace("\"", "\\\"") + "\"></p>"; + } - if (author != null) { - if (m_article.author != null && m_article.author.length() > 0) { - author.setText(getString(R.string.author_formatted, m_article.author)); - } else { - author.setVisibility(View.GONE); + } catch (MalformedURLException e) { + // + } catch (Exception e) { + e.printStackTrace(); } - } - } + } + } + } + + content += "<p> </p><p> </p><p> </p><p> </p></body></html>"; + try { + web.loadDataWithBaseURL(null, content, "text/html", "utf-8", null); + } catch (RuntimeException e) { + e.printStackTrace(); } + + if (m_activity.isSmallScreen()) + web.setOnTouchListener(m_gestureListener); + + web.setVisibility(View.VISIBLE); } - }, 50); - + + TextView dv = (TextView)view.findViewById(R.id.date); + + if (dv != null) { + Date d = new Date(m_article.updated * 1000L); + DateFormat df = new SimpleDateFormat("MMM dd, HH:mm"); + dv.setText(df.format(d)); + } + + TextView tagv = (TextView)view.findViewById(R.id.tags); + + if (tagv != null) { + if (m_article.feed_title != null) { + tagv.setText(m_article.feed_title); + } else if (m_article.tags != null) { + String tagsStr = ""; + + for (String tag : m_article.tags) + tagsStr += tag + ", "; + + tagsStr = tagsStr.replaceAll(", $", ""); + + tagv.setText(tagsStr); + } else { + tagv.setVisibility(View.GONE); + } + } + + TextView author = (TextView)view.findViewById(R.id.author); + + if (author != null) { + if (m_article.author != null && m_article.author.length() > 0) { + author.setText(getString(R.string.author_formatted, m_article.author)); + } else { + author.setVisibility(View.GONE); + } + } + } return view; } @@ -423,44 +412,9 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl return false; } - private void onLeftSideTapped() { - ArticlePager ap = (ArticlePager) m_activity.getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_ARTICLE); - - if (ap != null && ap.isAdded()) { - ap.selectArticle(false); - } - } - - private void onRightSideTapped() { - ArticlePager ap = (ArticlePager) m_activity.getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_ARTICLE); - - if (ap != null && ap.isAdded()) { - ap.selectArticle(true); - } - } - @Override - public boolean onSingleTapConfirmed(MotionEvent e) { - - int width = getView().getWidth(); - int x = Math.round(e.getX()); - - if (x <= width/15) { - onLeftSideTapped(); - return true; - } else if (x >= width-(width/15)) { - onRightSideTapped(); - return true; - } /* else if (!m_activity.isCompatMode()) { - ActionBar bar = m_activity.getSupportActionBar(); - - if (bar.isShowing()) { - bar.hide(); - } else { - bar.show(); - } - } */ + public boolean onSingleTapConfirmed(MotionEvent arg0) { + // TODO Auto-generated method stub return false; } - } diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index 181d4418..dafbd26d 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -282,7 +282,6 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh @SuppressWarnings({ "unchecked", "serial" }) public void refresh(boolean background) { //FeedCategory cat = m_onlineServices.getActiveCategory(); - m_activity.setProgressBarVisibility(true); final int catId = (m_activeCategory != null) ? m_activeCategory.id : -4; diff --git a/src/org/fox/ttrss/HeadlinesActivity.java b/src/org/fox/ttrss/HeadlinesActivity.java index e9e2439d..6d0af32b 100644 --- a/src/org/fox/ttrss/HeadlinesActivity.java +++ b/src/org/fox/ttrss/HeadlinesActivity.java @@ -201,7 +201,9 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL } else { HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); - hf.setActiveArticle(article); + if (hf != null) { + hf.setActiveArticle(article); + } } GlobalState.getInstance().m_activeArticle = article; diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index c1499cec..42d960bc 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -362,7 +362,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, @SuppressWarnings({ "unchecked", "serial" }) public void refresh(boolean append) { - if (m_activity != null) { + if (m_activity != null && m_feed != null) { m_refreshInProgress = true; m_activity.setProgressBarVisibility(true); diff --git a/src/org/fox/ttrss/offline/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java index d4870e1b..8c0b3c60 100644 --- a/src/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -175,7 +175,10 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector. WebSettings ws = web.getSettings(); ws.setSupportZoom(true); - ws.setBuiltInZoomControls(false); + ws.setBuiltInZoomControls(true); + + if (!m_activity.isCompatMode()) + ws.setDisplayZoomControls(false); web.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN); @@ -373,46 +376,9 @@ public class OfflineArticleFragment extends Fragment implements GestureDetector. return false; } - private void onLeftSideTapped() { - OfflineArticlePager ap = (OfflineArticlePager) m_activity.getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_ARTICLE); - - if (ap != null && ap.isAdded()) { - ap.selectArticle(false); - } - } - - private void onRightSideTapped() { - OfflineArticlePager ap = (OfflineArticlePager) m_activity.getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_ARTICLE); - - if (ap != null && ap.isAdded()) { - ap.selectArticle(true); - } - } - @Override public boolean onSingleTapConfirmed(MotionEvent e) { - - int width = getView().getWidth(); - int x = Math.round(e.getX()); - - if (x <= width/15) { - onLeftSideTapped(); - return true; - } else if (x >= width-(width/15)) { - onRightSideTapped(); - return true; - } /* else if (!m_activity.isCompatMode()) { - ActionBar bar = m_activity.getSupportActionBar(); - - if (bar.isShowing()) { - bar.hide(); - } else { - bar.show(); - } - } */ - + // TODO Auto-generated method stub return false; } - - } diff --git a/src/org/fox/ttrss/offline/OfflineFeedsFragment.java b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java index a2231485..839f22df 100644 --- a/src/org/fox/ttrss/offline/OfflineFeedsFragment.java +++ b/src/org/fox/ttrss/offline/OfflineFeedsFragment.java @@ -121,13 +121,19 @@ public class OfflineFeedsFragment extends Fragment implements OnItemClickListene } public void refresh() { - if (m_cursor != null && !m_cursor.isClosed()) m_cursor.close(); - - m_cursor = createCursor(); - - if (m_cursor != null) { - m_adapter.changeCursor(m_cursor); - m_adapter.notifyDataSetChanged(); + try { + if (!isAdded()) return; + + if (m_cursor != null && !m_cursor.isClosed()) m_cursor.close(); + + m_cursor = createCursor(); + + if (m_cursor != null && m_adapter != null) { + m_adapter.changeCursor(m_cursor); + m_adapter.notifyDataSetChanged(); + } + } catch (NullPointerException e) { + e.printStackTrace(); } } diff --git a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index 9ee61684..0eeeee6f 100644 --- a/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/src/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -256,13 +256,19 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis } public void refresh() { - if (m_cursor != null && !m_cursor.isClosed()) m_cursor.close(); - - m_cursor = createCursor(); - - if (m_cursor != null) { - m_adapter.changeCursor(m_cursor); - m_adapter.notifyDataSetChanged(); + try { + if (!isAdded()) return; + + if (m_cursor != null && !m_cursor.isClosed()) m_cursor.close(); + + m_cursor = createCursor(); + + if (m_cursor != null && m_adapter != null) { + m_adapter.changeCursor(m_cursor); + m_adapter.notifyDataSetChanged(); + } + } catch (NullPointerException e) { + e.printStackTrace(); } } |