Skip to content

Commit

Permalink
Merge pull request #28 from Team-Sopetit/feature/#25-onboarding-theme…
Browse files Browse the repository at this point in the history
…-fix

#25 [fix] 온보딩 테마 선택 뷰 이슈 해결
  • Loading branch information
emjayMJkim authored Jan 11, 2024
2 parents 1cc529c + 502b423 commit dad8192
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.sopetit.softie.ui.onboarding

import android.os.Bundle
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ActivityOnboardingBinding
Expand Down Expand Up @@ -53,10 +57,49 @@ class OnboardingActivity :
if (themeChoiceView) {
changeFragment(ChoiceThemeFragment())
viewModel.setLayoutTranslucent(true)
initSetSpeechText()
initSetTranslucentBackground()
changeSecondThemeChoice()
}
}
}

private fun changeSecondThemeChoice() {
viewModel.secondThemeChoiceView.observe(this) { isSecondThemeView ->
if (isSecondThemeView) {
changeFragment(ChoiceThemeFragment())
viewModel.setLayoutTranslucent(false)
viewModel.changeRoutineChoiceView(false)
}
}
}

private fun initSetSpeechText() {
val nickname = viewModel.bearNickname.value ?: ""
val message = getString(R.string.onboarding_choice_theme_speech).format(nickname)

binding.tvOnboardingThemeSpeech.text =
SpannableStringBuilder(message).apply {
setSpan(
ForegroundColorSpan(
ContextCompat.getColor(
binding.root.context,
R.color.onboarding_speech
)
),
SPAN_START,
SPAN_START + nickname.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}

private fun initSetTranslucentBackground() {
binding.clOnboardingThemeTranslucentBackgroundContent.setOnClickListener {
viewModel.setLayoutTranslucent(false)
}
}

private fun initChangeRoutineChoice() {
viewModel.routineChoiceView.observe(this) { routineChoiceView ->
if (routineChoiceView) {
Expand All @@ -70,4 +113,9 @@ class OnboardingActivity :
.replace(R.id.fcv_onboarding_fragment, fragment)
.commit()
}

companion object {
const val SPAN_START = 5
const val MAXIMUM_THEME_SELECTION = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class OnboardingViewModel : ViewModel() {
val themeChoiceView: LiveData<Boolean>
get() = _themeChoiceView

private val _secondThemeChoiceView: MutableLiveData<Boolean> = MutableLiveData(false)
val secondThemeChoiceView: LiveData<Boolean>
get() = _secondThemeChoiceView

private val _routineChoiceView: MutableLiveData<Boolean> = MutableLiveData(false)
val routineChoiceView: LiveData<Boolean>
get() = _routineChoiceView
Expand All @@ -26,6 +30,10 @@ class OnboardingViewModel : ViewModel() {
val selectedThemeArray: LiveData<ArrayList<Int>>
get() = _selectedThemeArray

private val _selectedRoutineArray: MutableLiveData<ArrayList<Int>> = MutableLiveData()
val selectedRoutineArray: LiveData<ArrayList<Int>>
get() = _selectedRoutineArray

private val _layoutTranslucent: MutableLiveData<Boolean> = MutableLiveData(false)
val layoutTranslucent: LiveData<Boolean>
get() = _layoutTranslucent
Expand All @@ -48,14 +56,22 @@ class OnboardingViewModel : ViewModel() {
_themeChoiceView.value = true
}

fun changeRoutineChoiceView() {
_routineChoiceView.value = true
fun changeSecondThemeChoiceView() {
_secondThemeChoiceView.value = true
}

fun changeRoutineChoiceView(isRoutineChoice: Boolean) {
_routineChoiceView.value = isRoutineChoice
}

fun setSelectedThemeArray(themeArray: ArrayList<Int>) {
_selectedThemeArray.value = themeArray
}

fun setSelectedRoutineArray(routineArray: ArrayList<Int>) {
_selectedRoutineArray.value = routineArray
}

fun setLayoutTranslucent(boolean: Boolean) {
_layoutTranslucent.value = boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RoutineChoiceFragment :

private fun initSetThemeBackBtn() {
binding.btnOnboardingRoutineBackTheme.setOnClickListener {
viewModel.changeThemeChoiceView()
viewModel.changeSecondThemeChoiceView()
}
}

Expand Down Expand Up @@ -79,8 +79,19 @@ class RoutineChoiceFragment :

private fun selectRoutines() {
choiceRoutineAdapter.setOnRoutineClickListener {
Timber.d("routineChoice: routine -> ${choiceRoutineAdapter.selectedRoutineArray}")
viewModel.setSelectedRoutineArray(choiceRoutineAdapter.selectedRoutineArray)
setNoticeVisible()
setRoutineBtn()
}
}

private fun setRoutineBtn() {
viewModel.selectedRoutineArray.observe(viewLifecycleOwner) {
if (it.size > 0) {
routineViewModel.setRoutineBtnEnabled(true)
} else {
routineViewModel.setRoutineBtnEnabled(false)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ class RoutineChoiceViewModel : ViewModel() {
val isNoticeVisible: LiveData<Boolean>
get() = _isNoticeVisible

private val _isRoutineBtnEnabled: MutableLiveData<Boolean> = MutableLiveData()
val isRoutineBtnEnabled: LiveData<Boolean>
get() = _isRoutineBtnEnabled

fun setNoticeVisible(visible: Boolean) {
_isNoticeVisible.value = visible
}

fun setRoutineBtnEnabled(isEnabled: Boolean) {
_isRoutineBtnEnabled.value = isEnabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ItemOnboardingChoiceThemeBinding
import com.sopetit.softie.domain.entity.Theme
import com.sopetit.softie.ui.onboarding.themechoice.ChoiceThemeFragment.Companion.MAXIMUM_THEME_SELECTION
import com.sopetit.softie.ui.onboarding.OnboardingActivity.Companion.MAXIMUM_THEME_SELECTION
import com.sopetit.softie.util.ItemDiffCallback
import com.sopetit.softie.util.toast

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
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.OnboardingActivity.Companion.MAXIMUM_THEME_SELECTION
import com.sopetit.softie.ui.onboarding.OnboardingViewModel
import com.sopetit.softie.util.binding.BindingFragment

Expand All @@ -31,39 +28,10 @@ class ChoiceThemeFragment :
binding.viewModel = viewModel
binding.themeViewModel = themeViewModel

initSetTranslucentBackground()
initSetSpeechText()
initMakeThemeAdapter()
initChangeFragment()
}

private fun initSetTranslucentBackground() {
binding.clOnboardingChoiceThemeTranslucentBackground.setOnClickListener {
themeViewModel.setLayoutTranslucent(false)
viewModel.setLayoutTranslucent(false)
}
}

private fun initSetSpeechText() {
val nickname = viewModel.bearNickname.value ?: ""
val message = getString(R.string.onboarding_choice_theme_speech).format(nickname)

binding.tvOnboardingChoiceThemeSpeech.text =
SpannableStringBuilder(message).apply {
setSpan(
ForegroundColorSpan(
ContextCompat.getColor(
requireActivity(),
R.color.onboarding_speech
)
),
SPAN_START,
SPAN_START + nickname.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}

private fun initMakeThemeAdapter() {
_choiceThemeAdapter = ChoiceThemeAdapter()
binding.rvOnboardingChoiceTheme.apply {
Expand Down Expand Up @@ -98,7 +66,7 @@ class ChoiceThemeFragment :
themeViewModel.themeBtnEnabled.observe(viewLifecycleOwner) {
if (it) {
binding.btnOnboardingChoiceTheme.setOnClickListener {
viewModel.changeRoutineChoiceView()
viewModel.changeRoutineChoiceView(true)
}
}
}
Expand All @@ -108,9 +76,4 @@ class ChoiceThemeFragment :
super.onDestroyView()
_choiceThemeAdapter = null
}

companion object {
const val SPAN_START = 5
const val MAXIMUM_THEME_SELECTION = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,4 @@ class ChoiceThemeViewModel : ViewModel() {
fun setThemeBtnEnabled(boolean: Boolean) {
_themeBtnEnabled.value = boolean
}

private val _layoutTranslucent: MutableLiveData<Boolean> = MutableLiveData(true)
val layoutTranslucent: LiveData<Boolean>
get() = _layoutTranslucent

fun setLayoutTranslucent(boolean: Boolean) {
_layoutTranslucent.value = boolean
}
}
62 changes: 51 additions & 11 deletions app/src/main/res/layout/activity_onboarding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,6 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_onboarding_choice_theme_translucent_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/onboarding_translucent"
android:visibility="@{viewModel.layoutTranslucent ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="@id/cl_onboarding_top_bar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/fcv_onboarding_fragment"
android:layout_width="0dp"
Expand All @@ -92,5 +81,56 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cl_onboarding_top_bar" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_onboarding_theme_translucent_background_content"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/onboarding_translucent"
android:visibility="@{viewModel.layoutTranslucent ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="@id/fcv_onboarding_fragment"
app:layout_constraintEnd_toEndOf="@id/fcv_onboarding_fragment"
app:layout_constraintBottom_toBottomOf="@id/fcv_onboarding_fragment" />

<ImageView
android:id="@+id/iv_onboarding_theme_title_bear"
android:layout_width="53dp"
android:layout_height="50dp"
android:src="@drawable/ic_bear_face_1"
android:layout_marginTop="34dp"
android:layout_marginStart="22dp"
android:visibility="@{viewModel.layoutTranslucent ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="@id/cl_onboarding_top_bar"
app:layout_constraintStart_toStartOf="parent" />

<ImageView
android:id="@+id/iv_onboarding_theme_speech_background"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_marginTop="29dp"
android:layout_marginStart="14dp"
android:layout_marginEnd="23dp"
android:background="@drawable/ic_speech_long"
android:visibility="@{viewModel.layoutTranslucent ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toBottomOf="@id/cl_onboarding_top_bar"
app:layout_constraintStart_toEndOf="@id/iv_onboarding_theme_title_bear"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/tv_onboarding_theme_speech"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="14dp"
android:text="@{viewModel.layoutTranslucent ? @string/onboarding_choice_theme_speech(viewModel.bearNickname) : @string/onboarding_choice_theme_speech_after}"
android:visibility="@{viewModel.layoutTranslucent ? View.VISIBLE : View.GONE}"
android:textColor="@color/gray700"
android:textAppearance="@style/bubble16"
android:bufferType="spannable"
app:layout_constraintTop_toTopOf="@id/iv_onboarding_theme_speech_background"
app:layout_constraintBottom_toBottomOf="@id/iv_onboarding_theme_speech_background"
app:layout_constraintStart_toStartOf="@id/iv_onboarding_theme_speech_background"
app:layout_constraintEnd_toEndOf="@id/iv_onboarding_theme_speech_background" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@
android:text="@string/onboarding_routine_select_btn"
android:textAppearance="@style/body1"
android:textColor="@color/gray000"
android:background="@drawable/shape_main1_fill_12_rect"
android:layout_marginStart="10dp"
android:background="@{routineViewModel.isRoutineBtnEnabled ? @drawable/shape_main1_fill_12_rect : @drawable/shape_gray200_fill_12_rect}"
android:enabled="@{routineViewModel.isRoutineBtnEnabled ? true : false}"
android:clickable="@{routineViewModel.isRoutineBtnEnabled ? true : false}"
app:layout_constraintTop_toTopOf="@id/btn_onboarding_routine_back_theme"
app:layout_constraintBottom_toBottomOf="@id/btn_onboarding_routine_back_theme"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
13 changes: 1 addition & 12 deletions app/src/main/res/layout/fragment_onboarding_choice_theme.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_onboarding_choice_theme_translucent_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/onboarding_translucent"
android:visibility="@{themeViewModel.layoutTranslucent ? View.VISIBLE : View.GONE}"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<ImageView
android:id="@+id/iv_onboarding_choice_theme_title_bear"
android:layout_width="53dp"
Expand Down Expand Up @@ -88,7 +77,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="14dp"
android:text="@{themeViewModel.layoutTranslucent ? @string/onboarding_choice_theme_speech(viewModel.bearNickname) : @string/onboarding_choice_theme_speech_after}"
android:text="@string/onboarding_choice_theme_speech_after"
android:textColor="@color/gray700"
android:textAppearance="@style/bubble16"
android:bufferType="spannable"
Expand Down

0 comments on commit dad8192

Please sign in to comment.