Skip to content

Commit

Permalink
♻️ optimize bindingadapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Hogu59 authored and kmkim2689 committed Sep 23, 2024
1 parent 91d4048 commit bd76bf7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,36 +179,6 @@ fun TextView.setCommentCount(count: Int) {
text = context.getString(R.string.comment_format_plural).format(count)
}

@BindingAdapter("bind:content", "bind:visibleCondition")
fun setVisibility(
view: View,
content: String?,
visibleCondition: Boolean,
) {
view.visibility =
if (content.isNullOrEmpty() && visibleCondition) {
View.VISIBLE
} else {
View.GONE
}
}

@BindingAdapter("bind:hour", "bind:minute", "bind:second", "bind:visibleCondition")
fun setTimeVisibility(
view: View,
hour: String?,
minute: String?,
second: String?,
visibleCondition: Boolean,
) {
view.visibility =
if ((hour.isNullOrEmpty() || minute.isNullOrEmpty() || second.isNullOrEmpty()) && visibleCondition) {
View.VISIBLE
} else {
View.GONE
}
}

@BindingAdapter("count")
fun setFormattedLikeCount(
textView: TextView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class RecipeMakingViewModel(
val imageSelected: LiveData<Boolean>
get() = _imageSelected

private val _isButtonClicked: MutableLiveData<Boolean> = MutableLiveData(false)
val isButtonClicked: LiveData<Boolean>
get() = _isButtonClicked
private val _isMakingStepButtonClicked: MutableLiveData<Boolean> = MutableLiveData(false)
val isMakingStepButtonClicked: LiveData<Boolean>
get() = _isMakingStepButtonClicked

private var thumbnailTitle: String? = null

Expand Down Expand Up @@ -121,7 +121,7 @@ class RecipeMakingViewModel(
second == null
) {
_uiEvent.value = Event(RecipeMakingEvent.DescriptionFormNotCompleted)
_isButtonClicked.value = true
_isMakingStepButtonClicked.value = true
return@launch
}

Expand Down
10 changes: 5 additions & 5 deletions android/app/src/main/res/layout/fragment_recipe_making.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="16dp"
app:visibleCondition="@{vm.isButtonClicked}"
app:visibleCondition="@{vm.isMakingStepButtonClicked}"
app:content="@={vm.titleContent}"
app:hintContent="@{@string/making_write_recipe_title}"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -83,7 +83,7 @@
layout="@layout/item_form_text_with_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:visibleCondition="@{vm.isButtonClicked}"
app:visibleCondition="@{vm.isMakingStepButtonClicked}"
android:layout_marginVertical="16dp"
app:content="@={vm.ingredientContent}"
app:hintContent="@{@string/making_write_ingredient}"
Expand All @@ -101,7 +101,7 @@
app:hour="@={vm.hourContent}"
app:minute="@={vm.minuteContent}"
app:second="@={vm.secondContent}"
app:visibleCondition="@{vm.isButtonClicked}"
app:visibleCondition="@{vm.isMakingStepButtonClicked}"
android:layout_marginVertical="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -115,7 +115,7 @@
android:layout_marginVertical="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:visibleCondition="@{vm.isButtonClicked}"
app:visibleCondition="@{vm.isMakingStepButtonClicked}"
app:layout_constraintTop_toBottomOf="@id/item_time_required"
app:selectedRating="@={vm.difficultySelectedValue}"
app:title="@{@string/making_form_difficulty}" />
Expand All @@ -129,7 +129,7 @@
app:content="@={vm.introductionContent}"
app:hintContent="@{@string/step_making_hint}"
app:layout_constraintEnd_toEndOf="parent"
app:visibleCondition="@{vm.isButtonClicked}"
app:visibleCondition="@{vm.isMakingStepButtonClicked}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/makingRecipeDifficulty"
app:title="@{@string/making_form_introduction}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
style="@style/WarningMessageUnfilledForm"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/et_form_text"
bind:content="@{content}"
bind:visibleCondition="@{visibleCondition}" />
bind:visibility="@{visibleCondition &amp;&amp; (content == null || content.isEmpty())}" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
android:id="@+id/tv_alert_message"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/et_form_text"
bind:content="@{content}"
bind:visibleCondition="@{visibleCondition}"
bind:visibility="@{visibleCondition &amp;&amp; (content == null || content.isEmpty())}"
style="@style/WarningMessageUnfilledForm" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
style="@style/WarningMessageUnfilledForm"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/et_time_amount_picker"
bind:hour="@{hour}"
bind:minute="@{minute}"
bind:second="@{second}"
bind:visibleCondition="@{visibleCondition}" />
bind:visibility="@{visibleCondition &amp;&amp; (hour == null || hour.isEmpty() || minute == null || minute.isEmpty() || second == null || second.isEmpty())}" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit bd76bf7

Please sign in to comment.