aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-16 12:21:12 -0700
committerAllan Wang <me@allanwang.ca>2017-06-16 12:21:12 -0700
commit87e7e132a060e235d434a9ef44ae0363d7ef660b (patch)
treeba78c3240c6e4c0bf4ad43692f8625bc7f964a75 /app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
parentb9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff (diff)
downloadfrost-87e7e132a060e235d434a9ef44ae0363d7ef660b.tar.gz
frost-87e7e132a060e235d434a9ef44ae0363d7ef660b.tar.bz2
frost-87e7e132a060e235d434a9ef44ae0363d7ef660b.zip
Add url formatter
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 8dfceaad..0d99d67a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -12,6 +12,7 @@ import com.pitchedapps.frost.LoginActivity
import com.pitchedapps.frost.R
import com.pitchedapps.frost.WebOverlayActivity
import com.pitchedapps.frost.dbflow.CookieModel
+import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbTab
/**
@@ -30,10 +31,23 @@ fun Activity.cookies(): ArrayList<CookieModel> {
return intent?.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf()
}
+val String.formattedFbUrl: String
+ get() {
+ var url = this
+ if (url.startsWith("#!/")) url = url.substring(2)
+ if (url.startsWith('/')) url = FB_URL_BASE + url.substring(1)
+ url = url.replace("/#!/", "/")
+ val ref = url.indexOf("?ref")
+ if (ref != -1) url = url.substring(0, ref)
+ return url
+ }
+
fun Context.launchWebOverlay(url: String) {
+ val argUrl = url.formattedFbUrl
+ L.i("Launch web overlay: $argUrl")
val intent = Intent(this, WebOverlayActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
- intent.putExtra(ARG_URL, url)
+ intent.putExtra(ARG_URL, argUrl)
val bundle = ActivityOptionsCompat.makeCustomAnimation(this, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
ContextCompat.startActivity(this, intent, bundle)
}