From 35c1162262847979c779f76bbb44eaaeeab78509 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Sat, 10 Oct 2020 09:12:09 -0700 Subject: [PATCH] Add transition animation to timer form fragment --- .idea/codeStyles/Project.xml | 16 ++++++++++++++++ app/build.gradle | 4 ++-- .../trainterval/timerform/TimerFormFragment.kt | 12 ++++++++++++ .../trainterval/timerlist/TimerListFragment.kt | 15 ++++++++++++++- app/src/main/res/layout/fragment_timer_form.xml | 2 ++ app/src/main/res/layout/fragment_timer_list.xml | 1 + app/src/main/res/values/styles.xml | 1 + build.gradle | 2 +- gradlew | 0 9 files changed, 49 insertions(+), 4 deletions(-) mode change 100644 => 100755 gradlew diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index adef587..baf56fc 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,6 +1,22 @@ + + diff --git a/app/build.gradle b/app/build.gradle index 059de90..39a9587 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,8 +78,8 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.core:core-ktx:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - - implementation 'com.google.android.material:material:1.2.0-alpha05' + implementation 'androidx.transition:transition-ktx:1.4.0-beta01' + implementation 'com.google.android.material:material:1.3.0-alpha02' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' diff --git a/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt b/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt index 00ddec7..33608ab 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt @@ -9,6 +9,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController +import com.google.android.material.transition.MaterialContainerTransform import com.wbrawner.trainterval.R import com.wbrawner.trainterval.shared.IntervalTimer import com.wbrawner.trainterval.timerform.IntervalTimerEditState.* @@ -47,6 +48,17 @@ class TimerFormFragment : Fragment() { it.setSupportActionBar(toolbar) it.supportActionBar?.setDisplayHomeAsUpEnabled(true) } + val context = view.context + sharedElementEnterTransition = MaterialContainerTransform().apply { + duration = resources.getInteger(android.R.integer.config_longAnimTime).toLong() + fadeMode = MaterialContainerTransform.FADE_MODE_CROSS + scrimColor = resources.getColor(R.color.colorSurface, context.theme) + } + sharedElementReturnTransition = MaterialContainerTransform().apply { + duration = resources.getInteger(android.R.integer.config_longAnimTime).toLong() + fadeMode = MaterialContainerTransform.FADE_MODE_CROSS + scrimColor = resources.getColor(R.color.colorSurface, context.theme) + } coroutineScope = CoroutineScope(Dispatchers.Main) coroutineScope!!.launch { timerFormViewModel.timerState.observe(viewLifecycleOwner, Observer { state -> diff --git a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt index bb7ef89..be9f7b5 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt @@ -6,11 +6,14 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.doOnPreDraw import androidx.fragment.app.Fragment import androidx.lifecycle.Observer +import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager +import com.google.android.material.transition.MaterialElevationScale import com.wbrawner.trainterval.R import com.wbrawner.trainterval.shared.IntervalTimer import com.wbrawner.trainterval.timerlist.IntervalTimerListState.* @@ -33,6 +36,11 @@ class TimerListFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + postponeEnterTransition() + view.doOnPreDraw { startPostponedEnterTransition() } + exitTransition = MaterialElevationScale(false) + reenterTransition = MaterialElevationScale(true) + allowReturnTransitionOverlap = false (activity as? AppCompatActivity)?.let { it.setSupportActionBar(toolbar) it.supportActionBar?.setDisplayHomeAsUpEnabled(false) @@ -55,7 +63,12 @@ class TimerListFragment : Fragment() { is EmptyListState -> renderEmptyList() is SuccessListState -> renderSuccessState(state.timers) is ErrorState -> renderErrorState(state.message) - is CreateTimer -> findNavController().navigate(R.id.timerFormFragment) + is CreateTimer -> findNavController().navigate( + R.id.timerFormFragment, + null, + null, + FragmentNavigatorExtras(addTimerButton to "fabContainer") + ) is EditTimer -> findNavController().navigate(R.id.timerFormFragment) is OpenTimer -> findNavController().navigate( R.id.activeTimerFragment, diff --git a/app/src/main/res/layout/fragment_timer_form.xml b/app/src/main/res/layout/fragment_timer_form.xml index d961a5b..641da23 100644 --- a/app/src/main/res/layout/fragment_timer_form.xml +++ b/app/src/main/res/layout/fragment_timer_form.xml @@ -1,11 +1,13 @@ diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 67dfb11..4cb92b0 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,6 +8,7 @@ @color/colorAccent true true + true diff --git a/build.gradle b/build.gradle index cabef2f..31ad689 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradlew b/gradlew old mode 100644 new mode 100755