Hey I have json response coming from retrofit. I w...
# android
v
Hey I have json response coming from retrofit. I want to filter accordingly to
sentAt
property. I want to compare latest time and move block accordingly to that. Right now in my json there is 4 items/block but it could be more. Can some one know how to filter list and modify in efficient way. Also i need to convert
sentAt
value in time and date format and store in other variable. The format of todays date will be in
time
and if date is old i need in
date
format. Added Data class ConversationsResponse
Copy code
data class ConversationsResponse(
    val conversations: List<Conversations>? = null
)
Conversations
Copy code
data class Conversations(
    val id: String? = null,
    val title: String? = null,
    val lastMessage: LastMessage? = null
)
LastMessage
Copy code
data class LastMessage(
    val id: String? = null,
    val text: String? = null,
    val sentAt: String? = null
)
🧵 2
Json Response
Copy code
{
  "conversations": [
    {
      "id": "789",
      "title": "Conversation Title 3",
      "lastMessage": {
        "id": "4677",
        "text": "Text 3",
        "sentAt": "2021-09-28T10:39:10.0492422+01:00"
      }
    },
    {
      "id": "456",
      "title": "Conversation Title 2",
      "lastMessage": {
        "id": "3c7e",
        "text": "Text2",
        "sentAt": "2021-09-26T12:39:10.0493518+01:00"
      }
    },
    {
      "id": "101",
      "title": "Conversation Title 4",
      "lastMessage": {
        "id": "f983",
        "text": "Text 4",
        "sentAt": "2021-09-30T13:39:10.0493537+01:00"
      }
    },
    {
      "id": "123",
      "title": "Conversation Title 1",
      "lastMessage": {
        "id": "f983",
        "text": "Text 1",
        "sentAt": "2021-09-26T12:38:00.0493537+01:00"
      }
    }......
  ]
}
Expected Result
Copy code
{
  "conversations": [
    {
      "id": "101",
      "title": "Conversation Title 4",
      "lastMessage": {
        "id": "f983",
        "text": "Text 4",
        "sentAt": "2021-09-30T13:39:10.0493537+01:00"
      }
    },
    {
      "id": "789",
      "title": "Conversation Title 3",
      "lastMessage": {
        "id": "4677",
        "text": "Text 3",
        "sentAt": "2021-09-28T10:39:10.0492422+01:00"
      }
    },
    {
      "id": "456",
      "title": "Conversation Title 2",
      "lastMessage": {
        "id": "3c7e",
        "text": "Text2",
        "sentAt": "2021-09-26T12:39:10.0493518+01:00"
      }
    },
    {
      "id": "123",
      "title": "Conversation Title 1",
      "lastMessage": {
        "id": "f983",
        "text": "Text 1",
        "sentAt": "2021-09-26T12:38:00.0493537+01:00"
      }
    }......
  ]
}
For example to store value in variable id : 101 time : 13:39 id : 789 time : 28/09/2021
m
are you just trying to order by
sentAt
?
v
@Matthew Laser Yes kind of