diff options
author | Allan Wang <me@allanwang.ca> | 2017-05-30 19:55:57 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-05-30 19:55:57 -0700 |
commit | c53e343f039b65c0aee2ee316b8c844a5b596bb8 (patch) | |
tree | bbe8bc8a4e416ca7d143306d2fe0e2ddb25f78d6 /app/src/main/kotlin/com/pitchedapps/frost/facebook | |
parent | 20ef6500dc0b6d84905d92d8469feb6ff0ac502d (diff) | |
download | frost-c53e343f039b65c0aee2ee316b8c844a5b596bb8.tar.gz frost-c53e343f039b65c0aee2ee316b8c844a5b596bb8.tar.bz2 frost-c53e343f039b65c0aee2ee316b8c844a5b596bb8.zip |
working tab db and initial cookie map
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/CookieMap.kt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/CookieMap.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/CookieMap.kt new file mode 100644 index 00000000..96b1f2de --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/CookieMap.kt @@ -0,0 +1,45 @@ +package com.pitchedapps.frost.facebook + +import android.webkit.CookieManager +import com.pitchedapps.frost.utils.Prefs + +/** + * Created by Allan Wang on 2017-05-30. + */ +object CookieMap { + + var userId: Int = -1 + private val userMatcher = "c_user=([0-9]*);" + private val map = HashMap<String, String>() + + operator fun get(key: String) = map[key] + + operator fun set(key: String, value: String) { + map[key] = value + } + + fun put(url: String, cookie: String) { + map.put(url, cookie) + checkUserId(url, cookie) + } + + fun checkUserId(url: String, cookie: String) { + if (userId != -1) return + if (!url.contains("facebook") || !cookie.contains(userMatcher)) return + val id = Regex(userMatcher).find(cookie)?.value + if (id != null) { + userId = id.toInt() + save() + } + } + + fun save() { + Prefs.userId = userId + CookieManager.getInstance().flush() + + } + + fun reset() { + + } +}
\ No newline at end of file |