Created WebImageView and applyed it to PostAdapter images.

This commit is contained in:
Pierre 2018-04-14 13:32:41 +02:00
parent 602cb9571d
commit db68d5be18
4 changed files with 79 additions and 6 deletions

View File

@ -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.data.utils.Utilities;
import org.communiquons.android.comunic.client.ui.views.EditCommentContentView; 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.LikeButtonView;
import org.communiquons.android.comunic.client.ui.views.WebImageView;
import java.util.ArrayList; import java.util.ArrayList;
@ -149,17 +150,23 @@ public class PostsAdapter extends ArrayAdapter<Post>{
((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent())); ((TextView) convertView.findViewById(R.id.post_content)).setText(Utilities.prepareStringTextView(post.getContent()));
//Set post image (if any) //Set post image (if any)
ImageView postImage = convertView.findViewById(R.id.post_image); WebImageView postImage = convertView.findViewById(R.id.post_image);
postImage.setVisibility(View.GONE);
postImage.setImageDrawable(null);
ImageLoadHelper.remove(postImage);
if(post.getType() == PostTypes.IMAGE){ if(post.getType() == PostTypes.IMAGE){
//Make image visible //Make image visible
postImage.setVisibility(View.VISIBLE); postImage.setVisibility(View.VISIBLE);
//Load image //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 //Set posts likes

View File

@ -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);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -70,10 +70,11 @@
</LinearLayout> </LinearLayout>
<!-- Post image (if any) --> <!-- Post image (if any) -->
<ImageView <org.communiquons.android.comunic.client.ui.views.WebImageView
android:id="@+id/post_image" android:id="@+id/post_image"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="200dp" android:layout_height="200dp"
android:src="@drawable/img_placeholder"
android:contentDescription="@string/post_image_description" android:contentDescription="@string/post_image_description"
android:scaleType="centerInside" /> android:scaleType="centerInside" />