detail: make transitions shared axis

Make detail transitions operate on a shared axis.

This just looks nicer.
This commit is contained in:
OxygenCobalt 2022-07-26 21:18:33 -06:00
parent ebdbd682b0
commit 114d355011
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
7 changed files with 51 additions and 62 deletions

View file

@ -28,6 +28,7 @@ import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearSmoothScroller import androidx.recyclerview.widget.LinearSmoothScroller
import com.google.android.material.transition.MaterialSharedAxis
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentDetailBinding import org.oxycblt.auxio.databinding.FragmentDetailBinding
import org.oxycblt.auxio.detail.recycler.AlbumDetailAdapter import org.oxycblt.auxio.detail.recycler.AlbumDetailAdapter
@ -67,6 +68,14 @@ class AlbumDetailFragment :
private val detailAdapter = AlbumDetailAdapter(this) private val detailAdapter = AlbumDetailAdapter(this)
private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) } private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
}
override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater) override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater)
override fun onBindingCreated(binding: FragmentDetailBinding, savedInstanceState: Bundle?) { override fun onBindingCreated(binding: FragmentDetailBinding, savedInstanceState: Bundle?) {

View file

@ -25,6 +25,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import com.google.android.material.transition.MaterialSharedAxis
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentDetailBinding import org.oxycblt.auxio.databinding.FragmentDetailBinding
import org.oxycblt.auxio.detail.recycler.ArtistDetailAdapter import org.oxycblt.auxio.detail.recycler.ArtistDetailAdapter
@ -62,6 +63,14 @@ class ArtistDetailFragment :
private val detailAdapter = ArtistDetailAdapter(this) private val detailAdapter = ArtistDetailAdapter(this)
private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) } private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
}
override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater) override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater)
override fun onBindingCreated(binding: FragmentDetailBinding, savedInstanceState: Bundle?) { override fun onBindingCreated(binding: FragmentDetailBinding, savedInstanceState: Bundle?) {

View file

@ -25,6 +25,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.activityViewModels import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import com.google.android.material.transition.MaterialSharedAxis
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentDetailBinding import org.oxycblt.auxio.databinding.FragmentDetailBinding
import org.oxycblt.auxio.detail.recycler.DetailAdapter import org.oxycblt.auxio.detail.recycler.DetailAdapter
@ -63,6 +64,14 @@ class GenreDetailFragment :
private val detailAdapter = GenreDetailAdapter(this) private val detailAdapter = GenreDetailAdapter(this)
private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) } private val settings: Settings by lifecycleObject { binding -> Settings(binding.context) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
}
override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater) override fun onCreateBinding(inflater: LayoutInflater) = FragmentDetailBinding.inflate(inflater)
override fun onBindingCreated(binding: FragmentDetailBinding, savedInstanceState: Bundle?) { override fun onBindingCreated(binding: FragmentDetailBinding, savedInstanceState: Bundle?) {

View file

@ -35,6 +35,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2 import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.transition.MaterialSharedAxis
import java.lang.reflect.Field import java.lang.reflect.Field
import kotlin.math.abs import kotlin.math.abs
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
@ -88,6 +89,13 @@ class HomeFragment : ViewBindingFragment<FragmentHomeBinding>(), Toolbar.OnMenuI
binding.homeToolbar.menu.findItem(R.id.submenu_sorting) binding.homeToolbar.menu.findItem(R.id.submenu_sorting)
} }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, /* forward= */ false)
}
override fun onCreateBinding(inflater: LayoutInflater) = FragmentHomeBinding.inflate(inflater) override fun onCreateBinding(inflater: LayoutInflater) = FragmentHomeBinding.inflate(inflater)
override fun onBindingCreated(binding: FragmentHomeBinding, savedInstanceState: Bundle?) { override fun onBindingCreated(binding: FragmentHomeBinding, savedInstanceState: Bundle?) {

View file

@ -3,7 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="?attr/colorSurface">
<org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout <org.oxycblt.auxio.ui.coordinator.EdgeCoordinatorLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/home_layout" android:id="@+id/home_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="?attr/colorSurface">
<org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout <org.oxycblt.auxio.ui.coordinator.EdgeAppBarLayout
android:id="@+id/home_appbar" android:id="@+id/home_appbar"

View file

@ -21,18 +21,10 @@
app:argType="long" /> app:argType="long" />
<action <action
android:id="@+id/action_show_artist" android:id="@+id/action_show_artist"
app:destination="@id/artist_detail_fragment" app:destination="@id/artist_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_album" android:id="@+id/action_show_album"
app:destination="@id/album_detail_fragment" app:destination="@id/album_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/album_detail_fragment" android:id="@+id/album_detail_fragment"
@ -44,18 +36,10 @@
app:argType="long" /> app:argType="long" />
<action <action
android:id="@+id/action_show_artist" android:id="@+id/action_show_artist"
app:destination="@id/artist_detail_fragment" app:destination="@id/artist_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_album" android:id="@+id/action_show_album"
app:destination="@id/album_detail_fragment" app:destination="@id/album_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/genre_detail_fragment" android:id="@+id/genre_detail_fragment"
@ -67,18 +51,10 @@
app:argType="long" /> app:argType="long" />
<action <action
android:id="@+id/action_show_artist" android:id="@+id/action_show_artist"
app:destination="@id/artist_detail_fragment" app:destination="@id/artist_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_album" android:id="@+id/action_show_album"
app:destination="@id/album_detail_fragment" app:destination="@id/album_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/search_fragment" android:id="@+id/search_fragment"
@ -87,25 +63,13 @@
tools:layout="@layout/fragment_search"> tools:layout="@layout/fragment_search">
<action <action
android:id="@+id/action_show_genre" android:id="@+id/action_show_genre"
app:destination="@id/genre_detail_fragment" app:destination="@id/genre_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_artist" android:id="@+id/action_show_artist"
app:destination="@id/artist_detail_fragment" app:destination="@id/artist_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_album" android:id="@+id/action_show_album"
app:destination="@id/album_detail_fragment" app:destination="@id/album_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/home_fragment" android:id="@+id/home_fragment"
@ -121,24 +85,12 @@
app:popExitAnim="@anim/nav_default_pop_exit_anim" /> app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_genre" android:id="@+id/action_show_genre"
app:destination="@id/genre_detail_fragment" app:destination="@id/genre_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_artist" android:id="@+id/action_show_artist"
app:destination="@id/artist_detail_fragment" app:destination="@id/artist_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
<action <action
android:id="@+id/action_show_album" android:id="@+id/action_show_album"
app:destination="@id/album_detail_fragment" app:destination="@id/album_detail_fragment" />
app:enterAnim="@anim/nav_default_enter_anim"
app:exitAnim="@anim/nav_default_exit_anim"
app:popEnterAnim="@anim/nav_default_pop_enter_anim"
app:popExitAnim="@anim/nav_default_pop_exit_anim" />
</fragment> </fragment>
</navigation> </navigation>