diff --git a/app/src/main/java/foundation/e/apps/data/application/utils/CategoryStringFormatter.kt b/app/src/main/java/foundation/e/apps/data/application/utils/CategoryStringFormatter.kt
new file mode 100644
index 0000000000000000000000000000000000000000..d1d42e195bf6a0a3ef46a2fcfb64cc92f7aa17a8
--- /dev/null
+++ b/app/src/main/java/foundation/e/apps/data/application/utils/CategoryStringFormatter.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2024 MURENA SAS
+ *
+ * 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.data.application.utils
+
+import java.util.Locale
+
+object CategoryStringFormatter {
+ fun format(input: String): String {
+ return when (input) {
+ "unknown" -> "Unknown"
+ else ->
+ input.replace("_", " ").split(" ").joinToString(" ") { word ->
+ if (word.lowercase() == "and") word.lowercase(Locale.getDefault())
+ else {
+ word.replaceFirstChar {
+ if (it.isLowerCase()) it.titlecase(Locale.getDefault())
+ else it.toString()
+ } // Example: books and reference -> Books and Reference
+ }
+ }
+ } // Capitalize each word except "and"
+ }
+}
diff --git a/app/src/main/java/foundation/e/apps/data/application/utils/CategoryUtils.kt b/app/src/main/java/foundation/e/apps/data/application/utils/CategoryUtils.kt
index 5908cf2898f9afec3875c28f9306cd46ff405df8..d105b266df1c45071bfb652a759eefce4c3e843e 100644
--- a/app/src/main/java/foundation/e/apps/data/application/utils/CategoryUtils.kt
+++ b/app/src/main/java/foundation/e/apps/data/application/utils/CategoryUtils.kt
@@ -1,6 +1,5 @@
/*
- * Apps Quickly and easily install Android apps onto your device!
- * Copyright (C) 2021 E FOUNDATION
+ * Copyright (C) 2021-2024 MURENA SAS
*
* 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
@@ -14,6 +13,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
+ *
*/
package foundation.e.apps.data.application.utils
@@ -26,7 +26,7 @@ import foundation.e.apps.data.enums.AppTag
object CategoryUtils {
private const val CATEGORY_OPEN_GAMES_ID = "game_open_games"
- private const val CATEGORY_OPEN_GAMES_TITLE = "Open games"
+ private const val CATEGORY_OPEN_GAMES_TITLE = "Open Games"
private const val CATEGORY_TITLE_REPLACEABLE_CONJUNCTION = "&"
private const val CATEGORY_TITLE_CONJUNCTION = "and"
@@ -127,7 +127,8 @@ object CategoryUtils {
return if (category.contentEquals(CATEGORY_OPEN_GAMES_ID)) {
CATEGORY_OPEN_GAMES_TITLE
} else {
- categories.translations.getOrDefault(category, "")
+ val value = categories.translations.getOrDefault(category, "")
+ CategoryStringFormatter.format(value)
}
}
diff --git a/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt
index 210a4aa1199b004e2de40ee65647947477eeb268..9034b313a6cc7c306278bcb441e032a2e5e1a379 100644
--- a/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt
+++ b/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt
@@ -55,6 +55,7 @@ import foundation.e.apps.MainActivity
import foundation.e.apps.R
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.shareUri
+import foundation.e.apps.data.application.utils.CategoryStringFormatter
import foundation.e.apps.data.cleanapk.CleanApkRetrofit
import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.enums.ResultStatus
@@ -148,6 +149,8 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
private const val PRIVACY_GUIDELINE_URL = "https://doc.e.foundation/privacy_score"
private const val REQUEST_EXODUS_REPORT_URL =
"https://reports.exodus-privacy.eu.org/en/analysis/submit#"
+ private const val CATEGORY_GAMES_F_DROID = "game_open_games"
+ private const val CATEGORY_GAMES_PWA = "web_games"
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -460,15 +463,17 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) {
private fun updateCategoryTitle(app: Application) {
binding.titleInclude.apply {
- var catText = app.category.ifBlank { args.category }
- when {
- catText.isBlank() -> categoryTitle.isVisible = false
- catText == "game_open_games" -> catText = getString(R.string.games) // F-droid games
- catText == "web_games" -> catText = getString(R.string.games) // PWA games
+ var categoryText = app.category.ifBlank { args.category }
+
+ categoryText = when (categoryText) {
+ CATEGORY_GAMES_F_DROID, CATEGORY_GAMES_PWA -> getString(R.string.games)
+ else -> CategoryStringFormatter.format(categoryText)
}
- catText = catText.replace("_", " ")
- categoryTitle.text = catText
+ this.categoryTitle.apply {
+ isVisible = categoryText.isNotBlank()
+ text = categoryText
+ }
}
}
diff --git a/app/src/test/java/foundation/e/apps/category/CategoryStringFormatterTest.kt b/app/src/test/java/foundation/e/apps/category/CategoryStringFormatterTest.kt
new file mode 100644
index 0000000000000000000000000000000000000000..f5ac42507c701ad57bf9b1abd1d1f46234fdd602
--- /dev/null
+++ b/app/src/test/java/foundation/e/apps/category/CategoryStringFormatterTest.kt
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2024 MURENA SAS
+ *
+ * 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.category
+
+import foundation.e.apps.data.application.utils.CategoryStringFormatter
+import org.junit.Assert.assertEquals
+import org.junit.Test
+
+class CategoryStringFormatterTest {
+
+ @Test
+ fun testFormatString_withUnderscores() {
+ val input = "health_and_fitness"
+ val expected = "Health and Fitness"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withSpaces() {
+ val input = "health and fitness"
+ val expected = "Health and Fitness"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withAllWordsCapitalized() {
+ val input = "Health And Fitness"
+ val expected = "Health and Fitness"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withLeadingAndTrailingUnderscores() {
+ val input = "_health_and_fitness_"
+ val expected = "Health and Fitness"
+ val result =
+ CategoryStringFormatter.format(input.trim('_')) // Trimming underscores for testing
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withNoUnderscores() {
+ val input = "health"
+ val expected = "Health"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withOnlyAnd() {
+ val input = "and"
+ val expected = "and"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withOnlyCapitalizedAnd() {
+ val input = "And"
+ val expected = "and"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_withEmptyString() {
+ val input = ""
+ val expected = ""
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+
+ @Test
+ fun testFormatString_unknown() {
+ val input = "unknown"
+ val expected = "Unknown"
+ val result = CategoryStringFormatter.format(input)
+ assertEquals(expected, result)
+ }
+}