From b6d718f287df5424f06f396b6ec18c3ae3c20249 Mon Sep 17 00:00:00 2001 From: MohitMali Date: Wed, 1 Nov 2023 15:36:14 +0530 Subject: [PATCH] Fixed note saving with `FileDescriptor`. * Now we are using fileDescriptor for custom apps to read zim file from asset folder, so we have improved our notes saving functionality according to this change. --- .../org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt | 2 +- .../page/notes/viewmodel/effects/ShowOpenNoteDialog.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt index e280061a1..dc52f0ff4 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/AddNoteDialog.kt @@ -117,7 +117,7 @@ class AddNoteDialog : DialogFragment() { .inject(this) // Returns name of the form ".../Kiwix/granbluefantasy_en_all_all_nopic_2018-10.zim" - zimFileName = zimReaderContainer.zimCanonicalPath + zimFileName = zimReaderContainer.zimCanonicalPath ?: zimReaderContainer.name if (zimFileName != null) { // No zim file currently opened zimFileTitle = zimReaderContainer.zimFileTitle zimId = zimReaderContainer.id.orEmpty() diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/viewmodel/effects/ShowOpenNoteDialog.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/viewmodel/effects/ShowOpenNoteDialog.kt index 77873906d..8adaa9b4a 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/viewmodel/effects/ShowOpenNoteDialog.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/page/notes/viewmodel/effects/ShowOpenNoteDialog.kt @@ -45,8 +45,13 @@ data class ShowOpenNoteDialog( { effects.offer(OpenPage(page, zimReaderContainer)) }, { val item = page as NoteListItem - val file = File(item.zimFilePath.orEmpty()) - zimReaderContainer.setZimFile(file) + // Check if zimFilePath is not null, and then set it in zimReaderContainer. + // For custom apps, we are currently using fileDescriptor, and they only have a single file in them, + // which is already set in zimReaderContainer, so there's no need to set it again. + item.zimFilePath?.let { + val file = File(it) + zimReaderContainer.setZimFile(file) + } effects.offer(OpenNote(item.noteFilePath, item.zimUrl, item.title)) } )