-
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
…view #52 [fix] 행복루틴 엠티뷰 서버 연결
- Loading branch information
Showing
9 changed files
with
159 additions
and
15 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
36 changes: 29 additions & 7 deletions
36
app/src/main/java/com/sopetit/softie/ui/happyroutine/HappyRoutineFragment.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 |
---|---|---|
@@ -1,27 +1,49 @@ | ||
package com.sopetit.softie.ui.happyroutine | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.viewModels | ||
import coil.load | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentHappyRoutineBinding | ||
import com.sopetit.softie.ui.happyroutine.list.HappyAddListActivity | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
import com.sopetit.softie.util.setStatusBarColor | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class HappyRoutineFragment : | ||
BindingFragment<FragmentHappyRoutineBinding>(R.layout.fragment_happy_routine) { | ||
|
||
private val viewModel by viewModels<HappyRoutineViewModel>() | ||
lateinit var sharedPreferences: SharedPreferences | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setStatusBarColor(R.color.background) | ||
|
||
setClickEmptyCardListener() | ||
sharedPreferences = | ||
this.requireActivity().getSharedPreferences("user", Context.MODE_PRIVATE) | ||
val bearType = sharedPreferences.getString("bearType", "BROWN") | ||
|
||
initSetBearFace(bearType) | ||
setCardEnter() | ||
} | ||
|
||
private fun initSetBearFace(dollType: String?) { | ||
if (dollType != null) { | ||
viewModel.setDollFace(dollType) | ||
viewModel.bearFace.observe(viewLifecycleOwner) { bearFace -> | ||
binding.ivHappyRoutineCharacter.load(bearFace) | ||
} | ||
} | ||
} | ||
|
||
private fun setClickEmptyCardListener() { | ||
binding.clHappyRoutineEmptyCard.setOnClickListener { | ||
val intentToHappyAddList = Intent(activity, HappyAddListActivity::class.java) | ||
startActivity(intentToHappyAddList) | ||
private fun setCardEnter() { | ||
binding.ivHappyRoutineEmptyCard.setOnClickListener { | ||
val intent = Intent(requireContext(), HappyAddListActivity::class.java) | ||
startActivity(intent) | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/sopetit/softie/ui/happyroutine/HappyRoutineViewModel.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,37 @@ | ||
package com.sopetit.softie.ui.happyroutine | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.sopetit.softie.domain.usecase.doll.GetDollUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class HappyRoutineViewModel @Inject constructor( | ||
private val getDollUseCase: GetDollUseCase | ||
) : ViewModel() { | ||
private val _bearFace: MutableLiveData<String> = MutableLiveData() | ||
val bearFace: LiveData<String> | ||
get() = _bearFace | ||
|
||
fun setDollFace(type: String) { | ||
viewModelScope.launch { | ||
when (type) { | ||
"BROWN" -> getDollUseCase.invoke(type) | ||
"GRAY" -> getDollUseCase.invoke(type) | ||
"PANDA" -> getDollUseCase.invoke(type) | ||
"RED" -> getDollUseCase.invoke(type) | ||
else -> getDollUseCase.invoke("BROWN") | ||
}.onSuccess { response -> | ||
_bearFace.value = response | ||
Timber.d("곰돌이 서버 통신 성공 -> $response") | ||
}.onFailure { | ||
Timber.e("곰돌이 서버 통신 실패 -> ${it.message}") | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.