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

#39 [ui] 행복루틴 추가하기 상세뷰 #43

Merged
merged 20 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bd7b6ce
#39 [chore] happyroutine 패키지 재배치
pump9918 Jan 11, 2024
5541606
#39 [ui] 행복 루틴 추가(상세) drawable 추가
pump9918 Jan 12, 2024
b4a1f9a
#39 [ui] 행복 루틴 추가(상세) 뷰 작업
pump9918 Jan 12, 2024
e33dcc2
#39 [ui] 카드 및 상세페이지 데이터 클래스 생성
pump9918 Jan 12, 2024
73111ed
#39 [ui] 행복 루틴 상세 뷰 로직
pump9918 Jan 12, 2024
93da852
#39 [chore] 행복 루틴 리스트 뷰와 연결
pump9918 Jan 12, 2024
8664ee5
#39 [ui] 카드 뒷편 뷰 xml
pump9918 Jan 12, 2024
f70c87c
#39 [chore] 기기대응 dimen 파일
pump9918 Jan 12, 2024
afbfacd
#39 [fix] 카드 앞 뒷면 통합, 길이 조정
pump9918 Jan 14, 2024
54a8720
#39 [fix] 카드 글자 수 반응 xml 수정
pump9918 Jan 14, 2024
d593d89
#39 [feat] 카테고리 별 데이터, 카드 연결
pump9918 Jan 14, 2024
95ec437
#39 [fix] 세팅 정렬
pump9918 Jan 14, 2024
51eb22e
#39 [chore] CI 정렬 수정
pump9918 Jan 14, 2024
bc44ccf
#39 [chore] CI 정렬 재수정
pump9918 Jan 14, 2024
6389ade
#39 [chore] CI 정렬 다시 수정
pump9918 Jan 14, 2024
08d2a6d
Merge remote-tracking branch 'origin/develop' into feature/#39-ui-hap…
pump9918 Jan 14, 2024
c24fcf6
#39 [chore] 서버 관계 없는 string 제거
pump9918 Jan 14, 2024
99683b3
#39 [chore] 데이터 binding 함수화
pump9918 Jan 14, 2024
fb68b36
#39 [chore] 매니패스트 정상화
pump9918 Jan 14, 2024
2a56eb5
Merge remote-tracking branch 'origin/develop' into feature/#39-ui-hap…
pump9918 Jan 14, 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
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ dependencies {
// Splash Screen
implementation("androidx.core:core-splashscreen:1.0.1")

// indicator
implementation("com.tbuonomo:dotsindicator:5.0")

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@
</activity>

<activity
android:name=".ui.main.happy.addlist.HappyAddListActivity"
android:exported="false"
android:name=".ui.happyroutine.addlist.HappyAddListActivity"
android:exported="true"
Copy link
Contributor

Choose a reason for hiding this comment

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

false로 바꿔서 올려주세요!

android:screenOrientation="portrait" />

<activity
android:name=".ui.happyroutine.adddetail.HappyDetailActivity"
android:exported="true"
Copy link
Contributor

Choose a reason for hiding this comment

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

false로 바꿔서 올려주세요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ㅇㅊㅊ

android:screenOrientation="portrait" />

<activity
android:name=".ui.setting.SettingActivity"
android:exported="false"
android:screenOrientation="portrait" />

<activity
android:name=".ui.main.LoginActivity"
android:exported="false"
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/sopetit/softie/domain/entity/HappyCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sopetit.softie.domain.entity

import androidx.annotation.DrawableRes

data class HappyCard(
val categoryId: Int,
val name: String,
val nameColor: String,
val title: String,
@DrawableRes val iconImageUrl: Int,
val routines: List<Routines>
) {
data class Routines(
val routineId: Int,
@DrawableRes val cardImageUrl: Int,
Copy link
Contributor

Choose a reason for hiding this comment

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

꼼꼼하네요

val content: String,
val detailTitle: String,
val detailContent: String,
val detailTime: String,
val detailPlace: String
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopetit.softie.ui.main.happy
package com.sopetit.softie.ui.happyroutine

import android.os.Bundle
import android.view.View
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.sopetit.softie.ui.happyroutine.adddetail

import android.content.Intent
import android.graphics.Color
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.CompositePageTransformer
import androidx.viewpager2.widget.ViewPager2
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ActivityHappyAddDetailBinding
import com.sopetit.softie.ui.happyroutine.addlist.HappyAddListActivity.Companion.ID
import com.sopetit.softie.ui.main.MainActivity
import com.sopetit.softie.util.binding.BindingActivity

class HappyDetailActivity :
BindingActivity<ActivityHappyAddDetailBinding>(R.layout.activity_happy_add_detail) {
private lateinit var viewPager: ViewPager2
private lateinit var happyRoutineAddCardPagerAdapter: HappyDetailCardPagerAdapter

private val viewModel by viewModels<HappyDetailCardViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewPager = binding.vpHappyAddDetailCard

val categoryId = intent.getIntExtra(ID, -1)
val viewModel = ViewModelProvider(this).get(HappyDetailCardViewModel::class.java)
val happyCard = viewModel.mockHappyCardList.value?.get(categoryId - 1)

happyCard?.let {
binding.tvHappyAddDetailTitle.text = happyCard.name
binding.ivHappyAddDetailIcon.setImageResource(happyCard.iconImageUrl)
binding.tvHappyAddDetailSubtitle.text = happyCard.title
binding.tvHappyAddDetailTitle.setTextColor(Color.parseColor(happyCard.nameColor))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

with(binding)으로 묶어주세요

Copy link
Contributor

Choose a reason for hiding this comment

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

onCreate 안이 아닌 따로 함수로 빼주세요


setBackEnter()
setSnackbarEnter()
setupAdapter(categoryId)
setIndicator()
initViewPager()
initPagerDiv(0, 90)
}

private fun setBackEnter() {
binding.ivHappyAddDetailBack.setOnClickListener {
finish()
}
}

private fun setSnackbarEnter() {
binding.btnHappyDetailAdd.setOnClickListener {
moveToIng()
}
}

private fun moveToIng() {
Copy link
Contributor

Choose a reason for hiding this comment

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

moveToProgress처럼 바꿔주세요!

Intent(this, MainActivity::class.java).apply {
startActivity(this)
}
}

private fun setupAdapter(categoryId: Int) {
with(binding) {
happyRoutineAddCardPagerAdapter =
HappyDetailCardPagerAdapter() // categoryId를 전달합니다.
Copy link
Contributor

Choose a reason for hiding this comment

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

주석 삭제 부탁드립니다

vpHappyAddDetailCard.adapter = happyRoutineAddCardPagerAdapter
}
happyRoutineAddCardPagerAdapter.submitList(
viewModel.getHappyCardListForId(categoryId).get(0).routines
)
}

private fun setIndicator() {
binding.diHappyAddDetailIndicator.attachTo(binding.vpHappyAddDetailCard)
}

private fun initViewPager() {
viewPager.adapter = happyRoutineAddCardPagerAdapter

val dp = resources.getDimensionPixelSize(R.dimen.view_margin)
val d = resources.displayMetrics.density
val margin = (dp * d).toInt()

with(binding.vpHappyAddDetailCard) {
clipChildren = false
clipToPadding = false
offscreenPageLimit = 3
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.

오오 감사합니다!

Copy link
Contributor

Choose a reason for hiding this comment

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

다른 곳에서 쓰인 companion object중에 3이면서 코드 상에서 동일한 의미를 가진 상수가 있다면 대체 부탁드립니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

민회가 작성한 코드가 있다 해서 merge 후 대체하겠습니다!

setPadding(margin, 0, margin, 0)
}
val compositePageTransformer = CompositePageTransformer()
binding.vpHappyAddDetailCard.setPageTransformer(compositePageTransformer)
}

private fun initPagerDiv(previewWidth: Int, itemMargin: Int) {
val decoMargin = previewWidth + itemMargin
val pageTransX = decoMargin + previewWidth
val decoration = PageDecoration(decoMargin)

binding.vpHappyAddDetailCard.also {
it.offscreenPageLimit = 1
it.addItemDecoration(decoration)
it.setPageTransformer { page, position ->
page.translationX = position * -pageTransX
}
}
}

private class PageDecoration(private val margin: Int) : RecyclerView.ItemDecoration() {

override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
outRect.left = margin
outRect.right = margin
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.sopetit.softie.ui.happyroutine.adddetail

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.sopetit.softie.databinding.ItemHappyAddDetailCardBinding
import com.sopetit.softie.domain.entity.HappyCard
import com.sopetit.softie.util.ItemDiffCallback

class HappyDetailCardPagerAdapter() :
ListAdapter<HappyCard.Routines, HappyDetailCardPagerAdapter.HappyPagerViewHolder>(
ItemDiffCallback<HappyCard.Routines>(
onItemsTheSame = { oldItem, newItem -> oldItem.routineId == newItem.routineId },
onContentsTheSame = { oldItem, newItem -> oldItem.routineId == newItem.routineId }
Copy link
Member

Choose a reason for hiding this comment

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

onContentsTheSame은 { oldItem, newItem -> oldItem == newItem }으로 바꿔주세요!

onItemsTheSame = { oldItem, newItem -> oldItem.routineId == newItem.routineId },
onContentsTheSame = { oldItem, newItem -> oldItem == newItem }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

좋은 지적 감사합니다~~

Copy link
Contributor

Choose a reason for hiding this comment

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

앗차차~ 거긴 제가 잘못했네요~

)
) {

class HappyPagerViewHolder(
private val binding: ItemHappyAddDetailCardBinding
) :
RecyclerView.ViewHolder(binding.root) {

fun onBind(data: HappyCard.Routines) {
binding.ivHappyRoutineAddCard.setImageResource(data.cardImageUrl)
binding.tvHappyRoutineAddCardDetailTitle.text = data.detailTitle
binding.tvHappyRoutineAddCardDetailTitleBack.text = data.detailTitle
binding.tvHappyRoutineAddCardDetailContentBack.text = data.detailContent
binding.tvHappyRoutineAddCardDetailTimeBack.text = data.detailTime
binding.tvHappyRoutineAddCardDetailPlaceBack.text = data.detailPlace
Copy link
Contributor

Choose a reason for hiding this comment

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

다음 번에는 item.xml에서 data binding 써보세요! activity, fragment에서 쓰는 것처럼 코드가 간결해집니다.

  • with(binding) 써주세요

binding.clHappyRoutineAddCard.setOnClickListener {
val isVisible = binding.clHappyRoutineAddCard.visibility == View.VISIBLE
if (isVisible) {
binding.clHappyRoutineAddCard.visibility = View.INVISIBLE
binding.clHappyRoutineAddCardBack.visibility = View.VISIBLE
Copy link
Contributor

Choose a reason for hiding this comment

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

이 로직은 뒷면이 보이는 로직이고
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.

오 그게 더 깔끔하겠네요 함수화하겠습니다!

} else {
binding.clHappyRoutineAddCard.visibility = View.VISIBLE
binding.clHappyRoutineAddCardBack.visibility = View.INVISIBLE
}
}
binding.clHappyRoutineAddCardBack.setOnClickListener {
val isVisible = binding.clHappyRoutineAddCardBack.visibility == View.VISIBLE
if (isVisible) {
binding.clHappyRoutineAddCardBack.visibility = View.INVISIBLE
binding.clHappyRoutineAddCard.visibility = View.VISIBLE
} else {
binding.clHappyRoutineAddCardBack.visibility = View.VISIBLE
binding.clHappyRoutineAddCard.visibility = View.INVISIBLE
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (isVisible) {
binding.clHappyRoutineAddCardBack.visibility = View.INVISIBLE
binding.clHappyRoutineAddCard.visibility = View.VISIBLE
} else {
binding.clHappyRoutineAddCardBack.visibility = View.VISIBLE
binding.clHappyRoutineAddCard.visibility = View.INVISIBLE
if (isVisible) {
showCardFront()
} else {
showCardBack()

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): HappyPagerViewHolder {
val binding = ItemHappyAddDetailCardBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
return HappyPagerViewHolder(binding)
}

override fun onBindViewHolder(holder: HappyPagerViewHolder, position: Int) {
holder.onBind(currentList[position])
}
}
Loading