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

Verified Commit 331d0884 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor(install): decouple AppInstall from app-only helpers

parent b217e659
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.install

import foundation.e.apps.data.cleanapk.CleanApkRetrofit
import foundation.e.apps.data.installation.model.InstallationSource
import javax.inject.Inject

class AppInstallIconUrlBuilder @Inject constructor() {
    fun build(source: InstallationSource, iconImageUrl: String): String {
        return if (source == InstallationSource.PLAY_STORE || source == InstallationSource.PWA) {
            "${CleanApkRetrofit.ASSET_URL}$iconImageUrl"
        } else {
            iconImageUrl
        }
    }
}
+38 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.install

import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.installation.model.InstallationSource
import foundation.e.apps.data.installation.model.InstallationType

fun Source.toInstallationSource(): InstallationSource {
    return when (this) {
        Source.OPEN_SOURCE -> InstallationSource.OPEN_SOURCE
        Source.PWA -> InstallationSource.PWA
        Source.SYSTEM_APP -> InstallationSource.SYSTEM_APP
        Source.PLAY_STORE -> InstallationSource.PLAY_STORE
    }
}

fun Type.toInstallationType(): InstallationType {
    return when (this) {
        Type.NATIVE -> InstallationType.NATIVE
        Type.PWA -> InstallationType.PWA
    }
}

fun InstallationSource.toAppSource(): Source {
    return when (this) {
        InstallationSource.OPEN_SOURCE -> Source.OPEN_SOURCE
        InstallationSource.PWA -> Source.PWA
        InstallationSource.SYSTEM_APP -> Source.SYSTEM_APP
        InstallationSource.PLAY_STORE -> Source.PLAY_STORE
    }
}

fun InstallationType.toAppType(): Type {
    return when (this) {
        InstallationType.NATIVE -> Type.NATIVE
        InstallationType.PWA -> Type.PWA
    }
}
+4 −4
Original line number Diff line number Diff line
@@ -28,11 +28,11 @@ import androidx.core.net.toUri
import androidx.lifecycle.LiveData
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.install.download.data.DownloadProgressLD
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.install.pkg.AppLoungePackageManager
import foundation.e.apps.data.install.pkg.PwaManager
import foundation.e.apps.data.installation.model.InstallationType
import foundation.e.apps.data.parentalcontrol.ContentRatingDao
import foundation.e.apps.data.parentalcontrol.ContentRatingEntity
import foundation.e.apps.domain.model.install.Status
@@ -127,8 +127,8 @@ class AppManagerImpl @Inject constructor(
    override suspend fun downloadApp(appInstall: AppInstall, isUpdate: Boolean) {
        mutex.withLock {
            when (appInstall.type) {
                Type.NATIVE -> downloadNativeApp(appInstall, isUpdate)
                Type.PWA -> pwaManager.installPWAApp(appInstall)
                InstallationType.NATIVE -> downloadNativeApp(appInstall, isUpdate)
                InstallationType.PWA -> pwaManager.installPWAApp(appInstall)
            }
        }
    }
@@ -136,7 +136,7 @@ class AppManagerImpl @Inject constructor(
    override suspend fun installApp(appInstall: AppInstall) {
        val list = mutableListOf<File>()
        when (appInstall.type) {
            Type.NATIVE -> {
            InstallationType.NATIVE -> {
                val parentPathFile = File("$cacheDir/${appInstall.packageName}")
                parentPathFile.listFiles()?.let { list.addAll(it) }
                list.sort()
+6 −4
Original line number Diff line number Diff line
@@ -20,22 +20,24 @@ package foundation.e.apps.data.install.core

import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.Type
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.install.toInstallationSource
import foundation.e.apps.data.install.toInstallationType
import foundation.e.apps.data.installation.model.InstallationType
import javax.inject.Inject

class InstallationRequest @Inject constructor() {
    fun create(application: Application): AppInstall {
        val appInstall = AppInstall(
            application._id,
            application.source,
            application.source.toInstallationSource(),
            application.status,
            application.name,
            application.package_name,
            mutableListOf(),
            mutableMapOf(),
            application.status,
            application.type,
            application.type.toInstallationType(),
            application.icon_image_path,
            application.latest_version_code,
            application.offer_type,
@@ -45,7 +47,7 @@ class InstallationRequest @Inject constructor() {
            it.contentRating = application.contentRating
        }

        if (appInstall.type == Type.PWA || application.source == Source.SYSTEM_APP) {
        if (appInstall.type == InstallationType.PWA || application.source == Source.SYSTEM_APP) {
            appInstall.downloadURLList = mutableListOf(application.url)
        }

+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import foundation.e.apps.data.install.AppInstallRepository
import foundation.e.apps.data.install.AppManager
import foundation.e.apps.data.install.AppManagerWrapper
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.install.toAppSource
import foundation.e.apps.data.install.wrapper.AppEventDispatcher
import foundation.e.apps.data.playstore.utils.GplayHttpRequestException
import kotlinx.coroutines.CancellationException
@@ -43,7 +44,7 @@ class DownloadUrlRefresher @Inject constructor(
    suspend fun updateDownloadUrls(appInstall: AppInstall, isAnUpdate: Boolean): Boolean {
        return runCatching {
            applicationRepository.updateFusedDownloadWithDownloadingInfo(
                appInstall.source,
                appInstall.source.toAppSource(),
                appInstall
            )
        }.fold(
Loading