diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-11 13:03:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 13:03:22 -0700 |
commit | 29e54d74a8fdd943a0d85c3645538fdd62769e36 (patch) | |
tree | 14f1e7aa2781a6c552fd3f7f7a1e30fdf5a40db6 /app/src/main/kotlin/com/pitchedapps | |
parent | 8a4b0795415f0fa2c5cdcf9ef86a2c44da6b178e (diff) | |
download | frost-29e54d74a8fdd943a0d85c3645538fdd62769e36.tar.gz frost-29e54d74a8fdd943a0d85c3645538fdd62769e36.tar.bz2 frost-29e54d74a8fdd943a0d85c3645538fdd62769e36.zip |
Move network checker to io thread (#150)
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt index 14d15bd6..d73d69df 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt @@ -13,7 +13,7 @@ import com.raizlabs.android.dbflow.annotation.PrimaryKey import com.raizlabs.android.dbflow.annotation.Table import com.raizlabs.android.dbflow.kotlinextensions.* import com.raizlabs.android.dbflow.structure.BaseModel -import org.jetbrains.anko.doAsync +import io.reactivex.schedulers.Schedulers import org.jsoup.Jsoup import paperparcel.PaperParcel import java.net.UnknownHostException @@ -66,31 +66,28 @@ fun removeCookie(id: Long) { } fun CookieModel.fetchUsername(callback: (String) -> Unit) { - ReactiveNetwork.checkInternetConnectivity().subscribe { + ReactiveNetwork.checkInternetConnectivity().subscribeOn(Schedulers.io()).subscribe { yes, _ -> if (!yes) return@subscribe callback("") - doAsync { - var result = "" - try { - result = Jsoup.connect(FbTab.PROFILE.url) - .cookie(FACEBOOK_COM, cookie) - .get().title() - L.d("Fetch username found", result) - } catch (e: Exception) { - if (e !is UnknownHostException) - e.logFrostAnswers("Fetch username failed") - } finally { - if (result.isBlank() && (name?.isNotBlank() ?: false)) { - callback(name!!) - return@doAsync - } - if (name != result) { - name = result - saveFbCookie(this@fetchUsername) - } - callback(result) + var result = "" + try { + result = Jsoup.connect(FbTab.PROFILE.url) + .cookie(FACEBOOK_COM, cookie) + .get().title() + L.d("Fetch username found", result) + } catch (e: Exception) { + if (e !is UnknownHostException) + e.logFrostAnswers("Fetch username failed") + } finally { + if (result.isBlank() && (name?.isNotBlank() ?: false)) { + callback(name!!) + return@subscribe } + if (name != result) { + name = result + saveFbCookie(this@fetchUsername) + } + callback(result) } - } }
\ No newline at end of file |