flavor images: add fade-in displayer; rework progressbar display

This commit is contained in:
Andrew Dolgov 2015-06-05 15:03:23 +03:00
parent 79f4b94a34
commit e5159ab48a

View File

@ -1,6 +1,5 @@
package org.fox.ttrss; package org.fox.ttrss;
import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -52,6 +51,7 @@ import com.nhaarman.listviewanimations.appearance.simple.SwingBottomInAnimationA
import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
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;
@ -102,6 +102,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private boolean m_compactLayoutMode = false; private boolean m_compactLayoutMode = false;
private int m_listPreviousVisibleItem; private int m_listPreviousVisibleItem;
private ListView m_list; private ListView m_list;
private ImageLoader m_imageLoader = ImageLoader.getInstance();
public ArticleList getSelectedArticles() { public ArticleList getSelectedArticles() {
ArticleList tmp = new ArticleList(); ArticleList tmp = new ArticleList();
@ -672,6 +673,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
.cacheInMemory(true) .cacheInMemory(true)
.resetViewBeforeLoading(true) .resetViewBeforeLoading(true)
.cacheOnDisk(true) .cacheOnDisk(true)
.displayer(new FadeInBitmapDisplayer(500))
.build(); .build();
} }
@ -970,8 +972,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
}); });
final ViewGroup flavorImageHolder = holder.flavorImageHolder; //final ViewGroup flavorImageHolder = holder.flavorImageHolder;
final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar; //final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar;
if (holder.flavorImageView.getTag() == null || !holder.flavorImageView.getTag().equals(imgSrc)) { if (holder.flavorImageView.getTag() == null || !holder.flavorImageView.getTag().equals(imgSrc)) {
@ -979,42 +981,43 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false); ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
ImageLoader.getInstance().displayImage(imgSrc, imageAware, displayImageOptions, new ImageLoadingListener() { m_imageLoader.displayImage(imgSrc, imageAware, displayImageOptions, new ImageLoadingListener() {
@Override @Override
public void onLoadingCancelled(String arg0, public void onLoadingCancelled(String arg0,
View arg1) { View arg1) {
// TODO Auto-generated method stub
//
} }
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override @Override
public void onLoadingComplete(String arg0, public void onLoadingComplete(String arg0,
View arg1, Bitmap arg2) { View arg1, Bitmap arg2) {
if (!isAdded() || arg2 == null) return; if (!isAdded() || arg2 == null) return;
flavorImageLoadingBar.setVisibility(View.INVISIBLE); holder.flavorImageLoadingBar.setVisibility(View.GONE);
if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) { if (arg2.getWidth() > FLAVOR_IMG_MIN_WIDTH && arg2.getHeight() > FLAVOR_IMG_MIN_HEIGHT) {
flavorImageHolder.setVisibility(View.VISIBLE); holder.flavorImageHolder.setVisibility(View.VISIBLE);
} else { } else {
flavorImageHolder.setVisibility(View.GONE); holder.flavorImageHolder.setVisibility(View.GONE);
} }
} }
@Override @Override
public void onLoadingFailed(String arg0, public void onLoadingFailed(String arg0,
View arg1, FailReason arg2) { View arg1, FailReason arg2) {
flavorImageHolder.setVisibility(View.GONE);
holder.flavorImageLoadingBar.setVisibility(View.GONE);
holder.flavorImageHolder.setVisibility(View.GONE);
article.noValidFlavorImage = true; article.noValidFlavorImage = true;
} }
@Override @Override
public void onLoadingStarted(String arg0, public void onLoadingStarted(String arg0,
View arg1) { View arg1) {
// TODO Auto-generated method stub holder.flavorImageLoadingBar.setVisibility(View.VISIBLE);
} }
}); });
@ -1234,6 +1237,12 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
@Override @Override
public void onScrollStateChanged(AbsListView view, int scrollState) { public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
m_imageLoader.pause();
} else {
m_imageLoader.resume();
}
if (scrollState == SCROLL_STATE_IDLE && m_prefs.getBoolean("headlines_mark_read_scroll", false)) { if (scrollState == SCROLL_STATE_IDLE && m_prefs.getBoolean("headlines_mark_read_scroll", false)) {
if (!m_readArticles.isEmpty()) { if (!m_readArticles.isEmpty()) {
m_activity.toggleArticlesUnread(m_readArticles); m_activity.toggleArticlesUnread(m_readArticles);