mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-08 12:02:33 +01:00
remap login cookies
This commit is contained in:
parent
e5a43ed02a
commit
0f8f664533
@ -1,13 +1,8 @@
|
||||
package com.pitchedapps.frost
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.support.v4.app.ActivityOptionsCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.widget.SwipeRefreshLayout
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.AppCompatTextView
|
||||
@ -20,13 +15,13 @@ import com.bumptech.glide.load.engine.GlideException
|
||||
import com.bumptech.glide.request.RequestListener
|
||||
import com.bumptech.glide.request.target.Target
|
||||
import com.pitchedapps.frost.dbflow.CookieModel
|
||||
import com.pitchedapps.frost.dbflow.loadFbCookiesAsync
|
||||
import com.pitchedapps.frost.dbflow.saveFbCookie
|
||||
import com.pitchedapps.frost.facebook.FACEBOOK_COM
|
||||
import com.pitchedapps.frost.facebook.FbTab
|
||||
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.bindView
|
||||
import com.pitchedapps.frost.utils.cookies
|
||||
import com.pitchedapps.frost.utils.launchNewTask
|
||||
import com.pitchedapps.frost.views.fadeIn
|
||||
import com.pitchedapps.frost.views.fadeOut
|
||||
@ -58,18 +53,6 @@ class LoginActivity : AppCompatActivity() {
|
||||
val profileObservable = SingleSubject.create<Boolean>()!!
|
||||
val usernameObservable = SingleSubject.create<String>()!!
|
||||
|
||||
companion object {
|
||||
const val EXTRA_COOKIES = "extra_cookies"
|
||||
fun newInstance(context: Context, cookies: ArrayList<CookieModel> = arrayListOf()) {
|
||||
val intent = Intent(context, LoginActivity::class.java)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putExtra(EXTRA_COOKIES, cookies)
|
||||
val bundle = ActivityOptionsCompat.makeCustomAnimation(context, R.anim.slide_in_right, R.anim.slide_out_right).toBundle()
|
||||
ContextCompat.startActivity(context, intent, bundle)
|
||||
if (context is Activity) context.finish()
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to set and enable swipeRefresh
|
||||
var refresh: Boolean
|
||||
get() = swipeRefresh.isRefreshing
|
||||
@ -108,11 +91,16 @@ class LoginActivity : AppCompatActivity() {
|
||||
L.d("Zip done")
|
||||
if (!foundImage) L.e("Could not get profile photo; Invalid id?\n\t$cookie")
|
||||
textview.setTextWithFade(String.format(getString(R.string.welcome), name), duration = 500)
|
||||
Handler().postDelayed({
|
||||
val cookies = cookies()
|
||||
cookies.add(cookie)
|
||||
launchNewTask(MainActivity::class.java, cookies)
|
||||
}, 1000)
|
||||
/*
|
||||
* 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 {
|
||||
cookies ->
|
||||
Handler().postDelayed({
|
||||
launchNewTask(MainActivity::class.java, ArrayList(cookies))
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
loadProfile(cookie.id)
|
||||
loadUsername(cookie)
|
||||
|
@ -40,9 +40,10 @@ fun loadFbCookiesAsync(callback: (cookies: List<CookieModel>) -> Unit) {
|
||||
(select from CookieModel::class).async().queryListResultCallback { _, tResult -> callback.invoke(tResult) }.execute()
|
||||
}
|
||||
|
||||
fun saveFbCookie(cookie: CookieModel) {
|
||||
fun saveFbCookie(cookie: CookieModel, callback: (() -> Unit)? = null) {
|
||||
cookie.async save {
|
||||
L.d("Fb cookie $cookie saved")
|
||||
callback?.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,11 @@ package com.pitchedapps.frost.events
|
||||
|
||||
import android.content.Context
|
||||
import com.pitchedapps.frost.WebOverlayActivity
|
||||
import com.pitchedapps.frost.utils.launchWebOverlay
|
||||
|
||||
/**
|
||||
* Created by Allan Wang on 2017-06-01.
|
||||
*/
|
||||
class WebLaunchEvent(val url: String) {
|
||||
fun execute(context: Context) = WebOverlayActivity.newInstance(context, url)
|
||||
fun execute(context: Context) = context.launchWebOverlay(url)
|
||||
}
|
@ -8,7 +8,7 @@ import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic
|
||||
import com.pitchedapps.frost.R
|
||||
|
||||
enum class FbTab(@StringRes val titleId: Int, val icon: IIcon, relativeUrl: String) {
|
||||
FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, ""),
|
||||
FEED(R.string.feed, CommunityMaterial.Icon.cmd_newspaper, "feed"),
|
||||
PROFILE(R.string.profile, CommunityMaterial.Icon.cmd_account, "me"),
|
||||
EVENTS(R.string.events, GoogleMaterial.Icon.gmd_event, "events/upcoming"),
|
||||
FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_people, "friends/center/requests"),
|
||||
|
@ -16,16 +16,16 @@ import com.pitchedapps.frost.facebook.FbTab
|
||||
private const val EXTRA_COOKIES = "extra_cookies"
|
||||
private const val ARG_URL = "arg_url"
|
||||
|
||||
fun Activity.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf()) {
|
||||
fun Context.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<CookieModel> = arrayListOf()) {
|
||||
val intent = (Intent(this, clazz))
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
intent.putParcelableArrayListExtra(EXTRA_COOKIES, cookieList)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
if (this is Activity) finish()
|
||||
}
|
||||
|
||||
fun Activity.cookies(): ArrayList<CookieModel> {
|
||||
return intent.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf()
|
||||
return intent?.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf()
|
||||
}
|
||||
|
||||
fun Context.launchWebOverlay(url: String) {
|
||||
|
@ -9,6 +9,7 @@ import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.injectors.CssAssets
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
import com.pitchedapps.frost.utils.launchNewTask
|
||||
import com.pitchedapps.frost.views.circularReveal
|
||||
import com.pitchedapps.frost.views.fadeOut
|
||||
|
||||
@ -32,10 +33,10 @@ class FrostWebViewClient(val position: () -> Int) : WebViewClient() {
|
||||
if (!url.contains(FACEBOOK_COM)) return
|
||||
if (url.contains("logout.php")) {
|
||||
FbCookie.logout(Prefs.userId)
|
||||
LoginActivity.newInstance(view.context)
|
||||
view.context.launchNewTask(LoginActivity::class.java)
|
||||
} else if (url.contains("login.php")) {
|
||||
FbCookie.reset()
|
||||
LoginActivity.newInstance(view.context)
|
||||
view.context.launchNewTask(LoginActivity::class.java)
|
||||
}
|
||||
view.fadeOut(duration = 200L)
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ class LoginWebView @JvmOverloads constructor(
|
||||
loadLogin()
|
||||
return
|
||||
}
|
||||
cookieObservable.onNext(Pair(url, CookieManager.getInstance().getCookie(url)))
|
||||
CssAssets.LOGIN.inject(view, {
|
||||
if (view.visibility == View.INVISIBLE)
|
||||
view.circularReveal(offset = 150L)
|
||||
})
|
||||
cookieObservable.onNext(Pair(url, CookieManager.getInstance().getCookie(url)))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user