Skip to content

Commit

Permalink
#36 [�피드] 피드 간단일기 키워드 RV에서 Chip으로 수정
Browse files Browse the repository at this point in the history
#36 [�피드] 피드 간단일기 키워드 RV에서 Chip으로 수정
  • Loading branch information
ChunBaee authored May 26, 2023
2 parents e5e37ef + ce47b4d commit af50d2a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.chunbae.narchive.presentation.ui.main.feed.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.RecyclerView
import com.chunbae.narchive.R
import com.chunbae.narchive.data.data.FeedData
import com.chunbae.narchive.databinding.ItemFeedNormalDiaryBinding
import com.chunbae.narchive.databinding.ItemFeedSimpleDiaryBinding
import com.google.android.material.chip.Chip

class FeedAdapter (private val onClicked : (Int) -> Unit) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var feedDatas = mutableListOf<FeedData>()
private lateinit var context : Context

inner class NormalDiaryViewHolder(private val binding : ItemFeedNormalDiaryBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item : FeedData) {
Expand All @@ -20,13 +25,23 @@ class FeedAdapter (private val onClicked : (Int) -> Unit) : RecyclerView.Adapter
inner class SimpleDiaryViewHolder(private val binding : ItemFeedSimpleDiaryBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item : FeedData) {
binding.feedData = item
binding.itemFeedSimpleDiaryRvKeywords.adapter = item.keywords?.let { SimpleDiaryKeywordAdapter(it) }
item.keywords?.let {
for(i in it) {
binding.itemFeedSimpleDiaryRvKeywords.addView(Chip(context).apply {
text = i
isCloseIconVisible = false
chipBackgroundColor = ResourcesCompat.getColorStateList(resources, R.color.color_B2F0F4, null)
setTextColor(ResourcesCompat.getColorStateList(resources, R.color.white, null))
})
}
}
binding.root.setOnClickListener { onClicked.invoke(item.feedIdx) }
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
//:TODO 추후에 아이템 없을때 ViewHolder도 추가하기
context = parent.context
return when(viewType) {
1 -> SimpleDiaryViewHolder(ItemFeedSimpleDiaryBinding.inflate(LayoutInflater.from(parent.context), parent, false))
else -> NormalDiaryViewHolder(ItemFeedNormalDiaryBinding.inflate(LayoutInflater.from(parent.context), parent, false))
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/res/layout/item_feed_simple_diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,15 @@
app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_tv_user_nickname"
tools:text="3일 전" />

<androidx.recyclerview.widget.RecyclerView
<com.google.android.material.chip.ChipGroup
android:id="@+id/item_feed_simple_diary_rv_keywords"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_20"
android:layout_marginHorizontal="@dimen/margin_15"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
android:orientation="vertical"
app:spanCount="5"
app:layout_constraintTop_toBottomOf="@id/item_feed_simple_diary_iv_user_profile"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:itemCount="10"
tools:listitem="@layout/item_feed_simple_diary_rv_keywords"/>
app:layout_constraintEnd_toEndOf="parent" />

<ImageView
android:id="@+id/item_feed_simple_diary_iv_thumbnail"
Expand Down

0 comments on commit af50d2a

Please sign in to comment.