Add MaterialSchemes and remove any in-line color theming to be replaced with a themeUtils call

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-08-11 18:04:13 +02:00
parent 9298de0d43
commit a8422e665a
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
19 changed files with 132 additions and 122 deletions

View File

@ -61,7 +61,6 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.flexibleadapter.items.IFilterable;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.flexibleadapter.items.ISectionable;
import eu.davidea.flexibleadapter.utils.FlexibleUtils;
import eu.davidea.viewholders.FlexibleViewHolder;
public class ConversationItem extends AbstractFlexibleItem<ConversationItem.ConversationItemViewHolder> implements

View File

@ -42,7 +42,6 @@ import com.nextcloud.talk.databinding.ItemCustomOutcomingTextMessageBinding
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.chat.ReadStatus
import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils.searchAndReplaceWithMentionSpan
@ -61,9 +60,6 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var serverTheme: ServerTheme
lateinit var reactionsInterface: ReactionsInterface
override fun onBind(message: ChatMessage) {

View File

@ -51,7 +51,6 @@ import com.nextcloud.talk.components.filebrowser.webdav.ReadFilesystemOperation;
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.databinding.ReactionsInsideMessageBinding;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.ui.theme.ServerTheme;
import com.nextcloud.talk.ui.theme.ViewThemeUtils;
import com.nextcloud.talk.utils.DisplayUtils;
import com.nextcloud.talk.utils.DrawableUtils;
@ -95,9 +94,6 @@ public abstract class MagicPreviewMessageViewHolder extends MessageHolders.Incom
@Inject
Context context;
@Inject
ServerTheme serverTheme;
@Inject
ViewThemeUtils viewThemeUtils;

View File

@ -35,7 +35,6 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.Toast
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.ColorUtils
import autodagger.AutoInjector
import coil.load
import com.google.android.flexbox.FlexboxLayout
@ -45,7 +44,6 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA
import com.nextcloud.talk.databinding.ItemCustomOutcomingLocationMessageBinding
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.chat.ReadStatus
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.UriUtils
@ -66,16 +64,12 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
var locationName: String? = ""
var locationGeoLink: String? = ""
@JvmField
@Inject
var context: Context? = null
lateinit var context: Context
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var serverTheme: ServerTheme
lateinit var reactionsInterface: ReactionsInterface
@SuppressLint("SetTextI18n")
@ -218,12 +212,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context!!.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessage.setTextColor(serverTheme.colorText)
binding.messageQuote.quotedMessageAuthor.setTextColor(
ColorUtils.setAlphaComponent(serverTheme.colorText, ALPHA_80_INT)
)
binding.messageQuote.quoteColoredView.setBackgroundColor(serverTheme.colorText)
viewThemeUtils.colorOutgoingQuoteText(binding.messageQuote.quotedMessage)
viewThemeUtils.colorOutgoingQuoteAuthorText(binding.messageQuote.quotedMessageAuthor)
viewThemeUtils.colorOutgoingQuoteBackground(binding.messageQuote.quoteColoredView)
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
} else {
@ -259,6 +250,5 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
private const val TAG = "LocOutMessageView"
private const val HALF_ALPHA_INT: Int = 255 / 2
private val ALPHA_60_INT: Int = (255 * 0.6).roundToInt()
private val ALPHA_80_INT: Int = (255 * 0.8).roundToInt()
}
}

View File

@ -26,7 +26,6 @@ import android.content.Context
import android.graphics.PorterDuff
import android.view.View
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.graphics.ColorUtils
import autodagger.AutoInjector
import coil.load
import com.nextcloud.talk.R
@ -38,13 +37,11 @@ import com.nextcloud.talk.databinding.ItemCustomOutcomingPollMessageBinding
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.chat.ReadStatus
import com.nextcloud.talk.polls.ui.PollMainDialogFragment
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.stfalcon.chatkit.messages.MessageHolders
import javax.inject.Inject
import kotlin.math.roundToInt
@AutoInjector(NextcloudTalkApplication::class)
class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : MessageHolders
@ -59,9 +56,6 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var serverTheme: ServerTheme
@Inject
lateinit var appPreferences: AppPreferences
@ -182,12 +176,9 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessage.setTextColor(serverTheme.colorText)
binding.messageQuote.quotedMessageAuthor.setTextColor(
ColorUtils.setAlphaComponent(serverTheme.colorText, ALPHA_80_INT)
)
binding.messageQuote.quoteColoredView.setBackgroundColor(serverTheme.colorText)
viewThemeUtils.colorOutgoingQuoteText(binding.messageQuote.quotedMessage)
viewThemeUtils.colorOutgoingQuoteAuthorText(binding.messageQuote.quotedMessageAuthor)
viewThemeUtils.colorOutgoingQuoteBackground(binding.messageQuote.quoteColoredView)
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
} else {
@ -205,6 +196,5 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
companion object {
private val TAG = NextcloudTalkApplication::class.java.simpleName
private val ALPHA_80_INT: Int = (255 * 0.8).roundToInt()
}
}

View File

@ -31,7 +31,6 @@ import android.view.View
import android.widget.SeekBar
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.work.WorkInfo
import androidx.work.WorkManager
import autodagger.AutoInjector
@ -42,14 +41,12 @@ import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedA
import com.nextcloud.talk.databinding.ItemCustomOutcomingVoiceMessageBinding
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.chat.ReadStatus
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.stfalcon.chatkit.messages.MessageHolders
import java.util.concurrent.ExecutionException
import javax.inject.Inject
import kotlin.math.roundToInt
@AutoInjector(NextcloudTalkApplication::class)
class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
@ -65,9 +62,6 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var serverTheme: ServerTheme
@JvmField
@Inject
var appPreferences: AppPreferences? = null
@ -269,15 +263,9 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context!!.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessage.setTextColor(serverTheme.colorText)
binding.messageQuote.quotedMessageAuthor.setTextColor(
ColorUtils.setAlphaComponent(
serverTheme.colorText,
ALPHA_80_INT
)
)
binding.messageQuote.quoteColoredView.setBackgroundColor(serverTheme.colorText)
viewThemeUtils.colorOutgoingQuoteText(binding.messageQuote.quotedMessage)
viewThemeUtils.colorOutgoingQuoteAuthorText(binding.messageQuote.quotedMessageAuthor)
viewThemeUtils.colorOutgoingQuoteBackground(binding.messageQuote.quoteColoredView)
binding.messageQuote.quotedChatMessageView.visibility = View.VISIBLE
} else {
@ -300,8 +288,5 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) : MessageHolders
companion object {
private const val TAG = "VoiceOutMessageView"
private const val SEEKBAR_START: Int = 0
private const val HALF_ALPHA_INT: Int = 255 / 2
private val ALPHA_80_INT: Int = (255 * 0.8).roundToInt()
private val ALPHA_60_INT: Int = (255 * 0.6).roundToInt()
}
}

View File

@ -154,7 +154,6 @@ import com.nextcloud.talk.ui.dialog.MessageActionsDialog
import com.nextcloud.talk.ui.dialog.ShowReactionsDialog
import com.nextcloud.talk.ui.recyclerview.MessageSwipeActions
import com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.AttendeePermissionsUtil
import com.nextcloud.talk.utils.ConductorRemapping
@ -235,9 +234,6 @@ class ChatController(args: Bundle) :
@Inject
lateinit var permissionUtil: PlatformPermissionUtil
@Inject
lateinit var serverTheme: ServerTheme
val disposables = DisposableSet()
var roomToken: String? = null
@ -2702,8 +2698,7 @@ class ChatController(args: Bundle) :
chatMessage,
conversationUser,
hasChatPermission,
ncApi!!,
serverTheme
ncApi
).show()
}
}

View File

@ -46,7 +46,6 @@ import com.nextcloud.talk.controllers.base.NewBaseController
import com.nextcloud.talk.controllers.util.viewBinding
import com.nextcloud.talk.databinding.ControllerEntryMenuBinding
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.users.UserManager
import com.nextcloud.talk.utils.ShareUtils
import com.nextcloud.talk.utils.UriUtils
@ -73,9 +72,6 @@ class EntryMenuController(args: Bundle) :
@Inject
lateinit var userManager: UserManager
@Inject
lateinit var serverTheme: ServerTheme
private val operation: ConversationOperationEnum
private var conversation: Conversation? = null
private var shareIntent: Intent? = null

View File

@ -31,7 +31,6 @@ import com.nextcloud.talk.R
import com.nextcloud.talk.activities.CallActivity
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.databinding.DialogAudioOutputBinding
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.webrtc.WebRtcAudioManager
import javax.inject.Inject
@ -42,9 +41,6 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
@Inject
lateinit var viewThemeUtils: ViewThemeUtils
@Inject
lateinit var serverTheme: ServerTheme
private lateinit var dialogAudioOutputBinding: DialogAudioOutputBinding
override fun onCreate(savedInstanceState: Bundle?) {
@ -97,22 +93,22 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
when (callActivity.audioManager?.currentAudioDevice) {
WebRtcAudioManager.AudioDevice.BLUETOOTH -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputBluetoothIcon)
dialogAudioOutputBinding.audioOutputBluetoothText.setTextColor(serverTheme.primaryColor)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputBluetoothText)
}
WebRtcAudioManager.AudioDevice.SPEAKER_PHONE -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputSpeakerIcon)
dialogAudioOutputBinding.audioOutputSpeakerText.setTextColor(serverTheme.primaryColor)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputSpeakerText)
}
WebRtcAudioManager.AudioDevice.EARPIECE -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputEarspeakerIcon)
dialogAudioOutputBinding.audioOutputEarspeakerText.setTextColor(serverTheme.primaryColor)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputEarspeakerText)
}
WebRtcAudioManager.AudioDevice.WIRED_HEADSET -> {
viewThemeUtils.colorImageView(dialogAudioOutputBinding.audioOutputWiredHeadsetIcon)
dialogAudioOutputBinding.audioOutputWiredHeadsetText.setTextColor(serverTheme.primaryColor)
viewThemeUtils.colorPrimaryTextViewElementDarkMode(dialogAudioOutputBinding.audioOutputWiredHeadsetText)
}
else -> Log.d(TAG, "AudioOutputDialog doesn't know this AudioDevice")

View File

@ -51,7 +51,6 @@ import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.generic.GenericOverall
import com.nextcloud.talk.models.json.reactions.ReactionsOverall
import com.nextcloud.talk.ui.theme.ServerTheme
import com.nextcloud.talk.ui.theme.ViewThemeUtils
import com.nextcloud.talk.utils.ApiUtils
import io.reactivex.Observer
@ -68,8 +67,7 @@ class ShowReactionsDialog(
private val chatMessage: ChatMessage,
private val user: User?,
private val hasChatPermission: Boolean,
private val ncApi: NcApi,
private val serverTheme: ServerTheme
private val ncApi: NcApi
) : BottomSheetDialog(activity), ReactionItemClickListener {
@Inject

View File

@ -0,0 +1,35 @@
/*
* Nextcloud Talk application
*
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
*
* 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
import scheme.Scheme
interface MaterialSchemes {
/**
* Schema for light theme
*/
val lightScheme: Scheme
/**
* Schema for light theme
*/
val darkScheme: Scheme
}

View File

@ -0,0 +1,33 @@
/*
* Nextcloud Talk application
*
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
*
* 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
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)
}
}

View File

@ -24,8 +24,8 @@ package com.nextcloud.talk.ui.theme
import com.nextcloud.talk.data.user.model.User
import com.nextcloud.talk.models.json.capabilities.Capabilities
interface ServerThemeProvider {
fun getServerThemeForUser(user: User?): ServerTheme
fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme
fun getServerThemeForCurrentUser(): ServerTheme
interface MaterialSchemesProvider {
fun getMaterialSchemesForUser(user: User?): MaterialSchemes
fun getMaterialSchemesForCapabilities(capabilities: Capabilities?): MaterialSchemes
fun getMaterialSchemesForCurrentUser(): MaterialSchemes
}

View File

@ -30,14 +30,14 @@ import com.nextcloud.talk.utils.ui.ColorUtil
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
internal class ServerThemeProviderImpl @Inject constructor(
internal class MaterialSchemesProviderImpl @Inject constructor(
private val userProvider: CurrentUserProviderNew,
private val colorUtil: ColorUtil
) : ServerThemeProvider {
) : MaterialSchemesProvider {
private val themeCache: ConcurrentHashMap<String, ServerTheme> = ConcurrentHashMap()
private val themeCache: ConcurrentHashMap<String, MaterialSchemes> = ConcurrentHashMap()
override fun getServerThemeForUser(user: User?): ServerTheme {
override fun getMaterialSchemesForUser(user: User?): MaterialSchemes {
val url: String = if (user?.baseUrl != null) {
user.baseUrl!!
} else {
@ -45,18 +45,18 @@ internal class ServerThemeProviderImpl @Inject constructor(
}
if (!themeCache.containsKey(url)) {
themeCache[url] = getServerThemeForCapabilities(user?.capabilities)
themeCache[url] = getMaterialSchemesForCapabilities(user?.capabilities)
}
return themeCache[url]!!
}
override fun getServerThemeForCurrentUser(): ServerTheme {
return getServerThemeForUser(userProvider.currentUser.blockingGet())
override fun getMaterialSchemesForCurrentUser(): MaterialSchemes {
return getMaterialSchemesForUser(userProvider.currentUser.blockingGet())
}
override fun getServerThemeForCapabilities(capabilities: Capabilities?): ServerTheme {
return ServerThemeImpl(capabilities?.themingCapability, colorUtil)
override fun getMaterialSchemesForCapabilities(capabilities: Capabilities?): MaterialSchemes {
return MaterialSchemesImpl(ServerThemeImpl(capabilities?.themingCapability, colorUtil))
}
companion object {

View File

@ -22,7 +22,6 @@
package com.nextcloud.talk.ui.theme
import androidx.annotation.ColorInt
import scheme.Scheme
interface ServerTheme {
@get:ColorInt
@ -51,14 +50,4 @@ interface ServerTheme {
*/
@get:ColorInt
val colorText: Int
/**
* Schema for light theme
*/
val lightScheme: Scheme
/**
* Schema for light theme
*/
val darkScheme: Scheme
}

View File

@ -26,29 +26,20 @@ 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 {
internal class ServerThemeImpl(themingCapability: ThemingCapability?, colorUtil: ColorUtil) : ServerTheme {
override val primaryColor: Int
override val colorElement: Int
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)
colorElement = colorUtil.getNullSafeColor(themingCapability?.colorElement, primaryColor)
colorElementBright = colorUtil.getNullSafeColor(themingCapability?.colorElementBright, primaryColor)
colorElementDark = colorUtil.getNullSafeColor(themingCapability?.colorElementDark, primaryColor)
colorText = colorUtil.getTextColor(themingCapability?.colorText, primaryColor)
lightScheme = Scheme.light(primaryColor)
darkScheme = Scheme.dark(primaryColor)
}
}

View File

@ -33,12 +33,12 @@ internal abstract class ThemeModule {
@Binds
@Reusable
abstract fun bindServerThemeProvider(provider: ServerThemeProviderImpl): ServerThemeProvider
abstract fun bindMaterialSchemesProvider(provider: MaterialSchemesProviderImpl): MaterialSchemesProvider
companion object {
@Provides
fun provideCurrentServerTheme(themeProvider: ServerThemeProvider): ServerTheme {
return themeProvider.getServerThemeForCurrentUser()
fun provideCurrentMaterialSchemes(themeProvider: MaterialSchemesProvider): MaterialSchemes {
return themeProvider.getMaterialSchemesForCurrentUser()
}
}
}

View File

@ -81,19 +81,20 @@ import com.yarolegovich.mp.MaterialSwitchPreference
import eu.davidea.flexibleadapter.utils.FlexibleUtils
import scheme.Scheme
import javax.inject.Inject
import kotlin.math.roundToInt
@Suppress("TooManyFunctions")
class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private val colorUtil: ColorUtil) {
class ViewThemeUtils @Inject constructor(private val schemes: MaterialSchemes, private val colorUtil: ColorUtil) {
/**
* Scheme for painting elements
*/
fun getScheme(context: Context): Scheme = when {
isDarkMode(context) -> theme.darkScheme
else -> theme.lightScheme
isDarkMode(context) -> schemes.darkScheme
else -> schemes.lightScheme
}
private fun getSchemeDark(): Scheme = theme.darkScheme
private fun getSchemeDark(): Scheme = schemes.darkScheme
private fun withScheme(view: View, block: (Scheme) -> Unit) {
block(getScheme(view.context))
@ -220,6 +221,12 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
}
}
fun colorPrimaryTextViewElementDarkMode(textView: TextView) {
withSchemeDark { scheme ->
textView.setTextColor(scheme.primary)
}
}
fun colorPrimaryView(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.primary)
@ -264,11 +271,22 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
}
}
/**
* Tints the image with text color
*/
fun colorImageViewText(imageView: ImageView) {
imageView.imageTintList = ColorStateList.valueOf(theme.colorText)
fun colorOutgoingQuoteText(textView: TextView) {
withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurfaceVariant)
}
}
fun colorOutgoingQuoteAuthorText(textView: TextView) {
withScheme(textView) { scheme ->
ColorUtils.setAlphaComponent(scheme.onSurfaceVariant, ALPHA_80_INT)
}
}
fun colorOutgoingQuoteBackground(view: View) {
withScheme(view) { scheme ->
view.setBackgroundColor(scheme.onSurfaceVariant)
}
}
fun colorMaterialTextButton(button: MaterialButton) {
@ -814,6 +832,9 @@ class ViewThemeUtils @Inject constructor(private val theme: ServerTheme, private
R.drawable.ic_mimetype_package_x_generic,
R.drawable.ic_mimetype_folder
)
private val ALPHA_80_INT: Int = (255 * 0.8).roundToInt()
private const val SWITCH_COMPAT_TRACK_ALPHA: Int = 77
private const val HALF_ALPHA_INT: Int = 255 / 2
private const val SURFACE_OPACITY_BUTTON_DISABLED: Float = 0.12f

View File

@ -1,5 +1,5 @@
build:
maxIssues: 86
maxIssues: 84
weights:
# complexity: 2
# LongParameterList: 1