From ac614b753b2e4d2f1a6c54ec5272f19a94cba3f1 Mon Sep 17 00:00:00 2001 From: pump9918 Date: Sun, 23 Jun 2024 21:05:28 +0900 Subject: [PATCH] =?UTF-8?q?#176=20[feat]=20=EB=B7=B0=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A0=80,=20recyclerview=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20mo?= =?UTF-8?q?ck=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 5 + .../com/sopetit/softie/di/RepositoryModule.kt | 8 ++ .../domain/repository/AddRoutineRepository.kt | 2 +- .../repository/MockAddRoutineRepository.kt | 96 +++++++++++++++++++ .../usecase/addroutine/GetMakerCardUseCase.kt | 7 +- .../addroutine/GetRoutineThemeListUseCase.kt | 11 ++- .../ui/addroutine/list/AddListActivity.kt | 38 +++++++- .../ui/addroutine/list/AddListViewModel.kt | 26 ++--- .../addroutine/list/MakerCardPagerAdapter.kt | 8 +- .../list/RoutineThemeListAdapter.kt | 57 +++++++++++ .../ui/happyroutine/HappyMyRoutineFragment.kt | 3 +- app/src/main/res/drawable/ic_theme1_pink.xml | 13 +++ app/src/main/res/drawable/ic_theme2_red.xml | 13 +++ .../main/res/drawable/ic_theme3_orange.xml | 12 +++ .../main/res/drawable/ic_theme4_yellow.xml | 13 +++ app/src/main/res/drawable/ic_theme5_green.xml | 13 +++ app/src/main/res/drawable/ic_theme6_sky.xml | 13 +++ app/src/main/res/drawable/ic_theme7_blue.xml | 13 +++ app/src/main/res/drawable/ic_theme8_maker.xml | 23 +++++ app/src/main/res/layout/activity_add_list.xml | 6 +- app/src/main/res/values/dimens.xml | 4 +- 21 files changed, 356 insertions(+), 28 deletions(-) create mode 100644 app/src/main/java/com/sopetit/softie/domain/repository/MockAddRoutineRepository.kt create mode 100644 app/src/main/java/com/sopetit/softie/ui/addroutine/list/RoutineThemeListAdapter.kt create mode 100644 app/src/main/res/drawable/ic_theme1_pink.xml create mode 100644 app/src/main/res/drawable/ic_theme2_red.xml create mode 100644 app/src/main/res/drawable/ic_theme3_orange.xml create mode 100644 app/src/main/res/drawable/ic_theme4_yellow.xml create mode 100644 app/src/main/res/drawable/ic_theme5_green.xml create mode 100644 app/src/main/res/drawable/ic_theme6_sky.xml create mode 100644 app/src/main/res/drawable/ic_theme7_blue.xml create mode 100644 app/src/main/res/drawable/ic_theme8_maker.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5b1fa6f3..9aaf8be9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,6 +46,11 @@ + + + suspend fun getMakerCard(): Result> suspend fun getRoutineTheme(): Result } diff --git a/app/src/main/java/com/sopetit/softie/domain/repository/MockAddRoutineRepository.kt b/app/src/main/java/com/sopetit/softie/domain/repository/MockAddRoutineRepository.kt new file mode 100644 index 00000000..0e8b8480 --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/domain/repository/MockAddRoutineRepository.kt @@ -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> { + 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 { + 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" + ) + ) + ) + ) + } +} diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetMakerCardUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetMakerCardUseCase.kt index 74b0c625..99dd1eca 100644 --- a/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetMakerCardUseCase.kt +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetMakerCardUseCase.kt @@ -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> { + return addRoutineRepository.getMakerCard() + } } + diff --git a/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetRoutineThemeListUseCase.kt b/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetRoutineThemeListUseCase.kt index 0348babb..1eeaa44f 100644 --- a/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetRoutineThemeListUseCase.kt +++ b/app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetRoutineThemeListUseCase.kt @@ -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 { + return try { + val result = addRoutineRepository.getRoutineTheme() + result + } catch (e: Exception) { + Result.failure(e) + } + } } diff --git a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListActivity.kt b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListActivity.kt index faca3c01..2def2b27 100644 --- a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListActivity.kt +++ b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListActivity.kt @@ -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(R.layout.activity_add_list) { +class AddListActivity : BindingActivity(R.layout.activity_add_list) { private lateinit var viewPager: ViewPager2 private val makerCardPagerAdapter = MakerCardPagerAdapter() private val viewModel by viewModels() + private var routineThemeListAdapter: RoutineThemeListAdapter? = null + private lateinit var itemDeco: RecyclerView.ItemDecoration + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding.viewModel = viewModel @@ -27,10 +31,14 @@ class AddListActivity : setCurrentCard() setBackEnter() startMakerHelpModal() + setRoutineThemeListAdapter() + setItemDeco() + setupObservers() } private fun setInitBinding() { // 초기 바인딩 설정 viewModel.getMakerCard() + viewModel.getRoutineTheme() } private fun setHappyDetailCardPagerAdapter() { // maker 카드 뷰페이저 어댑터 @@ -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) + } + } + } } diff --git a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListViewModel.kt b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListViewModel.kt index 330b931f..5a196e01 100644 --- a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListViewModel.kt +++ b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListViewModel.kt @@ -18,8 +18,8 @@ class AddListViewModel @Inject constructor( private val getMakerCardUseCase: GetMakerCardUseCase, private val getRoutineThemeListUseCase: GetRoutineThemeListUseCase ) : ViewModel() { - private val _addMakerCardResponse = MutableLiveData() - val addMakerCardResponse: LiveData get() = _addMakerCardResponse + private val _addMakerCardResponse = MutableLiveData>() + val addMakerCardResponse: LiveData> get() = _addMakerCardResponse private val _addRoutineThemeListResponse = MutableLiveData() val addRoutineThemeListResponse: LiveData get() = _addRoutineThemeListResponse @@ -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") + } + } + } } diff --git a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/MakerCardPagerAdapter.kt b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/MakerCardPagerAdapter.kt index 31ce0bcb..57977b5e 100644 --- a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/MakerCardPagerAdapter.kt +++ b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/MakerCardPagerAdapter.kt @@ -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() { +class MakerCardPagerAdapter : RecyclerView.Adapter() { private var dataList = listOf() @@ -52,4 +51,9 @@ class MakerCardPagerAdapter : } override fun getItemCount(): Int = dataList.size + + fun submitList(newDataList: List) { + dataList = newDataList + notifyDataSetChanged() + } } diff --git a/app/src/main/java/com/sopetit/softie/ui/addroutine/list/RoutineThemeListAdapter.kt b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/RoutineThemeListAdapter.kt new file mode 100644 index 00000000..5e786d5d --- /dev/null +++ b/app/src/main/java/com/sopetit/softie/ui/addroutine/list/RoutineThemeListAdapter.kt @@ -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( + ItemDiffCallback( + 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]) + } +} diff --git a/app/src/main/java/com/sopetit/softie/ui/happyroutine/HappyMyRoutineFragment.kt b/app/src/main/java/com/sopetit/softie/ui/happyroutine/HappyMyRoutineFragment.kt index 2b7f7e64..e74a931a 100644 --- a/app/src/main/java/com/sopetit/softie/ui/happyroutine/HappyMyRoutineFragment.kt +++ b/app/src/main/java/com/sopetit/softie/ui/happyroutine/HappyMyRoutineFragment.kt @@ -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 @@ -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) } } diff --git a/app/src/main/res/drawable/ic_theme1_pink.xml b/app/src/main/res/drawable/ic_theme1_pink.xml new file mode 100644 index 00000000..4ddb642d --- /dev/null +++ b/app/src/main/res/drawable/ic_theme1_pink.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_theme2_red.xml b/app/src/main/res/drawable/ic_theme2_red.xml new file mode 100644 index 00000000..5fac478c --- /dev/null +++ b/app/src/main/res/drawable/ic_theme2_red.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_theme3_orange.xml b/app/src/main/res/drawable/ic_theme3_orange.xml new file mode 100644 index 00000000..8c76dc2a --- /dev/null +++ b/app/src/main/res/drawable/ic_theme3_orange.xml @@ -0,0 +1,12 @@ + + + diff --git a/app/src/main/res/drawable/ic_theme4_yellow.xml b/app/src/main/res/drawable/ic_theme4_yellow.xml new file mode 100644 index 00000000..a9f43ba2 --- /dev/null +++ b/app/src/main/res/drawable/ic_theme4_yellow.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_theme5_green.xml b/app/src/main/res/drawable/ic_theme5_green.xml new file mode 100644 index 00000000..85951c1e --- /dev/null +++ b/app/src/main/res/drawable/ic_theme5_green.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_theme6_sky.xml b/app/src/main/res/drawable/ic_theme6_sky.xml new file mode 100644 index 00000000..2156037c --- /dev/null +++ b/app/src/main/res/drawable/ic_theme6_sky.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_theme7_blue.xml b/app/src/main/res/drawable/ic_theme7_blue.xml new file mode 100644 index 00000000..1184205f --- /dev/null +++ b/app/src/main/res/drawable/ic_theme7_blue.xml @@ -0,0 +1,13 @@ + + + + diff --git a/app/src/main/res/drawable/ic_theme8_maker.xml b/app/src/main/res/drawable/ic_theme8_maker.xml new file mode 100644 index 00000000..9721c6e9 --- /dev/null +++ b/app/src/main/res/drawable/ic_theme8_maker.xml @@ -0,0 +1,23 @@ + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_add_list.xml b/app/src/main/res/layout/activity_add_list.xml index 10cf7417..3ca0da10 100644 --- a/app/src/main/res/layout/activity_add_list.xml +++ b/app/src/main/res/layout/activity_add_list.xml @@ -67,8 +67,8 @@ android:layout_marginEnd="20dp" android:padding="9dp" android:src="@drawable/ic_maker_help" - app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="@id/iv_add_list_maker_chip" + app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/iv_add_list_maker_chip" /> 30dp 20dp 6dp - 12dp - 8dp + 8dp + 4dp