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

Commit 04b6203e authored by Md.Hasib Prince's avatar Md.Hasib Prince Committed by Aayush Gupta
Browse files

App Lounge: fixed-> app list page for Open Source and WPA

 Conflicts:
	app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt
parent 44475b4b
Loading
Loading
Loading
Loading
+41 −12
Original line number Diff line number Diff line
@@ -334,19 +334,11 @@ class FusedAPIImpl @Inject constructor(
    suspend fun listApps(category: String, browseUrl: String, authData: AuthData): List<FusedApp>? {
        val preferredApplicationType = preferenceManagerModule.preferredApplicationType()

        if (preferredApplicationType != APP_TYPE_ANY) {
            val response = if (preferredApplicationType == APP_TYPE_OPEN) {
                cleanAPKRepository.listApps(
                    category,
                    CleanAPKInterface.APP_SOURCE_FOSS,
                    CleanAPKInterface.APP_TYPE_ANY
                ).body()
        if (preferredApplicationType != "any") {
            val response = if (preferredApplicationType == "open") {
                getOpenSourceAppsResponse(category)
            } else {
                cleanAPKRepository.listApps(
                    category,
                    CleanAPKInterface.APP_SOURCE_ANY,
                    CleanAPKInterface.APP_TYPE_PWA
                ).body()
                getPWAAppsResponse(category)
            }
            response?.apps?.forEach {
                it.status =
@@ -360,6 +352,43 @@ class FusedAPIImpl @Inject constructor(
        }
    }

    suspend fun getPWAApps(category: String): List<FusedApp>? {
        val response = getPWAAppsResponse(category)
        response?.apps?.forEach {
            it.status =
                pkgManagerModule.getPackageStatus(it.package_name, it.latest_version_code)
        }
        return response?.apps
    }

    suspend fun getOpenSourceApps(category: String): List<FusedApp>? {
        val response = getOpenSourceAppsResponse(category)
        response?.apps?.forEach {
            it.status =
                pkgManagerModule.getPackageStatus(it.package_name, it.latest_version_code)
        }
        return response?.apps
    }

    suspend fun getPlayStoreApps(browseUrl: String, authData: AuthData): List<FusedApp> {
        return gPlayAPIRepository.listApps(browseUrl, authData).map { app ->
            app.transformToFusedApp()
        }
    }

    private suspend fun getOpenSourceAppsResponse(category: String) = cleanAPKRepository.listApps(
        category,
        CleanAPKInterface.APP_SOURCE_FOSS,
        CleanAPKInterface.APP_TYPE_ANY
    ).body()

    private suspend fun getPWAAppsResponse(category: String) = cleanAPKRepository.listApps(
        category,
        CleanAPKInterface.APP_SOURCE_ANY,
        CleanAPKInterface.APP_TYPE_PWA
    ).body()


    suspend fun getApplicationDetails(
        packageNameList: List<String>,
        authData: AuthData,
+2 −1
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ class ApplicationListFragment : Fragment(R.layout.fragment_application_list), Fu
            applicationListViewModel.getList(
                args.category,
                args.browseUrl,
                it
                it,
                args.source
            )
        }

+5 −3
Original line number Diff line number Diff line
@@ -26,20 +26,22 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import foundation.e.apps.api.fused.FusedAPIRepository
import foundation.e.apps.api.fused.data.FusedApp
import foundation.e.apps.api.fused.data.Origin
import foundation.e.apps.domain.ApplicationListUseCase
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class ApplicationListViewModel @Inject constructor(
    private val fusedAPIRepository: FusedAPIRepository
    private val fusedAPIRepository: FusedAPIRepository,
    private val applicationListUseCase: ApplicationListUseCase
) : ViewModel() {

    val appListLiveData: MutableLiveData<List<FusedApp>> = MutableLiveData()

    fun getList(category: String, browseUrl: String, authData: AuthData) {
    fun getList(category: String, browseUrl: String, authData: AuthData, source: String) {
        viewModelScope.launch(Dispatchers.IO) {
            appListLiveData.postValue(fusedAPIRepository.listApps(category, browseUrl, authData))
            appListLiveData.postValue(applicationListUseCase.getAppsList(category, browseUrl, authData, source))
        }
    }

+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ class CategoriesRVAdapter :
                    CategoriesFragmentDirections.actionCategoriesFragmentToApplicationListFragment(
                        oldList[position].id,
                        oldList[position].title,
                        oldList[position].tag,
                        oldList[position].browseUrl
                    )
                holder.itemView.findNavController().navigate(direction)
+15 −0
Original line number Diff line number Diff line
package foundation.e.apps.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import foundation.e.apps.domain.repositories.IApplicationsRepository
import foundation.e.apps.repositories.ApplicationRepositoryImpl

@InstallIn(ViewModelComponent::class)
@Module
interface RepositoryModule {
    @Binds
    fun getApplicationsRepository(applicationRepositoryImpl: ApplicationRepositoryImpl): IApplicationsRepository
}
 No newline at end of file
Loading