-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#10 [ui] 행복루틴 추가하기(목록) 뷰 #20
Changes from 34 commits
7784374
bc79862
6b4c0a5
6ae9da1
558f7d0
a34b25d
6af7775
e362db2
c4de93d
c27de5a
fa6b5d9
9745584
b346cdf
51981c5
0e8eedd
ffd448a
b880f82
0cb86c6
40f307d
57e9fdb
f230357
35bb19a
f139f92
4ec8e14
1dc9f10
258ed07
7723c76
bba8d31
3a8bfe4
35410b4
b95a3e5
b39c071
61d2e5d
64df98d
03a66fe
5377e86
ea1c32e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class HappyChip( | ||
val themeId: Int, | ||
val name: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
import androidx.annotation.DrawableRes | ||
|
||
data class HappyContent( | ||
val routineId: Int, | ||
val title: String, | ||
val content: String, | ||
@DrawableRes val imageUrl: Int, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.sopetit.softie.ui.main.happy.addlist | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.ActivityHappyAddListBinding | ||
import com.sopetit.softie.domain.entity.HappyContent | ||
import com.sopetit.softie.ui.main.MainActivity | ||
import com.sopetit.softie.util.HorizontalChipItemDecoration | ||
import com.sopetit.softie.util.VerticalItemDecoration | ||
import com.sopetit.softie.util.binding.BindingActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class HappyAddListActivity : | ||
BindingActivity<ActivityHappyAddListBinding>(R.layout.activity_happy_add_list) { | ||
|
||
private val viewModel by viewModels<HappyAddListViewModel>() | ||
private lateinit var itemDeco: RecyclerView.ItemDecoration | ||
private lateinit var chipDeco: RecyclerView.ItemDecoration | ||
|
||
private lateinit var happyAddListChipContentAdapter: HappyAddListChipContentAdapter | ||
private lateinit var happyAddListContentAdapter: HappyAddListContentAdapter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adapter도 메모리 누수 방지를 위해 null처리를 해주는 것이 좋을 것 같습니다!! 헷갈리면 제 코드 참고하세용 |
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityHappyAddListBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
val themeId = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 처음에 아무것도 선택 안된채로 초기화 시켜둔건가요?.? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. id는 뒤에 할당받아 사용할거라 0으로 두었습니다! |
||
|
||
happyAddListChipContentAdapter = HappyAddListChipContentAdapter() | ||
happyAddListContentAdapter = HappyAddListContentAdapter(::moveToDetail) | ||
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setChipAdapter 처럼 함수 분리 해주세요! |
||
|
||
itemDeco = VerticalItemDecoration(applicationContext) | ||
binding.rvHappyAddList.addItemDecoration(itemDeco) | ||
chipDeco = HorizontalChipItemDecoration(applicationContext) | ||
binding.rvHappyAddListChip.addItemDecoration(chipDeco) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 마찬가지 입니다. setItemDeco로 함수 분리 해주세요! |
||
binding.ivHappyAddBackArrow.setOnClickListener { | ||
finish() | ||
} | ||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 역시나 함수 분리 부탁드립니다! setBackBtnClickListener처럼 (꼭 변수명 따라가지 않아도 됨) 부탁드립니다. |
||
|
||
setupAdapter(themeId) | ||
} | ||
|
||
private fun setupAdapter(themeId: Int) { | ||
with(binding) { | ||
rvHappyAddListChip.adapter = happyAddListChipContentAdapter | ||
rvHappyAddList.adapter = happyAddListContentAdapter | ||
} | ||
happyAddListChipContentAdapter.submitList(viewModel.mockHappyChipList.value) | ||
happyAddListContentAdapter.submitList(viewModel.mockHappyContentList.value) | ||
|
||
happyAddListChipContentAdapter.setOnChipClickListener { handleChipClick(it.themeId) } | ||
} | ||
|
||
private fun handleChipClick(themeId: Int) { | ||
val listToSubmit = when (themeId) { | ||
1 -> viewModel.mockHappyContentList.value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넘 멋져요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 고맙습니다 허허 |
||
2 -> viewModel.mockHappyContentListOne.value | ||
3 -> viewModel.mockHappyContentListTwo.value | ||
4 -> viewModel.mockHappyContentListThree.value | ||
5 -> viewModel.mockHappyContentListFour.value | ||
6 -> viewModel.mockHappyContentListFive.value | ||
else -> viewModel.mockHappyContentList.value | ||
Comment on lines
+71
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 enum class 한 번 써보세요! when을 사용할 때 else를 쓰지 않아도 됩니다! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 충고 감사함다 |
||
} | ||
|
||
listToSubmit?.let { makeSubmitList(it) } | ||
} | ||
|
||
private fun makeSubmitList(list: List<HappyContent>) { | ||
happyAddListContentAdapter.submitList(list) | ||
} | ||
|
||
private fun moveToDetail(id: Int) { | ||
Intent(this, MainActivity::class.java).apply { | ||
putExtra(ID, id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋아요 |
||
startActivity(this) | ||
} | ||
} | ||
|
||
companion object { | ||
const val ID = "id" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.sopetit.softie.ui.main.happy.addlist | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopetit.softie.databinding.ItemHappyAddListChipBinding | ||
import com.sopetit.softie.domain.entity.HappyChip | ||
import com.sopetit.softie.util.ItemDiffCallback | ||
|
||
class HappyAddListChipContentAdapter : | ||
ListAdapter<HappyChip, HappyAddListChipContentAdapter.HappyAddListChipContentViewHolder>( | ||
ItemDiffCallback<HappyChip>( | ||
onItemsTheSame = { oldItem, newItem -> oldItem == newItem }, | ||
onContentsTheSame = { oldItem, newItem -> oldItem == newItem } | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onItemsTheSame은 아이템이 같은지, onContentsTheSame은 아이템의 내용이 같은지 확인합니다. onItemsTheSame를 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 지적 감사합니다~~ |
||
) { | ||
|
||
inner class HappyAddListChipContentViewHolder( | ||
private val binding: ItemHappyAddListChipBinding, | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(data: HappyChip) { | ||
binding.itemHappyAddChipComponent.text = data.name | ||
binding.root.setOnClickListener { | ||
onItemClickListener?.let { it(data) } | ||
} | ||
} | ||
} | ||
|
||
private var onItemClickListener: ((HappyChip) -> Unit)? = null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 변수 class 위로 올려주세요!! 강희언니가 코드 리뷰 해준 제꺼 pr 참고하시면 좋을 것 같아용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 반영하겠습니다~~ |
||
fun setOnChipClickListener(listener: (HappyChip) -> Unit) { | ||
onItemClickListener = listener | ||
} | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): HappyAddListChipContentViewHolder { | ||
val binding = ItemHappyAddListChipBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
return HappyAddListChipContentViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: HappyAddListChipContentViewHolder, position: Int) { | ||
holder.onBind(getItem(position)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.sopetit.softie.ui.main.happy.addlist | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopetit.softie.databinding.ItemHappyAddListBinding | ||
import com.sopetit.softie.domain.entity.HappyContent | ||
import com.sopetit.softie.util.ItemDiffCallback | ||
|
||
class HappyAddListContentAdapter(private val moveToDetail: (Int) -> Unit) : | ||
ListAdapter<HappyContent, HappyAddListContentAdapter.HappyAddListContentViewHolder>( | ||
ItemDiffCallback<HappyContent>( | ||
onItemsTheSame = { oldItem, newItem -> oldItem == newItem }, | ||
onContentsTheSame = { oldItem, newItem -> oldItem == newItem } | ||
) | ||
) { | ||
|
||
inner class HappyAddListContentViewHolder( | ||
private val binding: ItemHappyAddListBinding, | ||
private val moveToDetail: (Int) -> Unit, | ||
) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(data: HappyContent) { | ||
binding.tvHappyListItemTitle.text = data.title | ||
binding.tvHappyListItemContent.text = data.content | ||
binding.ivHappyListItemIcon.setImageResource(data.imageUrl) | ||
|
||
binding.root.setOnClickListener { | ||
moveToDetail(data.routineId) | ||
} | ||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감격입니다!!!! 이제 호연님도 리사이클러뷰 마스터 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이야!!!! 이제 리사이클러뷰 클릭리스너 마스터했네요!!! |
||
} | ||
} | ||
|
||
override fun onCreateViewHolder( | ||
parent: ViewGroup, | ||
viewType: Int | ||
): HappyAddListContentViewHolder { | ||
val binding = ItemHappyAddListBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
return HappyAddListContentViewHolder(binding, moveToDetail) | ||
} | ||
|
||
override fun onBindViewHolder(holder: HappyAddListContentViewHolder, position: Int) { | ||
holder.onBind(currentList[position]) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.sopetit.softie.ui.main.happy.addlist | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.domain.entity.HappyChip | ||
import com.sopetit.softie.domain.entity.HappyContent | ||
|
||
class HappyAddListViewModel : ViewModel() { | ||
private val _mockHappyChipList = MutableLiveData<List<HappyChip>>() | ||
val mockHappyChipList: LiveData<List<HappyChip>> = _mockHappyChipList | ||
|
||
private val _mockHappyContentList = MutableLiveData<List<HappyContent>>() | ||
val mockHappyContentList: LiveData<List<HappyContent>> = _mockHappyContentList | ||
|
||
private val _mockHappyContentListOne = MutableLiveData<List<HappyContent>>() | ||
val mockHappyContentListOne: LiveData<List<HappyContent>> = _mockHappyContentListOne | ||
|
||
private val _mockHappyContentListTwo = MutableLiveData<List<HappyContent>>() | ||
val mockHappyContentListTwo: LiveData<List<HappyContent>> = _mockHappyContentListTwo | ||
|
||
private val _mockHappyContentListThree = MutableLiveData<List<HappyContent>>() | ||
val mockHappyContentListThree: LiveData<List<HappyContent>> = _mockHappyContentListThree | ||
|
||
private val _mockHappyContentListFour = MutableLiveData<List<HappyContent>>() | ||
val mockHappyContentListFour: LiveData<List<HappyContent>> = _mockHappyContentListFour | ||
|
||
private val _mockHappyContentListFive = MutableLiveData<List<HappyContent>>() | ||
val mockHappyContentListFive: LiveData<List<HappyContent>> = _mockHappyContentListFive | ||
Comment on lines
+11
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mock이라고 이름 붙이는 것도 좋지만, 그냥 실제 변수명처럼 쓴다면, 나중에 두 번 고칠 일은 없겠죠~? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오우 꿀팁이네요~ 가짜 데이터를 더 잘 사용하게 된다면 바꿔보겠습니다ㅎ |
||
|
||
init { | ||
_mockHappyContentList.value = listOf<HappyContent>( | ||
HappyContent( | ||
routineId = 1, | ||
title = "관계쌓기", | ||
content = "성숙한 사랑을 만나기 위한", | ||
imageUrl = R.drawable.ic_happy_red, | ||
), | ||
HappyContent( | ||
routineId = 2, | ||
title = "관계쌓기", | ||
content = "진정성 있는 관계를 만드는", | ||
imageUrl = R.drawable.ic_happy_red, | ||
), | ||
HappyContent( | ||
routineId = 3, | ||
title = "한 걸음 성장", | ||
content = "나를 알고 진짜 목표를 세우는", | ||
imageUrl = R.drawable.ic_happy_orange, | ||
), | ||
HappyContent( | ||
routineId = 4, | ||
title = "한 걸음 성장", | ||
content = "좋아하는, 잘하는 일을 찾아 가는", | ||
imageUrl = R.drawable.ic_happy_orange, | ||
), | ||
HappyContent( | ||
routineId = 5, | ||
title = "잘 쉬어가기", | ||
content = "데이터가 아직 없습니다", | ||
imageUrl = R.drawable.ic_happy_green, | ||
), | ||
HappyContent( | ||
routineId = 6, | ||
title = "새로운 나", | ||
content = "나를 알고 진짜 목표를 세우는", | ||
imageUrl = R.drawable.ic_happy_blue, | ||
), | ||
HappyContent( | ||
routineId = 7, | ||
title = "마음 챙김", | ||
content = "데이터가 아직 없습니다", | ||
imageUrl = R.drawable.ic_happy_purple, | ||
), | ||
) | ||
|
||
_mockHappyChipList.value = listOf<HappyChip>( | ||
HappyChip( | ||
themeId = 1, | ||
name = "전체", | ||
), | ||
HappyChip( | ||
themeId = 2, | ||
name = "관계쌓기", | ||
), | ||
HappyChip( | ||
themeId = 3, | ||
name = "한 걸음 성장", | ||
), | ||
HappyChip( | ||
themeId = 4, | ||
name = "잘 쉬어가기", | ||
), | ||
HappyChip( | ||
themeId = 5, | ||
name = "새로운 나", | ||
), | ||
HappyChip( | ||
themeId = 6, | ||
name = "마음 챙김", | ||
) | ||
) | ||
|
||
_mockHappyContentListOne.value = listOf<HappyContent>( | ||
HappyContent( | ||
routineId = 1, | ||
title = "관계쌓기", | ||
content = "성숙한 사랑을 만나기 위한", | ||
imageUrl = R.drawable.ic_happy_red, | ||
), | ||
HappyContent( | ||
routineId = 2, | ||
title = "관계쌓기", | ||
content = "진정성 있는 관계를 만드는", | ||
imageUrl = R.drawable.ic_happy_red, | ||
), | ||
) | ||
|
||
_mockHappyContentListTwo.value = listOf<HappyContent>( | ||
HappyContent( | ||
routineId = 3, | ||
title = "한 걸음 성장", | ||
content = "나를 알고 진짜 목표를 세우는", | ||
imageUrl = R.drawable.ic_happy_orange, | ||
), | ||
HappyContent( | ||
routineId = 4, | ||
title = "한 걸음 성장", | ||
content = "좋아하는, 잘하는 일을 찾아 가는", | ||
imageUrl = R.drawable.ic_happy_orange, | ||
), | ||
) | ||
|
||
_mockHappyContentListThree.value = listOf<HappyContent>( | ||
HappyContent( | ||
routineId = 5, | ||
title = "잘 쉬어가기", | ||
content = "데이터가 아직 없습니다", | ||
imageUrl = R.drawable.ic_happy_green, | ||
), | ||
) | ||
|
||
_mockHappyContentListFour.value = listOf<HappyContent>( | ||
HappyContent( | ||
routineId = 6, | ||
title = "새로운 나", | ||
content = "나를 알고 진짜 목표를 세우는", | ||
imageUrl = R.drawable.ic_happy_blue, | ||
), | ||
) | ||
|
||
_mockHappyContentListFive.value = listOf<HappyContent>( | ||
HappyContent( | ||
routineId = 7, | ||
title = "마음 챙김", | ||
content = "데이터가 아직 없습니다", | ||
imageUrl = R.drawable.ic_happy_purple, | ||
), | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋아요~