mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
Add dialog and notes indicator for HistoryChart
This commit is contained in:
@@ -49,23 +49,12 @@ class AndroidDataView(
|
||||
override fun onShowPress(e: MotionEvent?) = Unit
|
||||
|
||||
override fun onSingleTapUp(e: MotionEvent?): Boolean {
|
||||
val x: Float
|
||||
val y: Float
|
||||
try {
|
||||
val pointerId = e!!.getPointerId(0)
|
||||
x = e.getX(pointerId)
|
||||
y = e.getY(pointerId)
|
||||
} catch (ex: RuntimeException) {
|
||||
// Android often throws IllegalArgumentException here. Apparently,
|
||||
// the pointer id may become invalid shortly after calling
|
||||
// e.getPointerId.
|
||||
return false
|
||||
}
|
||||
view?.onClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
return true
|
||||
return handleClick(e, true)
|
||||
}
|
||||
|
||||
override fun onLongPress(e: MotionEvent?) = Unit
|
||||
override fun onLongPress(e: MotionEvent?) {
|
||||
handleClick(e)
|
||||
}
|
||||
|
||||
override fun onScroll(
|
||||
e1: MotionEvent?,
|
||||
@@ -137,4 +126,22 @@ class AndroidDataView(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleClick(e: MotionEvent?, isSingleTap: Boolean = false): Boolean {
|
||||
val x: Float
|
||||
val y: Float
|
||||
try {
|
||||
val pointerId = e!!.getPointerId(0)
|
||||
x = e.getX(pointerId)
|
||||
y = e.getY(pointerId)
|
||||
} catch (ex: RuntimeException) {
|
||||
// Android often throws IllegalArgumentException here. Apparently,
|
||||
// the pointer id may become invalid shortly after calling
|
||||
// e.getPointerId.
|
||||
return false
|
||||
}
|
||||
if (isSingleTap) view?.onClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
else view?.onLongClick(x / canvas.innerDensity, y / canvas.innerDensity)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,10 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
paletteColor = habit.color,
|
||||
series = emptyList(),
|
||||
defaultSquare = HistoryChart.Square.OFF,
|
||||
hasNotes = emptyList(),
|
||||
theme = themeSwitcher.currentTheme,
|
||||
today = DateUtils.getTodayWithOffset().toLocalDate(),
|
||||
onDateClickedListener = onDateClickedListener ?: OnDateClickedListener { },
|
||||
onDateClickedListener = onDateClickedListener ?: OnDateClickedListener { _, _ -> },
|
||||
padding = 10.0,
|
||||
)
|
||||
dataView = AndroidDataView(context!!, null)
|
||||
@@ -103,6 +104,7 @@ class HistoryEditorDialog : AppCompatDialogFragment(), CommandRunner.Listener {
|
||||
)
|
||||
chart?.series = model.series
|
||||
chart?.defaultSquare = model.defaultSquare
|
||||
chart?.hasNotes = model.hasNotes
|
||||
dataView.postInvalidate()
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ class HistoryCardView(context: Context, attrs: AttributeSet) : LinearLayout(cont
|
||||
dateFormatter = JavaLocalDateFormatter(Locale.getDefault()),
|
||||
series = state.series,
|
||||
defaultSquare = state.defaultSquare,
|
||||
hasNotes = state.hasNotes,
|
||||
firstWeekday = state.firstWeekday,
|
||||
)
|
||||
binding.chart.postInvalidate()
|
||||
|
||||
@@ -59,6 +59,7 @@ class HistoryWidget(
|
||||
val historyChart = (this.view as HistoryChart)
|
||||
historyChart.series = model.series
|
||||
historyChart.defaultSquare = model.defaultSquare
|
||||
historyChart.hasNotes = model.hasNotes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +75,7 @@ class HistoryWidget(
|
||||
firstWeekday = prefs.firstWeekday,
|
||||
series = listOf(),
|
||||
defaultSquare = HistoryChart.Square.OFF,
|
||||
hasNotes = listOf(),
|
||||
)
|
||||
}
|
||||
).apply {
|
||||
|
||||
Reference in New Issue
Block a user