Refactor application loading + Paging on main Page
This commit is contained in:
parent
45f5e9023e
commit
1e58752008
26 changed files with 596 additions and 423 deletions
|
|
@ -1,16 +1,27 @@
|
|||
package com.pixelized.biblib.repository.book
|
||||
|
||||
|
||||
import android.util.Log
|
||||
import androidx.paging.DataSource
|
||||
import com.pixelized.biblib.database.BibLibDatabase
|
||||
import com.pixelized.biblib.database.crossref.BookAuthorCrossRef
|
||||
import com.pixelized.biblib.database.crossref.BookGenreCrossRef
|
||||
import com.pixelized.biblib.database.data.*
|
||||
import com.pixelized.biblib.database.relation.BookRelation
|
||||
import com.pixelized.biblib.model.*
|
||||
import com.pixelized.biblib.utils.injection.inject
|
||||
|
||||
class BookRepository : IBookRepository {
|
||||
val database: BibLibDatabase by inject()
|
||||
|
||||
override fun update(data: List<Book>) {
|
||||
override fun getAll(): List<Book> =
|
||||
database.bookDao().getAll().map { it.toBook() }
|
||||
|
||||
override fun getBook(): DataSource.Factory<Int, Book> =
|
||||
database.bookDao().getBook().map { it.toBook() }
|
||||
|
||||
override suspend fun update(data: List<Book>) {
|
||||
Log.d("pouet", "BookRepository#update(): $data")
|
||||
val authors = mutableSetOf<AuthorDbo>()
|
||||
val genres = mutableSetOf<GenreDbo>()
|
||||
val series = mutableSetOf<SeriesDbo>()
|
||||
|
|
@ -83,4 +94,42 @@ class BookRepository : IBookRepository {
|
|||
synopsis = synopsis,
|
||||
isNew = isNew,
|
||||
)
|
||||
|
||||
private fun BookRelation.toBook(): Book = Book(
|
||||
id = book.id,
|
||||
title = book.title,
|
||||
sort = book.sort,
|
||||
author = authors.map { it.toAuthor() },
|
||||
haveCover = book.haveCover,
|
||||
releaseDate = book.releaseDate,
|
||||
language = language?.toLanguage(),
|
||||
rating = book.rating,
|
||||
genre = genres?.map { it.toGenre() },
|
||||
series = series?.toSeries(),
|
||||
synopsis = book.synopsis,
|
||||
isNew = book.isNew,
|
||||
)
|
||||
|
||||
private fun AuthorDbo.toAuthor() = Author(
|
||||
id = id,
|
||||
name = name,
|
||||
sort = sort,
|
||||
)
|
||||
|
||||
private fun LanguageDbo.toLanguage() = Language(
|
||||
id = id,
|
||||
code = code,
|
||||
)
|
||||
|
||||
private fun GenreDbo.toGenre() = Genre(
|
||||
id = id,
|
||||
name = name,
|
||||
)
|
||||
|
||||
private fun SeriesDbo.toSeries() = Series(
|
||||
id = id,
|
||||
name = name,
|
||||
sort = sort,
|
||||
index = index,
|
||||
)
|
||||
}
|
||||
|
|
@ -1,7 +1,13 @@
|
|||
package com.pixelized.biblib.repository.book
|
||||
|
||||
import androidx.paging.DataSource
|
||||
import com.pixelized.biblib.model.Book
|
||||
|
||||
interface IBookRepository {
|
||||
fun update(data: List<Book>)
|
||||
|
||||
fun getAll(): List<Book>
|
||||
|
||||
fun getBook(): DataSource.Factory<Int, Book>
|
||||
|
||||
suspend fun update(data: List<Book>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue