Commit 94949958 authored by aniket's avatar aniket

supports infinite scrolling for search results

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