Improved the scanning of ZIM files from storage.

* Improved the `TestObserver` to properly to receive the test values.
This commit is contained in:
MohitMaliFtechiz 2025-05-09 16:12:30 +05:30
parent bbae4dbd64
commit bfb209acd5
5 changed files with 18 additions and 23 deletions

View File

@ -303,9 +303,7 @@ class LocalLibraryFragment : BaseFragment(), CopyMoveFileHandler.FileCopyMoveCal
)
}
if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) {
lifecycleScope.launch {
zimManageViewModel.fileSelectActions.emit(FileSelectActions.RestartActionMode)
}
offerAction(FileSelectActions.RestartActionMode)
}
showCopyMoveDialogForOpenedZimFileFromStorage()
}

View File

@ -41,9 +41,10 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@ -667,11 +668,10 @@ class ZimManageViewModel @Inject constructor(
private fun booksFromStorageNotIn(
booksFromDao: Flow<List<BookOnDisk>>,
scanningProgressListener: ScanningProgressListener
): Flow<List<BookOnDisk>> {
return storageObserver.getBooksOnFileSystem(scanningProgressListener)
.combine(booksFromDao.map { it.map { bookOnDisk -> bookOnDisk.book.id } }) { files, daoBooks ->
removeBooksAlreadyInDao(files, daoBooks)
}
): Flow<List<BookOnDisk>> = flow {
val scannedBooks = storageObserver.getBooksOnFileSystem(scanningProgressListener).first()
val daoBookIds = booksFromDao.first().map { it.book.id }
emit(removeBooksAlreadyInDao(scannedBooks, daoBookIds))
}
private fun removeBooksAlreadyInDao(

View File

@ -45,7 +45,7 @@ class TestObserver<T>(
job = scope.launch {
flow.collect {
values.add(it)
completionChannel.trySend(Unit)
completionChannel.send(Unit)
}
}
}

View File

@ -21,9 +21,9 @@ package org.kiwix.kiwixmobile.core
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao
import org.kiwix.kiwixmobile.core.dao.LibkiwixBookmarks
import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel
@ -44,16 +44,13 @@ class StorageObserver @Inject constructor(
fun getBooksOnFileSystem(
scanningProgressListener: ScanningProgressListener,
dispatcher: CoroutineDispatcher = Dispatchers.IO
): Flow<List<BookOnDisk>> {
return scanFiles(scanningProgressListener)
.combine(downloadRoomDao.downloads()) { files, downloads ->
toFilesThatAreNotDownloading(files, downloads)
}
.map { files ->
files.mapNotNull { convertToBookOnDisk(it) }
}
.flowOn(dispatcher)
}
): Flow<List<BookOnDisk>> = flow {
val files = scanFiles(scanningProgressListener).first()
val downloads = downloadRoomDao.downloads().first()
val result = toFilesThatAreNotDownloading(files, downloads)
.mapNotNull { convertToBookOnDisk(it) }
emit(result)
}.flowOn(dispatcher)
private fun scanFiles(scanningProgressListener: ScanningProgressListener): Flow<List<File>> =
fileSearch.scan(scanningProgressListener)

View File

@ -229,7 +229,7 @@ class TestObserver<T>(
job = scope.launch {
flow.collect {
values.add(it)
completionChannel.trySend(Unit)
completionChannel.send(Unit)
}
}
}