Added support for conversation images.

This commit is contained in:
Pierre HUBERT 2018-08-16 10:35:04 +02:00
parent 2a202f1308
commit 6252cfaf2f
3 changed files with 91 additions and 37 deletions

View File

@ -4,7 +4,6 @@ import android.content.Context;
import android.support.annotation.CallSuper; import android.support.annotation.CallSuper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.ArrayMap;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -12,12 +11,11 @@ import android.widget.TextView;
import org.communiquons.android.comunic.client.R; import org.communiquons.android.comunic.client.R;
import org.communiquons.android.comunic.client.data.arrays.ConversationMessagesList; import org.communiquons.android.comunic.client.data.arrays.ConversationMessagesList;
import org.communiquons.android.comunic.client.data.models.UserInfo;
import org.communiquons.android.comunic.client.data.models.ConversationMessage; import org.communiquons.android.comunic.client.data.models.ConversationMessage;
import org.communiquons.android.comunic.client.data.models.UserInfo;
import org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView;
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage; import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
import java.util.ArrayList;
/** /**
* Conversation messages adapter * Conversation messages adapter
* *
@ -121,11 +119,13 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
private class BaseMessageHolder extends RecyclerView.ViewHolder { private class BaseMessageHolder extends RecyclerView.ViewHolder {
private TextView mMessage; private TextView mMessage;
private EnlargeableWebImageView mImage;
BaseMessageHolder(@NonNull View itemView) { BaseMessageHolder(@NonNull View itemView) {
super(itemView); super(itemView);
mMessage = itemView.findViewById(R.id.message_body); mMessage = itemView.findViewById(R.id.message_body);
mImage = itemView.findViewById(R.id.messageImage);
} }
/** /**
@ -135,7 +135,16 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
*/ */
@CallSuper @CallSuper
void bind(int pos){ void bind(int pos){
mMessage.setText(mList.get(pos).getContent()); ConversationMessage message = mList.get(pos);
mMessage.setText(message.getContent());
mMessage.setVisibility(mMessage.getText().length() > 0 ? View.VISIBLE : View.GONE);
mImage.setVisibility(message.hasImage() ? View.VISIBLE : View.GONE);
if(message.hasImage())
mImage.loadURL(message.getImage_path());
else
mImage.removeImage();
} }
} }

View File

@ -6,41 +6,69 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="8dp"> android:paddingTop="16dp">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<org.communiquons.android.comunic.client.ui.views.WebUserAccountImage <org.communiquons.android.comunic.client.ui.views.WebUserAccountImage
android:id="@+id/account_image" android:id="@+id/account_image"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:src="@drawable/default_account_image"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
app:layout_constraintLeft_toLeftOf="parent" /> android:src="@drawable/default_account_image"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/user_name" android:id="@+id/user_name"
tools:text="John Doe"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:paddingBottom="4dp"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintLeft_toRightOf="@+id/account_image" app:layout_constraintLeft_toRightOf="@+id/account_image"
android:layout_marginStart="8dp" app:layout_constraintTop_toTopOf="@id/account_image"
app:layout_constraintTop_toTopOf="parent" tools:text="John Doe" />
android:layout_marginTop="4dp" />
<TextView <TextView
android:id="@+id/message_body" android:id="@+id/message_body"
tools:text="Hello man, how are you?"
android:background="@drawable/conversation_message_otheruser_bg"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="0dp"
android:background="@drawable/conversation_message_otheruser_bg"
android:maxWidth="240dp" android:maxWidth="240dp"
android:padding="8dp" android:padding="8dp"
android:textColor="@color/conversation_otheruser_messages_textColor" android:textColor="@color/conversation_otheruser_messages_textColor"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@+id/user_name"
app:layout_constraintLeft_toRightOf="@+id/account_image" app:layout_constraintLeft_toRightOf="@+id/account_image"
android:layout_marginStart="8dp" /> app:layout_constraintTop_toBottomOf="@+id/user_name"
tools:text="Hello man, how are you?" />
</android.support.constraint.ConstraintLayout>
<org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView
android:id="@+id/messageImage"
android:layout_width="157dp"
android:layout_height="98dp"
android:layout_marginStart="60dp"
android:layout_marginTop="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/constraintLayout2"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/img_placeholder"
android:scaleType="fitStart"/>
<!---<TextView <!---<TextView
android:id="@+id/text_message_time" android:id="@+id/text_message_time"

View File

@ -6,7 +6,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="8dp"> android:paddingTop="16dp">
<TextView <TextView
android:id="@+id/message_body" android:id="@+id/message_body"
@ -21,6 +21,23 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView
android:id="@+id/messageImage"
android:layout_width="157dp"
android:layout_height="98dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
android:scaleType="fitEnd"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/message_body"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/message_body"
app:layout_constraintTop_toBottomOf="@+id/message_body"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="@drawable/img_placeholder" />
<!--<TextView <!--<TextView
android:id="@+id/text_message_time" android:id="@+id/text_message_time"
android:text="11:40" android:text="11:40"