Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
7cb71c65
Commit
7cb71c65
authored
Jan 18, 2018
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render system messages
parent
00278aaf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
2 deletions
+41
-2
ChatRoomAdapter.kt
...n/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
+41
-2
No files found.
app/src/main/java/chat/rocket/android/chatroom/ui/ChatRoomAdapter.kt
View file @
7cb71c65
...
@@ -2,7 +2,13 @@ package chat.rocket.android.chatroom.ui
...
@@ -2,7 +2,13 @@ package chat.rocket.android.chatroom.ui
import
DateTimeHelper
import
DateTimeHelper
import
android.content.Context
import
android.content.Context
import
android.graphics.Color
import
android.graphics.Typeface
import
android.support.v7.widget.RecyclerView
import
android.support.v7.widget.RecyclerView
import
android.text.Spannable
import
android.text.SpannableString
import
android.text.style.ForegroundColorSpan
import
android.text.style.StyleSpan
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.ImageView
...
@@ -15,6 +21,7 @@ import chat.rocket.android.util.setVisibility
...
@@ -15,6 +21,7 @@ import chat.rocket.android.util.setVisibility
import
chat.rocket.android.util.textContent
import
chat.rocket.android.util.textContent
import
chat.rocket.common.util.ifNull
import
chat.rocket.common.util.ifNull
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.Message
import
chat.rocket.core.model.MessageType
import
chat.rocket.core.model.Value
import
chat.rocket.core.model.Value
import
com.facebook.drawee.view.SimpleDraweeView
import
com.facebook.drawee.view.SimpleDraweeView
import
kotlinx.android.synthetic.main.avatar.view.*
import
kotlinx.android.synthetic.main.avatar.view.*
...
@@ -79,8 +86,8 @@ class ChatRoomAdapter(private val context: Context,
...
@@ -79,8 +86,8 @@ class ChatRoomAdapter(private val context: Context,
private
fun
bindUserName
(
message
:
Message
,
textView
:
TextView
)
{
private
fun
bindUserName
(
message
:
Message
,
textView
:
TextView
)
{
val
useRealName
=
settings
?.
get
(
USE_REALNAME
)
?.
value
as
Boolean
val
useRealName
=
settings
?.
get
(
USE_REALNAME
)
?.
value
as
Boolean
val
realName
=
message
.
sender
?.
name
val
username
=
message
.
sender
?.
username
val
username
=
message
.
sender
?.
username
val
realName
=
message
.
sender
?.
name
val
senderName
=
if
(
useRealName
)
realName
else
username
val
senderName
=
if
(
useRealName
)
realName
else
username
senderName
.
let
{
senderName
.
let
{
// TODO: Fallback to username if real name happens to be null. ATM this could happen if the
// TODO: Fallback to username if real name happens to be null. ATM this could happen if the
...
@@ -96,7 +103,39 @@ class ChatRoomAdapter(private val context: Context,
...
@@ -96,7 +103,39 @@ class ChatRoomAdapter(private val context: Context,
}
}
private
fun
bindContent
(
message
:
Message
,
textView
:
TextView
)
{
private
fun
bindContent
(
message
:
Message
,
textView
:
TextView
)
{
textView
.
textContent
=
message
.
message
when
(
message
.
type
)
{
//TODO: Add implementation for other types.
//TODO: Move all those strings to xml. Refer to https://github.com/RocketChat/Rocket.Chat.Android/blob/develop/app/src/main/res/values/system_message_strings.xml
MessageType
.
MESSAGE_REMOVED
->
setSystemMessage
(
message
,
textView
,
"Message removed"
)
MessageType
.
USER_JOINED
->
setSystemMessage
(
message
,
textView
,
"Has joined the channel."
)
MessageType
.
USER_LEFT
->
setSystemMessage
(
message
,
textView
,
"Has left the channel."
)
MessageType
.
USER_ADDED
->
setSystemMessage
(
message
,
textView
,
"User ${message.message} added by ${message.sender?.username}"
)
else
->
textView
.
textContent
=
message
.
message
}
}
private
fun
setSystemMessage
(
message
:
Message
,
textView
:
TextView
,
msg
:
String
)
{
val
spannableMsg
=
SpannableString
(
msg
)
spannableMsg
.
setSpan
(
StyleSpan
(
Typeface
.
ITALIC
),
0
,
spannableMsg
.
length
,
0
)
spannableMsg
.
setSpan
(
ForegroundColorSpan
(
Color
.
GRAY
),
0
,
spannableMsg
.
length
,
0
)
if
(
message
.
type
==
MessageType
.
USER_ADDED
)
{
val
userAddedStartIndex
=
5
val
userAddedLastIndex
=
userAddedStartIndex
+
message
.
message
.
length
val
addedByStartIndex
=
userAddedLastIndex
+
10
val
addedByLastIndex
=
addedByStartIndex
+
message
.
sender
?.
username
!!
.
length
spannableMsg
.
setSpan
(
StyleSpan
(
Typeface
.
BOLD_ITALIC
),
userAddedStartIndex
,
userAddedLastIndex
,
0
)
spannableMsg
.
setSpan
(
StyleSpan
(
Typeface
.
BOLD_ITALIC
),
addedByStartIndex
,
addedByLastIndex
,
0
)
}
textView
.
text
=
spannableMsg
}
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment