Skip to content

Commit

Permalink
Make onCheckedChangeListener interface (Closes #20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgurg committed Jun 22, 2023
1 parent 405179b commit b7d234d
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class ToggleIconView @JvmOverloads constructor(

private var mIsChecked: Boolean = false

private var mOnCheckedChangeListener: ((view: ToggleIconView, isChecked: Boolean) -> Unit)? = null
private var mOnCheckedChangeListener: OnCheckedChangeListener? = null

init {
createAndSetCheckedDrawable(checkedDrawableResId)
Expand Down Expand Up @@ -123,7 +123,7 @@ abstract class ToggleIconView @JvmOverloads constructor(
}

private fun invokeOnCheckedChangeListener(isChecked: Boolean) {
mOnCheckedChangeListener?.invoke(this, isChecked)
mOnCheckedChangeListener?.onCheckedChanged(this, isChecked)
}

private fun isStateSame(previousState: Boolean, currentState: Boolean): Boolean {
Expand Down Expand Up @@ -171,7 +171,11 @@ abstract class ToggleIconView @JvmOverloads constructor(
invokeOnCheckedChangeListener(isChecked)
}

open fun setOnCheckedChangeListener(listener: (view: ToggleIconView, isChecked: Boolean) -> Unit) {
open fun setOnCheckedChangeListener(listener: OnCheckedChangeListener) {
mOnCheckedChangeListener = listener
}

fun interface OnCheckedChangeListener {
fun onCheckedChanged(view: ToggleIconView, isChecked: Boolean)
}
}

0 comments on commit b7d234d

Please sign in to comment.