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

Commit f4b0b21b authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

refactor: apply rabbit suggestion

parent 09862d43
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ class SystemAppsUpdatesRepository @Inject constructor(
) {
    private val systemAppProjectList = mutableListOf<SystemAppProject>()

    private val androidVersionCode by lazy { getAndroidVersionCodeChar() }

    private fun getUpdatableSystemApps(): List<String> {
        return systemAppProjectList.map { it.packageName }
    }
@@ -130,7 +132,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
        val projectId = systemAppProject.projectId

        return if (systemAppProject.dependsOnAndroidVersion) {
            val latestRelease = getLatestSystemAppReleaseByAndroidVersion(projectId)
            val latestRelease = getLatestReleaseByAndroidVersion(projectId)
            if (latestRelease == null) {
                null //todo replace by an error code to avoid to check for nullity in calling method ?
            } else {
@@ -143,15 +145,12 @@ class SystemAppsUpdatesRepository @Inject constructor(
        }
    }

    //todo: rename & rewrite ?
    private suspend fun getLatestSystemAppReleaseByAndroidVersion(projectId: Int): GitlabReleaseInfo? {
    private suspend fun getLatestReleaseByAndroidVersion(projectId: Int): GitlabReleaseInfo? {
        val gitlabReleaseList = systemAppDefinitionApi.getSystemAppReleases(projectId).body()

        val latestRelease = gitlabReleaseList?.filter {
            it.tagName.contains("api${getAndroidVersion()}-")
        }?.sortedByDescending { it.releasedAt }?.first()

        return latestRelease
        return gitlabReleaseList?.filter {
            it.tagName.contains("api$androidVersionCode-")
        }?.sortedByDescending { it.releasedAt }?.firstOrNull()
    }

    /*
@@ -159,7 +158,7 @@ class SystemAppsUpdatesRepository @Inject constructor(
    through BUILD.VERSIO_CODES (may be due to targeted SDK or minimum SDK.)
    todo: This method shouldn't be called for each app. We need to define it only once!
     */
    private fun getAndroidVersion(): String {
    private fun getAndroidVersionCodeChar(): String {
        return when (Build.VERSION.SDK_INT) {
            Build.VERSION_CODES.Q -> "Q"
            Build.VERSION_CODES.R -> "R"
+5 −6
Original line number Diff line number Diff line
package foundation.e.apps.data.gitlab.models

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.squareup.moshi.Json
import java.util.Date
import com.squareup.moshi.JsonClass
import java.time.Instant


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonClass(generateAdapter = true)
data class GitlabReleaseInfo(
    @Json(name = "tag_name") val tagName: String,
    @Json(name = "name") val releaseName: String,
    @Json(name = "created_at") val createdAt: Date,
    @Json(name = "released_at") val releasedAt: Date,
    @Json(name = "created_at") val createdAt: Instant,
    @Json(name = "released_at") val releasedAt: Instant,
)