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
ad96c9db
Commit
ad96c9db
authored
Jan 04, 2018
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ChatRoomsAdapter.kt
parent
deb483de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
29 deletions
+50
-29
ChatRoomsAdapter.kt
...java/chat/rocket/android/chatrooms/ui/ChatRoomsAdapter.kt
+50
-29
No files found.
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsAdapter.kt
View file @
ad96c9db
package
chat.rocket.android.chatrooms.ui
package
chat.rocket.android.chatrooms.ui
import
DateTimeHelper
import
DrawableHelper
import
DrawableHelper
import
android.content.Context
import
android.content.Context
import
android.support.v7.widget.RecyclerView
import
android.support.v7.widget.RecyclerView
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
android.widget.TextView
import
chat.rocket.android.R
import
chat.rocket.android.R
import
chat.rocket.android.util.inflate
import
chat.rocket.android.util.setVisibility
import
chat.rocket.android.util.textContent
import
chat.rocket.common.model.BaseRoom.RoomType
import
chat.rocket.common.model.BaseRoom.RoomType
import
chat.rocket.core.model.ChatRoom
import
chat.rocket.core.model.ChatRoom
import
com.facebook.drawee.view.SimpleDraweeView
import
com.facebook.drawee.view.SimpleDraweeView
...
@@ -15,48 +19,65 @@ import kotlinx.android.synthetic.main.item_chat.view.*
...
@@ -15,48 +19,65 @@ import kotlinx.android.synthetic.main.item_chat.view.*
class
ChatRoomsAdapter
(
private
var
dataSet
:
MutableList
<
ChatRoom
>,
private
val
context
:
Context
)
:
RecyclerView
.
Adapter
<
ChatRoomsAdapter
.
ViewHolder
>()
{
class
ChatRoomsAdapter
(
private
var
dataSet
:
MutableList
<
ChatRoom
>,
private
val
context
:
Context
)
:
RecyclerView
.
Adapter
<
ChatRoomsAdapter
.
ViewHolder
>()
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
=
ViewHolder
(
parent
.
inflate
(
R
.
layout
.
item_chat
))
val
view
=
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
R
.
layout
.
item_chat
,
parent
,
false
)
return
ViewHolder
(
view
)
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
chat
=
dataSet
[
position
]
val
chatRoom
=
dataSet
[
position
]
val
chatRoomName
=
chatRoom
.
name
holder
.
chatName
.
textContent
=
chatRoomName
// holder.userAvatar.setImageURI(chat.user.avatarUri)
if
(
chatRoom
.
type
==
RoomType
.
ONE_TO_ONE
)
{
holder
.
chatName
.
text
=
chat
.
name
val
canonicalUrl
=
chatRoom
.
client
.
restUrl
.
toString
()
// holder.lastMessage.text = chat.lastMessage
// TODO get safe URL
// holder.lastMessageDateTime.text = DateTimeHelper.getDate(chat.lastMessageDateTime, context)
holder
.
userAvatar
.
setImageURI
(
canonicalUrl
+
"avatar/"
+
chatRoomName
)
holder
.
userAvatar
.
setVisibility
(
true
)
}
else
{
holder
.
roomAvatar
.
setImageDrawable
(
DrawableHelper
.
getTextDrawable
(
chatRoomName
))
holder
.
roomAvatar
.
setVisibility
(
true
)
}
when
(
chat
.
type
)
{
val
totalUnreadMessage
=
chatRoom
.
unread
RoomType
.
PRIVATE
->
{
when
{
DrawableHelper
.
compoundDrawable
(
holder
.
chatName
,
DrawableHelper
.
getDrawableFromId
(
R
.
drawable
.
ic_lock_outline_black
,
context
))
totalUnreadMessage
in
1
..
99
->
{
holder
.
unreadMessage
.
textContent
=
totalUnreadMessage
.
toString
()
holder
.
unreadMessage
.
setVisibility
(
true
)
}
}
RoomType
.
PUBLIC
->
{
totalUnreadMessage
>
99
->
{
DrawableHelper
.
compoundDrawable
(
holder
.
chatName
,
DrawableHelper
.
getDrawableFromId
(
R
.
drawable
.
ic_hashtag_black
,
context
))
holder
.
unreadMessage
.
textContent
=
context
.
getString
(
R
.
string
.
msg_more_than_ninety_nine_unread_messages
)
holder
.
unreadMessage
.
setVisibility
(
true
)
}
}
// chat.rocket.common.model.BaseRoom.RoomType.ONE_TO_ONE -> {
// DrawableHelper.compoundDrawable(holder.chatName, DrawableHelper.getUserStatusDrawable(chat.user.status, context))
// }
}
}
// val totalUnreadMessage = chat.totalUnreadMessages
val
lastMessage
=
chatRoom
.
lastMessage
// when {
val
lastMessageSender
=
lastMessage
?.
sender
// totalUnreadMessage in 1..99 -> {
if
(
lastMessage
!=
null
&&
lastMessageSender
!=
null
)
{
// holder.unreadMessage.text = totalUnreadMessage.toString()
val
message
=
lastMessage
.
message
// holder.unreadMessage.visibility = View.VISIBLE
val
senderUsername
=
lastMessageSender
.
username
// }
when
(
senderUsername
)
{
// totalUnreadMessage > 99 -> {
chatRoomName
->
{
// holder.unreadMessage.text = context.getString(R.string.msg_more_than_ninety_nine_unread_messages)
holder
.
lastMessage
.
textContent
=
message
// holder.unreadMessage.visibility = View.VISIBLE
}
// }
// TODO Change to MySelf
// }
chatRoom
.
user
?.
username
->
{
holder
.
lastMessage
.
textContent
=
context
.
getString
(
R
.
string
.
msg_you
)
+
": $message"
}
else
->
{
holder
.
lastMessage
.
textContent
=
"@$senderUsername: $message"
}
}
val
localDateTime
=
DateTimeHelper
.
getLocalDateTime
(
lastMessage
.
timestamp
)
holder
.
lastMessageDateTime
.
textContent
=
DateTimeHelper
.
getDate
(
localDateTime
,
context
)
}
}
}
override
fun
getItemCount
():
Int
=
dataSet
.
size
override
fun
getItemCount
():
Int
=
dataSet
.
size
override
fun
getItemViewType
(
position
:
Int
):
Int
=
position
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
class
ViewHolder
(
itemView
:
View
)
:
RecyclerView
.
ViewHolder
(
itemView
)
{
val
userAvatar
:
SimpleDraweeView
=
itemView
.
image_user_avatar
val
userAvatar
:
SimpleDraweeView
=
itemView
.
image_user_avatar
val
roomAvatar
:
ImageView
=
itemView
.
image_room_avatar
val
chatName
:
TextView
=
itemView
.
text_chat_name
val
chatName
:
TextView
=
itemView
.
text_chat_name
val
lastMessage
:
TextView
=
itemView
.
text_last_message
val
lastMessage
:
TextView
=
itemView
.
text_last_message
val
lastMessageDateTime
:
TextView
=
itemView
.
text_last_message_date_time
val
lastMessageDateTime
:
TextView
=
itemView
.
text_last_message_date_time
...
...
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