add flavor image loading progressbars

try to only animate flavor images if they are not cached yet
This commit is contained in:
Andrew Dolgov 2014-10-28 21:58:56 +03:00
parent 1c4b41085e
commit 903e4250f9
5 changed files with 62 additions and 27 deletions

View File

@ -34,6 +34,7 @@ import android.widget.ArrayAdapter;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -43,6 +44,7 @@ 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;
@ -666,7 +668,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public CheckBox selectionBoxView; public CheckBox selectionBoxView;
public ImageView menuButtonView; public ImageView menuButtonView;
public ViewGroup flavorImageHolder; public ViewGroup flavorImageHolder;
public ProgressBar flavorImageLoadingBar;
} }
private class ArticleListAdapter extends ArrayAdapter<Article> { private class ArticleListAdapter extends ArrayAdapter<Article> {
@ -759,6 +761,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
holder.selectionBoxView = (CheckBox) v.findViewById(R.id.selected); holder.selectionBoxView = (CheckBox) v.findViewById(R.id.selected);
holder.menuButtonView = (ImageView) v.findViewById(R.id.article_menu_button); holder.menuButtonView = (ImageView) v.findViewById(R.id.article_menu_button);
holder.flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder); holder.flavorImageHolder = (ViewGroup) v.findViewById(R.id.flavorImageHolder);
holder.flavorImageLoadingBar = (ProgressBar) v.findViewById(R.id.flavorImageLoadingBar);
v.setTag(holder); v.setTag(holder);
@ -854,16 +857,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
} }
if (holder.flavorImageView != null && m_prefs.getBoolean("headlines_show_flavor_image", true)) { if (holder.flavorImageView != null && m_prefs.getBoolean("headlines_show_flavor_image", true)) {
holder.flavorImageView.setVisibility(View.GONE);
holder.flavorImageHolder.setVisibility(View.GONE);
Document doc = Jsoup.parse(articleContent); Document doc = Jsoup.parse(articleContent);
boolean loadableImageFound = false;
Element img = doc.select("img").first(); if (doc != null) {
if (doc != null) { Element img = doc.select("img").first();
if (img != null) { if (img != null) {
String imgSrc = img.attr("src"); String imgSrc = img.attr("src");
@ -878,11 +878,17 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
.cacheOnDisk(true) .cacheOnDisk(true)
.build(); .build();
final ImageView flavorImageView = holder.flavorImageView;
final ViewGroup flavorImageHolder = holder.flavorImageHolder; final ViewGroup flavorImageHolder = holder.flavorImageHolder;
final ImageView flavorImageView = holder.flavorImageView;
final ProgressBar flavorImageLoadingBar = holder.flavorImageLoadingBar;
ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false); ImageAware imageAware = new ImageViewAware(holder.flavorImageView, false);
flavorImageHolder.setVisibility(View.VISIBLE);
final boolean weNeedAnimation = MemoryCacheUtils.findCachedBitmapsForImageUri(imgSrc, ImageLoader.getInstance().getMemoryCache()).size() == 0;
loadableImageFound = true;
ImageLoader.getInstance().displayImage(imgSrc, imageAware, options, new ImageLoadingListener() { ImageLoader.getInstance().displayImage(imgSrc, imageAware, options, new ImageLoadingListener() {
@Override @Override
@ -898,27 +904,29 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
// TODO Auto-generated method stub // TODO Auto-generated method stub
if (!isAdded() || arg2 == null) return; if (!isAdded() || arg2 == null) return;
flavorImageLoadingBar.setVisibility(View.INVISIBLE);
if (arg2.getWidth() > 128 && arg2.getHeight() > 128) { if (arg2.getWidth() > 128 && arg2.getHeight() > 128) {
if (arg0 != null && !arg0.equals(arg1.getTag())) { if (!m_activity.isCompatMode() && weNeedAnimation) {
if (!m_activity.isCompatMode() && flavorImageView.getVisibility() != View.VISIBLE) {
ObjectAnimator anim = ObjectAnimator.ofFloat(flavorImageView, "alpha", 0f, 1f); ObjectAnimator anim = ObjectAnimator.ofFloat(flavorImageView, "alpha", 0f, 1f);
anim.setDuration(500); anim.setDuration(200);
anim.start(); anim.start();
}
} }
//flavorImageHolder.setVisibility(View.VISIBLE);
flavorImageView.setTag(arg0); } else {
flavorImageHolder.setVisibility(View.VISIBLE); flavorImageHolder.setVisibility(View.GONE);
flavorImageView.setVisibility(View.VISIBLE); }
}
} }
@Override @Override
public void onLoadingFailed(String arg0, public void onLoadingFailed(String arg0,
View arg1, FailReason arg2) { View arg1, FailReason arg2) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} flavorImageHolder.setVisibility(View.GONE);
}
@Override @Override
public void onLoadingStarted(String arg0, public void onLoadingStarted(String arg0,
@ -928,10 +936,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
}); });
} }
}
}
} else if (holder.flavorImageHolder != null) { if (!loadableImageFound) {
holder.flavorImageHolder.setVisibility(View.GONE);
}
} else {
holder.flavorImageHolder.setVisibility(View.GONE); holder.flavorImageHolder.setVisibility(View.GONE);
} }

View File

@ -78,6 +78,12 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:layout_span="2"> android:layout_span="2">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/flavorImageLoadingBar" />
<org.fox.ttrss.util.EnlargingImageView <org.fox.ttrss.util.EnlargingImageView
android:id="@+id/flavor_image" android:id="@+id/flavor_image"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -78,6 +78,12 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:layout_span="2"> android:layout_span="2">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/flavorImageLoadingBar" />
<org.fox.ttrss.util.EnlargingImageView <org.fox.ttrss.util.EnlargingImageView
android:id="@+id/flavor_image" android:id="@+id/flavor_image"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -79,6 +79,12 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:layout_span="2"> android:layout_span="2">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/flavorImageLoadingBar" />
<org.fox.ttrss.util.EnlargingImageView <org.fox.ttrss.util.EnlargingImageView
android:id="@+id/flavor_image" android:id="@+id/flavor_image"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -79,6 +79,12 @@
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:layout_span="2"> android:layout_span="2">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/flavorImageLoadingBar" />
<org.fox.ttrss.util.EnlargingImageView <org.fox.ttrss.util.EnlargingImageView
android:id="@+id/flavor_image" android:id="@+id/flavor_image"
android:layout_width="match_parent" android:layout_width="match_parent"