From 1769dbcef9786b847ffeaebdf6ecced45da9222c Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 26 Dec 2017 03:37:32 -0500 Subject: Enhancement/fb requests (#575) * Update lambdas to references * Simplify regex and parsers * Fix some parsing and add more tests * Improve message parser and tests * Simplify parser * Shorten interfaces * Push rem * Create notification parser * Clean up notification service * Clean up notification service * Add safe cookie fallback * Fix cookie reference * Make parsers only hold cookie string * Clean up cookie references * Fix up login and event theme * Update changelog Remove workspace backup --- .../pitchedapps/frost/activities/LoginActivity.kt | 55 ++++++++++++++-------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt') 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 0d6cce07..e2f7a3d2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -25,10 +25,9 @@ import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL import com.pitchedapps.frost.utils.* import com.pitchedapps.frost.web.LoginWebView -import io.reactivex.Observable +import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.functions.BiFunction -import io.reactivex.internal.operators.single.SingleToObservable import io.reactivex.subjects.SingleSubject @@ -37,18 +36,18 @@ import io.reactivex.subjects.SingleSubject */ class LoginActivity : BaseActivity() { - val toolbar: Toolbar by bindView(R.id.toolbar) - val web: LoginWebView by bindView(R.id.login_webview) - val swipeRefresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh) - val textview: AppCompatTextView by bindView(R.id.textview) - val profile: ImageView by bindView(R.id.profile) + private val toolbar: Toolbar by bindView(R.id.toolbar) + private val web: LoginWebView by bindView(R.id.login_webview) + private val swipeRefresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh) + private val textview: AppCompatTextView by bindView(R.id.textview) + private val profile: ImageView by bindView(R.id.profile) - val profileObservable = SingleSubject.create() - val usernameObservable = SingleSubject.create() - lateinit var profileLoader: RequestManager + private val profileSubject = SingleSubject.create() + private val usernameSubject = SingleSubject.create() + private lateinit var profileLoader: RequestManager // Helper to set and enable swipeRefresh - var refresh: Boolean + private var refresh: Boolean get() = swipeRefresh.isRefreshing set(value) { if (value) swipeRefresh.isEnabled = true @@ -73,10 +72,12 @@ class LoginActivity : BaseActivity() { profileLoader = Glide.with(profile) } - fun loadInfo(cookie: CookieModel) { + private fun loadInfo(cookie: CookieModel) { refresh = true - Observable.zip(SingleToObservable(profileObservable), SingleToObservable(usernameObservable), - BiFunction> { foundImage, name -> Pair(foundImage, name) }) + Single.zip>( + profileSubject, + usernameSubject, + BiFunction(::Pair)) .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) -> refresh = false if (!foundImage) { @@ -85,7 +86,11 @@ class LoginActivity : BaseActivity() { } textview.text = String.format(getString(R.string.welcome), name) textview.fadeIn() - frostAnswers { logLogin(LoginEvent().putMethod("frost_browser").putSuccess(true)) } + frostAnswers { + logLogin(LoginEvent() + .putMethod("frost_browser") + .putSuccess(true)) + } /* * The user may have logged into an account that is already in the database * We will let the db handle duplicates and load it now after the new account has been saved @@ -102,23 +107,23 @@ class LoginActivity : BaseActivity() { } - fun loadProfile(id: Long) { + private fun loadProfile(id: Long) { profileLoader.load(PROFILE_PICTURE_URL(id)).withRoundIcon().listener(object : RequestListener { override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - profileObservable.onSuccess(true) + profileSubject.onSuccess(true) return false } override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { e.logFrostAnswers("Profile loading exception") - profileObservable.onSuccess(false) + profileSubject.onSuccess(false) return false } }).into(profile) } - fun loadUsername(cookie: CookieModel) { - cookie.fetchUsername { usernameObservable.onSuccess(it) } + private fun loadUsername(cookie: CookieModel) { + cookie.fetchUsername(usernameSubject::onSuccess) } override fun backConsumer(): Boolean { @@ -129,4 +134,14 @@ class LoginActivity : BaseActivity() { return false } + override fun onResume() { + super.onResume() + web.resumeTimers() + } + + override fun onPause() { + web.pauseTimers() + super.onPause() + } + } \ No newline at end of file -- cgit v1.2.3