diff --git a/app/src/main/java/com/example/markmoussa/meshchatapplication/ConversationListAdapter.kt b/app/src/main/java/com/example/markmoussa/meshchatapplication/ConversationListAdapter.kt
index 9ce0287..2a83c27 100644
--- a/app/src/main/java/com/example/markmoussa/meshchatapplication/ConversationListAdapter.kt
+++ b/app/src/main/java/com/example/markmoussa/meshchatapplication/ConversationListAdapter.kt
@@ -2,6 +2,7 @@ package com.example.markmoussa.meshchatapplication
import android.content.Context
import android.support.v7.widget.RecyclerView
+import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -57,8 +58,13 @@ class ConversationListAdapter(private val mContext: Context, private val mConver
} else {
usernameText.text = conversation.user.userIdentifier.toString()
}
- if(conversation.messageList != null) {
- messagePreviewText.text = conversation.messageList.getMessageStringAtIndex(conversation.messageList.lastReadIndex)
+ if(!(conversation.messageList?.getMessages()!!.isEmpty())) {
+
+ var messagePreview = conversation.messageList.getMessageStringAtIndex(conversation.messageList.getMessages().size - 1)
+ if(!(messagePreview.isNullOrEmpty()) && messagePreview!!.length > 40) {
+ messagePreview = messagePreview.substring(0, 33) + "..."
+ }
+ messagePreviewText.text = messagePreview
} else {
messagePreviewText.text = ""
}
diff --git a/app/src/main/java/com/example/markmoussa/meshchatapplication/Store.kt b/app/src/main/java/com/example/markmoussa/meshchatapplication/Store.kt
index 4b1a2b9..7290840 100644
--- a/app/src/main/java/com/example/markmoussa/meshchatapplication/Store.kt
+++ b/app/src/main/java/com/example/markmoussa/meshchatapplication/Store.kt
@@ -5,6 +5,7 @@ package com.example.markmoussa.meshchatapplication
// link: https://github.com/Hype-Labs/HypeChatDemo.android
import android.content.Context
+import android.util.Log
import java.io.Serializable
import java.lang.ref.WeakReference
import java.util.Vector
@@ -60,11 +61,12 @@ class Store(val userIdentifier: Long): Serializable {
}
fun getMessageStringAtIndex(index: Int): String? {
- if(messages.isEmpty() || messages!!.size >= index) {
+ if(messages.isEmpty() || messages!!.size < index) {
+ Log.d("Store", "this was activated")
// this means there's no message at this index and therefore need to return null
return null
}
- return messages[index].first.toString()
+ return messages[index].first
}
diff --git a/app/src/main/res/layout/item_conversation.xml b/app/src/main/res/layout/item_conversation.xml
index e0833f9..20ff729 100644
--- a/app/src/main/res/layout/item_conversation.xml
+++ b/app/src/main/res/layout/item_conversation.xml
@@ -9,36 +9,39 @@
android:id="@+id/userNameTextView"
android:layout_width="0dp"
android:layout_height="20dp"
+ android:layout_marginBottom="8dp"
android:layout_marginEnd="168dp"
+ android:layout_marginTop="16dp"
android:text="TextView"
- app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintBottom_toTopOf="@+id/messagePreviewTextView"
app:layout_constraintEnd_toStartOf="@+id/onlineStatusIcon"
app:layout_constraintStart_toEndOf="@+id/profilePicImageView"
app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintStart_toEndOf="@+id/profilePicImageView"
+ app:layout_constraintTop_toTopOf="parent" />