Commit f495ce5f authored by Leonardo Aramaki's avatar Leonardo Aramaki

Add spotlight functionality inside de Toolbar

parent 4aa50996
......@@ -2,12 +2,12 @@ package chat.rocket.android.chatrooms.ui
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.support.v7.util.DiffUtil
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.support.v7.widget.SearchView
import android.view.*
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter
......@@ -15,6 +15,7 @@ import chat.rocket.android.chatrooms.presentation.ChatRoomsView
import chat.rocket.android.widget.DividerItemDecoration
import chat.rocket.core.model.ChatRoom
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.app_bar.*
import kotlinx.android.synthetic.main.fragment_chat_rooms.*
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.android.UI
......@@ -23,7 +24,9 @@ import kotlinx.coroutines.experimental.launch
import javax.inject.Inject
class ChatRoomsFragment : Fragment(), ChatRoomsView {
@Inject lateinit var presenter: ChatRoomsPresenter
private var searchView: SearchView? = null
companion object {
fun newInstance() = ChatRoomsFragment()
......@@ -32,6 +35,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
setHasOptionsMenu(true)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_chat_rooms, container, false)
......@@ -39,24 +43,40 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
floating_search_view.setOnQueryChangeListener { oldQuery, newQuery ->
floating_search_view.showProgress()
presenter.chatRoomsByName(newQuery)
if (oldQuery.isNotEmpty() && newQuery.isEmpty()) {
floating_search_view.clearSuggestions()
floating_search_view.hideProgress()
}
}
activity?.apply {
(activity as AppCompatActivity).apply {
recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recycler_view.addItemDecoration(DividerItemDecoration(this, 144, 32))
recycler_view.adapter = ChatRoomsAdapter(this)
recycler_view.itemAnimator = DefaultItemAnimator()
if (supportActionBar == null) {
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(false)
supportActionBar?.setDisplayShowHomeEnabled(false)
supportActionBar?.setDisplayShowTitleEnabled(false)
}
}
presenter.loadChatRooms()
}
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
inflater?.inflate(R.menu.chatrooms_menu, menu)
val searchItem = menu?.findItem(R.id.action_search)
searchView = searchItem?.actionView as SearchView
val sv = searchView
sv?.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return queryChatRoomsByName(query)
}
override fun onQueryTextChange(newText: String?): Boolean {
return queryChatRoomsByName(newText)
}
})
}
/*override fun showChatRooms(dataSet: MutableList<ChatRoom>) {
floating_search_view.hideProgress()
}*/
......@@ -69,7 +89,6 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
DiffUtil.calculateDiff(RoomsDiffCallback(adapter.dataSet, newDataSet))
}.await()
floating_search_view.hideProgress()
adapter.updateRooms(newDataSet)
diff.dispatchUpdatesTo(adapter)
}
......@@ -84,6 +103,11 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun showGenericErrorMessage() = showMessage(getString(R.string.msg_generic_error))
private fun queryChatRoomsByName(name: String?): Boolean {
presenter.chatRoomsByName(name ?: "")
return true
}
class RoomsDiffCallback(private val oldRooms: List<ChatRoom>,
private val newRooms: List<ChatRoom>) : DiffUtil.Callback() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout 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="match_parent"
android:fitsSystemWindows="true"
tools:context=".chatrooms.ui.ChatRoomsFragment">
<include
android:id="@+id/layout_app_bar"
layout="@layout/app_bar"
android:background="@color/black" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:gravity="center_horizontal"
android:paddingTop="84dp" />
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<!--<com.arlib.floatingsearchview.FloatingSearchView-->
<!--android:id="@+id/floating_search_view"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--app:floatingSearch_close_search_on_keyboard_dismiss="true"-->
<!--app:floatingSearch_dimBackground="false"-->
<!--app:floatingSearch_dismissOnOutsideTouch="true"-->
<!--app:floatingSearch_leftActionMode="showSearch"-->
<!--app:floatingSearch_searchBarMarginLeft="4dp"-->
<!--app:floatingSearch_searchBarMarginRight="4dp"-->
<!--app:floatingSearch_searchBarMarginTop="28dp" />-->
<com.arlib.floatingsearchview.FloatingSearchView
android:id="@+id/floating_search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:floatingSearch_close_search_on_keyboard_dismiss="true"
app:floatingSearch_dimBackground="false"
app:floatingSearch_dismissOnOutsideTouch="true"
app:floatingSearch_leftActionMode="showSearch"
app:floatingSearch_searchBarMarginLeft="4dp"
app:floatingSearch_searchBarMarginRight="4dp"
app:floatingSearch_searchBarMarginTop="28dp" />
<com.wang.avi.AVLoadingIndicatorView
android:id="@+id/view_loading"
......@@ -36,4 +43,4 @@
app:indicatorName="BallPulseIndicator"
tools:visibility="visible" />
</RelativeLayout>
\ No newline at end of file
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always|collapseActionView" />
</menu>
\ No newline at end of file
......@@ -35,5 +35,6 @@
<string name="msg_content_description_log_in_using_twitter">Fazer login através do Twitter</string>
<string name="msg_content_description_log_in_using_gitlab">Fazer login através do Gitlab</string>
<string name="msg_you">Você</string>
<string name="search">Pesquisar</string>
</resources>
......@@ -37,5 +37,6 @@
<string name="msg_content_description_log_in_using_twitter">Login using Twitter</string>
<string name="msg_content_description_log_in_using_gitlab">Login using Gitlab</string>
<string name="msg_you">You</string>
<string name="search">Search</string>
</resources>
\ 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