From e52e597a3d7f079eee23ec64b2e5db77a0ab3557 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 5 Jun 2015 19:26:36 +0300 Subject: [PATCH] minor efforts to speedup article fragment a bit --- org.fox.ttrss/build.gradle | 2 +- org.fox.ttrss/org.fox.ttrss.iml | 2 +- .../java/org/fox/ttrss/ArticleFragment.java | 90 +++++++++++-------- .../ttrss/offline/OfflineArticleFragment.java | 12 --- 4 files changed, 57 insertions(+), 49 deletions(-) diff --git a/org.fox.ttrss/build.gradle b/org.fox.ttrss/build.gradle index 2d393abb..85004938 100755 --- a/org.fox.ttrss/build.gradle +++ b/org.fox.ttrss/build.gradle @@ -33,7 +33,7 @@ dependencies { compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.shamanland:fab:0.0.5' compile 'ch.acra:acra:4.5.0' - compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.1.0@aar' + compile 'com.ToxicBakery.viewpager.transforms:view-pager-transforms:1.2.32@aar' compile 'me.relex:circleindicator:1.1.1@aar' compile 'com.viewpagerindicator:library:2.4.1' compile 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar' diff --git a/org.fox.ttrss/org.fox.ttrss.iml b/org.fox.ttrss/org.fox.ttrss.iml index b1d7db1b..33f61c90 100755 --- a/org.fox.ttrss/org.fox.ttrss.iml +++ b/org.fox.ttrss/org.fox.ttrss.iml @@ -88,7 +88,6 @@ - @@ -101,6 +100,7 @@ + \ No newline at end of file diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java index b4b753f8..92056e1d 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleFragment.java @@ -7,11 +7,11 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; import android.text.Html; +import android.util.Log; import android.util.TypedValue; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -54,8 +54,12 @@ public class ArticleFragment extends Fragment { protected View m_contentView; protected FSVideoChromeClient m_chromeClient; protected View m_fab; + protected int m_articleFontSize; + protected int m_articleSmallFontSize; + protected boolean m_acceleratedWebview = true; + private boolean m_isVisible; - public void initialize(Article article) { + public void initialize(Article article) { m_article = article; } @@ -146,10 +150,19 @@ public class ArticleFragment extends Fragment { getActivity().getMenuInflater().inflate(R.menu.article_link_context_menu, menu); } - super.onCreateContextMenu(menu, v, menuInfo); - + super.onCreateContextMenu(menu, v, menuInfo); + } - + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + + m_isVisible = isVisibleToUser; + + renderContent(null); + } + @SuppressLint("NewApi") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { @@ -214,14 +227,14 @@ public class ArticleFragment extends Fragment { } } - final int articleFontSize = Integer.parseInt(m_prefs.getString("article_font_size_sp", "16")); - final int articleSmallFontSize = Math.max(10, Math.min(18, articleFontSize - 2)); + m_articleFontSize = Integer.parseInt(m_prefs.getString("article_font_size_sp", "16")); + m_articleSmallFontSize = Math.max(10, Math.min(18, m_articleFontSize - 2)); TextView title = (TextView)view.findViewById(R.id.title); if (title != null) { - title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3)); + title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, m_articleFontSize + 3)); String titleStr; @@ -266,7 +279,7 @@ public class ArticleFragment extends Fragment { if (comments != null) { if (m_activity.getApiLevel() >= 4 && m_article.comments_count > 0) { - comments.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize); + comments.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); String commentsTitle = getResources().getQuantityString(R.plurals.article_comments, m_article.comments_count, m_article.comments_count); comments.setText(commentsTitle); @@ -298,7 +311,7 @@ public class ArticleFragment extends Fragment { if (note != null) { if (m_article.note != null && !"".equals(m_article.note)) { - note.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize); + note.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); note.setText(m_article.note); } else { note.setVisibility(View.GONE); @@ -311,7 +324,7 @@ public class ArticleFragment extends Fragment { TextView dv = (TextView)view.findViewById(R.id.date); if (dv != null) { - dv.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize); + dv.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); Date d = new Date(m_article.updated * 1000L); DateFormat df = new SimpleDateFormat("MMM dd, HH:mm"); @@ -323,7 +336,7 @@ public class ArticleFragment extends Fragment { boolean hasAuthor = false; if (author != null) { - author.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize); + author.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); if (m_article.author != null && m_article.author.length() > 0) { author.setText(getString(R.string.author_formatted, m_article.author)); @@ -336,7 +349,7 @@ public class ArticleFragment extends Fragment { TextView tagv = (TextView)view.findViewById(R.id.tags); if (tagv != null) { - tagv.setTextSize(TypedValue.COMPLEX_UNIT_SP, articleSmallFontSize); + tagv.setTextSize(TypedValue.COMPLEX_UNIT_SP, m_articleSmallFontSize); if (m_article.feed_title != null) { String fTitle = m_article.feed_title; @@ -376,17 +389,25 @@ public class ArticleFragment extends Fragment { } }); - boolean acceleratedWebview = true; - // prevent flicker in ics if (!m_prefs.getBoolean("webview_hardware_accel", true)) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { m_web.setLayerType(View.LAYER_TYPE_SOFTWARE, null); - acceleratedWebview = false; + m_acceleratedWebview = false; } } - String cssOverride = ""; + m_web.setVisibility(View.VISIBLE); + + if (savedInstanceState != null || m_isVisible) renderContent(savedInstanceState); + + return view; + } + + protected void renderContent(Bundle savedInstanceState) { + if (!isAdded()) return; + + Log.d(TAG, "renderContent: " + m_article.title); WebSettings ws = m_web.getSettings(); ws.setSupportZoom(false); @@ -396,6 +417,8 @@ public class ArticleFragment extends Fragment { String backgroundHexColor = String.format("#%06X", (0xFFFFFF & tvBackground.data)); + String cssOverride = ""; + cssOverride = "body { background : "+ backgroundHexColor+"; }"; TypedValue tvTextColor = new TypedValue(); @@ -416,7 +439,7 @@ public class ArticleFragment extends Fragment { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ws.setJavaScriptEnabled(true); - m_chromeClient = new FSVideoChromeClient(view); + m_chromeClient = new FSVideoChromeClient(getView()); m_web.setWebChromeClient(m_chromeClient); } @@ -424,20 +447,20 @@ public class ArticleFragment extends Fragment { cssOverride += "body { text-align : justify; } "; } - ws.setDefaultFontSize(articleFontSize); + ws.setDefaultFontSize(m_articleFontSize); StringBuilder content = new StringBuilder("" + - "" + - "" + - "" + - "" + - "" + - ""); + "" + + "" + + "" + + "" + + "" + + ""); content.append(articleContent); @@ -478,7 +501,7 @@ public class ArticleFragment extends Fragment { // } - if (savedInstanceState == null || !acceleratedWebview) { + if (savedInstanceState == null || !m_acceleratedWebview) { m_web.loadDataWithBaseURL(baseUrl, content.toString(), "text/html", "utf-8", null); } else { WebBackForwardList rc = m_web.restoreState(savedInstanceState); @@ -493,10 +516,7 @@ public class ArticleFragment extends Fragment { e.printStackTrace(); } - m_web.setVisibility(View.VISIBLE); - - return view; - } + } @Override public void onPause() { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java index c0a101c7..82232087 100755 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -185,18 +185,6 @@ public class OfflineArticleFragment extends Fragment { TextView title = (TextView)view.findViewById(R.id.title); if (title != null) { - - /* if (m_prefs.getBoolean("enable_condensed_fonts", false)) { - Typeface tf = TypefaceCache.get(m_activity, "sans-serif-condensed", Typeface.NORMAL); - - if (tf != null && !tf.equals(title.getTypeface())) { - title.setTypeface(tf); - } - - title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 5)); - } else { - title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3)); - } */ title.setTextSize(TypedValue.COMPLEX_UNIT_SP, Math.min(21, articleFontSize + 3));