Commit b9326410 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add implementation for room search

parent 226e069b
package chat.rocket.android.chatrooms.search
import android.os.Parcel
import android.os.Parcelable
import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion
class ChatRoomSuggestion(val chatRoomName: String) : SearchSuggestion {
override fun getBody(): String = chatRoomName
constructor(parcel: Parcel) : this(parcel.readString())
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(chatRoomName)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<ChatRoomSuggestion> {
override fun createFromParcel(parcel: Parcel): ChatRoomSuggestion {
return ChatRoomSuggestion(parcel)
}
override fun newArray(size: Int): Array<ChatRoomSuggestion?> {
return arrayOfNulls(size)
}
}
}
\ No newline at end of file
package chat.rocket.android.chatrooms.search
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import chat.rocket.android.R
class SearchResultsListAdapter(private var data: List<ChatRoomSuggestion>) : RecyclerView.Adapter<SearchResultsListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent?.getContext())
.inflate(R.layout.search_results_list_item, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
val chatRoomSuggestion = data[position]
holder?.chatRoomName?.text = chatRoomSuggestion.body
}
override fun getItemCount(): Int = data.size
fun swapData(newData: List<ChatRoomSuggestion>) {
data = newData
notifyDataSetChanged()
}
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val chatRoomName: TextView = view.findViewById(R.id.text_chat_suggestion_name)
}
}
\ No newline at end of file
......@@ -33,6 +33,13 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
presenter.chatRooms()
floating_search_view.setOnQueryChangeListener { oldQuery, newQuery ->
if (oldQuery.isNotEmpty() && newQuery.isEmpty()) {
floating_search_view.clearSuggestions()
} else {
floating_search_view.showProgress()
}
}
}
override fun showChatRooms(dataSet: MutableList<ChatRoom>) {
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="175dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="@+id/text_chat_suggestion_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
tools:text="androidnativeapp" />
</LinearLayout>
</android.support.v7.widget.CardView>
\ No newline at end of file
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