Skip to content

A fully functional Android app built entirely with Kotlin and Jetpack Compose

Extract `UTF-8` character encoding

Simon Marquis0418997f5a04
diff --git a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt
index b012b12b1..c29b57d47 100644
--- a/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt
+++ b/feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt
@@ -26,17 +26,20 @@ import androidx.navigation.navArgument
import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute
import java.net.URLDecoder
import java.net.URLEncoder
+import kotlin.text.Charsets.UTF_8
+
+private val URL_CHARACTER_ENCODING = UTF_8.name()
@VisibleForTesting
internal const val topicIdArg = "topicId"
internal class TopicArgs(val topicId: String) {
constructor(savedStateHandle: SavedStateHandle) :
- this(URLDecoder.decode(checkNotNull(savedStateHandle[topicIdArg]), "UTF-8"))
+ this(URLDecoder.decode(checkNotNull(savedStateHandle[topicIdArg]), URL_CHARACTER_ENCODING))
}
fun NavController.navigateToTopic(topicId: String) {
- val encodedId = URLEncoder.encode(topicId, "UTF-8")
+ val encodedId = URLEncoder.encode(topicId, URL_CHARACTER_ENCODING)
this.navigate("topic_route/$encodedId") {
launchSingleTop = true
}