-
Notifications
You must be signed in to change notification settings - Fork 2
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
[UI/#21] 성향테스트뷰 UI / Animation 구현 #23
Changes from all commits
3d008d9
47bd2c4
424376a
5d234d4
94be11d
4fb145e
9a0383f
fbecdfa
1d27f1a
a725099
89a12cd
df76d6e
2f1c49b
378716a
e460a3e
6b270ec
b61be93
21f1b69
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,9 @@ | ||
package com.going.domain.entity | ||
|
||
data class TendencyTestMock( | ||
val question: String, | ||
val firstAnswer: String, | ||
val secondAnswer: String, | ||
val thirdAnswer: String, | ||
val fourthAnswer: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,121 @@ | ||
package com.going.presentation.tendencytest | ||
|
||
import android.animation.Animator | ||
import android.animation.ObjectAnimator | ||
import android.os.Bundle | ||
import android.view.animation.DecelerateInterpolator | ||
import android.widget.ProgressBar | ||
import androidx.activity.viewModels | ||
import com.going.presentation.R | ||
import com.going.presentation.databinding.ActivityTendencyTestSplashBinding | ||
import com.going.presentation.databinding.ActivityTendencyTestBinding | ||
import com.going.ui.base.BaseActivity | ||
import com.going.ui.extension.setOnSingleClickListener | ||
|
||
class TendencyTestActivity : | ||
BaseActivity<ActivityTendencyTestSplashBinding>(R.layout.activity_tendency_test_splash) { | ||
BaseActivity<ActivityTendencyTestBinding>(R.layout.activity_tendency_test) { | ||
|
||
private lateinit var fadeInList: List<ObjectAnimator> | ||
private lateinit var fadeOutList: List<ObjectAnimator> | ||
|
||
private val viewModel by viewModels<TendencyTestViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initStartBtnSingleClickListener() | ||
initBindingViewModel() | ||
initFadeAnimation() | ||
initFadeListener() | ||
initNextBtnClickListener() | ||
} | ||
|
||
private fun initBindingViewModel() { | ||
binding.viewModel = viewModel | ||
} | ||
|
||
private fun initFadeAnimation() { | ||
fadeOutList = listOf<ObjectAnimator>( | ||
ObjectAnimator.ofFloat(binding.tvFirstAnswer, "alpha", 1f, 0f).apply { | ||
duration = DURATION | ||
}, | ||
ObjectAnimator.ofFloat(binding.tvSecondAnswer, "alpha", 1f, 0f).apply { | ||
duration = DURATION | ||
}, | ||
ObjectAnimator.ofFloat(binding.tvThirdAnswer, "alpha", 1f, 0f).apply { | ||
duration = DURATION | ||
}, | ||
ObjectAnimator.ofFloat(binding.tvFourthAnswer, "alpha", 1f, 0f).apply { | ||
duration = DURATION | ||
}, | ||
) | ||
|
||
fadeInList = listOf<ObjectAnimator>( | ||
ObjectAnimator.ofFloat(binding.tvFirstAnswer, "alpha", 0f, 1f).apply { | ||
duration = DURATION | ||
}, | ||
ObjectAnimator.ofFloat(binding.tvSecondAnswer, "alpha", 0f, 1f).apply { | ||
duration = DURATION | ||
}, | ||
ObjectAnimator.ofFloat(binding.tvThirdAnswer, "alpha", 0f, 1f).apply { | ||
duration = DURATION | ||
}, | ||
ObjectAnimator.ofFloat(binding.tvFourthAnswer, "alpha", 0f, 1f).apply { | ||
duration = DURATION | ||
}, | ||
) | ||
} | ||
|
||
private fun initFadeListener() { | ||
fadeOutList[0].addListener( | ||
object : Animator.AnimatorListener { | ||
override fun onAnimationStart(animation: Animator) { | ||
viewModel.clearAllChecked() | ||
setProgressAnimate(binding.pbTendencyTest, viewModel.step.value + 1) | ||
fadeOutList.map { | ||
it.start() | ||
} | ||
} | ||
|
||
override fun onAnimationEnd(animation: Animator) { | ||
viewModel.plusStepValue() | ||
|
||
fadeInList.map { | ||
it.start() | ||
} | ||
} | ||
|
||
override fun onAnimationCancel(animation: Animator) { | ||
// | ||
} | ||
|
||
override fun onAnimationRepeat(animation: Animator) { | ||
// | ||
} | ||
}, | ||
) | ||
} | ||
|
||
private fun initStartBtnSingleClickListener() { | ||
binding.btnTendencySplashStart.setOnSingleClickListener { | ||
// 페이지 이동~ | ||
private fun setProgressAnimate(pb: ProgressBar, progressTo: Int) = | ||
ObjectAnimator.ofInt(pb, "progress", pb.progress, progressTo * 100).apply { | ||
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. "progress" 같은 친구들도 const val로 표시해두면 좋을듯요! 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. 아 깜빡하고 안했네요!! 수정 완료했습니다 |
||
duration = DURATION | ||
setAutoCancel(true) | ||
interpolator = DecelerateInterpolator() | ||
start() | ||
} | ||
|
||
private fun initNextBtnClickListener() { | ||
binding.btnTendencyNext.setOnSingleClickListener { | ||
when (viewModel.step.value) { | ||
9 -> moveTendencyTestResultActivity() | ||
else -> fadeOutList[0].start() | ||
} | ||
} | ||
} | ||
|
||
private fun moveTendencyTestResultActivity() { | ||
// 페이지 이동 기능 추가 예정 | ||
} | ||
|
||
companion object { | ||
const val DURATION = 500L | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.going.presentation.tendencytest | ||
|
||
import android.os.Bundle | ||
import com.going.presentation.R | ||
import com.going.presentation.databinding.ActivityTendencyTestSplashBinding | ||
import com.going.ui.base.BaseActivity | ||
import com.going.ui.extension.setOnSingleClickListener | ||
|
||
class TendencyTestSplashActivity : | ||
BaseActivity<ActivityTendencyTestSplashBinding>(R.layout.activity_tendency_test_splash) { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initStartBtnSingleClickListener() | ||
} | ||
|
||
private fun initStartBtnSingleClickListener() { | ||
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. 싱글클릭 말고 다른 리스너 달거 아니면 initStartBtnClickListener로 수정해주셍요 ~ 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. 이게 더 좋은 방법이네요! |
||
binding.btnTendencySplashStart.setOnSingleClickListener { | ||
// 페이지 이동~ | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.going.presentation.tendencytest | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.going.domain.entity.TendencyTestMock | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
|
||
class TendencyTestViewModel : ViewModel() { | ||
val step = MutableStateFlow(1) | ||
val isChecked = MutableLiveData(false) | ||
val isFirstChecked = MutableLiveData(false) | ||
val isSecondChecked = MutableLiveData(false) | ||
val isThirdChecked = MutableLiveData(false) | ||
val isFourthChecked = MutableLiveData(false) | ||
|
||
val tendencyResultList: MutableList<Int> = MutableList(9) { 0 } | ||
|
||
val mockList: List<TendencyTestMock> = listOf( | ||
TendencyTestMock( | ||
"1번 문항", | ||
"1-1", | ||
"1-2", | ||
"1-3", | ||
"1-4", | ||
), | ||
TendencyTestMock( | ||
"2번 문항", | ||
"2-1", | ||
"2-2", | ||
"2-3", | ||
"2-4", | ||
), | ||
TendencyTestMock( | ||
"3번 문항", | ||
"3-1", | ||
"3-2", | ||
"3-3", | ||
"3-4", | ||
), | ||
TendencyTestMock( | ||
"4번 문항", | ||
"4-1", | ||
"4-2", | ||
"4-3", | ||
"4-4", | ||
), | ||
TendencyTestMock( | ||
"5번 문항", | ||
"5-1", | ||
"5-2", | ||
"5-3", | ||
"5-4", | ||
), | ||
TendencyTestMock( | ||
"6번 문항", | ||
"6-1", | ||
"6-2", | ||
"6-3", | ||
"6-4", | ||
), | ||
TendencyTestMock( | ||
"7번 문항", | ||
"7-1", | ||
"7-2", | ||
"7-3", | ||
"7-4", | ||
), | ||
TendencyTestMock( | ||
"8번 문항", | ||
"8-1", | ||
"8-2", | ||
"8-3", | ||
"8-4", | ||
), | ||
TendencyTestMock( | ||
"9번 문항", | ||
"9-1", | ||
"9-2", | ||
"9-3", | ||
"9-4", | ||
), | ||
) | ||
|
||
fun plusStepValue() { | ||
step.value = step.value.plus(1) | ||
} | ||
|
||
fun setCheckedValue(id: Int) { | ||
clearAllChecked() | ||
isChecked.value = true | ||
tendencyResultList[step.value - 1] = id | ||
|
||
when (id) { | ||
1 -> isFirstChecked.value = true | ||
2 -> isSecondChecked.value = true | ||
3 -> isThirdChecked.value = true | ||
4 -> isFourthChecked.value = true | ||
} | ||
} | ||
|
||
fun clearAllChecked() { | ||
isChecked.value = false | ||
isFirstChecked.value = false | ||
isSecondChecked.value = false | ||
isThirdChecked.value = false | ||
isFourthChecked.value = false | ||
} | ||
|
||
companion object { | ||
const val MAX_STEP = 9 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:id="@android:id/background"> | ||
<shape> | ||
<corners android:radius="0dp"/> | ||
<solid android:color="@color/gray_50"/> | ||
</shape> | ||
</item> | ||
<item android:id="@android:id/secondaryProgress"> | ||
<shape> | ||
<corners android:radius="0dp"/> | ||
<solid android:color="@color/gray_50"/> | ||
</shape> | ||
</item> | ||
<item android:id="@android:id/progress"> | ||
<clip> | ||
<shape> | ||
<corners android:radius="0dp"/> | ||
<solid android:color="@color/red_500"/> | ||
</shape> | ||
</clip> | ||
</item> | ||
</layer-list> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_checked="true"> | ||
<shape> | ||
<stroke android:width="1dp"/> | ||
<stroke android:color="@color/red_500"/> | ||
<corners android:radius="8dp" /> | ||
</shape> | ||
</item> | ||
|
||
<item android:state_checked="false"> | ||
<shape> | ||
<corners android:radius="8dp" /> | ||
<solid android:color="@color/gray_50"/> | ||
</shape> | ||
</item> | ||
</selector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item> | ||
<shape> | ||
<stroke android:width="1dp" /> | ||
<stroke android:color="@color/red_500" /> | ||
<corners android:radius="8dp" /> | ||
</shape> | ||
</item> | ||
</selector> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item> | ||
<shape> | ||
<corners android:radius="8dp" /> | ||
<solid android:color="@color/gray_50" /> | ||
</shape> | ||
</item> | ||
</selector> |
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.
목 액티비티처럼 화면 회전 막아주세용 ~
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.
이건 몰랐었네요!
이전에 제가 만든 액티비티들에도 다 적용했습니다 :)