This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MySceneGridItemRecyclerViewAdapter( | |
private val mValues: MutableList<DummyItem>, | |
private val animationListener: (state: AnimationState, tag: String) -> Unit | |
) : RecyclerView.Adapter<MyViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | |
val view = LayoutInflater.from(parent.context) | |
.inflate(R.layout.item_scene_13_grid, parent, false) | |
return ViewHolder(view) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GridListFragment { | |
... | |
adapter = MySceneGridItemRecyclerViewAdapter( itemList) { state, tag -> | |
Log.d("Scene13Fragment", "Animation state: $state") | |
animationStateLiveData.value = state to tag | |
} | |
private fun initObservers() { | |
animationStateLiveData.observe(viewLifecycleOwner, Observer { pair -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomMotionLayout : MotionLayout { | |
constructor(context: Context?) : super(context) | |
constructor(context: Context?, attrs: AttributeSet?) : super( | |
context, | |
attrs | |
) | |
constructor( | |
context: Context?, | |
attrs: AttributeSet?, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InterceptScrollingRecyclerView: RecyclerView { | |
constructor(context: Context): super(context) | |
constructor(context: Context, attrs: AttributeSet): super(context, attrs) | |
var swipeFrozen = false | |
override fun onInterceptTouchEvent(e: MotionEvent?): Boolean { | |
if (swipeFrozen) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initObservers() { | |
animationStateLiveData.observe(viewLifecycleOwner, Observer { pair -> | |
when (pair.first) { | |
AnimationState.STARTED, AnimationState.IN_PROGRESS -> { | |
recyclerView.swipeFrozen = true | |
} | |
else -> { | |
recyclerView.swipeFrozen = false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ConstraintSet | |
android:id="@+id/goneRight" | |
app:deriveConstraintsFrom="@id/like"> | |
<Constraint | |
android:id="@+id/cardViewScene" | |
android:layout_marginStart="600dp" | |
android:rotation="70" | |
app:layout_constraintHeight_percent="0.9" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) { | |
animationListener(AnimationState.COMPLETED) | |
if (p1 == R.id.goneRight || p1 == R.id.goneLeft) { | |
removeItemListener(position) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Transition | |
app:autoTransition="animateToEnd" | |
app:constraintSetEnd="@id/goneRight" | |
app:constraintSetStart="@id/like" | |
app:duration="50" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Transition | |
app:constraintSetEnd="@id/like" | |
app:constraintSetStart="@id/rest" | |
app:duration="100"> | |
<OnSwipe | |
app:dragDirection="dragRight" | |
app:onTouchUp="autoCompleteToStart" | |
app:touchAnchorId="@id/cardViewScene" | |
app:touchAnchorSide="right" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val awaitListChanged: suspend () -> Unit = { | |
suspendCancellableCoroutine<Int> { cont -> | |
val observer = object : RecyclerView.AdapterDataObserver() { | |
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { | |
unregisterAdapterDataObserver(this) | |
cont.resume(positionStart) | |
} | |
} | |
cont.invokeOnCancellation { unregisterAdapterDataObserver(observer) } | |
registerAdapterDataObserver(observer) |