aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-01-04 23:59:30 -0500
committerAllan Wang <me@allanwang.ca>2019-01-04 23:59:30 -0500
commit5d2722b2205e404ee90cbb7e141ac63ca6570e1a (patch)
treea52744da7d5f18b600a57116f125c9fae5cb1411 /app/src/main/kotlin/com
parenta1cf58e0eee8d16576380e05a8d87e128242bf05 (diff)
downloadfrost-5d2722b2205e404ee90cbb7e141ac63ca6570e1a.tar.gz
frost-5d2722b2205e404ee90cbb7e141ac63ca6570e1a.tar.bz2
frost-5d2722b2205e404ee90cbb7e141ac63ca6570e1a.zip
Remove unused dependencies and remove reactivex from username fetcher
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt28
1 files changed, 11 insertions, 17 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 f7d97833..d7dd71ed 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
@@ -17,7 +17,7 @@
package com.pitchedapps.frost.dbflow
import android.os.Parcelable
-import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
+import com.pitchedapps.frost.dbflow.CookieModel_Table.cookie
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.frostJsoup
@@ -34,11 +34,10 @@ import com.raizlabs.android.dbflow.kotlinextensions.save
import com.raizlabs.android.dbflow.kotlinextensions.select
import com.raizlabs.android.dbflow.kotlinextensions.where
import com.raizlabs.android.dbflow.structure.BaseModel
-import io.reactivex.disposables.Disposable
-import io.reactivex.schedulers.Schedulers
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
+import kotlinx.coroutines.withTimeoutOrNull
import java.net.UnknownHostException
/**
@@ -98,25 +97,20 @@ fun removeCookie(id: Long) {
}
}
-inline fun CookieModel.fetchUsername(crossinline callback: (String) -> Unit): Disposable =
- ReactiveNetwork.checkInternetConnectivity().subscribeOn(Schedulers.io()).subscribe { yes, _ ->
- if (!yes) return@subscribe callback("")
- var result = ""
+suspend fun CookieModel.fetchUsername(): String? = withContext(Dispatchers.IO) {
+ withTimeoutOrNull(5000) {
+ var result: String? = null
try {
result = frostJsoup(cookie, FbItem.PROFILE.url).title()
L.d { "Fetch username found" }
} catch (e: Exception) {
if (e !is UnknownHostException)
e.logFrostEvent("Fetch username failed")
- } finally {
- if (result.isBlank() && (name?.isNotBlank() == true)) {
- callback(name!!)
- return@subscribe
- }
- if (name != result) {
- name = result
- saveFbCookie(this@fetchUsername)
- }
- callback(result)
}
+ if (name?.isNotBlank() == false && result != null && result != name) {
+ name = result
+ saveFbCookie(this@fetchUsername)
+ }
+ result
}
+} \ No newline at end of file