mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Merge branch 'release/2.1.0' into dev
This commit is contained in:
@@ -20,14 +20,13 @@ package org.isoron.uhabits.core.io
|
||||
|
||||
import org.isoron.uhabits.core.AppScope
|
||||
import org.isoron.uhabits.core.DATABASE_VERSION
|
||||
import org.isoron.uhabits.core.commands.Command
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.commands.CreateHabitCommand
|
||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||
import org.isoron.uhabits.core.commands.EditHabitCommand
|
||||
import org.isoron.uhabits.core.database.DatabaseOpener
|
||||
import org.isoron.uhabits.core.database.MigrationHelper
|
||||
import org.isoron.uhabits.core.database.Repository
|
||||
import org.isoron.uhabits.core.models.Entry
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.models.ModelFactory
|
||||
import org.isoron.uhabits.core.models.Timestamp
|
||||
@@ -81,34 +80,33 @@ class LoopDBImporter
|
||||
var habit = habitList.getByUUID(habitRecord.uuid)
|
||||
val entryRecords = entryRepository.findAll("where habit = ?", habitRecord.id.toString())
|
||||
|
||||
var command: Command
|
||||
if (habit == null) {
|
||||
habit = modelFactory.buildHabit()
|
||||
habitRecord.id = null
|
||||
habitRecord.copyTo(habit)
|
||||
command = CreateHabitCommand(modelFactory, habitList, habit)
|
||||
command.run()
|
||||
CreateHabitCommand(modelFactory, habitList, habit).run()
|
||||
} else {
|
||||
val modified = modelFactory.buildHabit()
|
||||
habitRecord.id = habit.id
|
||||
habitRecord.copyTo(modified)
|
||||
command = EditHabitCommand(habitList, habit.id!!, modified)
|
||||
command.run()
|
||||
EditHabitCommand(habitList, habit.id!!, modified).run()
|
||||
}
|
||||
|
||||
// Reload saved version of the habit
|
||||
habit = habitList.getByUUID(habitRecord.uuid)
|
||||
habit = habitList.getByUUID(habitRecord.uuid)!!
|
||||
val entries = habit.originalEntries
|
||||
|
||||
// Import entries
|
||||
for (r in entryRecords) {
|
||||
val t = Timestamp(r.timestamp!!)
|
||||
val (_, value, notes) = habit!!.originalEntries.get(t)
|
||||
val oldNotes = r.notes ?: ""
|
||||
if (value != r.value || notes != oldNotes) CreateRepetitionCommand(habitList, habit, t, r.value!!, oldNotes).run()
|
||||
val (_, value, notes) = entries.get(t)
|
||||
if (value != r.value || notes != r.notes) {
|
||||
entries.add(Entry(t, r.value!!, r.notes ?: ""))
|
||||
}
|
||||
}
|
||||
|
||||
runner.notifyListeners(command)
|
||||
habit.recompute()
|
||||
}
|
||||
|
||||
habitList.resort()
|
||||
db.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.isoron.uhabits.core.ui.views.Theme
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import java.util.ArrayList
|
||||
import java.util.Calendar
|
||||
import kotlin.math.max
|
||||
|
||||
data class TargetCardState(
|
||||
val color: PaletteColor,
|
||||
@@ -96,15 +97,44 @@ class TargetCardPresenter {
|
||||
|
||||
val cal = DateUtils.getStartOfTodayCalendarWithOffset()
|
||||
val daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH)
|
||||
val daysInWeek = 7
|
||||
val daysInQuarter = 91
|
||||
val daysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR)
|
||||
val weeksInMonth = daysInMonth / 7
|
||||
val weeksInQuarter = 13
|
||||
val weeksInYear = 52
|
||||
val monthsInQuarter = 3
|
||||
val monthsInYear = 12
|
||||
|
||||
val denominator = habit.frequency.denominator
|
||||
val dailyTarget = habit.targetValue / habit.frequency.denominator
|
||||
val targetToday = dailyTarget * (1 - skippedDayToday)
|
||||
val targetThisWeek = dailyTarget * (7 - skippedDaysThisWeek)
|
||||
val targetThisMonth = dailyTarget * (daysInMonth - skippedDaysThisMonth)
|
||||
val targetThisQuarter = dailyTarget * (daysInQuarter - skippedDaysThisQuarter)
|
||||
val targetThisYear = dailyTarget * (daysInYear - skippedDaysThisYear)
|
||||
|
||||
var targetToday = dailyTarget
|
||||
var targetThisWeek = when (denominator) {
|
||||
7 -> habit.targetValue
|
||||
else -> dailyTarget * daysInWeek
|
||||
}
|
||||
var targetThisMonth = when (denominator) {
|
||||
30 -> habit.targetValue
|
||||
7 -> habit.targetValue * weeksInMonth
|
||||
else -> dailyTarget * daysInMonth
|
||||
}
|
||||
var targetThisQuarter = when (denominator) {
|
||||
30 -> habit.targetValue * monthsInQuarter
|
||||
7 -> habit.targetValue * weeksInQuarter
|
||||
else -> dailyTarget * daysInQuarter
|
||||
}
|
||||
var targetThisYear = when (denominator) {
|
||||
30 -> habit.targetValue * monthsInYear
|
||||
7 -> habit.targetValue * weeksInYear
|
||||
else -> dailyTarget * daysInYear
|
||||
}
|
||||
|
||||
targetToday = max(0.0, targetToday - dailyTarget * skippedDayToday)
|
||||
targetThisWeek = max(0.0, targetThisWeek - dailyTarget * skippedDaysThisWeek)
|
||||
targetThisMonth = max(0.0, targetThisMonth - dailyTarget * skippedDaysThisMonth)
|
||||
targetThisQuarter = max(0.0, targetThisQuarter - dailyTarget * skippedDaysThisQuarter)
|
||||
targetThisYear = max(0.0, targetThisYear - dailyTarget * skippedDaysThisYear)
|
||||
|
||||
val values = ArrayList<Double>()
|
||||
if (habit.frequency.denominator <= 1) values.add(valueToday / 1e3)
|
||||
|
||||
Reference in New Issue
Block a user