diff options
Diffstat (limited to 'app/src/main/kotlin')
4 files changed, 24 insertions, 13 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 92cdf503..949659f6 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt @@ -32,7 +32,8 @@ object CookiesDb { @Table(database = CookiesDb::class, allFields = true, primaryKeyConflict = ConflictAction.REPLACE) data class CookieModel(@PrimaryKey var id: Long = -1L, var name: String? = null, var cookie: String? = null) : BaseModel(), Parcelable { companion object { - @JvmField val CREATOR = PaperParcelCookieModel.CREATOR + @JvmField + val CREATOR = PaperParcelCookieModel.CREATOR } override fun describeContents() = 0 @@ -60,14 +61,13 @@ fun saveFbCookie(cookie: CookieModel, callback: (() -> Unit)? = null) { } fun removeCookie(id: Long) { - loadFbCookie(id)?.async?.delete({ + loadFbCookie(id)?.async?.delete { L.d("Fb cookie deleted", id.toString()) - }) + } } fun CookieModel.fetchUsername(callback: (String) -> Unit) { - ReactiveNetwork.checkInternetConnectivity().subscribeOn(Schedulers.io()).subscribe { - yes, _ -> + ReactiveNetwork.checkInternetConnectivity().subscribeOn(Schedulers.io()).subscribe { yes, _ -> if (!yes) return@subscribe callback("") var result = "" try { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt index 3b0125be..40cef772 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt @@ -19,9 +19,9 @@ object FbCookie { val webCookie: String? get() = CookieManager.getInstance().getCookie(FB_URL_BASE) - fun setWebCookie(cookie: String?, callback: (() -> Unit)?) { + private fun setWebCookie(cookie: String?, callback: (() -> Unit)?) { with(CookieManager.getInstance()) { - removeAllCookies({ + removeAllCookies { if (cookie == null) { callback?.invoke() return@removeAllCookies @@ -29,12 +29,12 @@ object FbCookie { L.d("Setting cookie", cookie) val cookies = cookie.split(";").map { Pair(it, SingleSubject.create<Boolean>()) } cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie, { callback.onSuccess(it) }) } - Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {}).subscribeOn(AndroidSchedulers.mainThread()).subscribe({ + Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {}).subscribeOn(AndroidSchedulers.mainThread()).subscribe { callback?.invoke() L.d("Cookies set", webCookie) flush() - }) - }) + } + } } } @@ -61,10 +61,10 @@ object FbCookie { fun reset(callback: () -> Unit) { Prefs.userId = -1L with(CookieManager.getInstance()) { - removeAllCookies({ + removeAllCookies { flush() callback() - }) + } } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 1dbf651e..53745602 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -11,6 +11,7 @@ import com.pitchedapps.frost.activities.LoginActivity import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.SelectorActivity import com.pitchedapps.frost.activities.WebOverlayActivity +import com.pitchedapps.frost.dbflow.removeCookie import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem @@ -52,7 +53,10 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient refreshObservable.onNext(true) if (!url.isFacebookUrl) return if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) }) - else if (url.contains("login.php")) FbCookie.reset({ launchLogin(view.context) }) + else if (url.contains("login.php")) { + removeCookie(Prefs.userId) // cookie is invalid + FbCookie.reset({ launchLogin(view.context) }) + } } 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 dd8e2390..6bf04ae1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -2,6 +2,7 @@ package com.pitchedapps.frost.web import android.annotation.SuppressLint import android.content.Context +import android.graphics.Color import android.util.AttributeSet import android.view.View import android.webkit.* @@ -17,6 +18,7 @@ import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.isFacebookUrl import org.jetbrains.anko.doAsync import org.jetbrains.anko.uiThread +import org.jetbrains.anko.withAlpha /** * Created by Allan Wang on 2017-05-29. @@ -74,6 +76,11 @@ class LoginWebView @JvmOverloads constructor( } } + override fun onPageCommitVisible(view: WebView, url: String?) { + super.onPageCommitVisible(view, url) + view.setBackgroundColor(Color.TRANSPARENT) + } + override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean { //For now, we will ignore all attempts to launch external apps during login if (request.url == null || request.url.scheme == "intent" || request.url.scheme == "android-app") |