From 6162e6e919c9c9dac247fc8172b070c6d303e768 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 7 Jun 2024 10:46:54 -0400 Subject: [PATCH 1/2] Safely access editPostRepository.id --- .../java/org/wordpress/android/ui/posts/EditPostActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt index 6933c9c0bf12..2090abec6cd0 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt @@ -3813,7 +3813,9 @@ class EditPostActivity : LocaleAwareActivity(), EditorFragmentActivity, EditorIm @Subscribe(threadMode = ThreadMode.MAIN) fun onPostUploaded(event: OnPostUploaded) { val post: PostModel? = event.post - if (post != null && post.id == editPostRepository.id) { + val editPostId = editPostRepository.getPost()?.id + + if (post != null && post.id == editPostId) { if (!isRemotePreviewingFromEditor) { // We are not remote previewing a post: show snackbar and update post status if needed val snackbarAttachView = findViewById(R.id.editor_activity) From 08efcdcc847da37754daf6551dafef301045b7d9 Mon Sep 17 00:00:00 2001 From: Annmarie Ziegler Date: Fri, 7 Jun 2024 11:28:16 -0400 Subject: [PATCH 2/2] Add check for EditPostRepository property has been initialized --- .../java/org/wordpress/android/ui/posts/EditPostActivity.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt index 2090abec6cd0..3e7fe716c570 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.kt @@ -3813,7 +3813,10 @@ class EditPostActivity : LocaleAwareActivity(), EditorFragmentActivity, EditorIm @Subscribe(threadMode = ThreadMode.MAIN) fun onPostUploaded(event: OnPostUploaded) { val post: PostModel? = event.post - val editPostId = editPostRepository.getPost()?.id + + // Check if editPostRepository is initialized + val editPostRepositoryInitialized = this::editPostRepository.isInitialized + val editPostId = if (editPostRepositoryInitialized) editPostRepository.getPost()?.id else null if (post != null && post.id == editPostId) { if (!isRemotePreviewingFromEditor) {