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

Commit 406f2cb7 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

change how system apps are combined with other updatable apps

parent f0553887
Loading
Loading
Loading
Loading
+32 −12
Original line number Diff line number Diff line
@@ -126,15 +126,19 @@ class UpdatesManagerImpl @Inject constructor(
            status = if (status == ResultStatus.OK) status else gplayStatus
        }

        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)
        val systemApps = mutableListOf<Application>()

        getUpdatesFromApi({
            val systemApps = getSystemUpdates().toMutableList()
            putAppLoungeAtLast(systemApps)
            Pair(systemApps, ResultStatus.OK)
        }, updateList)
            getSystemUpdates().toMutableList().let {
                Pair(it, ResultStatus.OK)
            }
        }, systemApps)

        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)

        arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps)

        return Pair(nonFaultyUpdateList, status)
        return Pair(updateList, status)
    }

    suspend fun getUpdatesOSS(): Pair<List<Application>, ResultStatus> {
@@ -167,19 +171,35 @@ class UpdatesManagerImpl @Inject constructor(
            }, updateList)
        }

        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)
        val systemApps = mutableListOf<Application>()

        getUpdatesFromApi({
            val systemApps = getSystemUpdates().toMutableList()
            putAppLoungeAtLast(systemApps)
            Pair(systemApps, ResultStatus.OK)
        }, updateList)
            getSystemUpdates().toMutableList().let {
                Pair(it, ResultStatus.OK)
            }
        }, systemApps)

        val nonFaultyUpdateList = faultyAppRepository.removeFaultyApps(updateList)

        arrangeWithSystemApps(updateList, nonFaultyUpdateList, systemApps)

        return Pair(nonFaultyUpdateList, status)
        return Pair(updateList, status)
    }

    suspend fun getSystemUpdates(): List<Application> = applicationRepository.getSystemUpdates()

    private fun arrangeWithSystemApps(
        updateList: MutableList<Application>,
        nonFaultyApps: List<Application>,
        systemApps: List<Application>,
    ) {
        updateList.clear()
        updateList.addAll(nonFaultyApps)
        updateList.addAll(systemApps)

        putAppLoungeAtLast(updateList)
    }

    private fun putAppLoungeAtLast(updateList: MutableList<Application>) {
        val appLoungeItem = updateList.find { it.isSystemApp && it.package_name == context.packageName }
            ?: return