mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-11 08:27:50 -04:00
Merge pull request #1378 from kiwix/feature/macgills/#1376-delete-zims
#1376 Unable to delete old zim files after re-install
This commit is contained in:
commit
13cb6ffd52
@ -30,6 +30,8 @@ import javax.inject.Inject
|
|||||||
class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
||||||
|
|
||||||
fun books() = box.asFlowable()
|
fun books() = box.asFlowable()
|
||||||
|
.doOnNext(::removeBooksThatDoNotExist)
|
||||||
|
.map { books -> books.filter { it.file.exists() } }
|
||||||
.map { it.map(::BookOnDisk) }
|
.map { it.map(::BookOnDisk) }
|
||||||
|
|
||||||
fun getBooks() = box.all.map(::BookOnDisk)
|
fun getBooks() = box.all.map(::BookOnDisk)
|
||||||
@ -52,4 +54,12 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
|||||||
fun migrationInsert(books: ArrayList<Book>) {
|
fun migrationInsert(books: ArrayList<Book>) {
|
||||||
insert(books.map { BookOnDisk(book = it, file = it.file) })
|
insert(books.map { BookOnDisk(book = it, file = it.file) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun removeBooksThatDoNotExist(books: MutableList<BookOnDiskEntity>) {
|
||||||
|
delete(books.filterNot { it.file.exists() })
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun delete(books: List<BookOnDiskEntity>) {
|
||||||
|
box.remove(books)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user