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

Commit 37fe9e92 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Merge branch '5364-language_crash_app_categories' into 'main'

Issue 5364: Fix crash when clicking an "Open Source" category for different language

See merge request !109
parents 3b4d7f05 d46c3a87
Loading
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import foundation.e.apps.api.fused.utils.CategoryUtils
import foundation.e.apps.api.gplay.GPlayAPIRepository
import foundation.e.apps.manager.database.fusedDownload.FusedDownload
import foundation.e.apps.manager.pkg.PkgManagerModule
import foundation.e.apps.utils.enums.AppTag
import foundation.e.apps.utils.enums.Origin
import foundation.e.apps.utils.enums.Status
import foundation.e.apps.utils.enums.Type
@@ -309,11 +310,11 @@ class FusedAPIImpl @Inject constructor(
        }
    }

    private fun getCategoryTag(preferredApplicationType: String): String {
    private fun getCategoryTag(preferredApplicationType: String): AppTag {
        return if (preferredApplicationType == APP_TYPE_OPEN) {
            context.getString(R.string.open_source)
            AppTag.OpenSource(context.getString(R.string.open_source))
        } else {
            context.getString(R.string.pwa)
            AppTag.PWA(context.getString(R.string.pwa))
        }
    }

@@ -336,7 +337,7 @@ class FusedAPIImpl @Inject constructor(
                getFusedCategoryBasedOnCategoryType(
                    it,
                    type,
                    context.getString(R.string.open_source)
                    AppTag.OpenSource(context.getString(R.string.open_source))
                )
            )
        }
@@ -344,7 +345,7 @@ class FusedAPIImpl @Inject constructor(
        data?.let {
            categoriesList.addAll(
                getFusedCategoryBasedOnCategoryType(
                    it, type, context.getString(R.string.pwa)
                    it, type, AppTag.PWA(context.getString(R.string.pwa))
                )
            )
        }
@@ -376,7 +377,7 @@ class FusedAPIImpl @Inject constructor(
    private fun getFusedCategoryBasedOnCategoryType(
        categories: Categories,
        categoryType: Category.Type,
        tag: String
        tag: AppTag
    ): List<FusedCategory> {
        return when (categoryType) {
            Category.Type.APPLICATION -> {
@@ -390,7 +391,7 @@ class FusedAPIImpl @Inject constructor(

    private fun getAppsCategoriesAsFusedCategory(
        categories: Categories,
        tag: String
        tag: AppTag
    ): List<FusedCategory> {
        return categories.apps.map { category ->
            createFusedCategoryFromCategory(category, categories, Category.Type.APPLICATION, tag)
@@ -399,7 +400,7 @@ class FusedAPIImpl @Inject constructor(

    private fun getGamesCategoriesAsFusedCategory(
        categories: Categories,
        tag: String
        tag: AppTag
    ): List<FusedCategory> {
        return categories.games.map { category ->
            createFusedCategoryFromCategory(category, categories, Category.Type.GAME, tag)
@@ -410,7 +411,7 @@ class FusedAPIImpl @Inject constructor(
        category: String,
        categories: Categories,
        appType: Category.Type,
        tag: String
        tag: AppTag
    ): FusedCategory {
        return FusedCategory(
            id = category,
+6 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

package foundation.e.apps.api.fused.data

import foundation.e.apps.utils.enums.AppTag
import java.util.UUID

data class FusedCategory(
@@ -26,5 +27,9 @@ data class FusedCategory(
    val browseUrl: String = String(),
    val imageUrl: String = String(),
    var drawable: Int = -1,
    var tag: String = String()
    /*
     * Change tag to standard AppTag class.
     * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5364
     */
    var tag: AppTag = AppTag.GPlay()
)
+3 −3
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class CategoriesRVAdapter :
                    CategoriesFragmentDirections.actionCategoriesFragmentToApplicationListFragment(
                        oldList[position].id,
                        oldList[position].title,
                        oldList[position].tag,
                        oldList[position].tag.getOperationalTag(),
                        oldList[position].browseUrl
                    )
                holder.itemView.findNavController().navigate(direction)
@@ -66,9 +66,9 @@ class CategoriesRVAdapter :
            }
            categoryTitle.text = oldList[position].title
            val tag = oldList[position].tag
            if (tag.isNotEmpty()) {
            if (tag.displayTag.isNotBlank()) {
                categoryTag.visibility = View.VISIBLE
                categoryTag.text = tag
                categoryTag.text = tag.displayTag
            } else {
                categoryTag.visibility = View.INVISIBLE
                categoryTag.text = ""
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019-2022  E FOUNDATION
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps.utils.enums

/**
 * This sealed class is used for the tags shown in the categories screen,
 * the [displayTag] holds the tag in the user device specific locale.
 * (Example: [OpenSource.displayTag] for Deutsch language = "Quelloffen")
 *
 * Previously this was hard coded, which led to crashes due to changes in different locales.
 * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5364
 */
sealed class AppTag(val displayTag: String) {
    class OpenSource(displayTag: String): AppTag(displayTag)
    class PWA(displayTag: String): AppTag(displayTag)
    class GPlay(displayTag: String = ""): AppTag(displayTag)

    /**
     * In many places in the code, checks are for hard coded string "Open Source".
     * This method allows for all those check to work without modification.
     */
    fun getOperationalTag(): String {
        return if (this is OpenSource) "Open Source"
        else this::class.java.simpleName
    }

}
 No newline at end of file