forked from melod1n/fast-messenger
Mentions matching
This commit is contained in:
Generated
+1
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
@@ -392,7 +392,7 @@ class MessagesAdapter(
|
|||||||
if (message.isOutbox()) R.attr.messageOutTextColor else R.attr.messageInTextColor
|
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) {
|
fun prepareDate(message: VKMessage, date: TextView) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.meloda.fast.api.model
|
|||||||
|
|
||||||
import android.util.ArrayMap
|
import android.util.ArrayMap
|
||||||
import androidx.room.*
|
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.ArrayListToByteArrayConverter
|
||||||
import com.meloda.fast.database.dao.converters.ForwardedConverter
|
import com.meloda.fast.database.dao.converters.ForwardedConverter
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
@@ -125,7 +126,9 @@ open class VKMessage() : VKModel() {
|
|||||||
fromId = o.optInt("from_id", -1)
|
fromId = o.optInt("from_id", -1)
|
||||||
editTime = o.optInt("edit_time", -1)
|
editTime = o.optInt("edit_time", -1)
|
||||||
isOut = o.optInt("out") == 1
|
isOut = o.optInt("out") == 1
|
||||||
text = o.optString("text")
|
|
||||||
|
text = VKUtil.prepareMessageText(o.optString("text"))
|
||||||
|
|
||||||
randomId = o.optInt("random_id", -1)
|
randomId = o.optInt("random_id", -1)
|
||||||
conversationMessageId = o.optInt("conversation_message_id", -1)
|
conversationMessageId = o.optInt("conversation_message_id", -1)
|
||||||
isImportant = o.optBoolean("important")
|
isImportant = o.optBoolean("important")
|
||||||
|
|||||||
@@ -80,8 +80,46 @@ object VKUtil {
|
|||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
fun matchMentions(text: String): String {
|
fun prepareMessageText(message: String): String {
|
||||||
return text
|
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 {
|
// fun removeTime(date: Date): Long {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class FragmentConversations : BaseFragment(), ConversationsView {
|
|||||||
|
|
||||||
private fun prepareToolbar() {
|
private fun prepareToolbar() {
|
||||||
initToolbar(R.id.toolbar)
|
initToolbar(R.id.toolbar)
|
||||||
toolbar.title = getString(R.string.navigation_conversations)
|
toolbar.title = getString(R.string.navigation_chats)
|
||||||
setProfileAvatar()
|
setProfileAvatar()
|
||||||
|
|
||||||
TaskManager.addOnEventListener(object : TaskManager.OnEventListener {
|
TaskManager.addOnEventListener(object : TaskManager.OnEventListener {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="16dp"
|
||||||
android:baselineAligned="false"
|
android:baselineAligned="false"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/navigationConversations"
|
android:id="@+id/navigationConversations"
|
||||||
android:icon="@drawable/ic_message_outline"
|
android:icon="@drawable/ic_message_outline"
|
||||||
android:title="@string/navigation_conversations" />
|
android:title="@string/navigation_chats" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/navigationImportant"
|
android:id="@+id/navigationImportant"
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<string name="activity_login">Login</string>
|
<string name="activity_login">Login</string>
|
||||||
|
|
||||||
<string name="navigation_search">Search</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_friends">Friends</string>
|
||||||
<string name="navigation_important">Important</string>
|
<string name="navigation_important">Important</string>
|
||||||
<string name="navigation_settings">Settings</string>
|
<string name="navigation_settings">Settings</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user