mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-14 04:58:52 -06:00
Skip button on measurable dialog
This commit is contained in:
@@ -30,6 +30,7 @@ import android.widget.NumberPicker
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
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.inject.ActivityContext
|
||||
import org.isoron.uhabits.utils.InterfaceUtils
|
||||
@@ -76,6 +77,11 @@ class NumberPickerFactory
|
||||
val v = picker.value + 0.05 * picker2.value
|
||||
callback.onNumberPicked(v)
|
||||
}
|
||||
.setNegativeButton(R.string.skip_button) { _, _ ->
|
||||
picker.clearFocus()
|
||||
val v = Entry.SKIP.toDouble() / 1000
|
||||
callback.onNumberPicked(v)
|
||||
}
|
||||
.setOnDismissListener {
|
||||
callback.onNumberPickerDismissed()
|
||||
}
|
||||
|
||||
@@ -173,7 +173,8 @@ class FrequencyChart : ScrollableChart {
|
||||
rect[0f, 0f, baseSize.toFloat()] = baseSize.toFloat()
|
||||
rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j)
|
||||
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)
|
||||
}
|
||||
drawFooter(canvas, rect, date)
|
||||
@@ -222,11 +223,12 @@ class FrequencyChart : ScrollableChart {
|
||||
}
|
||||
|
||||
private fun drawMarker(canvas: Canvas, rect: RectF?, value: Int?) {
|
||||
val valueCopy = value?.let { max(0, it) }
|
||||
val padding = rect!!.height() * 0.2f
|
||||
// maximal allowed mark radius
|
||||
val maxRadius = (rect.height() - 2 * padding) / 2.0f
|
||||
// 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 colorIndex = min((colors.size - 1), ((colors.size - 1) * scale).roundToInt())
|
||||
pGraph!!.color = colors[colorIndex]
|
||||
|
||||
@@ -26,7 +26,7 @@ data class Entry(
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -60,34 +60,19 @@ class HistoryCardPresenter(
|
||||
val timestamp = Timestamp.fromLocalDate(date)
|
||||
screen.showFeedback()
|
||||
if (habit.isNumerical) {
|
||||
// val entries = habit.computedEntries
|
||||
// val oldValue = entries.get(timestamp).value
|
||||
// screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double ->
|
||||
// val thousands = (newValue * 1000).roundToInt()
|
||||
// commandRunner.run(
|
||||
// CreateRepetitionCommand(
|
||||
// habitList,
|
||||
// habit,
|
||||
// timestamp,
|
||||
// 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,
|
||||
),
|
||||
)
|
||||
val entries = habit.computedEntries
|
||||
val oldValue = entries.get(timestamp).value
|
||||
screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double ->
|
||||
val thousands = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
habitList,
|
||||
habit,
|
||||
timestamp,
|
||||
thousands,
|
||||
),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val currentValue = habit.computedEntries.get(timestamp).value
|
||||
val nextValue = Entry.nextToggleValue(
|
||||
@@ -120,14 +105,6 @@ class HistoryCardPresenter(
|
||||
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
|
||||
val entries = habit.computedEntries.getByInterval(oldest, today)
|
||||
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 {
|
||||
when {
|
||||
it.value == SKIP -> {
|
||||
|
||||
Reference in New Issue
Block a user