mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-27 22:55:08 +01:00
make theme ship schemes and utilize them in themeing util
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
58dc6a9aae
commit
0f997b433d
@ -22,6 +22,7 @@
|
||||
package com.nextcloud.talk.ui.theme
|
||||
|
||||
import androidx.annotation.ColorInt
|
||||
import scheme.Scheme
|
||||
|
||||
interface ServerTheme {
|
||||
@get:ColorInt
|
||||
@ -50,4 +51,14 @@ interface ServerTheme {
|
||||
*/
|
||||
@get:ColorInt
|
||||
val colorText: Int
|
||||
|
||||
/**
|
||||
* Schema for light theme
|
||||
*/
|
||||
val lightScheme: Scheme
|
||||
|
||||
/**
|
||||
* Schema for light theme
|
||||
*/
|
||||
val darkScheme: Scheme
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ package com.nextcloud.talk.ui.theme
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.models.json.capabilities.ThemingCapability
|
||||
import com.nextcloud.talk.utils.ui.ColorUtil
|
||||
import scheme.Scheme
|
||||
|
||||
internal class ServerThemeImpl(themingCapability: ThemingCapability?, colorUtil: ColorUtil) :
|
||||
ServerTheme {
|
||||
@ -35,6 +36,8 @@ internal class ServerThemeImpl(themingCapability: ThemingCapability?, colorUtil:
|
||||
override val colorElementBright: Int
|
||||
override val colorElementDark: Int
|
||||
override val colorText: Int
|
||||
override val lightScheme: Scheme
|
||||
override val darkScheme: Scheme
|
||||
|
||||
init {
|
||||
primaryColor = colorUtil.getNullSafeColorWithFallbackRes(themingCapability?.color, R.color.colorPrimary)
|
||||
@ -44,5 +47,8 @@ internal class ServerThemeImpl(themingCapability: ThemingCapability?, colorUtil:
|
||||
colorElementDark = colorUtil.getNullSafeColor(themingCapability?.colorElementDark, primaryColor)
|
||||
|
||||
colorText = colorUtil.getTextColor(themingCapability?.colorText, primaryColor)
|
||||
|
||||
lightScheme = Scheme.light(primaryColor)
|
||||
darkScheme = Scheme.dark(primaryColor)
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
package com.nextcloud.talk.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
@ -30,17 +31,21 @@ import android.view.View
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.RadioButton
|
||||
import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.appcompat.widget.SearchView.SearchAutoComplete
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.chip.Chip
|
||||
@ -49,16 +54,26 @@ import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.DrawableUtils
|
||||
import com.nextcloud.talk.utils.ui.ColorUtil
|
||||
import com.nextcloud.talk.utils.ui.PlatformThemeUtil.isDarkMode
|
||||
import com.yarolegovich.mp.MaterialPreferenceCategory
|
||||
import com.yarolegovich.mp.MaterialSwitchPreference
|
||||
import scheme.Scheme
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private val colorUtil: ColorUtil) {
|
||||
|
||||
/**
|
||||
* Scheme for painting elements
|
||||
*/
|
||||
fun getScheme(context: Context): Scheme = when {
|
||||
isDarkMode(context) -> theme.darkScheme
|
||||
else -> theme.lightScheme
|
||||
}
|
||||
|
||||
/**
|
||||
* Color for painting elements
|
||||
*/
|
||||
@ -71,10 +86,58 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
|
||||
block(getElementColor(view.context))
|
||||
}
|
||||
|
||||
private fun withScheme(view: View, block: (Scheme) -> Unit) {
|
||||
block(getScheme(view.context))
|
||||
}
|
||||
|
||||
fun themeToolbar(toolbar: MaterialToolbar) {
|
||||
withScheme(toolbar) { scheme ->
|
||||
toolbar.setBackgroundColor(scheme.surface)
|
||||
toolbar.setNavigationIconTint(scheme.onSurface)
|
||||
toolbar.setTitleTextColor(scheme.onSurface)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeSearchView(searchView: SearchView) {
|
||||
withScheme(searchView) { scheme ->
|
||||
// hacky as no default way is provided
|
||||
val editText = searchView.findViewById<SearchAutoComplete>(R.id.search_src_text)
|
||||
val searchPlate = searchView.findViewById<LinearLayout>(R.id.search_plate)
|
||||
editText.textSize = 16f
|
||||
editText.setHintTextColor(scheme.onSurfaceVariant)
|
||||
editText.setTextColor(scheme.onSurface)
|
||||
editText.setBackgroundColor(scheme.surface)
|
||||
searchPlate.setBackgroundColor(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeStatusBar(activity: Activity, view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
DisplayUtils.applyColorToStatusBar(activity, scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun resetStatusBar(activity: Activity, view: View) {
|
||||
DisplayUtils.applyColorToStatusBar(
|
||||
activity,
|
||||
ResourcesCompat.getColor(
|
||||
activity.resources,
|
||||
R.color.bg_default,
|
||||
activity.theme
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun themeFAB(fab: FloatingActionButton) {
|
||||
withElementColor(fab) { color ->
|
||||
fab.backgroundTintList = ColorStateList.valueOf(color)
|
||||
fab.imageTintList = ColorStateList.valueOf(theme.colorText)
|
||||
withScheme(fab) { scheme ->
|
||||
fab.backgroundTintList = ColorStateList.valueOf(scheme.primaryContainer)
|
||||
fab.imageTintList = ColorStateList.valueOf(scheme.onPrimaryContainer)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeCardView(cardView: MaterialCardView) {
|
||||
withScheme(cardView) { scheme ->
|
||||
cardView.backgroundTintList = ColorStateList.valueOf(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user