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

Commit 5968d4b6 authored by Hasib Prince's avatar Hasib Prince
Browse files

enabled search page pagination

parent c4302d7b
Loading
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import foundation.e.apps.ui.MainActivityViewModel
import foundation.e.apps.ui.PrivacyInfoViewModel
import foundation.e.apps.ui.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.ui.applicationlist.ApplicationListRVAdapter
import foundation.e.apps.utils.isNetworkAvailable
import kotlinx.coroutines.launch
import javax.inject.Inject

@@ -74,7 +75,8 @@ class SearchFragment :
    private var _binding: FragmentSearchBinding? = null
    private val binding get() = _binding!!

    private val searchViewModel: SearchViewModel by viewModels()
    //To avoid SyntheticAccessor, declared as protected
    protected val searchViewModel: SearchViewModel by viewModels()
    private val privacyInfoViewModel: PrivacyInfoViewModel by viewModels()
    private val appInfoFetchViewModel: AppInfoFetchViewModel by viewModels()
    private val mainActivityViewModel: MainActivityViewModel by activityViewModels()
@@ -126,6 +128,18 @@ class SearchFragment :
            this.authData = it.authData
            loadData()
        }

        binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)
                if (!recyclerView.canScrollVertically(1)) {
                    if (!requireContext().isNetworkAvailable()) {
                        return
                    }
                    searchViewModel.loadMore(searchText)
                }
            }
        })
    }

    private fun observeSearchResult(listAdapter: ApplicationListRVAdapter?) {
+4 −0
Original line number Diff line number Diff line
@@ -121,6 +121,10 @@ class SearchViewModel @Inject constructor(
        isLoading = true
        val gplaySearchResult = fusedAPIRepository.getGplaySearchResults(query, nextSubBundle)

        if (!gplaySearchResult.isSuccess()) {
            EventBus.invokeEvent(AppEvent.DataLoadError(gplaySearchResult))
        }

        val isFirstFetch = nextSubBundle == null
        nextSubBundle = gplaySearchResult.data?.second