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

View file

@ -22,8 +22,6 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import butterknife.BindView import butterknife.BindView
import butterknife.ButterKnife 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.home.room.detail.RoomDetailArgs
import im.vector.app.features.popup.PopupAlertManager import im.vector.app.features.popup.PopupAlertManager
import im.vector.app.features.popup.VerificationVectorAlert 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.Session
import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest
import org.matrix.android.sdk.api.session.crypto.verification.VerificationService 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.rageshake.VectorUncaughtExceptionHandler
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.settings.VectorSettingsActivity 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.ServerBackupStatusViewModel
import im.vector.app.features.workers.signout.ServerBackupStatusViewState import im.vector.app.features.workers.signout.ServerBackupStatusViewState
import im.vector.app.push.fcm.FcmHelper import im.vector.app.push.fcm.FcmHelper
@ -283,7 +282,7 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable, UnknownDeviceDet
uid = "upgradeSecurity", uid = "upgradeSecurity",
title = getString(titleRes), title = getString(titleRes),
description = getString(descRes), description = getString(descRes),
iconId = R.drawable.ic_shield_warning, iconId = R.drawable.ic_shield_warning
).apply { ).apply {
viewBinder = VerificationVectorAlert.ViewBinder(userItem, avatarRenderer) viewBinder = VerificationVectorAlert.ViewBinder(userItem, avatarRenderer)
colorInt = ContextCompat.getColor(this@HomeActivity, R.color.riotx_positive_accent) 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.graphics.Canvas
import android.net.Uri import android.net.Uri
import android.os.Build 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.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.core.app.NotificationCompat 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.VectorPreferences
import im.vector.app.features.settings.troubleshoot.TestNotificationReceiver import im.vector.app.features.settings.troubleshoot.TestNotificationReceiver
import org.matrix.android.sdk.api.session.call.MxCall import org.matrix.android.sdk.api.session.call.MxCall
import org.matrix.android.sdk.api.util.MatrixItem
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -323,19 +326,19 @@ class NotificationUtils @Inject constructor(private val context: Context,
builder.addAction( builder.addAction(
NotificationCompat.Action( NotificationCompat.Action(
R.drawable.ic_call_answer, IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
// IconCompat.createWithResource(applicationContext, R.drawable.ic_call) getActionText(R.string.call_notification_reject, R.color.riotx_notice),
// .setTint(ContextCompat.getColor(applicationContext, R.color.riotx_positive_accent)), rejectCallPendingIntent)
context.getString(R.string.call_notification_answer),
answerCallPendingIntent
)
) )
builder.addAction( builder.addAction(
NotificationCompat.Action( NotificationCompat.Action(
IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)), R.drawable.ic_call_answer,
context.getString(R.string.call_notification_reject), // IconCompat.createWithResource(applicationContext, R.drawable.ic_call)
rejectCallPendingIntent) // .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) builder.setFullScreenIntent(contentPendingIntent, true)
@ -369,8 +372,8 @@ class NotificationUtils @Inject constructor(private val context: Context,
builder.addAction( builder.addAction(
NotificationCompat.Action( NotificationCompat.Action(
IconCompat.createWithResource(context, R.drawable.ic_call_end).setTint(ContextCompat.getColor(context, R.color.riotx_notice)), IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
context.getString(R.string.call_notification_hangup), getActionText(R.string.call_notification_hangup, R.color.riotx_notice),
rejectCallPendingIntent) rejectCallPendingIntent)
) )
builder.setContentIntent(contentPendingIntent) builder.setContentIntent(contentPendingIntent)
@ -413,8 +416,8 @@ class NotificationUtils @Inject constructor(private val context: Context,
builder.addAction( builder.addAction(
NotificationCompat.Action( NotificationCompat.Action(
IconCompat.createWithResource(context, R.drawable.ic_call_end).setTint(ContextCompat.getColor(context, R.color.riotx_notice)), IconCompat.createWithResource(context, R.drawable.ic_call_hangup).setTint(ContextCompat.getColor(context, R.color.riotx_notice)),
context.getString(R.string.call_notification_hangup), getActionText(R.string.call_notification_hangup, R.color.riotx_notice),
rejectCallPendingIntent) rejectCallPendingIntent)
) )
@ -866,6 +869,13 @@ class NotificationUtils @Inject constructor(private val context: Context,
|| setting == NotificationManager.INTERRUPTION_FILTER_ALARMS || 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 { private fun ensureTitleNotEmpty(title: String?): CharSequence {
if (title.isNullOrBlank()) { if (title.isNullOrBlank()) {
return stringProvider.getString(R.string.app_name) 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.app.Activity
import android.view.View import android.view.View
import android.widget.Button
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import im.vector.app.R import im.vector.app.R

View file

@ -24,11 +24,8 @@ import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import im.vector.app.R 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 import java.lang.ref.WeakReference
interface VectorAlert { interface VectorAlert {
val uid: String val uid: String
val title: String val title: String
@ -68,7 +65,6 @@ interface VectorAlert {
interface ViewBinder { interface ViewBinder {
fun bind(view: View) 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 * 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 { ) : VectorAlert {
// will be set by manager, and accessible by actions at runtime // will be set by manager, and accessible by actions at runtime
override var weakCurrentActivity: WeakReference<Activity>? = null override var weakCurrentActivity: WeakReference<Activity>? = null
@ -114,6 +109,4 @@ open class DefaultVectorAlert(
override var colorAttribute: Int? = null override var colorAttribute: Int? = null
override var viewBinder: VectorAlert.ViewBinder? = null override var viewBinder: VectorAlert.ViewBinder? = null
} }

View file

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