From 697d01882ba8b1dbb85484ba3bf6e810e32448fc Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 24 Dec 2018 01:47:03 -0500 Subject: Enhancement/ktlint (#1259) * Add spotless * Reformat code * Apply license header * Add remaining license headers --- .../pitchedapps/frost/activities/LoginActivity.kt | 120 +++++++++++++-------- 1 file changed, 75 insertions(+), 45 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 9c8a60aa..8b5fe38d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt @@ -1,12 +1,28 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package com.pitchedapps.frost.activities import android.graphics.drawable.Drawable import android.os.Bundle import android.os.Handler -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout +import android.widget.ImageView import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.Toolbar -import android.widget.ImageView +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import ca.allanwang.kau.utils.bindView import ca.allanwang.kau.utils.fadeIn import ca.allanwang.kau.utils.fadeOut @@ -24,14 +40,18 @@ import com.pitchedapps.frost.facebook.profilePictureUrl import com.pitchedapps.frost.glide.FrostGlide import com.pitchedapps.frost.glide.GlideApp import com.pitchedapps.frost.glide.transform -import com.pitchedapps.frost.utils.* +import com.pitchedapps.frost.utils.L +import com.pitchedapps.frost.utils.Showcase +import com.pitchedapps.frost.utils.frostEvent +import com.pitchedapps.frost.utils.launchNewTask +import com.pitchedapps.frost.utils.logFrostEvent +import com.pitchedapps.frost.utils.setFrostColors import com.pitchedapps.frost.web.LoginWebView import io.reactivex.Single import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.functions.BiFunction import io.reactivex.subjects.SingleSubject - /** * Created by Allan Wang on 2017-06-01. */ @@ -78,51 +98,62 @@ class LoginActivity : BaseActivity() { private fun loadInfo(cookie: CookieModel) { refresh = true Single.zip>( - profileSubject, - usernameSubject, - BiFunction(::Pair)) - .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) -> - refresh = false - if (!foundImage) { - L.e { "Could not get profile photo; Invalid userId?" } - L._i { cookie } - } - textview.text = String.format(getString(R.string.welcome), name) - textview.fadeIn() - frostEvent("Login", "success" to 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 - */ - loadFbCookiesAsync { - val cookies = ArrayList(it) - Handler().postDelayed({ - if (Showcase.intro) - launchNewTask(cookies, true) - else - launchNewTask(cookies, true) - }, 1000) - } - }.disposeOnDestroy() + profileSubject, + usernameSubject, + BiFunction(::Pair) + ) + .observeOn(AndroidSchedulers.mainThread()).subscribe { (foundImage, name) -> + refresh = false + if (!foundImage) { + L.e { "Could not get profile photo; Invalid userId?" } + L._i { cookie } + } + textview.text = String.format(getString(R.string.welcome), name) + textview.fadeIn() + frostEvent("Login", "success" to 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 + */ + loadFbCookiesAsync { + val cookies = ArrayList(it) + Handler().postDelayed({ + if (Showcase.intro) + launchNewTask(cookies, true) + else + launchNewTask(cookies, true) + }, 1000) + } + }.disposeOnDestroy() loadProfile(cookie.id) loadUsername(cookie) } - private fun loadProfile(id: Long) { profileLoader.load(profilePictureUrl(id)) - .transform(FrostGlide.roundCorner).listener(object : RequestListener { - override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { - profileSubject.onSuccess(true) - return false - } - - override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { - e.logFrostEvent("Profile loading exception") - profileSubject.onSuccess(false) - return false - } - }).into(profile) + .transform(FrostGlide.roundCorner).listener(object : RequestListener { + override fun onResourceReady( + resource: Drawable?, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { + profileSubject.onSuccess(true) + return false + } + + override fun onLoadFailed( + e: GlideException?, + model: Any?, + target: Target?, + isFirstResource: Boolean + ): Boolean { + e.logFrostEvent("Profile loading exception") + profileSubject.onSuccess(false) + return false + } + }).into(profile) } private fun loadUsername(cookie: CookieModel) { @@ -146,5 +177,4 @@ class LoginActivity : BaseActivity() { web.pauseTimers() super.onPause() } - -} \ No newline at end of file +} -- cgit v1.2.3