diff --git a/.gitignore b/.gitignore index d9fd409..5c359bc 100755 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.iml .gradle +.idea +/.idea/* /local.properties /.idea/workspace.xml /.idea/libraries diff --git a/README.md b/README.md index 6159f5e..a9bf979 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,9 @@ Check this [project on dribbble](https://dribbble.com/shots/2818273-Female-in-IT-Filters) -Read how we did it [on our blog](https://yalantis.com/blog/develop-filter-animation-kotlin-android/) - + ##Requirements - Android SDK 18+ @@ -32,7 +31,7 @@ allprojects { Add the dependency: ```Groovy dependencies { - compile 'com.github.Yalantis:SearchFilter:v1.0.4' + implementation 'com.github.Yalantis:SearchFilter:v1.0.5' } ``` @@ -42,17 +41,17 @@ Firstly you need to place `Filter` above your `RecyclerView` in the layout file ```xml - - - - - - - + + - - + ``` diff --git a/app/build.gradle b/app/build.gradle index c212465..0925a61 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.1" + compileSdkVersion 33 + buildToolsVersion "20.0.3" defaultConfig { applicationId "com.yalantis.fitfilter" minSdkVersion 18 - targetSdkVersion 24 - versionCode 1 - versionName "1.0" + targetSdkVersion 33 + versionCode 2 + versionName "1.0.5" } buildTypes { release { @@ -20,9 +20,10 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - compile 'com.android.support:appcompat-v7:24.2.0' - compile 'com.facebook.fresco:fresco:0.13.0' - compile 'com.android.support:design:24.2.0' - compile project(':filter') + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation project(':filter') + + implementation "androidx.appcompat:appcompat:1.5.1" + implementation "com.google.android.material:material:1.6.1" + implementation "com.facebook.fresco:fresco:2.6.0" } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5affdba..295b1c7 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,8 @@ android:largeHeap="true" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/com/yalantis/fitfilter/DividerItemDecoration.java b/app/src/main/java/com/yalantis/fitfilter/DividerItemDecoration.java index ac9b0b6..ffd604d 100755 --- a/app/src/main/java/com/yalantis/fitfilter/DividerItemDecoration.java +++ b/app/src/main/java/com/yalantis/fitfilter/DividerItemDecoration.java @@ -3,10 +3,11 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; import android.view.View; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + /** * Created by galata on 17.09.16. */ diff --git a/app/src/main/java/com/yalantis/fitfilter/ExampleActivity.java b/app/src/main/java/com/yalantis/fitfilter/ExampleActivity.java index 9d87f51..805c52c 100755 --- a/app/src/main/java/com/yalantis/fitfilter/ExampleActivity.java +++ b/app/src/main/java/com/yalantis/fitfilter/ExampleActivity.java @@ -1,12 +1,13 @@ package com.yalantis.fitfilter; -import android.graphics.Color; import android.os.Bundle; -import android.support.v4.content.ContextCompat; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.util.DiffUtil; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.DiffUtil; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.imagepipeline.core.ImagePipelineConfig; @@ -16,7 +17,6 @@ import com.yalantis.filter.widget.Filter; import com.yalantis.filter.widget.FilterItem; -import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; @@ -152,7 +152,7 @@ private List findByTags(List tags) { } @Override - public void onFiltersSelected(@NotNull ArrayList filters) { + public void onFiltersSelected(@NonNull ArrayList filters) { List newQuestions = findByTags(filters); List oldQuestions = mAdapter.getQuestions(); mAdapter.setQuestions(newQuestions); @@ -174,11 +174,11 @@ public void onFilterDeselected(Tag item) { class Adapter extends FilterAdapter { - Adapter(@NotNull List items) { + Adapter(@NonNull List items) { super(items); } - @NotNull + @NonNull @Override public FilterItem createView(int position, Tag item) { FilterItem filterItem = new FilterItem(ExampleActivity.this); diff --git a/app/src/main/java/com/yalantis/fitfilter/QuestionsAdapter.java b/app/src/main/java/com/yalantis/fitfilter/QuestionsAdapter.java index 0f842c9..a84e79e 100755 --- a/app/src/main/java/com/yalantis/fitfilter/QuestionsAdapter.java +++ b/app/src/main/java/com/yalantis/fitfilter/QuestionsAdapter.java @@ -2,13 +2,14 @@ import android.content.Context; import android.graphics.drawable.GradientDrawable; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + import com.facebook.drawee.view.SimpleDraweeView; import java.util.List; diff --git a/app/src/main/java/com/yalantis/fitfilter/Tag.java b/app/src/main/java/com/yalantis/fitfilter/Tag.java index a23e746..260591e 100755 --- a/app/src/main/java/com/yalantis/fitfilter/Tag.java +++ b/app/src/main/java/com/yalantis/fitfilter/Tag.java @@ -1,6 +1,7 @@ package com.yalantis.fitfilter; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; import com.yalantis.filter.model.FilterModel; diff --git a/app/src/main/res/layout/activity_example.xml b/app/src/main/res/layout/activity_example.xml index f43fdd7..e7c9077 100755 --- a/app/src/main/res/layout/activity_example.xml +++ b/app/src/main/res/layout/activity_example.xml @@ -1,15 +1,15 @@ - - - - - - - + + - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_list.xml b/app/src/main/res/layout/item_list.xml index f7e0548..b2f3efd 100755 --- a/app/src/main/res/layout/item_list.xml +++ b/app/src/main/res/layout/item_list.xml @@ -83,7 +83,7 @@ android:layout_marginRight="16dp" android:background="#ebebeb" /> - - - () - private val mPendingAdditions = mutableListOf() + private val mPendingRemovals = mutableListOf() + private val mPendingAdditions = mutableListOf() private val mPendingMoves = mutableListOf() private val mPendingChanges = mutableListOf() - private val mAdditionsList = mutableListOf>() + private val mAdditionsList = mutableListOf>() private val mMovesList = mutableListOf>() private val mChangesList = mutableListOf>() - private val mAddAnimations = mutableListOf() - private val mMoveAnimations = mutableListOf() - private val mRemoveAnimations = mutableListOf() - private val mChangeAnimations = mutableListOf() + private val mAddAnimations = mutableListOf() + private val mMoveAnimations = mutableListOf() + private val mRemoveAnimations = mutableListOf() + private val mChangeAnimations = mutableListOf() - data class MoveInfo(var holder: RecyclerView.ViewHolder, var fromX: Int, var fromY: Int, var toX: Int, var toY: Int) + data class MoveInfo(var holder: ViewHolder, var fromX: Int, var fromY: Int, var toX: Int, var toY: Int) - data class ChangeInfo(var oldHolder: RecyclerView.ViewHolder?, var newHolder: RecyclerView.ViewHolder?, + data class ChangeInfo(var oldHolder: ViewHolder?, var newHolder: ViewHolder?, var fromX: Int = 0, var fromY: Int = 0, var toX: Int = 0, @@ -108,7 +108,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { } // Next, add stuff if (additionsPending) { - val additions = ArrayList() + val additions = ArrayList() additions.addAll(mPendingAdditions) mAdditionsList.add(additions) mPendingAdditions.clear() @@ -132,13 +132,13 @@ class FiltersListItemAnimator : SimpleItemAnimator() { } } - override fun animateRemove(holder: RecyclerView.ViewHolder): Boolean { + override fun animateRemove(holder: ViewHolder): Boolean { resetAnimation(holder) mPendingRemovals.add(holder) return true } - private fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { + private fun animateRemoveImpl(holder: ViewHolder) { val view = holder.itemView ValueAnimator.ofFloat(0f, 300f).setDuration(300).apply { @@ -161,14 +161,14 @@ class FiltersListItemAnimator : SimpleItemAnimator() { }.start() } - override fun animateAdd(holder: RecyclerView.ViewHolder): Boolean { + override fun animateAdd(holder: ViewHolder): Boolean { resetAnimation(holder) ViewCompat.setAlpha(holder.itemView, 0f) mPendingAdditions.add(holder) return true } - private fun animateAddImpl(holder: RecyclerView.ViewHolder) { + private fun animateAddImpl(holder: ViewHolder) { val view = holder.itemView mAddAnimations.add(holder) @@ -189,7 +189,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { }.start() } - override fun animateMove(holder: RecyclerView.ViewHolder, fromX: Int, fromY: Int, + override fun animateMove(holder: ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int): Boolean { var fromX = fromX var fromY = fromY @@ -213,7 +213,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { return true } - private fun animateMoveImpl(holder: RecyclerView.ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int) { + private fun animateMoveImpl(holder: ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int) { val view = holder.itemView val deltaX = toX - fromX val deltaY = toY - fromY @@ -242,7 +242,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { }.start() } - override fun animateChange(oldHolder: RecyclerView.ViewHolder, newHolder: RecyclerView.ViewHolder?, + override fun animateChange(oldHolder: ViewHolder, newHolder: ViewHolder?, fromX: Int, fromY: Int, toX: Int, toY: Int): Boolean { if (oldHolder === newHolder) { // Don't know how to run change animations when the same view holder is re-used. @@ -326,7 +326,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { } } - private fun endChangeAnimation(infoList: MutableList, item: RecyclerView.ViewHolder) { + private fun endChangeAnimation(infoList: MutableList, item: ViewHolder) { for (i in infoList.indices.reversed()) { val changeInfo = infoList[i] if (endChangeAnimationIfNecessary(changeInfo, item)) { @@ -346,7 +346,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { } } - private fun endChangeAnimationIfNecessary(changeInfo: ChangeInfo, item: RecyclerView.ViewHolder): Boolean { + private fun endChangeAnimationIfNecessary(changeInfo: ChangeInfo, item: ViewHolder): Boolean { var oldItem = false if (changeInfo.newHolder === item) { changeInfo.newHolder = null @@ -363,7 +363,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { return true } - override fun endAnimation(item: RecyclerView.ViewHolder) { + override fun endAnimation(item: ViewHolder) { val view = item.itemView // this will trigger end callback which should set properties to their target values. ViewCompat.animate(view).cancel() @@ -423,8 +423,9 @@ class FiltersListItemAnimator : SimpleItemAnimator() { dispatchFinishedWhenDone() } - private fun resetAnimation(holder: RecyclerView.ViewHolder) { - AnimatorCompatHelper.clearInterpolator(holder.itemView) + private fun resetAnimation(holder: ViewHolder) { + val defaultInterpolator = ValueAnimator().interpolator + holder.itemView.animate().interpolator = defaultInterpolator endAnimation(holder) } @@ -525,7 +526,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { dispatchAnimationsFinished() } - internal fun cancelAll(viewHolders: List) { + internal fun cancelAll(viewHolders: List) { for (i in viewHolders.indices.reversed()) { ViewCompat.animate(viewHolders[i].itemView).cancel() } @@ -548,7 +549,7 @@ class FiltersListItemAnimator : SimpleItemAnimator() { * * */ - override fun canReuseUpdatedViewHolder(viewHolder: RecyclerView.ViewHolder, + override fun canReuseUpdatedViewHolder(viewHolder: ViewHolder, payloads: List): Boolean { return !payloads.isEmpty() || super.canReuseUpdatedViewHolder(viewHolder, payloads) } diff --git a/filter/src/main/java/com/yalantis/filter/widget/CollapseView.kt b/filter/src/main/java/com/yalantis/filter/widget/CollapseView.kt index 113f899..a370f7c 100755 --- a/filter/src/main/java/com/yalantis/filter/widget/CollapseView.kt +++ b/filter/src/main/java/com/yalantis/filter/widget/CollapseView.kt @@ -13,9 +13,9 @@ import kotlinx.android.synthetic.main.view_collapse.view.* */ class CollapseView : FrameLayout { - constructor(context: Context?) : this(context, null) - constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0) - constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + constructor(context: Context) : this(context, null) + constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) + constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { LayoutInflater.from(context).inflate(R.layout.view_collapse, this, true) } diff --git a/filter/src/main/java/com/yalantis/filter/widget/Filter.kt b/filter/src/main/java/com/yalantis/filter/widget/Filter.kt index 852c0ad..1c0c525 100755 --- a/filter/src/main/java/com/yalantis/filter/widget/Filter.kt +++ b/filter/src/main/java/com/yalantis/filter/widget/Filter.kt @@ -20,9 +20,7 @@ import kotlinx.android.synthetic.main.collapsed_container.view.* import kotlinx.android.synthetic.main.filter.view.* import java.io.Serializable import java.util.* -import android.content.res.TypedArray import android.graphics.Color -import android.support.annotation.ColorInt /** diff --git a/filter/src/main/java/com/yalantis/filter/widget/FilterItem.kt b/filter/src/main/java/com/yalantis/filter/widget/FilterItem.kt index 03881e6..abe1f51 100755 --- a/filter/src/main/java/com/yalantis/filter/widget/FilterItem.kt +++ b/filter/src/main/java/com/yalantis/filter/widget/FilterItem.kt @@ -2,20 +2,18 @@ package com.yalantis.filter.widget import android.content.Context import android.content.res.ColorStateList -import android.graphics.Canvas import android.graphics.Typeface import android.graphics.drawable.GradientDrawable -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.annotation.DrawableRes -import android.support.v4.content.ContextCompat -import android.support.v4.content.res.ResourcesCompat import android.util.AttributeSet import android.view.LayoutInflater import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.FrameLayout +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.annotation.DrawableRes +import androidx.core.content.ContextCompat import com.yalantis.filter.R import com.yalantis.filter.listener.FilterItemListener import kotlinx.android.synthetic.main.item_filter.view.* @@ -30,7 +28,7 @@ class FilterItem : FrameLayout, Serializable { var isIncreased: Boolean = false var startX: Float = 0f var startY: Float = 0f - @ColorInt var cancelIconTint: Int = android.R.color.white + @ColorRes var cancelIconTint: Int = android.R.color.white @DrawableRes var cancelIcon: Int = R.drawable.ic_cancel @ColorInt var color: Int? = null @ColorInt var checkedColor: Int? = null diff --git a/filter/src/main/res/layout/item_filter.xml b/filter/src/main/res/layout/item_filter.xml index cc0b578..5bd05cd 100755 --- a/filter/src/main/res/layout/item_filter.xml +++ b/filter/src/main/res/layout/item_filter.xml @@ -9,7 +9,7 @@ android:layout_height="wrap_content" android:clipChildren="false"> - - - - -