-
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
#39 [ui] 행복루틴 추가하기 상세뷰 #43
Changes from 16 commits
bd7b6ce
5541606
b4a1f9a
e33dcc2
73111ed
93da852
8664ee5
f70c87c
afbfacd
54a8720
d593d89
95ec437
51eb22e
bc44ccf
6389ade
08d2a6d
c24fcf6
99683b3
fb68b36
2a56eb5
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 |
---|---|---|
|
@@ -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" | ||
android:screenOrientation="portrait" /> | ||
|
||
<activity | ||
android:name=".ui.happyroutine.adddetail.HappyDetailActivity" | ||
android:exported="true" | ||
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. false로 바꿔서 올려주세요! 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. ㅇㅊㅊ |
||
android:screenOrientation="portrait" /> | ||
|
||
<activity | ||
android:name=".ui.setting.SettingActivity" | ||
android:exported="false" | ||
android:screenOrientation="portrait" /> | ||
|
||
<activity | ||
android:name=".ui.main.LoginActivity" | ||
android:exported="false" | ||
|
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, | ||
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. 꼼꼼하네요 |
||
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 |
---|---|---|
@@ -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)) | ||
} | ||
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. with(binding)으로 묶어주세요 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. 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() { | ||
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. moveToProgress처럼 바꿔주세요! |
||
Intent(this, MainActivity::class.java).apply { | ||
startActivity(this) | ||
} | ||
} | ||
|
||
private fun setupAdapter(categoryId: Int) { | ||
with(binding) { | ||
happyRoutineAddCardPagerAdapter = | ||
HappyDetailCardPagerAdapter() // categoryId를 전달합니다. | ||
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. 주석 삭제 부탁드립니다 |
||
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 | ||
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. 오오 감사합니다! 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. 다른 곳에서 쓰인 companion object중에 3이면서 코드 상에서 동일한 의미를 가진 상수가 있다면 대체 부탁드립니다! 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. 민회가 작성한 코드가 있다 해서 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 } | ||||||||||||||||||||||
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. onContentsTheSame은
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. 앗차차~ 거긴 제가 잘못했네요~ |
||||||||||||||||||||||
) | ||||||||||||||||||||||
) { | ||||||||||||||||||||||
|
||||||||||||||||||||||
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 | ||||||||||||||||||||||
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. 다음 번에는 item.xml에서 data binding 써보세요! activity, fragment에서 쓰는 것처럼 코드가 간결해집니다.
|
||||||||||||||||||||||
binding.clHappyRoutineAddCard.setOnClickListener { | ||||||||||||||||||||||
val isVisible = binding.clHappyRoutineAddCard.visibility == View.VISIBLE | ||||||||||||||||||||||
if (isVisible) { | ||||||||||||||||||||||
binding.clHappyRoutineAddCard.visibility = View.INVISIBLE | ||||||||||||||||||||||
binding.clHappyRoutineAddCardBack.visibility = View.VISIBLE | ||||||||||||||||||||||
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. 오 그게 더 깔끔하겠네요 함수화하겠습니다! |
||||||||||||||||||||||
} 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 | ||||||||||||||||||||||
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.
Suggested change
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): 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]) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
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.
false로 바꿔서 올려주세요!