diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/call/CallListener.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/call/CallListener.kt index 4704a657df..d17be59cd4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/call/CallListener.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/call/CallListener.kt @@ -67,6 +67,4 @@ interface CallListener { * Called when an asserted identity event is received */ fun onCallAssertedIdentityReceived(callAssertedIdentityContent: CallAssertedIdentityContent) - - } diff --git a/newsfragment/3451.feature b/newsfragment/3451.feature new file mode 100644 index 0000000000..dbf1a9b02c --- /dev/null +++ b/newsfragment/3451.feature @@ -0,0 +1 @@ +Adds support for receiving MSC3086 Asserted Identity events. \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/core/glide/AvatarPlaceholder.kt b/vector/src/main/java/im/vector/app/core/glide/AvatarPlaceholder.kt new file mode 100644 index 0000000000..32968c4f80 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/glide/AvatarPlaceholder.kt @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.core.glide + +import android.content.Context +import android.graphics.drawable.Drawable +import com.bumptech.glide.Priority +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.Options +import com.bumptech.glide.load.data.DataFetcher +import com.bumptech.glide.load.model.ModelLoader +import com.bumptech.glide.load.model.ModelLoaderFactory +import com.bumptech.glide.load.model.MultiModelLoaderFactory +import com.bumptech.glide.signature.ObjectKey +import im.vector.app.core.extensions.vectorComponent +import org.matrix.android.sdk.api.util.MatrixItem + +data class AvatarPlaceholder(val matrixItem: MatrixItem) + +class AvatarPlaceholderModelLoaderFactory(private val context: Context) : ModelLoaderFactory { + + override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { + return AvatarPlaceholderModelLoader(context) + } + + override fun teardown() { + // Is there something to do here? + } +} + +class AvatarPlaceholderModelLoader(private val context: Context) + : ModelLoader { + + override fun buildLoadData(model: AvatarPlaceholder, width: Int, height: Int, options: Options): ModelLoader.LoadData? { + return ModelLoader.LoadData(ObjectKey(model), AvatarPlaceholderDataFetcher(context, model)) + } + + override fun handles(model: AvatarPlaceholder): Boolean { + return true + } +} + +class AvatarPlaceholderDataFetcher(context: Context, private val data: AvatarPlaceholder) + : DataFetcher { + + private val avatarRenderer = context.vectorComponent().avatarRenderer() + + override fun loadData(priority: Priority, callback: DataFetcher.DataCallback) { + val avatarPlaceholder = avatarRenderer.getPlaceholderDrawable(data.matrixItem) + callback.onDataReady(avatarPlaceholder) + } + + override fun cleanup() { + // NOOP + } + + override fun cancel() { + // NOOP + } + + override fun getDataClass(): Class { + return Drawable::class.java + } + + override fun getDataSource(): DataSource { + return DataSource.LOCAL + } +} diff --git a/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt b/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt index 6ded33f823..74c9d4f0f6 100644 --- a/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt +++ b/vector/src/main/java/im/vector/app/core/glide/MyAppGlideModule.kt @@ -17,6 +17,7 @@ package im.vector.app.core.glide import android.content.Context +import android.graphics.drawable.Drawable import android.util.Log import com.bumptech.glide.Glide @@ -40,5 +41,10 @@ class MyAppGlideModule : AppGlideModule() { InputStream::class.java, VectorGlideModelLoaderFactory(context) ) + registry.append( + AvatarPlaceholder::class.java, + Drawable::class.java, + AvatarPlaceholderModelLoaderFactory(context) + ) } } diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index a18f5bb918..c76bf615ff 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -198,18 +198,7 @@ class VectorCallActivity : VectorBaseActivity(), CallContro } is CallState.Connected -> { if (callState.iceConnectionState == MxPeerConnectionState.CONNECTED) { - if (state.transferee !is VectorCallViewState.TransfereeState.NoTransferee) { - val transfereeName = if (state.transferee is VectorCallViewState.TransfereeState.KnownTransferee) { - state.transferee.name - } else { - getString(R.string.call_transfer_unknown_person) - } - views.callActionText.text = getString(R.string.call_transfer_transfer_to_title, transfereeName) - views.callActionText.isVisible = true - views.callActionText.setOnClickListener { callViewModel.handle(VectorCallViewActions.TransferCall) } - views.callStatusText.text = state.formattedDuration - configureCallInfo(state) - } else if (state.isLocalOnHold || state.isRemoteOnHold) { + if (state.isLocalOnHold || state.isRemoteOnHold) { views.smallIsHeldIcon.isVisible = true views.callVideoGroup.isInvisible = true views.callInfoGroup.isVisible = true @@ -225,6 +214,17 @@ class VectorCallActivity : VectorBaseActivity(), CallContro views.callStatusText.text = getString(R.string.call_held_by_user, it.getBestName()) } } + } else if (state.transferee !is VectorCallViewState.TransfereeState.NoTransferee) { + val transfereeName = if (state.transferee is VectorCallViewState.TransfereeState.KnownTransferee) { + state.transferee.name + } else { + getString(R.string.call_transfer_unknown_person) + } + views.callActionText.text = getString(R.string.call_transfer_transfer_to_title, transfereeName) + views.callActionText.isVisible = true + views.callActionText.setOnClickListener { callViewModel.handle(VectorCallViewActions.TransferCall) } + views.callStatusText.text = state.formattedDuration + configureCallInfo(state) } else { views.callStatusText.text = state.formattedDuration configureCallInfo(state) @@ -256,15 +256,15 @@ class VectorCallActivity : VectorBaseActivity(), CallContro private fun configureCallInfo(state: VectorCallViewState, blurAvatar: Boolean = false) { state.callInfo?.opponentUserItem?.let { - val colorFilter = ContextCompat.getColor(this, R.color.bg_call_screen) - avatarRenderer.renderBlur(it, views.bgCallView, sampling = 20, rounded = false, colorFilter = colorFilter) + val colorFilter = ContextCompat.getColor(this, R.color.bg_call_screen_blur) + avatarRenderer.renderBlur(it, views.bgCallView, sampling = 20, rounded = false, colorFilter = colorFilter, addPlaceholder = false) if (state.transferee is VectorCallViewState.TransfereeState.NoTransferee) { views.participantNameText.text = it.getBestName() } else { views.participantNameText.text = getString(R.string.call_transfer_consulting_with, it.getBestName()) } if (blurAvatar) { - avatarRenderer.renderBlur(it, views.otherMemberAvatar, sampling = 2, rounded = true, colorFilter = colorFilter) + avatarRenderer.renderBlur(it, views.otherMemberAvatar, sampling = 2, rounded = true, colorFilter = colorFilter, addPlaceholder = true) } else { avatarRenderer.render(it, views.otherMemberAvatar) } @@ -273,13 +273,14 @@ class VectorCallActivity : VectorBaseActivity(), CallContro views.otherKnownCallLayout.isVisible = false } else { val otherCall = callManager.getCallById(state.otherKnownCallInfo.callId) - val colorFilter = ContextCompat.getColor(this, R.color.bg_call_screen) + val colorFilter = ContextCompat.getColor(this, R.color.bg_call_screen_blur) avatarRenderer.renderBlur( matrixItem = state.otherKnownCallInfo.opponentUserItem, imageView = views.otherKnownCallAvatarView, sampling = 20, - rounded = false, - colorFilter = colorFilter + rounded = true, + colorFilter = colorFilter, + addPlaceholder = true ) views.otherKnownCallLayout.isVisible = true views.otherSmallIsHeldIcon.isVisible = otherCall?.let { it.isLocalOnHold || it.remoteOnHold }.orFalse() @@ -288,7 +289,7 @@ class VectorCallActivity : VectorBaseActivity(), CallContro private fun configureCallViews() { views.callControlsView.interactionListener = this - views.otherKnownCallAvatarView.setOnClickListener { + views.otherKnownCallLayout.setOnClickListener { withState(callViewModel) { val otherCall = callManager.getCallById(it.otherKnownCallInfo?.callId ?: "") ?: return@withState startActivity(newIntent(this, otherCall, null)) diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt index 68905b6c49..e7b2b629e1 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt @@ -89,7 +89,7 @@ class VectorCallViewModel @AssistedInject constructor( } } - override fun assertedIdentityChanged(){ + override fun assertedIdentityChanged() { setState { copy(callInfo = call?.extractCallInfo()) } @@ -208,17 +208,17 @@ class VectorCallViewModel @AssistedInject constructor( } } - private fun WebRtcCall.extractCallInfo(): VectorCallViewState.CallInfo{ + private fun WebRtcCall.extractCallInfo(): VectorCallViewState.CallInfo { val assertedIdentity = this.remoteAssertedIdentity - val matrixItem = if(assertedIdentity != null){ + val matrixItem = if (assertedIdentity != null) { val userId = if (MatrixPatterns.isUserId(assertedIdentity.id)) { assertedIdentity.id!! } else { // Need an id starting with @ "@${assertedIdentity.displayName}" } - MatrixItem.UserItem(userId,assertedIdentity.displayName, assertedIdentity.avatarUrl) - }else { + MatrixItem.UserItem(userId, assertedIdentity.displayName, assertedIdentity.avatarUrl) + } else { getOpponentAsMatrixItem(session) } return VectorCallViewState.CallInfo(callId, matrixItem) diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewState.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewState.kt index b6c226564e..3e7791cc08 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewState.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewState.kt @@ -20,7 +20,6 @@ import com.airbnb.mvrx.Async import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.Uninitialized import im.vector.app.features.call.audio.CallAudioManager -import org.matrix.android.sdk.api.MatrixPatterns import org.matrix.android.sdk.api.session.call.CallState import org.matrix.android.sdk.api.util.MatrixItem @@ -54,7 +53,7 @@ data class VectorCallViewState( data class CallInfo( val callId: String, - val opponentUserItem: MatrixItem? = null, + val opponentUserItem: MatrixItem? = null ) constructor(callArgs: CallArgs) : this( diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt index d56f1aa015..25463428e9 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallManager.kt @@ -424,7 +424,7 @@ class WebRtcCallManager @Inject constructor( } override fun onCallAssertedIdentityReceived(callAssertedIdentityContent: CallAssertedIdentityContent) { - if(!BuildConfig.handleCallAssertedIdentityEvents){ + if (!BuildConfig.handleCallAssertedIdentityEvents) { return } val call = callsByCallId[callAssertedIdentityContent.callId] diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index c6cceee3b9..787027e0e2 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -34,6 +34,7 @@ import com.bumptech.glide.request.target.DrawableImageViewTarget import com.bumptech.glide.request.target.Target import im.vector.app.core.contacts.MappedContact import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.core.glide.AvatarPlaceholder import im.vector.app.core.glide.GlideApp import im.vector.app.core.glide.GlideRequest import im.vector.app.core.glide.GlideRequests @@ -136,7 +137,7 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active matrixItem: MatrixItem, target: Target) { val placeholder = getPlaceholderDrawable(matrixItem) - buildGlideRequest(glideRequests, matrixItem.avatarUrl) + glideRequests.loadResolvedUrl(matrixItem.avatarUrl) .apply { when (matrixItem) { is MatrixItem.SpaceItem -> { @@ -175,7 +176,12 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active } @UiThread - fun renderBlur(matrixItem: MatrixItem, imageView: ImageView, sampling: Int, rounded: Boolean, @ColorInt colorFilter: Int? = null) { + fun renderBlur(matrixItem: MatrixItem, + imageView: ImageView, + sampling: Int, + rounded: Boolean, + @ColorInt colorFilter: Int? = null, + addPlaceholder: Boolean) { val transformations = mutableListOf>( BlurTransformation(20, sampling) ) @@ -185,14 +191,26 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active if (rounded) { transformations.add(CircleCrop()) } - buildGlideRequest(GlideApp.with(imageView), matrixItem.avatarUrl) - .apply(RequestOptions.bitmapTransform(MultiTransformation(transformations))) + val bitmapTransform = RequestOptions.bitmapTransform(MultiTransformation(transformations)) + val glideRequests = GlideApp.with(imageView) + val placeholderRequest = if (addPlaceholder) { + glideRequests + .load(AvatarPlaceholder(matrixItem)) + .apply(bitmapTransform) + } else { + null + } + glideRequests.loadResolvedUrl(matrixItem.avatarUrl) + .apply(bitmapTransform) + // We are using thumbnail and error API so we can have blur transformation on it... + .thumbnail(placeholderRequest) + .error(placeholderRequest) .into(imageView) } @AnyThread fun getCachedDrawable(glideRequests: GlideRequests, matrixItem: MatrixItem): Drawable { - return buildGlideRequest(glideRequests, matrixItem.avatarUrl) + return glideRequests.loadResolvedUrl(matrixItem.avatarUrl) .onlyRetrieveFromCache(true) .apply(RequestOptions.circleCropTransform()) .submit() @@ -220,9 +238,9 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active // PRIVATE API ********************************************************************************* - private fun buildGlideRequest(glideRequests: GlideRequests, avatarUrl: String?): GlideRequest { + private fun GlideRequests.loadResolvedUrl(avatarUrl: String?): GlideRequest { val resolvedUrl = resolvedUrl(avatarUrl) - return glideRequests.load(resolvedUrl) + return load(resolvedUrl) } private fun resolvedUrl(avatarUrl: String?): String? { diff --git a/vector/src/main/res/layout/activity_call.xml b/vector/src/main/res/layout/activity_call.xml index c4bba45ebf..1c9401b5ab 100644 --- a/vector/src/main/res/layout/activity_call.xml +++ b/vector/src/main/res/layout/activity_call.xml @@ -9,7 +9,7 @@ android:id="@+id/constraintLayout" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/bg_call_screen" + android:background="@color/bg_call_screen_blur" tools:ignore="MergeRootFrame"> - @@ -66,7 +69,7 @@ android:importantForAccessibility="no" android:src="@drawable/ic_call_small_pause" /> - + #1E0DBD8B #1E61708B - #99000000 + #99000000 + #27303A #FFFF4B55 #FF61708B