mirror of
https://github.com/pierre42100/ComunicAndroid
synced 2024-11-27 07:49:28 +00:00
Display date on conversation message
This commit is contained in:
parent
b5a7df3f3d
commit
323ddbf78f
@ -1,5 +1,7 @@
|
||||
package org.communiquons.android.comunic.client.data.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@ -47,4 +49,15 @@ public class StringsUtils {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Format timestamp to string
|
||||
*
|
||||
* @param time The time to format
|
||||
* @return Generated string
|
||||
*/
|
||||
public static String FormatDate(int time){
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY-MM-dd",
|
||||
Locale.getDefault());
|
||||
return simpleDateFormat.format((long)1000*time);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ import org.communiquons.android.comunic.client.R;
|
||||
import org.communiquons.android.comunic.client.data.arrays.ConversationMessagesList;
|
||||
import org.communiquons.android.comunic.client.data.models.ConversationMessage;
|
||||
import org.communiquons.android.comunic.client.data.models.UserInfo;
|
||||
import org.communiquons.android.comunic.client.data.utils.StringsUtils;
|
||||
import org.communiquons.android.comunic.client.data.utils.Utilities;
|
||||
import org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView;
|
||||
import org.communiquons.android.comunic.client.ui.views.WebUserAccountImage;
|
||||
|
||||
@ -51,6 +53,8 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
|
||||
*/
|
||||
private ConversationMessagesList mList;
|
||||
|
||||
private Utilities utils;
|
||||
|
||||
/**
|
||||
* Public class constructor
|
||||
*
|
||||
@ -66,6 +70,8 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
|
||||
this.mContext = context;
|
||||
this.mList = list;
|
||||
|
||||
utils = new Utilities(mContext);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,6 +125,7 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
|
||||
private class BaseMessageHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView mMessage;
|
||||
private TextView mSentDate;
|
||||
private EnlargeableWebImageView mImage;
|
||||
|
||||
BaseMessageHolder(@NonNull View itemView) {
|
||||
@ -126,6 +133,17 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
|
||||
|
||||
mMessage = itemView.findViewById(R.id.message_body);
|
||||
mImage = itemView.findViewById(R.id.messageImage);
|
||||
mSentDate = itemView.findViewById(R.id.text_message_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the time a message was sent as a string
|
||||
*
|
||||
* @param message Information about the message
|
||||
* @return Generated sent string
|
||||
*/
|
||||
String messageDate(ConversationMessage message){
|
||||
return StringsUtils.FormatDate(message.getTime_insert());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,6 +163,16 @@ public class ConversationMessageAdapter extends RecyclerView.Adapter {
|
||||
mImage.loadURL(message.getImage_path());
|
||||
else
|
||||
mImage.removeImage();
|
||||
|
||||
|
||||
mSentDate.setText(messageDate(message));
|
||||
|
||||
if(pos < 1)
|
||||
mSentDate.setVisibility(View.VISIBLE);
|
||||
else if(messageDate(mList.get(pos-1)).equals(messageDate(message)))
|
||||
mSentDate.setVisibility(View.GONE);
|
||||
else
|
||||
mSentDate.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,8 @@
|
||||
android:layout_marginStart="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
app:layout_constraintTop_toBottomOf="@id/text_message_time"
|
||||
tools:layout_editor_absoluteY="16dp">
|
||||
|
||||
<org.communiquons.android.comunic.client.ui.views.WebUserAccountImage
|
||||
android:id="@+id/account_image"
|
||||
@ -45,7 +46,7 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:background="@drawable/conversation_message_otheruser_bg"
|
||||
android:maxWidth="240dp"
|
||||
android:maxWidth="220dp"
|
||||
android:padding="8dp"
|
||||
android:textColor="@color/conversation_otheruser_messages_textColor"
|
||||
app:layout_constraintLeft_toRightOf="@+id/account_image"
|
||||
@ -69,15 +70,17 @@
|
||||
android:scaleType="fitStart"/>
|
||||
|
||||
|
||||
|
||||
<!---<TextView
|
||||
<TextView
|
||||
android:id="@+id/text_message_time"
|
||||
tools:text="5min"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="@dimen/conversation_message_time_padding_top"
|
||||
android:textSize="10sp"
|
||||
app:layout_constraintLeft_toRightOf="@+id/message_body"
|
||||
android:layout_marginLeft="4dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/message_body" />-->
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="5min" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -10,16 +10,16 @@
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_body"
|
||||
tools:text="Hello, hello!"
|
||||
android:background="@drawable/conversation_message_currentuser_bg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="8dp"
|
||||
android:background="@drawable/conversation_message_currentuser_bg"
|
||||
android:maxWidth="240dp"
|
||||
android:padding="8dp"
|
||||
android:textColor="#ffffff"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/text_message_time"
|
||||
tools:text="Hello, hello!" />
|
||||
|
||||
<org.communiquons.android.comunic.client.ui.views.EnlargeableWebImageView
|
||||
android:id="@+id/messageImage"
|
||||
@ -38,14 +38,17 @@
|
||||
app:layout_constraintVertical_bias="0.0"
|
||||
app:srcCompat="@drawable/img_placeholder" />
|
||||
|
||||
<!--<TextView
|
||||
<TextView
|
||||
android:id="@+id/text_message_time"
|
||||
android:text="11:40"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="@dimen/conversation_message_time_padding_top"
|
||||
android:text="11:40"
|
||||
android:textSize="10sp"
|
||||
android:layout_marginRight="4dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/message_body"
|
||||
app:layout_constraintRight_toLeftOf="@+id/message_body" />-->
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -32,4 +32,7 @@
|
||||
|
||||
<!-- Navigation bar -->
|
||||
<dimen name="nav_bar_ic_height">30dp</dimen>
|
||||
|
||||
<!-- Conversation fragment -->
|
||||
<dimen name="conversation_message_time_padding_top">8dp</dimen>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user