-
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 all 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 |
---|---|---|
@@ -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, | ||
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,127 @@ | ||
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 { | ||
with(binding) { | ||
tvHappyAddDetailTitle.text = happyCard.name | ||
ivHappyAddDetailIcon.setImageResource(happyCard.iconImageUrl) | ||
tvHappyAddDetailSubtitle.text = happyCard.title | ||
tvHappyAddDetailTitle.setTextColor(Color.parseColor(happyCard.nameColor)) | ||
} | ||
} | ||
|
||
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() | ||
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 == newItem } | ||
) | ||
) { | ||
|
||
class HappyPagerViewHolder( | ||
private val binding: ItemHappyAddDetailCardBinding | ||
) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun onBind(data: HappyCard.Routines) { | ||
with(binding) { | ||
ivHappyRoutineAddCard.setImageResource(data.cardImageUrl) | ||
tvHappyRoutineAddCardDetailTitle.text = data.detailTitle | ||
tvHappyRoutineAddCardDetailTitleBack.text = data.detailTitle | ||
tvHappyRoutineAddCardDetailContentBack.text = data.detailContent | ||
tvHappyRoutineAddCardDetailTimeBack.text = data.detailTime | ||
tvHappyRoutineAddCardDetailPlaceBack.text = data.detailPlace | ||
|
||
clHappyRoutineAddCard.setOnClickListener { | ||
setCardFlip(clHappyRoutineAddCard, clHappyRoutineAddCardBack) | ||
} | ||
clHappyRoutineAddCardBack.setOnClickListener { | ||
setCardFlip(clHappyRoutineAddCardBack, clHappyRoutineAddCard) | ||
} | ||
} | ||
} | ||
|
||
private fun setCardFlip(viewFront: View, viewToBack: View) { | ||
val isVisible = viewFront.visibility == View.VISIBLE | ||
if (isVisible) { | ||
viewFront.visibility = View.INVISIBLE | ||
viewToBack.visibility = View.VISIBLE | ||
} else { | ||
viewFront.visibility = View.VISIBLE | ||
viewToBack.visibility = View.INVISIBLE | ||
} | ||
} | ||
} | ||
|
||
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.
꼼꼼하네요