Skip button on measurable dialog

pull/1319/head
Jakub Kalinowski 4 years ago
parent 2523c8e15f
commit 5527fd3514

@ -30,6 +30,7 @@ import android.widget.NumberPicker
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior
import org.isoron.uhabits.inject.ActivityContext import org.isoron.uhabits.inject.ActivityContext
import org.isoron.uhabits.utils.InterfaceUtils import org.isoron.uhabits.utils.InterfaceUtils
@ -76,6 +77,11 @@ class NumberPickerFactory
val v = picker.value + 0.05 * picker2.value val v = picker.value + 0.05 * picker2.value
callback.onNumberPicked(v) callback.onNumberPicked(v)
} }
.setNegativeButton(R.string.skip_button) { _, _ ->
picker.clearFocus()
val v = Entry.SKIP.toDouble() / 1000
callback.onNumberPicked(v)
}
.setOnDismissListener { .setOnDismissListener {
callback.onNumberPickerDismissed() callback.onNumberPickerDismissed()
} }

@ -173,7 +173,8 @@ class FrequencyChart : ScrollableChart {
rect[0f, 0f, baseSize.toFloat()] = baseSize.toFloat() rect[0f, 0f, baseSize.toFloat()] = baseSize.toFloat()
rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j) rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j)
val i = localeWeekdayList[j] % 7 val i = localeWeekdayList[j] % 7
if (values != null) drawMarker(canvas, rect, values[i]) if (values != null)
drawMarker(canvas, rect, values[i])
rect.offset(0f, rowHeight) rect.offset(0f, rowHeight)
} }
drawFooter(canvas, rect, date) drawFooter(canvas, rect, date)
@ -222,11 +223,12 @@ class FrequencyChart : ScrollableChart {
} }
private fun drawMarker(canvas: Canvas, rect: RectF?, value: Int?) { private fun drawMarker(canvas: Canvas, rect: RectF?, value: Int?) {
val valueCopy = value?.let { max(0, it) }
val padding = rect!!.height() * 0.2f val padding = rect!!.height() * 0.2f
// maximal allowed mark radius // maximal allowed mark radius
val maxRadius = (rect.height() - 2 * padding) / 2.0f val maxRadius = (rect.height() - 2 * padding) / 2.0f
// the real mark radius is scaled down by a factor depending on the maximal frequency // the real mark radius is scaled down by a factor depending on the maximal frequency
val scale = 1.0f / maxFreq * value!! val scale = 1.0f / maxFreq * valueCopy!!
val radius = maxRadius * scale val radius = maxRadius * scale
val colorIndex = min((colors.size - 1), ((colors.size - 1) * scale).roundToInt()) val colorIndex = min((colors.size - 1), ((colors.size - 1) * scale).roundToInt())
pGraph!!.color = colors[colorIndex] pGraph!!.color = colors[colorIndex]

@ -26,7 +26,7 @@ data class Entry(
/** /**
* Value indicating that the habit is not applicable for this timestamp. * Value indicating that the habit is not applicable for this timestamp.
*/ */
const val SKIP = -3 const val SKIP = -2
/** /**
* Value indicating that the user has performed the habit at this timestamp. * Value indicating that the user has performed the habit at this timestamp.

@ -60,34 +60,19 @@ class HistoryCardPresenter(
val timestamp = Timestamp.fromLocalDate(date) val timestamp = Timestamp.fromLocalDate(date)
screen.showFeedback() screen.showFeedback()
if (habit.isNumerical) { if (habit.isNumerical) {
// val entries = habit.computedEntries val entries = habit.computedEntries
// val oldValue = entries.get(timestamp).value val oldValue = entries.get(timestamp).value
// screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double -> screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double ->
// val thousands = (newValue * 1000).roundToInt() val thousands = (newValue * 1000).roundToInt()
// commandRunner.run( commandRunner.run(
// CreateRepetitionCommand( CreateRepetitionCommand(
// habitList, habitList,
// habit, habit,
// timestamp, timestamp,
// thousands, thousands,
// ), ),
// ) )
// } }
val currentValue = habit.computedEntries.get(timestamp).value
val nextValue = Entry.nextToggleValue(
value = currentValue,
isSkipEnabled = preferences.isSkipEnabled,
areQuestionMarksEnabled = preferences.areQuestionMarksEnabled
)
commandRunner.run(
CreateRepetitionCommand(
habitList,
habit,
timestamp,
nextValue,
),
)
} else { } else {
val currentValue = habit.computedEntries.get(timestamp).value val currentValue = habit.computedEntries.get(timestamp).value
val nextValue = Entry.nextToggleValue( val nextValue = Entry.nextToggleValue(
@ -120,14 +105,6 @@ class HistoryCardPresenter(
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
val entries = habit.computedEntries.getByInterval(oldest, today) val entries = habit.computedEntries.getByInterval(oldest, today)
val series = if (habit.isNumerical) { val series = if (habit.isNumerical) {
// entries.map {
// Entry(it.timestamp, max(0, it.value))
// }.map {
// when (it.value) {
// 0 -> HistoryChart.Square.OFF
// else -> HistoryChart.Square.ON
// }
// }
entries.map { entries.map {
when { when {
it.value == SKIP -> { it.value == SKIP -> {

Loading…
Cancel
Save