-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#8 [ui] Daily Routine - 추가하기
- Loading branch information
Showing
24 changed files
with
1,288 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopetit/softie/domain/entity/DailyCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class DailyCard( | ||
val backgroundImageUrl: String, | ||
val routineId: Int, | ||
val content: String | ||
) |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/sopetit/softie/domain/entity/DailyRoutineAdd.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class DailyRoutineAdd( | ||
val themeId: Int, | ||
val dailyRoutineCardList: List<DailyCard> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...c/main/java/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package com.sopetit.softie.ui.dailyroutine.dailyroutineadd | ||
|
||
import android.graphics.Rect | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.activity.viewModels | ||
import androidx.recyclerview.widget.RecyclerView | ||
import androidx.viewpager2.widget.CompositePageTransformer | ||
import androidx.viewpager2.widget.MarginPageTransformer | ||
import androidx.viewpager2.widget.ViewPager2 | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.ActivityDailyRoutineAddBinding | ||
import com.sopetit.softie.domain.entity.Theme | ||
import com.sopetit.softie.util.binding.BindingActivity | ||
|
||
class DailyRoutineAddActivity : | ||
BindingActivity<ActivityDailyRoutineAddBinding>(R.layout.activity_daily_routine_add) { | ||
private lateinit var viewPager: ViewPager2 | ||
private lateinit var dailyRoutineAddCardPagerAdapter: DailyRoutineAddCardPagerAdapter | ||
private lateinit var dailyRoutineAddThemeAdapter: DailyRoutineAddThemeAdapter | ||
|
||
private val dailyRoutineAddViewModel by viewModels<DailyRoutineAddViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
viewPager = binding.vpDailyRoutineAddCard | ||
binding.viewModel = dailyRoutineAddViewModel | ||
|
||
setupAdapter() | ||
setViewPager() | ||
setupList() | ||
setIndicator() | ||
setItemDiv() | ||
initPagerDiv(0, 90) | ||
addClickListener() | ||
} | ||
|
||
private fun addClickListener() { | ||
addRoutine() | ||
backToDailyRoutine() | ||
} | ||
|
||
private fun setupAdapter() { | ||
with(binding) { | ||
dailyRoutineAddCardPagerAdapter = DailyRoutineAddCardPagerAdapter() | ||
vpDailyRoutineAddCard.adapter = dailyRoutineAddCardPagerAdapter | ||
dailyRoutineAddThemeAdapter = DailyRoutineAddThemeAdapter().apply { | ||
setOnItemClickListener(object : DailyRoutineAddThemeAdapter.OnItemClickListener { | ||
override fun onItemClick(item: Theme, position: Int) { | ||
setRoutineList(item.themeId) | ||
} | ||
}) | ||
} | ||
rvDailyRoutineAddTheme.adapter = dailyRoutineAddThemeAdapter | ||
} | ||
} | ||
|
||
private fun setupList() { | ||
dailyRoutineAddViewModel.mockThemeList.observe(this) { | ||
dailyRoutineAddCardPagerAdapter.submitList(dailyRoutineAddViewModel.startNewDayCardList.value) | ||
dailyRoutineAddThemeAdapter.submitList(dailyRoutineAddViewModel.mockThemeList.value) | ||
} | ||
} | ||
|
||
private fun setRoutineList(themeId: Int) { | ||
dailyRoutineAddCardPagerAdapter.submitList( | ||
dailyRoutineAddViewModel.getDailyCardListForId(themeId)[0].dailyRoutineCardList | ||
) | ||
} | ||
|
||
private fun initPagerDiv(previewWidth: Int, itemMargin: Int) { | ||
val decoMargin = previewWidth + itemMargin | ||
val pageTransX = decoMargin + previewWidth | ||
val decoration = PageDecoration(decoMargin) | ||
|
||
binding.vpDailyRoutineAddCard.also { | ||
it.offscreenPageLimit = VIEW_PAGE.toInt() | ||
it.addItemDecoration(decoration) | ||
it.setPageTransformer { page, position -> | ||
page.translationX = position * -pageTransX | ||
} | ||
} | ||
} | ||
|
||
private fun setViewPager() { | ||
with(binding.vpDailyRoutineAddCard) { | ||
adapter = dailyRoutineAddCardPagerAdapter | ||
offscreenPageLimit = VIEW_PAGE.toInt() | ||
|
||
val dpValue = PADDING_PAGE | ||
val margin = (dpValue * resources.displayMetrics.density).toInt() | ||
setPadding(margin, PADDING_CARD, margin, PADDING_CARD) | ||
|
||
setPageTransformer( | ||
CompositePageTransformer().apply { | ||
addTransformer( | ||
MarginPageTransformer( | ||
resources.getDimensionPixelOffset(R.dimen.viewpager_margin) | ||
) | ||
) | ||
} | ||
) | ||
} | ||
} | ||
|
||
private fun setIndicator() { | ||
binding.diDailyRoutineAddIndicator.attachTo(binding.vpDailyRoutineAddCard) | ||
} | ||
|
||
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 | ||
} | ||
} | ||
|
||
class HorizontalItemDecorator(private val divHeight: Int) : RecyclerView.ItemDecoration() { | ||
@Override | ||
override fun getItemOffsets( | ||
outRect: Rect, | ||
view: View, | ||
parent: RecyclerView, | ||
state: RecyclerView.State | ||
) { | ||
super.getItemOffsets(outRect, view, parent, state) | ||
outRect.left = divHeight | ||
outRect.right = divHeight | ||
} | ||
} | ||
|
||
private fun setItemDiv() { | ||
binding.rvDailyRoutineAddTheme.addItemDecoration(HorizontalItemDecorator(16)) | ||
} | ||
|
||
private fun addRoutine() { | ||
binding.btnDailyRoutineAdd.setOnClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
private fun backToDailyRoutine() { | ||
binding.ivDailyRoutineAddBack.setOnClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
companion object { | ||
const val VIEW_PAGE = 3 | ||
const val PADDING_PAGE = 40 | ||
const val PADDING_CARD = 0 | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ava/com/sopetit/softie/ui/dailyroutine/dailyroutineadd/DailyRoutineAddCardPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.sopetit.softie.ui.dailyroutine.dailyroutineadd | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import coil.load | ||
import com.sopetit.softie.databinding.ItemDailyRoutineAddCardBinding | ||
import com.sopetit.softie.domain.entity.DailyCard | ||
import com.sopetit.softie.util.ItemDiffCallback | ||
import timber.log.Timber | ||
|
||
class DailyRoutineAddCardPagerAdapter : | ||
ListAdapter<DailyCard, DailyRoutineAddCardPagerAdapter.DailyPagerViewHolder>( | ||
ItemDiffCallback<DailyCard>( | ||
onItemsTheSame = { oldItem, newItem -> oldItem.routineId == newItem.routineId }, | ||
onContentsTheSame = { oldItem, newItem -> oldItem == newItem } | ||
) | ||
) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DailyPagerViewHolder { | ||
val binding = ItemDailyRoutineAddCardBinding.inflate( | ||
LayoutInflater.from(parent.context), parent, false | ||
) | ||
return DailyPagerViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: DailyPagerViewHolder, position: Int) { | ||
holder.onBind(currentList[position]) | ||
} | ||
|
||
class DailyPagerViewHolder(private val binding: ItemDailyRoutineAddCardBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(data: DailyCard) { | ||
binding.tvDailyRoutineAddCard.load(data.backgroundImageUrl) | ||
Timber.d("load Image -> $data") | ||
binding.tvDailyRoutineAddCardName.text = data.content | ||
} | ||
} | ||
} |
Oops, something went wrong.