-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ add taking time form for step making #358
Changes from 5 commits
200c52d
e2fc9aa
1f8551a
305681a
e6615e6
1ad929a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ fun RecipeStepEntity.toRecipeStepMaking(): RecipeStepMaking = | |
image = imageTitle ?: "", | ||
imageUri = imageUri ?: "", | ||
stepId = id, | ||
cookingTime = cookingTime ?: "::", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null 이면 "::"이렇게 표시하는게 의도된거죠..? 00:00:00 이런 방식이 아닌거죠..? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. null일 경우는 사실상 이뤄질 일이 없긴 한데, 없으면 그냥 빈 값으로 edittext에 들어가도록 하려고 했습니다. |
||
) | ||
|
||
fun IngredientEntity.toIngredient(): Ingredient = | ||
|
@@ -90,7 +91,7 @@ fun Ingredient.toIngredientRequest(): IngredientRequest = | |
|
||
fun RecipeStepMaking.toRecipeStepRequest(): RecipeStepRequest = | ||
RecipeStepRequest( | ||
cookingTime = "00:00:00", | ||
cookingTime = cookingTime, | ||
description = description, | ||
image = image, | ||
sequence = sequence, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,8 +202,8 @@ class RecipeMakingFragment : Fragment() { | |
val etHour = binding.itemTimeRequired.etTimeAmountPicker.etHour | ||
val etMinute = binding.itemTimeRequired.etTimeAmountPicker.etMinute | ||
val etSecond = binding.itemTimeRequired.etTimeAmountPicker.etSecond | ||
etHour.filters = arrayOf(MinMaxInputFilter(0, 23)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 시간에 맞는 필터사용 굿 👍 |
||
arrayOf(MinMaxInputFilter(0, 59)).also { filters -> | ||
etHour.filters = filters | ||
etMinute.filters = filters | ||
etSecond.filters = filters | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,8 +112,8 @@ class RecipeMakingViewModel | |
val ingredients = ingredientContent.value?.trim() | ||
val title = titleContent.value?.trim() | ||
val hour = hourContent.value | ||
val minute = minuteContent.value | ||
val second = secondContent.value | ||
val minute = minuteContent.value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minute이 second 아래로 옮겨진거 같은데, 이유가 있을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵넵 좋습니다! |
||
|
||
if (category.isNullOrEmpty() || | ||
introduction.isNullOrEmpty() || | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ class StepMakingViewModel | |
) : ViewModel(), | ||
StepMakingEventHandler, | ||
AppbarDoubleActionEventListener { | ||
private val stepTraversalStatus = MutableList(maximumStep) { false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 내용은 정확히 로직이 이해가 되지 않네요... 오프라인으로 설명 한번 들으러 가겠습니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 설명 잘 들었습니다! approve 하겠습니다! |
||
|
||
private val _stepNumber = MutableLiveData<Int>(1) | ||
val stepNumber: LiveData<Int> get() = _stepNumber | ||
|
||
|
@@ -56,8 +58,17 @@ class StepMakingViewModel | |
val uiEvent: LiveData<Event<RecipeStepMakingEvent>> | ||
get() = _uiEvent | ||
|
||
private var completionPressed = false | ||
|
||
private val _errorVisibility: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val errorVisibility: LiveData<Boolean> | ||
get() = _errorVisibility | ||
|
||
private val stepCompletion: MutableMap<Int, Boolean> = mutableMapOf(1 to false) | ||
|
||
val minuteContent = MutableLiveData<String>() | ||
val secondContent = MutableLiveData<String>() | ||
|
||
init { | ||
val stepNumber = stepNumber.value | ||
if (stepNumber != null) { | ||
|
@@ -72,6 +83,7 @@ class StepMakingViewModel | |
override fun moveToNextPage() { | ||
val imageUploaded = imageUploaded.value | ||
val introduction = introductionContent.value | ||
|
||
if (imageUploaded != true) { | ||
_uiEvent.value = Event(RecipeStepMakingEvent.ImageNotUploaded) | ||
return | ||
|
@@ -115,6 +127,9 @@ class StepMakingViewModel | |
|
||
override fun customAction() { | ||
viewModelScope.launch { | ||
completionPressed = true | ||
_errorVisibility.value = true | ||
|
||
if (imageSelected.value != true) { | ||
_uiEvent.value = Event(RecipeStepMakingEvent.FormNotCompleted) | ||
return@launch | ||
|
@@ -184,6 +199,8 @@ class StepMakingViewModel | |
private fun initStepData(stepNumber: Int) { | ||
viewModelScope.launch { | ||
_isLoading.value = true | ||
_errorVisibility.value = completionPressed && stepTraversalStatus[stepNumber - 1] | ||
stepTraversalStatus[stepNumber - 1] = true | ||
_imageUri.value = null | ||
fetchRecipeStep(stepNumber) | ||
_isLoading.value = false | ||
|
@@ -214,6 +231,8 @@ class StepMakingViewModel | |
_imageUploaded.value = false | ||
introductionContent.value = "" | ||
thumbnailTitle = null | ||
minuteContent.value = "" | ||
secondContent.value = "" | ||
} | ||
|
||
private suspend fun postRecipe(recipeCreation: RecipeCreation) { | ||
|
@@ -249,7 +268,11 @@ class StepMakingViewModel | |
sequence = stepNumber, | ||
).onSuccess { recipeStep -> | ||
if (recipeStep == null) return@onSuccess | ||
val minute = recipeStep.cookingTime.split(SEPARATOR_TIME).getOrNull(1) ?: "" | ||
val second = recipeStep.cookingTime.split(SEPARATOR_TIME).getOrNull(2) ?: "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 하디의 코드였다면, 어김없이 매직넘버로 슬라이딩 태클 걸었을지도...?ㅋㅋㅋ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
introductionContent.value = recipeStep.description | ||
minuteContent.value = if (minute.toIntOrNull() == 0) "" else minute | ||
secondContent.value = if (second.toIntOrNull() == 0) "" else second | ||
if (recipeStep.imageUri.isNotEmpty()) { | ||
_imageUri.value = Uri.parse(recipeStep.imageUri) | ||
} | ||
|
@@ -269,6 +292,11 @@ class StepMakingViewModel | |
stepNumber: Int, | ||
stepAction: StepAction, | ||
) { | ||
val minute = minuteContent.value | ||
val second = secondContent.value | ||
println("minute : $minute") | ||
println("second : $second") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거 지워주시면 감사하겠습니다! |
||
|
||
val recipeStep = | ||
RecipeStepMaking( | ||
recipeId = recipeId, | ||
|
@@ -277,6 +305,12 @@ class StepMakingViewModel | |
image = thumbnailTitle ?: "", | ||
stepId = 1L, | ||
imageUri = imageUri.value?.toString() ?: "", | ||
cookingTime = | ||
FORMAT_TIME_REQUIRED.format( | ||
0, | ||
minute?.toIntOrNull() ?: 0, | ||
second?.toIntOrNull() ?: 0, | ||
), | ||
) | ||
|
||
recipeStepMakingRepository.saveRecipeStep(recipeId = recipeId, recipeStep = recipeStep) | ||
|
@@ -290,6 +324,9 @@ class StepMakingViewModel | |
} | ||
|
||
companion object { | ||
private const val FORMAT_TIME_REQUIRED = "%02d:%02d:%02d" | ||
private const val SEPARATOR_TIME = ":" | ||
|
||
fun provideFactory( | ||
assistedFactory: StepMakingViewModelFactory, | ||
recipeId: Long, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:bind="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<data> | ||
|
||
<variable | ||
name="title" | ||
type="String" /> | ||
|
||
<variable | ||
name="hintContent" | ||
type="String" /> | ||
|
||
<variable | ||
name="content" | ||
type="String" /> | ||
|
||
<variable | ||
name="errorVisibility" | ||
type="Boolean" /> | ||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<include | ||
android:id="@+id/et_content" | ||
layout="@layout/item_form_multi_text" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
app:content="@={content}" | ||
app:hintContent="@{hintContent}" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:title="@{title}" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_alert_message" | ||
style="@style/WarningMessageUnfilledForm" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/et_content" | ||
bind:visibility="@{errorVisibility && (content == null || content.isEmpty())}" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null 처리 굿입니다!