I have following api call function and I'd like to know how can I make pagination for my data?
Logic
- Receiving data from API (done)
- Printing data into recyclerview (done)
- Making data paginate (either by scroll or by page numbers doesn't make any difference for me)
Questions
- How to make my data paginate?
- Is it best if I return data paginated by back-end or make them paginate in my app?
Current behavior
Currently my data are fully returned by data (without pagination) so if I have 1 item or 1000 items they all will be available at the same time (code below)
Code
private fun getProjects() {
    val queue = Volley.newRequestQueue(context)
    val url = "https://example.com/api/projects"
    val stringReq : StringRequest =
        object : StringRequest(
            Method.GET, url,
            Response.Listener { response ->
                val projects = Gson().fromJson(response, Projects::class.java)
                defText.isVisible = false
                total_projects_text = projects.total
                (activity as MainActivity?)?.setActionBarTitle("Projects ($total_projects_text)")
                // showing recyclerview data
                projectsRecycler.isVisible = true
                projectsRecycler.layoutManager = LinearLayoutManager(
                    context,
                    LinearLayoutManager.VERTICAL,
                    false
                )
                projectsRecycler.adapter = ProjectAdapter(context, projects)
            },
            Response.ErrorListener { error ->
                Toast.makeText(context, error.toString(), Toast.LENGTH_LONG).show()
                defText.isVisible = true
            }
        ){
            override fun getHeaders(): Map<String, String> {
                val headers = HashMap<String, String>()
                headers["Content-Type"] = "application/json"
                return headers
            }
        }
    queue.add(stringReq)
}
