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

Commit f29de8f0 authored by Hasib Prince's avatar Hasib Prince
Browse files

validation added for already running install process

parent 5dd075c5
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -478,6 +478,7 @@ class MainActivityViewModel @Inject constructor(
        if (shouldShowPaidAppsSnackBar(app)) {
            return
        }

        viewModelScope.launch {
            val fusedDownload: FusedDownload
            try {
+4 −0
Original line number Diff line number Diff line
@@ -74,6 +74,10 @@ class FusedManagerImpl @Inject constructor(
        databaseRepository.addDownload(fusedDownload)
    }

    suspend fun getDownloadById(fusedDownload: FusedDownload): FusedDownload? {
        return databaseRepository.getDownloadById(fusedDownload.id)
    }

    suspend fun getDownloadList(): List<FusedDownload> {
        return databaseRepository.getDownloadList()
    }
+12 −0
Original line number Diff line number Diff line
@@ -9,7 +9,9 @@ import foundation.e.apps.api.fdroid.FdroidRepository
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.download.data.DownloadProgress
import foundation.e.apps.manager.workmanager.InstallWorkManager
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.modules.CommonUtilsFunctions
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
import javax.inject.Singleton
@@ -34,6 +36,16 @@ class FusedManagerRepository @Inject constructor(
    }

    suspend fun addDownload(fusedDownload: FusedDownload) {
        if (CommonUtilsFunctions.checkWorkIsAlreadyAvailable(InstallWorkManager.context, fusedDownload.id)) {
            return
        }

        val existingFusedDownload = fusedManagerImpl.getDownloadById(fusedDownload)
        // We don't want to add any thing, if it already exists without INSTALLATION_ISSUE
        if (existingFusedDownload != null && existingFusedDownload.status != Status.INSTALLATION_ISSUE) {
            return
        }

        return fusedManagerImpl.addDownload(fusedDownload)
    }

+18 −14
Original line number Diff line number Diff line
@@ -200,7 +200,13 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), FusedAPIInte
        showLoadingUI()
        updatesViewModel.getUpdates(authData)
        binding.button.setOnClickListener {
            val id = UpdatesWorkManager.startUpdateAllWork(requireContext().applicationContext)
            UpdatesWorkManager.startUpdateAllWork(requireContext().applicationContext)
            observeUpdateWork()
            binding.button.isEnabled = false
        }
    }

    private fun observeUpdateWork() {
        WorkManager.getInstance(requireContext())
            .getWorkInfosByTagLiveData(UpdatesWorkManager.UPDATES_WORK_NAME)
            .observe(viewLifecycleOwner) {
@@ -214,8 +220,6 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), FusedAPIInte
                    binding.button.isEnabled = true
                }
            }
            binding.button.isEnabled = false
        }
    }

    private fun showLoadingUI() {
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ object UpdatesWorkManager {
        return PeriodicWorkRequest.Builder(
            UpdatesWorker::class.java,
            interval,
            TimeUnit.MINUTES
            TimeUnit.HOURS
        ).apply {
            setConstraints(buildWorkerConstraints())
            addTag(TAG)
Loading