Skip to content

Commit

Permalink
Set pill background color when the user is mentioned
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Jun 25, 2024
1 parent 5653e3b commit bbad78f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class AutoCompleter @AssistedInject constructor(

// Add the span
val span = PillImageSpan(
session, // TCHAP set pill background color when the user is mentioned
glideRequests,
avatarRenderer,
editText.context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
getRoom = timelineViewModel::getRoom,
getMember = timelineViewModel::getMember,
) { matrixItem: MatrixItem ->
PillImageSpan(glideRequests, avatarRenderer, requireContext(), matrixItem)
// TCHAP set pill background color when the user is mentioned
PillImageSpan(session, glideRequests, avatarRenderer, requireContext(), matrixItem)
}
}

Expand Down Expand Up @@ -820,6 +821,7 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), A
append(displayName)
setSpan(
PillImageSpan(
session, // TCHAP set pill background color when the user is mentioned
glideRequests,
avatarRenderer,
requireContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class EventTextRenderer @AssistedInject constructor(
}

private fun createPillImageSpan(matrixItem: MatrixItem) =
PillImageSpan(GlideApp.with(context), avatarRenderer, context, matrixItem)
// TCHAP set pill background color when the user is mentioned
PillImageSpan(sessionHolder.getActiveSession(), GlideApp.with(context), avatarRenderer, context, matrixItem)

private fun addPillSpan(
renderedText: Spannable,
Expand Down
18 changes: 14 additions & 4 deletions vector/src/main/java/im/vector/app/features/html/PillImageSpan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import im.vector.app.features.displayname.getBestName
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.api.extensions.orTrue
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.send.MatrixItemSpan
import org.matrix.android.sdk.api.util.MatrixItem
import java.lang.ref.WeakReference
Expand All @@ -49,6 +50,7 @@ import java.lang.ref.WeakReference
* Implements MatrixItemSpan so that it could be automatically transformed in matrix links and displayed as pills.
*/
class PillImageSpan(
private val session: Session,
private val glideRequests: GlideRequests,
private val avatarRenderer: AvatarRenderer,
private val context: Context,
Expand Down Expand Up @@ -156,10 +158,18 @@ class PillImageSpan(
setChipMinHeightResource(R.dimen.pill_min_height)
setChipIconSizeResource(R.dimen.pill_avatar_size)
chipIcon = icon
if (matrixItem is MatrixItem.EveryoneInRoomItem) {
chipBackgroundColor = ColorStateList.valueOf(ThemeUtils.getColor(context, R.attr.colorError))
// setTextColor API does not exist right now for ChipDrawable, use textAppearance
setTextAppearanceResource(R.style.TextAppearance_Vector_Body_OnError)
// TCHAP set pill background color when the user is mentioned
when {
matrixItem is MatrixItem.UserItem && matrixItem.id == session.myUserId-> {
chipBackgroundColor = ColorStateList.valueOf(ThemeUtils.getColor(context, R.attr.colorSecondary))
setTextColor(ThemeUtils.getColor(context, R.attr.colorOnSecondary))
setTextAppearanceResource(R.style.TextAppearance_Vector_Body_OnError)
}
matrixItem is MatrixItem.EveryoneInRoomItem -> {
chipBackgroundColor = ColorStateList.valueOf(ThemeUtils.getColor(context, R.attr.colorError))
// setTextColor API does not exist right now for ChipDrawable, use textAppearance
setTextAppearanceResource(R.style.TextAppearance_Vector_Body_OnError)
}
}
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class PillsPostProcessor @AssistedInject constructor(
}

private fun createPillImageSpan(matrixItem: MatrixItem) =
PillImageSpan(GlideApp.with(context), avatarRenderer, context, matrixItem)
// TCHAP set pill background color when the user is mentioned
PillImageSpan(sessionHolder.getActiveSession(), GlideApp.with(context), avatarRenderer, context, matrixItem)

private fun LinkSpan.createPillSpan(): PillImageSpan? {
val supportedHosts = context.resources.getStringArray(R.array.permalink_supported_hosts)
Expand Down

0 comments on commit bbad78f

Please sign in to comment.