mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-23 13:59:29 +00:00
Created WebUserAccountImage object
This commit is contained in:
parent
db68d5be18
commit
d2f2ea63f4
@ -25,6 +25,7 @@ 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 org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -97,19 +98,18 @@ public class PostsAdapter extends ArrayAdapter<Post>{
|
||||
userInfo = mUsersInfos.get(post.getUserID());
|
||||
|
||||
//Get the views related to user Information
|
||||
ImageView userAccountImage = convertView.findViewById(R.id.user_account_image);
|
||||
WebUserAccountImage userAccountImage = convertView.findViewById(R.id.user_account_image);
|
||||
TextView userAccountName = convertView.findViewById(R.id.user_account_name);
|
||||
|
||||
//Reset user information
|
||||
userAccountName.setText("");
|
||||
ImageLoadHelper.remove(userAccountImage);
|
||||
userAccountImage.setImageDrawable(UiUtils.getDrawable(getContext(),
|
||||
R.drawable.default_account_image));
|
||||
|
||||
//Set user information if available
|
||||
if(userInfo != null){
|
||||
userAccountName.setText(userInfo.getDisplayFullName());
|
||||
ImageLoadHelper.load(getContext(), userInfo.getAcountImageURL(), userAccountImage);
|
||||
userAccountImage.setUser(userInfo);
|
||||
}
|
||||
else {
|
||||
//Reset user information
|
||||
userAccountName.setText("");
|
||||
userAccountImage.removeUser();
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,6 +21,15 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView {
|
||||
*/
|
||||
private String mCurrURL;
|
||||
|
||||
/**
|
||||
* Default drawable ID (displayed on loading)
|
||||
*/
|
||||
private int mDefaultDrawable = R.drawable.img_placeholder;
|
||||
|
||||
|
||||
/**
|
||||
* Constructors
|
||||
*/
|
||||
public WebImageView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@ -33,6 +42,25 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current default drawable for this view
|
||||
*
|
||||
* @return The default drawable
|
||||
*/
|
||||
public int getDefaultDrawable() {
|
||||
return mDefaultDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default drawable for this view. This drawable will be used while the other one
|
||||
* is loading
|
||||
*
|
||||
* @param defaultDrawable The default drawable
|
||||
*/
|
||||
public void setDefaultDrawable(int defaultDrawable) {
|
||||
this.mDefaultDrawable = defaultDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an image specified by its URL in the image
|
||||
*
|
||||
@ -48,7 +76,7 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView {
|
||||
|
||||
//Reset image loader
|
||||
ImageLoadHelper.remove(this);
|
||||
setImageDrawable(UiUtils.getDrawable(getContext(), R.drawable.img_placeholder));
|
||||
setImageDrawable(UiUtils.getDrawable(getContext(), mDefaultDrawable));
|
||||
ImageLoadHelper.load(getContext(), url, this);
|
||||
|
||||
//Save image URL
|
||||
|
@ -0,0 +1,62 @@
|
||||
package org.communiquons.android.comunic.client.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||
|
||||
/**
|
||||
* WebAccountImage - This view is used to display user account image
|
||||
*
|
||||
* Created by pierre on 4/14/18.
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
public class WebUserAccountImage extends WebImageView {
|
||||
public WebUserAccountImage(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public WebUserAccountImage(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public WebUserAccountImage(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the view
|
||||
*
|
||||
* This method should be called by all the constructor of the view
|
||||
*/
|
||||
private void init(){
|
||||
|
||||
//Update the default drawable
|
||||
setDefaultDrawable(R.drawable.default_account_image);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user for the view
|
||||
*
|
||||
* @param user Information about the user
|
||||
*/
|
||||
public void setUser(@NonNull UserInfo user){
|
||||
loadURL(user.getAcountImageURL());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currently loaded user and display the default account image
|
||||
*/
|
||||
public void removeUser(){
|
||||
removeImage();
|
||||
setImageDrawable(UiUtils.getDrawable(getContext(), getDefaultDrawable()));
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
<org.communiquons.android.comunic.client.ui.views.WebUserAccountImage
|
||||
android:id="@+id/user_account_image"
|
||||
android:layout_width="@dimen/account_image_default_width"
|
||||
android:layout_height="@dimen/account_image_default_height"
|
||||
|
Loading…
Reference in New Issue
Block a user