Reputation: 54
I'm writing a messenger like app. I already have a recyclerview for drawing messages list. But also, i need to draw some attachments inside of each message(like images, sound, files and so). The data strucutre of message is:
"id": 2,
"text": "Test",
"sendTime": "21:31 12.10.22",
"userId": 1,
"user": {
"id": 1,
"login": "geckon01",
"email": "[email protected]",
"role": "host",
"lastOnline": "2022-10-23T11:03:57.6349417",
"avatarFileId": 0,
"avatarBase64": null
},
"attachments": [{
"id": 1,
"type": "Image",
"data": null,
"user": {
"id": 1,
"login": "geckon01",
"email": "[email protected]",
"role": "host",
"lastOnline": "2022-10-23T11:03:57.6349417",
"avatarFileId": 0,
"avatarBase64": null
},
"file": {
"id": 1,
"directory": "graphics",
"fileName": "1c08af89-41f2-4f85-bb5a-3336a37e51bf.jpg",
"type": "Graphics",
"fileOwner": {
"id": 1,
"login": "geckon01",
"email": "[email protected]",
"role": "host",
"lastOnline": "2022-10-23T11:03:57.6349417",
"avatarFileId": 0,
"avatarBase64": null
}
},
"messageId": 2
}]
}
So, i need to draw different view for attachemnt depend on its type. I'm thought to use fragments, but in my opinion it can be slow. Complite message, should be like this, where item1,3,4 can be image,file,text and so.
Upvotes: 0
Views: 620
Reputation: 108
You can use ConcatAdapter. The idea is you create different adapter for each view type. Here's a pseudo code
val concatAdapter = ConcatAdapter()
val headerAdapter = HeaderAdapter()
val messagesAdapter = MessagesAdapter()
val attachmentAdapter = AttachmentAdapter()
concatAdapter.add(headerAdapter)
concatAdapter.add(messagesAdapter)
concatAdapter.add(attachmentAdapter)
recyclerView.adapter = concatAdapter
Upvotes: 1