mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Created WebImageView and applyed it to PostAdapter images.
This commit is contained in:
parent
602cb9571d
commit
db68d5be18
@ -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<Post>{
|
||||
((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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable/img_placeholder.png
Normal file
BIN
app/src/main/res/drawable/img_placeholder.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
@ -70,10 +70,11 @@
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Post image (if any) -->
|
||||
<ImageView
|
||||
<org.communiquons.android.comunic.client.ui.views.WebImageView
|
||||
android:id="@+id/post_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:src="@drawable/img_placeholder"
|
||||
android:contentDescription="@string/post_image_description"
|
||||
android:scaleType="centerInside" />
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user