Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1c7b5dd authored by jo's avatar jo
Browse files

implement and add loadMore function in ApplicationCategory

parent 0ffeeb29
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -5,10 +5,36 @@ import android.content.Context
import io.eelo.appinstaller.api.ListApplicationsRequest
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.utils.*
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Constants
import io.eelo.appinstaller.utils.Error
import io.eelo.appinstaller.utils.Execute

class CategoryModel : CategoryModelInterface {

    override fun loadMore(context: Context) {
        var apps: ArrayList<Application>? = null
        if (Common.isNetworkAvailable(context)) {
            Execute({
                apps = loadApplicationsSynced(context)
            }, {
                if (error == null && apps != null) {
                    val result = ArrayList<Application>()
                    result.addAll(categoryApplicationsList.value!!)
                    result.addAll(apps!!)
                    if (apps!!.size != 0) {
                        categoryApplicationsList.value = result
                    }
                } else {
                    screenError.value = error
                }
            })
            page++
        } else {
            screenError.value = Error.NO_INTERNET
        }
    }

    lateinit var applicationManager: ApplicationManager
    lateinit var category: String
    private var page = 1
+2 −0
Original line number Diff line number Diff line
@@ -8,4 +8,6 @@ interface CategoryModelInterface {
    fun initialise(applicationManager: ApplicationManager, category: String)

    fun loadApplications(context: Context)

    fun loadMore(context: Context)
}
 No newline at end of file