Skip to content

Commit 12cc70a

Browse files
committed
Confetti: Always emit from checkmark, not popup button
1 parent fa670b1 commit 12cc70a

File tree

9 files changed

+29
-28
lines changed

9 files changed

+29
-28
lines changed

uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/CheckmarkDialog.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
3333
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
3434
import org.isoron.uhabits.databinding.CheckmarkPopupBinding
3535
import org.isoron.uhabits.utils.InterfaceUtils.getFontAwesome
36-
import org.isoron.uhabits.utils.getCenter
3736
import org.isoron.uhabits.utils.sres
3837

3938
class CheckmarkDialog : AppCompatDialogFragment() {
40-
var onToggle: (Int, String, Float, Float) -> Unit = { _, _, _, _ -> }
39+
var onToggle: (Int, String) -> Unit = { _, _ -> }
4140

4241
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
4342
val appComponent = (requireActivity().application as HabitsApplication).component
@@ -64,8 +63,7 @@ class CheckmarkDialog : AppCompatDialogFragment() {
6463
}
6564
fun onClick(v: Int) {
6665
val notes = view.notes.text.toString().trim()
67-
val location = view.yesBtn.getCenter()
68-
onToggle(v, notes, location.x, location.y)
66+
onToggle(v, notes)
6967
requireDialog().dismiss()
7068
}
7169
view.yesBtn.setOnClickListener { onClick(YES_MANUAL) }

uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import java.text.ParseException
2525

2626
class NumberDialog : AppCompatDialogFragment() {
2727

28-
var onToggle: (Double, String, Float, Float) -> Unit = { _, _, _, _ -> }
28+
var onToggle: (Double, String) -> Unit = { _, _ -> }
2929
var onDismiss: () -> Unit = {}
3030

3131
private var originalNotes: String = ""
@@ -122,7 +122,7 @@ class NumberDialog : AppCompatDialogFragment() {
122122
}
123123
val notes = view.notes.text.toString()
124124
val location = view.saveBtn.getCenter()
125-
onToggle(value, notes, location.x, location.y)
125+
onToggle(value, notes)
126126
requireDialog().dismiss()
127127
}
128128
}

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class ListHabitsActivity : AppCompatActivity(), Preferences.Listener {
180180
val timestamp = intent.extras?.getLong("timestamp")
181181
if (habitId != null && timestamp != null) {
182182
val habit = appComponent.habitList.getById(habitId)!!
183-
component.listHabitsBehavior.onEdit(habit, Timestamp(timestamp))
183+
component.listHabitsBehavior.onEdit(habit, Timestamp(timestamp), 0f, 0f)
184184
}
185185
}
186186
intent = null

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class ListHabitsScreen
224224
}
225225

226226
override fun showConfetti(color: PaletteColor, x: Float, y: Float) {
227+
if (x == 0f && y == 0f) return
227228
if (preferences.isConfettiAnimationDisabled) return
228229
val baseColor = themeSwitcher.currentTheme!!.color(color).toInt()
229230
rootView.get().konfettiView.start(
@@ -268,7 +269,7 @@ class ListHabitsScreen
268269
putDouble("value", value)
269270
putString("notes", notes)
270271
}
271-
dialog.onToggle = { v, n, x, y -> callback.onNumberPicked(v, n, x, y) }
272+
dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) }
272273
dialog.dismissCurrentAndShow(fm, "numberDialog")
273274
}
274275

@@ -286,7 +287,7 @@ class ListHabitsScreen
286287
putInt("value", selectedValue)
287288
putString("notes", notes)
288289
}
289-
dialog.onToggle = { v, n, x, y -> callback.onNotesSaved(v, n, x, y) }
290+
dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) }
290291
dialog.dismissCurrentAndShow(fm, "checkmarkDialog")
291292
}
292293

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/HabitCardView.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,17 @@ class HabitCardView(
169169
}
170170
onEdit = { timestamp ->
171171
triggerRipple(timestamp)
172-
habit?.let { behavior.onEdit(it, timestamp) }
172+
val location = getAbsoluteButtonLocation(timestamp)
173+
habit?.let { behavior.onEdit(it, timestamp, location.x, location.y) }
173174
}
174175
}
175176

176177
numberPanel = numberPanelFactory.create().apply {
177178
visibility = GONE
178179
onEdit = { timestamp ->
179180
triggerRipple(timestamp)
180-
habit?.let { behavior.onEdit(it, timestamp) }
181+
val location = getAbsoluteButtonLocation(timestamp)
182+
habit?.let { behavior.onEdit(it, timestamp, location.x, location.y) }
181183
}
182184
}
183185

@@ -224,9 +226,13 @@ class HabitCardView(
224226
private fun getRelativeButtonLocation(timestamp: Timestamp): PointF {
225227
val today = DateUtils.getTodayWithOffset()
226228
val offset = timestamp.daysUntil(today) - dataOffset
227-
val button = checkmarkPanel.buttons[offset]
229+
val panel = when (habit!!.isNumerical) {
230+
true -> numberPanel
231+
false -> checkmarkPanel
232+
}
233+
val button = panel.buttons[offset]
228234
val y = button.height / 2.0f
229-
val x = checkmarkPanel.x + button.x + (button.width / 2).toFloat()
235+
val x = panel.x + button.x + (button.width / 2).toFloat()
230236
return PointF(x, y)
231237
}
232238

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
181181
putDouble("value", value)
182182
putString("notes", notes)
183183
}
184-
dialog.onToggle = { v, n, x, y -> callback.onNumberPicked(v, n, x, y) }
184+
dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) }
185185
dialog.dismissCurrentAndShow(supportFragmentManager, "numberDialog")
186186
}
187187

@@ -198,7 +198,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
198198
putInt("value", selectedValue)
199199
putString("notes", notes)
200200
}
201-
dialog.onToggle = { v, n, x, y -> callback.onNotesSaved(v, n, x, y) }
201+
dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) }
202202
dialog.dismissCurrentAndShow(supportFragmentManager, "checkmarkDialog")
203203
}
204204

uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehavior.kt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ open class ListHabitsBehavior @Inject constructor(
5151
screen.showHabitScreen(h)
5252
}
5353

54-
fun onEdit(habit: Habit, timestamp: Timestamp?) {
54+
fun onEdit(habit: Habit, timestamp: Timestamp?, x: Float, y: Float) {
5555
val entry = habit.computedEntries.get(timestamp!!)
5656
if (habit.type == HabitType.NUMERICAL) {
5757
val oldValue = entry.value.toDouble() / 1000
58-
screen.showNumberPopup(oldValue, entry.notes) { newValue: Double, newNotes: String, x: Float, y: Float ->
58+
screen.showNumberPopup(oldValue, entry.notes) { newValue: Double, newNotes: String ->
5959
val value = (newValue * 1000).roundToInt()
6060
if (newValue != oldValue) {
6161
if (
@@ -72,7 +72,7 @@ open class ListHabitsBehavior @Inject constructor(
7272
entry.value,
7373
entry.notes,
7474
habit.color
75-
) { newValue: Int, newNotes: String, x: Float, y: Float ->
75+
) { newValue: Int, newNotes: String ->
7676
if (newValue != entry.value && newValue == YES_MANUAL) screen.showConfetti(habit.color, x, y)
7777
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes))
7878
}
@@ -159,19 +159,15 @@ open class ListHabitsBehavior @Inject constructor(
159159
fun interface NumberPickerCallback {
160160
fun onNumberPicked(
161161
newValue: Double,
162-
notes: String,
163-
x: Float,
164-
y: Float
162+
notes: String
165163
)
166164
fun onNumberPickerDismissed() {}
167165
}
168166

169167
fun interface CheckMarkDialogCallback {
170168
fun onNotesSaved(
171169
value: Int,
172-
notes: String,
173-
x: Float,
174-
y: Float
170+
notes: String
175171
)
176172
fun onNotesDismissed() {}
177173
}

uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/HistoryCard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class HistoryCardPresenter(
9898
entry.value,
9999
entry.notes,
100100
habit.color
101-
) { newValue, newNotes, _: Float, _: Float ->
101+
) { newValue, newNotes ->
102102
commandRunner.run(
103103
CreateRepetitionCommand(
104104
habitList,
@@ -135,7 +135,7 @@ class HistoryCardPresenter(
135135
screen.showNumberPopup(
136136
value = oldValue / 1000.0,
137137
notes = entry.notes
138-
) { newValue: Double, newNotes: String, _: Float, _: Float ->
138+
) { newValue: Double, newNotes: String ->
139139
val thousands = (newValue * 1000).roundToInt()
140140
commandRunner.run(
141141
CreateRepetitionCommand(

uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
7878

7979
@Test
8080
fun testOnEdit() {
81-
behavior.onEdit(habit2, getToday())
81+
behavior.onEdit(habit2, getToday(), 0f, 0f)
8282
verify(screen).showNumberPopup(
8383
eq(0.1),
8484
eq(""),
8585
picker.capture()
8686
)
87-
picker.lastValue.onNumberPicked(100.0, "", 0f, 0f)
87+
picker.lastValue.onNumberPicked(100.0, "")
8888
val today = getTodayWithOffset()
8989
assertThat(habit2.computedEntries.get(today).value, equalTo(100000))
9090
}

0 commit comments

Comments
 (0)