Skip to content

Commit

Permalink
Pull request #473: MCA-4335 Various fixes and customization improveme…
Browse files Browse the repository at this point in the history
…nt in InfobipRtcUi

Merge in MML/infobip-mobile-messaging-android from jdzubak-MCA-4335-rtcui-fixes-and-improvements to master

Squashed commit of the following:

commit 343510896ee47ce3d881aca7d7a12bfd22b05563
Author: Jakub Dzubak <[email protected]>
Date:   Mon Dec 9 08:32:36 2024 +0100

    MCA-4335 Various fixes and customization improvement in InfobipRtcUi

commit 0182e3cb5c06dd3624a7f60af3e08a48ebde19c6
Author: Jakub Dzubak <[email protected]>
Date:   Fri Dec 6 15:04:06 2024 +0100

    MCA-4335 Various fixes and customization improvement in InfobipRtcUi
  • Loading branch information
jakubdzubak1 committed Dec 11, 2024
1 parent 73d7ead commit 7fc64c2
Show file tree
Hide file tree
Showing 26 changed files with 383 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import android.provider.MediaStore;
import android.provider.OpenableColumns;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.FragmentActivity;

import org.infobip.mobile.messaging.logging.MobileMessagingLogger;
import org.infobip.mobile.messaging.mobileapi.InternalSdkError;
import org.infobip.mobile.messaging.util.DateTimeUtil;
Expand All @@ -23,6 +19,10 @@
import java.io.File;
import java.util.Date;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.FragmentActivity;

public class InAppChatAttachmentHelper {
private static final String JPEG_FILE_PREFIX = "IMG_";
private static final String JPEG_FILE_SUFFIX = ".jpg";
Expand Down Expand Up @@ -169,6 +169,6 @@ private static Uri getUriFromMediaStoreURI(Uri mediaStoreUri, FragmentActivity a
public interface InAppChatAttachmentHelperListener {
void onAttachmentCreated(InAppChatMobileAttachment attachment);

void onError(Context context, InternalSdkError.InternalSdkException exception);
void onError(Context context, Exception exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ class InAppChatFragment : Fragment(), InAppChatFragmentActivityResultDelegate.Re

override fun onError(
context: Context?,
exception: InternalSdkError.InternalSdkException?
exception: Exception?
) {
if (exception!!.message == InternalSdkError.ERROR_ATTACHMENT_MAX_SIZE_EXCEEDED.get()) {
MobileMessagingLogger.e(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.infobip.mobile.messaging.chat.view.styles

data class InAppChatTheme @JvmOverloads constructor(
val chatToolbarStyle: InAppChatToolbarStyle = InAppChatToolbarStyle(),
val attachmentToolbarStyle: InAppChatToolbarStyle = InAppChatToolbarStyle(),
val chatStyle: InAppChatStyle = InAppChatStyle(),
val chatInputViewStyle: InAppChatInputViewStyle = InAppChatInputViewStyle(),
val chatToolbarStyle: InAppChatToolbarStyle = InAppChatToolbarStyle(),
val attachmentToolbarStyle: InAppChatToolbarStyle = InAppChatToolbarStyle(),
val chatStyle: InAppChatStyle = InAppChatStyle(),
val chatInputViewStyle: InAppChatInputViewStyle = InAppChatInputViewStyle(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ interface InfobipRtcUi {
* 3. Default [InfobipRtcUi] style defined by InfobipRtcUi library
*
* Final value for every theme attribute is evaluated separately.
* It means you can define [InfobipRtcUiTheme.incomingCallMessageStyle] in runtime, colors in xml and skip icons.
* Library will use [InfobipRtcUiTheme.incomingCallMessageStyle] you defined in runtime, colors you defined in xml and default icons provided by library itself.
* It means you can define [InfobipRtcUiTheme.incomingCallScreenStyle] in runtime, colors in xml and skip icons.
* Library will use [InfobipRtcUiTheme.incomingCallScreenStyle] you defined in runtime, colors you defined in xml and default icons provided by library itself.
*
* @param theme data object holding all theme attributes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import com.infobip.webrtc.ui.internal.ui.CallActivity
import com.infobip.webrtc.ui.model.InCallButton
import com.infobip.webrtc.ui.view.styles.Colors
import com.infobip.webrtc.ui.view.styles.Icons
import com.infobip.webrtc.ui.view.styles.IncomingCallMessageStyle
import com.infobip.webrtc.ui.view.styles.InCallScreenStyle
import com.infobip.webrtc.ui.view.styles.IncomingCallScreenStyle
import com.infobip.webrtc.ui.view.styles.InfobipRtcUiTheme
import java.util.Locale

Expand Down Expand Up @@ -66,11 +67,9 @@ internal interface SdkLifetimeCache {
var locale: Locale?
var theme: InfobipRtcUiTheme?
val colors: Colors?
get() = theme?.colors
val icons: Icons?
get() = theme?.icons
val incomingCallMessageStyle: IncomingCallMessageStyle?
get() = theme?.incomingCallMessageStyle
val incomingCallScreenStyle: IncomingCallScreenStyle?
val inCallScreenStyle: InCallScreenStyle?
var inCallButtons: List<InCallButton>
var callErrorMapper: RtcUiCallErrorMapper?
}
Expand All @@ -89,8 +88,11 @@ internal class SdkLifetimeCacheImpl : SdkLifetimeCache {
get() = theme?.colors
override val icons: Icons?
get() = theme?.icons
override val incomingCallMessageStyle: IncomingCallMessageStyle?
get() = theme?.incomingCallMessageStyle
override val incomingCallScreenStyle: IncomingCallScreenStyle?
get() = theme?.incomingCallScreenStyle
override val inCallScreenStyle: InCallScreenStyle?
get() = theme?.inCallScreenStyle

override var inCallButtons: List<InCallButton> = emptyList()
get() = field.takeIf { it.isNotEmpty() } ?: listOf(
InCallButton.HangUp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,23 @@ internal class CallNotificationFactoryImpl(
isSilent: Boolean,
): Notification {
val themedContext by lazy { ContextThemeWrapper(context, R.style.InfobipRtcUi_Call) }
val incomeMessage: String? = Injector.cache.incomingCallMessageStyle?.messageText ?:
themedContext.resolveStyledStringAttribute(R.styleable.InfobipRtcUi_rtc_ui_incoming_call_message, R.attr.infobipRtcUiStyle, R.styleable.InfobipRtcUi)
val incomeHeadline: String? = Injector.cache.incomingCallMessageStyle?.headlineText ?:
themedContext.resolveStyledStringAttribute(R.styleable.InfobipRtcUi_rtc_ui_incoming_call_headline, R.attr.infobipRtcUiStyle, R.styleable.InfobipRtcUi)
val acceptCall = incomeMessage.isNullOrEmpty() && incomeHeadline.isNullOrEmpty()
val incomingCallScreenMessage: String? = Injector.cache.incomingCallScreenStyle?.messageText ?: themedContext.resolveStyledStringAttribute(
R.styleable.InfobipRtcUi_rtc_ui_incoming_call_message,
R.attr.infobipRtcUiStyle,
R.styleable.InfobipRtcUi
)
val incomingCallScreenHeadline: String? = Injector.cache.incomingCallScreenStyle?.headlineText ?: themedContext.resolveStyledStringAttribute(
R.styleable.InfobipRtcUi_rtc_ui_incoming_call_headline,
R.attr.infobipRtcUiStyle,
R.styleable.InfobipRtcUi
)
val incomingCallScreenCallerName: String? = Injector.cache.incomingCallScreenStyle?.callerName ?: themedContext.resolveStyledStringAttribute(
R.styleable.InfobipRtcUi_rtc_ui_incoming_call_caller_name,
R.attr.infobipRtcUiStyle,
R.styleable.InfobipRtcUi
)
val acceptCall = incomingCallScreenMessage.isNullOrEmpty() && incomingCallScreenHeadline.isNullOrEmpty()
val displayName = incomingCallScreenCallerName ?: callerName

val acceptIntent = PendingIntent.getActivity(
context, CALL_ACCEPT_REQUEST_CODE,
Expand All @@ -137,11 +149,11 @@ internal class CallNotificationFactoryImpl(
updateCurrentImmutableFlags
)

return commonCallNotification(callerName, description, INCOMING_CALL_NOTIFICATION_CHANNEL_ID) {
return commonCallNotification(displayName, description, INCOMING_CALL_NOTIFICATION_CHANNEL_ID) {
foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE
setStyle(
NotificationCompat.CallStyle.forIncomingCall(
Person.Builder().setName(callerName).setImportant(true).build(),
Person.Builder().setName(displayName).setImportant(true).build(),
declineIntent,
acceptIntent
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ import com.infobip.webrtc.ui.internal.utils.throttleFirst
import com.infobip.webrtc.ui.model.RtcUiError
import com.infobip.webrtc.ui.view.styles.Colors
import com.infobip.webrtc.ui.view.styles.Icons
import com.infobip.webrtc.ui.view.styles.IncomingCallMessageStyle
import com.infobip.webrtc.ui.view.styles.InCallScreenStyle
import com.infobip.webrtc.ui.view.styles.IncomingCallScreenStyle
import com.infobip.webrtc.ui.view.styles.InfobipRtcUiTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -116,9 +117,10 @@ class CallActivity : AppCompatActivity(R.layout.activity_call) {
attrs: AttributeSet
): View? {
Injector.cache.theme = InfobipRtcUiTheme(
incomingCallScreenStyle = Injector.cache.incomingCallScreenStyle ?: IncomingCallScreenStyle(this, attrs),
inCallScreenStyle = Injector.cache.inCallScreenStyle ?: InCallScreenStyle(this, attrs),
colors = Injector.cache.colors ?: Colors(this, attrs),
icons = Injector.cache.icons ?: Icons(this, attrs),
incomingCallMessageStyle = Injector.cache.incomingCallMessageStyle ?: IncomingCallMessageStyle(this, attrs)
)
return super.onCreateView(parent, name, context, attrs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ internal class CallViewModel : ViewModel() {
}
}

fun toggleMute() {
fun toggleMic() {
runCatching {
val newValue = !state.value.isMuted
callsDelegate.mute(newValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.infobip.webrtc.ui.internal.core.TAG
import com.infobip.webrtc.ui.internal.model.CallState
import com.infobip.webrtc.ui.internal.service.ScreenShareService
import com.infobip.webrtc.ui.internal.ui.CallViewModel
import com.infobip.webrtc.ui.internal.ui.view.CallAlert
import com.infobip.webrtc.ui.internal.ui.view.CircleImageButton
import com.infobip.webrtc.ui.internal.ui.view.InCallButtonAbs
import com.infobip.webrtc.ui.internal.ui.view.PipParamsFactory
Expand Down Expand Up @@ -75,8 +76,12 @@ class InCallFragment : Fragment() {
const val PIP_ACTION_VIDEO = 3
const val PIP_ACTION_HANGUP = 4

fun pipActionIntent(pipAction: Int): Intent {
fun pipActionIntent(
context: Context,
pipAction: Int
): Intent {
return Intent(ACTION_PIP).apply {
setPackage(context.packageName)
putExtra(EXTRAS_PIP_ACTION, pipAction)
}
}
Expand Down Expand Up @@ -145,7 +150,7 @@ class InCallFragment : Fragment() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == ACTION_PIP) {
when (intent.getIntExtra(EXTRAS_PIP_ACTION, 0)) {
PIP_ACTION_MUTE -> toggleMute()
PIP_ACTION_MUTE -> toggleMic()
PIP_ACTION_SPEAKER -> toggleSpeaker()
PIP_ACTION_VIDEO -> toggleVideo()
PIP_ACTION_HANGUP -> viewModel.hangup()
Expand All @@ -156,7 +161,7 @@ class InCallFragment : Fragment() {
}

private var speakerButton: InCallButtonAbs? = null
private var muteButton: InCallButtonAbs? = null
private var micButton: InCallButtonAbs? = null
private var flipCamButton: InCallButtonAbs? = null
private var screenShareButton: InCallButtonAbs? = null
private var videoButton: InCallButtonAbs? = null
Expand Down Expand Up @@ -243,7 +248,7 @@ class InCallFragment : Fragment() {
setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL)
}
screenSharingRenderers.setOnTouchListener(getLocalVideoTouchListener())
viewModel.peerName.let {
(Injector.cache.inCallScreenStyle?.callerName ?: viewModel.peerName).let {
nameInVoice.text = it
nameInVideo.text = it
nameInPip.text = it
Expand Down Expand Up @@ -348,10 +353,10 @@ class InCallFragment : Fragment() {
}
}

R.id.rtc_ui_mute_button -> {
muteButton = button
muteButton?.setOnClickListener {
toggleMute()
R.id.rtc_ui_mic_button -> {
micButton = button
micButton?.setOnClickListener {
toggleMic()
buttonDesc.onClick()
}
}
Expand Down Expand Up @@ -392,10 +397,9 @@ class InCallFragment : Fragment() {
R.id.rtc_ui_hang_up_button -> {
hangupButton = button
Injector.cache.colors?.let { res ->
hangupButton?.setIconTint(ColorStateList.valueOf(res.rtcUiActionsIcon))
hangupButton?.setBackgroundColor(ColorStateList.valueOf(res.rtcUiHangup))
hangupButton?.setIconTint(ColorStateList.valueOf(res.actionsIcon))
hangupButton?.setBackgroundColor(ColorStateList.valueOf(res.hangup))
}
hangupButton?.setLabelColor()
hangupButton?.setOnClickListener {
viewModel.hangup()
}
Expand Down Expand Up @@ -438,10 +442,11 @@ class InCallFragment : Fragment() {
//screenshare
binding.screenSharingNotice.isVisible = isLocalScreenShare
binding.screenSharingDisable.isVisible = isLocalScreenShare && !isPip
Injector.cache.colors.let { res -> (if (isLocalScreenShare) res?.rtcUiActionsBackground else res?.rtcUiBackground)?.let { binding.background.setBackgroundColor(it) } }
Injector.cache.colors.let { res -> (if (isLocalScreenShare) res?.actionsBackground else res?.background)?.let { binding.background.setBackgroundColor(it) } }
//another views
binding.connectionAlert.isVisible = callAlert != null && !isPip && showControls
binding.connectionAlert.setMode(callAlert)
binding.mutedMicrophoneAlert.setMode(CallAlert.Mode.DisabledMic)
binding.mutedMicrophoneAlert.isVisible = isMuted && !isPip && showControls
binding.peerMuteIndicatorInVideo.isVisible = (isRemoteVideo || isLocalScreenShare || isRemoteScreenShare) && isPeerMuted == true && !isPip && showControls
binding.peerMuteIndicatorInVoice.isVisible = !isRemoteVideo && !isLocalScreenShare && !isRemoteScreenShare && isPeerMuted == true && !isPip
Expand All @@ -452,11 +457,14 @@ class InCallFragment : Fragment() {
binding.bottomSheet.bottomSheetButtons.isVisible = !isPip
showFlipCam(isLocalVideo)
//check state
muteButton?.isChecked = !isMuted
micButton?.isChecked = isMuted
speakerButton?.isChecked = isSpeakerOn
screenShareButton?.isChecked = isLocalScreenShare
videoButton?.isChecked = isLocalVideo
customInCallButtons.forEach { it.refreshChecked(); it.refreshEnabled() }
customInCallButtons.forEach {
it.refreshChecked()
it.refreshEnabled()
}
}
}

Expand Down Expand Up @@ -541,8 +549,8 @@ class InCallFragment : Fragment() {
viewModel.toggleVideo()
}

private fun toggleMute() {
viewModel.toggleMute()
private fun toggleMic() {
viewModel.toggleMic()
}

private fun toggleSpeaker() {
Expand Down Expand Up @@ -579,23 +587,23 @@ class InCallFragment : Fragment() {

private fun customize() {
Injector.cache.colors?.let { res ->
val foregroundColorStateList = ColorStateList.valueOf(res.rtcUiForeground)
val foregroundColorStateList = ColorStateList.valueOf(res.foreground)
with(binding) {
toolbarBackground.setBackgroundColor(res.rtcUiOverlayBackground)
toolbarBackground.setBackgroundColor(res.overlayBackground)
nameInVideo.setTextColor(foregroundColorStateList)
nameInVoice.setTextColor(foregroundColorStateList)
nameInPip.setTextColor(foregroundColorStateList)
peerMuteIndicatorInVideo.imageTintList = foregroundColorStateList
peerMuteIndicatorInVoice.imageTintList = foregroundColorStateList
nameDivider.setBackgroundColor(res.rtcUiForeground)
nameDivider.setBackgroundColor(res.foreground)
elapsedTimeVideo.setTextColor(foregroundColorStateList)
elapsedTimeVoice.setTextColor(foregroundColorStateList)
collapseCallButton.imageTintList = foregroundColorStateList
avatar.imageTintList = foregroundColorStateList
background.setBackgroundColor(res.rtcUiBackground)
bottomSheet.pill.backgroundTintList = ColorStateList.valueOf(res.rtcUiColorSheetPill)
bottomSheet.divider.setBackgroundColor(res.rtcUiColorActionsDivider)
bottomSheet.bottomSheetButtons.setBackgroundColor(res.rtcUiColorSheetBackground)
background.setBackgroundColor(res.background)
bottomSheet.pill.backgroundTintList = ColorStateList.valueOf(res.sheetPill)
bottomSheet.divider.setBackgroundColor(res.actionsDivider)
bottomSheet.bottomSheetButtons.setBackgroundColor(res.sheetBackground)
}
}
}
Expand Down Expand Up @@ -700,7 +708,7 @@ class InCallFragment : Fragment() {
}
_binding = null
hangupButton?.setOnClickListener(null)
muteButton?.setOnClickListener(null)
micButton?.setOnClickListener(null)
speakerButton?.setOnClickListener(null)
flipCamButton?.setOnClickListener(null)
videoButton?.setOnClickListener(null)
Expand Down
Loading

0 comments on commit 7fc64c2

Please sign in to comment.