Skip to content

Commit 0418997

Browse files
committed
Extract UTF-8 character encoding
1 parent e844911 commit 0418997

File tree

1 file changed

+5
-2
lines changed
  • feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation

1 file changed

+5
-2
lines changed

feature/topic/src/main/java/com/google/samples/apps/nowinandroid/feature/topic/navigation/TopicNavigation.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ import androidx.navigation.navArgument
2626
import com.google.samples.apps.nowinandroid.feature.topic.TopicRoute
2727
import java.net.URLDecoder
2828
import java.net.URLEncoder
29+
import kotlin.text.Charsets.UTF_8
30+
31+
private val URL_CHARACTER_ENCODING = UTF_8.name()
2932

3033
@VisibleForTesting
3134
internal const val topicIdArg = "topicId"
3235

3336
internal class TopicArgs(val topicId: String) {
3437
constructor(savedStateHandle: SavedStateHandle) :
35-
this(URLDecoder.decode(checkNotNull(savedStateHandle[topicIdArg]), "UTF-8"))
38+
this(URLDecoder.decode(checkNotNull(savedStateHandle[topicIdArg]), URL_CHARACTER_ENCODING))
3639
}
3740

3841
fun NavController.navigateToTopic(topicId: String) {
39-
val encodedId = URLEncoder.encode(topicId, "UTF-8")
42+
val encodedId = URLEncoder.encode(topicId, URL_CHARACTER_ENCODING)
4043
this.navigate("topic_route/$encodedId") {
4144
launchSingleTop = true
4245
}

0 commit comments

Comments
 (0)