From 0f4f17599a610616459185cc2fcdc9347796029d Mon Sep 17 00:00:00 2001 From: Pantelis Stampoulis Date: Fri, 12 Apr 2024 13:55:33 +0300 Subject: [PATCH] Fixes: PostListMainViewModel multiple starts --- .../org/wordpress/android/ui/posts/PostListMainViewModel.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt index 8bc47403ba46..53e62f326d74 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListMainViewModel.kt @@ -85,6 +85,8 @@ class PostListMainViewModel @Inject constructor( private val uploadStarter: UploadStarter, private val postConflictResolutionFeatureUtils: PostConflictResolutionFeatureUtils ) : ViewModel(), CoroutineScope { + private var isStarted = false + private val lifecycleOwner = object : LifecycleOwner { val lifecycleRegistry = LifecycleRegistry(this) override val lifecycle: Lifecycle = lifecycleRegistry @@ -241,6 +243,7 @@ class PostListMainViewModel @Inject constructor( currentBottomSheetPostId: LocalId, editPostRepository: EditPostRepository ) { + if (isStarted) return this.site = site this.editPostRepository = editPostRepository @@ -300,6 +303,8 @@ class PostListMainViewModel @Inject constructor( savePostToDbUseCase.savePostToDb(editPostRepository, site) }) } + + isStarted = true } override fun onCleared() {