Skip to content

Commit

Permalink
Move enterPictureInPicture to onUserLeaveHint from onPause and add ex…
Browse files Browse the repository at this point in the history
…ception handling. (#1244)
  • Loading branch information
liviu-timar authored Dec 5, 2024
1 parent bb9c515 commit 8f47ccb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public abstract class io/getstream/video/android/ui/common/StreamCallActivity :
public fun onResume (Lio/getstream/video/android/core/Call;)V
public final fun onStop ()V
public fun onStop (Lio/getstream/video/android/core/Call;)V
public final fun onUserLeaveHint ()V
public fun onUserLeaveHint (Lio/getstream/video/android/core/Call;)V
public fun reject (Lio/getstream/video/android/core/Call;Lio/getstream/video/android/core/model/RejectReason;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun reject$default (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;Lio/getstream/video/android/core/model/RejectReason;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.app.PictureInPictureParams
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.PersistableBundle
Expand Down Expand Up @@ -231,6 +232,13 @@ public abstract class StreamCallActivity : ComponentActivity() {
}
}

public final override fun onUserLeaveHint() {
withCachedCall {
onUserLeaveHint(it)
super.onUserLeaveHint()
}
}

public final override fun onPause() {
withCachedCall {
onPause(it)
Expand Down Expand Up @@ -352,20 +360,36 @@ public abstract class StreamCallActivity : ComponentActivity() {
}

/**
* Called when the activity is paused. Makes sure the call object is available.
* Called when the activity is about to go into the background as the result of user choice. Makes sure the call object is available.
*
* @param call the call
*/
public open fun onPause(call: Call) {
public open fun onUserLeaveHint(call: Call) {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
// Default PiP behavior
if (isConnected(call) &&
if (packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) &&
isConnected(call) &&
!isChangingConfigurations &&
isVideoCall(call) &&
!isInPictureInPictureMode
) {
enterPictureInPicture()
try {
enterPictureInPicture()
} catch (e: Exception) {
logger.e(e) { "[onUserLeaveHint] Something went wrong when entering PiP." }
}
}

logger.d { "DefaultCallActivity - Leave Hinted (call -> $call)" }
}

/**
* Called when the activity is paused. Makes sure the call object is available.
*
* @param call the call
*/
public open fun onPause(call: Call) {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
logger.d { "DefaultCallActivity - Paused (call -> $call)" }
}

Expand Down

0 comments on commit 8f47ccb

Please sign in to comment.