aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-20 14:09:41 -0700
committerAllan Wang <me@allanwang.ca>2017-08-20 14:09:41 -0700
commit238c263376d2db2ef7bff765155832fa95309cf1 (patch)
tree202959e8969f0202fbe6c3a7e1f0a9e821e2609a /app
parent62e10aa1295bdcd99e307b22b4747bb5353cd5d7 (diff)
downloadfrost-238c263376d2db2ef7bff765155832fa95309cf1.tar.gz
frost-238c263376d2db2ef7bff765155832fa95309cf1.tar.bz2
frost-238c263376d2db2ef7bff765155832fa95309cf1.zip
Update login logic
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt20
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt34
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt5
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt4
-rw-r--r--app/src/main/res/layout/login_webview.xml2
-rw-r--r--app/src/main/res/xml/frost_changelog.xml3
11 files changed, 36 insertions, 54 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 6b1f2c5c..99f95469 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/LoginActivity.kt
@@ -21,6 +21,7 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.dbflow.fetchUsername
import com.pitchedapps.frost.dbflow.loadFbCookiesAsync
+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
@@ -64,6 +65,7 @@ class LoginActivity : BaseActivity() {
web.loadLogin({ refresh = it != 100 }) {
cookie ->
L.d("Login found")
+ FbCookie.save(cookie.id)
web.fadeOut(onFinish = {
profile.fadeIn()
loadInfo(cookie)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
index 343829c0..80dbc3dc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/MainActivity.kt
@@ -273,13 +273,7 @@ class MainActivity : BaseActivity(), SearchWebView.SearchContract,
content(String.format(string(R.string.kau_logout_confirm_as_x), currentCookie.name ?: Prefs.userId.toString()))
positiveText(R.string.kau_yes)
negativeText(R.string.kau_no)
- onPositive { _, _ ->
- FbCookie.logout(Prefs.userId) {
- val allCookies = cookies()
- allCookies.remove(currentCookie)
- launchLogin(allCookies, true)
- }
- }
+ onPositive { _, _ -> FbCookie.logout(this@MainActivity) }
}
}
}
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 949659f6..eecd6b48 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
@@ -79,7 +79,7 @@ fun CookieModel.fetchUsername(callback: (String) -> Unit) {
if (e !is UnknownHostException)
e.logFrostAnswers("Fetch username failed")
} finally {
- if (result.isBlank() && (name?.isNotBlank() ?: false)) {
+ if (result.isBlank() && (name?.isNotBlank() == true)) {
callback(name!!)
return@subscribe
}
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 40cef772..4dc7b62d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -1,5 +1,7 @@
package com.pitchedapps.frost.facebook
+import android.app.Activity
+import android.content.Context
import android.webkit.CookieManager
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.dbflow.loadFbCookie
@@ -7,6 +9,8 @@ import com.pitchedapps.frost.dbflow.removeCookie
import com.pitchedapps.frost.dbflow.saveFbCookie
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.cookies
+import com.pitchedapps.frost.utils.launchLogin
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.subjects.SingleSubject
@@ -83,6 +87,22 @@ object FbCookie {
setWebCookie(cookie.cookie, callback)
}
+ /**
+ * Helper function to remove the current cookies
+ * and launch the proper login page
+ */
+ fun logout(context: Context) {
+ val cookies = arrayListOf<CookieModel>()
+ if (context is Activity)
+ cookies.addAll(context.cookies().filter { it.id != Prefs.userId })
+ logout(Prefs.userId) {
+ context.launchLogin(cookies, true)
+ }
+ }
+
+ /**
+ * Clear the cookies of the given id
+ */
fun logout(id: Long, callback: () -> Unit) {
L.d("Logging out user $id")
removeCookie(id)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt
deleted file mode 100644
index f2bcc328..00000000
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/UsernameFetcher.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.pitchedapps.frost.facebook
-
-import com.pitchedapps.frost.dbflow.CookieModel
-import com.pitchedapps.frost.dbflow.saveFbCookie
-import com.pitchedapps.frost.utils.L
-import com.pitchedapps.frost.utils.logFrostAnswers
-import io.reactivex.subjects.SingleSubject
-import org.jsoup.Jsoup
-import kotlin.concurrent.thread
-
-/**
- * Created by Allan Wang on 2017-06-02.
- */
-object UsernameFetcher {
-
- fun fetch(data: CookieModel, callback: SingleSubject<String>) {
- thread {
- var name = ""
- try {
- name = Jsoup.connect(FbItem.PROFILE.url)
- .cookie(FACEBOOK_COM, data.cookie)
- .get().title()
- L.d("User name found", name)
- } catch (e: Exception) {
- e.logFrostAnswers("User name fetching failed")
- } finally {
- data.name = name
- saveFbCookie(data)
- callback.onSuccess(name)
- }
- }
- }
-
-} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
index 92d4c109..e342394f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -27,6 +27,7 @@ import com.pitchedapps.frost.R
import com.pitchedapps.frost.activities.*
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.FACEBOOK_COM
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.formattedFbUrl
import java.io.IOException
@@ -65,7 +66,9 @@ fun Context.launchWebOverlay(url: String) {
val argUrl = url.formattedFbUrl
L.v("Launch received", url)
L.i("Launch web overlay", argUrl)
- if (!(Prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl))))
+ if (argUrl.isFacebookUrl && argUrl.contains("/logout.php"))
+ FbCookie.logout(this)
+ else if (!(Prefs.linksInDefaultApp && resolveActivityForUri(Uri.parse(argUrl))))
startActivity(WebOverlayActivity::class.java, false, intentBuilder = {
putExtra(ARG_URL, argUrl)
})
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
index 2abc9b25..c7232fe3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -5,6 +5,7 @@ import android.support.v4.widget.SwipeRefreshLayout
import android.webkit.JavascriptInterface
import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.dbflow.CookieModel
+import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.*
import io.reactivex.subjects.Subject
@@ -68,7 +69,7 @@ class FrostJSI(val webView: FrostWebViewCore) {
@JavascriptInterface
fun loadLogin() {
- context.launchLogin(cookies, true)
+ FbCookie.logout(context)
}
/**
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 53745602..8335be7f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -11,7 +11,6 @@ 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
@@ -51,12 +50,6 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient
if (url == null) return
L.d("FWV Loading", url)
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")) {
- 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 6bf04ae1..51dc2e99 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -2,7 +2,6 @@ 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.*
@@ -18,7 +17,6 @@ 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.
@@ -78,7 +76,7 @@ class LoginWebView @JvmOverloads constructor(
override fun onPageCommitVisible(view: WebView, url: String?) {
super.onPageCommitVisible(view, url)
- view.setBackgroundColor(Color.TRANSPARENT)
+ view.setBackgroundColor(Prefs.bgColor)
}
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
diff --git a/app/src/main/res/layout/login_webview.xml b/app/src/main/res/layout/login_webview.xml
index 958bcec5..b64f2220 100644
--- a/app/src/main/res/layout/login_webview.xml
+++ b/app/src/main/res/layout/login_webview.xml
@@ -33,5 +33,7 @@
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="invisible" />
+
</RelativeLayout>
+
</android.support.v4.widget.SwipeRefreshLayout> \ No newline at end of file
diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml
index 5cbc6791..32227578 100644
--- a/app/src/main/res/xml/frost_changelog.xml
+++ b/app/src/main/res/xml/frost_changelog.xml
@@ -14,6 +14,9 @@
<item text="Fix url loading bug and add option to launch urls in default browser (behaviour setting)" />
<item text="Allow for bottom bar tabs (appearance setting)" />
<item text="Allow custom ringtones for notifications and messages (notification setting)" />
+ <item text="Improve logout logic when account is invalid" />
+ <item text="Fix material light background for certain items" />
+ <item text="Fix initial login not sticking" />
<item text="" />
<version title="v1.4.7"/>