aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt43
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt10
6 files changed, 52 insertions, 28 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
index fcffffb2..759e8298 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
@@ -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())
})
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
index 19fa6362..1fcdf798 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
@@ -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())
})
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
index 1660d8db..8df7f1bd 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
@@ -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()
}
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 ac58fb2f..8e40a988 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -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)
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
index 40735544..cda259b2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -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)
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 d4942e9e..954a340f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -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()
}