Skip to content

Commit

Permalink
Fix accept button notification (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandar-apostolov authored Apr 15, 2024
1 parent e27dfba commit d5fa4fa
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 112 deletions.
6 changes: 0 additions & 6 deletions stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -4116,7 +4116,6 @@ public final class io/getstream/video/android/core/notifications/NotificationCon

public abstract interface class io/getstream/video/android/core/notifications/NotificationHandler : io/getstream/android/push/permissions/NotificationPermissionHandler {
public static final field ACTION_ACCEPT_CALL Ljava/lang/String;
public static final field ACTION_DISMISS_NOTIFICATION Ljava/lang/String;
public static final field ACTION_INCOMING_CALL Ljava/lang/String;
public static final field ACTION_LEAVE_CALL Ljava/lang/String;
public static final field ACTION_LIVE_CALL Ljava/lang/String;
Expand All @@ -4128,8 +4127,6 @@ public abstract interface class io/getstream/video/android/core/notifications/No
public static final field INCOMING_CALL_NOTIFICATION_ID I
public static final field INTENT_EXTRA_CALL_CID Ljava/lang/String;
public static final field INTENT_EXTRA_CALL_DISPLAY_NAME Ljava/lang/String;
public static final field INTENT_EXTRA_NEXT_ACTION Ljava/lang/String;
public static final field INTENT_EXTRA_NEXT_ACTION_BUNDLE Ljava/lang/String;
public static final field INTENT_EXTRA_NOTIFICATION_ID Ljava/lang/String;
public abstract fun getOngoingCallNotification (Lio/getstream/video/android/model/StreamCallId;)Landroid/app/Notification;
public abstract fun getRingingCallNotification (Lio/getstream/video/android/core/RingingState;Lio/getstream/video/android/model/StreamCallId;Ljava/lang/String;)Landroid/app/Notification;
Expand All @@ -4140,7 +4137,6 @@ public abstract interface class io/getstream/video/android/core/notifications/No

public final class io/getstream/video/android/core/notifications/NotificationHandler$Companion {
public static final field ACTION_ACCEPT_CALL Ljava/lang/String;
public static final field ACTION_DISMISS_NOTIFICATION Ljava/lang/String;
public static final field ACTION_INCOMING_CALL Ljava/lang/String;
public static final field ACTION_LEAVE_CALL Ljava/lang/String;
public static final field ACTION_LIVE_CALL Ljava/lang/String;
Expand All @@ -4151,8 +4147,6 @@ public final class io/getstream/video/android/core/notifications/NotificationHan
public static final field INCOMING_CALL_NOTIFICATION_ID I
public static final field INTENT_EXTRA_CALL_CID Ljava/lang/String;
public static final field INTENT_EXTRA_CALL_DISPLAY_NAME Ljava/lang/String;
public static final field INTENT_EXTRA_NEXT_ACTION Ljava/lang/String;
public static final field INTENT_EXTRA_NEXT_ACTION_BUNDLE Ljava/lang/String;
public static final field INTENT_EXTRA_NOTIFICATION_ID Ljava/lang/String;
}

Expand Down
7 changes: 0 additions & 7 deletions stream-video-android-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@
</intent-filter>
</receiver>

<receiver android:name=".notifications.internal.receivers.DismissNotificationBroadcastReceiver"
android:exported="false">
<intent-filter android:priority="-1">
<action android:name="io.getstream.video.android.action.DISMISS_NOTIFICATION" />
</intent-filter>
</receiver>


<service android:name=".notifications.internal.service.CallService"
android:foregroundServiceType="shortService|microphone"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,8 @@ public class Call(
}

suspend fun accept(): Result<AcceptCallResponse> {
clientImpl.state.removeRingingCall()
clientImpl.state.maybeStopForegroundService()
return clientImpl.accept(type, id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ class ClientState(client: StreamVideo) {
_ringingCall.value = null
}

// Internal logic
private fun maybeStartForegroundService(call: Call, trigger: String) {
/**
* Start a foreground service that manages the call even when the UI is gone.
* This depends on the flag in [StreamVideoBuilder] called `runForegroundServiceForCalls`
*/
internal fun maybeStartForegroundService(call: Call, trigger: String) {
if (clientImpl.runForegroundService) {
val context = clientImpl.context
val serviceIntent = CallService.buildStartIntent(
Expand All @@ -140,7 +143,10 @@ class ClientState(client: StreamVideo) {
}
}

private fun maybeStopForegroundService() {
/**
* Stop the foreground service that manages the call even when the UI is gone.
*/
internal fun maybeStopForegroundService() {
if (clientImpl.runForegroundService) {
val context = clientImpl.context
val serviceIntent = CallService.buildStopIntent(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public interface NotificationHandler : NotificationPermissionHandler {
const val ACTION_INCOMING_CALL = "io.getstream.video.android.action.INCOMING_CALL"
const val ACTION_OUTGOING_CALL = "io.getstream.video.android.action.OUTGOING_CALL"
const val ACTION_ACCEPT_CALL = "io.getstream.video.android.action.ACCEPT_CALL"
const val ACTION_DISMISS_NOTIFICATION = "io.getstream.video.android.action.DISMISS_NOTIFICATION"
const val ACTION_REJECT_CALL = "io.getstream.video.android.action.REJECT_CALL"
const val ACTION_LEAVE_CALL = "io.getstream.video.android.action.LEAVE_CALL"
const val ACTION_ONGOING_CALL = "io.getstream.video.android.action.ONGOING_CALL"
Expand All @@ -47,10 +46,6 @@ public interface NotificationHandler : NotificationPermissionHandler {

const val INTENT_EXTRA_NOTIFICATION_ID: String =
"io.getstream.video.android.intent-extra.notification_id"
const val INTENT_EXTRA_NEXT_ACTION: String =
"io.getstream.video.android.intent-extra.next_action"
const val INTENT_EXTRA_NEXT_ACTION_BUNDLE: String =
"io.getstream.video.android.intent-extra.next_action_data"
const val INCOMING_CALL_NOTIFICATION_ID = 24756
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import android.content.pm.ResolveInfo
import io.getstream.log.taggedLogger
import io.getstream.video.android.core.notifications.DefaultNotificationHandler
import io.getstream.video.android.core.notifications.NotificationHandler
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_ACCEPT_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_LIVE_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_ONGOING_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_REJECT_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INCOMING_CALL_NOTIFICATION_ID
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_CALL_CID
import io.getstream.video.android.model.StreamCallId

Expand Down Expand Up @@ -96,7 +94,7 @@ internal class DefaultStreamIntentResolver(val context: Context) {
notificationId: Int,
): PendingIntent? =
searchActivityPendingIntent(
Intent(ACTION_LIVE_CALL),
Intent(NotificationHandler.ACTION_LIVE_CALL),
callId,
notificationId,
)
Expand All @@ -109,32 +107,13 @@ internal class DefaultStreamIntentResolver(val context: Context) {
*/
internal fun searchAcceptCallPendingIntent(
callId: StreamCallId,
): PendingIntent? = searchDismissNotificationPendingIntent(
callId,
notificationId: Int = NotificationHandler.INCOMING_CALL_NOTIFICATION_ID,
): PendingIntent? =
searchActivityPendingIntent(
Intent(ACTION_ACCEPT_CALL),
callId,
INCOMING_CALL_NOTIFICATION_ID,
),
)

/**
* Search for a broadcast that will dismiss a notification and will then proceed to call the [nextIntent].
*
* @param callId the callID
* @param nextIntent the next action intent.
*/
internal fun searchDismissNotificationPendingIntent(
callId: StreamCallId,
nextIntent: PendingIntent? = null,
): PendingIntent? {
val baseIntent = Intent(NotificationHandler.ACTION_DISMISS_NOTIFICATION)
baseIntent.putExtra(NotificationHandler.INTENT_EXTRA_NEXT_ACTION, nextIntent)
return searchBroadcastPendingIntent(
baseIntent,
Intent(NotificationHandler.ACTION_ACCEPT_CALL),
callId,
notificationId,
)
}

/**
* Searches for a broadcast receiver that can consume the [ACTION_REJECT_CALL] intent to reject
Expand Down Expand Up @@ -267,17 +246,16 @@ internal class DefaultStreamIntentResolver(val context: Context) {
baseIntent: Intent,
resolveInfo: ResolveInfo,
callId: StreamCallId,
notificationId: Int = INCOMING_CALL_NOTIFICATION_ID,
): Intent {
return Intent(baseIntent).apply {
component = ComponentName(
resolveInfo.activityInfo.applicationInfo.packageName,
resolveInfo.activityInfo.name,
)
putExtra(INTENT_EXTRA_CALL_CID, callId)
putExtra(NotificationHandler.INTENT_EXTRA_CALL_CID, callId)
putExtra(
NotificationHandler.INTENT_EXTRA_NOTIFICATION_ID,
notificationId,
NotificationHandler.INCOMING_CALL_NOTIFICATION_ID,
)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,12 @@ public final class io/getstream/video/android/compose/theme/VideoThemeKt {
public final class io/getstream/video/android/compose/ui/ComposableSingletons$StreamCallActivityComposeDelegateKt {
public static final field INSTANCE Lio/getstream/video/android/compose/ui/ComposableSingletons$StreamCallActivityComposeDelegateKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
public static field lambda-2 Lkotlin/jvm/functions/Function2;
public static field lambda-3 Lkotlin/jvm/functions/Function2;
public fun <init> ()V
public final fun getLambda-1$stream_video_android_ui_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-2$stream_video_android_ui_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-3$stream_video_android_ui_compose_release ()Lkotlin/jvm/functions/Function2;
}

public class io/getstream/video/android/compose/ui/ComposeStreamCallActivity : io/getstream/video/android/ui/common/StreamCallActivity {
Expand All @@ -378,6 +382,7 @@ public class io/getstream/video/android/compose/ui/StreamCallActivityComposeDele
public fun OnOutgoingCallContent (Landroidx/compose/ui/Modifier;Lio/getstream/video/android/core/Call;ZZLkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
public fun RejectedContent (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;Landroidx/compose/runtime/Composer;I)V
public fun RootContent (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;Landroidx/compose/runtime/Composer;I)V
public fun loadingContent (Lio/getstream/video/android/ui/common/StreamCallActivity;)V
public fun setContent (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ import android.net.Uri
import android.provider.Settings
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
Expand Down Expand Up @@ -76,6 +80,26 @@ public open class StreamCallActivityComposeDelegate : StreamActivityUiDelegate<S
private val logger by taggedLogger("StreamCallActivityUiDelegate")
}

/**
* Shows a progressbar until everything is set.
*/
override fun loadingContent(activity: StreamCallActivity) {
activity.setContent {
VideoTheme {
Box(
modifier = Modifier
.fillMaxSize()
.background(VideoTheme.colors.baseSheetPrimary),
) {
CircularProgressIndicator(
modifier = Modifier.align(Alignment.Center),
color = VideoTheme.colors.brandPrimary,
)
}
}
}
}

/**
* Create the delegate.
*
Expand Down Expand Up @@ -316,7 +340,7 @@ public open class StreamCallActivityComposeDelegate : StreamActivityUiDelegate<S
onCallAction(call, it)
},
durationPlaceholder = duration
?: stringResource(id = R.string.stream_audio_call_ui_calling),
?: "...",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class io/getstream/video/android/ui/common/AbstractCallActivity$Com
}

public abstract interface class io/getstream/video/android/ui/common/StreamActivityUiDelegate {
public abstract fun loadingContent (Lio/getstream/video/android/ui/common/StreamCallActivity;)V
public abstract fun setContent (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;)V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import io.getstream.video.android.core.Call

public interface StreamActivityUiDelegate<T : StreamCallActivity> {

/**
* Called when the [setContent] cannot yet be invoked (missing [Call] for e.g.).
* Used to show some UI in the activity if the call is not yet loaded.
*/
public fun loadingContent(activity: T)

/**
* Set the content for the activity,
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public abstract class StreamCallActivity : ComponentActivity() {
// Platform restriction
public final override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val uiDelegate = uiDelegate<StreamCallActivity>()
uiDelegate.loadingContent(this)
onPreCreate(savedInstanceState, null)
logger.d { "Entered [onCreate(Bundle?)" }
initializeCallOrFail(
Expand All @@ -145,6 +147,8 @@ public abstract class StreamCallActivity : ComponentActivity() {
persistentState: PersistableBundle?,
) {
super.onCreate(savedInstanceState)
val uiDelegate = uiDelegate<StreamCallActivity>()
uiDelegate.loadingContent(this)
onPreCreate(savedInstanceState, persistentState)
logger.d { "Entered [onCreate(Bundle, PersistableBundle?)" }
initializeCallOrFail(
Expand Down

0 comments on commit d5fa4fa

Please sign in to comment.