Skip to content

Commit 338686f

Browse files
committed
fix(new study screen): finish current stroke before changing pen color
1 parent 4760884 commit 338686f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/whiteboard/WhiteboardFragment.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class WhiteboardFragment :
8181
val whiteboardView = view.findViewById<WhiteboardView>(R.id.whiteboard_view)
8282
brushToolbarContainerHorizontal = view.findViewById(R.id.brush_toolbar_container_horizontal)
8383
brushToolbarContainerVertical = view.findViewById(R.id.brush_toolbar_container_vertical)
84+
val touchBlockerView = view.findViewById<View>(R.id.touch_blocker_view)
85+
86+
whiteboardView.isDrawing
87+
.onEach { isCurrentlyDrawing ->
88+
// When drawing starts, show the blocker. When it stops, hide it.
89+
touchBlockerView.visibility = if (isCurrentlyDrawing) View.VISIBLE else View.GONE
90+
}.launchIn(lifecycleScope)
8491

8592
val isNightMode = Themes.systemIsInNightMode(requireContext())
8693
viewModel.loadState(isNightMode)

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/whiteboard/WhiteboardView.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import android.view.MotionEvent
2828
import android.view.View
2929
import androidx.core.graphics.createBitmap
3030
import com.ichi2.anki.R
31+
import kotlinx.coroutines.flow.MutableStateFlow
32+
import kotlinx.coroutines.flow.asStateFlow
3133

3234
/**
3335
* A custom view for the whiteboard that handles drawing and touch events.
@@ -67,6 +69,8 @@ class WhiteboardView : View {
6769
private val canvasPaint = Paint(Paint.DITHER_FLAG)
6870

6971
private var hasMoved = false
72+
private val _isDrawing = MutableStateFlow(false)
73+
val isDrawing = _isDrawing.asStateFlow()
7074

7175
/**
7276
* Recreates the drawing buffer when the view size changes.
@@ -118,6 +122,7 @@ class WhiteboardView : View {
118122
when (event.action) {
119123
MotionEvent.ACTION_DOWN -> {
120124
hasMoved = false
125+
_isDrawing.value = true
121126
currentPath.moveTo(touchX, touchY)
122127
if (isPathEraser) {
123128
onEraseGestureStart?.invoke()
@@ -127,13 +132,15 @@ class WhiteboardView : View {
127132
}
128133
MotionEvent.ACTION_MOVE -> {
129134
hasMoved = true
135+
_isDrawing.value = true
130136
currentPath.lineTo(touchX, touchY)
131137
if (isPathEraser) {
132138
onEraseGestureMove?.invoke(touchX, touchY)
133139
}
134140
invalidate()
135141
}
136142
MotionEvent.ACTION_UP -> {
143+
_isDrawing.value = false
137144
if (isPathEraser) {
138145
onEraseGestureEnd?.invoke()
139146
} else {

AnkiDroid/src/main/res/layout/fragment_whiteboard.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,19 @@
122122
</LinearLayout>
123123

124124
</com.google.android.material.card.MaterialCardView>
125+
126+
<View
127+
android:id="@+id/touch_blocker_view"
128+
android:layout_width="0dp"
129+
android:layout_height="0dp"
130+
android:background="@android:color/transparent"
131+
android:clickable="true"
132+
android:focusable="true"
133+
android:elevation="10dp"
134+
android:visibility="gone"
135+
app:layout_constraintTop_toTopOf="@id/controls_container"
136+
app:layout_constraintBottom_toBottomOf="@id/controls_container"
137+
app:layout_constraintStart_toStartOf="@id/controls_container"
138+
app:layout_constraintEnd_toEndOf="@id/controls_container" />
139+
125140
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)