-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc05563
commit 0ce5c94
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/sopt/umbba_android/presentation/list/ListQuestionAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.sopt.umbba_android.presentation.list | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopt.umbba_android.data.model.response.ExampleResponseDto | ||
import com.sopt.umbba_android.databinding.ItemQuestionListBinding | ||
|
||
class ListQuestionAdapter(private val itemClick: (ExampleResponseDto) -> (Unit)) : | ||
ListAdapter<ExampleResponseDto, ListQuestionAdapter.ListViewHolder>(diffUtil) { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListViewHolder { | ||
val binding = | ||
ItemQuestionListBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return ListViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ListViewHolder, position: Int) { | ||
holder.onBind(currentList[position]) | ||
} | ||
|
||
class ListViewHolder( | ||
private val binding: ItemQuestionListBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(data: ExampleResponseDto) { | ||
TODO("서버 연결할 때 채우기") | ||
} | ||
} | ||
|
||
companion object { | ||
val diffUtil = object : DiffUtil.ItemCallback<ExampleResponseDto>() { | ||
override fun areItemsTheSame( | ||
oldItem: ExampleResponseDto, | ||
newItem: ExampleResponseDto | ||
): Boolean { | ||
return oldItem.id == newItem.id | ||
} | ||
|
||
override fun areContentsTheSame( | ||
oldItem: ExampleResponseDto, | ||
newItem: ExampleResponseDto | ||
): Boolean { | ||
return oldItem == newItem | ||
} | ||
} | ||
} | ||
} |