mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-13 22:43:06 +01:00
Fix up settings and overlay web
This commit is contained in:
parent
e916afddb8
commit
13b8505674
@ -13,10 +13,7 @@ import android.support.v7.widget.Toolbar
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.ImageButton
|
||||
import ca.allanwang.kau.utils.bindView
|
||||
import ca.allanwang.kau.utils.showChangelog
|
||||
import ca.allanwang.kau.utils.startActivitySlideIn
|
||||
import ca.allanwang.kau.utils.withMinAlpha
|
||||
import ca.allanwang.kau.utils.*
|
||||
import co.zsmb.materialdrawerkt.builders.Builder
|
||||
import co.zsmb.materialdrawerkt.builders.accountHeader
|
||||
import co.zsmb.materialdrawerkt.builders.drawer
|
||||
@ -27,6 +24,7 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial
|
||||
import com.mikepenz.iconics.IconicsDrawable
|
||||
import com.mikepenz.materialdrawer.AccountHeader
|
||||
import com.mikepenz.materialdrawer.Drawer
|
||||
import com.pitchedapps.frost.dbflow.loadFbCookie
|
||||
import com.pitchedapps.frost.dbflow.loadFbTabs
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.facebook.FbCookie.switchUser
|
||||
@ -176,22 +174,49 @@ class MainActivity : BaseActivity() {
|
||||
identifier = id
|
||||
}
|
||||
}
|
||||
profileSetting(nameRes = R.string.logout) {
|
||||
iicon = GoogleMaterial.Icon.gmd_exit_to_app
|
||||
iconColor = Prefs.textColor.toLong()
|
||||
textColor = Prefs.textColor.toLong()
|
||||
identifier = -2L
|
||||
}
|
||||
profileSetting(nameRes = R.string.add_account) {
|
||||
iconDrawable = IconicsDrawable(this@MainActivity, GoogleMaterial.Icon.gmd_add).actionBar().paddingDp(5).color(Prefs.textColor)
|
||||
textColor = Prefs.textColor.toLong()
|
||||
identifier = -2L
|
||||
identifier = -3L
|
||||
}
|
||||
profileSetting(nameRes = R.string.manage_account) {
|
||||
iicon = GoogleMaterial.Icon.gmd_settings
|
||||
iconColor = Prefs.textColor.toLong()
|
||||
textColor = Prefs.textColor.toLong()
|
||||
identifier = -3L
|
||||
identifier = -4L
|
||||
}
|
||||
onProfileChanged { _, profile, current ->
|
||||
if (current) launchWebOverlay(FbTab.PROFILE.url)
|
||||
else when (profile.identifier) {
|
||||
-2L -> launchNewTask(LoginActivity::class.java, clearStack = false)
|
||||
-3L -> launchNewTask(SelectorActivity::class.java, cookies(), false)
|
||||
-2L -> {
|
||||
val currentCookie = loadFbCookie(Prefs.userId)
|
||||
if (currentCookie == null) {
|
||||
toast(R.string.account_not_found)
|
||||
FbCookie.reset { launchLogin(cookies(), true) }
|
||||
} else {
|
||||
materialDialogThemed {
|
||||
title(R.string.logout)
|
||||
content(String.format(string(R.string.logout_confirm), currentCookie.name ?: Prefs.userId.toString()))
|
||||
positiveText(R.string.yes)
|
||||
negativeText(R.string.no)
|
||||
onPositive { _, _ ->
|
||||
FbCookie.logout(Prefs.userId) {
|
||||
val allCookies = cookies()
|
||||
allCookies.remove(currentCookie)
|
||||
launchLogin(allCookies, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-3L -> launchNewTask(LoginActivity::class.java, clearStack = false)
|
||||
-4L -> launchNewTask(SelectorActivity::class.java, cookies(), false)
|
||||
else -> {
|
||||
switchUser(profile.identifier, { refreshAll() })
|
||||
tabsForEachView { _, view -> view.badgeText = null }
|
||||
@ -234,7 +259,7 @@ class MainActivity : BaseActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_settings -> {
|
||||
startActivitySlideIn(SettingsActivity::class.java, clearStack = true, intentBuilder = {
|
||||
startActivity(SettingsActivity::class.java, clearStack = true, intentBuilder = {
|
||||
putParcelableArrayListExtra(EXTRA_COOKIES, cookies())
|
||||
})
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import ca.allanwang.kau.kpref.KPrefAdapterBuilder
|
||||
import ca.allanwang.kau.utils.*
|
||||
import ca.allanwang.kau.views.RippleCanvas
|
||||
import com.pitchedapps.frost.utils.*
|
||||
import org.jetbrains.anko.toast
|
||||
|
||||
/**
|
||||
* Created by Allan Wang on 2017-06-06.
|
||||
@ -29,7 +28,7 @@ class SettingsActivity : KPrefActivity() {
|
||||
if (item.pref != which) {
|
||||
item.pref = which
|
||||
reload()
|
||||
setFrostTheme()
|
||||
setFrostTheme(true)
|
||||
themeExterior()
|
||||
}
|
||||
true
|
||||
@ -98,8 +97,8 @@ class SettingsActivity : KPrefActivity() {
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setFrostTheme(true)
|
||||
super.onCreate(savedInstanceState)
|
||||
setFrostTheme()
|
||||
themeExterior(false)
|
||||
}
|
||||
|
||||
@ -113,7 +112,7 @@ class SettingsActivity : KPrefActivity() {
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
startActivitySlideOut(MainActivity::class.java, clearStack = true, intentBuilder = {
|
||||
startActivity(MainActivity::class.java, clearStack = true, intentBuilder = {
|
||||
putParcelableArrayListExtra(EXTRA_COOKIES, cookies())
|
||||
})
|
||||
}
|
||||
|
@ -8,10 +8,7 @@ import ca.allanwang.kau.utils.*
|
||||
import com.jude.swipbackhelper.SwipeBackHelper
|
||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.utils.ARG_URL
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
import com.pitchedapps.frost.utils.formattedFbUrl
|
||||
import com.pitchedapps.frost.utils.setFrostColors
|
||||
import com.pitchedapps.frost.utils.*
|
||||
import com.pitchedapps.frost.web.FrostWebView
|
||||
|
||||
|
||||
@ -32,7 +29,7 @@ open class WebOverlayActivity : AppCompatActivity() {
|
||||
get() = intent.extras!!.getString(ARG_URL).formattedFbUrl
|
||||
|
||||
val userId: Long
|
||||
get() = intent.extras?.getLong(ARG_USER_ID) ?: Prefs.userId
|
||||
get() = intent.extras?.getLong(ARG_USER_ID, Prefs.userId) ?: Prefs.userId
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -53,7 +50,7 @@ open class WebOverlayActivity : AppCompatActivity() {
|
||||
|
||||
frostWeb.web.setupWebview(url)
|
||||
frostWeb.web.addTitleListener({ toolbar.title = it })
|
||||
|
||||
L.d("UU $userId")
|
||||
if (userId != Prefs.userId) FbCookie.switchUser(userId) { frostWeb.web.loadBaseUrl() }
|
||||
else frostWeb.web.loadBaseUrl()
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ object FbCookie {
|
||||
with(CookieManager.getInstance()) {
|
||||
removeAllCookies({
|
||||
flush()
|
||||
callback.invoke()
|
||||
callback()
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -73,7 +73,10 @@ object FbCookie {
|
||||
fun switchUser(name: String, callback: () -> Unit) = switchUser(loadFbCookie(name), callback)
|
||||
|
||||
fun switchUser(cookie: CookieModel?, callback: () -> Unit) {
|
||||
if (cookie == null) return
|
||||
if (cookie == null) {
|
||||
callback()
|
||||
return
|
||||
}
|
||||
L.d("Switching user to $cookie")
|
||||
Prefs.userId = cookie.id
|
||||
setWebCookie(cookie.cookie, callback)
|
||||
|
@ -19,9 +19,7 @@ object Prefs : KPref() {
|
||||
|
||||
var prevId: Long by kpref("prev_id", -1L)
|
||||
|
||||
var theme: Int by kpref("theme", 0, postSetter = { value: Int ->
|
||||
loader.invalidate()
|
||||
})
|
||||
var theme: Int by kpref("theme", 0, postSetter = { _: Int -> loader.invalidate() })
|
||||
|
||||
var customTextColor: Int by kpref("color_text", Color.BLACK)
|
||||
|
||||
|
@ -15,10 +15,7 @@ import android.view.View
|
||||
import android.widget.TextView
|
||||
import ca.allanwang.kau.utils.*
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.pitchedapps.frost.BuildConfig
|
||||
import com.pitchedapps.frost.LoginActivity
|
||||
import com.pitchedapps.frost.R
|
||||
import com.pitchedapps.frost.WebOverlayActivity
|
||||
import com.pitchedapps.frost.*
|
||||
import com.pitchedapps.frost.dbflow.CookieModel
|
||||
import com.pitchedapps.frost.facebook.FB_URL_BASE
|
||||
import com.pitchedapps.frost.facebook.FbTab
|
||||
@ -36,6 +33,11 @@ fun Context.launchNewTask(clazz: Class<out Activity>, cookieList: ArrayList<Cook
|
||||
})
|
||||
}
|
||||
|
||||
fun Context.launchLogin(cookieList: ArrayList<CookieModel>, clearStack: Boolean = true) {
|
||||
if (cookieList.isNotEmpty()) launchNewTask(SelectorActivity::class.java, cookieList, clearStack)
|
||||
else launchNewTask(LoginActivity::class.java, clearStack = clearStack)
|
||||
}
|
||||
|
||||
fun Activity.cookies(): ArrayList<CookieModel> {
|
||||
return intent?.extras?.getParcelableArrayList<CookieModel>(EXTRA_COOKIES) ?: arrayListOf()
|
||||
}
|
||||
|
@ -27,11 +27,16 @@
|
||||
<string name="welcome">Welcome %s</string>
|
||||
<string name="login">Login</string>
|
||||
<string name="select_facebook_account">Select Facebook Account</string>
|
||||
<string name="account_not_found">Current account is not in the database</string>
|
||||
<string name="logout">Logout</string>
|
||||
<string name="logout_confirm">Are you sure you want to log out as %s?</string>
|
||||
<string name="add_account">Add Account</string>
|
||||
<string name="manage_account">Manage Account</string>
|
||||
<string name="exit">Exit</string>
|
||||
<string name="exit_confirmation">Are you sure you want to exit Frost?</string>
|
||||
<string name="do_not_show_again">Don\'t show again</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
|
||||
<string name="_default">Default</string>
|
||||
<string name="light">Light</string>
|
||||
|
Loading…
Reference in New Issue
Block a user