From 38f86606b514d6b5ee26edba19d95b15218e8f4f Mon Sep 17 00:00:00 2001 From: kanat Date: Thu, 29 Aug 2024 13:22:11 -0400 Subject: [PATCH 1/2] [5148] Crash on MediaGalleryPreviewActivity --- .../preview/MediaGalleryPreviewActivity.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt index 2620d6fd8a2..19f302ef9dc 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt @@ -204,6 +204,11 @@ public class MediaGalleryPreviewActivity : AppCompatActivity() { */ private var fileSharingJob: Job? = null + /** + * The current state of the screen. + */ + private var uiState: MediaGalleryPreviewActivityState? = null + /** * The ViewModel that exposes screen data. */ @@ -216,16 +221,18 @@ public class MediaGalleryPreviewActivity : AppCompatActivity() { */ override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val mediaGalleryPreviewActivityState = intent?.getParcelableExtra( - KeyMediaGalleryPreviewActivityState, - ) + + uiState = savedInstanceState?.getParcelable( + KeyMediaGalleryPreviewActivityState + ) ?: intent?.getParcelableExtra(KeyMediaGalleryPreviewActivityState) + val videoThumbnailsEnabled = intent?.getBooleanExtra(KeyVideoThumbnailsEnabled, true) ?: true val streamCdnImageResizing = intent?.createStreamCdnImageResizing() ?: StreamCdnImageResizing.defaultStreamCdnImageResizing() - val messageId = mediaGalleryPreviewActivityState?.messageId ?: "" + val messageId = uiState?.messageId ?: "" if (!mediaGalleryPreviewViewModel.hasCompleteMessage) { - val message = mediaGalleryPreviewActivityState?.toMessage() + val message = uiState?.toMessage() if (message != null) { mediaGalleryPreviewViewModel.message = message @@ -257,6 +264,13 @@ public class MediaGalleryPreviewActivity : AppCompatActivity() { } } + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + uiState?.also { + outState.putParcelable(KeyMediaGalleryPreviewActivityState, it) + } + } + /** * Responsible for updating the system UI. */ From 8b32f8014f0d9631640c8dde1993f62e9862ad1b Mon Sep 17 00:00:00 2001 From: kanat Date: Thu, 29 Aug 2024 13:27:53 -0400 Subject: [PATCH 2/2] fix spotless --- .../ui/attachments/preview/MediaGalleryPreviewActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt index 19f302ef9dc..3aeb385e764 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/attachments/preview/MediaGalleryPreviewActivity.kt @@ -223,7 +223,7 @@ public class MediaGalleryPreviewActivity : AppCompatActivity() { super.onCreate(savedInstanceState) uiState = savedInstanceState?.getParcelable( - KeyMediaGalleryPreviewActivityState + KeyMediaGalleryPreviewActivityState, ) ?: intent?.getParcelableExtra(KeyMediaGalleryPreviewActivityState) val videoThumbnailsEnabled = intent?.getBooleanExtra(KeyVideoThumbnailsEnabled, true) ?: true