diff options
author | Allan Wang <me@allanwang.ca> | 2019-03-07 18:56:42 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-03-07 18:56:42 -0500 |
commit | 2056d9cb72ef8088a6993cbbb48d5bbb41ffddf2 (patch) | |
tree | 67fc263b4d7693c1eaf33605c511cfe358a317be /app/src/main/kotlin | |
parent | 9edbab9845b8a1182dee35121a6348537fc657f7 (diff) | |
download | frost-2056d9cb72ef8088a6993cbbb48d5bbb41ffddf2.tar.gz frost-2056d9cb72ef8088a6993cbbb48d5bbb41ffddf2.tar.bz2 frost-2056d9cb72ef8088a6993cbbb48d5bbb41ffddf2.zip |
Make cookie name null by default
Diffstat (limited to 'app/src/main/kotlin')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt | 15 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt | 3 |
2 files changed, 9 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt index e5a50543..610b2796 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -116,7 +116,7 @@ class LoginActivity : BaseActivity() { val imageDeferred = async { loadProfile(cookie.id) } val nameDeferred = async { loadUsername(cookie) } - val name: String = nameDeferred.await() + val name: String? = nameDeferred.await() val foundImage: Boolean = imageDeferred.await() L._d { "Logged in and received data" } @@ -127,7 +127,7 @@ class LoginActivity : BaseActivity() { L._i { cookie } } - textview.text = String.format(getString(R.string.welcome), name) + textview.text = String.format(getString(R.string.welcome), name ?: "") textview.fadeIn() frostEvent("Login", "success" to true) @@ -172,22 +172,23 @@ class LoginActivity : BaseActivity() { } } - private suspend fun loadUsername(cookie: CookieEntity): String = withContext(Dispatchers.IO) { - val result: String = try { + private suspend fun loadUsername(cookie: CookieEntity): String? = withContext(Dispatchers.IO) { + val result: String? = try { withTimeout(5000) { frostJsoup(cookie.cookie, FbItem.PROFILE.url).title() } } catch (e: Exception) { if (e !is UnknownHostException) e.logFrostEvent("Fetch username failed") - "" + null } - if (cookie.name?.isNotBlank() == false && result != cookie.name) { + if (result != null) { cookieDao.save(cookie.copy(name = result)) + return@withContext result } - cookie.name ?: "" + return@withContext cookie.name } override fun backConsumer(): Boolean { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index 4c7572fb..4b891800 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -89,8 +89,7 @@ class LoginWebView @JvmOverloads constructor( val cookie = CookieManager.getInstance().getCookie(url) ?: return null L.d { "Checking cookie for login" } val id = FB_USER_MATCHER.find(cookie)[1]?.toLong() ?: return null - // TODO set name to null? - return CookieEntity(id, "", cookie) + return CookieEntity(id, null, cookie) } override fun onPageCommitVisible(view: WebView, url: String?) { |