mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-26 01:34:45 +01:00
Use GifImageView to display all the images in order to prevent slow playing of the gifs. Extend GifImageView as AspectRatioGifImageView to retain the features of AspectRatioImageView.
This commit is contained in:
parent
33db4809e4
commit
60b659e651
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
@ -43,7 +43,7 @@ dependencies {
|
|||||||
implementation 'com.android.support:customtabs:28.0.0'
|
implementation 'com.android.support:customtabs:28.0.0'
|
||||||
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
implementation 'com.alexvasilkov:gesture-views:2.5.2'
|
||||||
implementation 'com.android.support:cardview-v7:28.0.0'
|
implementation 'com.android.support:cardview-v7:28.0.0'
|
||||||
implementation 'com.github.bumptech.glide:glide:4.7.1'
|
implementation 'com.github.bumptech.glide:glide:4.8.0'
|
||||||
implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
|
implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
|
||||||
// Room components
|
// Room components
|
||||||
@ -58,11 +58,12 @@ dependencies {
|
|||||||
implementation 'org.sufficientlysecure:html-textview:3.6'
|
implementation 'org.sufficientlysecure:html-textview:3.6'
|
||||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||||
implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'
|
implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'
|
||||||
implementation 'jp.wasabeef:glide-transformations:3.3.0'
|
implementation 'jp.wasabeef:glide-transformations:4.0.0'
|
||||||
implementation 'com.muditsen.multilevelrecyclerview:multilevelview:1.0.0'
|
implementation 'com.muditsen.multilevelrecyclerview:multilevelview:1.0.0'
|
||||||
implementation 'com.google.dagger:dagger:2.17'
|
implementation 'com.google.dagger:dagger:2.17'
|
||||||
annotationProcessor 'com.google.dagger:dagger-compiler:2.17'
|
annotationProcessor 'com.google.dagger:dagger-compiler:2.17'
|
||||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
|
||||||
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.6'
|
implementation 'com.github.santalu:aspect-ratio-imageview:1.0.6'
|
||||||
|
implementation 'com.felipecsl:gifimageview:2.2.0'
|
||||||
}
|
}
|
||||||
|
54
app/src/main/java/CustomView/AspectRatioGifImageView.java
Normal file
54
app/src/main/java/CustomView/AspectRatioGifImageView.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package CustomView;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import com.felipecsl.gifimageview.library.GifImageView;
|
||||||
|
|
||||||
|
public class AspectRatioGifImageView extends GifImageView {
|
||||||
|
private float ratio;
|
||||||
|
|
||||||
|
public final float getRatio() {
|
||||||
|
return this.ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setRatio(float var1) {
|
||||||
|
this.ratio = var1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void init(Context context, AttributeSet attrs) {
|
||||||
|
if (attrs != null) {
|
||||||
|
TypedArray a = context.obtainStyledAttributes(attrs, com.santalu.aspectratioimageview.R.styleable.AspectRatioImageView);
|
||||||
|
this.ratio = a.getFloat(com.santalu.aspectratioimageview.R.styleable.AspectRatioImageView_ari_ratio, 1.0F);
|
||||||
|
a.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
int width = this.getMeasuredWidth();
|
||||||
|
int height = this.getMeasuredHeight();
|
||||||
|
if (width != 0 || height != 0) {
|
||||||
|
if (width > 0) {
|
||||||
|
height = (int)((float)width * this.ratio);
|
||||||
|
} else {
|
||||||
|
width = (int)((float)height / this.ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setMeasuredDimension(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AspectRatioGifImageView(Context context) {
|
||||||
|
super(context);
|
||||||
|
this.ratio = 1.0F;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AspectRatioGifImageView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
this.ratio = 1.0F;
|
||||||
|
this.init(context, attrs);
|
||||||
|
}
|
||||||
|
}
|
@ -61,7 +61,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
private PostRecyclerViewAdapter mAdapter;
|
private PostRecyclerViewAdapter mAdapter;
|
||||||
|
|
||||||
private PostViewModel mPostViewModel;
|
PostViewModel mPostViewModel;
|
||||||
|
|
||||||
@Inject @Named("no_oauth")
|
@Inject @Named("no_oauth")
|
||||||
Retrofit mRetrofit;
|
Retrofit mRetrofit;
|
||||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.ColorFilter;
|
import android.graphics.ColorFilter;
|
||||||
|
import android.graphics.drawable.Animatable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@ -32,14 +33,14 @@ import com.bumptech.glide.load.engine.GlideException;
|
|||||||
import com.bumptech.glide.request.RequestListener;
|
import com.bumptech.glide.request.RequestListener;
|
||||||
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.santalu.aspectratioimageview.AspectRatioImageView;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import CustomView.AspectRatioGifImageView;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation;
|
import jp.wasabeef.glide.transformations.BlurTransformation;
|
||||||
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,10 +116,29 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
if(mContext != null && !mPostData.isEmpty()) {
|
if(mContext != null && !mPostData.isEmpty()) {
|
||||||
if(!iconImageUrl.equals("")) {
|
if(!iconImageUrl.equals("")) {
|
||||||
glide.load(iconImageUrl)
|
glide.load(iconImageUrl)
|
||||||
.into(((DataViewHolder) holder).subredditIconCircleImageView);
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon))
|
||||||
|
.listener(new RequestListener<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||||
|
if(resource instanceof Animatable) {
|
||||||
|
//This is a gif
|
||||||
|
//((Animatable) resource).start();
|
||||||
|
((DataViewHolder) holder).subredditIconGifImageView.startAnimation();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon)
|
glide.load(R.drawable.subreddit_default_icon)
|
||||||
.into(((DataViewHolder) holder).subredditIconCircleImageView);
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(holder.getAdapterPosition() >= 0) {
|
if(holder.getAdapterPosition() >= 0) {
|
||||||
@ -128,9 +148,30 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
|
} else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
|
||||||
glide.load(mPostData.get(position).getSubredditIconUrl()).into(((DataViewHolder) holder).subredditIconCircleImageView);
|
glide.load(mPostData.get(position).getSubredditIconUrl())
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon))
|
||||||
|
.listener(new RequestListener<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||||
|
if(resource instanceof Animatable) {
|
||||||
|
//This is a gif
|
||||||
|
//((Animatable) resource).start();
|
||||||
|
((DataViewHolder) holder).subredditIconGifImageView.startAnimation();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon).into(((DataViewHolder) holder).subredditIconCircleImageView);
|
glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.into(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
((DataViewHolder) holder).cardView.setOnClickListener(new View.OnClickListener() {
|
((DataViewHolder) holder).cardView.setOnClickListener(new View.OnClickListener() {
|
||||||
@ -146,7 +187,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
((DataViewHolder) holder).subredditIconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
((DataViewHolder) holder).subredditIconGifImageView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if(canStartActivity) {
|
if(canStartActivity) {
|
||||||
@ -537,7 +578,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
|
|
||||||
class DataViewHolder extends RecyclerView.ViewHolder {
|
class DataViewHolder extends RecyclerView.ViewHolder {
|
||||||
@BindView(R.id.card_view_view_post_detail) CardView cardView;
|
@BindView(R.id.card_view_view_post_detail) CardView cardView;
|
||||||
@BindView(R.id.subreddit_icon_circle_image_view_best_post_item) CircleImageView subredditIconCircleImageView;
|
@BindView(R.id.subreddit_icon_gif_image_view_best_post_item) AspectRatioGifImageView subredditIconGifImageView;
|
||||||
@BindView(R.id.subreddit_text_view_best_post_item) TextView subredditNameTextView;
|
@BindView(R.id.subreddit_text_view_best_post_item) TextView subredditNameTextView;
|
||||||
@BindView(R.id.stickied_post_image_view_best_post_item) ImageView stickiedPostImageView;
|
@BindView(R.id.stickied_post_image_view_best_post_item) ImageView stickiedPostImageView;
|
||||||
@BindView(R.id.post_time_text_view_best_post_item) TextView postTimeTextView;
|
@BindView(R.id.post_time_text_view_best_post_item) TextView postTimeTextView;
|
||||||
@ -549,7 +590,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
@BindView(R.id.nsfw_text_view_item_best_post) TextView nsfwTextView;
|
@BindView(R.id.nsfw_text_view_item_best_post) TextView nsfwTextView;
|
||||||
@BindView(R.id.image_view_wrapper_item_best_post) RelativeLayout relativeLayout;
|
@BindView(R.id.image_view_wrapper_item_best_post) RelativeLayout relativeLayout;
|
||||||
@BindView(R.id.progress_bar_best_post_item) ProgressBar progressBar;
|
@BindView(R.id.progress_bar_best_post_item) ProgressBar progressBar;
|
||||||
@BindView(R.id.image_view_best_post_item) AspectRatioImageView imageView;
|
@BindView(R.id.image_view_best_post_item) AspectRatioGifImageView imageView;
|
||||||
@BindView(R.id.load_image_error_relative_layout_best_post_item) RelativeLayout errorRelativeLayout;
|
@BindView(R.id.load_image_error_relative_layout_best_post_item) RelativeLayout errorRelativeLayout;
|
||||||
@BindView(R.id.image_view_no_preview_link_best_post_item) ImageView noPreviewLinkImageView;
|
@BindView(R.id.image_view_no_preview_link_best_post_item) ImageView noPreviewLinkImageView;
|
||||||
@BindView(R.id.plus_button_item_best_post) ImageView upvoteButton;
|
@BindView(R.id.plus_button_item_best_post) ImageView upvoteButton;
|
||||||
@ -577,8 +618,14 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
if(holder instanceof DataViewHolder) {
|
if(holder instanceof DataViewHolder) {
|
||||||
|
if(((DataViewHolder) holder).imageView.isAnimating()) {
|
||||||
|
((DataViewHolder) holder).imageView.stopAnimation();
|
||||||
|
}
|
||||||
|
if(((DataViewHolder) holder).subredditIconGifImageView.isAnimating()) {
|
||||||
|
((DataViewHolder) holder).subredditIconGifImageView.stopAnimation();
|
||||||
|
}
|
||||||
glide.clear(((DataViewHolder) holder).imageView);
|
glide.clear(((DataViewHolder) holder).imageView);
|
||||||
glide.clear(((DataViewHolder) holder).subredditIconCircleImageView);
|
glide.clear(((DataViewHolder) holder).subredditIconGifImageView);
|
||||||
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE);
|
((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE);
|
||||||
((DataViewHolder) holder).relativeLayout.setVisibility(View.GONE);
|
((DataViewHolder) holder).relativeLayout.setVisibility(View.GONE);
|
||||||
((DataViewHolder) holder).gildedImageView.setVisibility(View.GONE);
|
((DataViewHolder) holder).gildedImageView.setVisibility(View.GONE);
|
||||||
|
@ -2,7 +2,10 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Animatable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -11,10 +14,16 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
|
import com.bumptech.glide.load.DataSource;
|
||||||
|
import com.bumptech.glide.load.engine.GlideException;
|
||||||
|
import com.bumptech.glide.request.RequestListener;
|
||||||
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
|
import com.bumptech.glide.request.target.Target;
|
||||||
|
import com.felipecsl.gifimageview.library.GifImageView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
|
|
||||||
class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@ -54,9 +63,30 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!mSubscribedSubredditData.get(i).getIconUrl().equals("")) {
|
if(!mSubscribedSubredditData.get(i).getIconUrl().equals("")) {
|
||||||
glide.load(mSubscribedSubredditData.get(i).getIconUrl()).into(((SubredditViewHolder) viewHolder).iconCircleImageView);
|
glide.load(mSubscribedSubredditData.get(i).getIconUrl())
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon))
|
||||||
|
.listener(new RequestListener<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||||
|
if(resource instanceof Animatable) {
|
||||||
|
//This is a gif
|
||||||
|
//((Animatable) resource).start();
|
||||||
|
((SubredditViewHolder) viewHolder).iconGifImageView.startAnimation();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).into(((SubredditViewHolder) viewHolder).iconGifImageView);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon).into(((SubredditViewHolder) viewHolder).iconCircleImageView);
|
glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.into(((SubredditViewHolder) viewHolder).iconGifImageView);
|
||||||
}
|
}
|
||||||
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(mSubscribedSubredditData.get(i).getName());
|
((SubredditViewHolder) viewHolder).subredditNameTextView.setText(mSubscribedSubredditData.get(i).getName());
|
||||||
}
|
}
|
||||||
@ -71,7 +101,10 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
glide.clear(((SubredditViewHolder) holder).iconCircleImageView);
|
if(((SubredditViewHolder) holder).iconGifImageView.isAnimating()) {
|
||||||
|
((SubredditViewHolder) holder).iconGifImageView.stopAnimation();
|
||||||
|
}
|
||||||
|
glide.clear(((SubredditViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits){
|
void setSubscribedSubreddits(List<SubscribedSubredditData> subscribedSubreddits){
|
||||||
@ -81,12 +114,12 @@ class SubscribedSubredditRecyclerViewAdapter extends RecyclerView.Adapter<Recycl
|
|||||||
|
|
||||||
|
|
||||||
private class SubredditViewHolder extends RecyclerView.ViewHolder {
|
private class SubredditViewHolder extends RecyclerView.ViewHolder {
|
||||||
private final CircleImageView iconCircleImageView;
|
private final GifImageView iconGifImageView;
|
||||||
private final TextView subredditNameTextView;
|
private final TextView subredditNameTextView;
|
||||||
|
|
||||||
public SubredditViewHolder(View itemView) {
|
public SubredditViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
iconCircleImageView = itemView.findViewById(R.id.subreddit_icon_circle_image_view_item_subscribed_subreddit);
|
iconGifImageView = itemView.findViewById(R.id.subreddit_icon_gif_image_view_item_subscribed_subreddit);
|
||||||
subredditNameTextView = itemView.findViewById(R.id.subreddit_name_text_view_item_subscribed_subreddit);
|
subredditNameTextView = itemView.findViewById(R.id.subreddit_name_text_view_item_subscribed_subreddit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.Animatable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -10,10 +13,16 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
|
import com.bumptech.glide.load.DataSource;
|
||||||
|
import com.bumptech.glide.load.engine.GlideException;
|
||||||
|
import com.bumptech.glide.request.RequestListener;
|
||||||
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
|
import com.bumptech.glide.request.target.Target;
|
||||||
|
import com.felipecsl.gifimageview.library.GifImageView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
|
|
||||||
class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private List<SubscribedUserData> mSubscribedUserData;
|
private List<SubscribedUserData> mSubscribedUserData;
|
||||||
@ -36,7 +45,7 @@ class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
|
||||||
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
@ -46,9 +55,29 @@ class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(!mSubscribedUserData.get(i).getIconUrl().equals("")) {
|
if(!mSubscribedUserData.get(i).getIconUrl().equals("")) {
|
||||||
glide.load(mSubscribedUserData.get(i).getIconUrl()).into(((UserViewHolder) viewHolder).iconCircleImageView);
|
glide.load(mSubscribedUserData.get(i).getIconUrl())
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon))
|
||||||
|
.listener(new RequestListener<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||||
|
if(resource instanceof Animatable) {
|
||||||
|
//This is a gif
|
||||||
|
((Animatable) resource).start();
|
||||||
|
((SubscribedUserRecyclerViewAdapter.UserViewHolder) viewHolder).iconGifImageView.startAnimation();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).into(((UserViewHolder) viewHolder).iconGifImageView);
|
||||||
} else {
|
} else {
|
||||||
glide.load(R.drawable.subreddit_default_icon).into(((UserViewHolder) viewHolder).iconCircleImageView);
|
glide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.into(((UserViewHolder) viewHolder).iconGifImageView);
|
||||||
}
|
}
|
||||||
((UserViewHolder) viewHolder).subredditNameTextView.setText(mSubscribedUserData.get(i).getName());
|
((UserViewHolder) viewHolder).subredditNameTextView.setText(mSubscribedUserData.get(i).getName());
|
||||||
}
|
}
|
||||||
@ -63,7 +92,7 @@ class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||||
glide.clear(((UserViewHolder) holder).iconCircleImageView);
|
glide.clear(((UserViewHolder) holder).iconGifImageView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSubscribedUsers(List<SubscribedUserData> subscribedUsers){
|
void setSubscribedUsers(List<SubscribedUserData> subscribedUsers){
|
||||||
@ -73,12 +102,12 @@ class SubscribedUserRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||||||
|
|
||||||
|
|
||||||
private class UserViewHolder extends RecyclerView.ViewHolder {
|
private class UserViewHolder extends RecyclerView.ViewHolder {
|
||||||
private final CircleImageView iconCircleImageView;
|
private final GifImageView iconGifImageView;
|
||||||
private final TextView subredditNameTextView;
|
private final TextView subredditNameTextView;
|
||||||
|
|
||||||
public UserViewHolder(View itemView) {
|
public UserViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
iconCircleImageView = itemView.findViewById(R.id.subreddit_icon_circle_image_view_item_subscribed_subreddit);
|
iconGifImageView = itemView.findViewById(R.id.subreddit_icon_gif_image_view_item_subscribed_subreddit);
|
||||||
subredditNameTextView = itemView.findViewById(R.id.subreddit_name_text_view_item_subscribed_subreddit);
|
subredditNameTextView = itemView.findViewById(R.id.subreddit_name_text_view_item_subscribed_subreddit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
import android.arch.lifecycle.Observer;
|
import android.arch.lifecycle.Observer;
|
||||||
import android.arch.lifecycle.ViewModelProviders;
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Animatable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@ -21,13 +23,19 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.Glide;
|
||||||
import com.bumptech.glide.RequestManager;
|
import com.bumptech.glide.RequestManager;
|
||||||
|
import com.bumptech.glide.load.DataSource;
|
||||||
|
import com.bumptech.glide.load.engine.GlideException;
|
||||||
|
import com.bumptech.glide.request.RequestListener;
|
||||||
|
import com.bumptech.glide.request.RequestOptions;
|
||||||
|
import com.bumptech.glide.request.target.Target;
|
||||||
|
import com.felipecsl.gifimageview.library.GifImageView;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import de.hdodenhof.circleimageview.CircleImageView;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class ViewSubredditDetailActivity extends AppCompatActivity {
|
public class ViewSubredditDetailActivity extends AppCompatActivity {
|
||||||
@ -39,7 +47,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
|||||||
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
|
private static final String FRAGMENT_OUT_STATE_KEY = "FOSK";
|
||||||
|
|
||||||
@BindView(R.id.banner_image_view_view_subreddit_detail_activity) ImageView bannerImageView;
|
@BindView(R.id.banner_image_view_view_subreddit_detail_activity) ImageView bannerImageView;
|
||||||
@BindView(R.id.icon_circle_image_view_view_subreddit_detail_activity) CircleImageView iconCircleImageView;
|
@BindView(R.id.icon_gif_image_view_view_subreddit_detail_activity) GifImageView iconGifImageView;
|
||||||
@BindView(R.id.subreddit_name_text_view_view_subreddit_detail_activity) TextView subredditNameTextView;
|
@BindView(R.id.subreddit_name_text_view_view_subreddit_detail_activity) TextView subredditNameTextView;
|
||||||
@BindView(R.id.subscriber_count_text_view_view_subreddit_detail_activity) TextView nSubscribersTextView;
|
@BindView(R.id.subscriber_count_text_view_view_subreddit_detail_activity) TextView nSubscribersTextView;
|
||||||
@BindView(R.id.online_subscriber_count_text_view_view_subreddit_detail_activity) TextView nOnlineSubscribersTextView;
|
@BindView(R.id.online_subscriber_count_text_view_view_subreddit_detail_activity) TextView nOnlineSubscribersTextView;
|
||||||
@ -117,7 +125,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
|||||||
public void onChanged(@Nullable final SubredditData subredditData) {
|
public void onChanged(@Nullable final SubredditData subredditData) {
|
||||||
if(subredditData != null) {
|
if(subredditData != null) {
|
||||||
if(subredditData.getBannerUrl().equals("")) {
|
if(subredditData.getBannerUrl().equals("")) {
|
||||||
iconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
iconGifImageView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
//Do nothing as it has no image
|
//Do nothing as it has no image
|
||||||
@ -138,16 +146,37 @@ public class ViewSubredditDetailActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(subredditData.getIconUrl().equals("")) {
|
if(subredditData.getIconUrl().equals("")) {
|
||||||
glide.load(getDrawable(R.drawable.subreddit_default_icon)).into(iconCircleImageView);
|
glide.load(getDrawable(R.drawable.subreddit_default_icon))
|
||||||
iconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))
|
||||||
|
.into(iconGifImageView);
|
||||||
|
iconGifImageView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
//Do nothing as it is a default icon
|
//Do nothing as it is a default icon
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
glide.load(subredditData.getIconUrl()).into(iconCircleImageView);
|
glide.load(subredditData.getIconUrl())
|
||||||
iconCircleImageView.setOnClickListener(new View.OnClickListener() {
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(216, 0)))
|
||||||
|
.error(glide.load(R.drawable.subreddit_default_icon))
|
||||||
|
.listener(new RequestListener<Drawable>() {
|
||||||
|
@Override
|
||||||
|
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
|
||||||
|
if(resource instanceof Animatable) {
|
||||||
|
//This is a gif
|
||||||
|
((Animatable) resource).start();
|
||||||
|
iconGifImageView.startAnimation();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.into(iconGifImageView);
|
||||||
|
iconGifImageView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class);
|
Intent intent = new Intent(ViewSubredditDetailActivity.this, ViewImageActivity.class);
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
android:layout_height="180dp" />
|
android:layout_height="180dp" />
|
||||||
|
|
||||||
<de.hdodenhof.circleimageview.CircleImageView
|
<com.felipecsl.gifimageview.library.GifImageView
|
||||||
android:id="@+id/icon_circle_image_view_view_subreddit_detail_activity"
|
android:id="@+id/icon_gif_image_view_view_subreddit_detail_activity"
|
||||||
android:layout_width="72dp"
|
android:layout_width="72dp"
|
||||||
android:layout_height="72dp"
|
android:layout_height="72dp"
|
||||||
android:layout_marginTop="-36dp"
|
android:layout_marginTop="-36dp"
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:layout_marginTop="16dp">
|
android:layout_marginTop="16dp">
|
||||||
|
|
||||||
<de.hdodenhof.circleimageview.CircleImageView
|
<CustomView.AspectRatioGifImageView
|
||||||
android:id="@+id/subreddit_icon_circle_image_view_best_post_item"
|
android:id="@+id/subreddit_icon_gif_image_view_best_post_item"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"
|
||||||
@ -34,7 +34,7 @@
|
|||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:layout_toStartOf="@id/stickied_post_image_view_best_post_item"
|
android:layout_toStartOf="@id/stickied_post_image_view_best_post_item"
|
||||||
android:layout_toEndOf="@id/subreddit_icon_circle_image_view_best_post_item"
|
android:layout_toEndOf="@id/subreddit_icon_gif_image_view_best_post_item"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:textColor="#E91E63"/>
|
android:textColor="#E91E63"/>
|
||||||
|
|
||||||
@ -148,7 +148,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerInParent="true" />
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
<com.santalu.aspectratioimageview.AspectRatioImageView
|
<CustomView.AspectRatioGifImageView
|
||||||
android:id="@+id/image_view_best_post_item"
|
android:id="@+id/image_view_best_post_item"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:background="?attr/selectableItemBackground">
|
||||||
|
|
||||||
<de.hdodenhof.circleimageview.CircleImageView
|
<com.felipecsl.gifimageview.library.GifImageView
|
||||||
android:id="@+id/subreddit_icon_circle_image_view_item_subscribed_subreddit"
|
android:id="@+id/subreddit_icon_gif_image_view_item_subscribed_subreddit"
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user