From db68d5be1893dc612cb2bd80a99353899517d129 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 14 Apr 2018 13:32:41 +0200 Subject: [PATCH] Created WebImageView and applyed it to PostAdapter images. --- .../client/ui/adapters/PostsAdapter.java | 17 +++-- .../comunic/client/ui/views/WebImageView.java | 65 ++++++++++++++++++ app/src/main/res/drawable/img_placeholder.png | Bin 0 -> 4004 bytes app/src/main/res/layout/post_item.xml | 3 +- 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebImageView.java create mode 100644 app/src/main/res/drawable/img_placeholder.png 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 0000000000000000000000000000000000000000..b16692d4cafae238a765126a90023792f61ecc88 GIT binary patch literal 4004 zcmd^Cc{tSj8vo6bEnDdzlPI!>!c1k)-Z6-nEHRy@WE&hbh+(31N|sWxmE%+>NtCUz zjNFQ{M24{wi807tgPHrCah{%Y?{ogR_uqTJ&v%}gcl&@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