Skip to content
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

Merged
merged 18 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@

<activity
android:name="com.going.presentation.onboarding.OnboardingProfileSettingActivity"
android:exported="false" />

<activity
android:name="com.going.presentation.tendencytest.TendencyTestSplashActivity"
android:exported="false" />
Comment on lines +48 to +50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

목 액티비티처럼 화면 회전 막아주세용 ~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 몰랐었네요!
이전에 제가 만든 액티비티들에도 다 적용했습니다 :)


<activity
android:name="com.going.presentation.tendencytest.TendencyTestActivity"
android:exported="true" />

</application>
Expand Down
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"progress" 같은 친구들도 const val로 표시해두면 좋을듯요!

Copy link
Member Author

Choose a reason for hiding this comment

The 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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

싱글클릭 말고 다른 리스너 달거 아니면 initStartBtnClickListener로 수정해주셍요 ~

Copy link
Member Author

Choose a reason for hiding this comment

The 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
}
}
23 changes: 23 additions & 0 deletions presentation/src/main/res/drawable/ll_progressbar.xml
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>
17 changes: 17 additions & 0 deletions presentation/src/main/res/drawable/sel_radiobutton.xml
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>
10 changes: 10 additions & 0 deletions presentation/src/main/res/drawable/sel_radiobutton_checked.xml
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>
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@{@string/text_count(viewModel.nowNameLength, viewModel.MAX_NAME_LEN)}"
android:text="@{@string/counter(viewModel.nowNameLength, viewModel.MAX_NAME_LEN)}"
android:textColor="@color/gray_200"
app:layout_constraintEnd_toEndOf="@id/et_onboarding_profile_setting_name"
app:layout_constraintTop_toBottomOf="@id/et_onboarding_profile_setting_name" />
Expand Down Expand Up @@ -109,7 +109,7 @@
android:id="@+id/tv_info_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{@string/text_count(viewModel.nowInfoLength, viewModel.MAX_INFO_LEN)}"
android:text="@{@string/counter(viewModel.nowInfoLength, viewModel.MAX_INFO_LEN)}"
android:textColor="@color/gray_200"
app:layout_constraintEnd_toEndOf="@id/et_onboarding_profile_setting_info"
app:layout_constraintTop_toBottomOf="@id/et_onboarding_profile_setting_info" />
Expand Down
Loading