Commit d1b4d63b authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Adds the search view.

parent 0bb00cbc
......@@ -141,14 +141,10 @@ private const val BUNDLE_CHAT_ROOM_MESSAGE = "chat_room_message"
class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiReactionListener,
ChatRoomAdapter.OnActionSelected, Drawable.Callback {
@Inject
lateinit var presenter: ChatRoomPresenter
@Inject
lateinit var parser: MessageParser
@Inject
lateinit var analyticsManager: AnalyticsManager
@Inject
lateinit var navigator: ChatRoomNavigator
@Inject lateinit var presenter: ChatRoomPresenter
@Inject lateinit var parser: MessageParser
@Inject lateinit var analyticsManager: AnalyticsManager
@Inject lateinit var navigator: ChatRoomNavigator
private lateinit var adapter: ChatRoomAdapter
internal lateinit var chatRoomId: String
private lateinit var chatRoomName: String
......@@ -597,45 +593,31 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
}
override fun showMessage(message: String) {
ui {
showToast(message)
}
ui { showToast(message) }
}
override fun showMessage(resId: Int) {
ui {
showToast(resId)
}
ui { showToast(resId) }
}
override fun showGenericErrorMessage() {
ui {
showMessage(getString(R.string.msg_generic_error))
}
ui { showMessage(getString(R.string.msg_generic_error)) }
}
override fun populatePeopleSuggestions(members: List<PeopleSuggestionUiModel>) {
ui {
suggestions_view.addItems("@", members)
}
ui { suggestions_view.addItems("@", members) }
}
override fun populateRoomSuggestions(chatRooms: List<ChatRoomSuggestionUiModel>) {
ui {
suggestions_view.addItems("#", chatRooms)
}
ui { suggestions_view.addItems("#", chatRooms) }
}
override fun populateCommandSuggestions(commands: List<CommandSuggestionUiModel>) {
ui {
suggestions_view.addItems("/", commands)
}
ui { suggestions_view.addItems("/", commands) }
}
override fun populateEmojiSuggestions(emojis: List<EmojiSuggestionUiModel>) {
ui {
suggestions_view.addItems(":", emojis)
}
ui { suggestions_view.addItems(":", emojis) }
}
override fun copyToClipboard(message: String) {
......
......@@ -37,11 +37,12 @@ class DirectoryPresenter @Inject constructor(
private val client: RocketChatClient = factory.get(currentServer)
private var offset: Long = 0
fun loadAllDirectoryChannels() {
fun loadAllDirectoryChannels(query: String? = null) {
launchUI(strategy) {
try {
view.showLoading()
val directoryResult = client.directory(
text = query,
directoryRequestType = DirectoryRequestType.Channels(),
offset = offset,
count = 60
......@@ -61,13 +62,18 @@ class DirectoryPresenter @Inject constructor(
}
}
fun loadAllDirectoryUsers(isSearchForGlobalUsers: Boolean) {
fun loadAllDirectoryUsers(isSearchForGlobalUsers: Boolean, query: String? = null) {
launchUI(strategy) {
try {
view.showLoading()
val directoryResult = client.directory(
text = query,
directoryRequestType = DirectoryRequestType.Users(),
directoryWorkspaceType = if (isSearchForGlobalUsers) DirectoryWorkspaceType.All() else DirectoryWorkspaceType.Local(),
directoryWorkspaceType = if (isSearchForGlobalUsers) {
DirectoryWorkspaceType.All()
} else {
DirectoryWorkspaceType.Local()
},
offset = offset,
count = 60
)
......@@ -86,12 +92,16 @@ class DirectoryPresenter @Inject constructor(
}
}
fun updateSorting(isSortByChannels: Boolean, isSearchForGlobalUsers: Boolean) {
fun updateSorting(
isSortByChannels: Boolean,
isSearchForGlobalUsers: Boolean,
query: String? = null
) {
resetOffset()
if (isSortByChannels) {
loadAllDirectoryChannels()
loadAllDirectoryChannels(query)
} else {
loadAllDirectoryUsers(isSearchForGlobalUsers)
loadAllDirectoryUsers(isSearchForGlobalUsers, query)
}
}
......
......@@ -2,9 +2,13 @@ package chat.rocket.android.directory.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DividerItemDecoration
......@@ -19,7 +23,9 @@ import chat.rocket.android.directory.presentation.DirectoryPresenter
import chat.rocket.android.directory.presentation.DirectoryView
import chat.rocket.android.directory.uimodel.DirectoryUiModel
import chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import chat.rocket.android.util.extension.onQueryTextListener
import chat.rocket.android.util.extensions.inflate
import chat.rocket.android.util.extensions.isNotNullNorBlank
import chat.rocket.android.util.extensions.showToast
import chat.rocket.android.util.extensions.ui
import dagger.android.support.AndroidSupportInjection
......@@ -62,6 +68,7 @@ class DirectoryFragment : Fragment(), DirectoryView {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AndroidSupportInjection.inject(this)
setHasOptionsMenu(true)
}
override fun onCreateView(
......@@ -79,6 +86,33 @@ class DirectoryFragment : Fragment(), DirectoryView {
analyticsManager.logScreenView(ScreenViewEvent.Directory)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.directory, menu)
val searchMenuItem = menu.findItem(R.id.action_search)
val searchView = searchMenuItem?.actionView as SearchView
with(searchView) {
setIconifiedByDefault(false)
maxWidth = Integer.MAX_VALUE
onQueryTextListener { updateSorting(isSortByChannels, isSearchForGlobalUsers, it) }
}
searchMenuItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
updateSorting(isSortByChannels, isSearchForGlobalUsers, reload = true)
return true
}
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
return true
}
})
}
override fun showChannels(dataSet: List<DirectoryUiModel>) {
ui {
if (directoryAdapter.itemCount == 0) {
......@@ -141,7 +175,17 @@ class DirectoryFragment : Fragment(), DirectoryView {
view_loading.isVisible = false
}
fun updateSorting(isSortByChannels: Boolean, isSearchForGlobalUsers: Boolean) {
fun updateSorting(
isSortByChannels: Boolean,
isSearchForGlobalUsers: Boolean,
query: String? = null,
reload: Boolean = false
) {
if (query.isNotNullNorBlank() || reload) {
directoryAdapter.clearData()
presenter.updateSorting(isSortByChannels, isSearchForGlobalUsers, query)
}
if (this.isSortByChannels != isSortByChannels ||
this.isSearchForGlobalUsers != isSearchForGlobalUsers
) {
......@@ -152,7 +196,7 @@ class DirectoryFragment : Fragment(), DirectoryView {
clearData()
setSorting(isSortByChannels, isSearchForGlobalUsers)
}
presenter.updateSorting(isSortByChannels, isSearchForGlobalUsers)
presenter.updateSorting(isSortByChannels, isSearchForGlobalUsers, query)
}
}
......
......@@ -75,6 +75,8 @@ fun String.lowercaseUrl(): String? = HttpUrl.parse(this)?.run {
fun String?.isNotNullNorEmpty(): Boolean = this != null && this.isNotEmpty()
fun String?.isNotNullNorBlank(): Boolean = this != null && this.isNotBlank()
inline fun String?.ifNotNullNotEmpty(block: (String) -> Unit) {
if (this != null && this.isNotEmpty()) {
block(this)
......
<?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="@drawable/ic_search_white_24dp"
android:title="@string/action_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
</menu>
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