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

Commit 865c4604 authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Introduce HomeConverter

parent c1c44c7e
Loading
Loading
Loading
Loading
+0 −69
Original line number Diff line number Diff line
@@ -19,22 +19,16 @@
package foundation.e.apps.data.application.home

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.liveData
import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.AuthData
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.application.search.FusedHomeDeferred
import foundation.e.apps.data.application.search.SearchApi
import foundation.e.apps.data.application.utils.toApplication
import foundation.e.apps.data.cleanapk.data.home.HomeScreenResponse
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.handleNetworkResult
@@ -46,10 +40,8 @@ import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import retrofit2.Response
import timber.log.Timber
import javax.inject.Inject
import foundation.e.apps.data.cleanapk.data.home.CleanApkHome

class HomeApiImpl @Inject constructor(
    @ApplicationContext private val context: Context,
@@ -211,65 +203,4 @@ class HomeApiImpl @Inject constructor(
            )
        }
    }

    private suspend fun toGenericHome(cleanApkHome: CleanApkHome, appType: String): List<Home> {
        val list = mutableListOf<Home>()

        openSourceCategories.forEach { (key, value) ->
            when (key) {
                "top_updated_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_apps, list, value)
                }

                "top_updated_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_games, list, value)
                }

                "popular_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_apps, list, value)
                }

                "popular_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_games, list, value)
                }

                "popular_apps_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_apps_in_last_24_hours,
                        list,
                        value
                    )
                }

                "popular_games_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_games_in_last_24_hours,
                        list,
                        value
                    )
                }

                "discover" -> {
                    applicationDataManager.prepareApps(cleanApkHome.discover, list, value)
                }
            }
        }

        return list.map {
            it.source = appType
            it
        }
    }

    private val openSourceCategories: Map<String, String> by lazy {
        mapOf(
            "top_updated_apps" to context.getString(R.string.top_updated_apps),
            "top_updated_games" to context.getString(R.string.top_updated_games),
            "popular_apps_in_last_24_hours" to context.getString(R.string.popular_apps_in_last_24_hours),
            "popular_games_in_last_24_hours" to context.getString(R.string.popular_games_in_last_24_hours),
            "popular_apps" to context.getString(R.string.popular_apps),
            "popular_games" to context.getString(R.string.popular_games),
            "discover" to context.getString(R.string.discover)
        )
    }
}
+2 −67
Original line number Diff line number Diff line
@@ -19,25 +19,20 @@
package foundation.e.apps.data.cleanapk.repositories

import android.content.Context
import android.util.Log
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.cleanapk.CleanApkDownloadInfoFetcher
import foundation.e.apps.data.cleanapk.CleanApkRetrofit
import foundation.e.apps.data.cleanapk.data.app.CleanApkApplication
import foundation.e.apps.data.cleanapk.data.categories.Categories
import foundation.e.apps.data.cleanapk.data.download.Download
import foundation.e.apps.data.cleanapk.data.home.CleanApkHome
import foundation.e.apps.data.cleanapk.data.search.Search
import retrofit2.Response
import javax.inject.Inject

class CleanApkAppsRepository @Inject constructor(
    private val cleanApkRetrofit: CleanApkRetrofit,
    private val applicationDataManager: ApplicationDataManager,
    private val homeConverter: HomeConverter,
    @ApplicationContext val context: Context
) : CleanApkRepository, CleanApkDownloadInfoFetcher {

@@ -49,8 +44,7 @@ class CleanApkAppsRepository @Inject constructor(
        )

        val home = response.body()?.home ?: throw IllegalStateException("No home data found")

        val listHome = toGenericHome(home, CleanApkRetrofit.APP_TYPE_ANY)
        val listHome = homeConverter.toGenericHome(home, CleanApkRetrofit.APP_TYPE_ANY)
        val map = mutableMapOf<String, List<Application>>()
        listHome.forEach {
            map[it.title] = it.list
@@ -59,55 +53,6 @@ class CleanApkAppsRepository @Inject constructor(
        return map
    }

    private suspend fun toGenericHome(cleanApkHome: CleanApkHome, appType: String): List<Home> {
        val list = mutableListOf<Home>()

        openSourceCategories.forEach { (key, value) ->
            when (key) {
                "top_updated_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_apps, list, value)
                }

                "top_updated_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_games, list, value)
                }

                "popular_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_apps, list, value)
                }

                "popular_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_games, list, value)
                }

                "popular_apps_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_apps_in_last_24_hours,
                        list,
                        value
                    )
                }

                "popular_games_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_games_in_last_24_hours,
                        list,
                        value
                    )
                }

                "discover" -> {
                    applicationDataManager.prepareApps(cleanApkHome.discover, list, value)
                }
            }
        }

        return list.map {
            it.source = appType
            it
        }
    }

    override suspend fun getSearchResult(query: String, searchBy: String?): Response<Search> {
        return cleanApkRetrofit.searchApps(
            query,
@@ -151,14 +96,4 @@ class CleanApkAppsRepository @Inject constructor(
        val version = versionCode?.let { it as String }
        return cleanApkRetrofit.getDownloadInfo(idOrPackageName, version, null)
    }

    private val openSourceCategories: Map<String, String> by lazy {
        mapOf(
            "top_updated_apps" to context.getString(R.string.top_updated_apps),
            "top_updated_games" to context.getString(R.string.top_updated_games),
            "popular_apps_in_last_24_hours" to context.getString(R.string.popular_apps_in_last_24_hours),
            "popular_games_in_last_24_hours" to context.getString(R.string.popular_games_in_last_24_hours),
            "discover" to context.getString(R.string.discover)
        )
    }
}
+2 −65
Original line number Diff line number Diff line
@@ -20,21 +20,17 @@ package foundation.e.apps.data.cleanapk.repositories

import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.cleanapk.CleanApkRetrofit
import foundation.e.apps.data.cleanapk.data.app.CleanApkApplication
import foundation.e.apps.data.cleanapk.data.categories.Categories
import foundation.e.apps.data.cleanapk.data.home.CleanApkHome
import foundation.e.apps.data.cleanapk.data.search.Search
import retrofit2.Response
import javax.inject.Inject

class CleanApkPwaRepository @Inject constructor(
    private val cleanAPKRetrofit: CleanApkRetrofit,
    private val applicationDataManager: ApplicationDataManager,
    private val homeConverter: HomeConverter,
    @ApplicationContext val context: Context
) : CleanApkRepository {

@@ -46,7 +42,7 @@ class CleanApkPwaRepository @Inject constructor(

        val home = response.body()?.home ?: throw IllegalStateException("No home data found")

        val listHome = toGenericHome(home, CleanApkRetrofit.APP_TYPE_PWA)
        val listHome = homeConverter.toGenericHome(home, CleanApkRetrofit.APP_TYPE_PWA)
        val map = mutableMapOf<String, List<Application>>()
        listHome.forEach {
            map[it.title] = it.list
@@ -55,55 +51,6 @@ class CleanApkPwaRepository @Inject constructor(
        return map
    }

    private suspend fun toGenericHome(cleanApkHome: CleanApkHome, appType: String): List<Home> {
        val list = mutableListOf<Home>()

        openSourceCategories.forEach { (key, value) ->
            when (key) {
                "top_updated_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_apps, list, value)
                }

                "top_updated_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_games, list, value)
                }

                "popular_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_apps, list, value)
                }

                "popular_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_games, list, value)
                }

                "popular_apps_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_apps_in_last_24_hours,
                        list,
                        value
                    )
                }

                "popular_games_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_games_in_last_24_hours,
                        list,
                        value
                    )
                }

                "discover" -> {
                    applicationDataManager.prepareApps(cleanApkHome.discover, list, value)
                }
            }
        }

        return list.map {
            it.source = appType
            it
        }
    }

    override suspend fun getSearchResult(query: String, searchBy: String?): Response<Search> {
        return cleanAPKRetrofit.searchApps(
            query,
@@ -139,14 +86,4 @@ class CleanApkPwaRepository @Inject constructor(
    override suspend fun getAppDetails(packageNameOrId: String): Response<CleanApkApplication> {
        return cleanAPKRetrofit.getAppOrPWADetailsByID(packageNameOrId, null, null)
    }

    private val openSourceCategories: Map<String, String> by lazy {
        mapOf(
            "top_updated_apps" to context.getString(R.string.top_updated_apps),
            "top_updated_games" to context.getString(R.string.top_updated_games),
            "popular_apps_in_last_24_hours" to context.getString(R.string.popular_apps_in_last_24_hours),
            "popular_games_in_last_24_hours" to context.getString(R.string.popular_games_in_last_24_hours),
            "discover" to context.getString(R.string.discover)
        )
    }
}
+76 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.cleanapk.repositories

import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.cleanapk.data.home.CleanApkHome
import javax.inject.Inject

class HomeConverter @Inject constructor(
    @ApplicationContext val context: Context,
    private val applicationDataManager: ApplicationDataManager
) {

    suspend fun toGenericHome(cleanApkHome: CleanApkHome, appType: String): List<Home> {
        val list = mutableListOf<Home>()

        openSourceCategories.forEach { (key, value) ->
            when (key) {
                "top_updated_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_apps, list, value)
                }

                "top_updated_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.top_updated_games, list, value)
                }

                "popular_apps" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_apps, list, value)
                }

                "popular_games" -> {
                    applicationDataManager.prepareApps(cleanApkHome.popular_games, list, value)
                }

                "popular_apps_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_apps_in_last_24_hours,
                        list,
                        value
                    )
                }

                "popular_games_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(
                        cleanApkHome.popular_games_in_last_24_hours,
                        list,
                        value
                    )
                }

                "discover" -> {
                    applicationDataManager.prepareApps(cleanApkHome.discover, list, value)
                }
            }
        }

        return list.map {
            it.source = appType
            it
        }
    }

    private val openSourceCategories: Map<String, String> by lazy {
        mapOf(
            "top_updated_apps" to context.getString(R.string.top_updated_apps),
            "top_updated_games" to context.getString(R.string.top_updated_games),
            "popular_apps_in_last_24_hours" to context.getString(R.string.popular_apps_in_last_24_hours),
            "popular_games_in_last_24_hours" to context.getString(R.string.popular_games_in_last_24_hours),
            "popular_apps" to context.getString(R.string.popular_apps),
            "popular_games" to context.getString(R.string.popular_games),
            "discover" to context.getString(R.string.discover)
        )
    }
}
 No newline at end of file