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 4e9e2c2..c22edcf 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 @@ -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{ 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(); } 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 index 5ee89f4..05063d4 100644 --- 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 @@ -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 diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebUserAccountImage.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebUserAccountImage.java new file mode 100644 index 0000000..4232107 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/WebUserAccountImage.java @@ -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())); + } +} diff --git a/app/src/main/res/layout/post_item.xml b/app/src/main/res/layout/post_item.xml index 5770a0d..7927c76 100644 --- a/app/src/main/res/layout/post_item.xml +++ b/app/src/main/res/layout/post_item.xml @@ -12,7 +12,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> -