Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.os.Build
import android.os.Bundle
import android.os.Process
import android.os.ResultReceiver
Expand Down Expand Up @@ -303,7 +304,7 @@ open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by MainSco
val currentNavigator: StateFlow<MediaSessionNavigator?> get() = navigator

fun getNavigator(context: Context, publication: Publication, publicationId: PublicationId, initialLocator: Locator?): MediaSessionNavigator {
context.startService(Intent(context, serviceClass))
context.startForegroundServiceCompat(Intent(context, serviceClass))

currentNavigator.value
?.takeIf { it.publicationId == publicationId }
Expand All @@ -329,6 +330,14 @@ open class MediaService : MediaBrowserServiceCompat(), CoroutineScope by MainSco

}

private fun Context.startForegroundServiceCompat(intent: Intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
}

// FIXME: Move to r2-shared
internal fun <T> createIfNull(property: KMutableProperty0<T?>, owner: Any, factory: () -> T): T =
property.get() ?: synchronized(owner) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.deferred
import nl.komponents.kovenant.task

@Deprecated("Dependency to Fuel and kovenant will eventually be removed from the Readium Toolkit")
fun Request.promise(): Promise<Triple<Request, Response, ByteArray>, Exception> {
val deferred = deferred<Triple<Request, Response, ByteArray>, Exception>()
task { response() } success {
Expand Down