mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
Fixed: Books are not displayed on the LocalLibrary screen if a book is deleted from storage after being added to the DAO.
* Improved the test cases as well.
This commit is contained in:
parent
f78e1447a6
commit
3e47cfa6ae
@ -60,7 +60,7 @@ class LibkiwixBookmarks @Inject constructor(
|
||||
manager: Manager,
|
||||
val sharedPreferenceUtil: SharedPreferenceUtil,
|
||||
private val bookDao: NewBookDao,
|
||||
private val zimReaderContainer: ZimReaderContainer?,
|
||||
private val zimReaderContainer: ZimReaderContainer?
|
||||
) : PageDao {
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,6 @@ import io.objectbox.kotlin.inValues
|
||||
import io.objectbox.kotlin.query
|
||||
import io.objectbox.query.QueryBuilder
|
||||
import io.reactivex.rxjava3.core.Completable
|
||||
import io.reactivex.rxjava3.core.Flowable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -64,12 +63,12 @@ class NewBookDao @Inject constructor(private val box: Box<BookOnDiskEntity>) {
|
||||
.flatMapSingle { bookOnDiskEntity ->
|
||||
// Check if the zimReaderSource exists as a suspend function
|
||||
rxSingle { bookOnDiskEntity.zimReaderSource.exists() }
|
||||
.flatMap { exists ->
|
||||
if (exists) io.reactivex.rxjava3.core.Single.just(bookOnDiskEntity)
|
||||
else io.reactivex.rxjava3.core.Single.never()
|
||||
.map { exists ->
|
||||
bookOnDiskEntity to exists
|
||||
}
|
||||
.onErrorResumeNext { _: Throwable -> io.reactivex.rxjava3.core.Single.never() }
|
||||
}
|
||||
.filter(Pair<BookOnDiskEntity, Boolean>::second)
|
||||
.map(Pair<BookOnDiskEntity, Boolean>::first)
|
||||
.toList()
|
||||
.toFlowable()
|
||||
}
|
||||
|
@ -27,9 +27,11 @@ import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.processors.PublishProcessor
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.kiwix.kiwixmobile.core.DarkModeConfig
|
||||
import org.kiwix.kiwixmobile.core.DarkModeConfig.Mode.Companion.from
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.extensions.isFileExist
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
@ -114,9 +116,10 @@ class SharedPreferenceUtil @Inject constructor(val context: Context) {
|
||||
putStoragePosition(0)
|
||||
}
|
||||
|
||||
!File(storage).exists() -> getPublicDirectoryPath(defaultPublicStorage()).also {
|
||||
putStoragePosition(0)
|
||||
}
|
||||
runBlocking { !File(storage).isFileExist() } ->
|
||||
getPublicDirectoryPath(defaultPublicStorage()).also {
|
||||
putStoragePosition(0)
|
||||
}
|
||||
|
||||
else -> storage
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ import io.objectbox.query.Query
|
||||
import io.objectbox.query.QueryBuilder
|
||||
import io.objectbox.rx.RxQuery
|
||||
import io.reactivex.Observable
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
@ -62,20 +64,20 @@ internal class NewBookDaoTest {
|
||||
inner class BooksTests {
|
||||
@Test
|
||||
fun `books emits entities whose file exists`() {
|
||||
val (expectedEntity, _) = expectEmissionOfExistingAndNotExistingBook()
|
||||
val books = newBookDao.books().test().also {
|
||||
it.awaitTerminalEvent()
|
||||
runBlocking {
|
||||
val (expectedEntity, _) = expectEmissionOfExistingAndNotExistingBook()
|
||||
val books = newBookDao.books().test()
|
||||
delay(1000)
|
||||
books.assertValues(listOf(BookOnDisk(expectedEntity)))
|
||||
}
|
||||
books.assertValues(listOf(BookOnDisk(expectedEntity)))
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Test
|
||||
fun `books deletes entities whose file does not exist`() {
|
||||
fun `books deletes entities whose file does not exist`() = runBlocking {
|
||||
val (_, deletedEntity) = expectEmissionOfExistingAndNotExistingBook()
|
||||
newBookDao.books().test().also {
|
||||
it.awaitTerminalEvent()
|
||||
}
|
||||
newBookDao.books().test()
|
||||
delay(1000)
|
||||
verify { box.remove(listOf(deletedEntity)) }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user