Commit 777c9bb4 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Implement "load more" feature

parent f50c6d46
......@@ -83,6 +83,13 @@ class SearchFragment : Fragment(), SearchView.OnQueryTextListener, SearchView.On
recyclerView.setHasFixedSize(true)
recyclerView.layoutManager = LinearLayoutManager(context)
recyclerView.adapter = ApplicationListAdapter(activity!!, applicationList)
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (!recyclerView.canScrollVertically(1)) {
searchViewModel.loadMore(context!!)
}
}
})
// Bind search view suggestions adapter to search suggestions list in view model
searchViewModel.getSuggestions().observe(this, Observer {
......@@ -98,7 +105,6 @@ class SearchFragment : Fragment(), SearchView.OnQueryTextListener, SearchView.On
applicationList.addAll(it)
progressBar.visibility = View.GONE
recyclerView.adapter.notifyDataSetChanged()
recyclerView.scrollToPosition(0)
if (applicationList.isEmpty()) {
recyclerView.visibility = View.GONE
} else {
......
......@@ -53,7 +53,13 @@ class SearchModel : SearchModelInterface {
override fun onSearchComplete(error: Error?, applicationList: ArrayList<Application>) {
if (error == null) {
this.applicationList.value = applicationList
if (pageNumber > 1 && this.applicationList.value != null) {
val combinedAppList = this.applicationList.value!!
combinedAppList.addAll(applicationList)
this.applicationList.value = combinedAppList
} else {
this.applicationList.value = applicationList
}
if (applicationList.isEmpty()) {
screenError.value = Error.NO_RESULTS
}
......
Supports Markdown
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