@@ -4,18 +4,80 @@ import android.content.Context
44import android.graphics.Color
55import android.graphics.drawable.ColorDrawable
66import android.graphics.drawable.Drawable
7- import androidx.annotation.*
7+ import androidx.annotation.ColorInt
8+ import androidx.annotation.ColorRes
9+ import androidx.annotation.DrawableRes
10+ import androidx.annotation.IdRes
811import androidx.core.content.ContextCompat
12+ import androidx.core.view.ViewCompat
913
1014data class SwipeAction internal constructor(
1115 @IdRes val actionId : Int ,
1216 val background : Drawable ? ,
1317 @DrawableRes val iconId : Int ,
1418 val text : CharSequence? ,
15- @ColorInt val iconTint : Int = Color . WHITE ,
16- @ColorInt val textColor : Int = Color . WHITE
19+ @ColorInt val iconTint : Int ,
20+ @ColorInt val textColor : Int
1721) {
1822
23+ constructor (builder: Builder ):
24+ this (
25+ builder.actionId,
26+ builder.background,
27+ builder.iconId,
28+ builder.text,
29+ builder.iconTint,
30+ builder.textColor
31+ )
32+
33+ class Builder (
34+ @IdRes internal val actionId : Int = ViewCompat .generateViewId(),
35+ @DrawableRes internal val iconId : Int
36+ ) {
37+
38+ internal var background: Drawable ? = null
39+ internal var text: CharSequence? = null
40+ @ColorInt
41+ internal var iconTint: Int = Color .WHITE
42+ @ColorInt
43+ internal var textColor: Int = Color .WHITE
44+
45+ fun background (background : Drawable ): Builder {
46+ this .background = background
47+ return this
48+ }
49+
50+ fun backgroundRes (context : Context , @DrawableRes backgroundRes : Int ): Builder {
51+ this .background = ContextCompat .getDrawable(context, backgroundRes)
52+ return this
53+ }
54+
55+ fun backgroundColor (@ColorInt color : Int ): Builder {
56+ this .background = ColorDrawable (color)
57+ return this
58+ }
59+
60+ fun text (text : CharSequence ): Builder {
61+ this .text = text
62+ return this
63+ }
64+
65+ fun iconTint (@ColorInt iconTint : Int ): Builder {
66+ this .iconTint = iconTint
67+ return this
68+ }
69+
70+ fun textColor (@ColorInt textColor : Int ): Builder {
71+ this .textColor = textColor
72+ return this
73+ }
74+
75+ fun build (): SwipeAction {
76+ return SwipeAction (this )
77+ }
78+
79+ }
80+
1981 companion object {
2082
2183 fun withBackgroundColor (
0 commit comments