Fix colors for themes 'finn' and 'dark'

- UIObject: Rename `setTheme` to `applyTheme` and `configure` to 
`adjustLayout`
This commit is contained in:
Finn M Glas 2020-06-19 10:29:01 +02:00
parent 840ef1f110
commit cfa7ce5d00
No known key found for this signature in database
GPG key ID: 902A30146014DFBF
10 changed files with 101 additions and 111 deletions

View file

@ -32,8 +32,6 @@ import kotlin.math.abs
class HomeActivity: UIObject, AppCompatActivity(), class HomeActivity: UIObject, AppCompatActivity(),
GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener { GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
private var currentTheme = "" // keep track of theme changes
private lateinit var mDetector: GestureDetectorCompat private lateinit var mDetector: GestureDetectorCompat
// timers // timers
@ -64,8 +62,6 @@ class HomeActivity: UIObject, AppCompatActivity(),
// Initialise layout // Initialise layout
setContentView(R.layout.home) setContentView(R.layout.home)
currentTheme = getSavedTheme(this)
} }
override fun onStart(){ override fun onStart(){
@ -82,11 +78,7 @@ class HomeActivity: UIObject, AppCompatActivity(),
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// TODO: do this immediately after changing preferences if (home_background_image != null && getSavedTheme(this) == "custom")
if (currentTheme != getSavedTheme(this)) recreate()
if (home_background_image != null && getSavedTheme(
this
) == "custom")
home_background_image.setImageBitmap(background) home_background_image.setImageBitmap(background)
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
@ -187,36 +179,52 @@ class HomeActivity: UIObject, AppCompatActivity(),
return if (mDetector.onTouchEvent(event)) { false } else { super.onTouchEvent(event) } return if (mDetector.onTouchEvent(event)) { false } else { super.onTouchEvent(event) }
} }
override fun setTheme() { override fun applyTheme() {
// Start by showing the settings icon // Start by showing the settings icon
showSettingsIcon() showSettingsIcon()
if (currentTheme == "custom") {
home_settings_icon.setTextColor(vibrantColor) home_settings_icon.setTextColor(vibrantColor)
home_container.setBackgroundColor(dominantColor)
if (launcherPreferences.getString("background_uri", "") != "") {
try { try {
background = MediaStore.Images.Media.getBitmap(this.contentResolver, Uri.parse( background = MediaStore.Images.Media.getBitmap(
launcherPreferences.getString("background_uri", ""))) this.contentResolver, Uri.parse(
launcherPreferences.getString("background_uri", "")
)
)
} catch (e: Exception) { } } catch (e: Exception) { }
if (background == null) if (background == null) { // same as in Settings - TODO make function called by both
currentTheme = saveTheme("finn") dominantColor = resources.getColor(R.color.finnmglasTheme_background_color)
vibrantColor = resources.getColor(R.color.finnmglasTheme_accent_color)
launcherPreferences.edit()
.putString("background_uri", "")
.putInt("custom_dominant", dominantColor)
.putInt("custom_vibrant", vibrantColor)
.apply()
saveTheme("finn")
recreate()
}
home_background_image.visibility = View.VISIBLE
} else {
home_background_image.visibility = View.INVISIBLE
} }
} }
override fun setOnClicks() { override fun setOnClicks() {
home_settings_icon.setOnClickListener() { home_settings_icon.setOnClickListener() {
openSettings(this) launch("launcher:settings", this, R.anim.bottom_up)
overridePendingTransition(R.anim.bottom_up, android.R.anim.fade_out)
} }
home_date_view.setOnClickListener() { home_date_view.setOnClickListener() {
launch(calendarApp, this) launch(calendarApp, this)
overridePendingTransition(0, 0)
} }
home_time_view.setOnClickListener() { home_time_view.setOnClickListener() {
launch(clockApp,this) launch(clockApp,this)
overridePendingTransition(0, 0)
} }
} }

View file

@ -15,13 +15,13 @@ interface UIObject {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
} }
setTheme() applyTheme()
setOnClicks() setOnClicks()
configure() adjustLayout()
} }
// Don't use actual themes, rather create them on the fly for faster theme-switching // Don't use actual themes, rather create them on the fly for faster theme-switching
fun setTheme() { } // colors fun applyTheme() { }
fun setOnClicks() { } // onClicks fun setOnClicks() { }
fun configure() { } // layoutElements fun adjustLayout() { }
} }

View file

@ -69,21 +69,19 @@ class ListActivity : AppCompatActivity(), UIObject {
} }
} }
override fun setTheme() { override fun applyTheme() {
if (getSavedTheme(this) == "custom") {
list_container.setBackgroundColor(dominantColor) list_container.setBackgroundColor(dominantColor)
list_appbar.setBackgroundColor(dominantColor) list_appbar.setBackgroundColor(dominantColor)
list_close.setTextColor(vibrantColor) list_close.setTextColor(vibrantColor)
list_tabs.setSelectedTabIndicatorColor(vibrantColor) list_tabs.setSelectedTabIndicatorColor(vibrantColor)
} }
}
override fun setOnClicks() { override fun setOnClicks() {
list_close.setOnClickListener() { finish() } list_close.setOnClickListener() { finish() }
} }
override fun configure() { override fun adjustLayout() {
// get info about which action this activity is open for // get info about which action this activity is open for
val bundle = intent.extras val bundle = intent.extras
if (bundle != null) { if (bundle != null) {

View file

@ -34,15 +34,13 @@ class ListFragmentApps : Fragment(), UIObject {
super<UIObject>.onStart() super<UIObject>.onStart()
} }
override fun setTheme() { override fun applyTheme() {
if (getSavedTheme(context!!) == "custom") {
list_apps_container.setBackgroundColor(dominantColor) list_apps_container.setBackgroundColor(dominantColor)
} }
}
override fun setOnClicks() { } override fun setOnClicks() { }
override fun configure() { override fun adjustLayout() {
// set up the list / recycler // set up the list / recycler
list_apps_rview.apply { list_apps_rview.apply {
// improve performance (since content changes don't change the layout size) // improve performance (since content changes don't change the layout size)

View file

@ -75,8 +75,7 @@ class SettingsActivity: AppCompatActivity(), UIObject {
} }
} }
override fun setTheme() { override fun applyTheme() {
if (getSavedTheme(this) == "custom") {
settings_container.setBackgroundColor(dominantColor) settings_container.setBackgroundColor(dominantColor)
settings_appbar.setBackgroundColor(dominantColor) settings_appbar.setBackgroundColor(dominantColor)
@ -84,7 +83,6 @@ class SettingsActivity: AppCompatActivity(), UIObject {
settings_close.setTextColor(vibrantColor) settings_close.setTextColor(vibrantColor)
settings_tabs.setSelectedTabIndicatorColor(vibrantColor) settings_tabs.setSelectedTabIndicatorColor(vibrantColor)
} }
}
override fun setOnClicks(){ override fun setOnClicks(){
// As older APIs somehow do not recognize the xml defined onClick // As older APIs somehow do not recognize the xml defined onClick

View file

@ -52,11 +52,8 @@ class ActionsRecyclerAdapter(val activity: Activity):
viewHolder.removeAction.visibility = View.GONE viewHolder.removeAction.visibility = View.GONE
viewHolder.chooseButton.visibility = View.VISIBLE viewHolder.chooseButton.visibility = View.VISIBLE
viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) } viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) }
if (getSavedTheme(activity) =="custom")
setButtonColor( setButtonColor(viewHolder.chooseButton, vibrantColor)
viewHolder.chooseButton,
vibrantColor
)
} }
if (content!!.startsWith("launcher")) { if (content!!.startsWith("launcher")) {
@ -85,11 +82,7 @@ class ActionsRecyclerAdapter(val activity: Activity):
viewHolder.removeAction.visibility = View.GONE viewHolder.removeAction.visibility = View.GONE
viewHolder.chooseButton.visibility = View.VISIBLE viewHolder.chooseButton.visibility = View.VISIBLE
viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) } viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) }
if (getSavedTheme(activity) =="custom") setButtonColor(viewHolder.chooseButton, vibrantColor)
setButtonColor(
viewHolder.chooseButton,
vibrantColor
)
} }
} }
} }

View file

@ -49,19 +49,11 @@ class SettingsFragmentActions : Fragment(), UIObject {
} }
} }
override fun setTheme() { override fun applyTheme() {
if (getSavedTheme(context!!) == "custom") {
settings_actions_container.setBackgroundColor(dominantColor) settings_actions_container.setBackgroundColor(dominantColor)
setButtonColor( setButtonColor(settings_actions_button_view_apps, vibrantColor)
settings_actions_button_view_apps, setButtonColor(settings_actions_button_install_apps, vibrantColor)
vibrantColor
)
setButtonColor(
settings_actions_button_install_apps,
vibrantColor
)
}
} }
override fun setOnClicks() { override fun setOnClicks() {

View file

@ -58,9 +58,7 @@ class SettingsFragmentMeta : Fragment(), UIObject {
return intent return intent
} }
override fun setTheme() { override fun applyTheme() {
if (getSavedTheme(context!!) == "custom") {
settings_meta_container.setBackgroundColor(dominantColor) settings_meta_container.setBackgroundColor(dominantColor)
setButtonColor(settings_meta_button_select_launcher, vibrantColor) setButtonColor(settings_meta_button_select_launcher, vibrantColor)
@ -73,7 +71,6 @@ class SettingsFragmentMeta : Fragment(), UIObject {
settings_meta_icon_github.setTextColor(vibrantColor) settings_meta_icon_github.setTextColor(vibrantColor)
settings_meta_icon_globe.setTextColor(vibrantColor) settings_meta_icon_globe.setTextColor(vibrantColor)
} }
}
override fun setOnClicks() { override fun setOnClicks() {

View file

@ -104,44 +104,52 @@ class SettingsFragmentTheme : Fragment(), UIObject {
} }
} }
override fun setTheme() { override fun applyTheme() {
// Hide 'select' button for the selected theme or allow customisation // Hide 'select' button for the selected theme or allow customisation
when (getSavedTheme(context!!)) { when (getSavedTheme(context!!)) {
"dark" -> settings_theme_dark_button_select.visibility = View.INVISIBLE "dark" -> settings_theme_dark_button_select.visibility = View.INVISIBLE
"finn" -> settings_theme_finn_button_select.visibility = View.INVISIBLE "finn" -> settings_theme_finn_button_select.visibility = View.INVISIBLE
"custom" -> { "custom" ->
settings_theme_custom_button_select.text = getString(R.string.settings_select_image) settings_theme_custom_button_select.text = getString(R.string.settings_select_image)
}
settings_theme_container.setBackgroundColor(dominantColor) settings_theme_container.setBackgroundColor(dominantColor)
setButtonColor( setButtonColor(settings_theme_finn_button_select, vibrantColor)
settings_theme_finn_button_select, setButtonColor(settings_theme_dark_button_select, vibrantColor)
vibrantColor setButtonColor(settings_theme_custom_button_select, vibrantColor)
) setButtonColor(settings_theme_custom_button_examples, vibrantColor)
setButtonColor(
settings_theme_dark_button_select,
vibrantColor
)
setButtonColor(
settings_theme_custom_button_select,
vibrantColor
)
setButtonColor(
settings_theme_custom_button_examples,
vibrantColor
)
}
}
} }
override fun setOnClicks() { override fun setOnClicks() {
// Theme changing buttons // Theme changing buttons
settings_theme_dark_button_select.setOnClickListener { settings_theme_dark_button_select.setOnClickListener {
intendedSettingsPause = true dominantColor = resources.getColor(R.color.darkTheme_background_color)
vibrantColor = resources.getColor(R.color.darkTheme_accent_color)
launcherPreferences.edit()
.putString("background_uri", "")
.putInt("custom_dominant", dominantColor)
.putInt("custom_vibrant", vibrantColor)
.apply()
saveTheme("dark") saveTheme("dark")
intendedSettingsPause = true
activity!!.recreate() activity!!.recreate()
} }
settings_theme_finn_button_select.setOnClickListener { settings_theme_finn_button_select.setOnClickListener {
intendedSettingsPause = true dominantColor = resources.getColor(R.color.finnmglasTheme_background_color)
vibrantColor = resources.getColor(R.color.finnmglasTheme_accent_color)
launcherPreferences.edit()
.putString("background_uri", "")
.putInt("custom_dominant", dominantColor)
.putInt("custom_vibrant", vibrantColor)
.apply()
saveTheme("finn") saveTheme("finn")
intendedSettingsPause = true
activity!!.recreate() activity!!.recreate()
} }
settings_theme_custom_button_select.setOnClickListener { settings_theme_custom_button_select.setOnClickListener {

View file

@ -89,12 +89,10 @@ class TutorialActivity: AppCompatActivity(), UIObject {
} }
} }
override fun setTheme() { override fun applyTheme() {
if (getSavedTheme(this) == "custom") {
tutorial_appbar.setBackgroundColor(dominantColor) tutorial_appbar.setBackgroundColor(dominantColor)
tutorial_container.setBackgroundColor(dominantColor) tutorial_container.setBackgroundColor(dominantColor)
tutorial_close.setTextColor(vibrantColor) tutorial_close.setTextColor(vibrantColor)
}
tutorial_page_hint.blink() // animate tutorial_page_hint.blink() // animate
} }