mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Confetti: Always emit from checkmark, not popup button
This commit is contained in:
@@ -33,11 +33,10 @@ import org.isoron.uhabits.core.models.Entry.Companion.UNKNOWN
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||
import org.isoron.uhabits.databinding.CheckmarkPopupBinding
|
||||
import org.isoron.uhabits.utils.InterfaceUtils.getFontAwesome
|
||||
import org.isoron.uhabits.utils.getCenter
|
||||
import org.isoron.uhabits.utils.sres
|
||||
|
||||
class CheckmarkDialog : AppCompatDialogFragment() {
|
||||
var onToggle: (Int, String, Float, Float) -> Unit = { _, _, _, _ -> }
|
||||
var onToggle: (Int, String) -> Unit = { _, _ -> }
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val appComponent = (requireActivity().application as HabitsApplication).component
|
||||
@@ -64,8 +63,7 @@ class CheckmarkDialog : AppCompatDialogFragment() {
|
||||
}
|
||||
fun onClick(v: Int) {
|
||||
val notes = view.notes.text.toString().trim()
|
||||
val location = view.yesBtn.getCenter()
|
||||
onToggle(v, notes, location.x, location.y)
|
||||
onToggle(v, notes)
|
||||
requireDialog().dismiss()
|
||||
}
|
||||
view.yesBtn.setOnClickListener { onClick(YES_MANUAL) }
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.text.ParseException
|
||||
|
||||
class NumberDialog : AppCompatDialogFragment() {
|
||||
|
||||
var onToggle: (Double, String, Float, Float) -> Unit = { _, _, _, _ -> }
|
||||
var onToggle: (Double, String) -> Unit = { _, _ -> }
|
||||
var onDismiss: () -> Unit = {}
|
||||
|
||||
private var originalNotes: String = ""
|
||||
@@ -122,7 +122,7 @@ class NumberDialog : AppCompatDialogFragment() {
|
||||
}
|
||||
val notes = view.notes.text.toString()
|
||||
val location = view.saveBtn.getCenter()
|
||||
onToggle(value, notes, location.x, location.y)
|
||||
onToggle(value, notes)
|
||||
requireDialog().dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ class ListHabitsActivity : AppCompatActivity(), Preferences.Listener {
|
||||
val timestamp = intent.extras?.getLong("timestamp")
|
||||
if (habitId != null && timestamp != null) {
|
||||
val habit = appComponent.habitList.getById(habitId)!!
|
||||
component.listHabitsBehavior.onEdit(habit, Timestamp(timestamp))
|
||||
component.listHabitsBehavior.onEdit(habit, Timestamp(timestamp), 0f, 0f)
|
||||
}
|
||||
}
|
||||
intent = null
|
||||
|
||||
@@ -224,6 +224,7 @@ class ListHabitsScreen
|
||||
}
|
||||
|
||||
override fun showConfetti(color: PaletteColor, x: Float, y: Float) {
|
||||
if (x == 0f && y == 0f) return
|
||||
if (preferences.isConfettiAnimationDisabled) return
|
||||
val baseColor = themeSwitcher.currentTheme!!.color(color).toInt()
|
||||
rootView.get().konfettiView.start(
|
||||
@@ -268,7 +269,7 @@ class ListHabitsScreen
|
||||
putDouble("value", value)
|
||||
putString("notes", notes)
|
||||
}
|
||||
dialog.onToggle = { v, n, x, y -> callback.onNumberPicked(v, n, x, y) }
|
||||
dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) }
|
||||
dialog.dismissCurrentAndShow(fm, "numberDialog")
|
||||
}
|
||||
|
||||
@@ -286,7 +287,7 @@ class ListHabitsScreen
|
||||
putInt("value", selectedValue)
|
||||
putString("notes", notes)
|
||||
}
|
||||
dialog.onToggle = { v, n, x, y -> callback.onNotesSaved(v, n, x, y) }
|
||||
dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) }
|
||||
dialog.dismissCurrentAndShow(fm, "checkmarkDialog")
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,8 @@ class HabitCardView(
|
||||
}
|
||||
onEdit = { timestamp ->
|
||||
triggerRipple(timestamp)
|
||||
habit?.let { behavior.onEdit(it, timestamp) }
|
||||
val location = getAbsoluteButtonLocation(timestamp)
|
||||
habit?.let { behavior.onEdit(it, timestamp, location.x, location.y) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +178,8 @@ class HabitCardView(
|
||||
visibility = GONE
|
||||
onEdit = { timestamp ->
|
||||
triggerRipple(timestamp)
|
||||
habit?.let { behavior.onEdit(it, timestamp) }
|
||||
val location = getAbsoluteButtonLocation(timestamp)
|
||||
habit?.let { behavior.onEdit(it, timestamp, location.x, location.y) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,9 +226,13 @@ class HabitCardView(
|
||||
private fun getRelativeButtonLocation(timestamp: Timestamp): PointF {
|
||||
val today = DateUtils.getTodayWithOffset()
|
||||
val offset = timestamp.daysUntil(today) - dataOffset
|
||||
val button = checkmarkPanel.buttons[offset]
|
||||
val panel = when (habit!!.isNumerical) {
|
||||
true -> numberPanel
|
||||
false -> checkmarkPanel
|
||||
}
|
||||
val button = panel.buttons[offset]
|
||||
val y = button.height / 2.0f
|
||||
val x = checkmarkPanel.x + button.x + (button.width / 2).toFloat()
|
||||
val x = panel.x + button.x + (button.width / 2).toFloat()
|
||||
return PointF(x, y)
|
||||
}
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
putDouble("value", value)
|
||||
putString("notes", notes)
|
||||
}
|
||||
dialog.onToggle = { v, n, x, y -> callback.onNumberPicked(v, n, x, y) }
|
||||
dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) }
|
||||
dialog.dismissCurrentAndShow(supportFragmentManager, "numberDialog")
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
|
||||
putInt("value", selectedValue)
|
||||
putString("notes", notes)
|
||||
}
|
||||
dialog.onToggle = { v, n, x, y -> callback.onNotesSaved(v, n, x, y) }
|
||||
dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) }
|
||||
dialog.dismissCurrentAndShow(supportFragmentManager, "checkmarkDialog")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user