integrate lottie and create view for users

This commit is contained in:
Carlos Martinez
2020-02-02 18:46:51 -03:00
parent 6a2722177e
commit 451d14ad95
14 changed files with 152 additions and 16 deletions

View File

@@ -0,0 +1,10 @@
package com.hako.base.extensions
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.LayoutRes
fun ViewGroup.inflate(@LayoutRes layout: Int, attachToRoot: Boolean = false) =
LayoutInflater
.from(context)
.inflate(layout, this, attachToRoot)

View File

@@ -0,0 +1,46 @@
package com.hako.base.widgets
import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import com.hako.base.R
import com.hako.base.extensions.inflate
import kotlinx.android.synthetic.main.like_button.view.*
private const val LIKE_MIN_FRAME = 0
private const val LIKE_MAX_FRAME = 28
private const val LIKE_ANIM_SPEED = 1f
private const val DISLIKE_MIN_FRAME = 28
private const val DISLIKE_MAX_FRAME = 70
private const val DISLIKE_ANIM_SPEED = 2f
class LikeButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
init {
inflate(R.layout.like_button, true)
}
fun like() {
like_button_animation_view.frame = LIKE_MAX_FRAME
}
fun dislike() {
like_button_animation_view.frame = LIKE_MIN_FRAME
}
fun playLike() {
like_button_animation_view.setMinAndMaxFrame(LIKE_MIN_FRAME, LIKE_MAX_FRAME)
like_button_animation_view.speed = LIKE_ANIM_SPEED
like_button_animation_view.playAnimation()
}
fun playDislike() {
like_button_animation_view.setMinAndMaxFrame(DISLIKE_MIN_FRAME, DISLIKE_MAX_FRAME)
like_button_animation_view.speed = DISLIKE_ANIM_SPEED
like_button_animation_view.playAnimation()
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape >
<solid android:color="@color/card_background" />
<corners android:radius="4dp" />
</shape>
</item>
</layer-list>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:parentTag="android.widget.FrameLayout">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/like_button_animation_view"
android:layout_width="40dp"
android:layout_height="40dp"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:lottie_rawRes="@raw/like_animation" />
</merge>

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="soft_background">#EEEEEE</color>
<color name="transparent">#00000000</color>
<color name="card_background">#FFFFFF</color>
</resources>