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/contracts/FrostContentContract.kt | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (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 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) + } + } + } +} -- cgit v1.2.3