From fe3c080991699812dc7988d314fd4c38d0b320c8 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 9 Dec 2020 17:48:34 +0100 Subject: [PATCH] VoIP: polish notifs and clean code --- .../vector/app/core/services/CallService.kt | 41 +++++++++---------- .../app/features/call/CallControlsView.kt | 2 - .../IncomingVerificationRequestHandler.kt | 1 - .../vector/app/features/home/HomeActivity.kt | 3 +- .../notifications/NotificationUtils.kt | 38 ++++++++++------- .../app/features/popup/IncomingCallAlert.kt | 1 - .../vector/app/features/popup/VectorAlert.kt | 9 +--- .../features/popup/VerificationVectorAlert.kt | 9 ---- 8 files changed, 45 insertions(+), 59 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/services/CallService.kt b/vector/src/main/java/im/vector/app/core/services/CallService.kt index 05875f3cf5..a5a59dc0ba 100644 --- a/vector/src/main/java/im/vector/app/core/services/CallService.kt +++ b/vector/src/main/java/im/vector/app/core/services/CallService.kt @@ -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(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(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, diff --git a/vector/src/main/java/im/vector/app/features/call/CallControlsView.kt b/vector/src/main/java/im/vector/app/features/call/CallControlsView.kt index 6e5678d3dc..d0b472b295 100644 --- a/vector/src/main/java/im/vector/app/features/call/CallControlsView.kt +++ b/vector/src/main/java/im/vector/app/features/call/CallControlsView.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt index e38ab2f6e8..9fca355158 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index 9fb63c50d3..fac36ee3eb 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -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) diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index ecac5b742c..74a93fceda 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -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) diff --git a/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt b/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt index ec823bc21f..e8189eec1d 100644 --- a/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt +++ b/vector/src/main/java/im/vector/app/features/popup/IncomingCallAlert.kt @@ -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 diff --git a/vector/src/main/java/im/vector/app/features/popup/VectorAlert.kt b/vector/src/main/java/im/vector/app/features/popup/VectorAlert.kt index 4394ef42d2..d46622ef32 100644 --- a/vector/src/main/java/im/vector/app/features/popup/VectorAlert.kt +++ b/vector/src/main/java/im/vector/app/features/popup/VectorAlert.kt @@ -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? = null @@ -114,6 +109,4 @@ open class DefaultVectorAlert( override var colorAttribute: Int? = null override var viewBinder: VectorAlert.ViewBinder? = null - } - diff --git a/vector/src/main/java/im/vector/app/features/popup/VerificationVectorAlert.kt b/vector/src/main/java/im/vector/app/features/popup/VerificationVectorAlert.kt index 3c02548725..2cd9ab59ac 100644 --- a/vector/src/main/java/im/vector/app/features/popup/VerificationVectorAlert.kt +++ b/vector/src/main/java/im/vector/app/features/popup/VerificationVectorAlert.kt @@ -47,13 +47,4 @@ class VerificationVectorAlert(uid: String, } } } - - - } - - - - - -