Skip to content

Commit

Permalink
#176 [feat] 뷰페이저, recyclerview 구현 및 mock 데이터 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
pump9918 committed Jun 23, 2024
1 parent 08db01e commit ac614b7
Show file tree
Hide file tree
Showing 21 changed files with 356 additions and 28 deletions.
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
</intent-filter>
</activity>

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

<activity
android:name=".ui.happyroutine.list.HappyAddListActivity"
android:exported="false"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import com.sopetit.softie.data.repositoryImpl.MemberHappinessRoutineRepositoryIm
import com.sopetit.softie.data.repositoryImpl.MemberRepositoryImpl
import com.sopetit.softie.data.repositoryImpl.RefreshTokenRepositoryImpl
import com.sopetit.softie.data.repositoryImpl.VersionRepositoryImpl
import com.sopetit.softie.domain.repository.AddRoutineRepository
import com.sopetit.softie.domain.repository.AuthRepository
import com.sopetit.softie.domain.repository.DailyRoutineRepository
import com.sopetit.softie.domain.repository.DollRepository
import com.sopetit.softie.domain.repository.HappinessRoutineRepository
import com.sopetit.softie.domain.repository.MemberHappinessRoutineRepository
import com.sopetit.softie.domain.repository.MemberRepository
import com.sopetit.softie.domain.repository.MockAddRoutineRepository
import com.sopetit.softie.domain.repository.RefreshTokenRepository
import com.sopetit.softie.domain.repository.VersionRepository
import dagger.Binds
Expand Down Expand Up @@ -55,6 +57,12 @@ abstract class RepositoryModule {
memberHappinessRoutineRepositoryImpl: MemberHappinessRoutineRepositoryImpl
): MemberHappinessRoutineRepository

@Binds
@Singleton
abstract fun bindAddRoutineRepository(
mockAddRoutineRepository: MockAddRoutineRepository
): AddRoutineRepository

@Binds
@Singleton
abstract fun bindToAuthRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.sopetit.softie.domain.entity.MakerCard
import com.sopetit.softie.domain.entity.RoutineTheme

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

import com.sopetit.softie.domain.entity.MakerCard
import com.sopetit.softie.domain.entity.RoutineTheme
import javax.inject.Inject

class MockAddRoutineRepository @Inject constructor() : AddRoutineRepository {
override suspend fun getMakerCard(): Result<List<MakerCard>> {
return Result.success(
listOf(
MakerCard(
artistId = 1,
artistImageUrl = "https://img.etoday.co.kr/pto_db/2024/04/600/20240426132100_2017673_647_863.jpeg",
subTitle = "하이브의 주인은 누구?",
title = "뉴진스가 돌아왔다",
hashtag = listOf(
MakerCard.Hashtag(hashtagId = 1, content = "민희진"),
MakerCard.Hashtag(hashtagId = 2, content = "방시혁"),
MakerCard.Hashtag(hashtagId = 2, content = "하이브")
)
),
MakerCard(
artistId = 2,
artistImageUrl = "https://cdn.hankyung.com/photo/202211/BF.23427209.1.jpg",
subTitle = "더이상 웹툰작가로는 못산다",
title = "침착맨의 시크릿",
hashtag = listOf(
MakerCard.Hashtag(hashtagId = 3, content = "침착침착"),
MakerCard.Hashtag(hashtagId = 4, content = "이말년")
)
),
MakerCard(
artistId = 3,
artistImageUrl = "https://res.heraldm.com/content/image/2024/05/06/20240506050023_0.jpg",
subTitle = "선재업고 얼마나 뛸 수 있어?",
title = "변우석의 성공담",
hashtag = listOf(
MakerCard.Hashtag(hashtagId = 5, content = "류선재"),
MakerCard.Hashtag(hashtagId = 6, content = "드라마")
)
)
)
)
}

override suspend fun getRoutineTheme(): Result<RoutineTheme> {
return Result.success(
RoutineTheme(
themes = listOf(
RoutineTheme.Themes(
themeId = 1,
modifier = "사람들과 어울리는",
name = "관계 쌓기",
description = "설명"
),
RoutineTheme.Themes(
themeId = 2,
modifier = "나를 돌보는",
name = "마음 챙김",
description = "설명2"
),
RoutineTheme.Themes(
themeId = 3,
modifier = "경제적으로 살아가는",
name = "통통한 통장",
description = "설명2"
),
RoutineTheme.Themes(
themeId = 4,
modifier = "하루를 상쾌하게",
name = "산뜻한 일상",
description = "설명2"
),
RoutineTheme.Themes(
themeId = 5,
modifier = "더 나은 나를 위해",
name = "한 걸음 성장",
description = "설명2"
),
RoutineTheme.Themes(
themeId = 6,
modifier = "튼튼하게 건강하게",
name = "건강한 몸",
description = "설명2"
),
RoutineTheme.Themes(
themeId = 7,
modifier = "튼튼하게 건강하게",
name = "나와 친해지기",
description = "설명2"
)
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.sopetit.softie.domain.usecase.addroutine

import com.sopetit.softie.domain.entity.MakerCard
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()
suspend operator fun invoke(): Result<List<MakerCard>> {
return addRoutineRepository.getMakerCard()
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.sopetit.softie.domain.usecase.addroutine

import com.sopetit.softie.domain.entity.RoutineTheme
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()
suspend operator fun invoke(): Result<RoutineTheme> {
return try {
val result = addRoutineRepository.getRoutineTheme()
result
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ 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.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) {
class AddListActivity : BindingActivity<ActivityAddListBinding>(R.layout.activity_add_list) {
private lateinit var viewPager: ViewPager2
private val makerCardPagerAdapter = MakerCardPagerAdapter()
private val viewModel by viewModels<AddListViewModel>()
private var routineThemeListAdapter: RoutineThemeListAdapter? = null
private lateinit var itemDeco: RecyclerView.ItemDecoration

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.viewModel = viewModel
Expand All @@ -27,10 +31,14 @@ class AddListActivity :
setCurrentCard()
setBackEnter()
startMakerHelpModal()
setRoutineThemeListAdapter()
setItemDeco()
setupObservers()
}

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

private fun setHappyDetailCardPagerAdapter() { // maker 카드 뷰페이저 어댑터
Expand Down Expand Up @@ -66,4 +74,30 @@ class AddListActivity :
// 모달 띄우기
}
}

private fun setRoutineThemeListAdapter() {
with(binding) {
routineThemeListAdapter = RoutineThemeListAdapter()
rvAddList.adapter = routineThemeListAdapter
}
}

private fun setItemDeco() {
itemDeco = VerticalItemDecoration(applicationContext)
binding.rvAddList.addItemDecoration(itemDeco)
}

private fun setupObservers() {
viewModel.addRoutineThemeListResponse.observe(this) { routineTheme ->
routineTheme?.let {
routineThemeListAdapter?.submitList(routineTheme.themes)
}
}

viewModel.addMakerCardResponse.observe(this) { makerCards ->
makerCards?.let {
makerCardPagerAdapter.submitList(makerCards)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ 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 _addMakerCardResponse = MutableLiveData<List<MakerCard>>()
val addMakerCardResponse: LiveData<List<MakerCard>> get() = _addMakerCardResponse

private val _addRoutineThemeListResponse = MutableLiveData<RoutineTheme>()
val addRoutineThemeListResponse: LiveData<RoutineTheme> get() = _addRoutineThemeListResponse
Expand All @@ -42,15 +42,15 @@ class AddListViewModel @Inject constructor(
}
}

// fun getRoutineTheme() {
// viewModelScope.launch {
// getRoutineThemeListUseCase
// .onSuccess { response ->
// _addRoutineThemeListResponse.value = response
// }
// .onFailure { throwable ->
// Timber.e("$throwable")
// }
// }
// }
fun getRoutineTheme() {
viewModelScope.launch {
val result = getRoutineThemeListUseCase()

result.onSuccess { response ->
_addRoutineThemeListResponse.value = response
}.onFailure { throwable ->
Timber.e("$throwable")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import com.sopetit.softie.R
import com.sopetit.softie.databinding.ItemAddListMakerCardBinding
import com.sopetit.softie.domain.entity.MakerCard

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

private var dataList = listOf<MakerCard>()

Expand Down Expand Up @@ -52,4 +51,9 @@ class MakerCardPagerAdapter :
}

override fun getItemCount(): Int = dataList.size

fun submitList(newDataList: List<MakerCard>) {
dataList = newDataList
notifyDataSetChanged()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.sopetit.softie.ui.addroutine.list

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.R
import com.sopetit.softie.databinding.ItemAddListBinding
import com.sopetit.softie.domain.entity.RoutineTheme
import com.sopetit.softie.util.ItemDiffCallback

class RoutineThemeListAdapter :
ListAdapter<RoutineTheme.Themes, RoutineThemeListAdapter.RoutineThemeListViewHolder>(
ItemDiffCallback<RoutineTheme.Themes>(
onItemsTheSame = { oldItem, newItem -> oldItem == newItem },
onContentsTheSame = { oldItem, newItem -> oldItem == newItem }
)
) {

inner class RoutineThemeListViewHolder(private val binding: ItemAddListBinding) :
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)
}
tvAddListItemContent.text = data.modifier
tvAddListItemTitle.text = data.name
}
}
}

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

override fun onBindViewHolder(holder: RoutineThemeListViewHolder, position: Int) {
holder.onBind(currentList[position])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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.happyroutine.complete.HappyRoutineCompleteActivity
import com.sopetit.softie.ui.happyroutine.delete.HappyDeleteFragment
import com.sopetit.softie.ui.happyroutine.list.HappyAddListActivity
Expand Down Expand Up @@ -71,7 +72,7 @@ class HappyMyRoutineFragment :

private fun startHappyAddListActivity() {
binding.ivHappyRoutineEmptyCard.setOnClickListener {
val intent = Intent(requireContext(), HappyAddListActivity::class.java)
val intent = Intent(requireContext(), AddListActivity::class.java)
resultLauncher.launch(intent)
}
}
Expand Down
Loading

0 comments on commit ac614b7

Please sign in to comment.