Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class NotesCanvas(context: Context, attrs: AttributeSet) : View(context, attrs)
return false
}

var finishDrawing = false
when (event.action) {
MotionEvent.ACTION_DOWN -> {
path.moveTo(x, y)
Expand All @@ -56,7 +55,10 @@ class NotesCanvas(context: Context, attrs: AttributeSet) : View(context, attrs)
}
currentX = x
currentY = y
val drawPath = DrawPath(path, viewModel.paint)
viewModel.onDrawPath(drawPath)
}

MotionEvent.ACTION_MOVE -> {
val x2 = (currentX + x) / 2
val y2 = (currentY + y) / 2
Expand All @@ -72,17 +74,14 @@ class NotesCanvas(context: Context, attrs: AttributeSet) : View(context, attrs)
currentX = x
currentY = y
}

MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
if (x == currentX && y == currentY) path.lineTo(x, y)
path = Path()
finishDrawing = true
}
}

if (!finishDrawing) {
val drawPath = DrawPath(path, viewModel.paint)
viewModel.onDrawPath(drawPath)
invalidate()
}
invalidate()

return true
}
Expand Down