diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-03 00:22:10 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-03 00:22:10 -0700 |
commit | 5796566137995c8d244720f87ba85bce0e0d2f00 (patch) | |
tree | 1736e12182c7cf2769ad953029dc6a645b803802 /app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt | |
parent | bc197ad5769ee792d930ac5b634e1e9000230689 (diff) | |
download | frost-5796566137995c8d244720f87ba85bce0e0d2f00.tar.gz frost-5796566137995c8d244720f87ba85bce0e0d2f00.tar.bz2 frost-5796566137995c8d244720f87ba85bce0e0d2f00.zip |
css updates and beginning login migration
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt new file mode 100644 index 00000000..da244ba3 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt @@ -0,0 +1,36 @@ +package com.pitchedapps.frost.facebook + +import com.pitchedapps.frost.dbflow.CookieModel +import com.pitchedapps.frost.dbflow.saveFbCookie +import com.pitchedapps.frost.events.FbAccountEvent +import com.pitchedapps.frost.utils.L +import org.greenrobot.eventbus.EventBus +import org.jsoup.Jsoup +import kotlin.concurrent.thread + +/** + * Created by Allan Wang on 2017-06-02. + */ +object UsernameFetcher { + + fun fetch(data: CookieModel, sender: Int) { + thread { + try { + val title = Jsoup.connect(FbTab.PROFILE.url) + .cookie(FACEBOOK_COM, data.cookie) + .get().title() + L.d("User name found: $title") + data.name = title + } catch (e: Exception) { + L.e("User name fetching failed: ${e.message}") + data.name = "" + } finally { + if (data.name != null) { + saveFbCookie(data) + EventBus.getDefault().post(FbAccountEvent(data, sender, FbAccountEvent.FLAG_USER_NAME)) + } + } + } + } + +}
\ No newline at end of file |