Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add selection animation #1545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
*/
package com.moez.QKSMS.feature.conversations

import android.animation.AnimatorInflater
import android.animation.AnimatorSet
import android.content.Context
import android.graphics.Typeface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import com.moez.QKSMS.R
Expand Down Expand Up @@ -70,14 +73,20 @@ class ConversationsAdapter @Inject constructor(
view.setOnClickListener {
val conversation = getItem(adapterPosition) ?: return@setOnClickListener
when (toggleSelection(conversation.id, false)) {
true -> view.isActivated = isSelected(conversation.id)
true -> {
view.isActivated = isSelected(conversation.id)
// add selection image
flipAvatarPic(view)
}
false -> navigator.showConversation(conversation.id)
}
}
view.setOnLongClickListener {
val conversation = getItem(adapterPosition) ?: return@setOnLongClickListener true
toggleSelection(conversation.id)
view.isActivated = isSelected(conversation.id)
// add selection image
flipAvatarPic(view)
true
}
}
Expand All @@ -87,7 +96,10 @@ class ConversationsAdapter @Inject constructor(
val conversation = getItem(position) ?: return
val view = viewHolder.containerView

val origActivated = view.isActivated
view.isActivated = isSelected(conversation.id)
// add selection image
if (origActivated != view.isActivated) flipAvatarPic(view)

view.avatars.contacts = conversation.recipients
view.title.collapseEnabled = conversation.recipients.size > 1
Expand All @@ -108,4 +120,24 @@ class ConversationsAdapter @Inject constructor(
override fun getItemViewType(position: Int): Int {
return if (getItem(position)?.unread == false) 0 else 1
}

// add selection image
private fun flipAvatarPic(parentView: View) {
if (parentView.isActivated) {
animatorFlipViews(parentView.avatars, parentView.checked)
} else {
animatorFlipViews(parentView.checked, parentView.avatars)
}
}

private fun animatorFlipViews(oldView: View, newView: View) {
val animatorSetOldView = AnimatorInflater.loadAnimator(oldView.context, R.animator.flip_front) as AnimatorSet
animatorSetOldView.setTarget(oldView)
val animatorSetNewView = AnimatorInflater.loadAnimator(newView.context, R.animator.flip_back) as AnimatorSet
animatorSetNewView.setTarget(newView)

val combAnimatorSet = AnimatorSet()
combAnimatorSet.playSequentially(animatorSetOldView,animatorSetNewView)
combAnimatorSet.start()
}
}
17 changes: 17 additions & 0 deletions presentation/src/main/res/animator/flip_back.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially">
<!-- Before rotating, immediately set the alpha to 1. -->
<objectAnimator
android:valueFrom="0.0"
android:valueTo="1.0"
android:propertyName="alpha"
android:duration="0" />

<!-- Rotate. -->
<objectAnimator
android:valueFrom="90"
android:valueTo="0"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="200" />
</set>
17 changes: 17 additions & 0 deletions presentation/src/main/res/animator/flip_front.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:ordering="sequentially">
<!-- Rotate. -->
<objectAnimator
android:valueFrom="0"
android:valueTo="-90"
android:propertyName="rotationY"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:duration="200" />

<!-- After rotation, set the alpha to 0. -->
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="1" />
</set>
8 changes: 8 additions & 0 deletions presentation/src/main/res/drawable/ic_check_circle_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<vector android:height="24dp"
android:width="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF00838F" android:pathData="M12,0 A12,12 0 1,1 12,24 A12,12 0 1,1 12,0z"/>
<path android:fillColor="#FFFFFFFF" android:pathData="M10,17l-5,-5 1.41,-1.41L10,14.17l7.59,-7.59L19,8l-9,9z"/>
</vector>
11 changes: 11 additions & 0 deletions presentation/src/main/res/layout/conversation_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
android:paddingEnd="16dp"
android:paddingBottom="12dp">

<ImageView
android:id="@+id/checked"
android:layout_width="48dp"
android:layout_height="48dp"
android:alpha="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0"
app:srcCompat="@drawable/ic_check_circle_24dp" />

<com.moez.QKSMS.common.widget.GroupAvatarView
android:id="@+id/avatars"
android:layout_width="48dp"
Expand Down