Fix media count indicator button colors so they match the chat color.

This commit is contained in:
jeffrey-signal
2026-04-07 11:14:28 -04:00
committed by Greyson Parrelli
parent b8b9a632b5
commit fb0c4757f2
4 changed files with 33 additions and 7 deletions

View File

@@ -1,9 +1,12 @@
package org.thoughtcrime.securesms.mediasend.v2
import android.content.Context
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.ViewCompat
import org.thoughtcrime.securesms.R
class MediaCountIndicatorButton @JvmOverloads constructor(
@@ -21,4 +24,8 @@ class MediaCountIndicatorButton @JvmOverloads constructor(
fun setCount(count: Int) {
countView.text = "$count"
}
fun setChatColor(@ColorInt color: Int) {
ViewCompat.setBackgroundTintList(countView, ColorStateList.valueOf(color))
}
}

View File

@@ -197,6 +197,7 @@ class MediaGalleryFragment : Fragment(R.layout.v2_media_gallery_fragment) {
viewStateLiveData.observe(viewLifecycleOwner) { state ->
binding.mediaGalleryBottomBarGroup.visible = state.selectedMedia.isNotEmpty()
binding.mediaGalleryCountButton.setCount(state.selectedMedia.size)
state.chatColor?.let { binding.mediaGalleryCountButton.setChatColor(it) }
val stopwatch = Stopwatch("mediaSubmit")
selectedAdapter.submitList(state.selectedMedia.map { MediaGallerySelectedItem.Model(it) }) {
@@ -214,14 +215,16 @@ class MediaGalleryFragment : Fragment(R.layout.v2_media_gallery_fragment) {
val galleryItemsWithSelection = LiveDataUtil.combineLatest(
viewModel.state.map { it.items },
viewStateLiveData.map { it.selectedMedia }
) { galleryItems, selectedMedia ->
viewStateLiveData.map { it.selectedMedia },
viewStateLiveData.map { it.chatColor }
) { galleryItems, selectedMedia, chatColor ->
galleryItems.map {
if (it is MediaGallerySelectableItem.FileModel) {
val selectedIndex = selectedMedia.indexOfFirst { selected -> selected.uri == it.media.uri }
it.copy(
isSelected = selectedIndex >= 0,
selectionOneBasedIndex = selectedIndex + 1
selectionOneBasedIndex = selectedIndex + 1,
chatColor = chatColor
)
} else {
it
@@ -339,7 +342,8 @@ class MediaGalleryFragment : Fragment(R.layout.v2_media_gallery_fragment) {
}
data class ViewState(
val selectedMedia: List<Media> = listOf()
val selectedMedia: List<Media> = listOf(),
val chatColor: Int? = null
)
interface Callbacks {

View File

@@ -2,10 +2,13 @@ package org.thoughtcrime.securesms.mediasend.v2.gallery
import android.animation.ValueAnimator
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.net.Uri
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.setPadding
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
@@ -29,6 +32,7 @@ import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel
import org.thoughtcrime.securesms.util.adapter.mapping.MappingViewHolder
import org.thoughtcrime.securesms.util.visible
import java.util.concurrent.TimeUnit
import org.signal.core.ui.R as CoreUiR
typealias OnMediaFolderClicked = (MediaFolder) -> Unit
typealias OnMediaClicked = (Media, Boolean) -> Unit
@@ -99,13 +103,13 @@ object MediaGallerySelectableItem {
}
}
data class FileModel(val media: Media, val isSelected: Boolean, val selectionOneBasedIndex: Int) : MappingModel<FileModel> {
data class FileModel(val media: Media, val isSelected: Boolean, val selectionOneBasedIndex: Int, val chatColor: Int? = null) : MappingModel<FileModel> {
override fun areItemsTheSame(newItem: FileModel): Boolean {
return newItem.media == media
}
override fun areContentsTheSame(newItem: FileModel): Boolean {
return newItem.media == media && isSelected == newItem.isSelected && selectionOneBasedIndex == newItem.selectionOneBasedIndex
return newItem.media == media && isSelected == newItem.isSelected && selectionOneBasedIndex == newItem.selectionOneBasedIndex && chatColor == newItem.chatColor
}
override fun getChangePayload(newItem: FileModel): Any? {
@@ -127,6 +131,12 @@ object MediaGallerySelectableItem {
override fun bind(model: FileModel) {
checkView?.visible = model.isSelected
checkView?.text = "${model.selectionOneBasedIndex}"
(checkView?.background?.mutate() as? LayerDrawable)?.getDrawable(1)
?.let { backgroundDrawable ->
val tintColor = model.chatColor ?: ContextCompat.getColor(itemView.context, CoreUiR.color.signal_light_colorPrimary)
DrawableCompat.setTint(backgroundDrawable, tintColor)
}
itemView.setOnClickListener { onMediaClicked(model.media, model.isSelected) }
itemView.setOnLongClickListener {
mediaGalleryGridItemTouchListener.startDragSelection(bindingAdapterPosition)

View File

@@ -49,7 +49,12 @@ class MediaSelectionGalleryFragment : Fragment(R.layout.fragment_container), Med
mediaGalleryFragment.bindSelectedMediaItemDragHelper(ItemTouchHelper(MediaSelectionItemTouchHelper(sharedViewModel)))
sharedViewModel.state.observe(viewLifecycleOwner) { state ->
mediaGalleryFragment.onViewStateUpdated(MediaGalleryFragment.ViewState(state.selectedMedia))
mediaGalleryFragment.onViewStateUpdated(
MediaGalleryFragment.ViewState(
selectedMedia = state.selectedMedia,
chatColor = state.recipient?.chatColors?.asSingleColor()
)
)
}
lifecycleDisposable += sharedViewModel.mediaErrors