aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-23 11:25:45 -0700
committerAllan Wang <me@allanwang.ca>2017-06-23 11:25:45 -0700
commit9cfccbe6cb3ddbf3fde55184fa484c82ebb4294b (patch)
tree4cc4fd467cc14ec46f9a38539d413a8a61b35f80 /app/src/main/kotlin/com
parent7bb1de11f0208ac6b6a9e7d8fd3db81490e18daf (diff)
downloadfrost-9cfccbe6cb3ddbf3fde55184fa484c82ebb4294b.tar.gz
frost-9cfccbe6cb3ddbf3fde55184fa484c82ebb4294b.tar.bz2
frost-9cfccbe6cb3ddbf3fde55184fa484c82ebb4294b.zip
Added custom theming
Diffstat (limited to 'app/src/main/kotlin/com')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt7
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt9
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt15
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt2
4 files changed, 26 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
index 08293f0e..ab3ffd09 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/MainActivity.kt
@@ -36,6 +36,7 @@ import com.pitchedapps.frost.facebook.FbCookie.switchUser
import com.pitchedapps.frost.facebook.FbTab
import com.pitchedapps.frost.facebook.PROFILE_PICTURE_URL
import com.pitchedapps.frost.fragments.WebFragment
+import com.pitchedapps.frost.injectors.CssAssets
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.views.BadgedIcon
import io.reactivex.android.schedulers.AndroidSchedulers
@@ -103,7 +104,7 @@ class MainActivity : BaseActivity() {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
- setFrostColors(toolbar, headers = arrayOf(tabs, appBar), backgrounds = arrayOf(viewPager))
+ setFrostColors(toolbar, themeWindow = false, headers = arrayOf(tabs, appBar), backgrounds = arrayOf(viewPager))
}
fun tabsForEachView(action: (position: Int, view: BadgedIcon) -> Unit) {
@@ -302,7 +303,9 @@ class MainActivity : BaseActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
- if (resultCode == REQUEST_RESTART) restart()
+ if (resultCode == REQUEST_RESTART) {
+ restart()
+ }
}
override fun onResume() {
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
index f6e5f2bf..92e29cb2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt
@@ -11,6 +11,7 @@ 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
+import com.pitchedapps.frost.injectors.CssAssets
import com.pitchedapps.frost.utils.*
import com.pitchedapps.frost.views.Keywords
@@ -76,13 +77,17 @@ class SettingsActivity : KPrefActivity() {
allowCustom = true
}
- colorPicker(R.string.text_color, { Prefs.customTextColor }, { Prefs.customTextColor = it; reload() }) {
+ fun invalidateCustomTheme() {
+ CssAssets.CUSTOM.injector = null
+ }
+
+ colorPicker(R.string.text_color, { Prefs.customTextColor }, { Prefs.customTextColor = it; reload(); invalidateCustomTheme() }) {
dependsOnCustom()
allowCustomAlpha = false
}
colorPicker(R.string.background_color, { Prefs.customBackgroundColor },
- { Prefs.customBackgroundColor = it; bgCanvas.ripple(it, duration = 500L) }) {
+ { Prefs.customBackgroundColor = it; bgCanvas.ripple(it, duration = 500L); invalidateCustomTheme() }) {
dependsOnCustom()
allowCustomAlpha = true
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt
index 4edddbed..8ccedf92 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt
@@ -1,13 +1,14 @@
package com.pitchedapps.frost.injectors
import android.webkit.WebView
+import ca.allanwang.kau.utils.*
import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
/**
* Created by Allan Wang on 2017-05-31.
* Mapping of the available assets
* The enum name must match the css file name
- * //TODO add folder mapping using Prefs
*/
enum class CssAssets(val folder: String = "themes") : InjectorContract {
MATERIAL_LIGHT, MATERIAL_DARK, MATERIAL_AMOLED, MATERIAL_GLASS, CUSTOM, ROUND_ICONS("components")
@@ -18,7 +19,17 @@ enum class CssAssets(val folder: String = "themes") : InjectorContract {
override fun inject(webView: WebView, callback: ((String) -> Unit)?) {
if (injector == null) {
- val content = webView.context.assets.open("css/$folder/$file").bufferedReader().use { it.readText() }
+ var content = webView.context.assets.open("css/$folder/$file").bufferedReader().use { it.readText() }
+ if (this == CUSTOM) {
+ content = content
+ .replace("\$T\$", Prefs.textColor.toRgbaString())
+ .replace("\$TT\$", Prefs.textColor.colorToBackground(0.05f).toRgbaString())
+ .replace("\$B\$", Prefs.bgColor.toRgbaString())
+ .replace("\$BB\$", Prefs.bgColor.colorToForeground(0.05f).toRgbaString())
+ .replace("\$O\$", Prefs.bgColor.withAlpha(255).toRgbaString())
+ .replace("\$D\$", Prefs.textColor.adjustAlpha(0.3f).toRgbaString())
+ L.d("Content $content")
+ }
injector = JsBuilder().css(content).build()
}
injector!!.inject(webView, callback)
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 cf1cbc67..7535eaa2 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Theme.kt
@@ -17,7 +17,7 @@ enum class Theme(val textRes: Int, val injector: InjectorContract,
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 })
+ CUSTOM(R.string.kau_custom, CssAssets.CUSTOM, { Prefs.customTextColor }, { Prefs.customBackgroundColor }, { Prefs.customHeaderColor }, { Prefs.customIconColor })
;
val textColor: Int