-
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 all 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 |
---|---|---|
|
@@ -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 |
---|---|---|
|
@@ -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,13 @@ class StepMakingViewModel | |
sequence = stepNumber, | ||
).onSuccess { recipeStep -> | ||
if (recipeStep == null) return@onSuccess | ||
val minute = | ||
recipeStep.cookingTime.split(SEPARATOR_TIME).getOrNull(1) ?: DEFAULT_TIME_STRING | ||
val second = | ||
recipeStep.cookingTime.split(SEPARATOR_TIME).getOrNull(2) ?: DEFAULT_TIME_STRING | ||
introductionContent.value = recipeStep.description | ||
minuteContent.value = if (minute.toIntOrNull() == 0) DEFAULT_TIME_STRING else minute | ||
secondContent.value = if (second.toIntOrNull() == 0) DEFAULT_TIME_STRING else second | ||
if (recipeStep.imageUri.isNotEmpty()) { | ||
_imageUri.value = Uri.parse(recipeStep.imageUri) | ||
} | ||
|
@@ -269,14 +294,23 @@ class StepMakingViewModel | |
stepNumber: Int, | ||
stepAction: StepAction, | ||
) { | ||
val minute = minuteContent.value | ||
val second = secondContent.value | ||
|
||
val recipeStep = | ||
RecipeStepMaking( | ||
recipeId = recipeId, | ||
sequence = stepNumber, | ||
description = introductionContent.value ?: "", | ||
image = thumbnailTitle ?: "", | ||
description = introductionContent.value ?: DEFAULT_TIME_STRING, | ||
image = thumbnailTitle ?: DEFAULT_TIME_STRING, | ||
stepId = 1L, | ||
imageUri = imageUri.value?.toString() ?: "", | ||
imageUri = imageUri.value?.toString() ?: DEFAULT_IMAGE_URI, | ||
cookingTime = | ||
FORMAT_TIME_REQUIRED.format( | ||
DEFAULT_TIME_VALUE, | ||
minute?.toIntOrNull() ?: DEFAULT_TIME_VALUE, | ||
second?.toIntOrNull() ?: DEFAULT_TIME_VALUE, | ||
), | ||
) | ||
|
||
recipeStepMakingRepository.saveRecipeStep(recipeId = recipeId, recipeStep = recipeStep) | ||
|
@@ -290,6 +324,12 @@ class StepMakingViewModel | |
} | ||
|
||
companion object { | ||
private const val FORMAT_TIME_REQUIRED = "%02d:%02d:%02d" | ||
private const val SEPARATOR_TIME = ":" | ||
private const val DEFAULT_TIME_STRING = "" | ||
private const val DEFAULT_TIME_VALUE = 0 | ||
private const val DEFAULT_IMAGE_URI = "" | ||
|
||
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 처리 굿입니다!