mirror of
https://github.com/mediathekview/zapp.git
synced 2024-09-20 04:12:14 +02:00
Use LifecycleService instead of deprecated IntentService
This commit is contained in:
parent
8378a19e22
commit
bb54c225e9
@ -8,10 +8,7 @@ import android.graphics.Bitmap
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ServiceLifecycleDispatcher
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.*
|
||||
import com.google.android.exoplayer2.ui.DefaultMediaDescriptionAdapter
|
||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager
|
||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager.BitmapCallback
|
||||
@ -25,7 +22,7 @@ import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.inject
|
||||
import timber.log.Timber
|
||||
|
||||
class BackgroundPlayerService : IntentService("BackgroundPlayerService"),
|
||||
class BackgroundPlayerService : LifecycleService(),
|
||||
MediaDescriptionAdapter,
|
||||
PlayerNotificationManager.NotificationListener,
|
||||
LifecycleOwner {
|
||||
@ -60,8 +57,6 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"),
|
||||
|
||||
private val binder = Binder()
|
||||
|
||||
private val lifecycleDispatcher: ServiceLifecycleDispatcher = ServiceLifecycleDispatcher(this)
|
||||
|
||||
private var playerNotificationManager: PlayerNotificationManager? = null
|
||||
private var foregroundActivityIntent: Intent? = null
|
||||
private var isPlaybackInBackground = false
|
||||
@ -74,7 +69,6 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"),
|
||||
* So is is save to aquire locks and release them in [.onDestroy]
|
||||
*/
|
||||
override fun onCreate() {
|
||||
lifecycleDispatcher.onServicePreSuperOnCreate()
|
||||
super.onCreate()
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
@ -83,28 +77,16 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"),
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
lifecycleDispatcher.onServicePreSuperOnBind()
|
||||
super.onBind(intent)
|
||||
|
||||
return binder
|
||||
}
|
||||
|
||||
override fun onStart(intent: Intent?, startId: Int) {
|
||||
lifecycleDispatcher.onServicePreSuperOnStart()
|
||||
super.onStart(intent, startId)
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
handleIntent(intent)
|
||||
return Service.START_STICKY
|
||||
}
|
||||
|
||||
override fun onHandleIntent(intent: Intent?) {}
|
||||
|
||||
override fun getLifecycle(): Lifecycle {
|
||||
return lifecycleDispatcher.lifecycle
|
||||
}
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent) {
|
||||
super.onTaskRemoved(rootIntent)
|
||||
onDestroy()
|
||||
@ -118,7 +100,6 @@ class BackgroundPlayerService : IntentService("BackgroundPlayerService"),
|
||||
playerNotificationManager?.setPlayer(null)
|
||||
}
|
||||
|
||||
lifecycleDispatcher.onServicePreSuperOnDestroy()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user