diff options
author | Andrew Dolgov <[email protected]> | 2014-11-29 11:18:43 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2014-11-29 11:18:43 +0300 |
commit | accfa1c6727caf5a68331fdde267d126d6d06111 (patch) | |
tree | 4b45415d6e1a5333a351ccf1fe5b395f0e41802d /org.fox.ttrss/src | |
parent | 104df9df30a7f5e547d2f8879ca7cfee214407fd (diff) |
make headlines listview a bit faster
Diffstat (limited to 'org.fox.ttrss/src')
5 files changed, 73 insertions, 25 deletions
diff --git a/org.fox.ttrss/src/main/AndroidManifest.xml b/org.fox.ttrss/src/main/AndroidManifest.xml index 39c8a890..0e72c0d5 100644 --- a/org.fox.ttrss/src/main/AndroidManifest.xml +++ b/org.fox.ttrss/src/main/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="289" - android:versionName="1.80" > + android:versionCode="290" + android:versionName="1.81" > <uses-sdk android:minSdkVersion="10" diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java index cfcbc584..6a7fb269 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ArticleImagesPagerActivity.java @@ -35,6 +35,7 @@ import com.viewpagerindicator.UnderlinePageIndicator; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import java.util.ArrayList; @@ -241,15 +242,38 @@ public class ArticleImagesPagerActivity extends CommonActivity implements Gestur if (savedInstanceState == null) { m_title = getIntent().getStringExtra("title"); - m_urls = getIntent().getStringArrayListExtra("urls"); + //m_urls = getIntent().getStringArrayListExtra("urls"); m_content = getIntent().getStringExtra("content"); + + String imgSrcFirst = getIntent().getStringExtra("firstSrc"); + + m_urls = new ArrayList<String>(); + + Document doc = Jsoup.parse(m_content); + Elements imgs = doc.select("img"); + + boolean firstFound = false; + + for (Element img : imgs) { + String imgSrc = img.attr("src"); + + if (imgSrcFirst.equals(imgSrc)) + firstFound = true; + + if (firstFound) { + if (imgSrc.indexOf("//") == 0) + imgSrc = "http:" + imgSrc; + + m_urls.add(imgSrc); + } + } + } else { m_urls = savedInstanceState.getStringArrayList("urls"); m_title = savedInstanceState.getString("title"); m_content = savedInstanceState.getString("content"); } - if (m_urls.size() > 1) { m_checkedUrls = new ArrayList<String>(); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java index 80dacea1..56704bf5 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/CommonActivity.java @@ -30,6 +30,7 @@ public class CommonActivity extends ActionBarActivity { public final static String THEME_DEFAULT = CommonActivity.THEME_LIGHT; public static final int EXCERPT_MAX_LENGTH = 256; + public static final int EXCERPT_MAX_QUERY_LENGTH = 1024; private SQLiteDatabase m_readableDb; private SQLiteDatabase m_writableDb; diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java index d78732cc..6a90865a 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/HeadlinesFragment.java @@ -828,16 +828,30 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, }); } - String articleContent = article.content != null ? article.content : ""; + boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT")); - if (holder.excerptView != null) { + String articleContent = article.content != null ? article.content : ""; + + + String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ? + articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent; + + /* if (m_compactLayoutMode || !showFlavorImage) { + if (articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH) { + articleContent = articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH); + } + } */ + + Document articleDoc = Jsoup.parse(articleContentReduced); + + if (holder.excerptView != null) { if (!m_prefs.getBoolean("headlines_show_content", true)) { holder.excerptView.setVisibility(View.GONE); - } else { - String tmp = articleContent.length() > CommonActivity.EXCERPT_MAX_LENGTH ? - articleContent.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…" : articleContent; + } else if (articleDoc != null) { + String excerpt = articleDoc.text(); - String excerpt = Jsoup.parse(tmp).text(); + if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH) + excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…"; holder.excerptView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineFontSize); holder.excerptView.setText(excerpt); @@ -845,19 +859,18 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } if (!m_compactLayoutMode) { - boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT")); if (holder.flavorImageView != null && showFlavorImage) { holder.flavorImageArrow.setVisibility(View.GONE); - Document doc = Jsoup.parse(articleContent); + //Document doc = Jsoup.parse(articleContent); boolean loadableImageFound = false; - if (doc != null) { + if (articleDoc != null) { //Element img = doc.select("img").first(); - final Elements imgs = doc.select("img"); + final Elements imgs = articleDoc.select("img"); Element img = null; for (Element tmp : imgs) { @@ -876,6 +889,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, if (img != null) { String imgSrc = img.attr("src"); + final String imgSrcFirst = imgSrc; // retarded schema-less urls if (imgSrc.indexOf("//") == 0) @@ -890,19 +904,27 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, holder.flavorImageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - ArrayList<String> imgsList = new ArrayList<String>(); + /* ArrayList<String> imgsList = new ArrayList<String>(); + + boolean firstFound = false; for (Element img : imgs) { String imgSrc = img.attr("src"); - if (imgSrc.indexOf("//") == 0) - imgSrc = "http:" + imgSrc; + if (imgSrcFirst.equals(imgSrc)) + firstFound = true; - imgsList.add(imgSrc); - } + if (firstFound) { + if (imgSrc.indexOf("//") == 0) + imgSrc = "http:" + imgSrc; + + imgsList.add(imgSrc); + } + } */ Intent intent = new Intent(m_activity, ArticleImagesPagerActivity.class); - intent.putExtra("urls", imgsList); + //intent.putExtra("urls", imgsList); + intent.putExtra("firstSrc", imgSrcFirst); intent.putExtra("title", article.title); intent.putExtra("content", article.content); diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java index 3918f966..edcaa1fd 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/offline/OfflineHeadlinesFragment.java @@ -694,18 +694,19 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis }); } - String articleContent = article.getString(article.getColumnIndex("content")); - if (articleContent == null) articleContent = ""; - if (holder.excerptView != null) { if (!m_prefs.getBoolean("headlines_show_content", true)) { holder.excerptView.setVisibility(View.GONE); } else { - String tmp = articleContent.length() > CommonActivity.EXCERPT_MAX_LENGTH ? - articleContent.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…" : articleContent; + String articleContent = article.getString(article.getColumnIndex("content")); + + String tmp = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ? + articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent; String excerpt = Jsoup.parse(tmp).text(); + if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH) excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…"; + holder.excerptView.setTextSize(TypedValue.COMPLEX_UNIT_SP, headlineFontSize); holder.excerptView.setText(excerpt); } |