Skip to content

Commit

Permalink
#176 [ui] 뷰페이저 -> 리사이클러뷰 변환 및 함수명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
pump9918 committed Jun 24, 2024
1 parent 8ea2866 commit 47a8863
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 233 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</activity>

<activity
android:name=".ui.addroutine.list.AddListActivity"
android:name=".ui.addroutine.list.AddRoutineActivity"
android:exported="false"
android:screenOrientation="portrait" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,44 @@ package com.sopetit.softie.ui.addroutine.list
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ActivityAddListBinding
import com.sopetit.softie.databinding.ActivityAddRoutineListBinding
import com.sopetit.softie.util.HorizontalItemDecoration
import com.sopetit.softie.util.VerticalItemDecoration
import com.sopetit.softie.util.binding.BindingActivity
import com.sopetit.softie.util.setSingleOnClickListener
import com.sopetit.softie.util.setStatusBarColorFromResource
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AddListActivity : BindingActivity<ActivityAddListBinding>(R.layout.activity_add_list) {
private lateinit var viewPager: ViewPager2
private val makerCardPagerAdapter = MakerCardPagerAdapter()
private val viewModel by viewModels<AddListViewModel>()
class AddRoutineActivity :
BindingActivity<ActivityAddRoutineListBinding>(R.layout.activity_add_routine_list) {
private val makerCardPagerAdapter = MakerCardAdapter()
private val viewModel by viewModels<AddRoutineViewModel>()
private var routineThemeListAdapter: RoutineThemeListAdapter? = null
private lateinit var itemDeco: RecyclerView.ItemDecoration

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.viewModel = viewModel
viewPager = binding.vpAddListMakerCard
setStatusBarColorFromResource(R.color.background)

startMakerHelpModal()
setBackEnter()
setInitBinding()
setHappyDetailCardPagerAdapter()
setCurrentCard()
setAddRoutineListCardPagerAdapter()
setRoutineThemeListAdapter()
setItemDeco()
setupObservers()
}

private fun startMakerHelpModal() {
binding.ivAddListMakerHelp.setSingleOnClickListener {
binding.ivAddRoutineListMakerHelp.setSingleOnClickListener {
MakerHelpDialogFragment().show(supportFragmentManager, "MakerHelpDialog")
}
}

private fun setBackEnter() {
binding.ivAddListBackArrow.setSingleOnClickListener {
binding.ivAddRoutineListBackArrow.setSingleOnClickListener {
finish()
}
}
Expand All @@ -53,28 +50,12 @@ class AddListActivity : BindingActivity<ActivityAddListBinding>(R.layout.activit
viewModel.getRoutineTheme()
}

private fun setHappyDetailCardPagerAdapter() {
private fun setAddRoutineListCardPagerAdapter() {
with(binding) {
vpAddListMakerCard.adapter = makerCardPagerAdapter
rvAddRoutineListMakerCard.adapter = makerCardPagerAdapter
}
}

private fun setCurrentCard() {
viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
val currentMakerId = getCurrentSelectedMakerId()
viewModel.setMakerId(currentMakerId)
}
})
}

private fun getCurrentSelectedMakerId(): Int {
val currentItem = binding.vpAddListMakerCard.currentItem
val itemId = makerCardPagerAdapter.getItemId(currentItem)
return itemId.toInt()
}

private fun setRoutineThemeListAdapter() {
with(binding) {
routineThemeListAdapter = RoutineThemeListAdapter()
Expand All @@ -83,8 +64,18 @@ class AddListActivity : BindingActivity<ActivityAddListBinding>(R.layout.activit
}

private fun setItemDeco() {
itemDeco = VerticalItemDecoration(applicationContext)
binding.rvAddList.addItemDecoration(itemDeco)
val horizontalDecoration = HorizontalItemDecoration(
context = this,
firstItemMargin = R.dimen.maker_recycler_view_first_margin,
itemMargin = R.dimen.maker_recycler_view_margin
)
val verticalDecoration = VerticalItemDecoration(
context = this,
firstItemMargin = R.dimen.add_routine_recycler_view_first_margin,
itemMargin = R.dimen.add_routine_recycler_view_margin
)
binding.rvAddRoutineListMakerCard.addItemDecoration(horizontalDecoration)
binding.rvAddList.addItemDecoration(verticalDecoration)
}

private fun setupObservers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class AddListViewModel @Inject constructor(
class AddRoutineViewModel @Inject constructor(
private val getMakerCardUseCase: GetMakerCardUseCase,
private val getRoutineThemeListUseCase: GetRoutineThemeListUseCase
) : ViewModel() {
Expand All @@ -24,12 +24,6 @@ class AddListViewModel @Inject constructor(
private val _addRoutineThemeListResponse = MutableLiveData<RoutineTheme>()
val addRoutineThemeListResponse: LiveData<RoutineTheme> get() = _addRoutineThemeListResponse

private val _myMakerId: MutableLiveData<Int> = MutableLiveData()

fun setMakerId(makerId: Int) {
_myMakerId.value = makerId
}

fun getMakerCard() {
viewModelScope.launch {
getMakerCardUseCase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,40 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ItemAddListMakerCardBinding
import com.sopetit.softie.databinding.ItemAddRoutineListMakerCardBinding
import com.sopetit.softie.domain.entity.MakerCard

class MakerCardPagerAdapter : RecyclerView.Adapter<MakerCardPagerAdapter.MakerPagerViewHolder>() {
class MakerCardAdapter : RecyclerView.Adapter<MakerCardAdapter.MakerPagerViewHolder>() {

private var dataList = listOf<MakerCard>()

class MakerPagerViewHolder(private val binding: ItemAddListMakerCardBinding) :
class MakerPagerViewHolder(private val binding: ItemAddRoutineListMakerCardBinding) :
RecyclerView.ViewHolder(binding.root) {

private val hashtagAdapter = MakerCardPagerHashtagAdapter(emptyList())
private val hashtagAdapter = MakerCardHashtagAdapter(emptyList())

init {
binding.rvAddListMakerHashtagChip.adapter = hashtagAdapter
binding.rvAddRoutineListMakerHashtag.adapter = hashtagAdapter
}

fun onBind(data: MakerCard) {
with(binding) {
ivAddListMakerCardImage.load(data.artistImageUrl) {
ivAddRoutineListMakerCardImage.load(data.artistImageUrl) {
placeholder(R.drawable.ic_happy_card_base)
error(R.drawable.ic_happy_card_base)
}
tvAddListMakerCardDetailSubtitle.text = data.subTitle
tvAddListMakerCardDetailTitle.text = data.title
tvAddRoutineListMakerCardDetailSubtitle.text = data.subTitle
tvAddRoutineListMakerCardDetailTitle.text = data.title

(binding.rvAddListMakerHashtagChip.adapter as MakerCardPagerHashtagAdapter)?.submitList(
(binding.rvAddRoutineListMakerHashtag.adapter as MakerCardHashtagAdapter)?.submitList(
data.hashtag
)
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MakerPagerViewHolder {
val binding = ItemAddListMakerCardBinding.inflate(
val binding = ItemAddRoutineListMakerCardBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package com.sopetit.softie.ui.addroutine.list
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.sopetit.softie.databinding.ItemAddListMakerHashtagChipBinding
import com.sopetit.softie.databinding.ItemAddRoutineListMakerHashtagBinding
import com.sopetit.softie.domain.entity.MakerCard

class MakerCardPagerHashtagAdapter(private var hashtags: List<MakerCard.Hashtag>) :
RecyclerView.Adapter<MakerCardPagerHashtagAdapter.HashtagViewHolder>() {
class MakerCardHashtagAdapter(private var hashtags: List<MakerCard.Hashtag>) :
RecyclerView.Adapter<MakerCardHashtagAdapter.HashtagViewHolder>() {

class HashtagViewHolder(private val binding: ItemAddListMakerHashtagChipBinding) :
class HashtagViewHolder(private val binding: ItemAddRoutineListMakerHashtagBinding) :
RecyclerView.ViewHolder(binding.root) {

fun onBind(hashtag: MakerCard.Hashtag) {
with(binding) {
tvAddListItemContent.text = hashtag.content
tvAddRoutineListMakerHashtagContent.text = hashtag.content
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HashtagViewHolder {
val binding = ItemAddListMakerHashtagChipBinding.inflate(
val binding = ItemAddRoutineListMakerHashtagBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
Expand All @@ -36,6 +36,5 @@ class MakerCardPagerHashtagAdapter(private var hashtags: List<MakerCard.Hashtag>

fun submitList(newHashtags: List<MakerCard.Hashtag>) {
hashtags = newHashtags
notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ItemAddListBinding
import com.sopetit.softie.databinding.ItemAddRoutineListBinding
import com.sopetit.softie.domain.entity.RoutineTheme
import com.sopetit.softie.util.ItemDiffCallback

Expand All @@ -18,23 +18,25 @@ class RoutineThemeListAdapter :
)
) {

inner class RoutineThemeListViewHolder(private val binding: ItemAddListBinding) :
inner class RoutineThemeListViewHolder(private val binding: ItemAddRoutineListBinding) :
RecyclerView.ViewHolder(binding.root) {

fun onBind(data: RoutineTheme.Themes) {
with(binding) {
when (data.themeId) {
1 -> ivAddListItemIcon.load(R.drawable.ic_theme1_pink)
2 -> ivAddListItemIcon.load(R.drawable.ic_theme2_red)
3 -> ivAddListItemIcon.load(R.drawable.ic_theme3_orange)
4 -> ivAddListItemIcon.load(R.drawable.ic_theme4_yellow)
5 -> ivAddListItemIcon.load(R.drawable.ic_theme5_green)
6 -> ivAddListItemIcon.load(R.drawable.ic_theme6_sky)
7 -> ivAddListItemIcon.load(R.drawable.ic_theme7_blue)
else -> ivAddListItemIcon.load(R.drawable.ic_bear_base)
val iconItem = when (data.themeId) {
1 -> R.drawable.ic_theme1_pink
2 -> R.drawable.ic_theme2_red
3 -> R.drawable.ic_theme3_orange
4 -> R.drawable.ic_theme4_yellow
5 -> R.drawable.ic_theme5_green
6 -> R.drawable.ic_theme6_sky
7 -> R.drawable.ic_theme7_blue
else -> R.drawable.ic_bear_base
}
tvAddListItemContent.text = data.modifier
tvAddListItemTitle.text = data.name

ivAddRoutineListItemIcon.load(iconItem)
tvAddRoutineListItemModifier.text = data.modifier
tvAddRoutineListItemName.text = data.name
}
}
}
Expand All @@ -43,7 +45,7 @@ class RoutineThemeListAdapter :
parent: ViewGroup,
viewType: Int
): RoutineThemeListViewHolder {
val binding = ItemAddListBinding.inflate(
val binding = ItemAddRoutineListBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.fragment.app.viewModels
import coil.load
import com.sopetit.softie.R
import com.sopetit.softie.databinding.FragmentHappyMyRoutineBinding
import com.sopetit.softie.ui.addroutine.list.AddListActivity
import com.sopetit.softie.ui.addroutine.list.AddRoutineActivity
import com.sopetit.softie.ui.happyroutine.complete.HappyRoutineCompleteActivity
import com.sopetit.softie.ui.happyroutine.delete.HappyDeleteFragment
import com.sopetit.softie.util.CustomSnackbar
Expand Down Expand Up @@ -71,7 +71,7 @@ class HappyMyRoutineFragment :

private fun startHappyAddListActivity() {
binding.ivHappyRoutineEmptyCard.setOnClickListener {
val intent = Intent(requireContext(), AddListActivity::class.java)
val intent = Intent(requireContext(), AddRoutineActivity::class.java)
resultLauncher.launch(intent)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class HappyDetailCardPagerAdapter() :
data.timeTaken
tvHappyRoutineAddCardDetailPlaceBack.text = data.place

clHappyRoutineAddCard.setOnClickListener {
setCardFlip(clHappyRoutineAddCard, clHappyRoutineAddCardBack)
clHappyRoutineAddCardBack.setOnClickListener {
setCardFlip(clHappyRoutineAddCardBack, clHappyRoutineAddCardBack)
}
clHappyRoutineAddCardBack.setOnClickListener {
setCardFlip(clHappyRoutineAddCardBack, clHappyRoutineAddCard)
setCardFlip(clHappyRoutineAddCardBack, clHappyRoutineAddCardBack)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ActivityHappyAddListBinding
import com.sopetit.softie.ui.happyroutine.detail.HappyDetailActivity
import com.sopetit.softie.util.HorizontalChipItemDecoration
import com.sopetit.softie.util.HorizontalItemDecoration
import com.sopetit.softie.util.VerticalItemDecoration
import com.sopetit.softie.util.binding.BindingActivity
import com.sopetit.softie.util.setSingleOnClickListener
Expand All @@ -20,8 +20,6 @@ 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
Expand All @@ -44,7 +42,6 @@ class HappyAddListActivity :

setChipAdapters()
setBackEnter()
setItemDeco()
setHappyAddListAdapter()
}

Expand All @@ -59,13 +56,6 @@ class HappyAddListActivity :
}
}

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

private fun setHappyAddListAdapter() {
with(binding) {
rvHappyAddListChip.adapter = happyAddListChipContentAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import android.content.Context
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.sopetit.softie.R

class HorizontalChipItemDecoration(val context: Context) : RecyclerView.ItemDecoration() {
class HorizontalItemDecoration(
val context: Context,
val firstItemMargin: Int,
val itemMargin: Int
) : RecyclerView.ItemDecoration() {

override fun getItemOffsets(
outRect: Rect,
Expand All @@ -18,10 +21,10 @@ class HorizontalChipItemDecoration(val context: Context) : RecyclerView.ItemDeco
val position = parent.getChildAdapterPosition(view)

if (position == 0) {
outRect.left = context.resources.getDimensionPixelSize(R.dimen.chip_first_margin)
outRect.left = context.resources.getDimensionPixelSize(firstItemMargin)
} else {
outRect.left = 0
}
outRect.right = context.resources.getDimensionPixelSize(R.dimen.chip_margin)
outRect.right = context.resources.getDimensionPixelSize(itemMargin)
}
}
Loading

0 comments on commit 47a8863

Please sign in to comment.