From e8524aa37cf180d552129c717eb42bcad630231c Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 4 May 2022 04:12:59 +0530 Subject: [PATCH 1/4] App lounge: (issue_5364) create new sealed class AppTag.kt for storing tags in user specific locale. --- .../foundation/e/apps/utils/enums/AppTag.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt diff --git a/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt b/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt new file mode 100644 index 000000000..420aec5cd --- /dev/null +++ b/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt @@ -0,0 +1,25 @@ +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 -- GitLab From f26e07612505a0f7b07563f3c569e11ac536fd05 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 4 May 2022 04:15:40 +0530 Subject: [PATCH 2/4] App lounge: (issue_5364) [WIP] update FusedCategory.tag from String to AppTag type. --- .../java/foundation/e/apps/api/fused/data/FusedCategory.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/data/FusedCategory.kt b/app/src/main/java/foundation/e/apps/api/fused/data/FusedCategory.kt index 7beeacd1f..e64d4dd6b 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/data/FusedCategory.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/data/FusedCategory.kt @@ -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() ) -- GitLab From 855c6ce0faefe923f7184ba7a75c64428e50d2c4 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 4 May 2022 04:18:39 +0530 Subject: [PATCH 3/4] App lounge: (issue_5364) modify code for new AppTag type --- .../e/apps/api/fused/FusedAPIImpl.kt | 19 ++++++++++--------- .../categories/model/CategoriesRVAdapter.kt | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 15d77d99b..8f8cd36d7 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -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 { return when (categoryType) { Category.Type.APPLICATION -> { @@ -390,7 +391,7 @@ class FusedAPIImpl @Inject constructor( private fun getAppsCategoriesAsFusedCategory( categories: Categories, - tag: String + tag: AppTag ): List { 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 { 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, diff --git a/app/src/main/java/foundation/e/apps/categories/model/CategoriesRVAdapter.kt b/app/src/main/java/foundation/e/apps/categories/model/CategoriesRVAdapter.kt index d8b4cb9d7..02a02f3da 100644 --- a/app/src/main/java/foundation/e/apps/categories/model/CategoriesRVAdapter.kt +++ b/app/src/main/java/foundation/e/apps/categories/model/CategoriesRVAdapter.kt @@ -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 = "" -- GitLab From 1f0d6e6f5bfdac216ef0cf9242ef1ee27f48a6b5 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 4 May 2022 04:25:15 +0530 Subject: [PATCH 4/4] App lounge: (issue_5364) add license --- .../foundation/e/apps/utils/enums/AppTag.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt b/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt index 420aec5cd..0f13ea18c 100644 --- a/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt +++ b/app/src/main/java/foundation/e/apps/utils/enums/AppTag.kt @@ -1,3 +1,20 @@ +/* + * 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 . + */ + package foundation.e.apps.utils.enums /** -- GitLab