aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt42
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt21
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt28
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt4
-rw-r--r--app/src/main/res/values/strings.xml3
10 files changed, 80 insertions, 48 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
index 30562499..3991e53a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
@@ -7,6 +7,7 @@ import ca.allanwang.kau.email.sendEmail
import ca.allanwang.kau.kpref.CoreAttributeContract
import ca.allanwang.kau.kpref.KPrefActivity
import ca.allanwang.kau.kpref.KPrefAdapterBuilder
+import ca.allanwang.kau.kpref.items.KPrefColorPicker
import ca.allanwang.kau.utils.*
import ca.allanwang.kau.views.RippleCanvas
import com.mikepenz.google_material_typeface_library.GoogleMaterial
@@ -21,10 +22,7 @@ class SettingsActivity : KPrefActivity() {
override fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit = {
textColor = { Prefs.textColor }
- accentColor = {
- if (Prefs.headerColor.isColorVisibleOn(Prefs.bgColor, 100)) Prefs.headerColor
- else Prefs.textColor
- }
+ accentColor = { Prefs.accentColor }
}
override fun onCreateKPrefs(savedInstanceState: android.os.Bundle?): KPrefAdapterBuilder.() -> Unit = {
@@ -71,40 +69,39 @@ class SettingsActivity : KPrefActivity() {
}
if (BuildConfig.DEBUG) {
- colorPicker(R.string.text_color, { Prefs.customTextColor }, { Prefs.customTextColor = it; reload() }) {
+
+ fun KPrefColorPicker.KPrefColorContract.dependsOnCustom() {
enabler = { Prefs.isCustomTheme }
- onDisabledClick = { itemView, _, _ -> itemView.snackbar(R.string.requires_custom_theme); true }
- allowCustomAlpha = false
+ onDisabledClick = { itemView, _, _ -> itemView.frostSnackbar(R.string.requires_custom_theme); true }
allowCustom = true
}
+ colorPicker(R.string.text_color, { Prefs.customTextColor }, { Prefs.customTextColor = it; reload() }) {
+ dependsOnCustom()
+ allowCustomAlpha = false
+ }
+
colorPicker(R.string.background_color, { Prefs.customBackgroundColor },
{ Prefs.customBackgroundColor = it; bgCanvas.ripple(it, duration = 500L) }) {
- enabler = { Prefs.isCustomTheme }
- onDisabledClick = { itemView, _, _ -> itemView.snackbar(R.string.requires_custom_theme); true }
+ dependsOnCustom()
allowCustomAlpha = true
- allowCustom = true
}
colorPicker(R.string.header_color, { Prefs.customHeaderColor }, {
Prefs.customHeaderColor = it
- val darkerColor = it.darken()
- this@SettingsActivity.navigationBarColor = darkerColor
- toolbarCanvas.ripple(darkerColor, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
+ this@SettingsActivity.navigationBarColor = it
+ toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
}) {
- enabler = { Prefs.isCustomTheme }
- onDisabledClick = { itemView, _, _ -> itemView.snackbar(R.string.requires_custom_theme); true }
+ dependsOnCustom()
allowCustomAlpha = true
- allowCustom = true
}
colorPicker(R.string.icon_color, { Prefs.customIconColor }, {
Prefs.customIconColor = it
invalidateOptionsMenu()
}) {
- enabler = { Prefs.isCustomTheme }
- onDisabledClick = { itemView, _, _ -> itemView.snackbar(R.string.requires_custom_theme); true }
- allowCustom = true
+ dependsOnCustom()
+ allowCustomAlpha = false
}
}
@@ -179,10 +176,9 @@ class SettingsActivity : KPrefActivity() {
fun themeExterior(animate: Boolean = true) {
if (animate) bgCanvas.fade(Prefs.bgColor)
else bgCanvas.set(Prefs.bgColor)
- val darkAccent = Prefs.headerColor.darken()
- if (animate) toolbarCanvas.ripple(darkAccent, RippleCanvas.MIDDLE, RippleCanvas.END)
- else toolbarCanvas.set(darkAccent)
- this.navigationBarColor = darkAccent
+ if (animate) toolbarCanvas.ripple(Prefs.headerColor, RippleCanvas.MIDDLE, RippleCanvas.END)
+ else toolbarCanvas.set(Prefs.headerColor)
+ this.navigationBarColor = Prefs.headerColor
}
override fun onBackPressed() {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
index 002d92f7..35319f71 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/WebOverlayActivity.kt
@@ -3,16 +3,14 @@ package com.pitchedapps.frost
import android.content.Intent
import android.os.Bundle
import android.support.design.widget.CoordinatorLayout
+import android.support.design.widget.Snackbar
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
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
@@ -56,6 +54,13 @@ open class WebOverlayActivity : AppCompatActivity() {
frostWeb.web.addTitleListener({ toolbar.title = it })
if (userId != Prefs.userId) FbCookie.switchUser(userId) { frostWeb.web.loadBaseUrl() }
else frostWeb.web.loadBaseUrl()
+ if (Prefs.firstWebOverlay) {
+ Prefs.firstWebOverlay = false
+ coordinator.frostSnackbar(R.string.web_overlay_swipe_hint) {
+ duration = Snackbar.LENGTH_INDEFINITE
+ setAction(R.string.kau_ok) { _ -> this.dismiss() }
+ }
+ }
}
/**
@@ -77,10 +82,10 @@ open class WebOverlayActivity : AppCompatActivity() {
* Our theme for the overlay should be fully opaque
*/
fun theme() {
- val darkAccent = Prefs.headerColor.darken().withAlpha(255)
- statusBarColor = darkAccent.darken()
- navigationBarColor = darkAccent
- toolbar.setBackgroundColor(darkAccent)
+ val opaqueAccent = Prefs.headerColor.withAlpha(255)
+ statusBarColor = opaqueAccent.darken()
+ navigationBarColor = opaqueAccent
+ toolbar.setBackgroundColor(opaqueAccent)
toolbar.setTitleTextColor(Prefs.iconColor)
coordinator.setBackgroundColor(Prefs.bgColor.withAlpha(255))
toolbar.overflowIcon?.setTint(Prefs.iconColor)
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 59ef6cd7..0f8eee09 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/dbflow/CookiesDb.kt
@@ -43,7 +43,7 @@ fun loadFbCookie(name: String): CookieModel? = (select from CookieModel::class w
* Loads cookies sorted by name
*/
fun loadFbCookiesAsync(callback: (cookies: List<CookieModel>) -> Unit) {
- (select from CookieModel::class).orderBy(CookieModel_Table.name, true).async().queryListResultCallback { _, tResult -> callback.invoke(tResult) }.execute()
+ (select from CookieModel::class).orderBy(CookieModel_Table.name, true).async().queryListResultCallback { _, tResult -> callback(tResult) }.execute()
}
fun loadFbCookiesSync(): List<CookieModel> = (select from CookieModel::class).orderBy(CookieModel_Table.name, true).queryList()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
index 0a90c05f..b7a162ae 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt
@@ -51,7 +51,7 @@ fun WebView.jsInject(vararg injectors: InjectorContract, callback: ((Array<Strin
val validInjectors = injectors.filter { it != JsActions.EMPTY }
val observables = Array(validInjectors.size, { SingleSubject.create<String>() })
Observable.zip<String, Array<String>>(observables.map { it.toObservable() }, { it.map { it.toString() }.toTypedArray() }).subscribeOn(AndroidSchedulers.mainThread()).subscribe({
- callback.invoke(it)
+ callback(it)
})
(0 until validInjectors.size).asSequence().forEach {
i ->
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 9128c42b..a75a4f8d 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt
@@ -4,6 +4,7 @@ import android.graphics.Color
import ca.allanwang.kau.kpref.KPref
import ca.allanwang.kau.kpref.StringSet
import ca.allanwang.kau.kpref.kpref
+import ca.allanwang.kau.utils.isColorVisibleOn
import ca.allanwang.kau.utils.lazyResettable
import com.pitchedapps.frost.injectors.InjectorContract
@@ -56,6 +57,9 @@ object Prefs : KPref() {
val iconColor: Int
get() = t.iconColor
+ val accentColor: Int
+ get() = if (headerColor.isColorVisibleOn(bgColor, 100)) headerColor else textColor
+
val themeInjector: InjectorContract
get() = t.injector
@@ -71,4 +75,7 @@ object Prefs : KPref() {
var animate: Boolean by kpref("fancy_animations", true)
var notificationKeywords: StringSet by kpref("notification_keywords", mutableSetOf<String>())
+
+ //check if this is the first time launching the web overlay; show snackbar if true
+ var firstWebOverlay:Boolean by kpref("first_web_overlay", true)
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt
index 43bb6ec6..cf1cbc67 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt
@@ -14,23 +14,23 @@ enum class Theme(val textRes: Int, val injector: InjectorContract,
private val headerColorGetter: () -> Int, private val iconColorGetter: () -> Int) {
DEFAULT(R.string.kau_default, JsActions.EMPTY, { Color.BLACK }, { 0xfffafafa.toInt() }, { 0xff3b5998.toInt() }, { Color.WHITE }),
LIGHT(R.string.kau_light, CssAssets.MATERIAL_LIGHT, { Color.BLACK }, { 0xfffafafa.toInt() }, { 0xff3b5998.toInt() }, { Color.WHITE }),
- DARK(R.string.kau_dark, CssAssets.MATERIAL_DARK, { Color.WHITE }, { 0xff303030.toInt() }, { 0xff3b5998.toInt() }, { Color.WHITE }),
+ DARK(R.string.kau_dark, CssAssets.MATERIAL_DARK, { Color.WHITE }, { 0xff303030.toInt() }, { 0xff2e4b86.toInt() }, { Color.WHITE }),
AMOLED(R.string.kau_amoled, CssAssets.MATERIAL_AMOLED, { Color.WHITE }, { Color.BLACK }, { Color.BLACK }, { Color.WHITE }),
GLASS(R.string.kau_glass, CssAssets.MATERIAL_GLASS, { Color.WHITE }, { 0x80000000.toInt() }, { 0xb3000000.toInt() }, { Color.WHITE }),
CUSTOM(R.string.kau_custom, JsActions.EMPTY, { Prefs.customTextColor }, { Prefs.customBackgroundColor }, { Prefs.customHeaderColor }, { Prefs.customIconColor })
;
val textColor: Int
- get() = textColorGetter.invoke()
+ get() = textColorGetter()
val bgColor: Int
- get() = backgroundColorGetter.invoke()
+ get() = backgroundColorGetter()
val headerColor: Int
- get() = headerColorGetter.invoke()
+ get() = headerColorGetter()
val iconColor: Int
- get() = iconColorGetter.invoke()
+ get() = iconColorGetter()
companion object {
val values = values() //save one instance
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 a8a71845..70205bc6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt
@@ -7,10 +7,13 @@ import android.content.ComponentName
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
+import android.support.annotation.StringRes
+import android.support.design.internal.SnackbarContentLayout
+import android.support.design.widget.Snackbar
import android.support.v4.app.NotificationCompat
-import android.support.v7.widget.SimpleItemAnimator
import android.support.v7.widget.Toolbar
import android.view.View
+import android.widget.FrameLayout
import android.widget.TextView
import ca.allanwang.kau.utils.*
import com.afollestad.materialdialogs.MaterialDialog
@@ -102,15 +105,14 @@ fun Activity.setFrostTheme(forceTransparent: Boolean = false) {
fun Activity.setFrostColors(toolbar: Toolbar? = null, themeWindow: Boolean = true,
texts: Array<TextView> = arrayOf(), headers: Array<View> = arrayOf(), backgrounds: Array<View> = arrayOf()) {
- val darkAccent = Prefs.headerColor.darken()
- statusBarColor = darkAccent.darken().withAlpha(255)
- navigationBarColor = darkAccent
+ statusBarColor = Prefs.headerColor.darken(0.1f).withAlpha(255)
+ navigationBarColor = Prefs.headerColor
if (themeWindow) window.setBackgroundDrawable(ColorDrawable(Prefs.bgColor))
- toolbar?.setBackgroundColor(darkAccent)
+ toolbar?.setBackgroundColor(Prefs.headerColor)
toolbar?.setTitleTextColor(Prefs.iconColor)
toolbar?.overflowIcon?.setTint(Prefs.iconColor)
texts.forEach { it.setTextColor(Prefs.textColor) }
- headers.forEach { it.setBackgroundColor(darkAccent) }
+ headers.forEach { it.setBackgroundColor(Prefs.headerColor) }
backgrounds.forEach { it.setBackgroundColor(Prefs.bgColor) }
}
@@ -147,4 +149,18 @@ fun frostAnswersCustom(name: String, action: CustomEvent.() -> Unit = {}) {
frostAnswers {
logCustom(CustomEvent("Frost $name").apply { action() })
}
+}
+
+fun View.frostSnackbar(@StringRes text: Int, builder: Snackbar.() -> Unit = {}) {
+ Snackbar.make(this, text, Snackbar.LENGTH_LONG).apply {
+ builder()
+ //hacky workaround, but it has proper checks and shouldn't crash
+ ((view as? FrameLayout)?.getChildAt(0) as? SnackbarContentLayout)?.apply {
+ messageView.setTextColor(Prefs.textColor)
+ actionView.setTextColor(Prefs.accentColor)
+ //only set if previous text colors are set
+ view.setBackgroundColor(Prefs.bgColor.colorToForeground(0.1f))
+ }
+ show()
+ }
} \ No newline at end of file
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
index 694550d0..7f74990e 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt
@@ -9,6 +9,7 @@ import android.widget.FrameLayout
import android.widget.ProgressBar
import ca.allanwang.kau.utils.bindView
import ca.allanwang.kau.utils.tint
+import ca.allanwang.kau.utils.visible
import ca.allanwang.kau.utils.withAlpha
import com.pitchedapps.frost.R
import com.pitchedapps.frost.facebook.FbTab
@@ -18,8 +19,10 @@ import io.reactivex.android.schedulers.AndroidSchedulers
/**
* Created by Allan Wang on 2017-06-01.
*/
-class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0)
- : FrameLayout(context, attrs, defStyleAttr, defStyleRes), SwipeRefreshLayout.OnRefreshListener {
+class FrostWebView @JvmOverloads constructor(
+ context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0
+) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), SwipeRefreshLayout.OnRefreshListener {
+
val refresh: SwipeRefreshLayout by bindView(R.id.swipe_refresh)
val web: FrostWebViewCore by bindView(R.id.frost_webview_core)
val progress: ProgressBar by bindView(R.id.progressBar)
@@ -40,7 +43,7 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS
refresh.setOnRefreshListener(this)
addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
override fun onViewDetachedFromWindow(v: View) {
- web.visibility = View.VISIBLE
+ web.visible()
}
override fun onViewAttachedToWindow(v: View) {}
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 8265f429..fe024ea3 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -7,6 +7,7 @@ import android.view.View
import android.webkit.*
import ca.allanwang.kau.utils.fadeIn
import ca.allanwang.kau.utils.snackbar
+import com.pitchedapps.frost.R
import com.pitchedapps.frost.dbflow.CookieModel
import com.pitchedapps.frost.facebook.FACEBOOK_COM
import com.pitchedapps.frost.facebook.FbCookie
@@ -14,6 +15,7 @@ import com.pitchedapps.frost.injectors.CssHider
import com.pitchedapps.frost.injectors.jsInject
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.frostSnackbar
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.SingleSubject
import io.reactivex.subjects.Subject
@@ -77,7 +79,7 @@ class LoginWebView @JvmOverloads constructor(
override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
if (!url.contains(FACEBOOK_COM)) {
- view.snackbar("No longer under facebook; refreshing...")
+ view.frostSnackbar(R.string.no_longer_facebook)
loadLogin()
return
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 977c83ec..cc1bd9b3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -32,4 +32,7 @@
<string name="requires_custom_theme">Requires custom theme</string>
<string name="frost_feedback">Frost for Facebook: Feedback</string>
+ <string name="no_longer_facebook">No longer under facebook; refreshing…</string>
+
+ <string name="web_overlay_swipe_hint">Swipe right to go back to the previous window.</string>
</resources>