Skip to content

Commit

Permalink
Merge pull request #5 from Crdzbird/feature/custom_assets
Browse files Browse the repository at this point in the history
Created Custom Asset Option in LottieAlertDialog
  • Loading branch information
mayuce authored May 28, 2019
2 parents f482688 + d823aa8 commit 0fdcb13
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/custom.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/assets/dino.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/src/main/assets/goodbye.json

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions app/src/main/java/com/labters/lottiealertdialog/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,64 @@ class MainActivity : AppCompatActivity() {
},2000)
}

fun customAsset(view: View){
alertDialog= LottieAlertDialog.Builder(this,DialogTypes.TYPE_CUSTOM, "custom.json")
.setTitle("Loading new stuffs ;)")
.setDescription("Please Wait")
.build()
alertDialog.setCancelable(false)
alertDialog.show()
Handler().postDelayed(Runnable {
alertDialog.changeDialog(LottieAlertDialog.Builder(parentActivity,DialogTypes.TYPE_CUSTOM,"dino.json")
.setTitle("This is a Custom Asset")
.setDescription("Wanna see something more!")
.setPositiveText("Yeah")
.setNegativeText("Nah")
.setNoneText("None")
.setPositiveButtonColor(Color.parseColor("#f44242"))
.setPositiveTextColor(Color.parseColor("#ffeaea"))
.setNegativeButtonColor(Color.parseColor("#ffbb00"))
.setNegativeTextColor(Color.parseColor("#0a0906"))
.setNoneButtonColor(Color.parseColor("#1cd3ef"))
.setNoneTextColor(Color.parseColor("#c407c4"))
.setPositiveListener(object: ClickListener{
override fun onClick(dialog: LottieAlertDialog) {
alertDialog.changeDialog(LottieAlertDialog.Builder(parentActivity,DialogTypes.TYPE_CUSTOM,"goodbye.json")
.setTitle("That's bad...")
.setDescription("See you next time!")
.setPositiveText("Okay")
.setPositiveListener(object : ClickListener{
override fun onClick(dialog: LottieAlertDialog) {
dialog.dismiss()
}
})
)
}
})
.setNegativeListener(object : ClickListener
{
override fun onClick(dialog: LottieAlertDialog) {
alertDialog.changeDialog(LottieAlertDialog.Builder(parentActivity,DialogTypes.TYPE_CUSTOM, "custom.json")
.setTitle("Here you got")
.setDescription("Loading something new.")
.setPositiveText("Okay")
.setPositiveListener(object : ClickListener{
override fun onClick(dialog: LottieAlertDialog) {
dialog.dismiss()
}
}))
}
})
.setNoneListener(object: ClickListener
{
override fun onClick(dialog: LottieAlertDialog) {
dialog.dismiss()
}
})
)
}, 2000)
}

fun onClick(view : View)
{
alertDialog= LottieAlertDialog.Builder(this,DialogTypes.TYPE_LOADING)
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,28 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Start"
android:padding="20dp"
android:background="@drawable/background_button"
android:onClick="onClick"
/>

<Button
android:id="@+id/custom_asset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/start"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:text="Custom Aset"
android:padding="20dp"
android:background="@drawable/background_button"
android:onClick="customAsset"
/>

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class DialogTypes
@JvmField val TYPE_ERROR = 2
@JvmField val TYPE_WARNING = 3
@JvmField val TYPE_QUESTION = 4
@JvmField val TYPE_CUSTOM = 5
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.labters.lottiealertdialoglibrary

import android.animation.ValueAnimator
import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
Expand All @@ -19,6 +18,7 @@ import com.airbnb.lottie.LottieDrawable

class LottieAlertDialog : AlertDialog
{
private var mCustomAsset:String? = null
private var mContext : Context
private var mType:Int?=null
private var mTitle:String? = null
Expand Down Expand Up @@ -61,10 +61,12 @@ class LottieAlertDialog : AlertDialog
negativeBtnColor : Int?,
negativeTextColor : Int?,
noneBtnColor : Int?,
noneTextColor : Int?
noneTextColor : Int?,
customAsset: String?
) : super(context) {
this.mContext = context
this.mType = type
this.mCustomAsset = customAsset
this.mTitle = title
this.mDescription = description
this.mPositiveText = positiveText
Expand All @@ -88,8 +90,9 @@ class LottieAlertDialog : AlertDialog

data class Builder(
private val context: Context? = null,
private val type:Int? = null
)
private val type:Int? = null,
private val customAsset:String? = null
)
{
private var title:String? = null
private var description:String? = null
Expand Down Expand Up @@ -122,10 +125,11 @@ class LottieAlertDialog : AlertDialog
fun setNoneTextColor(color:Int?) : Builder= apply { this.noneTextColor = color ; return@apply}
fun build() = LottieAlertDialog(context!!,type,title, description, positiveText,
negativeText,noneText,positiveListener,negativeListener,noneListener,
positiveBtnColor,positiveTextColor,negativeBtnColor,negativeTextColor,noneBtnColor,noneTextColor)
positiveBtnColor,positiveTextColor,negativeBtnColor,negativeTextColor,noneBtnColor,noneTextColor,customAsset)

fun getContext() : Context? {return context}
fun getType() : Int? { return type}
fun getCustomAsset() : String? { return customAsset}
fun getTitle() : String? { return title}
fun getDescription() : String? { return description}
fun getPositiveText() : String? { return positiveText}
Expand Down Expand Up @@ -167,7 +171,7 @@ class LottieAlertDialog : AlertDialog
lAnimation.startAnimation(animationFadeIn)
if (mTitle!=null)
{
tvTitle.setText(mTitle)
tvTitle.text = mTitle
tvTitle.visibility=View.VISIBLE
}
else
Expand All @@ -176,7 +180,7 @@ class LottieAlertDialog : AlertDialog
}
if (mDescription!=null)
{
tvDescription.setText(mDescription)
tvDescription.text = mDescription
tvDescription.visibility=View.VISIBLE
}
else
Expand All @@ -185,9 +189,9 @@ class LottieAlertDialog : AlertDialog
}
if (mPositiveText!=null)
{
btnPositive.setText(mPositiveText)
btnPositive.text = mPositiveText
btnPositive.visibility=View.VISIBLE
btnPositive.setOnClickListener(View.OnClickListener { mPositiveListener?.onClick(LottieAlertDialog@this) })
btnPositive.setOnClickListener { mPositiveListener?.onClick(LottieAlertDialog@this) }
}
else
{
Expand All @@ -197,7 +201,7 @@ class LottieAlertDialog : AlertDialog
{
btnNegative.setText(mNegativeText)
btnNegative.visibility=View.VISIBLE
btnNegative.setOnClickListener(View.OnClickListener { mNegativeListener?.onClick(LottieAlertDialog@this) })
btnNegative.setOnClickListener { mNegativeListener?.onClick(LottieAlertDialog@this) }
}
else
{
Expand All @@ -207,7 +211,7 @@ class LottieAlertDialog : AlertDialog
{
btnNone.setText(mNoneText)
btnNone.visibility=View.VISIBLE
btnNone.setOnClickListener(View.OnClickListener { mNoneListener?.onClick(LottieAlertDialog@this) })
btnNone.setOnClickListener { mNoneListener?.onClick(LottieAlertDialog@this) }
}
else
{
Expand Down Expand Up @@ -265,13 +269,19 @@ class LottieAlertDialog : AlertDialog
lAnimation.setAnimation("question.json")
lAnimation.repeatCount=LottieDrawable.INFINITE
}
else if (mType == DialogTypes.TYPE_CUSTOM)
{
lAnimation.setAnimation(mCustomAsset)
lAnimation.repeatCount=LottieDrawable.INFINITE
}
lAnimation.playAnimation()
}

fun changeDialog(builder : Builder)
{
mContext= builder.getContext()!!
mType=builder.getType()
mCustomAsset=builder.getCustomAsset()
mTitle=builder.getTitle()
mDescription=builder.getDescription()
mPositiveText=builder.getPositiveText()
Expand Down

0 comments on commit 0fdcb13

Please sign in to comment.