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

Commit e3d01803 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

change how system apps are combined with other updatable apps

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


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


        getUpdatesFromApi({
        getUpdatesFromApi({
            val systemApps = getSystemUpdates().toMutableList()
            getSystemUpdates().toMutableList().let {
            putAppLoungeAtLast(systemApps)
                Pair(it, ResultStatus.OK)
            Pair(systemApps, ResultStatus.OK)
            }
        }, updateList)
        }, 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> {
    suspend fun getUpdatesOSS(): Pair<List<Application>, ResultStatus> {
@@ -167,19 +171,35 @@ class UpdatesManagerImpl @Inject constructor(
            }, updateList)
            }, updateList)
        }
        }


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


        getUpdatesFromApi({
        getUpdatesFromApi({
            val systemApps = getSystemUpdates().toMutableList()
            getSystemUpdates().toMutableList().let {
            putAppLoungeAtLast(systemApps)
                Pair(it, ResultStatus.OK)
            Pair(systemApps, ResultStatus.OK)
            }
        }, updateList)
        }, 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()
    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>) {
    private fun putAppLoungeAtLast(updateList: MutableList<Application>) {
        val appLoungeItem = updateList.find { it.isSystemApp && it.package_name == context.packageName }
        val appLoungeItem = updateList.find { it.isSystemApp && it.package_name == context.packageName }
            ?: return
            ?: return