VoIP: polish notifs and clean code

This commit is contained in:
ganfra 2020-12-09 17:48:34 +01:00
parent 92fe70c15c
commit fe3c080991
8 changed files with 45 additions and 59 deletions

View file

@ -170,29 +170,26 @@ class CallService : VectorService(), WiredHeadsetStateReceiver.HeadsetEventListe
val fromBg = intent.getBooleanExtra(EXTRA_IS_IN_BG, false)
val opponentMatrixItem = getOpponentMatrixItem(call)
Timber.v("displayIncomingCallNotification : display the dedicated notification")
if (!fromBg) {
// Show in-app notification if app is in foreground.
val incomingCallAlert = IncomingCallAlert(INCOMING_CALL_ALERT_UID,
shouldBeDisplayedIn = { activity ->
if (activity is RoomDetailActivity) {
call.roomId != activity.currentRoomId
} else if(activity is VectorCallActivity) {
activity.intent.getParcelableExtra<CallArgs>(MvRx.KEY_ARG)?.callId != call.callId
} else true
}
).apply {
viewBinder = IncomingCallAlert.ViewBinder(
matrixItem = opponentMatrixItem,
avatarRenderer = avatarRenderer,
isVideoCall = isVideoCall,
onAccept = { showCallScreen(call, VectorCallActivity.INCOMING_ACCEPT) },
onReject = { call.endCall() }
)
dismissedAction = Runnable { call.endCall() }
contentAction = Runnable { showCallScreen(call, VectorCallActivity.INCOMING_RINGING) }
}
alertManager.postVectorAlert(incomingCallAlert)
val incomingCallAlert = IncomingCallAlert(INCOMING_CALL_ALERT_UID,
shouldBeDisplayedIn = { activity ->
if (activity is RoomDetailActivity) {
call.roomId != activity.currentRoomId
} else if (activity is VectorCallActivity) {
activity.intent.getParcelableExtra<CallArgs>(MvRx.KEY_ARG)?.callId != call.callId
} else true
}
).apply {
viewBinder = IncomingCallAlert.ViewBinder(
matrixItem = opponentMatrixItem,
avatarRenderer = avatarRenderer,
isVideoCall = isVideoCall,
onAccept = { showCallScreen(call, VectorCallActivity.INCOMING_ACCEPT) },
onReject = { call.endCall() }
)
dismissedAction = Runnable { call.endCall() }
contentAction = Runnable { showCallScreen(call, VectorCallActivity.INCOMING_RINGING) }
}
alertManager.postVectorAlert(incomingCallAlert)
val notification = notificationUtils.buildIncomingCallNotification(
mxCall = call.mxCall,
title = opponentMatrixItem?.getBestName() ?: call.mxCall.opponentUserId,

View file

@ -22,8 +22,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible
import butterknife.BindView
import butterknife.ButterKnife

View file

@ -23,7 +23,6 @@ import im.vector.app.features.home.room.detail.RoomDetailActivity
import im.vector.app.features.home.room.detail.RoomDetailArgs
import im.vector.app.features.popup.PopupAlertManager
import im.vector.app.features.popup.VerificationVectorAlert
import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService

View file

@ -51,7 +51,6 @@ import im.vector.app.features.popup.VerificationVectorAlert
import im.vector.app.features.rageshake.VectorUncaughtExceptionHandler
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.VectorSettingsActivity
import im.vector.app.features.themes.ThemeUtils
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
import im.vector.app.features.workers.signout.ServerBackupStatusViewState
import im.vector.app.push.fcm.FcmHelper
@ -283,7 +282,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet
uid = "upgradeSecurity",
title = getString(titleRes),
description = getString(descRes),
iconId = R.drawable.ic_shield_warning,
iconId = R.drawable.ic_shield_warning
).apply {
viewBinder = VerificationVectorAlert.ViewBinder(userItem, avatarRenderer)
colorInt = ContextCompat.getColor(this@HomeActivity, R.color.riotx_positive_accent)

View file

@ -30,6 +30,10 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.net.Uri
import android.os.Build
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat
@ -53,7 +57,6 @@ import im.vector.app.features.home.room.detail.RoomDetailArgs
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.troubleshoot.TestNotificationReceiver
import org.matrix.android.sdk.api.session.call.MxCall
import org.matrix.android.sdk.api.util.MatrixItem
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Singleton
@ -323,19 +326,19 @@ class NotificationUtils @Inject constructor(private val context: Context,
builder.addAction(
NotificationCompat.Action(
R.drawable.ic_call_answer,
// IconCompat.createWithResource(applicationContext, R.drawable.ic_call)
// .setTint(ContextCompat.getColor(applicationContext, R.color.riotx_positive_accent)),
context.getString(R.string.call_notification_answer),
answerCallPendingIntent
)
IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
getActionText(R.string.call_notification_reject, R.color.riotx_notice),
rejectCallPendingIntent)
)
builder.addAction(
NotificationCompat.Action(
IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
context.getString(R.string.call_notification_reject),
rejectCallPendingIntent)
R.drawable.ic_call_answer,
// IconCompat.createWithResource(applicationContext, R.drawable.ic_call)
// .setTint(ContextCompat.getColor(applicationContext, R.color.riotx_positive_accent)),
getActionText(R.string.call_notification_answer, R.color.riotx_positive_accent),
answerCallPendingIntent
)
)
builder.setFullScreenIntent(contentPendingIntent, true)
@ -369,8 +372,8 @@ class NotificationUtils @Inject constructor(private val context: Context,
builder.addAction(
NotificationCompat.Action(
IconCompat.createWithResource(context, R.drawable.ic_call_end).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
context.getString(R.string.call_notification_hangup),
IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
getActionText(R.string.call_notification_hangup, R.color.riotx_notice),
rejectCallPendingIntent)
)
builder.setContentIntent(contentPendingIntent)
@ -413,8 +416,8 @@ class NotificationUtils @Inject constructor(private val context: Context,
builder.addAction(
NotificationCompat.Action(
IconCompat.createWithResource(context, R.drawable.ic_call_end).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
context.getString(R.string.call_notification_hangup),
IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
getActionText(R.string.call_notification_hangup, R.color.riotx_notice),
rejectCallPendingIntent)
)
@ -866,6 +869,13 @@ class NotificationUtils @Inject constructor(private val context: Context,
|| setting == NotificationManager.INTERRUPTION_FILTER_ALARMS
}
private fun getActionText(@StringRes stringRes: Int, @ColorRes colorRes: Int): Spannable {
return SpannableString(context.getText(stringRes)).apply {
val foregroundColorSpan = ForegroundColorSpan(ContextCompat.getColor(context, colorRes))
setSpan(foregroundColorSpan, 0, length, 0)
}
}
private fun ensureTitleNotEmpty(title: String?): CharSequence {
if (title.isNullOrBlank()) {
return stringProvider.getString(R.string.app_name)

View file

@ -18,7 +18,6 @@ package im.vector.app.features.popup
import android.app.Activity
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import im.vector.app.R

View file

@ -24,11 +24,8 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes
import im.vector.app.R
import im.vector.app.features.home.AvatarRenderer
import org.matrix.android.sdk.api.util.MatrixItem
import java.lang.ref.WeakReference
interface VectorAlert {
val uid: String
val title: String
@ -68,7 +65,6 @@ interface VectorAlert {
interface ViewBinder {
fun bind(view: View)
}
}
/**
@ -82,10 +78,9 @@ open class DefaultVectorAlert(
/**
* Alert are displayed by default, but let this lambda return false to prevent displaying
*/
override val shouldBeDisplayedIn: ((Activity) -> Boolean) = { true },
override val shouldBeDisplayedIn: ((Activity) -> Boolean) = { true }
) : VectorAlert {
// will be set by manager, and accessible by actions at runtime
override var weakCurrentActivity: WeakReference<Activity>? = null
@ -114,6 +109,4 @@ open class DefaultVectorAlert(
override var colorAttribute: Int? = null
override var viewBinder: VectorAlert.ViewBinder? = null
}

View file

@ -47,13 +47,4 @@ class VerificationVectorAlert(uid: String,
}
}
}
}