Skip to content

Commit

Permalink
#178 [mod] theme Data class 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
emjayMJkim committed Jun 24, 2024
1 parent 675ba79 commit 01e3f2d
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ data class ThemeListResponse(
val themeId: Int,
@SerialName("name")
val name: String,
@SerialName("iconImageUrl")
val iconImageUrl: String,
@SerialName("backgroundImageUrl")
val backgroundImageUrl: String
@SerialName("modifier")
val modifier: String,
@SerialName("description")
val description: String
)

fun toTheme() = themes.map {
Theme(
themeId = it.themeId,
name = it.name,
iconImageUrl = it.iconImageUrl,
backgroundImageUrl = it.backgroundImageUrl
modifier = it.modifier,
description = it.description
)
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/sopetit/softie/domain/entity/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.sopetit.softie.domain.entity

data class Theme(
val themeId: Int,
val modifier: String,
val name: String,
val iconImageUrl: String,
val backgroundImageUrl: String
val description: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.sopetit.softie.R
import com.sopetit.softie.databinding.ItemDailyRoutineAddThemeBinding
import com.sopetit.softie.domain.entity.Theme
import com.sopetit.softie.util.ItemDiffCallback
import com.sopetit.softie.util.binding.BindingAdapter.setCoilImage
import com.sopetit.softie.util.setSingleOnClickListener

class DailyRoutineAddThemeAdapter :
Expand Down Expand Up @@ -38,7 +37,7 @@ class DailyRoutineAddThemeAdapter :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: Theme) {
binding.tvDailyRoutineAddThemeName.text = data.name
binding.ivDailyRoutineAddThemeIcon.setCoilImage(data.iconImageUrl)
// binding.ivDailyRoutineAddThemeIcon.setCoilImage(data.iconImageUrl)
if (selectedPosition == absoluteAdapterPosition) {
changeThemeBackground(binding, true)
changeThemeTextColor(binding, true)
Expand All @@ -57,7 +56,7 @@ class DailyRoutineAddThemeAdapter :
selectedPosition = absoluteAdapterPosition
}
clickedThemeId = data.themeId
clickedThemeIcon = data.iconImageUrl
// clickedThemeIcon = data.iconImageUrl
}
}
}
Expand Down Expand Up @@ -113,7 +112,7 @@ class DailyRoutineAddThemeAdapter :
}

override fun onBindViewHolder(holder: DailyThemeViewHolder, position: Int) {
if (clickedThemeIcon == null) clickedThemeIcon = currentList[0].iconImageUrl
// if (clickedThemeIcon == null) clickedThemeIcon = currentList[0].iconImageUrl
holder.onBind(currentList[position])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.sopetit.softie.databinding.ItemOnboardingChoiceThemeBinding
import com.sopetit.softie.domain.entity.Theme
import com.sopetit.softie.ui.onboarding.OnboardingActivity.Companion.MAXIMUM_THEME_SELECTION
import com.sopetit.softie.util.ItemDiffCallback
import com.sopetit.softie.util.binding.BindingAdapter.setCoilImage
import com.sopetit.softie.util.toast

class ChoiceThemeAdapter :
Expand All @@ -26,8 +25,9 @@ class ChoiceThemeAdapter :
inner class ChoiceThemeViewHolder(private val binding: ItemOnboardingChoiceThemeBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: Theme) {
binding.tvThemeName.text = data.name
binding.ivThemeIcon.setCoilImage(data.iconImageUrl)
binding.item = data
// TODO 이미지 관련 재작업 예정 (동일 icon 재사용 위해 이전 pr 머지 후 작업)
// binding.ivThemeIcon.setCoilImage(data.iconImageUrl)
binding.root.setOnClickListener {
themeSelection(binding, data)
onItemClickListener?.let { it(data) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChoiceThemeFragment :

private fun initMakeThemeAdapter() {
_choiceThemeAdapter = ChoiceThemeAdapter()
themeViewModel.getThemeList()
// themeViewModel.getThemeList()
binding.rvOnboardingChoiceTheme.apply {
layoutManager = GridLayoutManager(requireContext(), 3)
adapter = choiceThemeAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ package com.sopetit.softie.ui.onboarding.themechoice
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopetit.softie.domain.entity.Theme
import com.sopetit.softie.domain.usecase.dailyroutine.GetThemeListUseCase
import com.sopetit.softie.domain.usecase.doll.GetDollUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
Expand All @@ -18,25 +15,38 @@ class ChoiceThemeViewModel @Inject constructor(
private val getThemeListUseCase: GetThemeListUseCase
) : ViewModel() {

private val _themeList = MutableLiveData<List<Theme>>()
// private val _themeList = MutableLiveData<List<Theme>>()
private val _themeList: MutableLiveData<List<Theme>> =
MutableLiveData(
listOf(
Theme(1, "", "좋은 관계 만들기", ""),
Theme(2, "", "마음 챙기기", ""),
Theme(3, "", "통통한 통장 만들기", ""),
Theme(4, "", "산뜻한 일상 만들기", ""),
Theme(5, "", "한 걸음 성장하기", ""),
Theme(6, "", "건강한 몸 만들기", ""),
Theme(7, "", "나와 친해지기", ""),
)
)
val themeList: LiveData<List<Theme>>
get() = _themeList

private val _themeBtnEnabled: MutableLiveData<Boolean> = MutableLiveData()
val themeBtnEnabled: LiveData<Boolean>
get() = _themeBtnEnabled

fun getThemeList() {
viewModelScope.launch {
getThemeListUseCase.invoke()
.onSuccess { response ->
_themeList.value = response
Timber.d("서버 통신 성공 -> $response")
}.onFailure {
Timber.e("서버 통신 실패 -> ${it.message}")
}
}
}
// TODO 서버 연결 시 재작업 예정
// fun getThemeList() {
// viewModelScope.launch {
// getThemeListUseCase.invoke()
// .onSuccess { response ->
// _themeList.value = response
// Timber.d("서버 통신 성공 -> $response")
// }.onFailure {
// Timber.e("서버 통신 실패 -> ${it.message}")
// }
// }
// }

fun setThemeBtnEnabled(boolean: Boolean) {
_themeBtnEnabled.value = boolean
Expand Down
87 changes: 49 additions & 38 deletions app/src/main/res/layout/item_onboarding_choice_theme.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingHorizontal="10dp">

<ImageView
android:id="@+id/iv_theme_background"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/shape_gray0_fill_gray200_stroke_100_circle"
android:layout_marginHorizontal="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<ImageView
android:id="@+id/iv_theme_icon"
android:layout_width="40dp"
android:layout_height="40dp"
app:layout_constraintTop_toTopOf="@id/iv_theme_background"
app:layout_constraintBottom_toBottomOf="@id/iv_theme_background"
app:layout_constraintStart_toStartOf="@id/iv_theme_background"
app:layout_constraintEnd_toEndOf="@id/iv_theme_background" />

<TextView
android:id="@+id/tv_theme_name"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="item"
type="com.sopetit.softie.domain.entity.Theme" />

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/theme_text"
android:textAppearance="@style/caption1"
android:textColor="@color/gray500"
android:layout_marginTop="9dp"
android:layout_marginBottom="30dp"
app:layout_constraintTop_toBottomOf="@id/iv_theme_background"
app:layout_constraintStart_toStartOf="@id/iv_theme_background"
app:layout_constraintEnd_toEndOf="@id/iv_theme_background"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
android:paddingHorizontal="10dp">

<ImageView
android:id="@+id/iv_theme_background"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/shape_gray0_fill_gray200_stroke_100_circle"
android:layout_marginHorizontal="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<ImageView
android:id="@+id/iv_theme_icon"
android:layout_width="40dp"
android:layout_height="40dp"
app:layout_constraintTop_toTopOf="@id/iv_theme_background"
app:layout_constraintBottom_toBottomOf="@id/iv_theme_background"
app:layout_constraintStart_toStartOf="@id/iv_theme_background"
app:layout_constraintEnd_toEndOf="@id/iv_theme_background" />

<TextView
android:id="@+id/tv_theme_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{item.name}"
android:textAppearance="@style/caption1"
android:textColor="@color/gray500"
android:layout_marginTop="9dp"
android:layout_marginBottom="30dp"
app:layout_constraintTop_toBottomOf="@id/iv_theme_background"
app:layout_constraintStart_toStartOf="@id/iv_theme_background"
app:layout_constraintEnd_toEndOf="@id/iv_theme_background"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit 01e3f2d

Please sign in to comment.