Skip to content
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

Merged
merged 37 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7784374
#10 [ui] 테마 추가하기
pump9918 Jan 9, 2024
bc79862
#10 [ui] 아이콘 추가
pump9918 Jan 9, 2024
6b4c0a5
#10 [ui] 카테고리 chip xml
pump9918 Jan 9, 2024
6ae9da1
#10 [ui] 카테고리 리스트 item
pump9918 Jan 9, 2024
558f7d0
#10 [ui] 카테고리 리사이클러뷰 xml
pump9918 Jan 9, 2024
a34b25d
Merge branch 'develop' into feature/#10-ui-happy-add-view-list
pump9918 Jan 9, 2024
6af7775
#10 [ui] chip 스타일 설정
pump9918 Jan 10, 2024
e362db2
#10 [ui] 상단 chip item xml
pump9918 Jan 10, 2024
c4de93d
#10 [ui] 하단 카테고리 item xml
pump9918 Jan 10, 2024
c27de5a
#10 [ui] 행복 루틴 추가(목록) xml
pump9918 Jan 10, 2024
fa6b5d9
#10 [chore] 패키징 수정
pump9918 Jan 10, 2024
9745584
#10 [ui] 행복루틴 추가 카테고리 데이터 클래스
pump9918 Jan 10, 2024
b346cdf
#10 [ui] 행복루틴 추가 카테고리 뷰 바인딩
pump9918 Jan 10, 2024
51981c5
#10 [ui] 행복루틴 추가 카테고리 어댑터
pump9918 Jan 10, 2024
0e8eedd
#10 [ui] 카테고리 Chip 데이터 클래스
pump9918 Jan 10, 2024
ffd448a
#10 [ui] 카테고리 Chip 뷰 바인딩
pump9918 Jan 10, 2024
b880f82
#10 [ui] 카테고리 Chip 어댑터
pump9918 Jan 10, 2024
0cb86c6
#10 [ui] 리사이클러뷰 간격-아이템 데코레이션
pump9918 Jan 10, 2024
40f307d
#10 [feat] 행복 루틴 추가(목록) 액티비티
pump9918 Jan 10, 2024
57e9fdb
#10 [chore] 불필요 코드 정리
pump9918 Jan 11, 2024
f230357
#10 [chore] 행복 루틴 데이터 클래스 패키징
pump9918 Jan 11, 2024
35bb19a
#10 [ui] viewModel 칩버튼별 데이터 정리
pump9918 Jan 11, 2024
f139f92
#10 [ui] Content 리스트 어댑터
pump9918 Jan 11, 2024
4ec8e14
#10 [ui] Content 세부 리스트 어댑터
pump9918 Jan 11, 2024
1dc9f10
#10 [ui] 칩 클릭이벤트별 개별 리스트 전송
pump9918 Jan 11, 2024
258ed07
Merge branch 'develop' into feature/#10-ui-happy-add-view-list
pump9918 Jan 11, 2024
7723c76
#10 [chore] CI 오류 수정
pump9918 Jan 11, 2024
bba8d31
Merge remote-tracking branch 'origin/feature/#10-ui-happy-add-view-li…
pump9918 Jan 11, 2024
3a8bfe4
#10 [chore] CI 오류 공백 수정
pump9918 Jan 11, 2024
35410b4
#10 [chore] CI 오류 공백 수정
pump9918 Jan 11, 2024
b95a3e5
#10 [ui] 컨텐츠 리스트 클릭시 액티비티 연결
pump9918 Jan 11, 2024
b39c071
#10 [ui] chip 클릭 색상 변경
pump9918 Jan 11, 2024
61d2e5d
#10 [chore] xml 변수명 수정
pump9918 Jan 11, 2024
64df98d
#10 [ui] 이전 버튼 기능 활성화
pump9918 Jan 11, 2024
03a66fe
#10 [fix] chip 버튼 1개씩 선택 로직 추가
pump9918 Jan 11, 2024
5377e86
#10 [chore] merge conflict 파일 처리
pump9918 Jan 11, 2024
ea1c32e
#10 [chore] 함수 분리 및 null 처리
pump9918 Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@
<activity
android:name=".ui.storytelling.StoryTellingActivity"
android:exported="true"
android:screenOrientation="portrait" />

<activity
android:name=".ui.main.happy.addlist.HappyAddListActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".ui.setting.SettingActivity"
android:exported="false"
Expand Down
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,
)
10 changes: 10 additions & 0 deletions app/src/main/java/com/sopetit/softie/domain/entity/HappyContent.kt
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아요~

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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 var happyAddListChipContentAdapter: HappyAddListChipContentAdapter? = null
private var happyAddListContentAdapter: HappyAddListContentAdapter? = null

private val themeId = 0

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityHappyAddListBinding.inflate(layoutInflater)
setContentView(binding.root)

setChipAdapters()
setBackEnter()
setItemDeco()
setupAdapter(themeId)
}

private fun setChipAdapters() {
happyAddListChipContentAdapter = HappyAddListChipContentAdapter()
happyAddListContentAdapter = HappyAddListContentAdapter(::moveToDetail)
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setChipAdapter 처럼 함수 분리 해주세요!

}

private fun setBackEnter() {
binding.ivHappyAddBackArrow.setOnClickListener {
finish()
}
Comment on lines +46 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

역시나 함수 분리 부탁드립니다! setBackBtnClickListener처럼 (꼭 변수명 따라가지 않아도 됨) 부탁드립니다.

}

private fun setItemDeco() {
itemDeco = VerticalItemDecoration(applicationContext)
binding.rvHappyAddList.addItemDecoration(itemDeco)
chipDeco = HorizontalChipItemDecoration(applicationContext)
binding.rvHappyAddListChip.addItemDecoration(chipDeco)
}

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넘 멋져요

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나중에 enum class 한 번 써보세요! when을 사용할 때 else를 쓰지 않아도 됩니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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,64 @@
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.themeId == newItem.themeId },
onContentsTheSame = { oldItem, newItem -> oldItem == newItem }
)
) {
private val selectedPositions = HashSet<Int>()
private var onItemClickListener: ((HappyChip) -> Unit)? = null

inner class HappyAddListChipContentViewHolder(
private val binding: ItemHappyAddListChipBinding,
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(data: HappyChip) {
binding.itemHappyAddChipComponent.text = data.name
binding.itemHappyAddChipComponent.isChecked = isSelected(adapterPosition)

binding.root.setOnClickListener {
chipCurrentSelection(adapterPosition)
notifyDataSetChanged()
onItemClickListener?.let { it(data) }
}
}
}

private fun isSelected(position: Int) = selectedPositions.contains(position)

private fun chipCurrentSelection(position: Int) {
if (isSelected(position)) {
selectedPositions.remove(position)
} else {
selectedPositions.clear()
selectedPositions.add(position)
}
}

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감격입니다!!!! 이제 호연님도 리사이클러뷰 마스터

Copy link
Member

Choose a reason for hiding this comment

The 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])
}
}
Loading