add some additional tag checking for headline images so they wouldn't reload all the time

This commit is contained in:
Andrew Dolgov 2017-06-01 09:38:44 +03:00
parent 22694af2f7
commit ebe9738163
3 changed files with 65 additions and 101 deletions

View File

@ -1181,110 +1181,72 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}); });
} }
//Log.d(TAG, "IMG: " + article.flavorImageUri + " STREAM: " + article.flavorStreamUri); Log.d(TAG, "IMG: " + article.flavorImageUri + " STREAM: " + article.flavorStreamUri);
holder.flavorImageLoadingBar.setVisibility(View.VISIBLE);
holder.flavorImageLoadingBar.setIndeterminate(true);
/*if ("video".equals(article.flavorImage.tagName().toLowerCase()) && article.flavorStreamUri != null) {
final MediaPlayer mediaPlayer = new MediaPlayer();
holder.flavorVideoView.setVisibility(View.VISIBLE);
repositionFlavorVideo(holder.flavorVideoView, holder);
try {
mediaPlayer.setDataSource(article.flavorStreamUri);
} catch (IOException e) {
e.printStackTrace();
}
final View bar = holder.flavorImageLoadingBar;
SurfaceHolder sh = holder.flavorVideoView.getHolder();
sh.addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
mediaPlayer.setDisplay(holder);
try {
mediaPlayer.prepareAsync();
} catch (IllegalStateException e) {
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
bar.setVisibility(View.GONE);
//resizeSurface();
mp.setLooping(true);
mp.start();
}
}
);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
//
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
//
}
});
} else { */
holder.flavorImageView.setVisibility(View.VISIBLE); holder.flavorImageView.setVisibility(View.VISIBLE);
holder.flavorImageView.setImageDrawable(null);
final GlideDrawableImageViewTarget glideImage = new GlideDrawableImageViewTarget(holder.flavorImageView); Log.d(TAG, "TAG:" + holder.flavorImageOverflow.getTag());
Glide.with(HeadlinesFragment.this) if (!article.flavorImageUri.equals(holder.flavorImageOverflow.getTag())) {
.load(article.flavorImageUri) holder.flavorImageLoadingBar.setVisibility(View.VISIBLE);
.dontAnimate() holder.flavorImageLoadingBar.setIndeterminate(true);
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(false)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
holder.flavorImageLoadingBar.setVisibility(View.GONE); Glide.with(HeadlinesFragment.this)
holder.flavorImageView.setVisibility(View.GONE); .load(article.flavorImageUri)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(false)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false; holder.flavorImageLoadingBar.setVisibility(View.GONE);
} holder.flavorImageView.setVisibility(View.GONE);
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
holder.flavorImageLoadingBar.setVisibility(View.GONE);
holder.flavorImageOverflow.setVisibility(View.VISIBLE);
if (resource.getIntrinsicWidth() > FLAVOR_IMG_MIN_SIZE && resource.getIntrinsicHeight() > FLAVOR_IMG_MIN_SIZE) {
holder.flavorImageView.setVisibility(View.VISIBLE);
holder.flavorImageOverflow.setVisibility(View.VISIBLE);
boolean forceDown = article.flavorImage != null && "video".equals(article.flavorImage.tagName().toLowerCase());
maybeRepositionFlavorImage(holder.flavorImageView, resource, holder, forceDown);
adjustVideoKindView(holder, article);
return false; return false;
} else {
return true;
} }
}
}) @Override
.into(glideImage); public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
holder.flavorImageLoadingBar.setVisibility(View.GONE);
if (resource.getIntrinsicWidth() > FLAVOR_IMG_MIN_SIZE && resource.getIntrinsicHeight() > FLAVOR_IMG_MIN_SIZE) {
//holder.flavorImageView.setVisibility(View.VISIBLE);
holder.flavorImageOverflow.setVisibility(View.VISIBLE);
holder.flavorImageOverflow.setTag(article.flavorImageUri);
boolean forceDown = article.flavorImage != null && "video".equals(article.flavorImage.tagName().toLowerCase());
maybeRepositionFlavorImage(holder.flavorImageView, resource, holder, forceDown);
adjustVideoKindView(holder, article);
return false;
} else {
holder.flavorImageOverflow.setVisibility(View.GONE);
return true;
}
}
})
.into(holder.flavorImageView);
} else {
holder.flavorImageOverflow.setVisibility(View.VISIBLE);
adjustVideoKindView(holder, article);
if (holder.flavorImageEmbedded) {
TypedValue tv = new TypedValue();
if (m_activity.getTheme().resolveAttribute(R.attr.headlineHeaderBackground, tv, true)) {
holder.headlineHeader.setBackgroundColor(tv.data);
}
} else {
holder.headlineHeader.setBackgroundDrawable(null);
}
}
} }
if (m_prefs.getBoolean("inline_video_player", false) && article.flavorImage != null && if (m_prefs.getBoolean("inline_video_player", false) && article.flavorImage != null &&

View File

@ -38,9 +38,11 @@
android:layout_alignParentTop="false" android:layout_alignParentTop="false"
android:layout_alignParentRight="false" android:layout_alignParentRight="false"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:max="100" android:max="100"
android:indeterminate="false" /> android:indeterminate="false"
android:layout_toRightOf="@+id/flavor_video"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView <ImageView
android:id="@+id/flavor_image" android:id="@+id/flavor_image"
@ -53,7 +55,6 @@
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:cropToPadding="true" android:cropToPadding="true"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/drawer_header"
android:visibility="visible" /> android:visibility="visible" />
<SurfaceView <SurfaceView

View File

@ -39,9 +39,11 @@
android:layout_alignParentTop="false" android:layout_alignParentTop="false"
android:layout_alignParentRight="false" android:layout_alignParentRight="false"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:max="100" android:max="100"
android:indeterminate="false" /> android:indeterminate="false"
android:layout_toRightOf="@+id/flavor_video"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView <ImageView
android:id="@+id/flavor_image" android:id="@+id/flavor_image"
@ -54,7 +56,6 @@
android:background="@android:color/transparent" android:background="@android:color/transparent"
android:cropToPadding="true" android:cropToPadding="true"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/drawer_header"
android:visibility="visible" /> android:visibility="visible" />
<SurfaceView <SurfaceView