Skip to content

Commit 5ebb953

Browse files
authored
Merge pull request #59 from Team-Sopetit/feature/#52-fix-happy-empty-view
#52 [fix] 행복루틴 엠티뷰 서버 연결
2 parents 152802a + a19b291 commit 5ebb953

File tree

9 files changed

+159
-15
lines changed

9 files changed

+159
-15
lines changed

app/src/main/java/com/sopetit/softie/di/RepositoryModule.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ abstract class RepositoryModule {
2323
memberRepositoryImpl: MemberRepositoryImpl
2424
): MemberRepository
2525

26-
/*@Binds
27-
@Singleton
28-
abstract fun bindToHappyCardRepository(
29-
happinessRoutineRepositoryImpl: HappinessRoutineRepositoryImpl
30-
): HappinessRoutineRepository*/
31-
3226
@Binds
3327
@Singleton
3428
abstract fun bindToDailyRoutineRepository(
Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
package com.sopetit.softie.ui.happyroutine
22

3+
import android.content.Context
34
import android.content.Intent
5+
import android.content.SharedPreferences
46
import android.os.Bundle
57
import android.view.View
8+
import androidx.fragment.app.viewModels
9+
import coil.load
610
import com.sopetit.softie.R
711
import com.sopetit.softie.databinding.FragmentHappyRoutineBinding
812
import com.sopetit.softie.ui.happyroutine.list.HappyAddListActivity
913
import com.sopetit.softie.util.binding.BindingFragment
10-
import com.sopetit.softie.util.setStatusBarColor
14+
import dagger.hilt.android.AndroidEntryPoint
1115

16+
@AndroidEntryPoint
1217
class HappyRoutineFragment :
1318
BindingFragment<FragmentHappyRoutineBinding>(R.layout.fragment_happy_routine) {
19+
20+
private val viewModel by viewModels<HappyRoutineViewModel>()
21+
lateinit var sharedPreferences: SharedPreferences
22+
1423
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
1524
super.onViewCreated(view, savedInstanceState)
16-
setStatusBarColor(R.color.background)
1725

18-
setClickEmptyCardListener()
26+
sharedPreferences =
27+
this.requireActivity().getSharedPreferences("user", Context.MODE_PRIVATE)
28+
val bearType = sharedPreferences.getString("bearType", "BROWN")
29+
30+
initSetBearFace(bearType)
31+
setCardEnter()
32+
}
33+
34+
private fun initSetBearFace(dollType: String?) {
35+
if (dollType != null) {
36+
viewModel.setDollFace(dollType)
37+
viewModel.bearFace.observe(viewLifecycleOwner) { bearFace ->
38+
binding.ivHappyRoutineCharacter.load(bearFace)
39+
}
40+
}
1941
}
2042

21-
private fun setClickEmptyCardListener() {
22-
binding.clHappyRoutineEmptyCard.setOnClickListener {
23-
val intentToHappyAddList = Intent(activity, HappyAddListActivity::class.java)
24-
startActivity(intentToHappyAddList)
43+
private fun setCardEnter() {
44+
binding.ivHappyRoutineEmptyCard.setOnClickListener {
45+
val intent = Intent(requireContext(), HappyAddListActivity::class.java)
46+
startActivity(intent)
2547
}
2648
}
2749
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.sopetit.softie.ui.happyroutine
2+
3+
import androidx.lifecycle.LiveData
4+
import androidx.lifecycle.MutableLiveData
5+
import androidx.lifecycle.ViewModel
6+
import androidx.lifecycle.viewModelScope
7+
import com.sopetit.softie.domain.usecase.doll.GetDollUseCase
8+
import dagger.hilt.android.lifecycle.HiltViewModel
9+
import kotlinx.coroutines.launch
10+
import timber.log.Timber
11+
import javax.inject.Inject
12+
13+
@HiltViewModel
14+
class HappyRoutineViewModel @Inject constructor(
15+
private val getDollUseCase: GetDollUseCase
16+
) : ViewModel() {
17+
private val _bearFace: MutableLiveData<String> = MutableLiveData()
18+
val bearFace: LiveData<String>
19+
get() = _bearFace
20+
21+
fun setDollFace(type: String) {
22+
viewModelScope.launch {
23+
when (type) {
24+
"BROWN" -> getDollUseCase.invoke(type)
25+
"GRAY" -> getDollUseCase.invoke(type)
26+
"PANDA" -> getDollUseCase.invoke(type)
27+
"RED" -> getDollUseCase.invoke(type)
28+
else -> getDollUseCase.invoke("BROWN")
29+
}.onSuccess { response ->
30+
_bearFace.value = response
31+
Timber.d("곰돌이 서버 통신 성공 -> $response")
32+
}.onFailure {
33+
Timber.e("곰돌이 서버 통신 실패 -> ${it.message}")
34+
}
35+
}
36+
}
37+
}

app/src/main/java/com/sopetit/softie/ui/main/home/HomeFragment.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.sopetit.softie.ui.main.home
22

3+
import android.content.Context
34
import android.content.Intent
5+
import android.content.SharedPreferences
46
import android.os.Bundle
57
import android.view.View
68
import androidx.fragment.app.viewModels
@@ -25,6 +27,7 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
2527
private val pandaBearLottieList =
2628
listOf(R.raw.panda_hello, R.raw.panda_eating_daily, R.raw.panda_eating_happy)
2729
private lateinit var userLottieList: List<Int>
30+
private lateinit var sharedPreferences: SharedPreferences
2831

2932
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3033
super.onViewCreated(view, savedInstanceState)
@@ -35,6 +38,10 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
3538
initLottie()
3639
setClickListener()
3740
setObserveHomeResponse()
41+
sharedPreferences =
42+
this.requireActivity().getSharedPreferences("user", Context.MODE_PRIVATE)
43+
sharedPreferences.edit()
44+
.putString("bearType", viewModel.homeResponse.value?.dollType ?: "BROWN").commit()
3845
}
3946

4047
private fun setUserLottieList() {

app/src/main/java/com/sopetit/softie/ui/main/home/HomeViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.sopetit.softie.domain.entity.Cotton
88
import com.sopetit.softie.domain.entity.Home
99
import com.sopetit.softie.domain.usecase.GetHomeUseCase
1010
import com.sopetit.softie.domain.usecase.PatchCottonUseCase
11+
import com.sopetit.softie.domain.usecase.doll.GetDollUseCase
1112
import com.sopetit.softie.ui.main.home.HomeFragment.Companion.RUN_OUT
1213
import dagger.hilt.android.lifecycle.HiltViewModel
1314
import kotlinx.coroutines.launch
@@ -17,7 +18,8 @@ import javax.inject.Inject
1718
@HiltViewModel
1819
class HomeViewModel @Inject constructor(
1920
private val getHomeUseCase: GetHomeUseCase,
20-
private val patchCottonUseCase: PatchCottonUseCase
21+
private val patchCottonUseCase: PatchCottonUseCase,
22+
private val getDollUseCase: GetDollUseCase
2123
) : ViewModel() {
2224
private val _homeResponse = MutableLiveData<Home>()
2325
val homeResponse: LiveData<Home> get() = _homeResponse

0 commit comments

Comments
 (0)