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

Commit 9f81987f authored by Md.Hasib Prince's avatar Md.Hasib Prince Committed by Hasib Prince
Browse files

App Lounge: Refactoring

parent 91c2fba3
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,5 +15,5 @@ interface ExodusTrackerApi {
    suspend fun getTrackerList(): Response<Trackers>

    @GET("search/{appHandle}")
    suspend fun getTrackerListOfAnApp(@Path("appHandle") appHandle: String): Response<Map<String, TrackerInfo>>
    suspend fun getTrackerInfoOfApp(@Path("appHandle") appHandle: String): Response<Map<String, TrackerInfo>>
}
+1 −1
Original line number Diff line number Diff line
@@ -4,5 +4,5 @@ import foundation.e.apps.api.Result
import foundation.e.apps.api.exodus.Tracker

interface ITrackerRepository {
    suspend fun getTrackerOfAnApp(appHandle: String): Result<List<Tracker>>
    suspend fun getTrackersOfAnApp(appHandle: String): Result<List<Tracker>>
}
+13 −15
Original line number Diff line number Diff line
@@ -16,27 +16,25 @@ class TrackerRepositoryImpl @Inject constructor(
) : ITrackerRepository {
    private var trackers: List<Tracker> = listOf()

    override suspend fun getTrackerOfAnApp(appHandle: String): Result<List<Tracker>> {
        val appTrackerResult = getResult { exodusTrackerApi.getTrackerListOfAnApp(appHandle) }
        if (appTrackerResult.isSuccess()) {
            return getTrackerListOfTheApp(appTrackerResult, appHandle)
    override suspend fun getTrackersOfAnApp(appHandle: String): Result<List<Tracker>> {
        val appTrackerInfoResult = getResult { exodusTrackerApi.getTrackerInfoOfApp(appHandle) }
        if (appTrackerInfoResult.isSuccess()) {
            return handleAppTrackerInfoResultSuccess(appTrackerInfoResult, appHandle)
        }
        return Result.error(extractErrorMessage(appTrackerResult))
        return Result.error(extractErrorMessage(appTrackerInfoResult))
    }

    private suspend fun getTrackerListOfTheApp(
    private suspend fun handleAppTrackerInfoResultSuccess(
        appTrackerResult: Result<Map<String, TrackerInfo>>,
        appHandle: String
    ): Result<List<Tracker>> {
        return if (trackers.isNotEmpty()) {
            handleAppTrackerResult(appTrackerResult, appHandle)
        } else {
            getTrackerList()
            handleAppTrackerResult(appTrackerResult, appHandle)
        if(trackers.isEmpty()) {
            generateTrackerList()
        }
        return createAppTrackerListResult(appTrackerResult, appHandle)
    }

    private suspend fun getTrackerList() {
    private suspend fun generateTrackerList() {
        val trackerListOfLocalDB = trackerDao.getTrackers()
        if (trackerListOfLocalDB.isNotEmpty()) {
            this.trackers = trackerListOfLocalDB
@@ -54,17 +52,17 @@ class TrackerRepositoryImpl @Inject constructor(
        return appTrackerResult.message ?: "Unknown Error"
    }

    private fun handleAppTrackerResult(
    private fun createAppTrackerListResult(
        appTrackerResult: Result<Map<String, TrackerInfo>>,
        appHandle: String
    ): Result<List<Tracker>> {
        appTrackerResult.data?.let {
            return Result.success(findTrackersForApp(it, appHandle))
            return Result.success(filterTrackersOfTheApp(it, appHandle))
        }
        return Result.error(extractErrorMessage(appTrackerResult))
    }

    private fun findTrackersForApp(
    private fun filterTrackersOfTheApp(
        appTrackerData: Map<String, TrackerInfo>,
        appHandle: String
    ): List<Tracker> {
+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ class ApplicationViewModel @Inject constructor(
                    emit(Result.success(it.trackers))
                    return@liveData
                }
                val trackerResultOfAnApp = trackerRepository.getTrackerOfAnApp(it.package_name)
                val trackerResultOfAnApp = trackerRepository.getTrackersOfAnApp(it.package_name)
                handleAppTrackerResult(trackerResultOfAnApp, it)
            }
        }