From fd2cbf25f5744a939ef6245809a1655e013a6420 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 10 Jan 2021 22:29:01 -0800 Subject: Start converting pref colors into themeProvider colors --- .../pitchedapps/frost/injectors/CssAssetsTest.kt | 32 ---------------------- .../frost/injectors/ThemeProviderTest.kt | 32 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/injectors/CssAssetsTest.kt create mode 100644 app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt (limited to 'app/src/test/kotlin/com') diff --git a/app/src/test/kotlin/com/pitchedapps/frost/injectors/CssAssetsTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/injectors/CssAssetsTest.kt deleted file mode 100644 index 8894e5b6..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/injectors/CssAssetsTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2019 Allan Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.pitchedapps.frost.injectors - -import java.io.File -import kotlin.test.Test -import kotlin.test.assertTrue - -class CssAssetsTest { - - @Test - fun verifyAssetsExist() { - CssAssets.values().forEach { asset -> - val file = File("src/web/assets/css/${asset.folder}/${asset.file}").absoluteFile - assertTrue(file.exists(), "${asset.name} not found at ${file.path}") - } - } -} diff --git a/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt new file mode 100644 index 00000000..f59980d2 --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2019 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.pitchedapps.frost.injectors + +import java.io.File +import kotlin.test.Test +import kotlin.test.assertTrue + +class ThemeProviderTest { + + @Test + fun verifyAssetsExist() { + ThemeProvider.values().forEach { asset -> + val file = File("src/web/assets/css/${asset.folder}/${asset.file}").absoluteFile + assertTrue(file.exists(), "${asset.name} not found at ${file.path}") + } + } +} -- cgit v1.2.3 From 8fe2427cff223a509441545227ac58b215903929 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Wed, 13 Jan 2021 00:32:09 -0800 Subject: Fix theme provider test --- .../com/pitchedapps/frost/injectors/ThemeProviderTest.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'app/src/test/kotlin/com') diff --git a/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt index f59980d2..e1ef6225 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/injectors/ThemeProviderTest.kt @@ -16,6 +16,8 @@ */ package com.pitchedapps.frost.injectors +import com.pitchedapps.frost.enums.Theme +import com.pitchedapps.frost.enums.ThemeCategory import java.io.File import kotlin.test.Test import kotlin.test.assertTrue @@ -24,9 +26,11 @@ class ThemeProviderTest { @Test fun verifyAssetsExist() { - ThemeProvider.values().forEach { asset -> - val file = File("src/web/assets/css/${asset.folder}/${asset.file}").absoluteFile - assertTrue(file.exists(), "${asset.name} not found at ${file.path}") + ThemeCategory.values().forEach { category -> + Theme.values.filter { it != Theme.DEFAULT }.forEach { theme -> + val file = File("src/web/assets/css/${category.folder}/themes/${theme.file}").absoluteFile + assertTrue(file.exists(), "${theme.name} not found at ${file.path}") + } } } } -- cgit v1.2.3 From 58068ce55e9e203a77c67dfee78fb2658e3bb6aa Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 24 Jan 2021 19:10:09 -0800 Subject: Create messenger client with cookie checking --- .../kotlin/com/pitchedapps/frost/db/CookiesDb.kt | 3 +- .../com/pitchedapps/frost/facebook/FbConst.kt | 1 + .../com/pitchedapps/frost/facebook/FbCookie.kt | 4 -- .../pitchedapps/frost/fragments/WebFragments.kt | 2 + .../kotlin/com/pitchedapps/frost/utils/Utils.kt | 20 ++++---- .../pitchedapps/frost/views/FrostVideoViewer.kt | 2 +- .../com/pitchedapps/frost/views/FrostWebView.kt | 2 +- .../kotlin/com/pitchedapps/frost/web/FrostJSI.kt | 2 +- .../pitchedapps/frost/web/FrostWebViewClients.kt | 55 +++++++++++++++++++--- .../com/pitchedapps/frost/facebook/FbConstTest.kt | 37 +++++++++++++++ 10 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt (limited to 'app/src/test/kotlin/com') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt index 163d151b..8c2e32a7 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/db/CookiesDb.kt @@ -44,7 +44,8 @@ data class CookieEntity( ) : Parcelable { override fun toString(): String = "CookieEntity(${hashCode()})" - fun toSensitiveString(): String = "CookieEntity(id=$id, name=$name, cookie=$cookie)" + fun toSensitiveString(): String = + "CookieEntity(id=$id, name=$name, cookie=$cookie cookieMessenger=$cookieMessenger)" } @Dao diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt index fc4e3fae..b0846864 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt @@ -34,6 +34,7 @@ const val FB_URL_MBASIC_BASE = "https://$FACEBOOK_MBASIC_COM/" fun profilePictureUrl(id: Long) = "https://graph.facebook.com/$id/picture?type=large" const val FB_LOGIN_URL = "${FB_URL_BASE}login" const val FB_HOME_URL = "${FB_URL_BASE}home.php" +const val MESSENGER_THREAD_PREFIX = "$HTTPS_MESSENGER_COM/t/" /* * User agent candidates. diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index b02ec941..4e932d09 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -24,7 +24,6 @@ import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.db.deleteById import com.pitchedapps.frost.db.save import com.pitchedapps.frost.db.selectById -import com.pitchedapps.frost.db.updateMessengerCookie import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.cookies @@ -121,11 +120,8 @@ class FbCookie(private val prefs: Prefs, private val cookieDao: CookieDao) { L.d { "Switching User; null cookie" } return } - val currentId = prefs.userId withContext(Dispatchers.Main + NonCancellable) { L.d { "Switching User" } - // Save current messenger cookie state. - cookieDao.updateMessengerCookie(currentId, messengerCookie) prefs.userId = cookie.id CookieManager.getInstance().apply { removeAllCookies() diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt index 502c37fb..3cac92af 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt @@ -26,6 +26,7 @@ import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.views.FrostWebView import com.pitchedapps.frost.web.FrostWebViewClient import com.pitchedapps.frost.web.FrostWebViewClientMenu +import com.pitchedapps.frost.web.FrostWebViewClientMessenger /** * Created by Allan Wang on 27/12/17. @@ -41,6 +42,7 @@ class WebFragment : BaseFragment() { * Given a webview, output a client */ fun client(web: FrostWebView) = when (baseEnum) { + FbItem.MESSENGER -> FrostWebViewClientMessenger(web) FbItem.MENU -> FrostWebViewClientMenu(web) else -> FrostWebViewClient(web) } 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 2d3a10c8..13ce2920 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -35,6 +35,7 @@ import ca.allanwang.kau.email.sendEmail import ca.allanwang.kau.mediapicker.createMediaFile import ca.allanwang.kau.mediapicker.createPrivateMediaFile import ca.allanwang.kau.utils.colorToForeground +import ca.allanwang.kau.utils.ctxCoroutine import ca.allanwang.kau.utils.darken import ca.allanwang.kau.utils.isColorDark import ca.allanwang.kau.utils.navigationBarColor @@ -77,8 +78,6 @@ import java.net.URLEncoder import java.nio.charset.StandardCharsets import java.util.ArrayList import java.util.Locale -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import org.apache.commons.text.StringEscapeUtils @@ -98,14 +97,6 @@ const val ARG_IMAGE_URL = "arg_image_url" const val ARG_TEXT = "arg_text" const val ARG_COOKIE = "arg_cookie" -/** - * Most context items implement [CoroutineScope] by default. - * We will add a fallback just in case. - * It is expected that the scope returned always has the Android main dispatcher as part of the context. - */ -internal inline val Context.ctxCoroutine: CoroutineScope - get() = this as? CoroutineScope ?: GlobalScope - inline fun Context.launchNewTask( cookieList: ArrayList = arrayListOf(), clearStack: Boolean = false @@ -186,7 +177,9 @@ fun WebOverlayActivity.url(): String { fun Activity.setFrostTheme(themeProvider: ThemeProvider, forceTransparent: Boolean = false) { val isTransparent = - forceTransparent || (Color.alpha(themeProvider.bgColor) != 255) || (Color.alpha(themeProvider.headerColor) != 255) + forceTransparent || (Color.alpha(themeProvider.bgColor) != 255) || (Color.alpha( + themeProvider.headerColor + ) != 255) if (themeProvider.bgColor.isColorDark) { setTheme(if (isTransparent) R.style.FrostTheme_Transparent else R.style.FrostTheme) } else { @@ -313,7 +306,10 @@ inline val String?.isFacebookUrl get() = this != null && (contains(FACEBOOK_COM) || contains(FBCDN_NET)) inline val String?.isMessengerUrl -get() = this != null && contains(MESSENGER_COM) + get() = this != null && contains(MESSENGER_COM) + +inline val String?.isFbCookie + get() = this != null && contains("c_user") /** * [true] if url is a video and can be accepted by VideoViewer diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt index 169e7f73..a76aeea0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostVideoViewer.kt @@ -25,6 +25,7 @@ import android.view.LayoutInflater import android.view.MotionEvent import android.view.ViewTreeObserver import android.widget.FrameLayout +import ca.allanwang.kau.utils.ctxCoroutine import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.fadeOut import ca.allanwang.kau.utils.gone @@ -46,7 +47,6 @@ import com.pitchedapps.frost.db.currentCookie import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.ctxCoroutine import com.pitchedapps.frost.utils.frostDownload import org.koin.core.component.KoinComponent import org.koin.core.component.inject diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index e4752d1b..ecd8c093 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -24,6 +24,7 @@ import android.util.AttributeSet import android.view.View import android.view.ViewGroup import ca.allanwang.kau.utils.AnimHolder +import ca.allanwang.kau.utils.ctxCoroutine import ca.allanwang.kau.utils.launchMain import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore @@ -37,7 +38,6 @@ import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.ctxCoroutine import com.pitchedapps.frost.utils.frostDownload import com.pitchedapps.frost.web.FrostChromeClient import com.pitchedapps.frost.web.FrostJSI diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt index 4e8e8cee..12e10e10 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -18,6 +18,7 @@ package com.pitchedapps.frost.web import android.content.Context import android.webkit.JavascriptInterface +import ca.allanwang.kau.utils.ctxCoroutine import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.WebOverlayActivityBase import com.pitchedapps.frost.contracts.MainActivityContract @@ -28,7 +29,6 @@ import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.WebContext import com.pitchedapps.frost.utils.cookies -import com.pitchedapps.frost.utils.ctxCoroutine import com.pitchedapps.frost.utils.isIndependent import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.showWebContextMenu diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 8ec5f975..1495b2e0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -22,11 +22,17 @@ import android.webkit.WebResourceRequest import android.webkit.WebResourceResponse import android.webkit.WebView import android.webkit.WebViewClient +import ca.allanwang.kau.utils.ctxCoroutine import ca.allanwang.kau.utils.withAlpha +import com.pitchedapps.frost.db.CookieDao +import com.pitchedapps.frost.db.currentCookie +import com.pitchedapps.frost.db.updateMessengerCookie import com.pitchedapps.frost.enums.ThemeCategory import com.pitchedapps.frost.facebook.FACEBOOK_BASE_COM import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.facebook.HTTPS_MESSENGER_COM +import com.pitchedapps.frost.facebook.MESSENGER_THREAD_PREFIX import com.pitchedapps.frost.facebook.WWW_FACEBOOK_COM import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.injectors.CssAsset @@ -39,6 +45,7 @@ import com.pitchedapps.frost.prefs.Prefs import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.isExplicitIntent import com.pitchedapps.frost.utils.isFacebookUrl +import com.pitchedapps.frost.utils.isFbCookie import com.pitchedapps.frost.utils.isImageUrl import com.pitchedapps.frost.utils.isIndirectImageUrl import com.pitchedapps.frost.utils.isMessengerUrl @@ -46,6 +53,7 @@ import com.pitchedapps.frost.utils.launchImageActivity import com.pitchedapps.frost.utils.resolveActivityForUri import com.pitchedapps.frost.views.FrostWebView import kotlinx.coroutines.channels.SendChannel +import kotlinx.coroutines.launch /** * Created by Allan Wang on 2017-05-31. @@ -71,11 +79,11 @@ open class BaseWebViewClient : WebViewClient() { */ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { - private val fbCookie: FbCookie get() = web.fbCookie - private val prefs: Prefs get() = web.prefs - private val themeProvider: ThemeProvider get() = web.themeProvider - private val refresh: SendChannel = web.parent.refreshChannel - private val isMain = web.parent.baseEnum != null + protected val fbCookie: FbCookie get() = web.fbCookie + protected val prefs: Prefs get() = web.prefs + protected val themeProvider: ThemeProvider get() = web.themeProvider + protected val refresh: SendChannel = web.parent.refreshChannel + protected val isMain = web.parent.baseEnum != null /** * True if current url supports refresh. See [doUpdateVisitedHistory] for updates @@ -279,8 +287,6 @@ private const val EMIT_FINISH = 0 */ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { - private val prefs: Prefs get() = web.prefs - override fun onPageFinished(view: WebView, url: String?) { super.onPageFinished(view, url) if (url == null) { @@ -302,3 +308,38 @@ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { // Skip } } + +class FrostWebViewClientMessenger(web: FrostWebView) : FrostWebViewClient(web) { + + override fun onPageFinished(view: WebView, url: String?) { + super.onPageFinished(view, url) + messengerCookieCheck(url!!) + } + + private val cookieDao: CookieDao get() = web.cookieDao + private var hasCookie = fbCookie.messengerCookie.isFbCookie + + /** + * Check cookie changes. Unlike fb checks, we will continuously poll for cookie changes during loading. + * There is no lifecycle association between messenger login and facebook login, + * so we'll try to be smart about when to check for state changes. + * + * From testing, it looks like this is called after redirects. + * We can therefore classify no login as pointing to messenger.com, + * and login as pointing to messenger.com/t/[thread id] + */ + private fun messengerCookieCheck(url: String?) { + if (url?.startsWith(HTTPS_MESSENGER_COM) != true) return + val shouldHaveCookie = url.startsWith(MESSENGER_THREAD_PREFIX) + L._d { "Messenger client: $url $shouldHaveCookie" } + if (shouldHaveCookie == hasCookie) return + hasCookie = shouldHaveCookie + web.context.ctxCoroutine.launch { + cookieDao.updateMessengerCookie( + prefs.userId, + if (shouldHaveCookie) fbCookie.messengerCookie else null + ) + L._d { "New cookie ${cookieDao.currentCookie(prefs)?.toSensitiveString()}" } + } + } +} diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt new file mode 100644 index 00000000..8a8c42d6 --- /dev/null +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt @@ -0,0 +1,37 @@ +package com.pitchedapps.frost.facebook + +import kotlin.test.Test +import kotlin.test.assertFalse + +class FbConstTest { + + private val constants = listOf( + FACEBOOK_COM, + MESSENGER_COM, + FBCDN_NET, + WWW_FACEBOOK_COM, + WWW_MESSENGER_COM, + HTTPS_FACEBOOK_COM, + HTTPS_MESSENGER_COM, + FACEBOOK_BASE_COM, + FB_URL_BASE, + FACEBOOK_MBASIC_COM, + FB_URL_MBASIC_BASE, + FB_LOGIN_URL, + FB_HOME_URL, + MESSENGER_THREAD_PREFIX + ) + + /** + * Make sure we don't have accidental double forward slashes after appending + */ + @Test + fun doubleForwardSlashTest() { + constants.forEach { + assertFalse( + it.replace("https://", "").contains("//"), + "Accidental forward slash for $it" + ) + } + } +} \ No newline at end of file -- cgit v1.2.3 From 4c2c8a9ce4872e8bbb2a55c8b527e4f7b22ef633 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 24 Jan 2021 19:52:51 -0800 Subject: Add option to log out for messenger --- .../frost/activities/BaseMainActivity.kt | 11 ++++++- .../frost/contracts/FrostContentContract.kt | 37 ++++++++++++++++++++++ .../com/pitchedapps/frost/facebook/FbCookie.kt | 16 ++++++++++ .../pitchedapps/frost/fragments/FragmentBase.kt | 2 ++ .../frost/fragments/FragmentContract.kt | 2 ++ .../pitchedapps/frost/views/FrostRecyclerView.kt | 9 ++++++ .../com/pitchedapps/frost/views/FrostWebView.kt | 5 +++ app/src/main/res/values/strings.xml | 2 ++ .../com/pitchedapps/frost/facebook/FbConstTest.kt | 18 ++++++++++- 9 files changed, 100 insertions(+), 2 deletions(-) (limited to 'app/src/test/kotlin/com') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index 394969cb..99c11b4d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -846,7 +846,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, .setCustomView(BadgedIcon(this@BaseMainActivity).apply { iicon = fbItem.icon }.also { - it.setAllAlpha(if (index == 0) SELECTED_TAB_ALPHA else UNSELECTED_TAB_ALPHA) + it.init(index, fbItem) }) ) } @@ -861,6 +861,15 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, } } + private fun BadgedIcon.init(index: Int, fbItem: FbItem) { + setAllAlpha(if (index == 0) SELECTED_TAB_ALPHA else UNSELECTED_TAB_ALPHA) + setOnLongClickListener { + if (index != contentBinding.viewpager.currentItem) return@setOnLongClickListener false + currentFragment?.onTabLongClick() + true + } + } + fun saveInstanceState(outState: Bundle) { outState.putStringArrayList(STATE_FORCE_FALLBACK, ArrayList(forcedFallbacks)) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt index b8d0d86f..a5d4e191 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt @@ -16,11 +16,19 @@ */ package com.pitchedapps.frost.contracts +import android.content.Context import android.view.View +import ca.allanwang.kau.utils.materialDialog +import com.pitchedapps.frost.R +import com.pitchedapps.frost.db.CookieDao +import com.pitchedapps.frost.db.updateMessengerCookie +import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.prefs.Prefs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.BroadcastChannel +import kotlinx.coroutines.launch /** * Created by Allan Wang on 20/12/17. @@ -171,8 +179,37 @@ interface FrostContentCore : DynamicUiContract { */ fun onTabClicked() + /** + * Triggered when view is within viewpager + * and tab is long clicked + */ + fun onTabLongClicked() + /** * Signal destruction to release some content manually */ fun destroy() } + +internal fun FrostContentCore.onTabLongClicked( + context: Context, + prefs: Prefs, + fbCookie: FbCookie, + cookieDao: CookieDao +) { + when (parent.baseEnum) { + FbItem.MESSENGER -> { + context.materialDialog { + message(R.string.messenger_logout) + positiveButton(R.string.kau_logout) { + scope.launch { + fbCookie.removeMessengerCookie() + cookieDao.updateMessengerCookie(prefs.userId, null) + reloadBase(true) + } + } + negativeButton(R.string.kau_cancel) + } + } + } +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index 4e932d09..eb3580d4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -110,6 +110,22 @@ class FbCookie(private val prefs: Prefs, private val cookieDao: CookieDao) { } } + /** + * As far as I'm aware there is no way to remove a specific cookie. + * As we only care about fb and messenger cookies, this is a workaround + * in which we remove all cookies then add back the fb one. + */ + suspend fun removeMessengerCookie() { + withContext(Dispatchers.Main + NonCancellable) { + val fbCookie = webCookie + with(CookieManager.getInstance()) { + removeAllCookies() + suspendSetWebCookie(FB_COOKIE_DOMAIN, fbCookie) + flush() + } + } + } + suspend fun switchUser(id: Long) { val cookie = cookieDao.selectById(id) ?: return L.e { "No cookie for id" } switchUser(cookie) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index c07884bc..e91069c8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -251,4 +251,6 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, override fun onBackPressed(): Boolean = content?.core?.onBackPressed() ?: false override fun onTabClick(): Unit = content?.core?.onTabClicked() ?: Unit + + override fun onTabLongClick(): Unit = content?.core?.onTabLongClicked() ?: Unit } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt index 10c612c5..3cd06bc9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt @@ -96,6 +96,8 @@ interface FragmentContract : FrostContentContainer { fun onBackPressed(): Boolean fun onTabClick() + + fun onTabLongClick() } interface RecyclerContentContract { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt index 89009b56..f4f0fe11 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt @@ -26,6 +26,9 @@ import ca.allanwang.kau.utils.fadeOut import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent +import com.pitchedapps.frost.contracts.onTabLongClicked +import com.pitchedapps.frost.db.CookieDao +import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.fragments.RecyclerContentContract import com.pitchedapps.frost.prefs.Prefs import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -47,6 +50,8 @@ class FrostRecyclerView @JvmOverloads constructor( FrostContentCore { private val prefs: Prefs by inject() + private val fbCookie: FbCookie by inject() + private val cookieDao: CookieDao by inject() override fun reload(animate: Boolean) = reloadBase(animate) @@ -107,6 +112,10 @@ class FrostRecyclerView @JvmOverloads constructor( else scrollToTop() } + override fun onTabLongClicked() { + onTabLongClicked(context, prefs, fbCookie, cookieDao) + } + private fun scrollToTop() { stopScroll() smoothScrollToPosition(0) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index ecd8c093..887d17f0 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -29,6 +29,7 @@ import ca.allanwang.kau.utils.launchMain import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent +import com.pitchedapps.frost.contracts.onTabLongClicked import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.currentCookie import com.pitchedapps.frost.facebook.FB_HOME_URL @@ -196,6 +197,10 @@ class FrostWebView @JvmOverloads constructor( private fun smoothScrollBy(y: Int) = smoothScrollTo(max(0, scrollY + y)) + override fun onTabLongClicked() { + onTabLongClicked(context, prefs, fbCookie, cookieDao) + } + override var active: Boolean = true set(value) { if (field == value) return diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 860895e5..53b291a2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,4 +79,6 @@ Disclaimer + Log out of Messenger? + diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt index 8a8c42d6..83bce973 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2021 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.pitchedapps.frost.facebook import kotlin.test.Test @@ -34,4 +50,4 @@ class FbConstTest { ) } } -} \ No newline at end of file +} -- cgit v1.2.3 From 2c85dae785b67241ef72500ac3c43fdff86bbad0 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 24 Jan 2021 20:02:12 -0800 Subject: Revert "Add option to log out for messenger" This reverts commit 4c2c8a9ce4872e8bbb2a55c8b527e4f7b22ef633. --- .../frost/activities/BaseMainActivity.kt | 11 +------ .../frost/contracts/FrostContentContract.kt | 37 ---------------------- .../com/pitchedapps/frost/facebook/FbCookie.kt | 16 ---------- .../pitchedapps/frost/fragments/FragmentBase.kt | 2 -- .../frost/fragments/FragmentContract.kt | 2 -- .../pitchedapps/frost/views/FrostRecyclerView.kt | 9 ------ .../com/pitchedapps/frost/views/FrostWebView.kt | 5 --- app/src/main/res/values/strings.xml | 2 -- .../com/pitchedapps/frost/facebook/FbConstTest.kt | 18 +---------- 9 files changed, 2 insertions(+), 100 deletions(-) (limited to 'app/src/test/kotlin/com') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index 99c11b4d..394969cb 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -846,7 +846,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, .setCustomView(BadgedIcon(this@BaseMainActivity).apply { iicon = fbItem.icon }.also { - it.init(index, fbItem) + it.setAllAlpha(if (index == 0) SELECTED_TAB_ALPHA else UNSELECTED_TAB_ALPHA) }) ) } @@ -861,15 +861,6 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, } } - private fun BadgedIcon.init(index: Int, fbItem: FbItem) { - setAllAlpha(if (index == 0) SELECTED_TAB_ALPHA else UNSELECTED_TAB_ALPHA) - setOnLongClickListener { - if (index != contentBinding.viewpager.currentItem) return@setOnLongClickListener false - currentFragment?.onTabLongClick() - true - } - } - fun saveInstanceState(outState: Bundle) { outState.putStringArrayList(STATE_FORCE_FALLBACK, ArrayList(forcedFallbacks)) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt index a5d4e191..b8d0d86f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt @@ -16,19 +16,11 @@ */ package com.pitchedapps.frost.contracts -import android.content.Context import android.view.View -import ca.allanwang.kau.utils.materialDialog -import com.pitchedapps.frost.R -import com.pitchedapps.frost.db.CookieDao -import com.pitchedapps.frost.db.updateMessengerCookie -import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem -import com.pitchedapps.frost.prefs.Prefs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.channels.BroadcastChannel -import kotlinx.coroutines.launch /** * Created by Allan Wang on 20/12/17. @@ -179,37 +171,8 @@ interface FrostContentCore : DynamicUiContract { */ fun onTabClicked() - /** - * Triggered when view is within viewpager - * and tab is long clicked - */ - fun onTabLongClicked() - /** * Signal destruction to release some content manually */ fun destroy() } - -internal fun FrostContentCore.onTabLongClicked( - context: Context, - prefs: Prefs, - fbCookie: FbCookie, - cookieDao: CookieDao -) { - when (parent.baseEnum) { - FbItem.MESSENGER -> { - context.materialDialog { - message(R.string.messenger_logout) - positiveButton(R.string.kau_logout) { - scope.launch { - fbCookie.removeMessengerCookie() - cookieDao.updateMessengerCookie(prefs.userId, null) - reloadBase(true) - } - } - negativeButton(R.string.kau_cancel) - } - } - } -} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index eb3580d4..4e932d09 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -110,22 +110,6 @@ class FbCookie(private val prefs: Prefs, private val cookieDao: CookieDao) { } } - /** - * As far as I'm aware there is no way to remove a specific cookie. - * As we only care about fb and messenger cookies, this is a workaround - * in which we remove all cookies then add back the fb one. - */ - suspend fun removeMessengerCookie() { - withContext(Dispatchers.Main + NonCancellable) { - val fbCookie = webCookie - with(CookieManager.getInstance()) { - removeAllCookies() - suspendSetWebCookie(FB_COOKIE_DOMAIN, fbCookie) - flush() - } - } - } - suspend fun switchUser(id: Long) { val cookie = cookieDao.selectById(id) ?: return L.e { "No cookie for id" } switchUser(cookie) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index e91069c8..c07884bc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -251,6 +251,4 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, override fun onBackPressed(): Boolean = content?.core?.onBackPressed() ?: false override fun onTabClick(): Unit = content?.core?.onTabClicked() ?: Unit - - override fun onTabLongClick(): Unit = content?.core?.onTabLongClicked() ?: Unit } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt index 3cd06bc9..10c612c5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt @@ -96,8 +96,6 @@ interface FragmentContract : FrostContentContainer { fun onBackPressed(): Boolean fun onTabClick() - - fun onTabLongClick() } interface RecyclerContentContract { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt index f4f0fe11..89009b56 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostRecyclerView.kt @@ -26,9 +26,6 @@ import ca.allanwang.kau.utils.fadeOut import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent -import com.pitchedapps.frost.contracts.onTabLongClicked -import com.pitchedapps.frost.db.CookieDao -import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.fragments.RecyclerContentContract import com.pitchedapps.frost.prefs.Prefs import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -50,8 +47,6 @@ class FrostRecyclerView @JvmOverloads constructor( FrostContentCore { private val prefs: Prefs by inject() - private val fbCookie: FbCookie by inject() - private val cookieDao: CookieDao by inject() override fun reload(animate: Boolean) = reloadBase(animate) @@ -112,10 +107,6 @@ class FrostRecyclerView @JvmOverloads constructor( else scrollToTop() } - override fun onTabLongClicked() { - onTabLongClicked(context, prefs, fbCookie, cookieDao) - } - private fun scrollToTop() { stopScroll() smoothScrollToPosition(0) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt index 887d17f0..ecd8c093 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt @@ -29,7 +29,6 @@ import ca.allanwang.kau.utils.launchMain import com.pitchedapps.frost.contracts.FrostContentContainer import com.pitchedapps.frost.contracts.FrostContentCore import com.pitchedapps.frost.contracts.FrostContentParent -import com.pitchedapps.frost.contracts.onTabLongClicked import com.pitchedapps.frost.db.CookieDao import com.pitchedapps.frost.db.currentCookie import com.pitchedapps.frost.facebook.FB_HOME_URL @@ -197,10 +196,6 @@ class FrostWebView @JvmOverloads constructor( private fun smoothScrollBy(y: Int) = smoothScrollTo(max(0, scrollY + y)) - override fun onTabLongClicked() { - onTabLongClicked(context, prefs, fbCookie, cookieDao) - } - override var active: Boolean = true set(value) { if (field == value) return diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 53b291a2..860895e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -79,6 +79,4 @@ Disclaimer - Log out of Messenger? - diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt index 83bce973..8a8c42d6 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt @@ -1,19 +1,3 @@ -/* - * Copyright 2021 Allan Wang - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ package com.pitchedapps.frost.facebook import kotlin.test.Test @@ -50,4 +34,4 @@ class FbConstTest { ) } } -} +} \ No newline at end of file -- cgit v1.2.3 From 53392bc41b7315896f520cdc9d3d59cc4f0fcabc Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 24 Jan 2021 20:03:49 -0800 Subject: Disable kotlin android extensions --- app/build.gradle | 7 +------ .../com/pitchedapps/frost/facebook/FbConstTest.kt | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'app/src/test/kotlin/com') diff --git a/app/build.gradle b/app/build.gradle index 2a0f7768..24fdd28e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' //apply plugin: 'com.getkeepsafe.dexcount' apply plugin: 'com.gladed.androidgitversion' @@ -204,11 +204,6 @@ android { } } - androidExtensions { - experimental = true - features = ["parcelize"] - } - } node { diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt index 8a8c42d6..83bce973 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbConstTest.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2021 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.pitchedapps.frost.facebook import kotlin.test.Test @@ -34,4 +50,4 @@ class FbConstTest { ) } } -} \ No newline at end of file +} -- cgit v1.2.3