Skip to content

Commit

Permalink
Feature/50 downloads redesign (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrakovNe authored Dec 1, 2024
1 parent b63163e commit 5cc540a
Show file tree
Hide file tree
Showing 51 changed files with 951 additions and 631 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ android {
applicationId = "org.grakovne.lissen"
minSdk = 28
targetSdk = 35
versionCode = 44
versionName = "1.1.13"
versionCode = 45
versionName = "1.1.14"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.grakovne.lissen.channel.audiobookshelf.common.converter

import org.grakovne.lissen.channel.audiobookshelf.library.model.LibraryItemsResponse
import org.grakovne.lissen.domain.Book
import org.grakovne.lissen.domain.BookCachedState
import org.grakovne.lissen.domain.PagedItems
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -19,7 +18,6 @@ class LibraryPageResponseConverter @Inject constructor() {
id = it.id,
title = title,
author = it.media.metadata.authorName,
cachedState = BookCachedState.ABLE_TO_CACHE,
duration = it.media.duration.toInt(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BookResponseConverter @Inject constructor() {
start = it.start,
end = it.end,
title = it.title,
available = true,
id = it.id,
duration = it.end - it.start,
)
Expand All @@ -39,6 +40,7 @@ class BookResponseConverter @Inject constructor() {
?.fold(0.0 to mutableListOf<BookChapter>()) { (accDuration, chapters), file ->
chapters.add(
BookChapter(
available = true,
start = accDuration,
end = accDuration + file.duration,
title = file.metaTags?.tagTitle
Expand Down Expand Up @@ -74,6 +76,7 @@ class BookResponseConverter @Inject constructor() {
?: emptyList(),
chapters = maybeChapters ?: filesAsChapters(),
libraryId = item.libraryId,
localProvided = false,
progress = progressResponse
?.let {
MediaProgress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ package org.grakovne.lissen.channel.audiobookshelf.library.converter

import org.grakovne.lissen.channel.audiobookshelf.library.model.LibraryItem
import org.grakovne.lissen.domain.Book
import org.grakovne.lissen.domain.BookCachedState
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class LibrarySearchItemsConverter @Inject constructor() {
fun apply(response: List<LibraryItem>): List<Book> {
return response
.mapNotNull {
val title = it.media.metadata.title ?: return@mapNotNull null

Book(
id = it.id,
title = title,
author = it.media.metadata.authorName,
cachedState = BookCachedState.ABLE_TO_CACHE,
duration = it.media.duration.toInt(),
)
}
}
fun apply(response: List<LibraryItem>) = response
.mapNotNull {
Book(
id = it.id,
title = it.media.metadata.title ?: return@mapNotNull null,
author = it.media.metadata.authorName,
duration = it.media.duration.toInt(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.grakovne.lissen.channel.audiobookshelf.podcast.converter

import org.grakovne.lissen.channel.audiobookshelf.podcast.model.PodcastItemsResponse
import org.grakovne.lissen.domain.Book
import org.grakovne.lissen.domain.BookCachedState
import org.grakovne.lissen.domain.PagedItems
import javax.inject.Inject
import javax.inject.Singleton
Expand All @@ -19,7 +18,6 @@ class PodcastPageResponseConverter @Inject constructor() {
id = it.id,
title = title,
author = it.media.metadata.author,
cachedState = BookCachedState.UNABLE_TO_CACHE,
duration = it.media.duration.toInt(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PodcastResponseConverter @Inject constructor() {
title = file.title,
duration = file.audioFile.duration,
id = file.id,
available = true,
),
)
accDuration + file.audioFile.duration to chapters
Expand All @@ -46,6 +47,7 @@ class PodcastResponseConverter @Inject constructor() {
title = item.media.metadata.title,
libraryId = item.libraryId,
author = item.media.metadata.author,
localProvided = false,
files = orderedEpisodes
?.map {
BookFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.grakovne.lissen.channel.audiobookshelf.podcast.converter

import org.grakovne.lissen.channel.audiobookshelf.podcast.model.PodcastItem
import org.grakovne.lissen.domain.Book
import org.grakovne.lissen.domain.BookCachedState
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -17,7 +16,6 @@ class PodcastSearchItemsConverter @Inject constructor() {
id = it.id,
title = title,
author = it.media.metadata.author,
cachedState = BookCachedState.UNABLE_TO_CACHE,
duration = it.media.duration.toInt(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.grakovne.lissen.channel.common.ChannelProvider
import org.grakovne.lissen.channel.common.MediaChannel
import org.grakovne.lissen.content.cache.LocalCacheRepository
import org.grakovne.lissen.domain.Book
import org.grakovne.lissen.domain.BookCachedState.CACHED
import org.grakovne.lissen.domain.DetailedItem
import org.grakovne.lissen.domain.Library
import org.grakovne.lissen.domain.PagedItems
Expand Down Expand Up @@ -106,11 +105,7 @@ class LissenMediaProvider @Inject constructor(

return when (sharedPreferences.isForceCache()) {
true -> localCacheRepository.fetchBooks(pageSize, pageNumber)
false -> {
providePreferredChannel()
.fetchBooks(libraryId, pageSize, pageNumber)
.map { flagCached(it) }
}
false -> providePreferredChannel().fetchBooks(libraryId, pageSize, pageNumber)
}
}

Expand Down Expand Up @@ -212,25 +207,6 @@ class LissenMediaProvider @Inject constructor(

suspend fun fetchConnectionInfo() = providePreferredChannel().fetchConnectionInfo()

private suspend fun flagCached(page: PagedItems<Book>): PagedItems<Book> {
val cachedBooks = localCacheRepository.fetchCachedBookIds()

val items = page
.items
.map { book ->
when (cachedBooks.contains(book.id)) {
true ->
book
.copy(cachedState = CACHED)
.also { Log.d(TAG, "${book.id} flagged as Cached") }

false -> book
}
}

return page.copy(items = items)
}

fun provideAuthService(): ChannelAuthService = channels[sharedPreferences.getChannel()]
?.provideChannelAuth()
?: throw IllegalStateException("Selected auth service has been requested but not selected")
Expand Down
Loading

0 comments on commit 5cc540a

Please sign in to comment.