From 6b49840d7c5593fefc4cd7324df6dc180cb9fbee Mon Sep 17 00:00:00 2001 From: Mark Raynsford Date: Mon, 20 Jan 2025 11:47:27 +0000 Subject: [PATCH] Work around a low-frequency crash relating to fragment parameters (2). --- .../viewer/preview/BookPreviewActivity.kt | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/simplified-viewer-preview/src/main/java/org/librarysimplified/viewer/preview/BookPreviewActivity.kt b/simplified-viewer-preview/src/main/java/org/librarysimplified/viewer/preview/BookPreviewActivity.kt index 5e57c8b39..311ddf85a 100644 --- a/simplified-viewer-preview/src/main/java/org/librarysimplified/viewer/preview/BookPreviewActivity.kt +++ b/simplified-viewer-preview/src/main/java/org/librarysimplified/viewer/preview/BookPreviewActivity.kt @@ -115,9 +115,28 @@ class BookPreviewActivity : AppCompatActivity(R.layout.activity_book_preview) { this.loadingProgress.max = 100 - this.feedEntry = - this.intent.getSerializableExtra(EXTRA_ENTRY) as FeedEntry.FeedEntryOPDS + val intent = this.intent + if (intent == null) { + this.logger.warn("BookPreviewActivity lacks an intent!") + this.finish() + return + } + + val extras = intent.extras + if (extras == null) { + this.logger.warn("BookPreviewActivity intent lacks extras!") + this.finish() + return + } + + val entry = extras.getSerializable(EXTRA_ENTRY) as FeedEntry.FeedEntryOPDS? + if (entry == null) { + this.logger.warn("BookPreviewActivity intent lacks OPDS entry!") + this.finish() + return + } + this.feedEntry = entry MDC.put(MDCKeys.BOOK_TITLE, this.feedEntry.feedEntry.title) MDC.put(MDCKeys.BOOK_ID, this.feedEntry.feedEntry.id) MDCKeys.put(MDCKeys.BOOK_PUBLISHER, this.feedEntry.feedEntry.publisher)