mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-08 20:12:39 +01:00
Add option to log out for messenger
This commit is contained in:
parent
58068ce55e
commit
4c2c8a9ce4
@ -846,7 +846,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract,
|
|||||||
.setCustomView(BadgedIcon(this@BaseMainActivity).apply {
|
.setCustomView(BadgedIcon(this@BaseMainActivity).apply {
|
||||||
iicon = fbItem.icon
|
iicon = fbItem.icon
|
||||||
}.also {
|
}.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) {
|
fun saveInstanceState(outState: Bundle) {
|
||||||
outState.putStringArrayList(STATE_FORCE_FALLBACK, ArrayList(forcedFallbacks))
|
outState.putStringArrayList(STATE_FORCE_FALLBACK, ArrayList(forcedFallbacks))
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,19 @@
|
|||||||
*/
|
*/
|
||||||
package com.pitchedapps.frost.contracts
|
package com.pitchedapps.frost.contracts
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.View
|
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.facebook.FbItem
|
||||||
|
import com.pitchedapps.frost.prefs.Prefs
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Allan Wang on 20/12/17.
|
* Created by Allan Wang on 20/12/17.
|
||||||
@ -171,8 +179,37 @@ interface FrostContentCore : DynamicUiContract {
|
|||||||
*/
|
*/
|
||||||
fun onTabClicked()
|
fun onTabClicked()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggered when view is within viewpager
|
||||||
|
* and tab is long clicked
|
||||||
|
*/
|
||||||
|
fun onTabLongClicked()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signal destruction to release some content manually
|
* Signal destruction to release some content manually
|
||||||
*/
|
*/
|
||||||
fun destroy()
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -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) {
|
suspend fun switchUser(id: Long) {
|
||||||
val cookie = cookieDao.selectById(id) ?: return L.e { "No cookie for id" }
|
val cookie = cookieDao.selectById(id) ?: return L.e { "No cookie for id" }
|
||||||
switchUser(cookie)
|
switchUser(cookie)
|
||||||
|
@ -251,4 +251,6 @@ abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract,
|
|||||||
override fun onBackPressed(): Boolean = content?.core?.onBackPressed() ?: false
|
override fun onBackPressed(): Boolean = content?.core?.onBackPressed() ?: false
|
||||||
|
|
||||||
override fun onTabClick(): Unit = content?.core?.onTabClicked() ?: Unit
|
override fun onTabClick(): Unit = content?.core?.onTabClicked() ?: Unit
|
||||||
|
|
||||||
|
override fun onTabLongClick(): Unit = content?.core?.onTabLongClicked() ?: Unit
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,8 @@ interface FragmentContract : FrostContentContainer {
|
|||||||
fun onBackPressed(): Boolean
|
fun onBackPressed(): Boolean
|
||||||
|
|
||||||
fun onTabClick()
|
fun onTabClick()
|
||||||
|
|
||||||
|
fun onTabLongClick()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RecyclerContentContract {
|
interface RecyclerContentContract {
|
||||||
|
@ -26,6 +26,9 @@ import ca.allanwang.kau.utils.fadeOut
|
|||||||
import com.pitchedapps.frost.contracts.FrostContentContainer
|
import com.pitchedapps.frost.contracts.FrostContentContainer
|
||||||
import com.pitchedapps.frost.contracts.FrostContentCore
|
import com.pitchedapps.frost.contracts.FrostContentCore
|
||||||
import com.pitchedapps.frost.contracts.FrostContentParent
|
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.fragments.RecyclerContentContract
|
||||||
import com.pitchedapps.frost.prefs.Prefs
|
import com.pitchedapps.frost.prefs.Prefs
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
@ -47,6 +50,8 @@ class FrostRecyclerView @JvmOverloads constructor(
|
|||||||
FrostContentCore {
|
FrostContentCore {
|
||||||
|
|
||||||
private val prefs: Prefs by inject()
|
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)
|
override fun reload(animate: Boolean) = reloadBase(animate)
|
||||||
|
|
||||||
@ -107,6 +112,10 @@ class FrostRecyclerView @JvmOverloads constructor(
|
|||||||
else scrollToTop()
|
else scrollToTop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onTabLongClicked() {
|
||||||
|
onTabLongClicked(context, prefs, fbCookie, cookieDao)
|
||||||
|
}
|
||||||
|
|
||||||
private fun scrollToTop() {
|
private fun scrollToTop() {
|
||||||
stopScroll()
|
stopScroll()
|
||||||
smoothScrollToPosition(0)
|
smoothScrollToPosition(0)
|
||||||
|
@ -29,6 +29,7 @@ import ca.allanwang.kau.utils.launchMain
|
|||||||
import com.pitchedapps.frost.contracts.FrostContentContainer
|
import com.pitchedapps.frost.contracts.FrostContentContainer
|
||||||
import com.pitchedapps.frost.contracts.FrostContentCore
|
import com.pitchedapps.frost.contracts.FrostContentCore
|
||||||
import com.pitchedapps.frost.contracts.FrostContentParent
|
import com.pitchedapps.frost.contracts.FrostContentParent
|
||||||
|
import com.pitchedapps.frost.contracts.onTabLongClicked
|
||||||
import com.pitchedapps.frost.db.CookieDao
|
import com.pitchedapps.frost.db.CookieDao
|
||||||
import com.pitchedapps.frost.db.currentCookie
|
import com.pitchedapps.frost.db.currentCookie
|
||||||
import com.pitchedapps.frost.facebook.FB_HOME_URL
|
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))
|
private fun smoothScrollBy(y: Int) = smoothScrollTo(max(0, scrollY + y))
|
||||||
|
|
||||||
|
override fun onTabLongClicked() {
|
||||||
|
onTabLongClicked(context, prefs, fbCookie, cookieDao)
|
||||||
|
}
|
||||||
|
|
||||||
override var active: Boolean = true
|
override var active: Boolean = true
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field == value) return
|
if (field == value) return
|
||||||
|
@ -79,4 +79,6 @@
|
|||||||
|
|
||||||
<string name="disclaimer">Disclaimer</string>
|
<string name="disclaimer">Disclaimer</string>
|
||||||
|
|
||||||
|
<string name="messenger_logout">Log out of Messenger?</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
package com.pitchedapps.frost.facebook
|
package com.pitchedapps.frost.facebook
|
||||||
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
@ -34,4 +50,4 @@ class FbConstTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user