SettingsController: theme switch preferences

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-07-21 17:24:42 +02:00 committed by Andy Scherzinger
parent 5abdacab25
commit 4c31f6f2e9
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
4 changed files with 66 additions and 0 deletions

View File

@ -518,6 +518,20 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
}
themeCategories()
themeSwitchPreferences()
}
private fun themeSwitchPreferences() {
binding.run {
listOf(
settingsScreenLock,
settingsScreenSecurity,
settingsIncognitoKeyboard,
settingsPhoneBookIntegration,
settingsReadPrivacy,
settingsProxyUseCredentials
).forEach(viewThemeUtils::colorSwitchPreference)
}
}
private fun themeCategories() {

View File

@ -24,13 +24,19 @@ package com.nextcloud.talk.ui.theme
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.graphics.Color
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.children
import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.nextcloud.talk.R
import com.yarolegovich.mp.MaterialPreferenceCategory
import com.yarolegovich.mp.MaterialSwitchPreference
import javax.inject.Inject
class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
@ -121,4 +127,43 @@ class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
category.setTitleColor(color)
}
}
fun colorSwitchPreference(preference: MaterialSwitchPreference) {
val children = preference.children
val switch = children.find { it is SwitchCompat }
if (switch != null) {
val switchCompat = (switch as SwitchCompat)
colorSwitchCompat(switchCompat)
}
}
// TODO cleanup
fun colorSwitchCompat(switchCompat: SwitchCompat) {
withElementColor(switchCompat) { color ->
val context = switchCompat.context
val thumbUncheckedColor = ResourcesCompat.getColor(
context.resources,
R.color.switch_thumb_color_unchecked,
context.theme
)
val trackUncheckedColor = ResourcesCompat.getColor(
context.resources,
R.color.switch_track_color_unchecked,
context.theme
)
val trackColor = Color.argb(77, Color.red(color), Color.green(color), Color.blue(color))
switchCompat.thumbTintList = ColorStateList(
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
intArrayOf(color, thumbUncheckedColor)
)
switchCompat.trackTintList = ColorStateList(
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
intArrayOf(trackColor, trackUncheckedColor)
)
}
}
}

View File

@ -76,4 +76,8 @@
<color name="dialog_background">#353535</color>
<color name="vote_dialog_background">#424242</color>
<color name="switch_thumb_color_unchecked">#cbcbcb</color>
<color name="switch_track_color_unchecked">#5a5a5a</color>
</resources>

View File

@ -111,4 +111,7 @@
<color name="dialog_background">#FFFFFF</color>
<color name="vote_dialog_background">#FFFFFF</color>
<color name="switch_thumb_color_unchecked">#ececec</color>
<color name="switch_track_color_unchecked">#b2b2b2</color>
</resources>