Migrate to latest bottom sheet theming implementation

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2024-03-12 20:19:47 +01:00
parent cc0ccdf56c
commit 13a5c9444f
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
7 changed files with 55 additions and 40 deletions

View File

@ -1198,6 +1198,7 @@ class ConversationInfoActivity :
cornerRadius(res = R.dimen.corner_radius) cornerRadius(res = R.dimen.corner_radius)
title(text = participant.displayName) title(text = participant.displayName)
viewThemeUtils.material.colorBottomSheetBackground(this.view)
listItemsWithImage(items = items) { _, index, _ -> listItemsWithImage(items = items) { _, index, _ ->
if (index == 0) { if (index == 0) {
removeAttendeeFromConversation(apiVersion, participant) removeAttendeeFromConversation(apiVersion, participant)

View File

@ -90,7 +90,7 @@ class ProfileBottomSheet(val ncApi: NcApi, val userModel: User, val viewThemeUti
MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT)).show { MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
cornerRadius(res = R.dimen.corner_radius) cornerRadius(res = R.dimen.corner_radius)
viewThemeUtils.platform.themeDialog(this.view) viewThemeUtils.material.colorBottomSheetBackground(this.view)
title(text = displayName) title(text = displayName)
listItemsWithImage(items = items) { _, index, _ -> listItemsWithImage(items = items) { _, index, _ ->

View File

@ -55,7 +55,8 @@ class AttachmentDialog(val activity: Activity, var chatActivity: ChatActivity) :
setContentView(dialogAttachmentBinding.root) setContentView(dialogAttachmentBinding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.platform.themeDialog(dialogAttachmentBinding.root) viewThemeUtils.material.colorBottomSheetBackground(dialogAttachmentBinding.root)
viewThemeUtils.material.colorBottomSheetDragHandle(dialogAttachmentBinding.bottomSheetDragHandle)
initItemsStrings() initItemsStrings()
initItemsVisibility() initItemsVisibility()
initItemsClickListeners() initItemsClickListeners()

View File

@ -82,7 +82,8 @@ class ConversationsListBottomDialog(
setContentView(binding.root) setContentView(binding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.platform.themeDialog(binding.root) viewThemeUtils.material.colorBottomSheetBackground(binding.root)
viewThemeUtils.material.colorBottomSheetDragHandle(binding.bottomSheetDragHandle)
initHeaderDescription() initHeaderDescription()
initItemsVisibility() initItemsVisibility()
initClickListeners() initClickListeners()

View File

@ -117,7 +117,8 @@ class MessageActionsDialog(
setContentView(dialogMessageActionsBinding.root) setContentView(dialogMessageActionsBinding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.platform.themeDialog(dialogMessageActionsBinding.root) viewThemeUtils.material.colorBottomSheetBackground(dialogMessageActionsBinding.root)
viewThemeUtils.material.colorBottomSheetDragHandle(dialogMessageActionsBinding.bottomSheetDragHandle)
initEmojiBar(hasChatPermission) initEmojiBar(hasChatPermission)
initMenuItemCopy(!message.isDeleted) initMenuItemCopy(!message.isDeleted)
val apiVersion = ApiUtils.getConversationApiVersion(user!!, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1)) val apiVersion = ApiUtils.getConversationApiVersion(user!!, intArrayOf(ApiUtils.API_V4, ApiUtils.API_V3, 1))

View File

@ -81,7 +81,8 @@ class ShowReactionsDialog(
binding = DialogMessageReactionsBinding.inflate(layoutInflater) binding = DialogMessageReactionsBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
viewThemeUtils.platform.themeDialog(binding.root) viewThemeUtils.material.colorBottomSheetBackground(binding.root)
viewThemeUtils.material.colorBottomSheetDragHandle(binding.bottomSheetDragHandle)
adapter = ReactionsAdapter(this, user) adapter = ReactionsAdapter(this, user)
binding.reactionsList.adapter = adapter binding.reactionsList.adapter = adapter
binding.reactionsList.layoutManager = LinearLayoutManager(context) binding.reactionsList.layoutManager = LinearLayoutManager(context)

View File

@ -64,6 +64,7 @@ import com.nextcloud.talk.utils.DrawableUtils
import com.nextcloud.talk.utils.message.MessageUtils import com.nextcloud.talk.utils.message.MessageUtils
import com.vanniktech.emoji.EmojiTextView import com.vanniktech.emoji.EmojiTextView
import com.wooplr.spotlight.SpotlightView import com.wooplr.spotlight.SpotlightView
import dynamiccolor.MaterialDynamicColors
import eu.davidea.flexibleadapter.utils.FlexibleUtils import eu.davidea.flexibleadapter.utils.FlexibleUtils
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.roundToInt import kotlin.math.roundToInt
@ -78,6 +79,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
private val appcompat: AndroidXViewThemeUtils private val appcompat: AndroidXViewThemeUtils
) : ) :
ViewThemeUtilsBase(schemes) { ViewThemeUtilsBase(schemes) {
private val dynamicColor = MaterialDynamicColors()
fun themeIncomingMessageBubble(bubble: View, grouped: Boolean, deleted: Boolean) { fun themeIncomingMessageBubble(bubble: View, grouped: Boolean, deleted: Boolean) {
val resources = bubble.resources val resources = bubble.resources
@ -104,9 +106,9 @@ class TalkSpecificViewThemeUtils @Inject constructor(
fun themeOutgoingMessageBubble(bubble: View, grouped: Boolean, deleted: Boolean) { fun themeOutgoingMessageBubble(bubble: View, grouped: Boolean, deleted: Boolean) {
withScheme(bubble) { scheme -> withScheme(bubble) { scheme ->
val bgBubbleColor = if (deleted) { val bgBubbleColor = if (deleted) {
ColorUtils.setAlphaComponent(scheme.surfaceVariant, HALF_ALPHA_INT) ColorUtils.setAlphaComponent(dynamicColor.surfaceVariant().getArgb(scheme), HALF_ALPHA_INT)
} else { } else {
scheme.surfaceVariant dynamicColor.surfaceVariant().getArgb(scheme)
} }
val layout = if (grouped) { val layout = if (grouped) {
@ -126,31 +128,31 @@ class TalkSpecificViewThemeUtils @Inject constructor(
fun colorOutgoingQuoteText(textView: TextView) { fun colorOutgoingQuoteText(textView: TextView) {
withScheme(textView) { scheme -> withScheme(textView) { scheme ->
textView.setTextColor(scheme.onSurfaceVariant) textView.setTextColor(dynamicColor.onSurfaceVariant().getArgb(scheme))
} }
} }
fun colorOutgoingQuoteAuthorText(textView: TextView) { fun colorOutgoingQuoteAuthorText(textView: TextView) {
withScheme(textView) { scheme -> withScheme(textView) { scheme ->
ColorUtils.setAlphaComponent(scheme.onSurfaceVariant, ALPHA_80_INT) ColorUtils.setAlphaComponent(dynamicColor.onSurfaceVariant().getArgb(scheme), ALPHA_80_INT)
} }
} }
fun colorOutgoingQuoteBackground(view: View) { fun colorOutgoingQuoteBackground(view: View) {
withScheme(view) { scheme -> withScheme(view) { scheme ->
view.setBackgroundColor(scheme.onSurfaceVariant) view.setBackgroundColor(dynamicColor.onSurfaceVariant().getArgb(scheme))
} }
} }
fun colorContactChatItemName(contactName: androidx.emoji2.widget.EmojiTextView) { fun colorContactChatItemName(contactName: androidx.emoji2.widget.EmojiTextView) {
withScheme(contactName) { scheme -> withScheme(contactName) { scheme ->
contactName.setTextColor(scheme.onPrimaryContainer) contactName.setTextColor(dynamicColor.onPrimaryContainer().getArgb(scheme))
} }
} }
fun colorContactChatItemBackground(card: MaterialCardView) { fun colorContactChatItemBackground(card: MaterialCardView) {
withScheme(card) { scheme -> withScheme(card) { scheme ->
card.setCardBackgroundColor(scheme.primaryContainer) card.setCardBackgroundColor(dynamicColor.primaryContainer().getArgb(scheme))
} }
} }
@ -166,7 +168,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
.mutate() .mutate()
DrawableCompat.setTintList( DrawableCompat.setTintList(
drawable, drawable,
ColorStateList.valueOf(scheme.primary) ColorStateList.valueOf(dynamicColor.primary().getArgb(scheme))
) )
emoji.background = drawable emoji.background = drawable
} }
@ -178,7 +180,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
.getDrawable(linearLayout.context, R.drawable.reaction_self_background)!! .getDrawable(linearLayout.context, R.drawable.reaction_self_background)!!
.mutate() .mutate()
val backgroundColor = if (incoming) { val backgroundColor = if (incoming) {
scheme.primaryContainer dynamicColor.primaryContainer().getArgb(scheme)
} else { } else {
ContextCompat.getColor( ContextCompat.getColor(
linearLayout.context, linearLayout.context,
@ -207,7 +209,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
private fun colorDrawable(context: Context, drawable: Drawable) { private fun colorDrawable(context: Context, drawable: Drawable) {
withScheme(context) { scheme -> withScheme(context) { scheme ->
drawable.setTint(scheme.primary) drawable.setTint(dynamicColor.primary().getArgb(scheme))
} }
} }
@ -217,9 +219,9 @@ class TalkSpecificViewThemeUtils @Inject constructor(
withScheme(avatar) { scheme -> withScheme(avatar) { scheme ->
val layers = arrayOfNulls<Drawable>(2) val layers = arrayOfNulls<Drawable>(2)
layers[0] = ContextCompat.getDrawable(avatar.context, R.drawable.ic_avatar_background) layers[0] = ContextCompat.getDrawable(avatar.context, R.drawable.ic_avatar_background)
layers[0]?.setTint(scheme.surfaceVariant) layers[0]?.setTint(dynamicColor.surfaceVariant().getArgb(scheme))
layers[1] = ContextCompat.getDrawable(avatar.context, foreground) layers[1] = ContextCompat.getDrawable(avatar.context, foreground)
layers[1]?.setTint(scheme.onSurfaceVariant) layers[1]?.setTint(dynamicColor.onSurfaceVariant().getArgb(scheme))
drawable = LayerDrawable(layers) drawable = LayerDrawable(layers)
} }
@ -231,10 +233,10 @@ class TalkSpecificViewThemeUtils @Inject constructor(
// hacky as no default way is provided // hacky as no default way is provided
val editText = searchView.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text) val editText = searchView.findViewById<SearchView.SearchAutoComplete>(R.id.search_src_text)
val searchPlate = searchView.findViewById<LinearLayout>(R.id.search_plate) val searchPlate = searchView.findViewById<LinearLayout>(R.id.search_plate)
editText.setHintTextColor(scheme.onSurfaceVariant) editText.setHintTextColor(dynamicColor.onSurfaceVariant().getArgb(scheme))
editText.setTextColor(scheme.onSurface) editText.setTextColor(dynamicColor.onSurface().getArgb(scheme))
editText.setBackgroundColor(scheme.surface) editText.setBackgroundColor(dynamicColor.surface().getArgb(scheme))
searchPlate.setBackgroundColor(scheme.surface) searchPlate.setBackgroundColor(dynamicColor.surface().getArgb(scheme))
} }
} }
@ -248,7 +250,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
intArrayOf(-android.R.attr.state_checked) intArrayOf(-android.R.attr.state_checked)
), ),
intArrayOf( intArrayOf(
scheme.secondaryContainer, dynamicColor.secondaryContainer().getArgb(scheme),
background background
) )
) )
@ -259,8 +261,8 @@ class TalkSpecificViewThemeUtils @Inject constructor(
intArrayOf(-android.R.attr.state_checked) intArrayOf(-android.R.attr.state_checked)
), ),
intArrayOf( intArrayOf(
scheme.onSecondaryContainer, dynamicColor.onSecondaryContainer().getArgb(scheme),
scheme.surface dynamicColor.surface().getArgb(scheme)
) )
) )
) )
@ -269,29 +271,33 @@ class TalkSpecificViewThemeUtils @Inject constructor(
fun themeMicInputCloud(micInputCloud: MicInputCloud) { fun themeMicInputCloud(micInputCloud: MicInputCloud) {
withScheme(micInputCloud) { scheme -> withScheme(micInputCloud) { scheme ->
micInputCloud.setColor(scheme.primary) micInputCloud.setColor(dynamicColor.primary().getArgb(scheme))
} }
} }
fun themeWaveFormSeekBar(waveformSeekBar: WaveformSeekBar) { fun themeWaveFormSeekBar(waveformSeekBar: WaveformSeekBar) {
withScheme(waveformSeekBar) { scheme -> withScheme(waveformSeekBar) { scheme ->
waveformSeekBar.thumb.colorFilter = waveformSeekBar.thumb.colorFilter =
PorterDuffColorFilter(scheme.inversePrimary, PorterDuff.Mode.SRC_IN) PorterDuffColorFilter(dynamicColor.inversePrimary().getArgb(scheme), PorterDuff.Mode.SRC_IN)
waveformSeekBar.setColors(scheme.inversePrimary, scheme.onPrimaryContainer) waveformSeekBar.setColors(
dynamicColor.inversePrimary().getArgb(scheme),
dynamicColor.onPrimaryContainer().getArgb(scheme)
)
waveformSeekBar.progressDrawable?.colorFilter = waveformSeekBar.progressDrawable?.colorFilter =
PorterDuffColorFilter(scheme.primary, PorterDuff.Mode.SRC_IN) PorterDuffColorFilter(dynamicColor.primary().getArgb(scheme), PorterDuff.Mode.SRC_IN)
} }
} }
fun themeForegroundColorSpan(context: Context): ForegroundColorSpan { fun themeForegroundColorSpan(context: Context): ForegroundColorSpan {
return withScheme(context) { scheme -> return withScheme(context) { scheme ->
return@withScheme ForegroundColorSpan(scheme.primary) return@withScheme ForegroundColorSpan(dynamicColor.primary().getArgb(scheme))
} }
} }
fun themeSpotlightView(context: Context, builder: SpotlightView.Builder): SpotlightView.Builder { fun themeSpotlightView(context: Context, builder: SpotlightView.Builder): SpotlightView.Builder {
return withScheme(context) { scheme -> return withScheme(context) { scheme ->
return@withScheme builder.headingTvColor(scheme.primary).lineAndArcColor(scheme.primary) return@withScheme builder.headingTvColor(dynamicColor.primary().getArgb(scheme))
.lineAndArcColor(dynamicColor.primary().getArgb(scheme))
} }
} }
@ -305,7 +311,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
do { do {
val end = start + constraint.length val end = start + constraint.length
spanText.setSpan( spanText.setSpan(
ForegroundColorSpan(scheme.primary), ForegroundColorSpan(dynamicColor.primary().getArgb(scheme)),
start, start,
end, end,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
@ -323,34 +329,34 @@ class TalkSpecificViewThemeUtils @Inject constructor(
fun themeSortButton(sortButton: MaterialButton) { fun themeSortButton(sortButton: MaterialButton) {
withScheme(sortButton) { scheme -> withScheme(sortButton) { scheme ->
sortButton.iconTint = ColorStateList.valueOf(scheme.onSurface) sortButton.iconTint = ColorStateList.valueOf(dynamicColor.onSurface().getArgb(scheme))
sortButton.setTextColor(scheme.onSurface) sortButton.setTextColor(dynamicColor.onSurface().getArgb(scheme))
} }
} }
fun themePathNavigationButton(navigationBtn: MaterialButton) { fun themePathNavigationButton(navigationBtn: MaterialButton) {
withScheme(navigationBtn) { scheme -> withScheme(navigationBtn) { scheme ->
navigationBtn.iconTint = ColorStateList.valueOf(scheme.onSurface) navigationBtn.iconTint = ColorStateList.valueOf(dynamicColor.onSurface().getArgb(scheme))
navigationBtn.setTextColor(scheme.onSurface) navigationBtn.setTextColor(dynamicColor.onSurface().getArgb(scheme))
} }
} }
fun themeSortListButtonGroup(relativeLayout: RelativeLayout) { fun themeSortListButtonGroup(relativeLayout: RelativeLayout) {
withScheme(relativeLayout) { scheme -> withScheme(relativeLayout) { scheme ->
relativeLayout.setBackgroundColor(scheme.surface) relativeLayout.setBackgroundColor(dynamicColor.surface().getArgb(scheme))
} }
} }
fun themeStatusDrawable(context: Context, statusDrawable: StatusDrawable) { fun themeStatusDrawable(context: Context, statusDrawable: StatusDrawable) {
withScheme(context) { scheme -> withScheme(context) { scheme ->
statusDrawable.colorStatusDrawable(scheme.surface) statusDrawable.colorStatusDrawable(dynamicColor.surface().getArgb(scheme))
} }
} }
fun themeMessageCheckMark(imageView: ImageView) { fun themeMessageCheckMark(imageView: ImageView) {
withScheme(imageView) { scheme -> withScheme(imageView) { scheme ->
imageView.setColorFilter( imageView.setColorFilter(
scheme.onSurfaceVariant, dynamicColor.onSurfaceVariant().getArgb(scheme),
PorterDuff.Mode.SRC_ATOP PorterDuff.Mode.SRC_ATOP
) )
} }
@ -365,7 +371,11 @@ class TalkSpecificViewThemeUtils @Inject constructor(
context.getColor(R.color.nc_incoming_text_default) context.getColor(R.color.nc_incoming_text_default)
) )
} else { } else {
MessageUtils(context).getRenderedMarkdownText(context, message, scheme.onSurfaceVariant) MessageUtils(context).getRenderedMarkdownText(
context,
message,
dynamicColor.onSurfaceVariant().getArgb(scheme)
)
} }
} }
} }
@ -375,7 +385,7 @@ class TalkSpecificViewThemeUtils @Inject constructor(
return@withScheme if (!isOutgoingMessage || isSelfReaction) { return@withScheme if (!isOutgoingMessage || isSelfReaction) {
ContextCompat.getColor(binding.root.context, R.color.high_emphasis_text) ContextCompat.getColor(binding.root.context, R.color.high_emphasis_text)
} else { } else {
scheme.onSurfaceVariant dynamicColor.onSurfaceVariant().getArgb(scheme)
} }
} }
} }