mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Address review comments
This commit is contained in:
@@ -100,7 +100,7 @@ open class EntryList {
|
||||
val intervals = buildIntervals(frequency, original)
|
||||
snapIntervalsTogether(intervals)
|
||||
val computed = buildEntriesFromInterval(original, intervals)
|
||||
computed.filter { it.value != UNKNOWN }.forEach { add(it) }
|
||||
computed.filter { it.value != UNKNOWN || it.notes.isNotEmpty() }.forEach { add(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -298,14 +298,14 @@ class HabitCardListCache @Inject constructor(
|
||||
if (targetId != null && targetId != habit.id) continue
|
||||
newData.scores[habit.id] = habit.scores[today].value
|
||||
val list: MutableList<Int> = ArrayList()
|
||||
val notesList: MutableList<Boolean> = ArrayList()
|
||||
val notesIndicators: MutableList<Boolean> = ArrayList()
|
||||
for ((_, value, note) in habit.computedEntries.getByInterval(dateFrom, today)) {
|
||||
list.add(value)
|
||||
if (note.isNotEmpty()) notesList.add(true) else notesList.add(false)
|
||||
notesIndicators.add(note.isNotEmpty())
|
||||
}
|
||||
val entries = list.toTypedArray()
|
||||
newData.checkmarks[habit.id] = ArrayUtils.toPrimitive(entries)
|
||||
newData.notesIndicators[habit.id] = notesList.toBooleanArray()
|
||||
newData.notesIndicators[habit.id] = notesIndicators.toBooleanArray()
|
||||
runner!!.publishProgress(this, position)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,24 +48,22 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
}
|
||||
|
||||
fun onEdit(habit: Habit, timestamp: Timestamp?) {
|
||||
val entries = habit.computedEntries.get(timestamp!!)
|
||||
val notes = entries.notes
|
||||
val entry = habit.computedEntries.get(timestamp!!)
|
||||
if (habit.type == HabitType.NUMERICAL) {
|
||||
val oldValue = entries.value.toDouble()
|
||||
val oldValue = entry.value.toDouble()
|
||||
screen.showNumberPicker(
|
||||
oldValue / 1000,
|
||||
habit.unit,
|
||||
notes
|
||||
entry.notes
|
||||
) { newValue: Double, newNotes: String, ->
|
||||
val value = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
|
||||
}
|
||||
} else {
|
||||
val value = entries.value
|
||||
screen.showCheckmarkDialog(
|
||||
notes
|
||||
entry.notes
|
||||
) { newNotes ->
|
||||
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
|
||||
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, entry.value, newNotes))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,50 +59,44 @@ class HistoryCardPresenter(
|
||||
val screen: Screen,
|
||||
) : OnDateClickedListener {
|
||||
|
||||
override fun onDateClicked(date: LocalDate, isLongClick: Boolean) {
|
||||
override fun onDateShortPress(date: LocalDate) {
|
||||
val timestamp = Timestamp.fromLocalDate(date)
|
||||
screen.showFeedback()
|
||||
val entries = habit.computedEntries
|
||||
val oldValue = entries.get(timestamp).value
|
||||
val notes = entries.get(timestamp).notes
|
||||
if (habit.isNumerical) {
|
||||
screen.showNumberPicker(oldValue / 1000.0, habit.unit, notes) { newValue: Double, newNotes: String ->
|
||||
val thousands = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
thousands,
|
||||
newNotes,
|
||||
),
|
||||
)
|
||||
}
|
||||
showNumberPicker(timestamp)
|
||||
} else {
|
||||
if (!isLongClick) {
|
||||
val nextValue = Entry.nextToggleValue(
|
||||
value = oldValue,
|
||||
isSkipEnabled = preferences.isSkipEnabled,
|
||||
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||
)
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
val nextValue = Entry.nextToggleValue(
|
||||
value = entry.value,
|
||||
isSkipEnabled = preferences.isSkipEnabled,
|
||||
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||
)
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
nextValue,
|
||||
entry.notes,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDateLongPress(date: LocalDate) {
|
||||
val timestamp = Timestamp.fromLocalDate(date)
|
||||
screen.showFeedback()
|
||||
if (habit.isNumerical) {
|
||||
showNumberPicker(timestamp)
|
||||
} else {
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
screen.showCheckmarkDialog(entry.notes) { newNotes ->
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
nextValue,
|
||||
notes,
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
screen.showCheckmarkDialog(notes) { newNotes ->
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
oldValue,
|
||||
entry.value,
|
||||
newNotes,
|
||||
),
|
||||
)
|
||||
@@ -110,6 +104,27 @@ class HistoryCardPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNumberPicker(timestamp: Timestamp) {
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
val oldValue = entry.value
|
||||
screen.showNumberPicker(
|
||||
oldValue / 1000.0,
|
||||
habit.unit,
|
||||
entry.notes
|
||||
) { newValue: Double, newNotes: String ->
|
||||
val thousands = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
thousands,
|
||||
newNotes,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun onClickEditButton() {
|
||||
screen.showHistoryEditorDialog(this)
|
||||
}
|
||||
@@ -167,7 +182,7 @@ class HistoryCardPresenter(
|
||||
today = today.toLocalDate(),
|
||||
theme = theme,
|
||||
series = series,
|
||||
defaultSquare = defaultSquare
|
||||
defaultSquare = defaultSquare,
|
||||
hasNotes = hasNotes,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -32,8 +32,9 @@ import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.math.round
|
||||
|
||||
fun interface OnDateClickedListener {
|
||||
fun onDateClicked(date: LocalDate, isLongClick: Boolean)
|
||||
interface OnDateClickedListener {
|
||||
fun onDateShortPress(date: LocalDate) {}
|
||||
fun onDateLongPress(date: LocalDate) {}
|
||||
}
|
||||
|
||||
class HistoryChart(
|
||||
@@ -45,7 +46,7 @@ class HistoryChart(
|
||||
var hasNotes: List<Boolean>,
|
||||
var theme: Theme,
|
||||
var today: LocalDate,
|
||||
var onDateClickedListener: OnDateClickedListener = OnDateClickedListener { _, _ -> },
|
||||
var onDateClickedListener: OnDateClickedListener = object : OnDateClickedListener {},
|
||||
var padding: Double = 0.0,
|
||||
) : DataView {
|
||||
|
||||
@@ -88,7 +89,11 @@ class HistoryChart(
|
||||
if (row == 0 || col == nColumns) return
|
||||
val clickedDate = topLeftDate.plus(offset)
|
||||
if (clickedDate.isNewerThan(today)) return
|
||||
onDateClickedListener.onDateClicked(clickedDate, isLongClick)
|
||||
if (isLongClick) {
|
||||
onDateClickedListener.onDateLongPress(clickedDate)
|
||||
} else {
|
||||
onDateClickedListener.onDateShortPress(clickedDate)
|
||||
}
|
||||
}
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
|
||||
@@ -38,43 +38,38 @@ class WidgetBehavior @Inject constructor(
|
||||
fun onAddRepetition(habit: Habit, timestamp: Timestamp?) {
|
||||
notificationTray.cancel(habit)
|
||||
val entry = habit.originalEntries.get(timestamp!!)
|
||||
val notes = entry.notes
|
||||
setValue(habit, timestamp, Entry.YES_MANUAL, notes)
|
||||
setValue(habit, timestamp, Entry.YES_MANUAL, entry.notes)
|
||||
}
|
||||
|
||||
fun onRemoveRepetition(habit: Habit, timestamp: Timestamp?) {
|
||||
notificationTray.cancel(habit)
|
||||
val entry = habit.originalEntries.get(timestamp!!)
|
||||
val notes = entry.notes
|
||||
setValue(habit, timestamp, Entry.NO, notes)
|
||||
setValue(habit, timestamp, Entry.NO, entry.notes)
|
||||
}
|
||||
|
||||
fun onToggleRepetition(habit: Habit, timestamp: Timestamp) {
|
||||
val entry = habit.originalEntries.get(timestamp)
|
||||
val currentValue = entry.value
|
||||
val notes = entry.notes
|
||||
val newValue = nextToggleValue(
|
||||
value = currentValue,
|
||||
isSkipEnabled = preferences.isSkipEnabled,
|
||||
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
|
||||
)
|
||||
setValue(habit, timestamp, newValue, notes)
|
||||
setValue(habit, timestamp, newValue, entry.notes)
|
||||
notificationTray.cancel(habit)
|
||||
}
|
||||
|
||||
fun onIncrement(habit: Habit, timestamp: Timestamp, amount: Int) {
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
val currentValue = entry.value
|
||||
val notes = entry.notes
|
||||
setValue(habit, timestamp, currentValue + amount, notes)
|
||||
setValue(habit, timestamp, currentValue + amount, entry.notes)
|
||||
notificationTray.cancel(habit)
|
||||
}
|
||||
|
||||
fun onDecrement(habit: Habit, timestamp: Timestamp, amount: Int) {
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
val currentValue = entry.value
|
||||
val notes = entry.notes
|
||||
setValue(habit, timestamp, currentValue - amount, notes)
|
||||
setValue(habit, timestamp, currentValue - amount, entry.notes)
|
||||
notificationTray.cancel(habit)
|
||||
}
|
||||
|
||||
|
||||
@@ -90,20 +90,20 @@ class HistoryChartTest {
|
||||
|
||||
// Click top left date
|
||||
view.onClick(20.0, 46.0)
|
||||
verify(dateClickedListener).onDateClicked(LocalDate(2014, 10, 26), false)
|
||||
verify(dateClickedListener).onDateShortPress(LocalDate(2014, 10, 26))
|
||||
reset(dateClickedListener)
|
||||
view.onClick(2.0, 28.0)
|
||||
verify(dateClickedListener).onDateClicked(LocalDate(2014, 10, 26), false)
|
||||
verify(dateClickedListener).onDateShortPress(LocalDate(2014, 10, 26))
|
||||
reset(dateClickedListener)
|
||||
|
||||
// Click date in the middle
|
||||
view.onClick(163.0, 113.0)
|
||||
verify(dateClickedListener).onDateClicked(LocalDate(2014, 12, 10), false)
|
||||
verify(dateClickedListener).onDateShortPress(LocalDate(2014, 12, 10))
|
||||
reset(dateClickedListener)
|
||||
|
||||
// Click today
|
||||
view.onClick(336.0, 37.0)
|
||||
verify(dateClickedListener).onDateClicked(LocalDate(2015, 1, 25), false)
|
||||
verify(dateClickedListener).onDateShortPress(LocalDate(2015, 1, 25))
|
||||
reset(dateClickedListener)
|
||||
|
||||
// Click header
|
||||
@@ -115,6 +115,37 @@ class HistoryChartTest {
|
||||
verifyNoMoreInteractions(dateClickedListener)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testLongClick() = runBlocking {
|
||||
assertRenders(400, 200, "$base/base.png", view)
|
||||
|
||||
// Click top left date
|
||||
view.onLongClick(20.0, 46.0)
|
||||
verify(dateClickedListener).onDateLongPress(LocalDate(2014, 10, 26))
|
||||
reset(dateClickedListener)
|
||||
view.onLongClick(2.0, 28.0)
|
||||
verify(dateClickedListener).onDateLongPress(LocalDate(2014, 10, 26))
|
||||
reset(dateClickedListener)
|
||||
|
||||
// Click date in the middle
|
||||
view.onLongClick(163.0, 113.0)
|
||||
verify(dateClickedListener).onDateLongPress(LocalDate(2014, 12, 10))
|
||||
reset(dateClickedListener)
|
||||
|
||||
// Click today
|
||||
view.onLongClick(336.0, 37.0)
|
||||
verify(dateClickedListener).onDateLongPress(LocalDate(2015, 1, 25))
|
||||
reset(dateClickedListener)
|
||||
|
||||
// Click header
|
||||
view.onLongClick(160.0, 15.0)
|
||||
verifyNoMoreInteractions(dateClickedListener)
|
||||
|
||||
// Click right axis
|
||||
view.onLongClick(360.0, 60.0)
|
||||
verifyNoMoreInteractions(dateClickedListener)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDrawWeekDay() = runBlocking {
|
||||
view.firstWeekday = DayOfWeek.MONDAY
|
||||
|
||||
Reference in New Issue
Block a user