-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/sopetit/softie/domain/entity/MakerCard.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
app/src/main/java/com/sopetit/softie/domain/entity/RoutineTheme.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/sopetit/softie/domain/repository/AddRoutineRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetMakerCardUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopetit/softie/domain/usecase/addroutine/GetRoutineThemeListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
// 모달 띄우기 | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/sopetit/softie/ui/addroutine/list/AddListViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
// } | ||
// } | ||
// } | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/com/sopetit/softie/ui/addroutine/list/MakerCardPagerAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/sopetit/softie/ui/addroutine/list/MakerCardPagerHashtagAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters