Skip to content

Commit

Permalink
Add updatePublishingState to handle changing button state in the home…
Browse files Browse the repository at this point in the history
… bottom sheet
  • Loading branch information
zwarm committed Feb 19, 2024
1 parent 7ac0197 commit 2de8b96
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.ui.posts.prepublishing.home

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineDispatcher
Expand All @@ -22,6 +23,7 @@ import org.wordpress.android.ui.posts.prepublishing.home.PrepublishingHomeItemUi
import org.wordpress.android.ui.posts.prepublishing.home.PrepublishingHomeItemUiState.SocialUiState
import org.wordpress.android.ui.posts.prepublishing.home.PrepublishingHomeItemUiState.StoryTitleUiState
import org.wordpress.android.ui.posts.prepublishing.home.usecases.GetButtonUiStateUseCase
import org.wordpress.android.ui.posts.prepublishing.publishing.PublishingEvent
import org.wordpress.android.ui.posts.trackPrepublishingNudges
import org.wordpress.android.ui.stories.StoryRepositoryWrapper
import org.wordpress.android.ui.stories.usecase.UpdateStoryPostTitleUseCase
Expand Down Expand Up @@ -253,4 +255,30 @@ class PrepublishingHomeViewModel @Inject constructor(

_socialUiState.postValue(newState)
}

fun updatePublishingState(publishingEvent: PublishingEvent) {
Log.i(javaClass.simpleName, "***=> updatePublishingState: $uiState")
val newButtonState = when (publishingEvent) {
is PublishingEvent.MediaUploadInProgress -> PrepublishingHomeItemUiState.ButtonUiState.InProgressButtonUiState(null)
is PublishingEvent.PostUploadError -> PrepublishingHomeItemUiState.ButtonUiState.ErrorButtonUiState(null)
is PublishingEvent.PostUploadInProgress -> PrepublishingHomeItemUiState.ButtonUiState.InProgressButtonUiState(null)
is PublishingEvent.PostUploadStarted -> PrepublishingHomeItemUiState.ButtonUiState.InProgressButtonUiState(null)
is PublishingEvent.PostUploadSuccess -> PrepublishingHomeItemUiState.ButtonUiState.DoneButtonUiState(null)
is PublishingEvent.ReadyToUpload -> PrepublishingHomeItemUiState.ButtonUiState.InProgressButtonUiState(null)
}

val updatedUiState = uiState.value?.map { item ->
if (item is PrepublishingHomeItemUiState.ButtonUiState) {
// update button state
newButtonState
} else {
item
}
}

// Post the updated state
updatedUiState?.let { updatedValue ->
_uiState.postValue(updatedValue)
}
}
}

0 comments on commit 2de8b96

Please sign in to comment.