Skip to content

Commit

Permalink
Remove depreciated call of lifecycleScope.launchWhenCreated
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Jan 23, 2024
1 parent 54af5b1 commit ae6c7c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.media3.common.Player
import ch.srgssr.pillarbox.analytics.SRGAnalytics
import ch.srgssr.pillarbox.core.business.integrationlayer.service.IlHost
Expand Down Expand Up @@ -72,21 +72,17 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
val ilHost = (intent.extras?.getSerializable(ARG_IL_HOST) as URL?) ?: IlHost.DEFAULT
playerViewModel = ViewModelProvider(this, factory = SimplePlayerViewModel.Factory(application, ilHost))[SimplePlayerViewModel::class.java]
readIntent(intent)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
SRGAnalytics.trackPagView(DemoPageView("simple player", levels = listOf("app", "pillarbox")))
}
}
lifecycleScope.launchWhenCreated {
playerViewModel.pictureInPictureRatio.collectLatest {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && playerViewModel.pictureInPictureEnabled.value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
lifecycleScope.launch {
playerViewModel.pictureInPictureRatio.flowWithLifecycle(lifecycle, Lifecycle.State.CREATED).collectLatest {
val params = PictureInPictureParams.Builder()
.setAspectRatio(playerViewModel.pictureInPictureRatio.value)
.build()
setPictureInPictureParams(params)
}
}
}

// Bind PlaybackService to allow background playback and MediaNotification.
bindPlaybackService()
setContent {
Expand Down Expand Up @@ -166,6 +162,11 @@ class SimplePlayerActivity : ComponentActivity(), ServiceConnection {
}
}

override fun onResume() {
super.onResume()
SRGAnalytics.trackPagView(DemoPageView("simple player", levels = listOf("app", "pillarbox")))
}

override fun onStart() {
super.onStart()
playerViewModel.player.play()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.media3.common.Player
import ch.srgssr.pillarbox.analytics.SRGAnalytics
import ch.srgssr.pillarbox.demo.DemoPageView
Expand All @@ -43,14 +43,9 @@ class MediaControllerActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
SRGAnalytics.trackPagView(DemoPageView("media controller player", levels = listOf("app", "pillarbox")))
}
}
lifecycleScope.launchWhenCreated {
controllerViewModel.pictureInPictureRatio.collectLatest {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && controllerViewModel.pictureInPictureEnabled.value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
lifecycleScope.launch {
controllerViewModel.pictureInPictureRatio.flowWithLifecycle(lifecycle, Lifecycle.State.CREATED).collectLatest {
val params = PictureInPictureParams.Builder()
.setAspectRatio(controllerViewModel.pictureInPictureRatio.value)
.build()
Expand Down Expand Up @@ -111,4 +106,9 @@ class MediaControllerActivity : ComponentActivity() {
controllerViewModel.pictureInPictureEnabled.value = isInPictureInPictureMode
}
}

override fun onResume() {
super.onResume()
SRGAnalytics.trackPagView(DemoPageView("media controller player", levels = listOf("app", "pillarbox")))
}
}

0 comments on commit ae6c7c7

Please sign in to comment.