mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-29 15:45:12 +01:00
Extract viewthemeutils to commons library
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
8c08efbf4f
commit
712e9b9eab
@ -332,8 +332,8 @@ dependencies {
|
||||
|
||||
// implementation 'androidx.activity:activity-ktx:1.4.0'
|
||||
|
||||
//
|
||||
implementation 'com.github.nextcloud.android-common:ui:4da3363e61ed646e091754147558ee3be346abc5'
|
||||
// TODO substitute for tag after first common release
|
||||
implementation 'com.github.nextcloud.android-common:ui:83c4a8aa885e8ef1bba2e44704be8625db396e1b'
|
||||
}
|
||||
|
||||
task installGitHooks(type: Copy, group: "development") {
|
||||
|
@ -19,7 +19,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.ui.theme.viewthemeutils
|
||||
package com.nextcloud.talk.ui.theme
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
@ -46,6 +46,7 @@ import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.chip.ChipDrawable
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
import com.nextcloud.talk.utils.DrawableUtils
|
@ -23,11 +23,10 @@ package com.nextcloud.talk.ui.theme
|
||||
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import com.nextcloud.talk.ui.theme.viewthemeutils.AndroidViewThemeUtils
|
||||
import com.nextcloud.talk.ui.theme.viewthemeutils.AndroidXViewThemeUtils
|
||||
import com.nextcloud.talk.ui.theme.viewthemeutils.DialogViewThemeUtils
|
||||
import com.nextcloud.talk.ui.theme.viewthemeutils.MaterialViewThemeUtils
|
||||
import com.nextcloud.talk.ui.theme.viewthemeutils.TalkSpecificViewThemeUtils
|
||||
import com.nextcloud.android.common.ui.theme.utils.AndroidViewThemeUtils
|
||||
import com.nextcloud.android.common.ui.theme.utils.AndroidXViewThemeUtils
|
||||
import com.nextcloud.android.common.ui.theme.utils.DialogViewThemeUtils
|
||||
import com.nextcloud.android.common.ui.theme.utils.MaterialViewThemeUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
|
@ -1,290 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Álvaro Brey
|
||||
* Copyright (C) 2022 Álvaro Brey
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.ui.theme.viewthemeutils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.os.Build
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.CheckBox
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.RadioButton
|
||||
import android.widget.SeekBar
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.nextcloud.android.common.ui.color.ColorUtil
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import com.nextcloud.android.common.ui.util.PlatformThemeUtil
|
||||
import com.nextcloud.talk.R
|
||||
import eu.davidea.flexibleadapter.utils.FlexibleUtils
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* View theme utils for platform views (android.widget.*, android.view.*)
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class AndroidViewThemeUtils @Inject constructor(schemes: MaterialSchemes, private val colorUtil: ColorUtil) :
|
||||
ViewThemeUtilsBase(schemes) {
|
||||
|
||||
fun colorViewBackground(view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
view.setBackgroundColor(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorToolbarMenuIcon(context: Context, item: MenuItem) {
|
||||
withScheme(context) { scheme ->
|
||||
item.icon.setColorFilter(scheme.onSurface, PorterDuff.Mode.SRC_ATOP)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeStatusBar(activity: Activity, view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
applyColorToStatusBar(activity, scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
private fun applyColorToStatusBar(activity: Activity, @ColorInt color: Int) {
|
||||
val window = activity.window
|
||||
val isLightTheme = !PlatformThemeUtil.isDarkMode(activity)
|
||||
if (window != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
val decor = window.decorView
|
||||
if (isLightTheme) {
|
||||
val systemUiFlagLightStatusBar = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or
|
||||
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
} else {
|
||||
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
}
|
||||
decor.systemUiVisibility = systemUiFlagLightStatusBar
|
||||
} else {
|
||||
decor.systemUiVisibility = 0
|
||||
}
|
||||
window.statusBarColor = color
|
||||
} else if (isLightTheme) {
|
||||
window.statusBarColor = Color.BLACK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun resetStatusBar(activity: Activity) {
|
||||
applyColorToStatusBar(
|
||||
activity,
|
||||
ResourcesCompat.getColor(
|
||||
activity.resources,
|
||||
// TODO do not use talk.R
|
||||
R.color.bg_default,
|
||||
activity.theme
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun themeDialog(view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
view.setBackgroundColor(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeDialogDark(view: View) {
|
||||
withSchemeDark { scheme ->
|
||||
view.setBackgroundColor(scheme.surface)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeDialogDivider(view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
view.setBackgroundColor(scheme.surfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeHorizontalSeekBar(seekBar: SeekBar) {
|
||||
withScheme(seekBar) { scheme ->
|
||||
themeHorizontalProgressBar(seekBar, scheme.primary)
|
||||
seekBar.thumb.setColorFilter(scheme.primary, PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeHorizontalProgressBar(progressBar: ProgressBar?, @ColorInt color: Int) {
|
||||
if (progressBar != null) {
|
||||
progressBar.indeterminateDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
||||
progressBar.progressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorPrimaryTextViewElement(textView: TextView) {
|
||||
withScheme(textView) { scheme ->
|
||||
textView.setTextColor(scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorPrimaryTextViewElementDarkMode(textView: TextView) {
|
||||
withSchemeDark { scheme ->
|
||||
textView.setTextColor(scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorPrimaryView(view: View) {
|
||||
withScheme(view) { scheme ->
|
||||
view.setBackgroundColor(scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Colors the background as element color and the foreground as text color.
|
||||
*/
|
||||
fun colorImageViewButton(imageView: ImageView) {
|
||||
withScheme(imageView) { scheme ->
|
||||
imageView.imageTintList = ColorStateList.valueOf(scheme.onPrimaryContainer)
|
||||
imageView.backgroundTintList = ColorStateList.valueOf(scheme.primaryContainer)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeImageButton(imageButton: ImageButton) {
|
||||
withScheme(imageButton) { scheme ->
|
||||
imageButton.imageTintList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_selected),
|
||||
intArrayOf(-android.R.attr.state_selected),
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
scheme.onSurfaceVariant,
|
||||
scheme.onSurfaceVariant,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tints the image with element color
|
||||
*/
|
||||
fun colorImageView(imageView: ImageView) {
|
||||
withScheme(imageView) { scheme ->
|
||||
imageView.imageTintList = ColorStateList.valueOf(scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorTextButtons(vararg buttons: Button) {
|
||||
withScheme(buttons[0]) { scheme ->
|
||||
for (button in buttons) {
|
||||
button.setTextColor(
|
||||
ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun colorCircularProgressBarOnPrimaryContainer(progressBar: ProgressBar) {
|
||||
withScheme(progressBar) { scheme ->
|
||||
progressBar.indeterminateDrawable.setColorFilter(scheme.onPrimaryContainer, PorterDuff.Mode.SRC_ATOP)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorCircularProgressBar(progressBar: ProgressBar) {
|
||||
withScheme(progressBar) { scheme ->
|
||||
progressBar.indeterminateDrawable.setColorFilter(scheme.primary, PorterDuff.Mode.SRC_ATOP)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorCircularProgressBarOnSurfaceVariant(progressBar: ProgressBar) {
|
||||
withScheme(progressBar) { scheme ->
|
||||
progressBar.indeterminateDrawable.setColorFilter(scheme.onSurfaceVariant, PorterDuff.Mode.SRC_ATOP)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeCheckbox(checkbox: CheckBox) {
|
||||
withScheme(checkbox) { scheme ->
|
||||
checkbox.buttonTintList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(-android.R.attr.state_checked),
|
||||
intArrayOf(android.R.attr.state_checked)
|
||||
),
|
||||
intArrayOf(Color.GRAY, scheme.primary)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeRadioButton(radioButton: RadioButton) {
|
||||
withScheme(radioButton) { scheme ->
|
||||
radioButton.buttonTintList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(-android.R.attr.state_checked),
|
||||
intArrayOf(android.R.attr.state_checked)
|
||||
),
|
||||
intArrayOf(Color.GRAY, scheme.primary)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorEditText(editText: EditText) {
|
||||
withScheme(editText) { scheme ->
|
||||
// TODO check API-level compatibility
|
||||
// editText.background.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
|
||||
editText.backgroundTintList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(-android.R.attr.state_focused),
|
||||
intArrayOf(android.R.attr.state_focused)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.outline,
|
||||
scheme.primary
|
||||
)
|
||||
)
|
||||
editText.setHintTextColor(scheme.onSurfaceVariant)
|
||||
editText.setTextColor(scheme.onSurface)
|
||||
}
|
||||
}
|
||||
|
||||
fun highlightText(textView: TextView, originalText: String, constraint: String) {
|
||||
withScheme(textView) { scheme ->
|
||||
// TODO do not use FlexibleUtils for this
|
||||
FlexibleUtils.highlightText(textView, originalText, constraint, scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Álvaro Brey
|
||||
* Copyright (C) 2022 Álvaro Brey
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.ui.theme.viewthemeutils
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import com.nextcloud.talk.R
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* View theme utils for Android extension views (androidx.*)
|
||||
*/
|
||||
class AndroidXViewThemeUtils @Inject constructor(schemes: MaterialSchemes) :
|
||||
ViewThemeUtilsBase(schemes) {
|
||||
|
||||
fun colorSwitchCompat(switchCompat: SwitchCompat) {
|
||||
withScheme(switchCompat) { scheme ->
|
||||
|
||||
val context = switchCompat.context
|
||||
|
||||
val thumbUncheckedColor = ResourcesCompat.getColor(
|
||||
context.resources,
|
||||
// TODO extract to common
|
||||
R.color.switch_thumb_color_unchecked,
|
||||
context.theme
|
||||
)
|
||||
val trackUncheckedColor = ResourcesCompat.getColor(
|
||||
context.resources,
|
||||
// TODO extract to common
|
||||
R.color.switch_track_color_unchecked,
|
||||
context.theme
|
||||
)
|
||||
|
||||
val trackColor = Color.argb(
|
||||
SWITCH_COMPAT_TRACK_ALPHA,
|
||||
Color.red(scheme.primary),
|
||||
Color.green(scheme.primary),
|
||||
Color.blue(scheme.primary)
|
||||
)
|
||||
|
||||
switchCompat.thumbTintList = ColorStateList(
|
||||
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
|
||||
intArrayOf(scheme.primary, thumbUncheckedColor)
|
||||
)
|
||||
|
||||
switchCompat.trackTintList = ColorStateList(
|
||||
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
|
||||
intArrayOf(trackColor, trackUncheckedColor)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeSwipeRefreshLayout(swipeRefreshLayout: SwipeRefreshLayout) {
|
||||
withScheme(swipeRefreshLayout) { scheme ->
|
||||
swipeRefreshLayout.setColorSchemeColors(scheme.primary)
|
||||
swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.refresh_spinner_background)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val SWITCH_COMPAT_TRACK_ALPHA: Int = 77
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Álvaro Brey
|
||||
* Copyright (C) 2022 Álvaro Brey
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.ui.theme.viewthemeutils
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import com.google.android.material.R
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* View theme utils for dialogs
|
||||
*/
|
||||
class DialogViewThemeUtils @Inject constructor(schemes: MaterialSchemes) :
|
||||
ViewThemeUtilsBase(schemes) {
|
||||
|
||||
fun colorMaterialAlertDialogBackground(context: Context, dialogBuilder: MaterialAlertDialogBuilder) {
|
||||
withScheme(dialogBuilder.context) { scheme ->
|
||||
val materialShapeDrawable = MaterialShapeDrawable(
|
||||
context,
|
||||
null,
|
||||
R.attr.alertDialogStyle,
|
||||
R.style.MaterialAlertDialog_MaterialComponents
|
||||
)
|
||||
materialShapeDrawable.initializeElevationOverlay(context)
|
||||
materialShapeDrawable.fillColor = ColorStateList.valueOf(scheme.surface)
|
||||
|
||||
// dialogCornerRadius first appeared in Android Pie
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
val radius = context.resources.getDimension(com.nextcloud.talk.R.dimen.dialogBorderRadius)
|
||||
materialShapeDrawable.setCornerSize(radius)
|
||||
}
|
||||
|
||||
dialogBuilder.background = materialShapeDrawable
|
||||
}
|
||||
}
|
||||
|
||||
fun colorDialogMenuText(button: MaterialButton) {
|
||||
withScheme(button) { scheme ->
|
||||
button.setTextColor(scheme.onSurface)
|
||||
button.iconTint = ColorStateList.valueOf(scheme.onSurface)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorDialogHeadline(textView: TextView) {
|
||||
withScheme(textView) { scheme ->
|
||||
textView.setTextColor(scheme.onSurface)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorDialogSupportingText(textView: TextView) {
|
||||
withScheme(textView) { scheme ->
|
||||
textView.setTextColor(scheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorDialogIcon(icon: ImageView) {
|
||||
withScheme(icon) { scheme ->
|
||||
icon.setColorFilter(scheme.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorMaterialAlertDialogIcon(context: Context, drawableId: Int): Drawable {
|
||||
val drawable = AppCompatResources.getDrawable(context, drawableId)!!
|
||||
withScheme(context) { scheme ->
|
||||
DrawableCompat.setTint(drawable, scheme.secondary)
|
||||
}
|
||||
return drawable
|
||||
}
|
||||
}
|
@ -1,299 +0,0 @@
|
||||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Álvaro Brey
|
||||
* Copyright (C) 2022 Álvaro Brey
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.ui.theme.viewthemeutils
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import androidx.core.content.ContextCompat
|
||||
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
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.textfield.TextInputLayout
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
import com.nextcloud.android.common.ui.color.ColorUtil
|
||||
import com.nextcloud.android.common.ui.theme.MaterialSchemes
|
||||
import com.nextcloud.android.common.ui.theme.ViewThemeUtilsBase
|
||||
import scheme.Scheme
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* View theme utils for Material views (com.google.android.material.*)
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
class MaterialViewThemeUtils @Inject constructor(schemes: MaterialSchemes, private val colorUtil: ColorUtil) :
|
||||
ViewThemeUtilsBase(schemes) {
|
||||
fun colorToolbarOverflowIcon(toolbar: MaterialToolbar) {
|
||||
withScheme(toolbar) { scheme ->
|
||||
toolbar.overflowIcon?.setColorFilter(scheme.onSurface, PorterDuff.Mode.SRC_ATOP)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeSearchBarText(searchText: MaterialTextView) {
|
||||
withScheme(searchText) { scheme ->
|
||||
searchText.setHintTextColor(scheme.onSurfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeFAB(fab: FloatingActionButton) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorMaterialTextButton(button: MaterialButton) {
|
||||
withScheme(button) { scheme ->
|
||||
button.rippleColor = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_pressed)
|
||||
),
|
||||
intArrayOf(
|
||||
colorUtil.adjustOpacity(scheme.primary, SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorMaterialButtonText(button: MaterialButton) {
|
||||
withScheme(button) { scheme ->
|
||||
val disabledColor = ContextCompat.getColor(button.context, com.nextcloud.talk.R.color.disabled_text)
|
||||
val colorStateList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(scheme.primary, disabledColor)
|
||||
)
|
||||
button.setTextColor(colorStateList)
|
||||
button.iconTint = colorStateList
|
||||
}
|
||||
}
|
||||
|
||||
fun colorMaterialButtonPrimaryFilled(button: MaterialButton) {
|
||||
withScheme(button) { scheme ->
|
||||
button.backgroundTintList =
|
||||
ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
|
||||
button.setTextColor(
|
||||
ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.onPrimary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
button.iconTint = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.onPrimary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorMaterialButtonPrimaryOutlined(button: MaterialButton) {
|
||||
withScheme(button) { scheme ->
|
||||
button.strokeColor = ColorStateList.valueOf(scheme.outline)
|
||||
button.setTextColor(
|
||||
ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
)
|
||||
button.iconTint = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorMaterialButtonPrimaryBorderless(button: MaterialButton) {
|
||||
withScheme(button) { scheme ->
|
||||
button.setTextColor(
|
||||
ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
)
|
||||
button.iconTint = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
colorUtil.adjustOpacity(scheme.onSurface, ON_SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun themeToolbar(toolbar: MaterialToolbar) {
|
||||
withScheme(toolbar) { scheme ->
|
||||
toolbar.setBackgroundColor(scheme.surface)
|
||||
toolbar.setNavigationIconTint(scheme.onSurface)
|
||||
toolbar.setTitleTextColor(scheme.onSurface)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorCardViewBackground(card: MaterialCardView) {
|
||||
withScheme(card) { scheme ->
|
||||
card.setCardBackgroundColor(scheme.surfaceVariant)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorProgressBar(progressIndicator: LinearProgressIndicator) {
|
||||
withScheme(progressIndicator) { scheme ->
|
||||
progressIndicator.setIndicatorColor(scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorTextInputLayout(textInputLayout: TextInputLayout) {
|
||||
withScheme(textInputLayout) { scheme ->
|
||||
val errorColor = scheme.onSurfaceVariant
|
||||
|
||||
val errorColorStateList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(-android.R.attr.state_focused),
|
||||
intArrayOf(android.R.attr.state_focused)
|
||||
),
|
||||
intArrayOf(
|
||||
errorColor,
|
||||
errorColor
|
||||
)
|
||||
)
|
||||
val coloredColorStateList = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(-android.R.attr.state_focused),
|
||||
intArrayOf(android.R.attr.state_focused)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.outline,
|
||||
scheme.primary
|
||||
)
|
||||
)
|
||||
|
||||
textInputLayout.setBoxStrokeColorStateList(coloredColorStateList)
|
||||
textInputLayout.setErrorIconTintList(errorColorStateList)
|
||||
textInputLayout.setErrorTextColor(errorColorStateList)
|
||||
textInputLayout.boxStrokeErrorColor = errorColorStateList
|
||||
textInputLayout.defaultHintTextColor = coloredColorStateList
|
||||
}
|
||||
}
|
||||
|
||||
fun themeTabLayoutOnSurface(tabLayout: TabLayout) {
|
||||
withScheme(tabLayout) { scheme ->
|
||||
tabLayout.setBackgroundColor(scheme.surface)
|
||||
colorTabLayout(tabLayout, scheme)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorTabLayout(tabLayout: TabLayout, scheme: Scheme) {
|
||||
tabLayout.setSelectedTabIndicatorColor(scheme.primary)
|
||||
tabLayout.tabTextColors = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_selected),
|
||||
intArrayOf(-android.R.attr.state_selected)
|
||||
),
|
||||
intArrayOf(
|
||||
scheme.primary,
|
||||
ContextCompat.getColor(tabLayout.context, com.nextcloud.talk.R.color.high_emphasis_text)
|
||||
)
|
||||
)
|
||||
tabLayout.tabRippleColor = ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_pressed)
|
||||
),
|
||||
intArrayOf(
|
||||
colorUtil.adjustOpacity(scheme.primary, SURFACE_OPACITY_BUTTON_DISABLED)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun colorChipBackground(chip: Chip) {
|
||||
withScheme(chip) { scheme ->
|
||||
chip.chipBackgroundColor = ColorStateList.valueOf(scheme.primary)
|
||||
chip.setTextColor(scheme.onPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
fun colorChipOutlined(chip: Chip, strokeWidth: Float) {
|
||||
withScheme(chip) { scheme ->
|
||||
chip.chipBackgroundColor = ColorStateList.valueOf(Color.TRANSPARENT)
|
||||
chip.chipStrokeWidth = strokeWidth
|
||||
chip.chipStrokeColor = ColorStateList.valueOf(scheme.primary)
|
||||
chip.setTextColor(scheme.primary)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.12f
|
||||
private const val ON_SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.38f
|
||||
}
|
||||
}
|
@ -32,7 +32,6 @@
|
||||
<!-- App bar -->
|
||||
<color name="appbar">#1E1E1E</color>
|
||||
<color name="fontAppbar">#FFFFFF</color>
|
||||
<color name="refresh_spinner_background">#222222</color>
|
||||
|
||||
<!-- general text colors -->
|
||||
<color name="no_emphasis_text">#ffffff</color>
|
||||
@ -78,7 +77,5 @@
|
||||
<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>
|
||||
|
@ -33,7 +33,6 @@
|
||||
<color name="appbar">@android:color/white</color>
|
||||
<color name="fontAppbar">#666666</color>
|
||||
<color name="fontSecondaryAppbar">#A5A5A5</color>
|
||||
<color name="refresh_spinner_background">#ffffff</color>
|
||||
|
||||
<!-- general text colors -->
|
||||
<color name="no_emphasis_text">#000000</color>
|
||||
@ -108,7 +107,6 @@
|
||||
<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>
|
||||
|
@ -74,8 +74,6 @@
|
||||
<dimen name="standard_eighth_margin">2dp</dimen>
|
||||
<dimen name="scope_padding">12dp</dimen>
|
||||
|
||||
<dimen name="dialogBorderRadius">28dp</dimen>
|
||||
|
||||
<dimen name="default_checkbox_dialog_start_margin">18dp</dimen>
|
||||
|
||||
<dimen name="mediatab_file_icon_size">50dp</dimen>
|
||||
|
@ -20,8 +20,3 @@
|
||||
|
||||
include ':app'
|
||||
|
||||
includeBuild('../android-common') {
|
||||
dependencySubstitution {
|
||||
substitute module('com.github.nextcloud.android-common:ui') using project(':ui')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user