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

Commit 54ae789e authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

Merge branch '8633-fix-translation-for-sources' into 'main'

fix(source): localize Source labels and parsing via string resources

See merge request !700
parents a1858001 416bcc25
Loading
Loading
Loading
Loading
Loading
+11 −20
Original line number Diff line number Diff line
@@ -17,29 +17,20 @@

package foundation.e.apps.data.enums

enum class Source {
    OPEN_SOURCE,
    PWA,
    SYSTEM_APP,
    PLAY_STORE;
import androidx.annotation.StringRes
import foundation.e.apps.R

    override fun toString(): String {
        return when (this) {
            PLAY_STORE -> ""
            else -> name.lowercase()
                .split("_")
                .joinToString(" ") { it.replaceFirstChar(Char::uppercase) }
        }
    }
enum class Source(@param:StringRes val stringResId: Int?) {
    OPEN_SOURCE(R.string.open_source),
    PWA(R.string.pwa),
    SYSTEM_APP(R.string.system_app),
    PLAY_STORE(null);

    fun toString(getString: (Int) -> String) = stringResId?.let(getString) ?: ""

    companion object {
        fun fromString(source: String): Source {
            return when (source) {
                "Open Source" -> OPEN_SOURCE
                "PWA" -> PWA
                "SYSTEM_APP" -> SYSTEM_APP
                else -> PLAY_STORE
            }
        fun fromStringResId(@StringRes source: Int): Source {
            return entries.find { it.stringResId == source } ?: PLAY_STORE
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -447,7 +447,7 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
            val source = if (isFdroidDeepLink) Source.OPEN_SOURCE else args.source
            if (source == Source.OPEN_SOURCE || source == Source.PWA) {
                sourceTag.visibility = View.VISIBLE
                sourceTag.text = it.source.toString()
                sourceTag.text = it.source.toString(::getString)
            }
            appIcon.load(it.iconUrl)
        }
+3 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import foundation.e.apps.R
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.application.ApplicationInstaller
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.install.download.data.DownloadProgress
import foundation.e.apps.data.install.pkg.AppLoungePackageManager
@@ -228,8 +229,9 @@ class ApplicationListFragment :
         * Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/478
         */
        showLoadingUI()
        val sourceType = Source.fromStringResId(args.source)
        viewModel.loadList(args.category, args.source)
        if (args.source != "Open Source" && args.source != "PWA") {
        if (sourceType != Source.OPEN_SOURCE && sourceType != Source.PWA) {
            /*
             * For Play store apps we try to load more apps on reaching end of list.
             * Source: https://stackoverflow.com/a/46342525
+1 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ class ApplicationListRVAdapter(

    private fun ApplicationListItemBinding.updateSourceTag(searchApp: Application) {
        sourceTag.visibility = View.INVISIBLE
        val tag = searchApp.source.toString()
        val tag = searchApp.source.toString(root.context::getString)
        if (tag.isNotBlank()) {
            sourceTag.text = tag
            sourceTag.visibility = View.VISIBLE
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

package foundation.e.apps.ui.applicationlist

import androidx.annotation.StringRes
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@@ -45,11 +46,11 @@ class ApplicationListViewModel @Inject constructor(

    private var nextPageUrl: String? = null

    fun loadList(category: String, source: String) {
    fun loadList(category: String, @StringRes sourceResourceId: Int) {
        if (isLoading) {
            return
        }
        val sourceType = Source.fromString(source)
        val sourceType = Source.fromStringResId(sourceResourceId)
        val isCleanApk = sourceType != Source.PLAY_STORE

        viewModelScope.launch(Dispatchers.IO) {
Loading