Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

[feature/kotlin] Kotlin code in animator module #55

Merged
merged 9 commits into from
Feb 1, 2020

Conversation

ivybae
Copy link
Collaborator

@ivybae ivybae commented Oct 3, 2019

Hi, @tarek360 :)
As you see in this PR, I added kotlin source set in animator module.
I think we can remove java source set after we discuss about changes.

  1. RepeatMode
    I changed RepeatMode type to sealed class.

  2. @JvmStatic fun animate
    I think animator module can be called from Java.
    And, I tested in app module MainActivity.

  3. apply
    I used many apply inline function in AnimationBuilder class.
    So, I want to change more like :

RichPathAnimator.create { paths = allPaths; duration = 800; .... }

I need your advice.
Thanks!

@ivybae ivybae mentioned this pull request Oct 3, 2019
override fun evaluate(fraction: Float, startPathDataNodes: Array<PathDataNode>?, endPathDataNodes: Array<PathDataNode>?): Array<PathDataNode> {
if (evaluatedNodes == null) {
evaluatedNodes = PathParserCompat.deepCopyNodes(startPathDataNodes)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can do like so:

val evaluatedNodes = this.evaluatedNodes?.let { it } ?: PathParserCompat.deepCopyNodes(startPathDataNodes)
this.evaluatedNodes = evaluatedNodes

then we can remove !! from evaluatedNodes!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree with that. You can see in 7bb9d6a.

}
}
applyAnimatorProperties(valueAnimator, path)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move applyAnimatorProperties(valueAnimator, path) inside apply{} block then can remove val valueAnimator

like below:

ValueAnimator.ofFloat(*values).apply {
    addUpdateListener { animation ->
        listener?.update(path, animation.animatedValue as Float)
        path.onRichPathUpdatedListener?.onPathUpdated()
    }
    applyAnimatorProperties(this, path)
}

Copy link
Collaborator Author

@ivybae ivybae Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. You can see in b9ce4a1.

Copy link
Owner

@tarek360 tarek360 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, This is a great PR and thank you for your efforts!

I agree with the three points you mentioned in the PR description, especially the second and the third points, I always prefer to have backward compatibility as you did and also I would like to see that Kotlin style you suggested :)

Thanks!

@ivybae
Copy link
Collaborator Author

ivybae commented Oct 15, 2019

First of all, This is a great PR and thank you for your efforts!

I agree with the three points you mentioned in the PR description, especially the second and the third points, I always prefer to have backward compatibility as you did and also I would like to see that Kotlin style you suggested :)

Thanks!

@tarek360 Hi, Thank you for saying so.
I'm concerned three things about Kotlin Builder style.

First, If we are going to support backward compatibility and add new Kotlin style, then I think we should modify like below in AnimationBuilder.

[ AnimationBuilder.kt ]

    var trimPathEnd = floatArrayOf(0f)
        set(value) {
            property("trimPathEnd", *value)
            field = value
        }

    fun trimPathEnd(vararg values: Float) = apply {
        trimPathEnd = values
    }

Second, If we add animate method in RichPathAnimator, then we can keep similar with Java.
[ RichPathAnimator.kt ]

companion object {
        private val animationBuilders = arrayListOf<AnimationBuilder>()
        @JvmStatic fun animate(vararg paths: RichPath): AnimationBuilder {
            val viewAnimator = RichPathAnimator()
            return viewAnimator.addAnimationBuilder(*paths)
        }

        fun animate(vararg paths: RichPath, block:AnimationBuilder.()->Unit){
            AnimationBuilder(RichPathAnimator(), *paths).apply(block).run {
                animationBuilders.add(this)
                start()
            }
        }
    }

Last, we create animation in Kotlin like this :
I moved start() method to AnimationBuilder block before.

      RichPathAnimator.animate(*allPaths) {
            trimPathEnd = floatArrayOf(0f, 1f)
            // ..
        }

What about that?
I'm looking forward your advice.
Thank you. Have a good day!

@tarek360
Copy link
Owner

Hi, for the 1st and 2nd points, if we keep it, for now, I see it still works with Java correctly and but not Kotlin style, so I think later after we merge this PR, we can have another version of the builder with Kotlin DSL.

The 3rd point, I'd get rid of the asterisk!

What do you think?

@ivybae
Copy link
Collaborator Author

ivybae commented Oct 19, 2019

@tarek360
I agree with that. paths is vararg type, so we should change to List type.

And, I also think we can develop Kotlin DSL after merging this :)

@ivybae
Copy link
Collaborator Author

ivybae commented Oct 28, 2019

@tarek360
Hi, I modified vararg parameter paths to Array type.
And I also added thenAnimate method overloading like below.
Because I thought it could be better that not to change client code in java.
fun thenAnimate(path: RichPath): AnimationBuilder { return thenAnimate(arrayOf(path)) }
please check this out 3747986.

@tarek360
Copy link
Owner

I think the code like
animate(path1, path2, path3) or thenAnimate(path1, path2, path3)
will be broken.
do you think we should overload this as well?
or maybe something like:

animate(path1)
animate(path1, path2, path3)
animateAll(paths)
or maybe you you have a better idea, what do you think?

@ivybae
Copy link
Collaborator Author

ivybae commented Nov 4, 2019

@tarek360
I thought animate and thenAnimate have procedural order.
I guess that's why you said that it will be broken, right?

Then you means that we are going to replace thenAnimate to animate and animateAll?

@tarek360
Copy link
Owner

@step4me this PR is getting old :)
I'd merge it and fix any backward compatibility issue later.
so don't worry about that, just remove the java source and add back com. to the Kotlin source package, please!

@tarek360 tarek360 changed the base branch from develop to richpath-kotlin February 1, 2020 06:18
@tarek360 tarek360 merged commit 2d60a42 into tarek360:richpath-kotlin Feb 1, 2020
tarek360 added a commit that referenced this pull request Nov 3, 2020
* [feature/kotlin] Kotlin code in animator module (#55)

* add buildSrc/build to gitignore

* add kotlin source directory and configuration for animator module

* add RichPathAnimator kotlin class

* add kotlin classes to animator module

* change to kotlin richpathanimator reference in app module MainActivity

* remove non-null assertion operator in PathEvaluator

* remove local variable using apply block in AnimationBuilder

* modify vararg parameter [paths] to Array type in AnimationBuilder

Co-authored-by: Ahmed Tarek <a.tarek360@gmail.com>

* fix java/kotlin compatability

* fix repeatMode repeatCount

* add kotlin source directory and configuration for richpath module

* convert java to kotlin on RichPath, View, Drawable and Util classes

* move model and util directories to below richpath directory

* add Group Kotlin class

* modify RichPathView's parent to  AppCompatImageView

* convert java to kotlin related on PathParser classes

* convert java to kotlin on PathUtils class

* convert java to kotlin on OnRichPathUpdatedListener interface

* modify PathEvaluator's generic type to nullable and deepCopyNodes' return type to non-null

* modify Boolean type variable `pivotToCenter` to `isPivotToCenter`

* delete `originalPath` variable and use constructor parameter `src`

* modify pathDataNodes getter and setter

* modify package references of richpath module

* modify {@link class} in JavaDoc to [class] in KDoc

* delete java source set and rename kotlin package in richpath module

* rename test package source set to kotlin and convert java to kotlin on UtilsTest

* delete sourceSets configuration on animator and richpath modules

* modify showToast msg parameter type to non-null

* modify sourceSet name kotlin to java

Co-authored-by: Injin Bae <eyegochild@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants