Skip to content

Commit

Permalink
- Components bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samanshah committed May 18, 2024
1 parent e3bb429 commit 918b18a
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 148 deletions.
2 changes: 1 addition & 1 deletion PishkhanHelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ afterEvaluate {
artifactId = 'pishkhanhelper'

// Version Library Name (Example : "1.0.0")
version = '0.2.1'
version = '0.2.2'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,42 @@ import ir.ayantech.pishkhanhelper.helper.changeEnable

private var mLastClickTime: Long = 0

fun ViewBinding.initButtonFilled(
fun View.initButtonFilled(
btnText: String,
isEnable: Boolean = true,
btnOnClick: View.OnClickListener? = null
) {
(this as? ComponentButtonFilledBinding)?.let {
filledButton.text = btnText
filledButton.setOnClickListener {
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) {
return@setOnClickListener
}
mLastClickTime = SystemClock.elapsedRealtime()
btnOnClick?.onClick(it)
ComponentButtonFilledBinding.bind(this).initButtonFilled(
btnText,
isEnable,
btnOnClick,
)
}

fun ComponentButtonFilledBinding.initButtonFilled(
btnText: String,
isEnable: Boolean = true,
btnOnClick: View.OnClickListener? = null
) {
filledButton.text = btnText
filledButton.setOnClickListener {
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) {
return@setOnClickListener
}
changeEnable(isEnable = isEnable)
filledButton.setHorizontallyScrolling(true)
filledButton.isSelected = true
mLastClickTime = SystemClock.elapsedRealtime()
btnOnClick?.onClick(it)
}
changeEnable(isEnable = isEnable)
filledButton.setHorizontallyScrolling(true)
filledButton.isSelected = true
}

fun ViewBinding.performButtonFilledClick() {
(this as? ComponentButtonFilledBinding)?.let {
filledButton.performClick()
}
fun View.performButtonFilledClick() {
ComponentButtonFilledBinding.bind(this).performButtonFilledClick()
}

fun ComponentButtonFilledBinding.performButtonFilledClick() {
filledButton.performClick()
}

//fun ViewBinding.changeEnable(
Expand All @@ -42,10 +54,14 @@ fun ViewBinding.performButtonFilledClick() {
// }
//}

fun ViewBinding.setFilledButtonText(text: String?) {
(this as? ComponentButtonFilledBinding)?.let {
filledButton.text = text
}
fun View.setFilledButtonText(text: String?) {
ComponentButtonFilledBinding.bind(this).setFilledButtonText(text)
}

fun ViewBinding.getText() = (this as? ComponentButtonFilledBinding)?.filledButton?.text.toString()
fun ComponentButtonFilledBinding.setFilledButtonText(text: String?) {
filledButton.text = text
}

fun View.getText() = ComponentButtonFilledBinding.bind(this).getText()

fun ComponentButtonFilledBinding.getText() = filledButton.text.toString()
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,51 @@ import ir.ayantech.pishkhanhelper.databinding.ComponentButtonOutlinedBinding
import ir.ayantech.pishkhanhelper.helper.getDimension
import ir.ayantech.pishkhanhelper.helper.getDimensionInt

fun View.initButtonOutlined(
context: Context,
btnText: String,
tint: Int? = null,
btnOnClick: View.OnClickListener? = null
) {
ComponentButtonOutlinedBinding.bind(this).initButtonOutlined(
context,
btnText,
tint,
btnOnClick,
)
}

fun ViewBinding.initButtonOutlined(
fun ComponentButtonOutlinedBinding.initButtonOutlined(
context: Context,
btnText: String,
tint: Int? = null,
btnOnClick: View.OnClickListener? = null
) {
(this as? ComponentButtonOutlinedBinding)?.let {
outlinedButton.text = btnText
outlinedButton.setOnClickListener(btnOnClick)
tint?.let {
outlinedButton.setTextColor(ColorStateList.valueOf(tint))
outlinedButton.text = btnText
outlinedButton.setOnClickListener(btnOnClick)
tint?.let {
outlinedButton.setTextColor(ColorStateList.valueOf(tint))

val gradientDrawable = GradientDrawable()
gradientDrawable.setStroke(context.getDimensionInt(R.dimen.margin_1), tint)
gradientDrawable.cornerRadius = context.getDimension(R.dimen.margin_12)
gradientDrawable.setColor(getColor(context, R.color.helper_transparent))
val gradientDrawable = GradientDrawable()
gradientDrawable.setStroke(context.getDimensionInt(R.dimen.margin_1), tint)
gradientDrawable.cornerRadius = context.getDimension(R.dimen.margin_12)
gradientDrawable.setColor(getColor(context, R.color.helper_transparent))

val gradientDrawableDefault = GradientDrawable()
gradientDrawableDefault.setStroke(context.getDimensionInt(R.dimen.margin_1), tint)
gradientDrawableDefault.setColor(getColor(context, R.color.helper_transparent))
gradientDrawableDefault.cornerRadius = context.getDimension(R.dimen.margin_12)
gradientDrawableDefault.setColor(getColor(context, R.color.helper_transparent))
val gradientDrawableDefault = GradientDrawable()
gradientDrawableDefault.setStroke(context.getDimensionInt(R.dimen.margin_1), tint)
gradientDrawableDefault.setColor(getColor(context, R.color.helper_transparent))
gradientDrawableDefault.cornerRadius = context.getDimension(R.dimen.margin_12)
gradientDrawableDefault.setColor(getColor(context, R.color.helper_transparent))

val stateListDrawable = StateListDrawable()
stateListDrawable.addState(
intArrayOf(android.R.attr.state_activated),
gradientDrawableDefault
)
val stateListDrawable = StateListDrawable()
stateListDrawable.addState(
intArrayOf(android.R.attr.state_activated),
gradientDrawableDefault
)

stateListDrawable.addState(StateSet.WILD_CARD, gradientDrawable)
outlinedButton.background = stateListDrawable
outlinedButton.isSelected = true
}
stateListDrawable.addState(StateSet.WILD_CARD, gradientDrawable)
outlinedButton.background = stateListDrawable
outlinedButton.isSelected = true
}
}

Expand All @@ -60,8 +71,10 @@ fun ViewBinding.initButtonOutlined(
// outlinedButton.changeVisibility(show = isVisible)
//}

fun ViewBinding.setButtonOutlinedText(text: String) {
(this as? ComponentButtonOutlinedBinding)?.let {
outlinedButton.text = text
}
fun View.setButtonOutlinedText(text: String) {
ComponentButtonOutlinedBinding.bind(this).setButtonOutlinedText(text)
}

fun ComponentButtonOutlinedBinding.setButtonOutlinedText(text: String) {
outlinedButton.text = text
}
Loading

0 comments on commit 918b18a

Please sign in to comment.