mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-12 17:08:59 -04:00
Improved the books()
method to properly return the new books along with the old saved books.
This commit is contained in:
parent
4e3f66243b
commit
1cdd683e79
@ -31,7 +31,19 @@ import javax.inject.Inject
|
||||
class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
||||
|
||||
fun books() = box.asFlowable()
|
||||
.doOnNext(::removeBooksThatDoNotExist)
|
||||
.map { books ->
|
||||
books.map { bookOnDiskEntity ->
|
||||
bookOnDiskEntity.file.let { file ->
|
||||
// set zimReaderSource for previously saved books
|
||||
val zimReaderSource = ZimReaderSource(file)
|
||||
if (zimReaderSource.canOpenInLibkiwix()) {
|
||||
bookOnDiskEntity.zimReaderSource = zimReaderSource
|
||||
}
|
||||
}
|
||||
bookOnDiskEntity
|
||||
}
|
||||
}
|
||||
.doOnNext { removeBooksThatDoNotExist(it.toMutableList()) }
|
||||
.map { books -> books.filter { it.zimReaderSource.exists() } }
|
||||
.map { it.map(::BookOnDisk) }
|
||||
|
||||
@ -92,7 +104,7 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
||||
}
|
||||
|
||||
private fun removeBooksThatDoNotExist(books: MutableList<BookOnDiskEntity>) {
|
||||
delete(books.filterNot { it.zimReaderSource.exists() || it.file.exists() })
|
||||
delete(books.filterNot { it.zimReaderSource.exists() })
|
||||
}
|
||||
|
||||
private fun delete(books: List<BookOnDiskEntity>) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user