diff --git a/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesImpl.kt b/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesImpl.kt deleted file mode 100644 index 2824e26bd..000000000 --- a/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesImpl.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Andy Scherzinger - * Copyright (C) 2022 Andy Scherzinger - * - * 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 . - */ - -package com.nextcloud.talk.ui.theme - -import com.nextcloud.android.common.ui.theme.MaterialSchemes -import com.nextcloud.android.common.ui.theme.ServerTheme -import scheme.Scheme - -class MaterialSchemesImpl(serverTheme: ServerTheme) : - MaterialSchemes { - override val lightScheme: Scheme - override val darkScheme: Scheme - - init { - lightScheme = Scheme.light(serverTheme.primaryColor) - darkScheme = Scheme.dark(serverTheme.primaryColor) - } -} diff --git a/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesProviderImpl.kt b/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesProviderImpl.kt index 6cd0c2a91..ffccd9f94 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesProviderImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/theme/MaterialSchemesProviderImpl.kt @@ -23,11 +23,11 @@ package com.nextcloud.talk.ui.theme +import com.nextcloud.android.common.ui.color.ColorUtil import com.nextcloud.android.common.ui.theme.MaterialSchemes import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.models.json.capabilities.Capabilities import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew -import com.nextcloud.talk.utils.ui.ColorUtil import java.util.concurrent.ConcurrentHashMap import javax.inject.Inject @@ -57,7 +57,8 @@ internal class MaterialSchemesProviderImpl @Inject constructor( } override fun getMaterialSchemesForCapabilities(capabilities: Capabilities?): MaterialSchemes { - return MaterialSchemesImpl(ServerThemeImpl(capabilities?.themingCapability, colorUtil)) + val serverTheme = ServerThemeImpl(capabilities?.themingCapability, colorUtil) + return MaterialSchemes.fromServerTheme(serverTheme) } companion object { diff --git a/app/src/main/java/com/nextcloud/talk/ui/theme/ServerThemeImpl.kt b/app/src/main/java/com/nextcloud/talk/ui/theme/ServerThemeImpl.kt index d4c23508a..37ccf6477 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/theme/ServerThemeImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/theme/ServerThemeImpl.kt @@ -26,7 +26,7 @@ package com.nextcloud.talk.ui.theme import com.nextcloud.android.common.ui.theme.ServerTheme import com.nextcloud.talk.R import com.nextcloud.talk.models.json.capabilities.ThemingCapability -import com.nextcloud.talk.utils.ui.ColorUtil +import com.nextcloud.android.common.ui.color.ColorUtil internal class ServerThemeImpl(themingCapability: ThemingCapability?, colorUtil: ColorUtil) : ServerTheme { diff --git a/app/src/main/java/com/nextcloud/talk/ui/theme/ViewThemeUtils.kt b/app/src/main/java/com/nextcloud/talk/ui/theme/ViewThemeUtils.kt index 0cd797099..85cddb760 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/theme/ViewThemeUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/ui/theme/ViewThemeUtils.kt @@ -74,7 +74,7 @@ import com.nextcloud.android.common.ui.theme.MaterialSchemes 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.android.common.ui.color.ColorUtil import com.nextcloud.talk.utils.ui.PlatformThemeUtil.isDarkMode import com.vanniktech.emoji.EmojiTextView import com.yarolegovich.mp.MaterialPreferenceCategory diff --git a/app/src/main/java/com/nextcloud/talk/utils/ui/ColorUtil.kt b/app/src/main/java/com/nextcloud/talk/utils/ui/ColorUtil.kt deleted file mode 100644 index 3f4a8a558..000000000 --- a/app/src/main/java/com/nextcloud/talk/utils/ui/ColorUtil.kt +++ /dev/null @@ -1,92 +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 . - */ -package com.nextcloud.talk.utils.ui - -import android.content.Context -import android.graphics.Color -import androidx.annotation.ColorInt -import androidx.annotation.ColorRes -import androidx.core.content.ContextCompat -import androidx.core.graphics.ColorUtils -import com.nextcloud.talk.R -import javax.inject.Inject -import kotlin.math.roundToInt - -class ColorUtil @Inject constructor(private val context: Context) { - - @ColorInt - fun getNullSafeColor(color: String?, @ColorInt fallbackColor: Int): Int { - return color.parseColorOrFallback { fallbackColor } - } - - @ColorInt - fun getNullSafeColorWithFallbackRes(color: String?, @ColorRes fallbackColorRes: Int): Int { - return color.parseColorOrFallback { ContextCompat.getColor(context, fallbackColorRes) } - } - - @ColorInt - fun getTextColor(colorText: String?, @ColorInt backgroundColor: Int): Int { - return colorText.parseColorOrFallback { getForegroundColorForBackgroundColor(backgroundColor) } - } - - @ColorInt - fun getForegroundColorForBackgroundColor(@ColorInt color: Int): Int { - val hsl = FloatArray(HSL_SIZE) - ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl) - - return if (hsl[INDEX_LIGHTNESS] < LIGHTNESS_DARK_THRESHOLD) { - Color.WHITE - } else { - ContextCompat.getColor(context, R.color.grey_900) - } - } - - fun setLightness(@ColorInt color: Int, lightness: Float): Int { - require(lightness in 0.0..1.0) { "Lightness must be between 0 and 1" } - val hsl = FloatArray(HSL_SIZE) - ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hsl) - - hsl[INDEX_LIGHTNESS] = lightness - - return ColorUtils.HSLToColor(hsl) - } - - @ColorInt - private fun String?.parseColorOrFallback(fallback: () -> Int): Int { - return this?.let { Color.parseColor(this) } ?: fallback() - } - - @ColorInt - fun adjustOpacity(color: Int, opacity: Float): Int { - return Color.argb( - (Color.alpha(color) * opacity).roundToInt(), - Color.red(color), - Color.green(color), - Color.blue(color) - ) - } - - companion object { - private const val HSL_SIZE: Int = 3 - private const val INDEX_LIGHTNESS: Int = 2 - private const val LIGHTNESS_DARK_THRESHOLD: Float = 0.6f - } -}