Skip to content

Commit

Permalink
#8 [refact] : 데일리 루틴 리스트 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
minemi00 committed Jan 14, 2024
1 parent fe5d383 commit 0182c04
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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
import timber.log.Timber

class DailyRoutineAddActivity :
BindingActivity<ActivityDailyRoutineAddBinding>(R.layout.activity_daily_routine_add) {
Expand Down Expand Up @@ -42,7 +41,7 @@ class DailyRoutineAddActivity :
dailyRoutineAddThemeAdapter = DailyRoutineAddThemeAdapter().apply {
setOnItemClickListener(object : DailyRoutineAddThemeAdapter.OnItemClickListener {
override fun onItemClick(item: Theme, position: Int) {
setRoutineList(item)
setRoutineList(item.themeId)
}
})
}
Expand All @@ -57,9 +56,10 @@ class DailyRoutineAddActivity :
}
}

private fun setRoutineList(item: Theme) {
Timber.d("daily routine act -> ${item.themeId}")
dailyRoutineAddCardPagerAdapter.submitList(dailyRoutineAddViewModel.themeDailyRoutineList[item.themeId].value)
private fun setRoutineList(themeId: Int) {
dailyRoutineAddCardPagerAdapter.submitList(
dailyRoutineAddViewModel.getDailyCardListForId(themeId)[0].dailyRoutineCardList
)
}

private fun initPagerDiv(previewWidth: Int, itemMargin: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DailyRoutineAddThemeAdapter :
) {
private var onItemClickListener: OnItemClickListener? = null
private var selectedPosition = 0
var clickedThemeId: Int = 1

interface OnItemClickListener {
fun onItemClick(item: Theme, position: Int)
Expand All @@ -29,7 +30,9 @@ class DailyRoutineAddThemeAdapter :
this.onItemClickListener = listener
}

inner class DailyThemeViewHolder(private val binding: ItemDailyRoutineAddThemeBinding) :
inner class DailyThemeViewHolder(
private val binding: ItemDailyRoutineAddThemeBinding
) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: Theme) {
binding.tvDailyRoutineAddThemeName.text = data.name
Expand All @@ -51,6 +54,7 @@ class DailyRoutineAddThemeAdapter :
notifyItemChanged(selectedPosition)
selectedPosition = absoluteAdapterPosition
}
clickedThemeId = data.themeId
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sopetit.softie.domain.entity.DailyCard
import com.sopetit.softie.domain.entity.DailyRoutine
import com.sopetit.softie.domain.entity.Theme

class DailyRoutineAddViewModel : ViewModel() {
Expand Down Expand Up @@ -88,21 +89,6 @@ class DailyRoutineAddViewModel : ViewModel() {
val mockThemeList: LiveData<List<Theme>>
get() = _mockThemeList

val themeDailyRoutineList = listOf(
startNewDayCardList,
healthBodyCardList,
overcomeHelplessnessCardList,
restfulSleepCardList,
environmentalGuardCardList,
gratitudeCardList,
smallKindnessCardList,
smallAccomplishmentCardList,
preciousMeCardList,
forRichCardList,
readyImmerseCardList,
emptyCardList
)

val startNewDayCardList: LiveData<List<DailyCard>>
get() = _startNewDayCardList

Expand All @@ -118,12 +104,12 @@ class DailyRoutineAddViewModel : ViewModel() {
val environmentalGuardCardList: LiveData<List<DailyCard>>
get() = _environmentalGuardCardList

val gratitudeCardList: LiveData<List<DailyCard>>
get() = _gratitudeCardList

val smallKindnessCardList: LiveData<List<DailyCard>>
get() = _smallKindnessCardList

val gratitudeCardList: LiveData<List<DailyCard>>
get() = _gratitudeCardList

val smallAccomplishmentCardList: LiveData<List<DailyCard>>
get() = _smallAccomplishmentCardList

Expand Down Expand Up @@ -498,4 +484,65 @@ class DailyRoutineAddViewModel : ViewModel() {
)
)
)

private val _themeDailyRoutineList: MutableLiveData<List<DailyRoutine>> =
MutableLiveData(
mutableListOf(
DailyRoutine(
themeId = 1,
startNewDayCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 2,
healthBodyCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 3,
overcomeHelplessnessCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 4,
restfulSleepCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 5,
environmentalGuardCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 6,
smallKindnessCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 7,
gratitudeCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 8,
smallAccomplishmentCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 9,
preciousMeCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 10,
forRichCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 11,
readyImmerseCardList.value ?: emptyList()
),
DailyRoutine(
themeId = 12,
emptyCardList.value ?: emptyList()
)
)
)

private val themeDailyRoutineList: LiveData<List<DailyRoutine>> get() = _themeDailyRoutineList

fun getDailyCardListForId(themeId: Int): List<DailyRoutine> {
return themeDailyRoutineList.value?.filter { it.themeId == themeId } ?: emptyList()
}

}
1 change: 0 additions & 1 deletion app/src/main/res/layout/item_daily_routine_add_theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
android:layout_height="50dp"
android:layout_marginHorizontal="3dp"
android:background="@drawable/ic_daily_theme_background"
android:clickable="true"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down

0 comments on commit 0182c04

Please sign in to comment.