Loading app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +10 −9 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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)) } } Loading @@ -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)) ) ) } Loading @@ -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)) ) ) } Loading Loading @@ -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 -> { Loading @@ -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) Loading @@ -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) Loading @@ -410,7 +411,7 @@ class FusedAPIImpl @Inject constructor( category: String, categories: Categories, appType: Category.Type, tag: String tag: AppTag ): FusedCategory { return FusedCategory( id = category, Loading app/src/main/java/foundation/e/apps/api/fused/data/FusedCategory.kt +6 −1 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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() ) app/src/main/java/foundation/e/apps/categories/model/CategoriesRVAdapter.kt +3 −3 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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 = "" Loading app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt 0 → 100644 +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 Loading
app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +10 −9 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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)) } } Loading @@ -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)) ) ) } Loading @@ -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)) ) ) } Loading Loading @@ -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 -> { Loading @@ -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) Loading @@ -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) Loading @@ -410,7 +411,7 @@ class FusedAPIImpl @Inject constructor( category: String, categories: Categories, appType: Category.Type, tag: String tag: AppTag ): FusedCategory { return FusedCategory( id = category, Loading
app/src/main/java/foundation/e/apps/api/fused/data/FusedCategory.kt +6 −1 Original line number Diff line number Diff line Loading @@ -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( Loading @@ -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() )
app/src/main/java/foundation/e/apps/categories/model/CategoriesRVAdapter.kt +3 −3 Original line number Diff line number Diff line Loading @@ -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) Loading @@ -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 = "" Loading
app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt 0 → 100644 +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