From 0dfc1b3e6542b9deca6c56236b46e71e4c6976f5 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 23 Feb 2020 16:36:31 -0800 Subject: Remove singleton pattern for fbcookie --- .../main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 14 ++++++-------- .../com/pitchedapps/frost/utils/WebContextMenu.kt | 17 +++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils') 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 { * 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 Context.launchWebOverlayImpl(url: String) { +private inline fun 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(false, intentBuilder = { @@ -141,13 +141,13 @@ private inline fun Context.launchWebOverlay } } -fun Context.launchWebOverlay(url: String) = launchWebOverlayImpl(url) +fun Context.launchWebOverlay(url: String, fbCookie: FbCookie) = launchWebOverlayImpl(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(url) +fun Context.launchWebOverlayMobile(url: String, fbCookie: FbCookie) = + launchWebOverlayImpl(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) -- cgit v1.2.3