Skip to content

Commit

Permalink
refactor(artist): 사용하지 않는 멀티타입 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
re4rk committed Feb 20, 2024
1 parent e083af2 commit 882e34f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ArtistDetailViewModel @Inject constructor(

private fun Stages.toUiState() = this.stage.map {
StageUiState(
id = it.id.toLong(),
id = it.id,
name = it.name,
imageUrl = it.imageUrl,
startDate = it.startDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,24 @@ import com.festago.festago.presentation.ui.artistdetail.uistate.StageUiState

class ArtistDetailAdapter(
private val onArtistClick: (Long) -> Unit,
) : ListAdapter<Any, ArtistDetailViewHolder>(diffUtil) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArtistDetailViewHolder {
return when (viewType) {
1 -> ArtistDetailFestivalViewHolder.of(parent, onArtistClick)
else -> throw IllegalArgumentException("Invalid viewType")
}
) : ListAdapter<StageUiState, ArtistDetailFestivalViewHolder>(diffUtil) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArtistDetailFestivalViewHolder {
return ArtistDetailFestivalViewHolder.of(parent, onArtistClick)
}

override fun onBindViewHolder(holder: ArtistDetailViewHolder, position: Int) {
override fun onBindViewHolder(holder: ArtistDetailFestivalViewHolder, position: Int) {
val item = getItem(position)
return when (holder) {
is ArtistDetailFestivalViewHolder -> holder.bind(item as StageUiState)
}
}

override fun getItemViewType(position: Int): Int {
return when (getItem(position)) {
is StageUiState -> 1
else -> throw IllegalArgumentException("Invalid item")
}
holder.bind(item)
}

companion object {
private val diffUtil = object : DiffUtil.ItemCallback<Any>() {
override fun areItemsTheSame(oldItem: Any, newItem: Any): Boolean = when {
oldItem is StageUiState && newItem is StageUiState -> oldItem.id == newItem.id
else -> false
private val diffUtil = object : DiffUtil.ItemCallback<StageUiState>() {
override fun areItemsTheSame(oldItem: StageUiState, newItem: StageUiState): Boolean {
return oldItem.id == newItem.id
}

override fun areContentsTheSame(oldItem: Any, newItem: Any): Boolean = when {
oldItem is StageUiState && newItem is StageUiState
-> oldItem as StageUiState == newItem

else -> false
override fun areContentsTheSame(oldItem: StageUiState, newItem: StageUiState): Boolean {
return oldItem == newItem
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import java.time.LocalDate
class ArtistDetailFestivalViewHolder(
private val binding: ItemArtistDetailFestivalBinding,
onArtistClick: (Long) -> Unit,
) :
ArtistDetailViewHolder(binding) {
) : RecyclerView.ViewHolder(binding.root) {
private val artistAdapter = ArtistAdapter(onArtistClick)

init {
Expand Down

This file was deleted.

0 comments on commit 882e34f

Please sign in to comment.