Skip to content

Commit

Permalink
Fixes #206 - Fix a bug where isEmpty always returns true
Browse files Browse the repository at this point in the history
  • Loading branch information
warting committed Jan 25, 2023
1 parent 2f4c010 commit 77a445c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/src/main/java/se/warting/signaturepad/ViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class ViewActivity : Activity() {

override fun onSigned() {
Log.d("SignedListener", "OnSigned")
mSaveButton.isEnabled = true
mClearButton.isEnabled = true
mSaveButton.isEnabled = !mSignaturePad.isEmpty
mClearButton.isEnabled = !mSignaturePad.isEmpty
}

override fun onClear() {

Toast.makeText(this@ViewActivity, "OnClear", Toast.LENGTH_SHORT)
.show()

mSaveButton.isEnabled = false
mClearButton.isEnabled = false
mSaveButton.isEnabled = !mSignaturePad.isEmpty
mClearButton.isEnabled = !mSignaturePad.isEmpty
}
})
mClearButton.setOnClickListener { mSignaturePad.clear() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class SignaturePad(context: Context, attrs: AttributeSet?) : View(context, attrs

// View state
private val points = mutableListOf<TimedPoint>()
private var _isEmpty = false

private var mLastTouchX = 0f
private var mLastTouchY = 0f
Expand Down Expand Up @@ -171,7 +170,7 @@ class SignaturePad(context: Context, attrs: AttributeSet?) : View(context, attrs
mLastWidth = (mMinWidth + mMaxWidth) / 2f
mLastWidth = ((mMinWidth + mMaxWidth) / 2).toFloat()
mSignatureTransparentBitmap = null
makeEmpty(true)
notifyListeners()
invalidate()
}

Expand Down Expand Up @@ -281,11 +280,10 @@ class SignaturePad(context: Context, attrs: AttributeSet?) : View(context, attrs
}

val isEmpty: Boolean
get() = _isEmpty
get() = points.isEmpty()

private fun makeEmpty(newValue: Boolean) {
_isEmpty = newValue
if (_isEmpty) {
private fun notifyListeners() {
if (points.isEmpty()) {
mSignedListener?.onClear()
} else {
mSignedListener?.onSigned()
Expand Down

0 comments on commit 77a445c

Please sign in to comment.