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..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 @@ -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( + + 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. */