Commit 94949958 authored by aniket's avatar aniket

supports infinite scrolling for search results

parent 89aad912
......@@ -22,13 +22,13 @@ class AddMembersPresenter @Inject constructor(
val serverUrl: String? = serverInteractor.get()
private val client = if (serverUrl != null) factory.create(serverUrl) else null
fun queryUsersFromRegex(queryParam: String) {
fun queryUsersFromRegex(queryParam: String, offset: Long = 0) {
if (client != null) {
view.showLoading()
launchUI(strategy) {
try {
val allMembers = retryIO("queryUsers($queryParam)") {
client.queryUsers(queryParam)
client.queryUsers(queryParam, 60, offset)
}
val memberViewModelMapper = mapper.mapToViewModelList(allMembers.result)
view.showMembers(memberViewModelMapper, allMembers.total)
......
......@@ -6,12 +6,14 @@ import android.os.Bundle
import android.support.design.chip.Chip
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.MenuItem
import android.widget.EditText
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.createChannel.addMembers.presentation.AddMembersPresenter
import chat.rocket.android.createChannel.addMembers.presentation.AddMembersView
import chat.rocket.android.helper.EndlessRecyclerViewScrollListener
import chat.rocket.android.members.adapter.MembersAdapter
import chat.rocket.android.members.viewmodel.MemberViewModel
import chat.rocket.android.util.extensions.setVisible
......@@ -31,6 +33,7 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
@Inject
lateinit var presenter: AddMembersPresenter
private lateinit var queryParam: String
private var membersToAdd: ArrayList<String> = ArrayList()
private val adapter: MembersAdapter = MembersAdapter { memberViewModel ->
if (!membersToAdd.contains(memberViewModel.username)) {
......@@ -54,9 +57,10 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
setInitialChips()
observableFromSearchView(search_view)
.debounce(300, TimeUnit.MILLISECONDS)
.filter { item -> item.length > 1 }
.filter { item -> item.isNotEmpty() }
.observeOn(AndroidSchedulers.mainThread())
.subscribe { query ->
queryParam = query
run {
adapter.reAllocateArrayList()
presenter.queryUsersFromRegex(query)
......@@ -78,19 +82,18 @@ class AddMembersActivity : AppCompatActivity(), AddMembersView {
override fun showMembers(dataSet: List<MemberViewModel>, total: Long) {
if (adapter.itemCount == 0) {
adapter.prependData(dataSet)
//TODO work on this part after adding support for count and offset in sdk
// if (dataSet.size >= 59) { // TODO Check why the API retorns the specified count -1
// search_results.addOnScrollListener(object :
// EndlessRecyclerViewScrollListener(linearLayoutManager) {
// override fun onLoadMore(
// page: Int,
// totalItemsCount: Int,
// recyclerView: RecyclerView?
// ) {
// presenter.loadChatRoomsMembers(chatRoomId, chatRoomType, page * 60L)
// }
// })
// }
if (dataSet.size >= 59) {
search_results.addOnScrollListener(object :
EndlessRecyclerViewScrollListener(linearLayoutManager) {
override fun onLoadMore(
page: Int,
totalItemsCount: Int,
recyclerView: RecyclerView?
) {
presenter.queryUsersFromRegex(queryParam, page * 60L)
}
})
}
} else {
adapter.appendData(dataSet)
}
......
......@@ -7,7 +7,6 @@ import android.os.Bundle
import android.support.design.chip.Chip
import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.createChannel.addMembers.ui.AddMembersActivity
import chat.rocket.android.createChannel.presentation.CreateNewChannelPresenter
......
......@@ -2,7 +2,6 @@ package chat.rocket.android.members.ui
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
......
......@@ -65,8 +65,10 @@
<android.support.v7.widget.RecyclerView
android:id="@+id/search_results"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_margin="8dp"
app:layout_constraintTop_toBottomOf="@id/separator_1" />
android:scrollbars="vertical"
app:layout_constraintTop_toBottomOf="@id/separator_1"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
\ 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