Skip to content

Commit

Permalink
Merge pull request #127 from Team-Sopetit/feature/#108-fix-issue-fix
Browse files Browse the repository at this point in the history
#108 [fix] 이슈 해결
  • Loading branch information
emjayMJkim authored Jan 19, 2024
2 parents 403aff4 + 60dd719 commit 6d0e599
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class RoutineChoiceAdapter : ListAdapter<Routine, RoutineChoiceAdapter.RoutineCh
val isRoutineNoticeVisible: LiveData<Boolean>
get() = _isRoutineNoticeVisible

var selectPosition = ArrayList<Int>()

inner class RoutineChoiceViewHolder(private val binding: ItemOnboardingChoiceRoutineBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: Routine) {
Expand Down Expand Up @@ -128,6 +130,36 @@ class RoutineChoiceAdapter : ListAdapter<Routine, RoutineChoiceAdapter.RoutineCh
}

override fun onBindViewHolder(holder: RoutineChoiceViewHolder, position: Int) {

// val binding: ItemOnboardingChoiceRoutineBinding =
// ItemOnboardingChoiceRoutineBinding.bind(holder.itemView)
// if (selectPosition.contains(position)) {
// binding.tvRoutineContent.setBackgroundResource(R.drawable.shape_gray100_fill_gray400_stroke_99_rect)
// } else {
// binding.tvRoutineContent.setBackgroundResource(R.drawable.shape_white_fill_gray000_stroke_99_rect)
// }
//
// binding.tvRoutineContent.setOnClickListener {
//
// if (selectedRoutineArray.size == MAXIMUM_ROUTINE_SELECTION) {
// if (selectPosition.contains(position)) {
// selectPosition.remove(position)
// setNoticeVisible(false)
// } else {
// setNoticeVisible(true)
// }
// } else {
// if (selectPosition.contains(position)) {
// selectPosition.remove(position)
// } else {
// selectedRoutineArray.add(position)
// }
// setNoticeVisible(false)
// }
//
// notifyItemChanged(position)
// }

holder.onBind(currentList[position])
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.sopetit.softie.ui.onboarding.routinechoice

import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import androidx.core.app.ActivityCompat
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.sopetit.softie.R
import com.sopetit.softie.databinding.FragmentOnboardingChoiceRoutineBinding
import com.sopetit.softie.ui.main.MainActivity
Expand Down Expand Up @@ -36,6 +38,7 @@ class RoutineChoiceFragment :
initSetThemeBackBtn()
initSetSelectRoutineBtn()
initMakeRoutineAdapter()
setItemDiv()
}

private fun initSetThemeBackBtn() {
Expand Down Expand Up @@ -98,6 +101,39 @@ class RoutineChoiceFragment :
}
}

class HorizontalItemDecorator(
private val marginTop: Int,
private val marginBottom: Int,
private val itemMargin: Int
) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)

val position = parent.getChildAdapterPosition(view)
val itemCount = parent.adapter?.itemCount ?: 0

if (position == 0) {
outRect.top = marginTop
outRect.bottom = itemMargin
} else if (position == itemCount - 1) {
outRect.top = itemMargin
outRect.bottom = marginBottom
} else {
outRect.top = itemMargin
outRect.bottom = itemMargin
}
}
}

private fun setItemDiv() {
binding.rvOnboardingChoiceRoutine.addItemDecoration(HorizontalItemDecorator(30, 30, 0))
}

private fun setRoutineBtn() {
viewModel.selectedRoutineArray.observe(viewLifecycleOwner) {
if (it.size > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.sopetit.softie.ui.setting

import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.text.SpannableStringBuilder
import android.text.Spanned
Expand All @@ -27,19 +25,14 @@ class SettingUserExitFragment :
BindingFragment<FragmentSettingUserExitBinding>(R.layout.fragment_setting_user_exit) {

private lateinit var viewModel: SettingViewModel
private lateinit var sharedPreferences: SharedPreferences

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel = ViewModelProvider(requireActivity()).get(SettingViewModel::class.java)
binding.viewModel = viewModel

sharedPreferences =
this.requireActivity().getSharedPreferences("user", Context.MODE_PRIVATE)
val bearType = sharedPreferences.getString("bearType", BROWN)

initSetBear(bearType)
initSetBear()
initSetSpeechText()
initSetClickBackBtn()
initSetClickExitBtn()
Expand All @@ -62,12 +55,15 @@ class SettingUserExitFragment :
}
}

private fun initSetBear(bearType: String?) {
when (bearType) {
BROWN -> setBearImage(R.drawable.ic_bear_brown_crying)
GRAY -> setBearImage(R.drawable.ic_bear_gray_crying)
RED -> setBearImage(R.drawable.ic_bear_red_crying)
WHITE -> setBearImage(R.drawable.ic_bear_panda_crying)
private fun initSetBear() {
viewModel.setCryingBearType()
viewModel.bearType.observe(viewLifecycleOwner) { bearType ->
when (bearType) {
BROWN -> setBearImage(R.drawable.ic_bear_brown_crying)
GRAY -> setBearImage(R.drawable.ic_bear_gray_crying)
RED -> setBearImage(R.drawable.ic_bear_red_crying)
WHITE -> setBearImage(R.drawable.ic_bear_panda_crying)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopetit.softie.domain.usecase.GetBearTypeUseCase
import com.sopetit.softie.domain.usecase.InitSIgnUpStateUseCase
import com.sopetit.softie.domain.usecase.InitTokenUseCase
import com.sopetit.softie.domain.usecase.auth.DeleteAuthUseCase
import com.sopetit.softie.domain.usecase.auth.LogOutUseCase
import com.sopetit.softie.ui.onboarding.OnboardingViewModel.Companion.BROWN
import com.sopetit.softie.ui.onboarding.OnboardingViewModel.Companion.GRAY
import com.sopetit.softie.ui.onboarding.OnboardingViewModel.Companion.RED
import com.sopetit.softie.ui.onboarding.OnboardingViewModel.Companion.WHITE
import com.sopetit.softie.ui.setting.SettingActivity.Companion.SETTING_INIT
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -19,7 +24,8 @@ class SettingViewModel @Inject constructor(
private val deleteAuthUseCase: DeleteAuthUseCase,
private val logOutUseCase: LogOutUseCase,
private val initSIgnUpStateUseCase: InitSIgnUpStateUseCase,
private val initTokenUseCase: InitTokenUseCase
private val initTokenUseCase: InitTokenUseCase,
private val getBearTypeUseCase: GetBearTypeUseCase
) : ViewModel() {

private val _settingFragment: MutableLiveData<String> = MutableLiveData(SETTING_INIT)
Expand All @@ -34,10 +40,24 @@ class SettingViewModel @Inject constructor(
val isLogOutResponse: LiveData<Boolean>
get() = _isLogOutResponse

private val _bearType: MutableLiveData<String> = MutableLiveData()
val bearType: LiveData<String>
get() = _bearType

fun setSettingFragment(clickFragment: String) {
_settingFragment.value = clickFragment
}

fun setCryingBearType() {
when (getBearTypeUseCase()) {
BROWN -> _bearType.value = BROWN
GRAY -> _bearType.value = GRAY
RED -> _bearType.value = RED
WHITE -> _bearType.value = WHITE
else -> _bearType.value = BROWN
}
}

fun setDeleteAuth() {
viewModelScope.launch {
deleteAuthUseCase()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_setting_init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_marginTop="24dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
Expand Down

0 comments on commit 6d0e599

Please sign in to comment.