From ab1f9bad6bc6f77796a55532bc1b8a39ecd2be77 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Jan 2024 15:54:03 +0530 Subject: [PATCH 1/6] Improved the scanning of ZIM files. * Excluding the "data," "obb," and "Trash" folders from scanning is justified for several reasons. The "Trash" folder contains deleted files, making it unnecessary for scanning. Additionally, the "data" and "obb" folders are specifically designed for the app's private directory, and users usually do not store ZIM files there. Most file managers prohibit direct copying of files into these directories. Therefore, scanning these folders is not essential. Moreover, such scans consume time, given the presence of numerous files written by other apps, which are irrelevant to our application. --- .../core/utils/files/FileSearch.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt index e939585673..1ca8ab84f3 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt @@ -71,8 +71,25 @@ class FileSearch @Inject constructor(private val context: Context) { private fun directoryRoots() = StorageDeviceUtils.getReadableStorage(context).map(StorageDevice::name) - private fun scanDirectory(directory: String): List = - File(directory).walk().filter { it.extension.isAny(*zimFileExtensions) }.toList() + private fun scanDirectory(directory: String): List { + return File(directory).walk() + .onEnter { dir -> + // Excluding the "data," "obb," and "Trash" folders from scanning is justified for + // several reasons. The "Trash" folder contains deleted files, + // making it unnecessary for scanning. Additionally, + // the "data" and "obb" folders are specifically designed for the + // app's private directory, and users usually do not store ZIM files there. + // Most file managers prohibit direct copying of files into these directories. + // Therefore, scanning these folders is not essential. Moreover, + // such scans consume time, given the presence of numerous files written by other apps, + // which are irrelevant to our application. + !dir.name.equals(".Trash", ignoreCase = true) && + !dir.name.equals("data", ignoreCase = true) && + !dir.name.equals("obb", ignoreCase = true) + }.filter { + it.extension.isAny(*zimFileExtensions) + }.toList() + } } internal fun String.isAny(vararg suffixes: String) = From 153765491a7bcd8091c9b76d409af76c3987a53a Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Jan 2024 17:05:49 +0530 Subject: [PATCH 2/6] Removed the default scanning behavior upon launching the `LocalLibraryFragment`. * Now, scanning the storage only occurs when the user explicitly requests it. When the user attempts to refresh the list, the storage is scanned to identify ZIM files. This approach prevents unnecessary scanning when users frequently navigate to other screens. --- .../library/LocalLibraryFragment.kt | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index 25a1adcf27..d35b92ffdf 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -512,24 +512,16 @@ class LocalLibraryFragment : BaseFragment() { } private fun checkManageExternalStoragePermission() { - if (sharedPreferenceUtil.isPlayStoreBuild) { - requestFileSystemCheck() - } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - if (Environment.isExternalStorageManager()) { - // We already have permission!! - requestFileSystemCheck() - } else { - if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) { - // We should only ask for first time, If the users wants to revoke settings - // then they can directly toggle this feature from settings screen - sharedPreferenceUtil.manageExternalFilesPermissionDialog = false - // Show Dialog and Go to settings to give permission - showManageExternalStoragePermissionDialog() - } + if (!sharedPreferenceUtil.isPlayStoreBuild && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + if (!Environment.isExternalStorageManager()) { + // We do not have the permission!! + if (sharedPreferenceUtil.manageExternalFilesPermissionDialog) { + // We should only ask for first time, If the users wants to revoke settings + // then they can directly toggle this feature from settings screen + sharedPreferenceUtil.manageExternalFilesPermissionDialog = false + // Show Dialog and Go to settings to give permission + showManageExternalStoragePermissionDialog() } - } else { - requestFileSystemCheck() } } } From 13b0ab0519105b892643761d0add387ffb761c40 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Jan 2024 19:36:10 +0530 Subject: [PATCH 3/6] Displaying the scanning progress to the user: * We have enhanced our scanning process to provide real-time progress updates, allowing users to track how much time is required to complete the operation. --- .../library/LocalLibraryFragment.kt | 24 +++++++++++-- .../zimManager/ZimManageViewModel.kt | 35 +++++++++++++++---- .../layout/fragment_destination_library.xml | 12 +++++++ .../kiwix/kiwixmobile/core/StorageObserver.kt | 11 ++++-- .../core/utils/files/FileSearch.kt | 28 ++++++++++----- .../utils/files/ScanningProgressListener.kt | 23 ++++++++++++ 6 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/ScanningProgressListener.kt diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt index d35b92ffdf..40ad47f2fb 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/library/LocalLibraryFragment.kt @@ -86,6 +86,7 @@ import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDis import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk import org.kiwix.kiwixmobile.databinding.FragmentDestinationLibraryBinding +import org.kiwix.kiwixmobile.zimManager.MAX_PROGRESS import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel.FileSelectActions import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel.FileSelectActions.RequestDeleteMultiSelection @@ -235,8 +236,14 @@ class LocalLibraryFragment : BaseFragment() { } disposable.add(sideEffects()) disposable.add(fileSelectActions()) - zimManageViewModel.deviceListIsRefreshing.observe(viewLifecycleOwner) { - fragmentDestinationLibraryBinding?.zimSwiperefresh?.isRefreshing = it!! + zimManageViewModel.deviceListScanningProgress.observe(viewLifecycleOwner) { + fragmentDestinationLibraryBinding?.scanningProgressView?.apply { + progress = it + // hide this progress bar when scanning is complete. + visibility = if (it == MAX_PROGRESS) GONE else VISIBLE + // enable if the previous scanning is completes. + fragmentDestinationLibraryBinding?.zimSwiperefresh?.isEnabled = it == MAX_PROGRESS + } } if (savedInstanceState != null && savedInstanceState.getBoolean(WAS_IN_ACTION_MODE)) { zimManageViewModel.fileSelectActions.offer(FileSelectActions.RestartActionMode) @@ -258,6 +265,7 @@ class LocalLibraryFragment : BaseFragment() { SCROLL_DOWN -> { setBottomMarginToSwipeRefreshLayout(0) } + SCROLL_UP -> { getBottomNavigationView()?.let { setBottomMarginToSwipeRefreshLayout(it.measuredHeight) @@ -280,6 +288,18 @@ class LocalLibraryFragment : BaseFragment() { // the loading icon remains visible infinitely. fragmentDestinationLibraryBinding?.zimSwiperefresh?.isRefreshing = false } else { + fragmentDestinationLibraryBinding?.zimSwiperefresh?.apply { + // hide the swipe refreshing because now we are showing the ContentLoadingProgressBar + // to show the progress of how many files are scanned. + isRefreshing = false + // disable the swipe refresh layout until the ongoing scanning will not complete + // to avoid multiple scanning. + isEnabled = false + } + fragmentDestinationLibraryBinding?.scanningProgressView?.apply { + visibility = VISIBLE + progress = 0 + } requestFileSystemCheck() } } diff --git a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt index d449f2f255..275a2311a2 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModel.kt @@ -47,6 +47,7 @@ import org.kiwix.kiwixmobile.core.extensions.calculateSearchMatches import org.kiwix.kiwixmobile.core.extensions.registerReceiver import org.kiwix.kiwixmobile.core.utils.BookUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener import org.kiwix.kiwixmobile.core.zim_manager.Language import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.MULTI import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.NORMAL @@ -78,6 +79,8 @@ import java.util.Locale import java.util.concurrent.TimeUnit.MILLISECONDS import javax.inject.Inject +const val DEFAULT_PROGRESS = 0 +const val MAX_PROGRESS = 100 class ZimManageViewModel @Inject constructor( private val downloadDao: FetchDownloadDao, private val bookDao: NewBookDao, @@ -107,7 +110,7 @@ class ZimManageViewModel @Inject constructor( val sideEffects = PublishProcessor.create>() val libraryItems: MutableLiveData> = MutableLiveData() val fileSelectListStates: MutableLiveData = MutableLiveData() - val deviceListIsRefreshing = MutableLiveData() + val deviceListScanningProgress = MutableLiveData() val libraryListIsRefreshing = MutableLiveData() val shouldShowWifiOnlyDialog = MutableLiveData() val networkStates = MutableLiveData() @@ -430,15 +433,32 @@ class ZimManageViewModel @Inject constructor( .subscribeOn(Schedulers.io()) .observeOn(Schedulers.io()) .onBackpressureDrop() - .doOnNext { deviceListIsRefreshing.postValue(true) } + .doOnNext { deviceListScanningProgress.postValue(DEFAULT_PROGRESS) } .switchMap( { - booksFromStorageNotIn(booksFromDao) + booksFromStorageNotIn( + booksFromDao, + object : ScanningProgressListener { + override fun onProgressUpdate(scannedDirectory: Int, totalDirectory: Int) { + // Calculate the overall progress based on the number of processed directories + val overallProgress = + (scannedDirectory.toDouble() / totalDirectory.toDouble() * MAX_PROGRESS).toInt() + if (overallProgress != MAX_PROGRESS) { + // Send the progress if it is not 100% because after scanning the entire storage, + // it takes a bit of time to organize the ZIM files, filter them, + // and remove any duplicate ZIM files. We send the 100% progress + // in the doOnNext method to hide the progressBar from the UI + // and display all the filtered ZIM files. + deviceListScanningProgress.postValue(overallProgress) + } + } + } + ) }, 1 ) .onBackpressureDrop() - .doOnNext { deviceListIsRefreshing.postValue(false) } + .doOnNext { deviceListScanningProgress.postValue(MAX_PROGRESS) } .filter(List::isNotEmpty) .map { it.distinctBy { bookOnDisk -> bookOnDisk.book.id } } .subscribe( @@ -450,8 +470,11 @@ class ZimManageViewModel @Inject constructor( .subscribeOn(Schedulers.io()) .map { it.sortedBy { book -> book.book.title } } - private fun booksFromStorageNotIn(booksFromDao: Flowable>) = - storageObserver.booksOnFileSystem + private fun booksFromStorageNotIn( + booksFromDao: Flowable>, + scanningProgressListener: ScanningProgressListener + ) = + storageObserver.getBooksOnFileSystem(scanningProgressListener) .withLatestFrom( booksFromDao.map { it.map { bookOnDisk -> bookOnDisk.book.id } }, BiFunction(::removeBooksAlreadyInDao) diff --git a/app/src/main/res/layout/fragment_destination_library.xml b/app/src/main/res/layout/fragment_destination_library.xml index bf99307b3d..9b11a28c76 100644 --- a/app/src/main/res/layout/fragment_destination_library.xml +++ b/app/src/main/res/layout/fragment_destination_library.xml @@ -37,6 +37,18 @@ android:layout_height="wrap_content"> + + diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt index a92a178aa3..56a0cec09a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/StorageObserver.kt @@ -25,6 +25,7 @@ import org.kiwix.kiwixmobile.core.dao.FetchDownloadDao import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.utils.files.FileSearch +import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk import java.io.File import javax.inject.Inject @@ -35,12 +36,16 @@ class StorageObserver @Inject constructor( private val zimReaderFactory: ZimFileReader.Factory ) { - val booksOnFileSystem: Flowable> - get() = scanFiles() + fun getBooksOnFileSystem( + scanningProgressListener: ScanningProgressListener + ): Flowable> { + return scanFiles(scanningProgressListener) .withLatestFrom(downloadDao.downloads(), BiFunction(::toFilesThatAreNotDownloading)) .map { it.mapNotNull(::convertToBookOnDisk) } + } - private fun scanFiles() = fileSearch.scan().subscribeOn(Schedulers.io()) + private fun scanFiles(scanningProgressListener: ScanningProgressListener) = + fileSearch.scan(scanningProgressListener).subscribeOn(Schedulers.io()) private fun toFilesThatAreNotDownloading(files: List, downloads: List) = files.filter { fileHasNoMatchingDownload(downloads, it) } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt index 1ca8ab84f3..3c18836849 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/FileSearch.kt @@ -35,9 +35,10 @@ class FileSearch @Inject constructor(private val context: Context) { private val zimFileExtensions = arrayOf("zim", "zimaa") - fun scan(): Flowable> = + fun scan(scanningProgressListener: ScanningProgressListener): Flowable> = Flowable.combineLatest( - Flowable.fromCallable(::scanFileSystem).subscribeOn(Schedulers.io()), + Flowable.fromCallable { scanFileSystem(scanningProgressListener) } + .subscribeOn(Schedulers.io()), Flowable.fromCallable(::scanMediaStore).subscribeOn(Schedulers.io()), BiFunction, List, List> { filesSystemFiles, mediaStoreFiles -> filesSystemFiles + mediaStoreFiles @@ -61,12 +62,23 @@ class FileSearch @Inject constructor(private val context: Context) { null ) - private fun scanFileSystem() = - directoryRoots() - .fold(mutableListOf(), { acc, root -> - acc.apply { addAll(scanDirectory(root)) } - }) - .distinctBy { it.canonicalPath } + private fun scanFileSystem(scanningProgressListener: ScanningProgressListener): List { + val directoryRoots = directoryRoots() + val totalDirectories = directoryRoots.size + var processedDirectories = 0 + + return directoryRoots.fold(mutableListOf()) { acc, root -> + acc.apply { + addAll( + scanDirectory(root).also { + // Increment the count of processed directories and notify the progress + processedDirectories++ + scanningProgressListener.onProgressUpdate(processedDirectories, totalDirectories) + } + ) + } + }.distinctBy { it.canonicalPath } + } private fun directoryRoots() = StorageDeviceUtils.getReadableStorage(context).map(StorageDevice::name) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/ScanningProgressListener.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/ScanningProgressListener.kt new file mode 100644 index 0000000000..242940f763 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/files/ScanningProgressListener.kt @@ -0,0 +1,23 @@ +/* + * Kiwix Android + * Copyright (c) 2024 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package org.kiwix.kiwixmobile.core.utils.files + +interface ScanningProgressListener { + fun onProgressUpdate(scannedDirectory: Int, totalDirectory: Int) +} From 57800a8da71b25f3c17cd6ca828d723c30dfaabe Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Jan 2024 20:47:13 +0530 Subject: [PATCH 4/6] Fixed `FileSearchTest`, `StorageObserverTest`, and `ZimManageViewModelTest` test that are failing after this change. --- .../kiwixmobile/zimManager/ZimManageViewModelTest.kt | 7 ++++++- .../org/kiwix/kiwixmobile/core/StorageObserverTest.kt | 6 ++++-- .../kiwixmobile/core/utils/files/FileSearchTest.kt | 11 ++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt index 68f3f3a6f8..4810efdc5f 100644 --- a/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt +++ b/app/src/test/java/org/kiwix/kiwixmobile/zimManager/ZimManageViewModelTest.kt @@ -47,6 +47,7 @@ import org.kiwix.kiwixmobile.core.downloader.model.DownloadModel import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity.Book import org.kiwix.kiwixmobile.core.utils.BookUtils import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener import org.kiwix.kiwixmobile.core.zim_manager.Language import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.MULTI import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.SelectionMode.NORMAL @@ -128,7 +129,11 @@ class ZimManageViewModelTest { every { connectivityBroadcastReceiver.action } returns "test" every { downloadDao.downloads() } returns downloads every { newBookDao.books() } returns books - every { storageObserver.booksOnFileSystem } returns booksOnFileSystem + every { + storageObserver.getBooksOnFileSystem( + any() + ) + } returns booksOnFileSystem every { newLanguagesDao.languages() } returns languages every { fat32Checker.fileSystemStates } returns fileSystemStates every { connectivityBroadcastReceiver.networkStates } returns networkStates diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt index bc85ba3fb6..8ba316a9d8 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/StorageObserverTest.kt @@ -33,6 +33,7 @@ import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.reader.ZimFileReader.Factory import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil import org.kiwix.kiwixmobile.core.utils.files.FileSearch +import org.kiwix.kiwixmobile.core.utils.files.ScanningProgressListener import org.kiwix.sharedFunctions.book import org.kiwix.sharedFunctions.bookOnDisk import org.kiwix.sharedFunctions.resetSchedulers @@ -48,6 +49,7 @@ class StorageObserverTest { private val file: File = mockk() private val readerFactory: Factory = mockk() private val zimFileReader: ZimFileReader = mockk() + private val scanningProgressListener: ScanningProgressListener = mockk() private val files: PublishProcessor> = PublishProcessor.create() private val downloads: PublishProcessor> = PublishProcessor.create() @@ -66,7 +68,7 @@ class StorageObserverTest { @BeforeEach fun init() { clearAllMocks() every { sharedPreferenceUtil.prefStorage } returns "a" - every { fileSearch.scan() } returns files + every { fileSearch.scan(scanningProgressListener) } returns files every { downloadDao.downloads() } returns downloads every { readerFactory.create(file) } returns zimFileReader storageObserver = StorageObserver(downloadDao, fileSearch, readerFactory) @@ -92,7 +94,7 @@ class StorageObserverTest { verify { zimFileReader.dispose() } } - private fun booksOnFileSystem() = storageObserver.booksOnFileSystem + private fun booksOnFileSystem() = storageObserver.getBooksOnFileSystem(scanningProgressListener) .test() .also { downloads.offer(listOf(downloadModel)) diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/utils/files/FileSearchTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/utils/files/FileSearchTest.kt index 78167b6f56..3b1daad41c 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/utils/files/FileSearchTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/utils/files/FileSearchTest.kt @@ -47,6 +47,7 @@ class FileSearchTest { private val externalStorageDirectory: File = mockk() private val contentResolver: ContentResolver = mockk() private val storageDevice: StorageDevice = mockk() + private val scanningProgressListener: ScanningProgressListener = mockk() init { setScheduler(Schedulers.trampoline()) @@ -80,7 +81,7 @@ class FileSearchTest { @Test fun `scan of directory that doesn't exist returns nothing`() { every { contentResolver.query(any(), any(), any(), any(), any()) } returns null - fileSearch.scan() + fileSearch.scan(scanningProgressListener) .test() .assertValue(listOf()) } @@ -92,7 +93,7 @@ class FileSearchTest { File.createTempFile("willNotFind", ".txt") every { contentResolver.query(any(), any(), any(), any(), any()) } returns null every { storageDevice.name } returns zimFile.parent - val fileList = fileSearch.scan() + val fileList = fileSearch.scan(scanningProgressListener) .test() .values()[0] assertThat(fileList).containsExactlyInAnyOrder(zimFile, zimaaFile) @@ -109,7 +110,7 @@ class FileSearchTest { ) every { contentResolver.query(any(), any(), any(), any(), any()) } returns null every { storageDevice.name } returns zimFile.parentFile.parent - val fileList = fileSearch.scan() + val fileList = fileSearch.scan(scanningProgressListener) .test() .values()[0] assertThat(fileList).containsExactlyInAnyOrder(zimFile) @@ -123,7 +124,7 @@ class FileSearchTest { fun `scan media store, if files are readable they are returned`() { val fileToFind = File.createTempFile("fileToFind", ".zim") expectFromMediaStore(fileToFind) - fileSearch.scan() + fileSearch.scan(scanningProgressListener) .test() .assertValue(listOf(fileToFind)) } @@ -133,7 +134,7 @@ class FileSearchTest { val unreadableFile = File.createTempFile("fileToFind", ".zim") expectFromMediaStore(unreadableFile) unreadableFile.delete() - fileSearch.scan() + fileSearch.scan(scanningProgressListener) .test() .assertValue(listOf()) } From b86e87ffd50dc7c06aa89d0d31a5b98917b7619d Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 26 Jan 2024 16:37:05 +0530 Subject: [PATCH 5/6] Increase height of progress bar to properly show to the user. --- .../layout/fragment_destination_library.xml | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/app/src/main/res/layout/fragment_destination_library.xml b/app/src/main/res/layout/fragment_destination_library.xml index 9b11a28c76..99ef8e20f5 100644 --- a/app/src/main/res/layout/fragment_destination_library.xml +++ b/app/src/main/res/layout/fragment_destination_library.xml @@ -38,17 +38,6 @@ - @@ -58,12 +47,32 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> - + android:layout_height="match_parent"> + + + + @@ -76,8 +85,8 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - tools:ignore="RequiredSize" - app:layout_constraintVertical_bias="0.45" /> + app:layout_constraintVertical_bias="0.45" + tools:ignore="RequiredSize" />