diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-08 03:03:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-08 03:03:55 -0400 |
commit | b10a745c7f0f46f4f014e1ba7fa71172d7442b83 (patch) | |
tree | ef2516b69fb04ec0f565c5bb569fd5d80b7bd262 /app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt | |
parent | 6adfc496374eb88919f70a240eb15a726d2c18e0 (diff) | |
download | frost-b10a745c7f0f46f4f014e1ba7fa71172d7442b83.tar.gz frost-b10a745c7f0f46f4f014e1ba7fa71172d7442b83.tar.bz2 frost-b10a745c7f0f46f4f014e1ba7fa71172d7442b83.zip |
Dev-1.1.7 (#39) - feature overload + context menuv1.2
* Address some crashlytics issues
* Add text scaling
* Kau fixes and cleanup
* WIP formatter
* Create in house url formatter
* Update context menu
* Update themes
* Test proguard without R
* Implement sharing and clean up context menu
* Disable viewpager swipe on long press
* Test keeping lib strings
* Update changelog and proguard
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 | 76 |
1 files changed, 76 insertions, 0 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 new file mode 100644 index 00000000..1090f1f3 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbUrlFormatter.kt @@ -0,0 +1,76 @@ +package com.pitchedapps.frost.facebook + +/** + * Created by Allan Wang on 2017-07-07. + * + * Custom url builder so we can easily test it without the Android framework + */ +val String.formattedFbUrl: String + get() = FbUrlFormatter(this).toString() + +class FbUrlFormatter(url: String) { + val queries = mutableMapOf<String, String>() + val cleaned: String + + init { + var cleanedUrl = url + discardable.forEach { cleanedUrl = cleanedUrl.replace(it, "") } + decoder.forEach { (k, v) -> cleanedUrl = cleanedUrl.replace(k, v) } + val qm = cleanedUrl.indexOf("?") + if (qm > -1) { + cleanedUrl.substring(qm + 1).split("&").forEach { + val p = it.split("=") + queries.put(p[0], p.elementAtOrNull(1) ?: "") + } + cleanedUrl = cleanedUrl.substring(0, qm) + } + discardableQueries.forEach { queries.remove(it) } + if (cleanedUrl.startsWith("#!/")) cleanedUrl = cleanedUrl.substring(2) + if (cleanedUrl.startsWith("/")) cleanedUrl = FB_URL_BASE + cleanedUrl.substring(1) + cleaned = cleanedUrl + } + + override fun toString(): String { + val builder = StringBuilder() + builder.append(cleaned) + if (queries.isNotEmpty()) { + builder.append("?") + queries.forEach { (k, v) -> builder.append("$k=$v&") } + } + return builder.removeSuffix("&").toString() + } + + fun toLogList(): List<String> { + val list = mutableListOf(cleaned) + queries.forEach { (k, v) -> list.add("- $k\t=\t$v") } + return list + } + + companion object { + /** + * Items here are explicitly removed from the url + * Taken from FaceSlim + * https://github.com/indywidualny/FaceSlim/blob/master/app/src/main/java/org/indywidualni/fblite/util/Miscellany.java + */ + @JvmStatic val discardable = arrayOf( + "http://lm.facebook.com/l.php?u=", + "https://lm.facebook.com/l.php?u=", + "http://m.facebook.com/l.php?u=", + "https://m.facebook.com/l.php?u=", + "http://touch.facebook.com/l.php?u=", + "https://touch.facebook.com/l.php?u=" + ) + + @JvmStatic val discardableQueries = arrayOf("ref", "refid") + + @JvmStatic val decoder = mapOf( + "%3C" to "<", "%3E" to ">", "%23" to "#", "%25" to "%", + "%7B" to "{", "%7D" to "}", "%7C" to "|", "%5C" to "\\", + "%5E" to "^", "%7E" to "~", "%5B" to "[", "%5D" to "]", + "%60" to "`", "%3B" to ";", "%2F" to "/", "%3F" to "?", + "%3A" to ":", "%40" to "@", "%3D" to "=", "%26" to "&", + "%24" to "$", "%2B" to "+", "%22" to "\"", "%2C" to ",", + "%20" to " " + ) + } +}
\ No newline at end of file |