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

Verified Commit 140028c8 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

fix: show progress percent on search results

parent 20b30d80
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package foundation.e.apps.data.install

import android.content.Context
import androidx.lifecycle.LiveData
import foundation.e.apps.BuildConfig
import foundation.e.apps.OpenForTesting
import foundation.e.apps.data.Constants.MIN_VALID_RATING
import foundation.e.apps.data.application.data.Application
@@ -141,9 +142,10 @@ class AppManagerWrapper @Inject constructor(
            .values
            .sum()

        return ((downloadedSoFar / totalSizeBytes.toDouble()) * 100)
        val percent = ((downloadedSoFar / totalSizeBytes.toDouble()) * 100)
            .toInt()
            .coerceIn(0, 100)
        return percent
    }

    private suspend fun isProgressValidForApp(
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ import foundation.e.apps.ui.compose.state.mapAppToInstallState
import foundation.e.apps.ui.compose.theme.AppTheme
import foundation.e.apps.ui.AppProgressViewModel
import foundation.e.apps.ui.AppInfoFetchViewModel
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.asFlow
import kotlinx.coroutines.launch

@AndroidEntryPoint
class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
@@ -44,6 +47,14 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val composeView = view.findViewById<ComposeView>(R.id.composeView)
        composeView.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)

        // Ensure DownloadProgress emissions reach the ViewModel even if Compose does not recompose.
        viewLifecycleOwner.lifecycleScope.launch {
            appProgressViewModel.downloadProgress.asFlow().collect { progress ->
                searchViewModelV2.updateDownloadProgress(copyProgress(progress))
            }
        }

        composeView.setContent {
            AppTheme {
                val uiState by searchViewModelV2.uiState.collectAsState()
@@ -54,6 +65,7 @@ class SearchFragmentV2 : Fragment(R.layout.fragment_search_v2) {
                val statusByKey by searchViewModelV2.statusByKey.collectAsState()

                LaunchedEffect(downloadProgress) {
                    // Retain Compose-based updates as a secondary path for safety.
                    downloadProgress?.let {
                        searchViewModelV2.updateDownloadProgress(copyProgress(it))
                    }