Add proper colorization to send button in stories flow.
This commit is contained in:
parent
9ad55e2360
commit
aef0ed828c
4 changed files with 71 additions and 10 deletions
|
@ -0,0 +1,50 @@
|
|||
package org.thoughtcrime.securesms.color
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Parcelable
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.thoughtcrime.securesms.R
|
||||
|
||||
/**
|
||||
* Represents a set of colors to be applied to the foreground and background of a view.
|
||||
*
|
||||
* Supports mixing color ints and color resource ids.
|
||||
*/
|
||||
@Parcelize
|
||||
data class ViewColorSet(
|
||||
val foreground: ViewColor,
|
||||
val background: ViewColor
|
||||
) : Parcelable {
|
||||
companion object {
|
||||
fun forCustomColor(@ColorInt customColor: Int): ViewColorSet {
|
||||
return ViewColorSet(
|
||||
foreground = ViewColor.ColorResource(R.color.signal_colorOnCustom),
|
||||
background = ViewColor.ColorValue(customColor)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
sealed class ViewColor : Parcelable {
|
||||
|
||||
@ColorInt
|
||||
abstract fun resolve(context: Context): Int
|
||||
|
||||
@Parcelize
|
||||
data class ColorValue(@ColorInt val colorInt: Int) : ViewColor() {
|
||||
override fun resolve(context: Context): Int {
|
||||
return colorInt
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class ColorResource(@ColorRes val colorRes: Int) : ViewColor() {
|
||||
override fun resolve(context: Context): Int {
|
||||
return ContextCompat.getColor(context, colorRes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.fragment.app.Fragment
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.color.ViewColorSet
|
||||
import org.thoughtcrime.securesms.components.FragmentWrapperActivity
|
||||
import org.thoughtcrime.securesms.contacts.paged.ContactSearchKey
|
||||
import org.thoughtcrime.securesms.conversation.mutiselect.forward.MultiselectForwardFragment.Companion.RESULT_SELECTION
|
||||
|
@ -36,8 +37,14 @@ open class MultiselectForwardActivity : FragmentWrapperActivity(), MultiselectFo
|
|||
override fun getFragment(): Fragment {
|
||||
return MultiselectForwardFragment.create(
|
||||
args.let {
|
||||
if (it.sendButtonTint == -1) {
|
||||
if (it.sendButtonColors == null) {
|
||||
args.withSendButtonTint(ContextCompat.getColor(this, R.color.signal_colorPrimary))
|
||||
args.copy(
|
||||
sendButtonColors = ViewColorSet(
|
||||
foreground = ViewColorSet.ViewColor.ColorResource(R.color.signal_colorOnPrimary),
|
||||
background = ViewColorSet.ViewColor.ColorResource(R.color.signal_colorPrimary)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
args
|
||||
}
|
||||
|
|
|
@ -144,9 +144,10 @@ class MultiselectForwardFragment :
|
|||
val sendButton: AppCompatImageView = bottomBar.findViewById(R.id.share_confirm)
|
||||
val backgroundHelper: View = bottomBar.findViewById(R.id.background_helper)
|
||||
|
||||
if (args.sendButtonTint != -1) {
|
||||
sendButton.setColorFilter(ContextCompat.getColor(requireContext(), R.color.signal_colorOnCustom))
|
||||
ViewCompat.setBackgroundTintList(sendButton, ColorStateList.valueOf(args.sendButtonTint))
|
||||
val sendButtonColors = args.sendButtonColors
|
||||
if (sendButtonColors != null) {
|
||||
sendButton.setColorFilter(sendButtonColors.foreground.resolve(requireContext()))
|
||||
ViewCompat.setBackgroundTintList(sendButton, ColorStateList.valueOf(sendButtonColors.background.resolve(requireContext())))
|
||||
}
|
||||
|
||||
FullscreenHelper.configureBottomBarLayout(requireActivity(), bottomBarSpacer, bottomBar)
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.signal.core.util.ThreadUtil
|
|||
import org.signal.core.util.concurrent.SignalExecutors
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.attachments.Attachment
|
||||
import org.thoughtcrime.securesms.color.ViewColorSet
|
||||
import org.thoughtcrime.securesms.conversation.ConversationMessage
|
||||
import org.thoughtcrime.securesms.conversation.mutiselect.Multiselect
|
||||
import org.thoughtcrime.securesms.conversation.mutiselect.MultiselectPart
|
||||
|
@ -43,12 +44,12 @@ data class MultiselectForwardFragmentArgs @JvmOverloads constructor(
|
|||
val forceDisableAddMessage: Boolean = false,
|
||||
val forceSelectionOnly: Boolean = false,
|
||||
val selectSingleRecipient: Boolean = false,
|
||||
@ColorInt val sendButtonTint: Int = -1,
|
||||
val sendButtonColors: ViewColorSet? = null,
|
||||
val storySendRequirements: Stories.MediaTransform.SendRequirements = Stories.MediaTransform.SendRequirements.CAN_NOT_SEND,
|
||||
val isSearchEnabled: Boolean = true
|
||||
) : Parcelable {
|
||||
|
||||
fun withSendButtonTint(@ColorInt sendButtonTint: Int) = copy(sendButtonTint = sendButtonTint)
|
||||
fun withSendButtonTint(@ColorInt sendButtonTint: Int) = copy(sendButtonColors = ViewColorSet.forCustomColor(sendButtonTint))
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
|
@ -61,9 +62,11 @@ data class MultiselectForwardFragmentArgs @JvmOverloads constructor(
|
|||
.withDataType(mediaType)
|
||||
.build()
|
||||
|
||||
val sendButtonTint: Int = threadId.takeIf { it > 0 }
|
||||
?.let { SignalDatabase.threads.getRecipientForThreadId(it) }?.chatColors?.asSingleColor()
|
||||
?: -1
|
||||
val sendButtonColors: ViewColorSet? = threadId.takeIf { it > 0 }
|
||||
?.let { SignalDatabase.threads.getRecipientForThreadId(it) }
|
||||
?.chatColors
|
||||
?.asSingleColor()
|
||||
?.let { ViewColorSet.forCustomColor(it) }
|
||||
|
||||
ThreadUtil.runOnMain {
|
||||
consumer.accept(
|
||||
|
@ -71,7 +74,7 @@ data class MultiselectForwardFragmentArgs @JvmOverloads constructor(
|
|||
isMmsSupported,
|
||||
listOf(multiShareArgs),
|
||||
storySendRequirements = Stories.MediaTransform.SendRequirements.CAN_NOT_SEND,
|
||||
sendButtonTint = sendButtonTint
|
||||
sendButtonColors = sendButtonColors
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue