forked from melod1n/fast-messenger
Mentions matching
This commit is contained in:
@@ -392,7 +392,7 @@ class MessagesAdapter(
|
||||
if (message.isOutbox()) R.attr.messageOutTextColor else R.attr.messageInTextColor
|
||||
)
|
||||
)
|
||||
text.text = VKUtil.matchMentions(message.text)
|
||||
text.text = message.text
|
||||
}
|
||||
|
||||
fun prepareDate(message: VKMessage, date: TextView) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.meloda.fast.api.model
|
||||
|
||||
import android.util.ArrayMap
|
||||
import androidx.room.*
|
||||
import com.meloda.fast.api.util.VKUtil
|
||||
import com.meloda.fast.database.dao.converters.ArrayListToByteArrayConverter
|
||||
import com.meloda.fast.database.dao.converters.ForwardedConverter
|
||||
import org.json.JSONObject
|
||||
@@ -125,7 +126,9 @@ open class VKMessage() : VKModel() {
|
||||
fromId = o.optInt("from_id", -1)
|
||||
editTime = o.optInt("edit_time", -1)
|
||||
isOut = o.optInt("out") == 1
|
||||
text = o.optString("text")
|
||||
|
||||
text = VKUtil.prepareMessageText(o.optString("text"))
|
||||
|
||||
randomId = o.optInt("random_id", -1)
|
||||
conversationMessageId = o.optInt("conversation_message_id", -1)
|
||||
isImportant = o.optBoolean("important")
|
||||
|
||||
@@ -80,8 +80,46 @@ object VKUtil {
|
||||
return values
|
||||
}
|
||||
|
||||
fun matchMentions(text: String): String {
|
||||
return text
|
||||
fun prepareMessageText(message: String): String {
|
||||
if (message.isEmpty()) return message
|
||||
|
||||
var newText = message
|
||||
|
||||
val mentions = hashMapOf<String, String>()
|
||||
|
||||
var startFrom = 0
|
||||
|
||||
while (true) {
|
||||
val leftBracketIndex = newText.indexOf('[', startFrom)
|
||||
val verticalLineIndex = newText.indexOf('|', startFrom)
|
||||
val rightBracketIndex = newText.indexOf(']', startFrom)
|
||||
|
||||
if (leftBracketIndex == -1 ||
|
||||
verticalLineIndex == -1 ||
|
||||
rightBracketIndex == -1
|
||||
) {
|
||||
break
|
||||
}
|
||||
|
||||
val id = newText.substring(leftBracketIndex + 1, verticalLineIndex)
|
||||
|
||||
if (!id.matches(Regex("^id(\\d+)\$")) || rightBracketIndex - verticalLineIndex < 2) {
|
||||
break
|
||||
}
|
||||
|
||||
val text = newText.substring(verticalLineIndex + 1, rightBracketIndex)
|
||||
|
||||
val str = "[$id|$text]"
|
||||
|
||||
mentions[str] = text
|
||||
startFrom = rightBracketIndex + 1
|
||||
}
|
||||
|
||||
mentions.forEach {
|
||||
newText = newText.replace(it.key, it.value)
|
||||
}
|
||||
|
||||
return newText
|
||||
}
|
||||
|
||||
// fun removeTime(date: Date): Long {
|
||||
|
||||
@@ -74,7 +74,7 @@ class FragmentConversations : BaseFragment(), ConversationsView {
|
||||
|
||||
private fun prepareToolbar() {
|
||||
initToolbar(R.id.toolbar)
|
||||
toolbar.title = getString(R.string.navigation_conversations)
|
||||
toolbar.title = getString(R.string.navigation_chats)
|
||||
setProfileAvatar()
|
||||
|
||||
TaskManager.addOnEventListener(object : TaskManager.OnEventListener {
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_vertical"
|
||||
android:singleLine="true"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<item
|
||||
android:id="@+id/navigationConversations"
|
||||
android:icon="@drawable/ic_message_outline"
|
||||
android:title="@string/navigation_conversations" />
|
||||
android:title="@string/navigation_chats" />
|
||||
|
||||
<item
|
||||
android:id="@+id/navigationImportant"
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<string name="activity_login">Login</string>
|
||||
|
||||
<string name="navigation_search">Search</string>
|
||||
<string name="navigation_conversations">Conversations</string>
|
||||
<string name="navigation_chats">Chats</string>
|
||||
<string name="navigation_friends">Friends</string>
|
||||
<string name="navigation_important">Important</string>
|
||||
<string name="navigation_settings">Settings</string>
|
||||
|
||||
Reference in New Issue
Block a user