mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Replace notesIndicator by notes
This commit is contained in:
@@ -71,7 +71,7 @@ class CheckmarkButtonView(
|
|||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasNotes = false
|
var notes = ""
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
invalidate()
|
invalidate()
|
||||||
@@ -179,7 +179,7 @@ class CheckmarkButtonView(
|
|||||||
canvas.drawText(label, rect.centerX(), rect.centerY(), paint)
|
canvas.drawText(label, rect.centerX(), rect.centerY(), paint)
|
||||||
}
|
}
|
||||||
|
|
||||||
drawNotesIndicator(canvas, color, em, hasNotes)
|
drawNotesIndicator(canvas, color, em, notes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class CheckmarkPanelView(
|
|||||||
setupButtons()
|
setupButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
var notesIndicators = BooleanArray(0)
|
var notes = arrayOf<String>()
|
||||||
set(values) {
|
set(values) {
|
||||||
field = values
|
field = values
|
||||||
setupButtons()
|
setupButtons()
|
||||||
@@ -84,9 +84,9 @@ class CheckmarkPanelView(
|
|||||||
index + dataOffset < values.size -> values[index + dataOffset]
|
index + dataOffset < values.size -> values[index + dataOffset]
|
||||||
else -> UNKNOWN
|
else -> UNKNOWN
|
||||||
}
|
}
|
||||||
button.hasNotes = when {
|
button.notes = when {
|
||||||
index + dataOffset < notesIndicators.size -> notesIndicators[index + dataOffset]
|
index + dataOffset < notes.size -> notes[index + dataOffset]
|
||||||
else -> false
|
else -> ""
|
||||||
}
|
}
|
||||||
button.color = color
|
button.color = color
|
||||||
button.onToggle = { value -> onToggle(timestamp, value) }
|
button.onToggle = { value -> onToggle(timestamp, value) }
|
||||||
|
|||||||
@@ -124,9 +124,9 @@ class HabitCardListAdapter @Inject constructor(
|
|||||||
val habit = cache.getHabitByPosition(position)
|
val habit = cache.getHabitByPosition(position)
|
||||||
val score = cache.getScore(habit!!.id!!)
|
val score = cache.getScore(habit!!.id!!)
|
||||||
val checkmarks = cache.getCheckmarks(habit.id!!)
|
val checkmarks = cache.getCheckmarks(habit.id!!)
|
||||||
val notesIndicators = cache.getNoteIndicators(habit.id!!)
|
val notes = cache.getNotes(habit.id!!)
|
||||||
val selected = selected.contains(habit)
|
val selected = selected.contains(habit)
|
||||||
listView!!.bindCardView(holder, habit, score, checkmarks, notesIndicators, selected)
|
listView!!.bindCardView(holder, habit, score, checkmarks, notes, selected)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewAttachedToWindow(holder: HabitCardViewHolder) {
|
override fun onViewAttachedToWindow(holder: HabitCardViewHolder) {
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class HabitCardListView(
|
|||||||
habit: Habit,
|
habit: Habit,
|
||||||
score: Double,
|
score: Double,
|
||||||
checkmarks: IntArray,
|
checkmarks: IntArray,
|
||||||
notesIndicators: BooleanArray,
|
notes: Array<String>,
|
||||||
selected: Boolean
|
selected: Boolean
|
||||||
): View {
|
): View {
|
||||||
val cardView = holder.itemView as HabitCardView
|
val cardView = holder.itemView as HabitCardView
|
||||||
@@ -99,7 +99,7 @@ class HabitCardListView(
|
|||||||
cardView.score = score
|
cardView.score = score
|
||||||
cardView.unit = habit.unit
|
cardView.unit = habit.unit
|
||||||
cardView.threshold = habit.targetValue / habit.frequency.denominator
|
cardView.threshold = habit.targetValue / habit.frequency.denominator
|
||||||
cardView.notesIndicators = notesIndicators
|
cardView.notes = notes
|
||||||
|
|
||||||
val detector = GestureDetector(context, CardViewGestureDetector(holder))
|
val detector = GestureDetector(context, CardViewGestureDetector(holder))
|
||||||
cardView.setOnTouchListener { _, ev ->
|
cardView.setOnTouchListener { _, ev ->
|
||||||
|
|||||||
@@ -121,11 +121,11 @@ class HabitCardView(
|
|||||||
numberPanel.threshold = value
|
numberPanel.threshold = value
|
||||||
}
|
}
|
||||||
|
|
||||||
var notesIndicators
|
var notes
|
||||||
get() = checkmarkPanel.notesIndicators
|
get() = checkmarkPanel.notes
|
||||||
set(values) {
|
set(values) {
|
||||||
checkmarkPanel.notesIndicators = values
|
checkmarkPanel.notes = values
|
||||||
numberPanel.notesIndicators = values
|
numberPanel.notes = values
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkmarkPanel: CheckmarkPanelView
|
var checkmarkPanel: CheckmarkPanelView
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class NumberButtonView(
|
|||||||
field = value
|
field = value
|
||||||
invalidate()
|
invalidate()
|
||||||
}
|
}
|
||||||
var hasNotes = false
|
var notes = ""
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
invalidate()
|
invalidate()
|
||||||
@@ -221,7 +221,7 @@ class NumberButtonView(
|
|||||||
canvas.drawText(units, rect.centerX(), rect.centerY(), pUnit)
|
canvas.drawText(units, rect.centerX(), rect.centerY(), pUnit)
|
||||||
}
|
}
|
||||||
|
|
||||||
drawNotesIndicator(canvas, color, em, hasNotes)
|
drawNotesIndicator(canvas, color, em, notes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class NumberPanelView(
|
|||||||
setupButtons()
|
setupButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
var notesIndicators = BooleanArray(0)
|
var notes = arrayOf<String>()
|
||||||
set(values) {
|
set(values) {
|
||||||
field = values
|
field = values
|
||||||
setupButtons()
|
setupButtons()
|
||||||
@@ -96,9 +96,9 @@ class NumberPanelView(
|
|||||||
index + dataOffset < values.size -> values[index + dataOffset]
|
index + dataOffset < values.size -> values[index + dataOffset]
|
||||||
else -> 0.0
|
else -> 0.0
|
||||||
}
|
}
|
||||||
button.hasNotes = when {
|
button.notes = when {
|
||||||
index + dataOffset < notesIndicators.size -> notesIndicators[index + dataOffset]
|
index + dataOffset < notes.size -> notes[index + dataOffset]
|
||||||
else -> false
|
else -> ""
|
||||||
}
|
}
|
||||||
button.color = color
|
button.color = color
|
||||||
button.targetType = targetType
|
button.targetType = targetType
|
||||||
|
|||||||
@@ -202,10 +202,10 @@ fun View.sp(value: Float) = InterfaceUtils.spToPixels(context, value)
|
|||||||
fun View.dp(value: Float) = InterfaceUtils.dpToPixels(context, value)
|
fun View.dp(value: Float) = InterfaceUtils.dpToPixels(context, value)
|
||||||
fun View.str(id: Int) = resources.getString(id)
|
fun View.str(id: Int) = resources.getString(id)
|
||||||
|
|
||||||
fun View.drawNotesIndicator(canvas: Canvas, color: Int, size: Float, hasNotes: Boolean) {
|
fun View.drawNotesIndicator(canvas: Canvas, color: Int, size: Float, notes: String) {
|
||||||
val pNotesIndicator = Paint()
|
val pNotesIndicator = Paint()
|
||||||
pNotesIndicator.color = color
|
pNotesIndicator.color = color
|
||||||
if (hasNotes) {
|
if (notes.isNotBlank()) {
|
||||||
val cy = 0.8f * size
|
val cy = 0.8f * size
|
||||||
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
|
canvas.drawCircle(width.toFloat() - cy, cy, 8f, pNotesIndicator)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,8 +79,8 @@ class HabitCardListCache @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getNoteIndicators(habitId: Long): BooleanArray {
|
fun getNotes(habitId: Long): Array<String> {
|
||||||
return data.notesIndicators[habitId]!!
|
return data.notes[habitId]!!
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@@ -168,7 +168,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
data.habits.removeAt(position)
|
data.habits.removeAt(position)
|
||||||
data.idToHabit.remove(id)
|
data.idToHabit.remove(id)
|
||||||
data.checkmarks.remove(id)
|
data.checkmarks.remove(id)
|
||||||
data.notesIndicators.remove(id)
|
data.notes.remove(id)
|
||||||
data.scores.remove(id)
|
data.scores.remove(id)
|
||||||
listener.onItemRemoved(position)
|
listener.onItemRemoved(position)
|
||||||
}
|
}
|
||||||
@@ -213,7 +213,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
val habits: MutableList<Habit>
|
val habits: MutableList<Habit>
|
||||||
val checkmarks: HashMap<Long?, IntArray>
|
val checkmarks: HashMap<Long?, IntArray>
|
||||||
val scores: HashMap<Long?, Double>
|
val scores: HashMap<Long?, Double>
|
||||||
val notesIndicators: HashMap<Long?, BooleanArray>
|
val notes: HashMap<Long?, Array<String>>
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun copyCheckmarksFrom(oldData: CacheData) {
|
fun copyCheckmarksFrom(oldData: CacheData) {
|
||||||
@@ -226,10 +226,10 @@ class HabitCardListCache @Inject constructor(
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun copyNoteIndicatorsFrom(oldData: CacheData) {
|
fun copyNoteIndicatorsFrom(oldData: CacheData) {
|
||||||
val empty = BooleanArray(checkmarkCount)
|
val empty = (0..checkmarkCount).map { "" }.toTypedArray()
|
||||||
for (id in idToHabit.keys) {
|
for (id in idToHabit.keys) {
|
||||||
if (oldData.notesIndicators.containsKey(id)) notesIndicators[id] =
|
if (oldData.notes.containsKey(id)) notes[id] =
|
||||||
oldData.notesIndicators[id]!! else notesIndicators[id] = empty
|
oldData.notes[id]!! else notes[id] = empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
habits = LinkedList()
|
habits = LinkedList()
|
||||||
checkmarks = HashMap()
|
checkmarks = HashMap()
|
||||||
scores = HashMap()
|
scores = HashMap()
|
||||||
notesIndicators = HashMap()
|
notes = HashMap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,14 +298,14 @@ class HabitCardListCache @Inject constructor(
|
|||||||
if (targetId != null && targetId != habit.id) continue
|
if (targetId != null && targetId != habit.id) continue
|
||||||
newData.scores[habit.id] = habit.scores[today].value
|
newData.scores[habit.id] = habit.scores[today].value
|
||||||
val list: MutableList<Int> = ArrayList()
|
val list: MutableList<Int> = ArrayList()
|
||||||
val notesIndicators: MutableList<Boolean> = ArrayList()
|
val notes: MutableList<String> = ArrayList()
|
||||||
for ((_, value, note) in habit.computedEntries.getByInterval(dateFrom, today)) {
|
for ((_, value, note) in habit.computedEntries.getByInterval(dateFrom, today)) {
|
||||||
list.add(value)
|
list.add(value)
|
||||||
notesIndicators.add(note.isNotEmpty())
|
notes.add(note)
|
||||||
}
|
}
|
||||||
val entries = list.toTypedArray()
|
val entries = list.toTypedArray()
|
||||||
newData.checkmarks[habit.id] = ArrayUtils.toPrimitive(entries)
|
newData.checkmarks[habit.id] = ArrayUtils.toPrimitive(entries)
|
||||||
newData.notesIndicators[habit.id] = notesIndicators.toBooleanArray()
|
newData.notes[habit.id] = notes.toTypedArray()
|
||||||
runner!!.publishProgress(this, position)
|
runner!!.publishProgress(this, position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,7 +333,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
data.idToHabit[id] = habit
|
data.idToHabit[id] = habit
|
||||||
data.scores[id] = newData.scores[id]!!
|
data.scores[id] = newData.scores[id]!!
|
||||||
data.checkmarks[id] = newData.checkmarks[id]!!
|
data.checkmarks[id] = newData.checkmarks[id]!!
|
||||||
data.notesIndicators[id] = newData.notesIndicators[id]!!
|
data.notes[id] = newData.notes[id]!!
|
||||||
listener.onItemInserted(position)
|
listener.onItemInserted(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,10 +361,10 @@ class HabitCardListCache @Inject constructor(
|
|||||||
private fun performUpdate(id: Long, position: Int) {
|
private fun performUpdate(id: Long, position: Int) {
|
||||||
val oldScore = data.scores[id]!!
|
val oldScore = data.scores[id]!!
|
||||||
val oldCheckmarks = data.checkmarks[id]
|
val oldCheckmarks = data.checkmarks[id]
|
||||||
val oldNoteIndicators = data.notesIndicators[id]
|
val oldNoteIndicators = data.notes[id]
|
||||||
val newScore = newData.scores[id]!!
|
val newScore = newData.scores[id]!!
|
||||||
val newCheckmarks = newData.checkmarks[id]!!
|
val newCheckmarks = newData.checkmarks[id]!!
|
||||||
val newNoteIndicators = newData.notesIndicators[id]!!
|
val newNoteIndicators = newData.notes[id]!!
|
||||||
var unchanged = true
|
var unchanged = true
|
||||||
if (oldScore != newScore) unchanged = false
|
if (oldScore != newScore) unchanged = false
|
||||||
if (!Arrays.equals(oldCheckmarks, newCheckmarks)) unchanged = false
|
if (!Arrays.equals(oldCheckmarks, newCheckmarks)) unchanged = false
|
||||||
@@ -372,7 +372,7 @@ class HabitCardListCache @Inject constructor(
|
|||||||
if (unchanged) return
|
if (unchanged) return
|
||||||
data.scores[id] = newScore
|
data.scores[id] = newScore
|
||||||
data.checkmarks[id] = newCheckmarks
|
data.checkmarks[id] = newCheckmarks
|
||||||
data.notesIndicators[id] = newNoteIndicators
|
data.notes[id] = newNoteIndicators
|
||||||
listener.onItemChanged(position)
|
listener.onItemChanged(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user