Commit 1aee794d authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Sort chat list data by lastMessageDateTime.

parent 259ba172
......@@ -24,21 +24,21 @@ class ChatListFragment : Fragment() {
}
// This is just a sample showing 6 chat rooms (aka user subscription). We need to get it rid in a real word. REMARK: remove this comment and this method.
private fun createDumpData(): MutableList<Chat> {
val dumpChat1 = Chat("https://open.rocket.chat/avatar/filipe.brito",
"Filipe Brito",
"d",
"online",
"Type something...Type something...Type something",
LocalDateTime.of(2017, 11, 22,1, 3),
150)
val dumpChat2 = Chat("https://open.rocket.chat/avatar/leonardo.aramaki",
private fun createDumpData(): List<Chat> {
val dumpChat1 = Chat("https://open.rocket.chat/avatar/leonardo.aramaki",
"Leonardo Aramaki",
"d",
"busy",
"Type something",
LocalDateTime.of(2017, 11, 21,1, 3),
1)
val dumpChat2 = Chat("https://open.rocket.chat/avatar/filipe.brito",
"Filipe Brito",
"d",
"online",
"Type something...Type something...Type something",
LocalDateTime.of(2017, 11, 22,1, 3),
150)
val dumpChat3 = Chat("https://open.rocket.chat/avatar/lucio.maciel",
"Lucio Maciel",
"d",
......@@ -53,27 +53,29 @@ class ChatListFragment : Fragment() {
"@aaron.ogle @rafael.kellermann same problem over here. Although all the servers show up on the selection.",
LocalDateTime.of(2017, 11, 15,1, 3),
0)
val dumpChat5 = Chat("https://open.rocket.chat/avatar/matheus.cardoso",
"androidnativeapp",
"c",
null,
"Yes @sttyru, but you'll need to implement from the ground up following the docs at docs.rocket.chat where you can see the REST (HTTP) and Real-Time (WebSockets) calls.",
LocalDateTime.of(2017, 11, 14,1, 3),
0)
val dumpChat6 = Chat("https://open.rocket.chat/avatar/hetal",
val dumpChat5 = Chat("https://open.rocket.chat/avatar/hetal",
"general",
"c",
null,
"Has joined the channel.",
LocalDateTime.of(2017, 11, 13,1, 3),
0)
return arrayListOf(dumpChat1, dumpChat2, dumpChat3, dumpChat4, dumpChat5, dumpChat6)
val dumpChat6 = Chat("https://open.rocket.chat/avatar/matheus.cardoso",
"androidnativeapp",
"c",
null,
"Yes @sttyru, but you'll need to implement from the ground up following the docs at docs.rocket.chat where you can see the REST (HTTP) and Real-Time (WebSockets) calls.",
LocalDateTime.of(2017, 11, 14,1, 3),
0)
// creates a list of chat sorted by lastMessageDateTime attribute.
return listOf(dumpChat1, dumpChat2, dumpChat3, dumpChat4, dumpChat5, dumpChat6).sortedByDescending { chat -> chat.lastMessageDateTime }
}
// REMARK: The presenter should call this method. The presenter also need to sort the chat list by latest message (compared by its date).
private fun showChatList(dataSet: MutableList<Chat>) {
private fun showChatList(dataSet: List<Chat>) {
val context = activity.applicationContext
recycler_view.adapter = ChatListAdapter(dataSet, context)
recycler_view.adapter = ChatListAdapter(dataSet.toMutableList(), context)
recycler_view.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
recycler_view.addItemDecoration(DividerItemDecoration(activity, DividerItemDecoration.VERTICAL))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment