Skip to content

Commit

Permalink
♻️ rename recipe description making event
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkim2689 committed Aug 7, 2024
1 parent 40f0edc commit d6559fa
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.pengcook.android.presentation.making

sealed interface RecipeMakingEvent {
data class NavigateToMakingStep(val recipeId: Long) : RecipeMakingEvent

data object AddImage : RecipeMakingEvent

data class PresignedUrlRequestSuccessful(val presignedUrl: String) : RecipeMakingEvent

data object PostImageSuccessful : RecipeMakingEvent

data object PostImageFailure : RecipeMakingEvent

data object DescriptionFormNotCompleted : RecipeMakingEvent

data object PostRecipeFailure : RecipeMakingEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ class RecipeMakingFragment : Fragment() {
viewModel.uiEvent.observe(viewLifecycleOwner) { event ->
val newEvent = event.getContentIfNotHandled() ?: return@observe
when (newEvent) {
is MakingEvent.NavigateToMakingStep -> navigateToStepMaking(newEvent.recipeId)
is MakingEvent.AddImage -> addImage()
is MakingEvent.PostImageFailure -> showSnackBar(getString(R.string.image_upload_failed))
is MakingEvent.PostImageSuccessful -> showSnackBar(getString(R.string.image_upload_success))
is MakingEvent.PresignedUrlRequestSuccessful -> uploadImageToS3(newEvent.presignedUrl)
is MakingEvent.DescriptionFormNotCompleted -> showSnackBar(getString(R.string.making_warning_form_not_completed))
is MakingEvent.PostRecipeFailure -> showSnackBar(getString(R.string.making_warning_post_failure))
is RecipeMakingEvent.NavigateToMakingStep -> navigateToStepMaking(newEvent.recipeId)
is RecipeMakingEvent.AddImage -> addImage()
is RecipeMakingEvent.PostImageFailure -> showSnackBar(getString(R.string.image_upload_failed))
is RecipeMakingEvent.PostImageSuccessful -> showSnackBar(getString(R.string.image_upload_success))
is RecipeMakingEvent.PresignedUrlRequestSuccessful -> uploadImageToS3(newEvent.presignedUrl)
is RecipeMakingEvent.DescriptionFormNotCompleted -> showSnackBar(getString(R.string.making_warning_form_not_completed))
is RecipeMakingEvent.PostRecipeFailure -> showSnackBar(getString(R.string.making_warning_post_failure))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import java.io.File

class RecipeMakingViewModel(private val makingRecipeRepository: MakingRecipeRepository) :
ViewModel(), RecipeMakingEventListener, SpinnerItemChangeListener {
private val _uiEvent: MutableLiveData<Event<MakingEvent>> = MutableLiveData()
val uiEvent: LiveData<Event<MakingEvent>>
private val _uiEvent: MutableLiveData<Event<RecipeMakingEvent>> = MutableLiveData()
val uiEvent: LiveData<Event<RecipeMakingEvent>>
get() = _uiEvent

private val _categorySelectedValue: MutableLiveData<String> = MutableLiveData()
Expand All @@ -39,10 +39,10 @@ class RecipeMakingViewModel(private val makingRecipeRepository: MakingRecipeRepo
viewModelScope.launch {
try {
val uri = makingRecipeRepository.fetchImageUri(keyName)
_uiEvent.value = Event(MakingEvent.PresignedUrlRequestSuccessful(uri))
_uiEvent.value = Event(RecipeMakingEvent.PresignedUrlRequestSuccessful(uri))
} catch (e: Exception) {
e.printStackTrace()
_uiEvent.value = Event(MakingEvent.PostImageFailure)
_uiEvent.value = Event(RecipeMakingEvent.PostImageFailure)
}
}
}
Expand All @@ -56,10 +56,10 @@ class RecipeMakingViewModel(private val makingRecipeRepository: MakingRecipeRepo
try {
makingRecipeRepository.uploadImageToS3(presignedUrl, file)
thumbnailTitle = file.name
_uiEvent.value = Event(MakingEvent.PostImageSuccessful)
_uiEvent.value = Event(RecipeMakingEvent.PostImageSuccessful)
} catch (e: Exception) {
e.printStackTrace()
_uiEvent.value = Event(MakingEvent.PostImageFailure)
_uiEvent.value = Event(RecipeMakingEvent.PostImageFailure)
}
}
}
Expand All @@ -69,7 +69,7 @@ class RecipeMakingViewModel(private val makingRecipeRepository: MakingRecipeRepo
}

override fun onAddImage() {
_uiEvent.value = Event(MakingEvent.AddImage)
_uiEvent.value = Event(RecipeMakingEvent.AddImage)
}

override fun onConfirm() {
Expand All @@ -87,7 +87,7 @@ class RecipeMakingViewModel(private val makingRecipeRepository: MakingRecipeRepo
title.isNullOrEmpty() ||
thumbnailTitle.isNullOrEmpty()
) {
_uiEvent.value = Event(MakingEvent.DescriptionFormNotCompleted)
_uiEvent.value = Event(RecipeMakingEvent.DescriptionFormNotCompleted)
return@launch
}

Expand Down Expand Up @@ -119,9 +119,9 @@ class RecipeMakingViewModel(private val makingRecipeRepository: MakingRecipeRepo

makingRecipeRepository.postRecipeDescription(recipeDescription)
.onSuccess { recipeId ->
_uiEvent.value = Event(MakingEvent.NavigateToMakingStep(recipeId))
_uiEvent.value = Event(RecipeMakingEvent.NavigateToMakingStep(recipeId))
}.onFailure {
_uiEvent.value = Event(MakingEvent.PostRecipeFailure)
_uiEvent.value = Event(RecipeMakingEvent.PostRecipeFailure)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import net.pengcook.android.data.repository.makingrecipe.DefaultMakingRecipeRepository
import net.pengcook.android.presentation.core.util.Event
import net.pengcook.android.presentation.making.MakingEvent
import net.pengcook.android.presentation.making.RecipeMakingEvent
import net.pengcook.android.presentation.making.RecipeMakingViewModel
import org.junit.After
import org.junit.Assert.assertEquals
Expand All @@ -33,8 +33,8 @@ class RecipeMakingViewModelTest {

private val repository: DefaultMakingRecipeRepository = mockk()

private val eventObserver: Observer<Event<MakingEvent>> = mockk(relaxed = true)
private val eventSlot = slot<Event<MakingEvent>>()
private val eventObserver: Observer<Event<RecipeMakingEvent>> = mockk(relaxed = true)
private val eventSlot = slot<Event<RecipeMakingEvent>>()

private lateinit var viewModel: RecipeMakingViewModel

Expand Down Expand Up @@ -68,7 +68,7 @@ class RecipeMakingViewModelTest {
coVerify { repository.fetchImageUri(keyName) }
assertEquals(
eventSlot.captured.getContentIfNotHandled(),
MakingEvent.PresignedUrlRequestSuccessful(url),
RecipeMakingEvent.PresignedUrlRequestSuccessful(url),
)
}

Expand All @@ -90,7 +90,7 @@ class RecipeMakingViewModelTest {
coVerify { repository.fetchImageUri(keyName) }
assertEquals(
eventSlot.captured.getContentIfNotHandled(),
MakingEvent.PostImageFailure,
RecipeMakingEvent.PostImageFailure,
)
}

Expand All @@ -112,7 +112,7 @@ class RecipeMakingViewModelTest {
coVerify { repository.uploadImageToS3(presignedUrl, file) }
assertEquals(
eventSlot.captured.getContentIfNotHandled(),
MakingEvent.PostImageSuccessful,
RecipeMakingEvent.PostImageSuccessful,
)
}

Expand All @@ -136,6 +136,6 @@ class RecipeMakingViewModelTest {

verify { eventObserver.onChanged(capture(eventSlot)) }
coVerify { repository.uploadImageToS3(presignedUrl, file) }
assertEquals(eventSlot.captured.getContentIfNotHandled(), MakingEvent.PostImageFailure)
assertEquals(eventSlot.captured.getContentIfNotHandled(), RecipeMakingEvent.PostImageFailure)
}
}

0 comments on commit d6559fa

Please sign in to comment.