mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-22 13:09:46 +01:00
SettingsController: theme switch preferences
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
5abdacab25
commit
4c31f6f2e9
@ -518,6 +518,20 @@ class SettingsController : NewBaseController(R.layout.controller_settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
themeCategories()
|
themeCategories()
|
||||||
|
themeSwitchPreferences()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun themeSwitchPreferences() {
|
||||||
|
binding.run {
|
||||||
|
listOf(
|
||||||
|
settingsScreenLock,
|
||||||
|
settingsScreenSecurity,
|
||||||
|
settingsIncognitoKeyboard,
|
||||||
|
settingsPhoneBookIntegration,
|
||||||
|
settingsReadPrivacy,
|
||||||
|
settingsProxyUseCredentials
|
||||||
|
).forEach(viewThemeUtils::colorSwitchPreference)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun themeCategories() {
|
private fun themeCategories() {
|
||||||
|
@ -24,13 +24,19 @@ package com.nextcloud.talk.ui.theme
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Color
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
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.button.MaterialButton
|
||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
import com.nextcloud.talk.R
|
||||||
import com.yarolegovich.mp.MaterialPreferenceCategory
|
import com.yarolegovich.mp.MaterialPreferenceCategory
|
||||||
|
import com.yarolegovich.mp.MaterialSwitchPreference
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
|
class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
|
||||||
@ -121,4 +127,43 @@ class ViewThemeUtils @Inject constructor(val theme: ServerTheme) {
|
|||||||
category.setTitleColor(color)
|
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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,4 +76,8 @@
|
|||||||
|
|
||||||
<color name="dialog_background">#353535</color>
|
<color name="dialog_background">#353535</color>
|
||||||
<color name="vote_dialog_background">#424242</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>
|
</resources>
|
||||||
|
@ -111,4 +111,7 @@
|
|||||||
<color name="dialog_background">#FFFFFF</color>
|
<color name="dialog_background">#FFFFFF</color>
|
||||||
<color name="vote_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>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user