-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#7 [ui] 온보딩 - 테마 선택 뷰 #12
Changes from 10 commits
f0f2b67
3a819da
69c6e6a
fb74ae9
d8201c9
36a401c
b4d2a00
719cc79
83c9c68
16668f7
c874cfa
e53dc90
4efc7db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class Theme( | ||
val themeId: Int, | ||
val name: String, | ||
val iconImageUrl: String, | ||
val backgroudnImageUrl: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sopetit.softie.ui.onboarding | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentOnboardingChoiceBearBinding | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
|
||
class BearChoiceFragment : | ||
BindingFragment<FragmentOnboardingChoiceBearBinding>(R.layout.fragment_onboarding_choice_bear) { | ||
|
||
private lateinit var viewModel: OnboardingViewModel | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewModel = ViewModelProvider(requireActivity()).get(OnboardingViewModel::class.java) | ||
binding.viewModel = viewModel | ||
|
||
initChangeFragment() | ||
} | ||
|
||
private fun initChangeFragment() { | ||
binding.clOnboardingChoiceBear.setOnClickListener { | ||
viewModel.changeBearNameChoiceView() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.sopetit.softie.ui.onboarding | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.fragment.app.Fragment | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.ActivityOnboardingBinding | ||
import com.sopetit.softie.ui.onboarding.routinechoice.RoutineChoiceFragment | ||
import com.sopetit.softie.ui.onboarding.themechoice.ChoiceThemeFragment | ||
import com.sopetit.softie.util.binding.BindingActivity | ||
|
||
class OnboardingActivity : | ||
BindingActivity<ActivityOnboardingBinding>(R.layout.activity_onboarding) { | ||
|
||
private val viewModel by viewModels<OnboardingViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding.viewModel = viewModel | ||
|
||
initMakeFragment() | ||
initChangeFragment() | ||
} | ||
|
||
private fun initMakeFragment() { | ||
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_onboarding_fragment) | ||
if (currentFragment == null) { | ||
viewModel.changeBearChoiceView() | ||
supportFragmentManager.beginTransaction() | ||
.add(R.id.fcv_onboarding_fragment, BearChoiceFragment()) | ||
.commit() | ||
} | ||
} | ||
|
||
private fun initChangeFragment() { | ||
initChangeRoutineChoice() | ||
initChangeSetBearName() | ||
initChangeThemeChoice() | ||
} | ||
|
||
private fun initChangeSetBearName() { | ||
viewModel.bearNameChoiceView.observe(this) { | ||
if (it) { | ||
changeFragment(SetBearNameFragment()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
이런 건 어떤가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이렇게 하는 게 더 가독성이 높아질 것 같네요!! |
||
} | ||
} | ||
|
||
private fun initChangeThemeChoice() { | ||
viewModel.themeChoiceView.observe(this) { | ||
if (it) { | ||
changeFragment(ChoiceThemeFragment()) | ||
} | ||
} | ||
} | ||
|
||
private fun initChangeRoutineChoice() { | ||
viewModel.routineChoiceView.observe(this) { | ||
if (it) { | ||
changeFragment(RoutineChoiceFragment()) | ||
} | ||
} | ||
} | ||
|
||
private fun changeFragment(fragment: Fragment) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.fcv_onboarding_fragment, fragment) | ||
.commit() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.sopetit.softie.ui.onboarding | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
|
||
class OnboardingViewModel : ViewModel() { | ||
|
||
private val _bearChoiceView: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val bearChoiceView: LiveData<Boolean> | ||
get() = _bearChoiceView | ||
|
||
private val _bearNameChoiceView: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val bearNameChoiceView: LiveData<Boolean> | ||
get() = _bearNameChoiceView | ||
|
||
private val _themeChoiceView: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val themeChoiceView: LiveData<Boolean> | ||
get() = _themeChoiceView | ||
|
||
private val _routineChoiceView: MutableLiveData<Boolean> = MutableLiveData(false) | ||
val routineChoiceView: LiveData<Boolean> | ||
get() = _routineChoiceView | ||
|
||
fun changeBearChoiceView() { | ||
_bearChoiceView.value = true | ||
} | ||
|
||
fun changeBearNameChoiceView() { | ||
_bearNameChoiceView.value = true | ||
} | ||
|
||
fun changeThemeChoiceView() { | ||
_themeChoiceView.value = true | ||
} | ||
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 view 값들에 대해서는 false 처리를 안해도 나중에 문제가 안될지,,!!
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 고민을 좀 했는데.. 일단은 지금 온보딩 과정 중에 뒤로가기 로직이 없는 상태라서 그냥 true로만 설정했습니다...! 나중에 유저 로직이 바뀌게 되면 코드 수정하겠습니당 |
||
|
||
fun changeRoutineChoiceView() { | ||
_routineChoiceView.value = true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.sopetit.softie.ui.onboarding | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentOnboardingSetBearNameBinding | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
|
||
class SetBearNameFragment : | ||
BindingFragment<FragmentOnboardingSetBearNameBinding>(R.layout.fragment_onboarding_set_bear_name) { | ||
|
||
private lateinit var viewModel: OnboardingViewModel | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewModel = ViewModelProvider(requireActivity()).get(OnboardingViewModel::class.java) | ||
binding.viewModel = viewModel | ||
|
||
initChangeFragment() | ||
} | ||
|
||
private fun initChangeFragment() { | ||
binding.clOnboardingSetBearName.setOnClickListener { | ||
viewModel.changeThemeChoiceView() | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sopetit.softie.ui.onboarding.routinechoice | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentOnboardingChoiceRoutineBinding | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
|
||
class RoutineChoiceFragment : | ||
BindingFragment<FragmentOnboardingChoiceRoutineBinding>(R.layout.fragment_onboarding_choice_routine) { | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.sopetit.softie.ui.onboarding.themechoice | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopetit.softie.databinding.ItemOnboardingChoiceThemeBinding | ||
import com.sopetit.softie.domain.entity.Theme | ||
import com.sopetit.softie.util.ItemDiffCallback | ||
|
||
class ChoiceThemeAdapter : | ||
ListAdapter<Theme, ChoiceThemeAdapter.ChoiceThemeViewHolder>(ItemDiffCallback<Theme>( | ||
onItemsTheSame = { old, new -> old.themeId == new.themeId }, | ||
onContentsTheSame = { old, new -> old == new } | ||
)) { | ||
|
||
class ChoiceThemeViewHolder(private val binding: ItemOnboardingChoiceThemeBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(data: Theme) { | ||
binding.tvThemeName.text = data.name | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChoiceThemeViewHolder { | ||
val binding = ItemOnboardingChoiceThemeBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
return ChoiceThemeViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ChoiceThemeViewHolder, position: Int) { | ||
holder.onBind(currentList[position]) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.sopetit.softie.ui.onboarding.themechoice | ||
|
||
import android.os.Bundle | ||
import android.text.SpannableStringBuilder | ||
import android.text.Spanned | ||
import android.text.style.ForegroundColorSpan | ||
import android.view.View | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.recyclerview.widget.GridLayoutManager | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentOnboardingChoiceThemeBinding | ||
import com.sopetit.softie.ui.onboarding.OnboardingViewModel | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
|
||
class ChoiceThemeFragment : | ||
BindingFragment<FragmentOnboardingChoiceThemeBinding>(R.layout.fragment_onboarding_choice_theme) { | ||
|
||
private lateinit var viewModel: OnboardingViewModel | ||
private val themeViewModel by viewModels<ChoiceThemeViewModel>() | ||
|
||
private var _choiceThemeAdapter: ChoiceThemeAdapter? = null | ||
private val choiceThemeAdapter | ||
get() = requireNotNull(_choiceThemeAdapter) | ||
|
||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
viewModel = ViewModelProvider(requireActivity()).get(OnboardingViewModel::class.java) | ||
binding.viewModel = viewModel | ||
|
||
binding.tvOnboardingChoiceThemeSpeech.text = | ||
SpannableStringBuilder(getString(R.string.onboarding_choice_theme_speech)).apply { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setSpan이 멘트의 특정부분만 인덱싱해서 색을 바꾸는 부분인가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네! 이렇게 하면 textview를 여러개 만들 필요가 없습니당 |
||
setSpan( | ||
ForegroundColorSpan( | ||
ContextCompat.getColor( | ||
requireActivity(), | ||
R.color.onboarding_speech | ||
) | ||
), | ||
5, | ||
8, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매직 넘버 말고 companion로 빼주실 수 있을까요?! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네엡!! 이걸 pr 올리고 발견했네요.. |
||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
|
||
initMakeThemeAdapter() | ||
} | ||
|
||
private fun initMakeThemeAdapter() { | ||
_choiceThemeAdapter = ChoiceThemeAdapter() | ||
binding.rcvOnboardingChoiceTheme.apply { | ||
layoutManager = GridLayoutManager(requireContext(), 3) | ||
adapter = choiceThemeAdapter | ||
} | ||
themeViewModel.mockThemeList.observe(viewLifecycleOwner) { | ||
choiceThemeAdapter.submitList(it) | ||
} | ||
} | ||
|
||
private fun initChangeFragment() { | ||
// TODO 버튼 클릭시 '루틴 선택' fragment로 화면 전환 (밑의 주석 삭제 예정) | ||
// binding.clOnboardingChoiceTheme.setOnClickListener { | ||
// viewModel.changeRoutineChoiceView() | ||
// } | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍👍