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

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

App Lounge: fixed app cancellation issue

parent 4c6fa275
Loading
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import foundation.e.apps.api.fused.FusedAPIRepository
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.fused.FusedManagerRepository
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
@@ -55,6 +56,7 @@ class MainActivityViewModel @Inject constructor(
    private val dataStoreModule: DataStoreModule,
    private val fusedAPIRepository: FusedAPIRepository,
    private val fusedManagerRepository: FusedManagerRepository,
    private val pkgManagerModule: PkgManagerModule
) : ViewModel() {

    val authDataJson: LiveData<String> = dataStoreModule.authData.asLiveData()
@@ -278,4 +280,13 @@ class MainActivityViewModel @Inject constructor(
    val internetConnection = liveData {
        emitSource(ReactiveNetwork().observeInternetConnectivity().asLiveData(Dispatchers.Default))
    }

    fun updateStatusOfFusedApps(fusedAppList: List<FusedApp>, fusedDownloadList: List<FusedDownload>) {
        fusedAppList.forEach {
            val downloadingItem = fusedDownloadList.find { fusedDownload ->
                fusedDownload.origin == it.origin && (fusedDownload.packageName == it.package_name || fusedDownload.id == it._id)
            }
            it.status = downloadingItem?.status ?: pkgManagerModule.getPackageStatus(it.package_name, it.latest_version_code)
        }
    }
}
+9 −9
Original line number Diff line number Diff line
@@ -84,15 +84,11 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu

    private fun observeDownloadList() {
        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val categoryList = viewModel.appListLiveData.value?.toMutableList()
            if (!categoryList.isNullOrEmpty()) {
                list.forEach {
                    categoryList.find { app ->
                        app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id)
                    }?.status = it.status
                }
                viewModel.appListLiveData.value = categoryList
            val appList = viewModel.appListLiveData.value?.toMutableList()
            appList?.let {
                mainActivityViewModel.updateStatusOfFusedApps(it, list)
            }
            viewModel.appListLiveData.value = appList
        }
    }

@@ -120,7 +116,11 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu
                ) { fusedApp ->
                    ApplicationDialogFragment(
                        title = getString(R.string.dialog_title_paid_app, fusedApp.name),
                        message = getString(R.string.dialog_paidapp_message, fusedApp.name, fusedApp.price),
                        message = getString(
                            R.string.dialog_paidapp_message,
                            fusedApp.name,
                            fusedApp.price
                        ),
                        positiveButtonText = getString(R.string.dialog_confirm),
                        positiveButtonAction = {
                            getApplication(fusedApp)
+2 −17
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import foundation.e.apps.api.fused.FusedAPIInterface
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.api.fused.data.FusedHome
import foundation.e.apps.databinding.HomeParentListItemBinding
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.User

@@ -43,6 +42,7 @@ class HomeParentRVAdapter(
) : ListAdapter<FusedHome, HomeParentRVAdapter.ViewHolder>(FusedHomeDiffUtil()) {

    private val viewPool = RecyclerView.RecycledViewPool()
    private var isDownloadObserverAdded = false

    inner class ViewHolder(val binding: HomeParentListItemBinding) :
        RecyclerView.ViewHolder(binding.root)
@@ -79,26 +79,11 @@ class HomeParentRVAdapter(
        homeChildRVAdapter: RecyclerView.Adapter<*>?
    ) {
        mainActivityViewModel.downloadList.observe(lifecycleOwner) {
            updateInstallingAppStatus(it, fusedHome)
            mainActivityViewModel.updateStatusOfFusedApps(fusedHome.list, it)
            (homeChildRVAdapter as HomeChildRVAdapter).setData(fusedHome.list)
        }
    }

    private fun updateInstallingAppStatus(
        downloadList: List<FusedDownload>,
        fusedHome: FusedHome
    ) {
        downloadList.forEach { fusedDownload ->
            findInstallingApp(fusedHome, fusedDownload)?.status = fusedDownload.status
        }
    }

    private fun findInstallingApp(fusedHome: FusedHome, fusedDownload: FusedDownload): FusedApp? {
        return fusedHome.list.find { app ->
            app.origin == fusedDownload.origin && (app.package_name == fusedDownload.packageName || app._id == fusedDownload.id)
        }
    }

    fun setData(newList: List<FusedHome>) {
        submitList(newList.map { it.copy() })
    }
+8 −6
Original line number Diff line number Diff line
@@ -119,7 +119,10 @@ class InstallAppWorker @AssistedInject constructor(
    ) {
        databaseRepository.getDownloadFlowById(it.id).takeWhile { isDownloading }
            .collect { fusedDownload ->
                fusedDownload?.let {
                if (fusedDownload == null) {
                    isDownloading = false
                    return@collect
                }
                Log.d(
                    TAG,
                    "doWork: flow collect ===> ${fusedDownload.name} ${fusedDownload.status}"
@@ -127,7 +130,6 @@ class InstallAppWorker @AssistedInject constructor(
                handleFusedDownloadStatus(fusedDownload)
            }
    }
    }

    private fun handleFusedDownloadStatus(fusedDownload: FusedDownload) {
        when (fusedDownload.status) {
+4 −8
Original line number Diff line number Diff line
@@ -164,15 +164,11 @@ class SearchFragment :
        }

        mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list ->
            val searchResult = searchViewModel.searchResult.value?.toMutableList()
            if (!searchResult.isNullOrEmpty()) {
                list.forEach {
                    searchResult.find { app ->
                        app.origin == it.origin && (app.package_name == it.packageName || app._id == it.id)
                    }?.status = it.status
                }
                searchViewModel.searchResult.value = searchResult
            val searchList = searchViewModel.searchResult.value?.toMutableList()
            searchList?.let {
                mainActivityViewModel.updateStatusOfFusedApps(searchList, list)
            }
            searchViewModel.searchResult.value = searchList
        }

        searchViewModel.searchResult.observe(viewLifecycleOwner) {
Loading