diff --git a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/StringsUtils.java b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/StringsUtils.java index 8d6190d..e0ac025 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/data/utils/StringsUtils.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/data/utils/StringsUtils.java @@ -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); + } } diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/ConversationMessageAdapter.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/ConversationMessageAdapter.java index 888fe84..d912ae1 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/ConversationMessageAdapter.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/adapters/ConversationMessageAdapter.java @@ -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); } } diff --git a/app/src/main/res/layout/conversation_message_item_received.xml b/app/src/main/res/layout/conversation_message_item_received.xml index 35ec715..9c92e10 100644 --- a/app/src/main/res/layout/conversation_message_item_received.xml +++ b/app/src/main/res/layout/conversation_message_item_received.xml @@ -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"> - - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:text="5min" /> \ No newline at end of file diff --git a/app/src/main/res/layout/conversation_message_item_sent.xml b/app/src/main/res/layout/conversation_message_item_sent.xml index 1a21248..77e860c 100644 --- a/app/src/main/res/layout/conversation_message_item_sent.xml +++ b/app/src/main/res/layout/conversation_message_item_sent.xml @@ -10,16 +10,16 @@ + app:layout_constraintTop_toBottomOf="@+id/text_message_time" + tools:text="Hello, hello!" /> - + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 34c00b9..77251a7 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -32,4 +32,7 @@ 30dp + + + 8dp