From 5aec10ce0fe191d78399869074c7e118256848ea Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 12 Jan 2021 23:07:02 -0800 Subject: Fix swipe disable logic and disable for messenger --- .../com/pitchedapps/frost/contracts/FrostContentContract.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt') 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 8a6e57af..b8d0d86f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt @@ -73,11 +73,17 @@ interface FrostContentParent : DynamicUiContract { var baseEnum: FbItem? + val swipeEnabled: Boolean get() = swipeAllowedByPage && !swipeDisabledByAction + + /** + * Temporary disable swiping based on action + */ + var swipeDisabledByAction: Boolean + /** - * Toggle state for allowing swipes - * Allowed on any thread + * Decides if swipe should be allowed for the current page */ - var swipeEnabled: Boolean + var swipeAllowedByPage: Boolean /** * Binds the container to self -- 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/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt') 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/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt') 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