mirror of
https://github.com/GrakovNe/lissen-android.git
synced 2026-07-31 02:18:14 -04:00
offline
This commit is contained in:
@@ -28,7 +28,7 @@ android {
|
||||
}
|
||||
debug {
|
||||
matchingFallbacks.add("release")
|
||||
isDebuggable = true
|
||||
isDebuggable = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,18 @@ class LissenMediaProvider @Inject constructor(
|
||||
fun provideFileUri(
|
||||
libraryItemId: String,
|
||||
chapterId: String
|
||||
): Uri = when (cacheConfiguration.localCacheUsing()) {
|
||||
true -> localCacheRepository.provideFileUri(libraryItemId, chapterId)
|
||||
false -> providePreferredChannel().provideFileUri(libraryItemId, chapterId)
|
||||
): ApiResult<Uri> = when (cacheConfiguration.localCacheUsing()) {
|
||||
true -> localCacheRepository
|
||||
.provideFileUri(libraryItemId, chapterId)
|
||||
?.let { ApiResult.Success(it) }
|
||||
?: ApiResult.Error(ApiError.InternalError)
|
||||
|
||||
false -> localCacheRepository
|
||||
.provideFileUri(libraryItemId, chapterId)
|
||||
?.let { ApiResult.Success(it) }
|
||||
?: providePreferredChannel()
|
||||
.provideFileUri(libraryItemId, chapterId)
|
||||
.let { ApiResult.Success(it) }
|
||||
}
|
||||
|
||||
fun provideBookCoverUri(
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.grakovne.lissen.content.cache
|
||||
|
||||
import android.net.Uri
|
||||
import android.net.Uri.parse
|
||||
import androidx.core.net.toFile
|
||||
import org.grakovne.lissen.channel.common.ApiError
|
||||
import org.grakovne.lissen.channel.common.ApiResult
|
||||
import org.grakovne.lissen.content.cache.api.CachedBookRepository
|
||||
@@ -12,6 +13,7 @@ import org.grakovne.lissen.domain.PagedItems
|
||||
import org.grakovne.lissen.domain.PlaybackProgress
|
||||
import org.grakovne.lissen.domain.PlaybackSession
|
||||
import org.grakovne.lissen.domain.RecentBook
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
@@ -23,8 +25,10 @@ class LocalCacheRepository @Inject constructor(
|
||||
private val properties: CacheBookStorageProperties
|
||||
) {
|
||||
|
||||
fun provideFileUri(libraryItemId: String, fileId: String): Uri =
|
||||
cachedBookRepository.provideFileUri(libraryItemId, fileId)
|
||||
fun provideFileUri(libraryItemId: String, fileId: String): Uri? =
|
||||
cachedBookRepository
|
||||
.provideFileUri(libraryItemId, fileId)
|
||||
.takeIf { it.toFile().exists() }
|
||||
|
||||
fun provideBookCover(bookId: String): Uri =
|
||||
cachedBookRepository
|
||||
@@ -32,7 +36,6 @@ class LocalCacheRepository @Inject constructor(
|
||||
.toString()
|
||||
.let { parse(it) }
|
||||
|
||||
|
||||
/**
|
||||
* For the local cache we avoiding to create intermediary entity like Session and using BookId
|
||||
* as a Playback Session Key
|
||||
|
||||
@@ -117,19 +117,27 @@ class AudioPlayerService : MediaSessionService() {
|
||||
val prepareQueue = async {
|
||||
val playingQueue = book
|
||||
.files
|
||||
.map { file ->
|
||||
MediaItem.Builder()
|
||||
.setMediaId(file.id)
|
||||
.setUri(mediaChannel.provideFileUri(book.id, file.id))
|
||||
.setTag(book)
|
||||
.setMediaMetadata(
|
||||
MediaMetadata.Builder()
|
||||
.setTitle(file.name)
|
||||
.setArtist(book.title)
|
||||
.setArtworkUri(mediaChannel.provideBookCoverUri(book.id))
|
||||
.build()
|
||||
.mapNotNull { file ->
|
||||
mediaChannel
|
||||
.provideFileUri(book.id, file.id)
|
||||
.fold(
|
||||
onSuccess = {
|
||||
MediaItem.Builder()
|
||||
.setMediaId(file.id)
|
||||
.setUri(it)
|
||||
.setTag(book)
|
||||
.setMediaMetadata(
|
||||
MediaMetadata.Builder()
|
||||
.setTitle(file.name)
|
||||
.setArtist(book.title)
|
||||
.setArtworkUri(mediaChannel.provideBookCoverUri(book.id))
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
},
|
||||
onFailure = { null }
|
||||
)
|
||||
.build()
|
||||
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
|
||||
Reference in New Issue
Block a user