VoIP: add call back action on rejected tile

This commit is contained in:
ganfra 2020-12-08 12:44:08 +01:00
parent e817844c5d
commit be1e7ee9a9
2 changed files with 29 additions and 5 deletions

View file

@ -18,8 +18,12 @@ package im.vector.app.core.extensions
import android.text.Spannable import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.UnderlineSpan import android.text.style.UnderlineSpan
import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.annotation.AttrRes import androidx.annotation.AttrRes
import androidx.annotation.ColorRes import androidx.annotation.ColorRes
@ -52,11 +56,13 @@ fun TextView.setTextOrHide(newText: CharSequence?, hideWhenBlank: Boolean = true
* @param coloredTextRes the resource id of the colored part of the text * @param coloredTextRes the resource id of the colored part of the text
* @param colorAttribute attribute of the color. Default to colorAccent * @param colorAttribute attribute of the color. Default to colorAccent
* @param underline true to also underline the text. Default to false * @param underline true to also underline the text. Default to false
* @param onClick attributes to handle click on the colored part if needed required
*/ */
fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int, fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int,
@StringRes coloredTextRes: Int, @StringRes coloredTextRes: Int,
@AttrRes colorAttribute: Int = R.attr.colorAccent, @AttrRes colorAttribute: Int = R.attr.colorAccent,
underline: Boolean = false) { underline: Boolean = false,
onClick: (() -> Unit)?) {
val coloredPart = resources.getString(coloredTextRes) val coloredPart = resources.getString(coloredTextRes)
// Insert colored part into the full text // Insert colored part into the full text
val fullText = resources.getString(fullTextRes, coloredPart) val fullText = resources.getString(fullTextRes, coloredPart)
@ -69,6 +75,21 @@ fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int,
text = SpannableString(fullText) text = SpannableString(fullText)
.apply { .apply {
setSpan(foregroundSpan, index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) setSpan(foregroundSpan, index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
if (onClick != null) {
val clickableSpan = object : ClickableSpan() {
override fun onClick(widget: View) {
onClick()
}
override fun updateDrawState(ds: TextPaint) {
ds.color = color
// underline will be handled separately if needed, see below
ds.isUnderlineText = false
}
}
setSpan(clickableSpan, index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
movementMethod = LinkMovementMethod.getInstance()
}
if (underline) { if (underline) {
setSpan(UnderlineSpan(), index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) setSpan(UnderlineSpan(), index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
} }
@ -76,12 +97,12 @@ fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int,
} }
fun TextView.setLeftDrawable(@DrawableRes iconRes: Int, @ColorRes tintColor: Int? = null) { fun TextView.setLeftDrawable(@DrawableRes iconRes: Int, @ColorRes tintColor: Int? = null) {
val icon = if(tintColor != null){ val icon = if (tintColor != null) {
val tint = ContextCompat.getColor(context, tintColor) val tint = ContextCompat.getColor(context, tintColor)
ContextCompat.getDrawable(context, iconRes)?.also { ContextCompat.getDrawable(context, iconRes)?.also {
DrawableCompat.setTint(it.mutate(), tint) DrawableCompat.setTint(it.mutate(), tint)
} }
}else { } else {
ContextCompat.getDrawable(context, iconRes) ContextCompat.getDrawable(context, iconRes)
} }
setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)

View file

@ -96,12 +96,15 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem<CallTileTimelineItem.Ho
when (attributes.callStatus) { when (attributes.callStatus) {
CallStatus.INVITED -> if (attributes.informationData.sentByMe) { CallStatus.INVITED -> if (attributes.informationData.sentByMe) {
setText(R.string.call_tile_you_started_call) setText(R.string.call_tile_you_started_call)
}else { } else {
text = context.getString(R.string.call_tile_other_started_call, attributes.userOfInterest.getBestName()) text = context.getString(R.string.call_tile_other_started_call, attributes.userOfInterest.getBestName())
} }
CallStatus.IN_CALL -> setText(R.string.call_tile_in_call) CallStatus.IN_CALL -> setText(R.string.call_tile_in_call)
CallStatus.REJECTED -> if (attributes.informationData.sentByMe) { CallStatus.REJECTED -> if (attributes.informationData.sentByMe) {
setTextWithColoredPart(R.string.call_tile_you_declined, R.string.call_tile_call_back) setTextWithColoredPart(R.string.call_tile_you_declined, R.string.call_tile_call_back) {
val callbackAction = RoomDetailAction.StartCall(attributes.callKind == CallKind.VIDEO)
attributes.callback?.onTimelineItemAction(callbackAction)
}
} else { } else {
text = context.getString(R.string.call_tile_other_declined, attributes.userOfInterest.getBestName()) text = context.getString(R.string.call_tile_other_declined, attributes.userOfInterest.getBestName())
} }