aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-06 19:29:25 -0700
committerAllan Wang <me@allanwang.ca>2017-06-06 19:29:25 -0700
commit067ea15188f20fa268255153e35c2df732fdffee (patch)
tree87a0fcd84f37ad569ec2743ffc702a69cd59e252 /app/src/main/kotlin/com/pitchedapps/frost/facebook
parentc4e22f5512570d05178711ba90c28eb6dc288253 (diff)
downloadfrost-067ea15188f20fa268255153e35c2df732fdffee.tar.gz
frost-067ea15188f20fa268255153e35c2df732fdffee.tar.bz2
frost-067ea15188f20fa268255153e35c2df732fdffee.zip
Clean up injectors and events
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt1
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt53
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt2
3 files changed, 40 insertions, 16 deletions
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 59d76954..0a7041de 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbConst.kt
@@ -3,6 +3,7 @@ package com.pitchedapps.frost.facebook
/**
* Created by Allan Wang on 2017-06-01.
*/
+const val HTTPS_FACEBOOK_COM = "https://facebook.com"
const val FACEBOOK_COM = "facebook.com"
const val FB_URL_BASE = "https://m.facebook.com/"
fun PROFILE_PICTURE_URL(id: Long) = "https://graph.facebook.com/$id/picture?type=large" \ No newline at end of file
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 2146ae26..2d46f36a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -7,25 +7,46 @@ import com.pitchedapps.frost.dbflow.removeCookie
import com.pitchedapps.frost.dbflow.saveFbCookie
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
+import io.reactivex.Observable
+import io.reactivex.android.schedulers.AndroidSchedulers
+import io.reactivex.subjects.SingleSubject
/**
* Created by Allan Wang on 2017-05-30.
*/
object FbCookie {
- var webCookie: String?
+ val webCookie: String?
get() = CookieManager.getInstance().getCookie(FB_URL_BASE)
- set(value) {
- CookieManager.getInstance().setCookie(FB_URL_BASE, value)
- CookieManager.getInstance().flush()
+
+ fun setWebCookie(cookie: String?, callback: (() -> Unit)?) {
+ with(CookieManager.getInstance()) {
+ removeAllCookies({
+ if (cookie == null) {
+ callback?.invoke()
+ return@removeAllCookies
+ }
+ L.d("Setting cookie to $cookie")
+ val cookies = cookie.split(";").map { Pair(it, SingleSubject.create<Boolean>()) }
+ cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie, { callback.onSuccess(it) }) }
+ Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {}).subscribeOn(AndroidSchedulers.mainThread()).subscribe({
+ callback?.invoke()
+ L.d("Cookies set: $webCookie")
+ flush()
+ })
+ })
}
+ }
operator fun invoke() {
L.d("User ${Prefs.userId}")
+ with(CookieManager.getInstance()) {
+ setAcceptCookie(true)
+ }
val dbCookie = loadFbCookie(Prefs.userId)?.cookie
if (dbCookie != null && webCookie == null) {
L.d("DbCookie found & WebCookie is null; setting webcookie")
- webCookie = dbCookie
+ setWebCookie(dbCookie, null)
}
}
@@ -37,28 +58,30 @@ object FbCookie {
saveFbCookie(cookie)
}
- fun reset() {
+ fun reset(callback: () -> Unit) {
Prefs.userId = Prefs.userIdDefault
with(CookieManager.getInstance()) {
- removeAllCookies(null)
- flush()
+ removeAllCookies({
+ flush()
+ callback.invoke()
+ })
}
}
- fun switchUser(id: Long) = switchUser(loadFbCookie(id))
+ fun switchUser(id: Long, callback: () -> Unit) = switchUser(loadFbCookie(id), callback)
- fun switchUser(name: String) = switchUser(loadFbCookie(name))
+ fun switchUser(name: String, callback: () -> Unit) = switchUser(loadFbCookie(name), callback)
- fun switchUser(cookie: CookieModel?) {
+ fun switchUser(cookie: CookieModel?, callback: () -> Unit) {
if (cookie == null) return
+ L.d("Switching user to $cookie")
Prefs.userId = cookie.id
- webCookie = cookie.cookie
- //TODO add webview refresh event
+ setWebCookie(cookie.cookie, callback)
}
- fun logout(id:Long) {
+ fun logout(id: Long, callback: () -> Unit) {
L.d("Logging out user $id")
removeCookie(id)
- reset()
+ reset(callback)
}
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt
index ba595276..17dd4862 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbTab.kt
@@ -14,7 +14,7 @@ enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: Stri
PROFILE(R.string.profile, CommunityMaterial.Icon.cmd_account, "me"),
EVENTS(R.string.events, GoogleMaterial.Icon.gmd_event, "events/upcoming"),
FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_people, "friends/center/requests"),
- MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages?disable_interstitial=1&rdr"),
+ MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages"),
NOTIFICATIONS(R.string.notifications, MaterialDesignIconic.Icon.gmi_globe, "notifications"),
ACTIVITY_LOG(R.string.activity_log, GoogleMaterial.Icon.gmd_list, "me/allactivity"),
PAGES(R.string.pages, GoogleMaterial.Icon.gmd_flag, "pages"),