aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/utils
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-02-23 16:36:31 -0800
committerAllan Wang <me@allanwang.ca>2020-02-23 16:36:31 -0800
commit0dfc1b3e6542b9deca6c56236b46e71e4c6976f5 (patch)
treed16e4c34b86b0cc236fce32baa38d71f3b7adfbf /app/src/main/kotlin/com/pitchedapps/frost/utils
parentcd69ccf7c49f486a6c90a7cee0d32a74ea00247d (diff)
downloadfrost-0dfc1b3e6542b9deca6c56236b46e71e4c6976f5.tar.gz
frost-0dfc1b3e6542b9deca6c56236b46e71e4c6976f5.tar.bz2
frost-0dfc1b3e6542b9deca6c56236b46e71e4c6976f5.zip
Remove singleton pattern for fbcookie
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt14
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt17
2 files changed, 15 insertions, 16 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 2bd9e6c1..854f315c 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -125,14 +125,14 @@ fun Activity.cookies(): ArrayList<CookieEntity> {
* Note that most requests may need to first check if the url can be launched as an overlay
* See [requestWebOverlay] to verify the launch
*/
-private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlayImpl(url: String) {
+private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlayImpl(url: String, fbCookie: FbCookie) {
val prefs = Prefs.get()
val argUrl = url.formattedFbUrl
L.v { "Launch received: $url\nLaunch web overlay: $argUrl" }
if (argUrl.isFacebookUrl && argUrl.contains("/logout.php")) {
L.d { "Logout php found" }
ctxCoroutine.launch {
- FbCookie.logout(this@launchWebOverlayImpl)
+ fbCookie.logout(this@launchWebOverlayImpl)
}
} else if (!(prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl)))) {
startActivity<T>(false, intentBuilder = {
@@ -141,13 +141,13 @@ private inline fun <reified T : WebOverlayActivityBase> Context.launchWebOverlay
}
}
-fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl<WebOverlayActivity>(url)
+fun Context.launchWebOverlay(url: String, fbCookie: FbCookie) = launchWebOverlayImpl<WebOverlayActivity>(url, fbCookie)
// TODO Currently, default is overlay. Switch this if default changes
-fun Context.launchWebOverlayDesktop(url: String) = launchWebOverlay(url)
+fun Context.launchWebOverlayDesktop(url: String, fbCookie: FbCookie) = launchWebOverlay(url, fbCookie)
-fun Context.launchWebOverlayMobile(url: String) =
- launchWebOverlayImpl<WebOverlayMobileActivity>(url)
+fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie) =
+ launchWebOverlayImpl<WebOverlayMobileActivity>(url, fbCookie)
private fun Context.fadeBundle() = ActivityOptions.makeCustomAnimation(
this,
@@ -409,8 +409,6 @@ fun EmailBuilder.addFrostDetails() {
addItem("Locale", Locale.getDefault().displayName)
}
-fun frostJsoup(url: String): Document = frostJsoup(FbCookie.webCookie, url)
-
fun frostJsoup(cookie: String?, url: String): Document =
Jsoup.connect(url).run {
if (cookie.isNullOrBlank()) this
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
index 61e2c11f..46c87c96 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/WebContextMenu.kt
@@ -25,12 +25,13 @@ import com.afollestad.materialdialogs.callbacks.onDismiss
import com.afollestad.materialdialogs.list.listItems
import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.MainActivity
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.formattedFbUrl
/**
* Created by Allan Wang on 2017-07-07.
*/
-fun Context.showWebContextMenu(wc: WebContext) {
+fun Context.showWebContextMenu(wc: WebContext, fbCookie: FbCookie) {
if (wc.isEmpty) return
var title = wc.url ?: string(R.string.menu)
title =
@@ -43,7 +44,7 @@ fun Context.showWebContextMenu(wc: WebContext) {
materialDialog {
title(text = title)
listItems(items = menuItems.map { string(it.textId) }) { _, position, _ ->
- menuItems[position].onClick(this@showWebContextMenu, wc)
+ menuItems[position].onClick(this@showWebContextMenu, wc, fbCookie)
}
onDismiss {
// showing the dialog interrupts the touch down event, so we must ensure that the viewpager's swipe is enabled
@@ -65,16 +66,16 @@ class WebContext(val unformattedUrl: String?, val text: String?) {
enum class WebContextType(
val textId: Int,
val constraint: (wc: WebContext) -> Boolean,
- val onClick: (c: Context, wc: WebContext) -> Unit
+ val onClick: (c: Context, wc: WebContext, fc: FbCookie) -> Unit
) {
OPEN_LINK(
R.string.open_link,
{ it.hasUrl },
- { c, wc -> c.launchWebOverlay(wc.url!!) }),
- COPY_LINK(R.string.copy_link, { it.hasUrl }, { c, wc -> c.copyToClipboard(wc.url) }),
- COPY_TEXT(R.string.copy_text, { it.hasText }, { c, wc -> c.copyToClipboard(wc.text) }),
- SHARE_LINK(R.string.share_link, { it.hasUrl }, { c, wc -> c.shareText(wc.url) }),
- DEBUG_LINK(R.string.debug_link, { it.hasUrl }, { c, wc ->
+ { c, wc , fc -> c.launchWebOverlay(wc.url!!, fc) }),
+ COPY_LINK(R.string.copy_link, { it.hasUrl }, { c, wc , fc-> c.copyToClipboard(wc.url) }),
+ COPY_TEXT(R.string.copy_text, { it.hasText }, { c, wc , fc-> c.copyToClipboard(wc.text) }),
+ SHARE_LINK(R.string.share_link, { it.hasUrl }, { c, wc, fc -> c.shareText(wc.url) }),
+ DEBUG_LINK(R.string.debug_link, { it.hasUrl }, { c, wc, fc ->
c.materialDialog {
title(R.string.debug_link)
message(R.string.debug_link_desc)