Skip to content

Commit

Permalink
Merge pull request #3652 from kiwix/Fix#3650
Browse files Browse the repository at this point in the history
Fixed: When we select any ZIM file using the file picker, it is not being added to the library screen.
  • Loading branch information
kelson42 authored Jan 5, 2024
2 parents 37b20df + 17068b5 commit bd27edc
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ import org.kiwix.kiwixmobile.core.extensions.setBottomMarginToFragmentContainerV
import org.kiwix.kiwixmobile.core.extensions.toast
import org.kiwix.kiwixmobile.core.main.CoreMainActivity
import org.kiwix.kiwixmobile.core.main.KIWIX_APK_WEBSITE_URL
import org.kiwix.kiwixmobile.core.main.MainRepositoryActions
import org.kiwix.kiwixmobile.core.navigateToAppSettings
import org.kiwix.kiwixmobile.core.navigateToSettings
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
import org.kiwix.kiwixmobile.core.utils.LanguageUtils
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import org.kiwix.kiwixmobile.core.utils.SimpleRecyclerViewScrollListener
Expand All @@ -82,6 +84,7 @@ import org.kiwix.kiwixmobile.core.utils.files.FileUtils
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BookOnDiskDelegate
import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskAdapter
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.ZimManageViewModel
import org.kiwix.kiwixmobile.zimManager.ZimManageViewModel.FileSelectActions
Expand All @@ -101,6 +104,8 @@ class LocalLibraryFragment : BaseFragment() {
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject lateinit var sharedPreferenceUtil: SharedPreferenceUtil
@Inject lateinit var dialogShower: DialogShower
@Inject lateinit var mainRepositoryActions: MainRepositoryActions
@Inject lateinit var zimReaderFactory: ZimFileReader.Factory

private var actionMode: ActionMode? = null
private val disposable = CompositeDisposable()
Expand Down Expand Up @@ -364,6 +369,19 @@ class LocalLibraryFragment : BaseFragment() {
if (!file.canRead()) {
activity.toast(R.string.unable_to_read_zim_file)
} else {
// Save the ZIM file to the database to display it on the local library screen.
// This is particularly useful when storage is slow or contains a large number of files.
// In such cases, scanning may take some time to show all the files on the
// local library screen. Since our application is already aware of this opened ZIM file,
// we can directly add it to the database.
// See https://github.com/kiwix/kiwix-android/issues/3650
zimReaderFactory.create(file)
?.let { zimFileReader ->
BookOnDisk(file, zimFileReader).also {
mainRepositoryActions.saveBook(it)
zimFileReader.dispose()
}
}
activity?.navigate(
LocalLibraryFragmentDirections.actionNavigationLibraryToNavigationReader()
.apply { zimFileUri = file.toUri().toString() }
Expand Down Expand Up @@ -403,6 +421,7 @@ class LocalLibraryFragment : BaseFragment() {

override fun onDestroyView() {
super.onDestroyView()
mainRepositoryActions.dispose()
actionMode = null
fragmentDestinationLibraryBinding?.zimfilelist?.adapter = null
fragmentDestinationLibraryBinding = null
Expand Down

0 comments on commit bd27edc

Please sign in to comment.