diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt index 6208f401..16cbc9c8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -16,6 +16,7 @@ */ package com.pitchedapps.frost.facebook +import android.net.Uri import com.pitchedapps.frost.utils.L import java.net.URLDecoder import java.nio.charset.StandardCharsets @@ -28,6 +29,12 @@ import java.nio.charset.StandardCharsets inline val String.formattedFbUrl: String get() = FbUrlFormatter(this).toString() +inline val Uri.formattedFbUri: Uri + get() { + val url = toString() + return if (url.startsWith("http")) Uri.parse(url.formattedFbUrl) else this + } + class FbUrlFormatter(url: String) { private val queries = mutableMapOf<String, String>() private val cleaned: String @@ -72,7 +79,10 @@ class FbUrlFormatter(url: String) { } discardableQueries.forEach { queries.remove(it) } if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1) - cleanedUrl = cleanedUrl.replaceFirst(".facebook.com//", ".facebook.com/") //sometimes we are given a bad url + cleanedUrl = cleanedUrl.replaceFirst( + ".facebook.com//", + ".facebook.com/" + ) //sometimes we are given a bad url L.v { "Formatted url from $url to $cleanedUrl" } return cleanedUrl } |