-
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.
Browse files
Browse the repository at this point in the history
…-routine #7 [ui] 온보딩 - 테마 선택 뷰
- Loading branch information
Showing
25 changed files
with
772 additions
and
5 deletions.
There are no files selected for viewing
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
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,8 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class Theme( | ||
val themeId: Int, | ||
val name: String, | ||
val iconImageUrl: String, | ||
val backgroudnImageUrl: String | ||
) |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/sopetit/softie/ui/onboarding/BearChoiceFragment.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,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() | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/sopetit/softie/ui/onboarding/OnboardingActivity.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,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) { bearNameChoice -> | ||
if (bearNameChoice) { | ||
changeFragment(SetBearNameFragment()) | ||
} | ||
} | ||
} | ||
|
||
private fun initChangeThemeChoice() { | ||
viewModel.themeChoiceView.observe(this) { themeChoiceView -> | ||
if (themeChoiceView) { | ||
changeFragment(ChoiceThemeFragment()) | ||
} | ||
} | ||
} | ||
|
||
private fun initChangeRoutineChoice() { | ||
viewModel.routineChoiceView.observe(this) { routineChoiceView -> | ||
if (routineChoiceView) { | ||
changeFragment(RoutineChoiceFragment()) | ||
} | ||
} | ||
} | ||
|
||
private fun changeFragment(fragment: Fragment) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.fcv_onboarding_fragment, fragment) | ||
.commit() | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/sopetit/softie/ui/onboarding/OnboardingViewModel.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,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 | ||
} | ||
|
||
fun changeRoutineChoiceView() { | ||
_routineChoiceView.value = true | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/sopetit/softie/ui/onboarding/SetBearNameFragment.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,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() | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sopetit/softie/ui/onboarding/routinechoice/RoutineChoiceFragment.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,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) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/sopetit/softie/ui/onboarding/themechoice/ChoiceThemeAdapter.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,38 @@ | ||
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]) | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/sopetit/softie/ui/onboarding/themechoice/ChoiceThemeFragment.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,73 @@ | ||
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 { | ||
setSpan( | ||
ForegroundColorSpan( | ||
ContextCompat.getColor( | ||
requireActivity(), | ||
R.color.onboarding_speech | ||
) | ||
), | ||
SPAN_START, | ||
SPAN_END, | ||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
|
||
initMakeThemeAdapter() | ||
} | ||
|
||
private fun initMakeThemeAdapter() { | ||
_choiceThemeAdapter = ChoiceThemeAdapter() | ||
binding.rvOnboardingChoiceTheme.apply { | ||
layoutManager = GridLayoutManager(requireContext(), 3) | ||
adapter = choiceThemeAdapter | ||
} | ||
themeViewModel.mockThemeList.observe(viewLifecycleOwner) { | ||
choiceThemeAdapter.submitList(it) | ||
} | ||
} | ||
|
||
private fun initChangeFragment() { | ||
// TODO 버튼 클릭시 '루틴 선택' fragment로 화면 전환 (밑의 주석 삭제 예정) | ||
// binding.clOnboardingChoiceTheme.setOnClickListener { | ||
// viewModel.changeRoutineChoiceView() | ||
// } | ||
} | ||
|
||
companion object { | ||
const val SPAN_START = 5 | ||
const val SPAN_END = 8 | ||
} | ||
} |
Oops, something went wrong.