diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java index c0ffb2e..4e9e2c2 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/PostsAdapter.java @@ -24,6 +24,7 @@ import org.communiquons.android.comunic.client.ui.utils.UiUtils; import org.communiquons.android.comunic.client.data.utils.Utilities; import org.communiquons.android.comunic.client.ui.views.EditCommentContentView; import org.communiquons.android.comunic.client.ui.views.LikeButtonView; +import org.communiquons.android.comunic.client.ui.views.WebImageView; import java.util.ArrayList; @@ -149,17 +150,23 @@ public class PostsAdapter extends ArrayAdapter{ ((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent())); //Set post image (if any) - ImageView postImage = convertView.findViewById(R.id.post_image); - postImage.setVisibility(View.GONE); - postImage.setImageDrawable(null); - ImageLoadHelper.remove(postImage); + WebImageView postImage = convertView.findViewById(R.id.post_image); if(post.getType() == PostTypes.IMAGE){ //Make image visible postImage.setVisibility(View.VISIBLE); //Load image - ImageLoadHelper.load(getContext(), post.getFile_path_url(), postImage); + postImage.loadURL(post.getFile_path_url()); + } + else { + + //Hide the image + postImage.setVisibility(View.GONE); + + //Remove the image + postImage.removeImage(); + } //Set posts likes diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java new file mode 100644 index 0000000..5ee89f4 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java @@ -0,0 +1,65 @@ +package org.communiquons.android.comunic.client.ui.views; + +import android.content.Context; +import android.util.AttributeSet; + +import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper; +import org.communiquons.android.comunic.client.ui.utils.UiUtils; + +/** + * WebImageView is a view that extends image view in order to ease rendering of web images + * + * @author Pierre HUBERT + * Created by pierre on 4/14/18. + */ + +public class WebImageView extends android.support.v7.widget.AppCompatImageView { + + /** + * Currently loaded image image + */ + private String mCurrURL; + + public WebImageView(Context context) { + super(context); + } + + public WebImageView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public WebImageView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + /** + * Load an image specified by its URL in the image + * + * @param url The URL pointing on the image + */ + public void loadURL(String url){ + + //Check if the same URL is already being loaded + if(url.equals(mCurrURL)){ + //Do nothing + return; + } + + //Reset image loader + ImageLoadHelper.remove(this); + setImageDrawable(UiUtils.getDrawable(getContext(), R.drawable.img_placeholder)); + ImageLoadHelper.load(getContext(), url, this); + + //Save image URL + mCurrURL = url; + } + + /** + * Remove any image that was being loaded for this view + */ + public void removeImage() { + mCurrURL = null; + ImageLoadHelper.remove(this); + } +} diff --git a/app/src/main/res/drawable/img_placeholder.png b/app/src/main/res/drawable/img_placeholder.png new file mode 100644 index 0000000..b16692d Binary files /dev/null and b/app/src/main/res/drawable/img_placeholder.png differ diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index e99d420..5770a0d 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -70,10 +70,11 @@ -