From d3e0ce0f83c117573840eaa777c7cae45361fe6e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 19 Sep 2012 23:23:26 +0400 Subject: [PATCH] less-crashy handling on article title --- res/layout/article_fragment.xml | 1 + src/org/fox/ttrss/ArticleFragment.java | 21 +++++++++++++--- .../ttrss/offline/OfflineArticleFragment.java | 24 +++++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/res/layout/article_fragment.xml b/res/layout/article_fragment.xml index cbcf672d..0b847017 100644 --- a/res/layout/article_fragment.xml +++ b/res/layout/article_fragment.xml @@ -15,6 +15,7 @@ " + titleStr + "")); - registerForContextMenu(title); + title.setText(titleStr); + title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + title.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW, + Uri.parse(m_article.link.trim())); + startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + m_activity.toast(R.string.error_other_error); + } + } + }); + + registerForContextMenu(title); } WebView web = (WebView)view.findViewById(R.id.content); diff --git a/src/org/fox/ttrss/offline/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java index 6fd7ad01..98ce59f4 100644 --- a/src/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -12,8 +12,11 @@ import org.jsoup.select.Elements; import android.annotation.SuppressLint; import android.app.Activity; +import android.content.Intent; import android.content.SharedPreferences; import android.database.Cursor; +import android.graphics.Paint; +import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.BaseColumns; @@ -24,6 +27,7 @@ import android.util.Log; import android.util.TypedValue; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; +import android.view.View.OnClickListener; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -118,8 +122,24 @@ public class OfflineArticleFragment extends Fragment { else titleStr = m_cursor.getString(m_cursor.getColumnIndex("title")); - title.setMovementMethod(LinkMovementMethod.getInstance()); - title.setText(Html.fromHtml("" + titleStr + "")); + final String link = m_cursor.getString(m_cursor.getColumnIndex("link")); + + title.setText(titleStr); + title.setPaintFlags(title.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); + title.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW, + Uri.parse(link.trim())); + startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + m_activity.toast(R.string.error_other_error); + } + } + }); + registerForContextMenu(title); }