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

Commit 4b9cb5f3 authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '5833-install_status_chopped' into 'main'

5833 install status chopped

See merge request !239
parents e7efe25a 6826e7b1
Loading
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -208,12 +208,18 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        if (appInfoFetchViewModel.isAppInBlockedList(it)) {
            binding.snackbarLayout.visibility = View.VISIBLE
        }

        fetchAppTracker(it)
        observeDownloadList()
        observeDownloadStatus(binding.root)
        stopLoadingUI()
    }

    private fun observeDownloadList() {
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            applicationViewModel.updateApplicationStatus(list)
        }
        stopLoadingUI()
    }

    private fun updateAppDescriptionText(it: FusedApp) {
@@ -483,11 +489,6 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        }
    }

    override fun onResume() {
        super.onResume()
        observeDownloadStatus(binding.root)
    }

    private fun handleInstallingIssue(
        installButton: MaterialButton,
        fusedApp: FusedApp,
@@ -709,7 +710,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        downloadProgress: DownloadProgress,
    ) {
        val progressResult = applicationViewModel.calculateProgress(downloadProgress)
        if (progressResult.first < 1) {
        if (view == null || progressResult.first < 1) {
            return
        }
        val downloadedSize = "${
@@ -783,6 +784,11 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        binding.ratingsInclude.appPrivacyScore.visibility = visibility
    }

    override fun onResume() {
        super.onResume()
        observeDownloadList()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding?.recyclerView?.adapter = null
@@ -790,11 +796,6 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
        applicationIcon = null
    }

    override fun onPause() {
        super.onPause()
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
    }

    private fun shareApp(name: String, shareUrl: String): Intent {
        val shareIntent = Intent().apply {
            action = Intent.ACTION_SEND
+22 −29
Original line number Diff line number Diff line
@@ -116,12 +116,19 @@ class ApplicationListFragment :
        }
    }

    private fun observeDownloadList(adapter: ApplicationListRVAdapter) {
    private fun observeDownloadList(
        adapter: ApplicationListRVAdapter,
        fusedAppResult: ResultSupreme<List<FusedApp>>
    ) {
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val appList = viewModel.appListLiveData.value?.data?.toMutableList() ?: emptyList()

            appList.let {
                mainActivityViewModel.updateStatusOfFusedApps(it, list)
                adapter.setData(it)
                if (isFusedAppsUpdated(fusedAppResult, listAdapter.currentList)) {
                    adapter.setData(it, args.translation)
                }
            }
        }
    }
@@ -134,26 +141,28 @@ class ApplicationListFragment :

    override fun onResume() {
        super.onResume()
        addDownloadProgressObserver()

        if (listAdapter.currentList.isNotEmpty() && viewModel.hasAnyAppInstallStatusChanged(listAdapter.currentList)) {
            /*mainActivityViewModel.authData.value?.let {
                refreshData(it)
            }*/
        if (listAdapter.currentList.isNotEmpty() && viewModel.hasAnyAppInstallStatusChanged(
                listAdapter.currentList
            )
        ) {
            repostAuthObjects()
        }
    }

    private fun addDownloadProgressObserver() {
        appProgressViewModel.downloadProgress.removeObservers(viewLifecycleOwner)
        appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
            updateProgressOfDownloadingItems(binding.recyclerView, it)
        }
    }

    private fun observeAppListLiveData() {
        viewModel.appListLiveData.observe(viewLifecycleOwner) {
            stopLoadingUI()
            if (it.isSuccess()) {
                if (!isFusedAppsUpdated(it)) {
                    return@observe
                }
                updateAppListRecyclerView(listAdapter, it)
                appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
                    updateProgressOfDownloadingItems(binding.recyclerView, it)
                }
                observeDownloadList(listAdapter, it)
            }
        }
    }
@@ -203,21 +212,6 @@ class ApplicationListFragment :
        return recyclerView
    }

    private fun updateAppListRecyclerView(
        listAdapter: ApplicationListRVAdapter?,
        fusedAppResult: ResultSupreme<List<FusedApp>>
    ) {
        val currentList = listAdapter?.currentList
        if (!isFusedAppsUpdated(fusedAppResult, currentList)
        ) {
            return
        }
        listAdapter?.setData(fusedAppResult.data!!, args.translation)
        listAdapter?.let { adapter ->
            observeDownloadList(adapter)
        }
    }

    private fun isFusedAppsUpdated(
        fusedAppResult: ResultSupreme<List<FusedApp>>,
        currentList: MutableList<FusedApp>?
@@ -340,7 +334,6 @@ class ApplicationListFragment :

    override fun onPause() {
        binding.shimmerLayout.stopShimmer()
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        super.onPause()
    }

+38 −24
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import foundation.e.apps.application.subFrags.ApplicationDialogFragment
import foundation.e.apps.applicationlist.ApplicationListRVAdapter
import foundation.e.apps.databinding.FragmentSearchBinding
import foundation.e.apps.login.AuthObject
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Status
@@ -120,7 +121,8 @@ class SearchFragment :
        setupListening()

        authObjects.observe(viewLifecycleOwner) {
            if (it == null) return@observe
            val currentQuery = searchView?.query?.toString() ?: ""
            if (it == null || (currentQuery.isNotEmpty() && lastSearch == currentQuery)) return@observe
            loadData(it)
        }

@@ -134,13 +136,10 @@ class SearchFragment :
            if (it.data?.first.isNullOrEmpty() && it.data?.second == false) {
                noAppsFoundLayout?.visibility = View.VISIBLE
            } else {
                if (!updateSearchResult(listAdapter, it)) return@observe
            }

                listAdapter?.let { adapter ->
                    observeDownloadList(adapter)
                }

            }
            observeScrollOfSearchResult(listAdapter)
        }
    }
@@ -172,19 +171,20 @@ class SearchFragment :
        listAdapter: ApplicationListRVAdapter?,
        it: ResultSupreme<Pair<List<FusedApp>, Boolean>>
    ): Boolean {
        val currentList = listAdapter?.currentList
        if (it.data?.first != null && !currentList.isNullOrEmpty() && !searchViewModel.isAnyAppUpdated(
        val currentList = listAdapter?.currentList ?: listOf()
        if (it.data?.first != null && !searchViewModel.isAnyAppUpdated(
                it.data?.first!!,
                currentList
            )
        ) {
            return false
        }
        listAdapter?.setData(it.data!!.first)

        binding.loadingProgressBar.isVisible = it.data!!.second
        stopLoadingUI()
        noAppsFoundLayout?.visibility = View.GONE
        searchHintLayout?.visibility = View.GONE
        listAdapter?.setData(it.data?.first!!)
        return true
    }

@@ -249,14 +249,22 @@ class SearchFragment :
    }

    private fun observeDownloadList(applicationListRVAdapter: ApplicationListRVAdapter) {
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val searchList =
                searchViewModel.searchResult.value?.data?.first?.toMutableList() ?: emptyList()
            searchList.let {
                mainActivityViewModel.updateStatusOfFusedApps(searchList, list)
                applicationListRVAdapter.setData(it)
        mainActivityViewModel.downloadList.removeObservers(viewLifecycleOwner)
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { fusedDownloadList ->
            refreshUI(fusedDownloadList, applicationListRVAdapter)
        }
    }

    private fun refreshUI(
        fusedDownloadList: List<FusedDownload>,
        applicationListRVAdapter: ApplicationListRVAdapter
    ) {
        val searchList =
            searchViewModel.searchResult.value?.data?.first?.toMutableList() ?: emptyList()

        val hasMoreDataToLoad = searchViewModel.searchResult.value?.data?.second == true
        mainActivityViewModel.updateStatusOfFusedApps(searchList, fusedDownloadList)
        updateSearchResult(applicationListRVAdapter, ResultSupreme.Success(Pair(searchList, hasMoreDataToLoad)))
    }

    override fun onTimeout(
@@ -325,12 +333,13 @@ class SearchFragment :
    override fun onResume() {
        super.onResume()
        binding.shimmerLayout.startShimmer()
        appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
            updateProgressOfInstallingApps(it)
        }
        addDownloadProgressObservers()

        if (shouldRefreshData()) {
            repostAuthObjects()
            if (binding.recyclerView.adapter is ApplicationListRVAdapter) {
                val searchAdapter = binding.recyclerView.adapter as ApplicationListRVAdapter
                observeDownloadList(searchAdapter)
            }
        }

        if (searchText.isEmpty() && (recyclerView?.adapter as ApplicationListRVAdapter).currentList.isEmpty()) {
@@ -339,10 +348,15 @@ class SearchFragment :
        }
    }

    private fun addDownloadProgressObservers() {
        appProgressViewModel.downloadProgress.removeObservers(viewLifecycleOwner)
        appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
            updateProgressOfInstallingApps(it)
        }
    }

    private fun shouldRefreshData() =
        searchText.isNotEmpty() && recyclerView?.adapter != null && searchViewModel.hasAnyAppInstallStatusChanged(
            (recyclerView?.adapter as ApplicationListRVAdapter).currentList
        )
        searchText.isNotEmpty() && recyclerView?.adapter != null

    override fun onPause() {
        binding.shimmerLayout.stopShimmer()