Skip to content

Commit

Permalink
#176 [ui] 루틴 추가 로직 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
pump9918 committed Jun 23, 2024
1 parent f2f191c commit 08db01e
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/com/sopetit/softie/domain/entity/MakerCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sopetit.softie.domain.entity

data class MakerCard(
val artistId: Int,
val artistImageUrl: String,
val subTitle: String,
val title: String,
val hashtag: List<Hashtag>
) {
data class Hashtag(
val hashtagId: Int,
val content: String,
)
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopetit/softie/domain/entity/RoutineTheme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopetit.softie.domain.entity

data class RoutineTheme(
val themes: List<Themes>
) {
data class Themes(
val themeId: Int,
val modifier: String,
val name: String,
val description: String,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sopetit.softie.domain.repository

import com.sopetit.softie.domain.entity.MakerCard
import com.sopetit.softie.domain.entity.RoutineTheme

interface AddRoutineRepository {
suspend fun getMakerCard(): Result<MakerCard>
suspend fun getRoutineTheme(): Result<RoutineTheme>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopetit.softie.domain.usecase.addroutine

import com.sopetit.softie.domain.repository.AddRoutineRepository
import javax.inject.Inject

class GetMakerCardUseCase @Inject constructor(
private val addRoutineRepository: AddRoutineRepository
) {
suspend operator fun invoke() =
addRoutineRepository.getMakerCard()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopetit.softie.domain.usecase.addroutine

import com.sopetit.softie.domain.repository.AddRoutineRepository
import javax.inject.Inject

class GetRoutineThemeListUseCase @Inject constructor(
private val addRoutineRepository: AddRoutineRepository
) {
suspend operator fun invoke() =
addRoutineRepository.getRoutineTheme()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.sopetit.softie.ui.addroutine.list

import android.os.Bundle
import androidx.activity.viewModels
import androidx.viewpager2.widget.ViewPager2
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ActivityAddListBinding
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>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.viewModel = viewModel
viewPager = binding.vpAddListMakerCard
setStatusBarColorFromResource(R.color.background)

setInitBinding()
setHappyDetailCardPagerAdapter()
setCurrentCard()
setBackEnter()
startMakerHelpModal()
}

private fun setInitBinding() { // 초기 바인딩 설정
viewModel.getMakerCard()
}

private fun setHappyDetailCardPagerAdapter() { // maker 카드 뷰페이저 어댑터
with(binding) {
vpAddListMakerCard.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 { // 현재 보고 있는 뷰페이저의 maker's id 가져오기
val currentItem = binding.vpAddListMakerCard.currentItem
val itemId = makerCardPagerAdapter.getItemId(currentItem)
return itemId.toInt()
}

private fun setBackEnter() { // 이전 버튼
binding.ivAddListBackArrow.setSingleOnClickListener {
finish()
}
}

private fun startMakerHelpModal() { // 메이커 도움말 모달 실행
binding.ivAddListMakerHelp.setSingleOnClickListener {
// 모달 띄우기
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.sopetit.softie.ui.addroutine.list

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopetit.softie.domain.entity.MakerCard
import com.sopetit.softie.domain.entity.RoutineTheme
import com.sopetit.softie.domain.usecase.addroutine.GetMakerCardUseCase
import com.sopetit.softie.domain.usecase.addroutine.GetRoutineThemeListUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject

@HiltViewModel
class AddListViewModel @Inject constructor(
private val getMakerCardUseCase: GetMakerCardUseCase,
private val getRoutineThemeListUseCase: GetRoutineThemeListUseCase
) : ViewModel() {
private val _addMakerCardResponse = MutableLiveData<MakerCard>()
val addMakerCardResponse: LiveData<MakerCard> get() = _addMakerCardResponse

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()
.onSuccess { response ->
_addMakerCardResponse.value = response
}
.onFailure { throwable ->
Timber.e("$throwable")
}
}
}

// fun getRoutineTheme() {
// viewModelScope.launch {
// getRoutineThemeListUseCase
// .onSuccess { response ->
// _addRoutineThemeListResponse.value = response
// }
// .onFailure { throwable ->
// Timber.e("$throwable")
// }
// }
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.sopetit.softie.ui.addroutine.list

import android.view.LayoutInflater
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.domain.entity.MakerCard

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

private var dataList = listOf<MakerCard>()

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

private val hashtagAdapter = MakerCardPagerHashtagAdapter(emptyList())

init {
binding.rvAddListMakerHashtagChip.adapter = hashtagAdapter
}

fun onBind(data: MakerCard) {
with(binding) {
ivAddListMakerCardImage.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

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

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MakerPagerViewHolder {
val binding = ItemAddListMakerCardBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return MakerPagerViewHolder(binding)
}

override fun onBindViewHolder(holder: MakerPagerViewHolder, position: Int) {
holder.onBind(dataList[position])
}

override fun getItemCount(): Int = dataList.size
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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.domain.entity.MakerCard

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

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

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

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HashtagViewHolder {
val binding = ItemAddListMakerHashtagChipBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
return HashtagViewHolder(binding)
}

override fun onBindViewHolder(holder: HashtagViewHolder, position: Int) {
holder.onBind(hashtags[position])
}

override fun getItemCount(): Int = hashtags.size

fun submitList(newHashtags: List<MakerCard.Hashtag>) {
hashtags = newHashtags
notifyDataSetChanged()
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/layout/activity_add_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

<data>

<variable
name="viewModel"
type="com.sopetit.softie.ui.addroutine.list.AddListViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down

0 comments on commit 08db01e

Please sign in to comment.