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

Commit 5bdfe7d8 authored by Hasib Prince's avatar Hasib Prince
Browse files

fixed: showing status in Install button

fixed: Category page and search page had issues to showing correct status in install button.That's fixed
parent 052cb9cd
Loading
Loading
Loading
Loading
Loading
+24 −20
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ class DownloadManager @Inject constructor(
        filePath: String = "",
        downloadCompleted: ((Boolean, String) -> Unit)?
    ) {
        try {
            downloadManager.query(downloadManagerQuery.setFilterById(downloadId))
                .use { cursor ->
                    if (cursor.moveToFirst()) {
@@ -90,6 +91,9 @@ class DownloadManager @Inject constructor(
                        }
                    }
                }
        } catch (e: Exception) {
            Timber.e(e)
        }
    }

    private fun tickerFlow(period: Duration, initialDelay: Duration = Duration.ZERO) = flow {
+4 −4
Original line number Diff line number Diff line
@@ -160,10 +160,6 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {

        binding.applicationLayout.visibility = View.INVISIBLE

        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            applicationViewModel.updateApplicationStatus(list)
        }

        applicationViewModel.fusedApp.observe(viewLifecycleOwner) { resultPair ->
            if (resultPair.second != ResultStatus.OK) {
                onTimeout()
@@ -306,6 +302,10 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
                binding.snackbarLayout.visibility = View.VISIBLE
            }
            fetchAppTracker(it)

            mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
                applicationViewModel.updateApplicationStatus(list)
            }
        }

        applicationViewModel.errorMessageLiveData.observe(viewLifecycleOwner) {
+8 −11
Original line number Diff line number Diff line
@@ -69,7 +69,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li

    private var _binding: FragmentApplicationListBinding? = null
    private val binding get() = _binding!!
    private var isDownloadObserverAdded = false

    /*
     * Prevent reloading apps.
@@ -93,18 +92,18 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
        }
    }

    private fun observeDownloadList() {
    private fun observeDownloadList(adapter: ApplicationListRVAdapter) {
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val appList = viewModel.appListLiveData.value?.data?.toMutableList() ?: emptyList()
            appList.let {
                mainActivityViewModel.updateStatusOfFusedApps(it, list)
                adapter.setData(it)
            }

            /*
             * Done in one line, so that on Ctrl+click on appListLiveData,
             * we can see that it is being updated here.
             */
            viewModel.appListLiveData.apply { value?.setData(appList) }
        }
    }

@@ -161,9 +160,12 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
            } else {
                isDetailsLoaded = true
                listAdapter?.setData(it.data!!)
                if (!isDownloadObserverAdded) {
                    observeDownloadList()
                    isDownloadObserverAdded = true
                listAdapter?.let { adapter ->
                    observeDownloadList(adapter)
                }

                appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
                    updateProgressOfDownloadingItems(binding.recyclerView, it)
                }
            }
            stopLoadingUI()
@@ -255,10 +257,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
                }
            }
        }

        appProgressViewModel.downloadProgress.observe(viewLifecycleOwner) {
            updateProgressOfDownloadingItems(binding.recyclerView, it)
        }
    }

    private fun showLoadingUI() {
@@ -298,7 +296,6 @@ class ApplicationListFragment : TimeoutFragment(R.layout.fragment_application_li
    }

    override fun onPause() {
        isDownloadObserverAdded = false
        binding.shimmerLayout.stopShimmer()
        super.onPause()
    }
+13 −9
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ class InstallAppWorker @AssistedInject constructor(
    }

    private suspend fun checkDownloadProcess(fusedDownload: FusedDownload) {
        try {
            downloadManager.query(downloadManagerQuery.setFilterById(*fusedDownload.downloadIdMap.keys.toLongArray()))
                .use { cursor ->
                    if (cursor.moveToFirst()) {
@@ -169,6 +170,9 @@ class InstallAppWorker @AssistedInject constructor(
                        }
                    }
                }
        } catch (e: Exception) {
            Timber.e(e)
        }
    }

    private suspend fun handleFusedDownloadStatus(fusedDownload: FusedDownload) {
+17 −30
Original line number Diff line number Diff line
@@ -161,36 +161,6 @@ class SearchFragment :
            layoutManager = LinearLayoutManager(view.context)
        }

        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val searchList =
                searchViewModel.searchResult.value?.data?.first?.toMutableList() ?: emptyList()
            searchList.let {
                mainActivityViewModel.updateStatusOfFusedApps(searchList, list)
            }

            /*
             * Done in one line, so that on Ctrl+click on searchResult,
             * we can see that it is being updated here.
             */
            searchViewModel.searchResult.apply { value?.setData(Pair(searchList, value?.data?.second ?: false)) }
        }

        /*
         * Explanation of double observers in HomeFragment.kt
         * Modified to check and search only if searchText in not blank, to prevent blank search.
         */

        mainActivityViewModel.internetConnection.observe(viewLifecycleOwner) {
            if (searchText.isNotBlank()) {
                refreshDataOrRefreshToken(mainActivityViewModel)
            }
        }
        mainActivityViewModel.authData.observe(viewLifecycleOwner) {
            if (searchText.isNotBlank()) {
                refreshDataOrRefreshToken(mainActivityViewModel)
            }
        }

        searchViewModel.searchResult.observe(viewLifecycleOwner) {
            if (it.data?.first.isNullOrEmpty()) {
                noAppsFoundLayout?.visibility = View.VISIBLE
@@ -199,7 +169,13 @@ class SearchFragment :
                binding.loadingProgressBar.isVisible = it.data!!.second
                stopLoadingUI()
                noAppsFoundLayout?.visibility = View.GONE
                searchHintLayout?.visibility = View.GONE
            }

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

            listAdapter?.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
                override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
                    searchView?.run {
@@ -227,6 +203,17 @@ 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)
            }
        }
    }

    override fun onTimeout() {
        if (!isTimeoutDialogDisplayed()) {
            binding.loadingProgressBar.isVisible = false
Loading