Skip to content

Commit

Permalink
merge: 서버에서 주는 형식에 맞게 Response 형식 변경 및 매퍼 로직 변경, 행사 태그를 칩 그룹에 추가하는 바인…
Browse files Browse the repository at this point in the history
…딩 어댑터 변경, 대회 목록도 행사 목록, 스크랩 목록처럼 바인딩 어댑터로 칩을 추가하도록 변경 (#907)

Related to: #906
  • Loading branch information
ki960213 authored Jan 27, 2024
1 parent 1f98e56 commit 1861824
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class EventResponse(
@SerialName("location")
val location: String,
@SerialName("tags")
val tags: List<String>,
val tags: List<EventTagResponse>,
@SerialName("thumbnailUrl")
val thumbnailUrl: String?,
@SerialName("type")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun EventResponse.toData(): Event = Event(
applyingStartDate = applyStartDate,
applyingEndDate = applyEndDate,
location = location,
tags = tags,
tags = tags.toData(),
posterImageUrl = thumbnailUrl?.let { BuildConfig.IMAGE_URL_PREFIX + it } ?: "",
type = type,
paymentType = paymentType.toPaymentType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class Event(
val applyingStartDate: LocalDateTime = DEFAULT_LOCAL_DATE_TIME,
val applyingEndDate: LocalDateTime = DEFAULT_LOCAL_DATE_TIME,
val location: String = "",
val tags: List<String> = emptyList(),
val tags: List<EventTag> = emptyList(),
val posterImageUrl: String? = "",
val paymentType: PaymentType = DEFAULT_PAYMENT_TYPE,
val onOfflineMode: OnOfflineMode = DEFAULT_ON_OFFLINE_MODE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.emmsale.presentation.common.bindingadapter

import androidx.databinding.BindingAdapter
import com.emmsale.data.model.EventTag
import com.emmsale.presentation.common.views.EventTagChip
import com.google.android.material.chip.ChipGroup

@BindingAdapter("app:eventChips")
fun ChipGroup.setEventChips(tags: List<String>?) {
fun ChipGroup.setEventChips(tags: List<EventTag>?) {
removeAllViews()
addEventTags(tags ?: emptyList())
}

private fun ChipGroup.addEventTags(tags: List<String>) {
private fun ChipGroup.addEventTags(tags: List<EventTag>) {
tags.forEach { addView(createEventTag(it)) }
}

private fun ChipGroup.createEventTag(tag: String) = EventTagChip(this.context).apply {
text = tag
private fun ChipGroup.createEventTag(tag: EventTag) = EventTagChip(this.context).apply {
text = tag.name
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.emmsale.presentation.ui.competitionList.recyclerView

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.emmsale.R
import com.emmsale.data.model.Event
import com.emmsale.databinding.ItemCompetitionBinding
import com.emmsale.presentation.common.views.EventTagChip
import com.emmsale.presentation.common.views.eventChipOf

class CompetitionViewHolder(
parent: ViewGroup,
Expand All @@ -24,18 +21,5 @@ class CompetitionViewHolder(

fun bind(event: Event) {
binding.event = event
binding.cgEventTags.removeAllViews()
event.tags.forEach(::addEventChip)
}

private fun addEventChip(tagName: String) {
binding.cgEventTags.addView(createEventChip(itemView.context, tagName))
}

private fun createEventChip(
context: Context,
tagName: String,
): EventTagChip = context.eventChipOf {
text = tagName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="10dp"
app:eventChips="@{event.tags}"
app:layout_constraintEnd_toEndOf="@+id/iv_event_poster"
app:layout_constraintStart_toStartOf="@+id/iv_event_poster"
app:layout_constraintTop_toBottomOf="@+id/tv_is_online" />
Expand Down

0 comments on commit 1861824

Please sign in to comment.