mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
It is possible to enlarge conversation messages images.
This commit is contained in:
parent
d48cdd1c32
commit
d9c61f652e
@ -18,6 +18,7 @@ import org.communiquons.android.comunic.client.data.helpers.ImageLoadHelper;
|
||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||
import org.communiquons.android.comunic.client.data.models.ConversationMessage;
|
||||
import org.communiquons.android.comunic.client.ui.utils.UiUtils;
|
||||
import org.communiquons.android.comunic.client.ui.views.WebImageView;
|
||||
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -96,7 +97,7 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
.findViewById(R.id.fragment_conversation_message_item_container);
|
||||
TextView contentView = convertView.
|
||||
findViewById(R.id.fragment_conversation_message_item_content);
|
||||
ImageView messageImageView = convertView.
|
||||
WebImageView messageImageView = convertView.
|
||||
findViewById(R.id.fragment_conversation_message_item_messageimage);
|
||||
WebUserAccountImage accountImageView;
|
||||
TextView userNameView = convertView.
|
||||
@ -181,8 +182,7 @@ public class ConversationMessageAdapter extends ArrayAdapter<ConversationMessage
|
||||
*/
|
||||
if(message.hasImage()){
|
||||
//Load the image
|
||||
ImageLoadHelper.remove(messageImageView);
|
||||
ImageLoadHelper.load(getContext(), message.getImage_path(), messageImageView);
|
||||
messageImageView.loadURL(message.getImage_path());
|
||||
|
||||
//Make the image visible
|
||||
messageImageView.setVisibility(View.VISIBLE);
|
||||
|
@ -0,0 +1,92 @@
|
||||
package org.communiquons.android.comunic.client.ui.views;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ActionMenuView;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.communiquons.android.comunic.client.R;
|
||||
|
||||
/**
|
||||
* Enlargeable images view.
|
||||
*
|
||||
* The image represented by this view can be clicked in order to be shown in a bigger way
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
* Created by pierre on 4/28/18.
|
||||
*/
|
||||
|
||||
public class EnlargeableWebImageView extends WebImageView {
|
||||
|
||||
/**
|
||||
* Optional additional OnClick Listener
|
||||
*/
|
||||
private OnClickListener mOnClickListener;
|
||||
|
||||
public EnlargeableWebImageView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public EnlargeableWebImageView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public EnlargeableWebImageView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize ImageView
|
||||
*/
|
||||
private void init(){
|
||||
|
||||
super.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
//Call additional onclick listener if required
|
||||
if(mOnClickListener != null)
|
||||
mOnClickListener.onClick(v);
|
||||
|
||||
openLargeImage();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(OnClickListener onClickListener) {
|
||||
this.mOnClickListener = onClickListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOnClickListeners() {
|
||||
return mOnClickListener == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the image in large dimensions
|
||||
*/
|
||||
public void openLargeImage(){
|
||||
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_image, null);
|
||||
WebImageView image = view.findViewById(R.id.image);
|
||||
|
||||
//Apply the image to the dialog (if available)
|
||||
if(hasImageURL()){
|
||||
image.loadURL(getCurrURL());
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setView(view)
|
||||
.show();
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -42,25 +42,6 @@ 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
|
||||
*
|
||||
@ -90,4 +71,41 @@ public class WebImageView extends android.support.v7.widget.AppCompatImageView {
|
||||
mCurrURL = null;
|
||||
ImageLoadHelper.remove(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current URL used in this image view
|
||||
*
|
||||
* @return The URL of the current image / null else
|
||||
*/
|
||||
public String getCurrURL() {
|
||||
return mCurrURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the current object has an image URL defined
|
||||
*
|
||||
* @return TRUE if a remote image as been set / FALSE else
|
||||
*/
|
||||
public boolean hasImageURL(){
|
||||
return mCurrURL != null;
|
||||
}
|
||||
}
|
||||
|
6
app/src/main/res/layout/dialog_image.xml
Normal file
6
app/src/main/res/layout/dialog_image.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.communiquons.android.comunic.client.ui.views.WebImageView android:src="@drawable/img_placeholder"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
@ -42,7 +42,7 @@
|
||||
android:textColor="@color/conversation_otheruser_messages_textColor"
|
||||
tools:text="A message"/>
|
||||
|
||||
<ImageView
|
||||
<org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView
|
||||
android:id="@+id/fragment_conversation_message_item_messageimage"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
|
Loading…
Reference in New Issue
Block a user