From 677a481ef553134d55077f8d040ea6495bfa8627 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 21 Mar 2024 18:19:55 +0530 Subject: [PATCH] Fixed: Opening ZIM file from history that does not exist in fileSystem leads to execpected UI behavior (When already a ZIM file opened in the reader). * The issue occurs because we are not opening the zim file in the reader because it does not exist in the fileSystem but we are loading the saved URL in webView of that file which does not exist. So when we are switching between fragments then we are opening the previously saved zim file but with the wrong URL which leads to this unexpected behavior. So to fix this we are closing the previously opened book if the new zim file does not exist in the fileSystem. --- .../nav/destination/reader/KiwixReaderFragment.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt index 83e0c8d53..ec1d9f3a4 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt +++ b/app/src/main/java/org/kiwix/kiwixmobile/nav/destination/reader/KiwixReaderFragment.kt @@ -113,6 +113,12 @@ class KiwixReaderFragment : CoreReaderFragment() { ) if (filePath == null || !File(filePath).isFileExist()) { + // Close the previously opened book in the reader. Since this file is not found, + // it will not be set in the zimFileReader. The previously opened ZIM file + // will be saved when we move between fragments. If we return to the reader again, + // it will attempt to open the last opened ZIM file with the last loaded URL, + // which is inside the non-existing ZIM file. This leads to unexpected behavior. + exitBook() activity.toast(R.string.error_file_not_found) return }