Fixed cardview clipping in sharedElement transitions

This commit is contained in:
Prathamesh More 2021-10-14 12:10:33 +05:30
parent 2673a1f0d0
commit 7b2f321693
6 changed files with 23 additions and 18 deletions

View file

@ -68,7 +68,7 @@ open class AlbumAdapter(
return ViewHolder(view) return ViewHolder(view)
} }
private fun getAlbumTitle(album: Album): String? { private fun getAlbumTitle(album: Album): String {
return album.title return album.title
} }
@ -88,7 +88,13 @@ open class AlbumAdapter(
holder.itemView.isActivated = isChecked holder.itemView.isActivated = isChecked
holder.title?.text = getAlbumTitle(album) holder.title?.text = getAlbumTitle(album)
holder.text?.text = getAlbumText(album) holder.text?.text = getAlbumText(album)
ViewCompat.setTransitionName(holder.image!!, album.id.toString()) // Check if imageContainer exists so we can have a smooth transition without
// CardView clipping, if it doesn't exist in current layout set transition name to image instead.
if (holder.imageContainer != null) {
ViewCompat.setTransitionName(holder.imageContainer!!, album.id.toString())
} else {
ViewCompat.setTransitionName(holder.image!!, album.id.toString())
}
loadAlbumCover(album, holder) loadAlbumCover(album, holder)
} }
@ -177,7 +183,7 @@ open class AlbumAdapter(
toggleChecked(layoutPosition) toggleChecked(layoutPosition)
} else { } else {
image?.let { image?.let {
listener?.onAlbumClick(dataSet[layoutPosition].id, it) listener?.onAlbumClick(dataSet[layoutPosition].id, imageContainer ?: it)
} }
} }
} }

View file

@ -85,12 +85,12 @@ class ArtistAdapter(
holder.itemView.isActivated = isChecked holder.itemView.isActivated = isChecked
holder.title?.text = artist.name holder.title?.text = artist.name
holder.text?.hide() holder.text?.hide()
holder.image?.let { val transitionName =
if (PreferenceUtil.albumArtistsOnly) { if (PreferenceUtil.albumArtistsOnly) artist.name else artist.id.toString()
ViewCompat.setTransitionName(it, artist.name) if (holder.imageContainer != null) {
} else { ViewCompat.setTransitionName(holder.imageContainer!!, transitionName)
ViewCompat.setTransitionName(it, artist.id.toString()) } else {
} ViewCompat.setTransitionName(holder.image!!, transitionName)
} }
loadArtistImage(artist, holder) loadArtistImage(artist, holder)
} }
@ -169,9 +169,9 @@ class ArtistAdapter(
val artist = dataSet[layoutPosition] val artist = dataSet[layoutPosition]
image?.let { image?.let {
if (PreferenceUtil.albumArtistsOnly && IAlbumArtistClickListener != null) { if (PreferenceUtil.albumArtistsOnly && IAlbumArtistClickListener != null) {
IAlbumArtistClickListener.onAlbumArtist(artist.name, it) IAlbumArtistClickListener.onAlbumArtist(artist.name, imageContainer ?: it)
} else { } else {
IArtistClickListener.onArtist(artist.id, it) IArtistClickListener.onArtist(artist.id, imageContainer ?: it)
} }
} }
} }

View file

@ -16,6 +16,7 @@ package code.name.monkey.retromusic.adapter.base;
import android.graphics.Color; import android.graphics.Color;
import android.view.View; import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
@ -50,6 +51,9 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
@Nullable @Nullable
public MaterialCardView imageContainerCard; public MaterialCardView imageContainerCard;
@Nullable
public FrameLayout imageContainer;
@Nullable @Nullable
public TextView imageText; public TextView imageText;
@ -88,13 +92,13 @@ public class MediaEntryViewHolder extends AbstractDraggableSwipeableItemViewHold
text2 = itemView.findViewById(R.id.text2); text2 = itemView.findViewById(R.id.text2);
image = itemView.findViewById(R.id.image); image = itemView.findViewById(R.id.image);
artistImage = itemView.findViewById(R.id.artistImage);
playerImage = itemView.findViewById(R.id.player_image); playerImage = itemView.findViewById(R.id.player_image);
time = itemView.findViewById(R.id.time); time = itemView.findViewById(R.id.time);
imageText = itemView.findViewById(R.id.imageText); imageText = itemView.findViewById(R.id.imageText);
imageTextContainer = itemView.findViewById(R.id.imageTextContainer); imageTextContainer = itemView.findViewById(R.id.imageTextContainer);
imageContainerCard = itemView.findViewById(R.id.imageContainerCard); imageContainerCard = itemView.findViewById(R.id.imageContainerCard);
imageContainer = itemView.findViewById(R.id.imageContainer);
menu = itemView.findViewById(R.id.menu); menu = itemView.findViewById(R.id.menu);
dragView = itemView.findViewById(R.id.drag_view); dragView = itemView.findViewById(R.id.drag_view);

View file

@ -104,10 +104,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply { sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.fragment_container
duration = 300L
scrimColor = Color.TRANSPARENT scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
setPathMotion(MaterialArcMotion()) setPathMotion(MaterialArcMotion())
} }
} }

View file

@ -73,10 +73,7 @@ abstract class AbsArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragm
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply { sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.fragment_container
duration = 300L
scrimColor = Color.TRANSPARENT scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
} }
} }

View file

@ -10,6 +10,7 @@
tools:ignore="MissingPrefix"> tools:ignore="MissingPrefix">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/imageContainer"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_margin="4dp" android:layout_margin="4dp"