-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#36 [ui] home 작업 #44
#36 [ui] home 작업 #44
Changes from 26 commits
b586eb1
5dcfa05
65619ee
eceb08c
81eda1a
36047e9
52f4858
0f10afb
6cdcbbb
9e7bc4f
8cc42c7
95415b7
9f0a7c3
487712a
310195b
4546d83
bd6bf17
63fa304
0100b3d
4a8447b
54067b7
21124c5
b0a1e0d
a35d4ea
f2953b4
0f97a04
7b16a35
eb9734a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
enum class Cotton { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DAILY와 HAPPINESS를 왜 enum으로 묶은 건가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 각 상황에 따라서 로직은 동일한데 넣는 파일이 달라서 분류해주려고 만들었습니다! |
||
DAILY, HAPPINESS | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class Home( | ||
val frameImageUrl: String, | ||
val name: String, | ||
val dollType: String, | ||
val dailyCottonCount: Int, | ||
val happinessCottonCount: Int, | ||
val conversations: List<String> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,127 @@ | ||
package com.sopetit.softie.ui.main.home | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.viewModels | ||
import com.sopetit.softie.R | ||
import com.sopetit.softie.databinding.FragmentHomeBinding | ||
import com.sopetit.softie.domain.entity.Cotton | ||
import com.sopetit.softie.ui.setting.SettingActivity | ||
import com.sopetit.softie.util.binding.BindingFragment | ||
import com.sopetit.softie.util.setStatusBarColor | ||
import kotlin.random.Random | ||
|
||
class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home) { | ||
private val viewModel by viewModels<HomeViewModel>() | ||
private val brownBearLottieList = | ||
listOf(R.raw.brown_hello, R.raw.brown_eating_daily, R.raw.brown_eating_happy) | ||
private val redBearLottieList = | ||
listOf(R.raw.red_hello, R.raw.red_eating_daily, R.raw.red_eating_happy) | ||
private val grayBearLottieList = | ||
listOf(R.raw.gray_hello, R.raw.gray_eating_daily, R.raw.gray_eating_happy) | ||
private val pandaBearLottieList = | ||
listOf(R.raw.panda_hello, R.raw.panda_eating_daily, R.raw.panda_eating_happy) | ||
private lateinit var userLottieList: List<Int> | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.viewModel = viewModel | ||
setStatusBarColor(R.color.home_background) | ||
|
||
setUserLottieList() | ||
initLottie() | ||
setClickListener() | ||
} | ||
|
||
private fun setUserLottieList() { | ||
viewModel.getHome() | ||
userLottieList = when (viewModel.homeResponse.value?.dollType) { | ||
"BROWN" -> brownBearLottieList | ||
"GRAY" -> grayBearLottieList | ||
"RED" -> redBearLottieList | ||
"PANDA" -> pandaBearLottieList | ||
else -> brownBearLottieList | ||
} | ||
} | ||
Comment on lines
+37
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리스트 형식과 switch도 좋지만 Map 형식은 어떤가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 찾아오겠습니다.! ! ! |
||
|
||
private fun initLottie() { | ||
binding.lottieHomeBear.setAnimation(userLottieList[HELLO]) | ||
setRandomMessage() | ||
} | ||
|
||
private fun setRandomMessage() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이러면 랜덤메세지는 서버에서 보내주는게 아니라 클라가 처리하게 되는건가용? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 랜덤 메세지 list를 받고 그 리스트 안에서 띄우는 건 클라가 처리합니다! |
||
val speechNum = viewModel.homeResponse.value?.conversations?.size ?: RUN_OUT | ||
val randomSpeech = Random.nextInt(START, speechNum) | ||
binding.tvHomeBearSpeech.text = | ||
viewModel.homeResponse.value?.conversations?.get(randomSpeech) | ||
} | ||
|
||
private fun setClickListener() { | ||
setClickSetting() | ||
setClickBear() | ||
setClickDaily() | ||
setClickHappy() | ||
} | ||
Comment on lines
+60
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수화란 이런것이군요..👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아앗 부끄럽다,,,😥 더 열심히 코드 짤게요,,, |
||
|
||
private fun setClickSetting() { | ||
binding.ivHomeSetting.setOnClickListener { | ||
val intentToSetting = Intent(activity, SettingActivity::class.java) | ||
startActivity(intentToSetting) | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 분리 좋아요! |
||
} | ||
} | ||
|
||
private fun setClickBear() { | ||
binding.lottieHomeBear.setOnClickListener { | ||
playLottieAnimation(userLottieList[HELLO]) | ||
setRandomMessage() | ||
} | ||
} | ||
|
||
private fun setClickDaily() { | ||
binding.clHomeSomWhite.setOnClickListener { | ||
checkCottonRemain(Cotton.DAILY) | ||
} | ||
} | ||
|
||
private fun setClickHappy() { | ||
binding.clHomeSomColor.setOnClickListener { | ||
checkCottonRemain(Cotton.HAPPINESS) | ||
} | ||
} | ||
|
||
private fun checkCottonRemain(cottonType: Cotton) { | ||
val isCottonRemain: (Int) -> Boolean = { cotton -> cotton > RUN_OUT } | ||
|
||
when (cottonType) { | ||
Cotton.DAILY -> { | ||
val cottonNum = viewModel.homeResponse.value?.dailyCottonCount ?: RUN_OUT | ||
if (isCottonRemain(cottonNum)) { | ||
viewModel.patchSom(cottonType) | ||
playLottieAnimation(userLottieList[DAILY]) | ||
Comment on lines
+100
to
+101
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2줄을 담당하는 메소드를 따로 지정하면 해당 메소드의 책임이 더 줄 수 있을 것 같아요! |
||
} | ||
} | ||
|
||
Cotton.HAPPINESS -> { | ||
val cottonNum = viewModel.homeResponse.value?.happinessCottonCount ?: RUN_OUT | ||
if (isCottonRemain(cottonNum)) { | ||
viewModel.patchSom(cottonType) | ||
playLottieAnimation(userLottieList[HAPPINESS]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun playLottieAnimation(lottieFile: Int) { | ||
binding.lottieHomeBear.setAnimation(lottieFile) | ||
binding.lottieHomeBear.playAnimation() | ||
} | ||
|
||
companion object { | ||
const val RUN_OUT = 0 | ||
val START = 0 | ||
val HELLO = 0 | ||
val DAILY = 1 | ||
val HAPPINESS = 2 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.sopetit.softie.ui.main.home | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.sopetit.softie.domain.entity.Cotton | ||
import com.sopetit.softie.domain.entity.Home | ||
import com.sopetit.softie.ui.main.home.HomeFragment.Companion.RUN_OUT | ||
|
||
class HomeViewModel : ViewModel() { | ||
private val _homeResponse = MutableLiveData<Home>() | ||
val homeResponse: LiveData<Home> get() = _homeResponse | ||
|
||
fun getHome() { | ||
_homeResponse.value = Home( | ||
frameImageUrl = "https://d2v80xjmx68n4w.cloudfront.net/gigs/vGe751615194459.jpg", | ||
name = "애착이", | ||
dollType = "PANDA", | ||
dailyCottonCount = 5, | ||
happinessCottonCount = 3, | ||
conversations = listOf("야", "메롱", "루틴이나 해", "솔직히 나 귀엽지", "안드로이드 사랑해", "나 소프티야") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ 기여엉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안드소프리티 사랑해 |
||
) | ||
} | ||
|
||
fun patchSom(cotton: Cotton) { | ||
val isCottonRemain: (Int) -> Boolean = { cotton -> cotton > RUN_OUT } | ||
val cottonCount = when (cotton) { | ||
Cotton.DAILY -> homeResponse.value?.dailyCottonCount ?: RUN_OUT | ||
Cotton.HAPPINESS -> homeResponse.value?.happinessCottonCount ?: RUN_OUT | ||
} | ||
|
||
if (isCottonRemain(cottonCount)) { | ||
val changeData = when (cotton) { | ||
Cotton.DAILY -> homeResponse.value?.copy(dailyCottonCount = cottonCount - 1) | ||
Cotton.HAPPINESS -> homeResponse.value?.copy(happinessCottonCount = cottonCount - 1) | ||
} | ||
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switch문만 담당하는 메소드를 따로 분리해서, 메소드를 호출하는 방식도 가독성에 좋을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. daily와 happiness가 반복되니까 따로 메소드로 빼주는 것도 좋을 것 같습니당 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 같은 줄 같지만 미묘하게 다릅니다! 변수로 넘겨서 처리하는 건 또 같은 얘기일 것 같아서 분리는 안했습니다만,,, 어디까지가 함수화가 좋을지 고민이 매번 됩니다 |
||
_homeResponse.value = changeData ?: homeResponse.value | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<group> | ||
<clip-path | ||
android:pathData="M0,0h24v24h-24z"/> | ||
<path | ||
android:pathData="M16.5,3.206C17.51,3.79 18.285,4.708 18.69,5.803C19.095,6.898 19.104,8.099 18.716,9.2C19.536,9.902 20.106,10.851 20.342,11.905C20.578,12.958 20.467,14.06 20.025,15.045C19.584,16.03 18.835,16.846 17.891,17.37C16.948,17.895 15.86,18.1 14.79,17.955C14.834,18.325 14.84,18.709 14.81,19.082C14.735,19.967 14.434,20.979 13.707,21.706C13.527,21.885 13.285,21.99 13.031,21.997C12.778,22.005 12.53,21.916 12.34,21.748C12.149,21.58 12.03,21.345 12.005,21.093C11.981,20.84 12.054,20.587 12.21,20.386L12.293,20.292C12.566,20.019 12.765,19.532 12.816,18.916C12.826,18.804 12.829,18.694 12.828,18.588C11.958,19.186 10.921,19.493 9.865,19.465C8.81,19.437 7.791,19.076 6.953,18.433C6.116,17.79 5.503,16.899 5.203,15.887C4.903,14.874 4.932,13.793 5.284,12.798C4.398,12.038 3.806,10.993 3.61,9.843C3.414,8.693 3.625,7.51 4.209,6.5C4.792,5.49 5.711,4.715 6.805,4.31C7.899,3.905 9.1,3.896 10.201,4.283C10.96,3.396 12.006,2.803 13.156,2.607C14.307,2.41 15.49,2.621 16.501,3.205L16.5,3.206ZM12,9.5C11.803,9.5 11.608,9.539 11.426,9.614C11.244,9.69 11.079,9.8 10.939,9.939C10.8,10.079 10.689,10.244 10.614,10.426C10.539,10.608 10.5,10.803 10.5,11C10.5,11.197 10.539,11.392 10.614,11.574C10.689,11.756 10.8,11.921 10.939,12.061C11.079,12.2 11.244,12.31 11.426,12.386C11.608,12.461 11.803,12.5 12,12.5C12.398,12.5 12.779,12.342 13.061,12.061C13.342,11.779 13.5,11.398 13.5,11C13.5,10.602 13.342,10.221 13.061,9.939C12.779,9.658 12.398,9.5 12,9.5Z" | ||
android:fillColor="#9FA4A9" | ||
android:fillType="evenOdd"/> | ||
</group> | ||
</vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainActivity랑 onboardingActivity는 false로 바꿔주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 감사합니다~