tweak flavor image loader a bit to be less cpu hungry
disable flavor image arrows because they are unreliable as only part of the content is being parsed for performance
This commit is contained in:
parent
531322faa2
commit
ef357ac421
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.fox.ttrss"
|
package="org.fox.ttrss"
|
||||||
android:versionCode="322"
|
android:versionCode="323"
|
||||||
android:versionName="1.97" >
|
android:versionName="1.98" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="15"
|
android:minSdkVersion="15"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.fox.ttrss;
|
package org.fox.ttrss;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -54,14 +53,12 @@ import com.nostra13.universalimageloader.core.assist.FailReason;
|
|||||||
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
|
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
|
||||||
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
|
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
|
||||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
|
||||||
import com.nostra13.universalimageloader.utils.MemoryCacheUtils;
|
|
||||||
|
|
||||||
import org.fox.ttrss.types.Article;
|
import org.fox.ttrss.types.Article;
|
||||||
import org.fox.ttrss.types.ArticleList;
|
import org.fox.ttrss.types.ArticleList;
|
||||||
import org.fox.ttrss.types.Feed;
|
import org.fox.ttrss.types.Feed;
|
||||||
import org.fox.ttrss.util.HeadlinesRequest;
|
import org.fox.ttrss.util.HeadlinesRequest;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
@ -861,7 +858,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ?
|
String articleContentReduced = articleContent.length() > CommonActivity.EXCERPT_MAX_QUERY_LENGTH ?
|
||||||
articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent;
|
articleContent.substring(0, CommonActivity.EXCERPT_MAX_QUERY_LENGTH) : articleContent;
|
||||||
|
|
||||||
Document articleDoc = Jsoup.parse(articleContentReduced);
|
if (article.articleDoc == null)
|
||||||
|
article.articleDoc = Jsoup.parse(articleContentReduced);
|
||||||
|
|
||||||
if (holder.excerptView != null) {
|
if (holder.excerptView != null) {
|
||||||
if (!m_prefs.getBoolean("headlines_show_content", true)) {
|
if (!m_prefs.getBoolean("headlines_show_content", true)) {
|
||||||
@ -875,7 +873,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
excerpt = excerpt.replace("]]>", "");
|
excerpt = excerpt.replace("]]>", "");
|
||||||
excerpt = Jsoup.parse(excerpt).text();
|
excerpt = Jsoup.parse(excerpt).text();
|
||||||
} else {
|
} else {
|
||||||
excerpt = articleDoc.text();
|
excerpt = article.articleDoc.text();
|
||||||
|
|
||||||
if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH)
|
if (excerpt.length() > CommonActivity.EXCERPT_MAX_LENGTH)
|
||||||
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…";
|
excerpt = excerpt.substring(0, CommonActivity.EXCERPT_MAX_LENGTH) + "…";
|
||||||
@ -889,13 +887,136 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
if (!m_compactLayoutMode) {
|
if (!m_compactLayoutMode) {
|
||||||
boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"));
|
boolean showFlavorImage = "HL_DEFAULT".equals(m_prefs.getString("headline_mode", "HL_DEFAULT"));
|
||||||
|
|
||||||
if (holder.flavorImageView != null && showFlavorImage) {
|
if (showFlavorImage && holder.flavorImageView != null) {
|
||||||
|
|
||||||
|
holder.flavorImageArrow.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
if (article.noValidFlavorImage) {
|
||||||
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
||||||
|
} else if (article.articleDoc != null) {
|
||||||
|
|
||||||
|
if (article.flavorImage == null) {
|
||||||
|
|
||||||
|
Elements imgs = article.articleDoc.select("img");
|
||||||
|
|
||||||
|
for (Element tmp : imgs) {
|
||||||
|
try {
|
||||||
|
if (Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_WIDTH && Integer.valueOf(tmp.attr("width")) > FLAVOR_IMG_MIN_HEIGHT) {
|
||||||
|
article.flavorImage = tmp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (article.flavorImage == null)
|
||||||
|
article.flavorImage = imgs.first();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (article.flavorImage != null) {
|
||||||
|
|
||||||
|
String imgSrc = article.flavorImage.attr("src");
|
||||||
|
final String imgSrcFirst = imgSrc;
|
||||||
|
|
||||||
|
// retarded schema-less urls
|
||||||
|
if (imgSrc.indexOf("//") == 0)
|
||||||
|
imgSrc = "http:" + imgSrc;
|
||||||
|
|
||||||
|
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
||||||
|
.cacheInMemory(true)
|
||||||
|
.resetViewBeforeLoading(true)
|
||||||
|
.cacheOnDisk(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ViewCompat.setTransitionName(holder.flavorImageView, "TRANSITION:ARTICLE_IMAGES_PAGER");
|
||||||
|
|
||||||
|
holder.flavorImageView.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
|
||||||
|
Intent intent = new Intent(m_activity, ArticleImagesPagerActivity.class);
|
||||||
|
intent.putExtra("firstSrc", imgSrcFirst);
|
||||||
|
intent.putExtra("title", article.title);
|
||||||
|
intent.putExtra("content", article.content);
|
||||||
|
|
||||||
|
ActivityOptionsCompat options =
|
||||||
|
ActivityOptionsCompat.makeSceneTransitionAnimation(m_activity,
|
||||||
|
holder.flavorImageView, // The view which starts the transition
|
||||||
|
"TRANSITION:ARTICLE_IMAGES_PAGER" // The transitionName of the view we’re transitioning to
|
||||||
|
);
|
||||||
|
ActivityCompat.startActivity(m_activity, intent, options.toBundle());
|
||||||
|
|
||||||
|
//startActivityForResult(intent, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final ViewGroup flavorImageHolder = holder.flavorImageHolder;
|
||||||
|
final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar;
|
||||||
|
|
||||||
|
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
|
||||||
|
|
||||||
|
ImageLoader.getInstance().displayImage(imgSrc, imageAware, options, new ImageLoadingListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingCancelled(String arg0,
|
||||||
|
View arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||||
|
@Override
|
||||||
|
public void onLoadingComplete(String arg0,
|
||||||
|
View arg1, Bitmap arg2) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
if (!isAdded() || arg2 == null) return;
|
||||||
|
|
||||||
|
flavorImageLoadingBar.setVisibility(View.INVISIBLE);
|
||||||
|
|
||||||
|
if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) {
|
||||||
|
flavorImageHolder.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
flavorImageHolder.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingFailed(String arg0,
|
||||||
|
View arg1, FailReason arg2) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
flavorImageHolder.setVisibility(View.GONE);
|
||||||
|
article.noValidFlavorImage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadingStarted(String arg0,
|
||||||
|
View arg1) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
article.noValidFlavorImage = true;
|
||||||
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if (holder.flavorImageView != null && showFlavorImage) {
|
||||||
holder.flavorImageArrow.setVisibility(View.GONE);
|
holder.flavorImageArrow.setVisibility(View.GONE);
|
||||||
|
|
||||||
boolean loadableImageFound = false;
|
boolean loadableImageFound = false;
|
||||||
|
|
||||||
if (articleDoc != null) {
|
if (article.articleDoc != null) {
|
||||||
final Elements imgs = articleDoc.select("img");
|
|
||||||
|
Elements imgs = article.articleDoc.select("img");
|
||||||
|
|
||||||
Element img = null;
|
Element img = null;
|
||||||
|
|
||||||
for (Element tmp : imgs) {
|
for (Element tmp : imgs) {
|
||||||
@ -921,6 +1042,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
imgSrc = "http:" + imgSrc;
|
imgSrc = "http:" + imgSrc;
|
||||||
|
|
||||||
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
||||||
|
.displayer(new FadeInBitmapDisplayer(500))
|
||||||
.cacheInMemory(true)
|
.cacheInMemory(true)
|
||||||
.resetViewBeforeLoading(true)
|
.resetViewBeforeLoading(true)
|
||||||
.cacheOnDisk(true)
|
.cacheOnDisk(true)
|
||||||
@ -1019,7 +1141,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
holder.flavorImageHolder.setVisibility(View.GONE);
|
holder.flavorImageHolder.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
} else if (holder.flavorImageHolder != null) {
|
} else if (holder.flavorImageHolder != null) {
|
||||||
holder.flavorImageHolder.setVisibility(View.GONE);
|
holder.flavorImageHolder.setVisibility(View.GONE); */
|
||||||
}
|
}
|
||||||
|
|
||||||
String articleAuthor = article.author != null ? article.author : "";
|
String articleAuthor = article.author != null ? article.author : "";
|
||||||
|
@ -3,6 +3,9 @@ package org.fox.ttrss.types;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -31,6 +34,11 @@ public class Article implements Parcelable {
|
|||||||
public String note;
|
public String note;
|
||||||
public boolean selected;
|
public boolean selected;
|
||||||
|
|
||||||
|
/* not serialized */
|
||||||
|
public Document articleDoc;
|
||||||
|
public Element flavorImage;
|
||||||
|
public boolean noValidFlavorImage;
|
||||||
|
|
||||||
public Article(Parcel in) {
|
public Article(Parcel in) {
|
||||||
readFromParcel(in);
|
readFromParcel(in);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user