mirror of
https://github.com/ev-map/EVMap.git
synced 2026-04-18 13:17:38 -04:00
add some more animations to the new onboarding
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package net.vonforst.evmap.fragment
|
||||
|
||||
import android.animation.AnimatorSet
|
||||
import android.animation.ObjectAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.DecelerateInterpolator
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
@@ -70,12 +74,14 @@ class OnboardingViewPagerAdapter(fragment: Fragment, val goToNext: () -> Unit) :
|
||||
}
|
||||
|
||||
class WelcomeFragment(val goToNext: () -> Unit) : Fragment() {
|
||||
private lateinit var binding: FragmentOnboardingWelcomeBinding
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val binding = FragmentOnboardingWelcomeBinding.inflate(inflater, container, false)
|
||||
binding = FragmentOnboardingWelcomeBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.btnGetStarted.setOnClickListener {
|
||||
goToNext()
|
||||
@@ -83,28 +89,84 @@ class WelcomeFragment(val goToNext: () -> Unit) : Fragment() {
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
binding.animationView.playAnimation()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
binding.animationView.progress = 0f
|
||||
}
|
||||
}
|
||||
|
||||
class IconsFragment(val goToNext: () -> Unit) : Fragment() {
|
||||
private lateinit var binding: FragmentOnboardingIconsBinding
|
||||
|
||||
val labels
|
||||
get() = listOf(
|
||||
binding.iconLabel1,
|
||||
binding.iconLabel2,
|
||||
binding.iconLabel3,
|
||||
binding.iconLabel4,
|
||||
binding.iconLabel5
|
||||
)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val binding = FragmentOnboardingIconsBinding.inflate(inflater, container, false)
|
||||
binding = FragmentOnboardingIconsBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.btnGetStarted.setOnClickListener {
|
||||
goToNext()
|
||||
}
|
||||
labels.forEach { it.alpha = 0f }
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@SuppressLint("Recycle")
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val animators = labels.flatMapIndexed { i, view ->
|
||||
listOf(
|
||||
ObjectAnimator.ofFloat(view, "translationY", -20f, 0f).apply {
|
||||
startDelay = 40L * i
|
||||
interpolator = DecelerateInterpolator()
|
||||
},
|
||||
ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).apply {
|
||||
startDelay = 40L * i
|
||||
interpolator = DecelerateInterpolator()
|
||||
}
|
||||
)
|
||||
}
|
||||
AnimatorSet().apply {
|
||||
playTogether(animators)
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
labels.forEach { it.alpha = 0f }
|
||||
}
|
||||
}
|
||||
|
||||
class DataSourceSelectFragment(val goToNext: () -> Unit) : Fragment() {
|
||||
private lateinit var prefs: PreferenceDataSource
|
||||
private lateinit var binding: FragmentOnboardingDataSourceBinding
|
||||
|
||||
val animatedItems
|
||||
get() = listOf(
|
||||
binding.rgDataSource.rbGoingElectric,
|
||||
binding.rgDataSource.textView27,
|
||||
binding.rgDataSource.rbOpenChargeMap,
|
||||
binding.rgDataSource.textView28
|
||||
)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -116,14 +178,19 @@ class DataSourceSelectFragment(val goToNext: () -> Unit) : Fragment() {
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding.btnGetStarted.isEnabled = false
|
||||
binding.btnGetStarted.visibility = View.INVISIBLE
|
||||
|
||||
for (rb in listOf(
|
||||
binding.rgDataSource.rbGoingElectric,
|
||||
binding.rgDataSource.rbOpenChargeMap
|
||||
)) {
|
||||
rb.setOnCheckedChangeListener { _, _ ->
|
||||
binding.btnGetStarted.isEnabled = true
|
||||
if (binding.btnGetStarted.visibility == View.INVISIBLE) {
|
||||
binding.btnGetStarted.visibility = View.VISIBLE
|
||||
ObjectAnimator.ofFloat(binding.btnGetStarted, "alpha", 0f, 1f).apply {
|
||||
interpolator = DecelerateInterpolator()
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,5 +207,32 @@ class DataSourceSelectFragment(val goToNext: () -> Unit) : Fragment() {
|
||||
prefs.welcomeDialogShown = true
|
||||
goToNext()
|
||||
}
|
||||
animatedItems.forEach { it.alpha = 0f }
|
||||
}
|
||||
|
||||
@SuppressLint("Recycle")
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val animators = animatedItems.flatMapIndexed { i, view ->
|
||||
listOf(
|
||||
ObjectAnimator.ofFloat(view, "translationY", 20f, 0f).apply {
|
||||
startDelay = 40L * i
|
||||
interpolator = DecelerateInterpolator()
|
||||
},
|
||||
ObjectAnimator.ofFloat(view, "alpha", 0f, 1f).apply {
|
||||
startDelay = 40L * i
|
||||
interpolator = DecelerateInterpolator()
|
||||
}
|
||||
)
|
||||
}
|
||||
AnimatorSet().apply {
|
||||
playTogether(animators)
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
animatedItems.forEach { it.alpha = 0f }
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnGetStarted"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
style="@style/Widget.MaterialComponents.Button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="24dp"
|
||||
|
||||
Reference in New Issue
Block a user