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.SpannableString
import android.text.TextPaint
import android.text.method.LinkMovementMethod
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan
import android.text.style.UnderlineSpan
import android.view.View
import android.widget.TextView
import androidx.annotation.AttrRes
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 colorAttribute attribute of the color. Default to colorAccent
* @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,
@StringRes coloredTextRes: Int,
@AttrRes colorAttribute: Int = R.attr.colorAccent,
underline: Boolean = false) {
underline: Boolean = false,
onClick: (() -> Unit)?) {
val coloredPart = resources.getString(coloredTextRes)
// Insert colored part into the full text
val fullText = resources.getString(fullTextRes, coloredPart)
@ -69,6 +75,21 @@ fun TextView.setTextWithColoredPart(@StringRes fullTextRes: Int,
text = SpannableString(fullText)
.apply {
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) {
setSpan(UnderlineSpan(), index, index + coloredPart.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}

View file

@ -101,7 +101,10 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem<CallTileTimelineItem.Ho
}
CallStatus.IN_CALL -> setText(R.string.call_tile_in_call)
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 {
text = context.getString(R.string.call_tile_other_declined, attributes.userOfInterest.getBestName())
}