diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-03 13:22:06 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-03 13:22:06 -0700 |
commit | 35185958b077880465696d686bd797895cd3ebd4 (patch) | |
tree | 431967b2b00d00c71b06fa7a7814e05524961ead /app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt | |
parent | 5796566137995c8d244720f87ba85bce0e0d2f00 (diff) | |
download | frost-35185958b077880465696d686bd797895cd3ebd4.tar.gz frost-35185958b077880465696d686bd797895cd3ebd4.tar.bz2 frost-35185958b077880465696d686bd797895cd3ebd4.zip |
setup login activity
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 | 19 |
1 files changed, 8 insertions, 11 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 index da244ba3..5bc58fa9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt @@ -2,9 +2,8 @@ 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 io.reactivex.subjects.SingleSubject import org.jsoup.Jsoup import kotlin.concurrent.thread @@ -13,22 +12,20 @@ import kotlin.concurrent.thread */ object UsernameFetcher { - fun fetch(data: CookieModel, sender: Int) { + fun fetch(data: CookieModel, callback: SingleSubject<String>) { thread { + var name = "" try { - val title = Jsoup.connect(FbTab.PROFILE.url) + name = Jsoup.connect(FbTab.PROFILE.url) .cookie(FACEBOOK_COM, data.cookie) .get().title() - L.d("User name found: $title") - data.name = title + L.d("User name found: $name") } 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)) - } + data.name = name + saveFbCookie(data) + callback.onSuccess(name) } } } |