mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 23:40:26 -04:00
Use an extension function to delete zims
This commit is contained in:
parent
7ef0054dd1
commit
537b2be914
@ -44,16 +44,22 @@ data class DeleteFiles(private val booksOnDiskListItems: List<BookOnDisk>) :
|
|||||||
val name = booksOnDiskListItems.joinToString(separator = "\n") { it.book.title }
|
val name = booksOnDiskListItems.joinToString(separator = "\n") { it.book.title }
|
||||||
|
|
||||||
dialogShower.show(DeleteZims(name), {
|
dialogShower.show(DeleteZims(name), {
|
||||||
val booksDeleted = booksOnDiskListItems.fold(true) { acc, book ->
|
activity.toast(
|
||||||
acc && deleteSpecificZimFile(book).also {
|
if (booksOnDiskListItems.deleteAll())
|
||||||
if (it && book.file.canonicalPath == zimReaderContainer.zimCanonicalPath) {
|
R.string.delete_zims_toast else
|
||||||
zimReaderContainer.setZimFile(null)
|
R.string.delete_zim_failed
|
||||||
}
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun List<BookOnDisk>.deleteAll(): Boolean {
|
||||||
|
return this.fold(true) { acc, book ->
|
||||||
|
acc && deleteSpecificZimFile(book).also {
|
||||||
|
if (it && book.file.canonicalPath == zimReaderContainer.zimCanonicalPath) {
|
||||||
|
zimReaderContainer.setZimFile(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
activity.toast(if (booksDeleted) R.string.delete_zims_toast else R.string.delete_zim_failed)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteSpecificZimFile(book: BookOnDisk): Boolean {
|
private fun deleteSpecificZimFile(book: BookOnDisk): Boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user