Bump org.jlleitschuh.gradle.ktlint from 11.0.0 to 11.4.2

Also run ./gradlew ktlintFormat to follow new format.
This commit is contained in:
Quentin Hibon
2023-07-03 23:40:16 +02:00
parent 7348ddeffa
commit 11ca993a75
138 changed files with 497 additions and 376 deletions

View File

@@ -37,7 +37,7 @@ import kotlin.math.roundToInt
class JavaCanvas(
val image: BufferedImage,
val pixelScale: Double = 2.0,
val pixelScale: Double = 2.0
) : Canvas {
override fun toImage(): Image {
@@ -131,7 +131,7 @@ class JavaCanvas(
y: Double,
width: Double,
height: Double,
cornerRadius: Double,
cornerRadius: Double
) {
g2d.fill(
RoundRectangle2D.Double(
@@ -140,7 +140,7 @@ class JavaCanvas(
toPixel(width).toDouble(),
toPixel(height).toDouble(),
toPixel(cornerRadius).toDouble(),
toPixel(cornerRadius).toDouble(),
toPixel(cornerRadius).toDouble()
)
)
}
@@ -194,9 +194,8 @@ class JavaCanvas(
centerY: Double,
radius: Double,
startAngle: Double,
swipeAngle: Double,
swipeAngle: Double
) {
g2d.fillArc(
toPixel(centerX - radius),
toPixel(centerY - radius),

View File

@@ -33,8 +33,11 @@ class JavaResourceFile(val path: String) : ResourceFile {
get() {
val mainPath = Paths.get("assets/main/$path")
val testPath = Paths.get("assets/test/$path")
return if (Files.exists(mainPath)) mainPath
else testPath
return if (Files.exists(mainPath)) {
mainPath
} else {
testPath
}
}
override suspend fun exists(): Boolean {

View File

@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.HabitList
data class ArchiveHabitsCommand(
val habitList: HabitList,
val selected: List<Habit>,
val selected: List<Habit>
) : Command {
override fun run() {
for (h in selected) h.isArchived = true

View File

@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.PaletteColor
data class ChangeHabitColorCommand(
val habitList: HabitList,
val selected: List<Habit>,
val newColor: PaletteColor,
val newColor: PaletteColor
) : Command {
override fun run() {
for (h in selected) h.color = newColor

View File

@@ -27,7 +27,7 @@ import javax.inject.Inject
@AppScope
open class CommandRunner
@Inject constructor(
private val taskRunner: TaskRunner,
private val taskRunner: TaskRunner
) {
private val listeners: LinkedList<Listener> = LinkedList()

View File

@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.ModelFactory
data class CreateHabitCommand(
val modelFactory: ModelFactory,
val habitList: HabitList,
val model: Habit,
val model: Habit
) : Command {
override fun run() {
val habit = modelFactory.buildHabit()

View File

@@ -28,7 +28,7 @@ data class CreateRepetitionCommand(
val habit: Habit,
val timestamp: Timestamp,
val value: Int,
val notes: String,
val notes: String
) : Command {
override fun run() {
val entries = habit.originalEntries

View File

@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.HabitList
data class DeleteHabitsCommand(
val habitList: HabitList,
val selected: List<Habit>,
val selected: List<Habit>
) : Command {
override fun run() {
for (h in selected) habitList.remove(h)

View File

@@ -25,7 +25,7 @@ import org.isoron.uhabits.core.models.HabitNotFoundException
data class EditHabitCommand(
val habitList: HabitList,
val habitId: Long,
val modified: Habit,
val modified: Habit
) : Command {
override fun run() {
val habit = habitList.getById(habitId) ?: throw HabitNotFoundException()

View File

@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.models.HabitList
data class UnarchiveHabitsCommand(
val habitList: HabitList,
val selected: List<Habit>,
val selected: List<Habit>
) : Command {
override fun run() {
for (h in selected) h.isArchived = false

View File

@@ -35,7 +35,7 @@ interface Database {
tableName: String,
values: Map<String, Any?>,
where: String,
vararg params: String,
vararg params: String
): Int
fun insert(tableName: String, values: Map<String, Any?>): Long?

View File

@@ -41,7 +41,7 @@ class JdbcDatabase(private val connection: Connection) : Database {
tableName: String,
values: Map<String, Any?>,
where: String,
vararg params: String,
vararg params: String
): Int {
return try {
val fields = ArrayList<String?>()

View File

@@ -24,7 +24,7 @@ import java.io.InputStream
import java.util.Locale
class MigrationHelper(
private val db: Database,
private val db: Database
) {
fun migrateTo(newVersion: Int) {
try {

View File

@@ -28,7 +28,7 @@ import java.util.LinkedList
class Repository<T>(
private val klass: Class<T>,
private val db: Database,
private val db: Database
) {
/**
* Returns the record that has the id provided. If no record is found, returns null.

View File

@@ -20,7 +20,7 @@ import java.io.InputStream
import java.util.ArrayList
internal class Tokenizer(
private val mStream: InputStream,
private val mStream: InputStream
) {
private var mIsNext = false
private var mCurrent = 0

View File

@@ -30,14 +30,14 @@ class GenericImporter
loopDBImporter: LoopDBImporter,
rewireDBImporter: RewireDBImporter,
tickmateDBImporter: TickmateDBImporter,
habitBullCSVImporter: HabitBullCSVImporter,
habitBullCSVImporter: HabitBullCSVImporter
) : AbstractImporter() {
var importers: List<AbstractImporter> = listOf(
loopDBImporter,
rewireDBImporter,
tickmateDBImporter,
habitBullCSVImporter,
habitBullCSVImporter
)
override fun canHandle(file: File): Boolean {

View File

@@ -48,7 +48,7 @@ class HabitBullCSVImporter
@Inject constructor(
private val habitList: HabitList,
private val modelFactory: ModelFactory,
logging: Logging,
logging: Logging
) : AbstractImporter() {
private val logger = logging.getLogger("HabitBullCSVImporter")
@@ -98,7 +98,7 @@ class HabitBullCSVImporter
val formats = listOf(
DateFormat.getDateInstance(DateFormat.SHORT),
SimpleDateFormat("yyyy-MM-dd", Locale.US),
SimpleDateFormat("MM/dd/yyyy", Locale.US),
SimpleDateFormat("MM/dd/yyyy", Locale.US)
)
var parsedDate: Date? = null
for (fmt in formats) {
@@ -116,7 +116,7 @@ class HabitBullCSVImporter
return Timestamp.from(
parsedCalendar[YEAR],
parsedCalendar[MONTH],
parsedCalendar[DAY_OF_MONTH],
parsedCalendar[DAY_OF_MONTH]
)
}

View File

@@ -45,7 +45,7 @@ class LoopDBImporter
@AppScope val modelFactory: ModelFactory,
@AppScope val opener: DatabaseOpener,
@AppScope val runner: CommandRunner,
@AppScope logging: Logging,
@AppScope logging: Logging
) : AbstractImporter() {
private val logger = logging.getLogger("LoopDBImporter")

View File

@@ -125,7 +125,7 @@ class RewireDBImporter
try {
c = db.query(
"select distinct date from checkins where habit_id=? and type=2",
rewireHabitId.toString(),
rewireHabitId.toString()
)
if (!c.moveToNext()) return
do {
@@ -147,7 +147,7 @@ class RewireDBImporter
try {
c = db.query(
"select time, active_days from reminders where habit_id=? limit 1",
rewireHabitId.toString(),
rewireHabitId.toString()
)
if (!c.moveToNext()) return
val rewireReminder = c.getInt(0)!!

View File

@@ -72,7 +72,7 @@ class TickmateDBImporter @Inject constructor(
try {
c = db.query(
"select distinct year, month, day from ticks where _track_id=?",
tickmateTrackId.toString(),
tickmateTrackId.toString()
)
if (!c.moveToNext()) return
do {

View File

@@ -21,7 +21,7 @@ package org.isoron.uhabits.core.models
data class Entry(
val timestamp: Timestamp,
val value: Int,
val notes: String = "",
val notes: String = ""
) {
companion object {
/**

View File

@@ -90,7 +90,7 @@ open class EntryList {
open fun recomputeFrom(
originalEntries: EntryList,
frequency: Frequency,
isNumerical: Boolean,
isNumerical: Boolean
) {
clear()
val original = originalEntries.getKnown()
@@ -167,7 +167,7 @@ open class EntryList {
*/
fun buildEntriesFromInterval(
original: List<Entry>,
intervals: List<Interval>,
intervals: List<Interval>
): List<Entry> {
val result = arrayListOf<Entry>()
if (original.isEmpty()) return result
@@ -246,7 +246,7 @@ open class EntryList {
fun buildIntervals(
freq: Frequency,
entries: List<Entry>,
entries: List<Entry>
): ArrayList<Interval> {
val filtered = entries.filter { it.value == YES_MANUAL }
val num = freq.numerator
@@ -294,21 +294,22 @@ open class EntryList {
fun List<Entry>.groupedSum(
truncateField: DateUtils.TruncateField,
firstWeekday: Int = Calendar.SATURDAY,
isNumerical: Boolean,
isNumerical: Boolean
): List<Entry> {
return this.map { (timestamp, value) ->
if (isNumerical) {
if (value == SKIP)
if (value == SKIP) {
Entry(timestamp, 0)
else
} else {
Entry(timestamp, max(0, value))
}
} else {
Entry(timestamp, if (value == YES_MANUAL) 1000 else 0)
}
}.groupBy { entry ->
entry.timestamp.truncate(
truncateField,
firstWeekday,
firstWeekday
)
}.entries.map { (timestamp, entries) ->
Entry(timestamp, entries.sumOf { it.value })
@@ -333,7 +334,7 @@ fun List<Entry>.countSkippedDays(
}.groupBy { entry ->
entry.timestamp.truncate(
truncateField,
firstWeekday,
firstWeekday
)
}.entries.map { (timestamp, entries) ->
Entry(timestamp, entries.sumOf { it.value })

View File

@@ -20,7 +20,7 @@ package org.isoron.uhabits.core.models
data class Frequency(
var numerator: Int,
var denominator: Int,
var denominator: Int
) {
init {
if (numerator == denominator) {

View File

@@ -39,7 +39,7 @@ data class Habit(
val computedEntries: EntryList,
val originalEntries: EntryList,
val scores: ScoreList,
val streaks: StreakList,
val streaks: StreakList
) {
init {
if (uuid == null) this.uuid = UUID.randomUUID().toString().replace("-", "")
@@ -78,7 +78,7 @@ data class Habit(
computedEntries.recomputeFrom(
originalEntries = originalEntries,
frequency = frequency,
isNumerical = isNumerical,
isNumerical = isNumerical
)
val today = DateUtils.getTodayWithOffset()
@@ -94,13 +94,13 @@ data class Habit(
targetValue = targetValue,
computedEntries = computedEntries,
from = from,
to = to,
to = to
)
streaks.recompute(
computedEntries,
from,
to,
to
)
}

View File

@@ -22,7 +22,7 @@ data class HabitMatcher(
val isArchivedAllowed: Boolean = false,
val isReminderRequired: Boolean = false,
val isCompletedAllowed: Boolean = true,
val isEnteredAllowed: Boolean = true,
val isEnteredAllowed: Boolean = true
) {
fun matches(habit: Habit): Boolean {
if (!isArchivedAllowed && habit.isArchived) return false
@@ -36,7 +36,7 @@ data class HabitMatcher(
@JvmField
val WITH_ALARM = HabitMatcher(
isArchivedAllowed = true,
isReminderRequired = true,
isReminderRequired = true
)
}
}

View File

@@ -35,7 +35,7 @@ interface ModelFactory {
scores = scores,
streaks = streaks,
originalEntries = buildOriginalEntries(),
computedEntries = buildComputedEntries(),
computedEntries = buildComputedEntries()
)
}
fun buildComputedEntries(): EntryList

View File

@@ -23,7 +23,7 @@ import org.isoron.uhabits.core.utils.DateUtils
data class Reminder(
val hour: Int,
val minute: Int,
val days: WeekdayList,
val days: WeekdayList
) {
val timeInMillis: Long
get() = DateUtils.getUpcomingTimeInMillis(hour, minute)

View File

@@ -23,7 +23,7 @@ import kotlin.math.sqrt
data class Score(
val timestamp: Timestamp,
val value: Double,
val value: Double
) {
companion object {
@@ -39,7 +39,7 @@ data class Score(
fun compute(
frequency: Double,
previousScore: Double,
checkmarkValue: Double,
checkmarkValue: Double
): Double {
val multiplier = 0.5.pow(sqrt(frequency) / 13.0)
var score = previousScore * multiplier

View File

@@ -49,7 +49,7 @@ class ScoreList {
@Synchronized
fun getByInterval(
fromTimestamp: Timestamp,
toTimestamp: Timestamp,
toTimestamp: Timestamp
): List<Score> {
val result: MutableList<Score> = ArrayList()
if (fromTimestamp.isNewerThan(toTimestamp)) return result
@@ -72,7 +72,7 @@ class ScoreList {
targetValue: Double,
computedEntries: EntryList,
from: Timestamp,
to: Timestamp,
to: Timestamp
) {
map.clear()
var rollingSum = 0.0
@@ -102,10 +102,11 @@ class ScoreList {
val normalizedRollingSum = rollingSum / 1000
if (values[offset] != Entry.SKIP) {
val percentageCompleted = if (!isAtMost) {
if (targetValue > 0)
if (targetValue > 0) {
min(1.0, normalizedRollingSum / targetValue)
else
} else {
1.0
}
} else {
if (targetValue > 0) {
(1 - ((normalizedRollingSum - targetValue) / targetValue)).coerceIn(

View File

@@ -22,11 +22,14 @@ import java.lang.Long.signum
data class Streak(
val start: Timestamp,
val end: Timestamp,
val end: Timestamp
) {
fun compareLonger(other: Streak): Int {
return if (length != other.length) signum(length - other.length.toLong())
else compareNewer(other)
return if (length != other.length) {
signum(length - other.length.toLong())
} else {
compareNewer(other)
}
}
fun compareNewer(other: Streak): Int {

View File

@@ -37,7 +37,7 @@ class StreakList {
fun recompute(
computedEntries: EntryList,
from: Timestamp,
to: Timestamp,
to: Timestamp
) {
list.clear()
val timestamps = computedEntries

View File

@@ -33,7 +33,7 @@ import javax.inject.Inject
*/
class SQLModelFactory
@Inject constructor(
val database: Database,
val database: Database
) : ModelFactory {
override fun buildOriginalEntries() = SQLiteEntryList(database)
override fun buildComputedEntries() = EntryList()

View File

@@ -158,8 +158,10 @@ open class Preferences(private val storage: Storage) {
open var isCheckmarkSequenceReversed: Boolean
get() {
if (shouldReverseCheckmarks == null) shouldReverseCheckmarks =
storage.getBoolean("pref_checkmark_reverse_order", false)
if (shouldReverseCheckmarks == null) {
shouldReverseCheckmarks =
storage.getBoolean("pref_checkmark_reverse_order", false)
}
return shouldReverseCheckmarks!!
}
set(reverse) {
@@ -255,9 +257,13 @@ open class Preferences(private val storage: Storage) {
fun getLongArray(key: String, defValue: LongArray): LongArray {
val string = getString(key, "")
return if (string.isEmpty()) defValue else splitLongs(
string
)
return if (string.isEmpty()) {
defValue
} else {
splitLongs(
string
)
}
}
}

View File

@@ -31,6 +31,6 @@ class ExportCSVTaskFactory
fun create(
selectedHabits: List<Habit>,
outputDir: File,
listener: ExportCSVTask.Listener,
listener: ExportCSVTask.Listener
) = ExportCSVTask(habitList, selectedHabits, outputDir, listener)
}

View File

@@ -56,7 +56,7 @@ class HabitCardListCache @Inject constructor(
private val allHabits: HabitList,
private val commandRunner: CommandRunner,
taskRunner: TaskRunner,
logging: Logging,
logging: Logging
) : CommandRunner.Listener {
private val logger = logging.getLogger("HabitCardListCache")
@@ -219,8 +219,12 @@ class HabitCardListCache @Inject constructor(
fun copyCheckmarksFrom(oldData: CacheData) {
val empty = IntArray(checkmarkCount)
for (id in idToHabit.keys) {
if (oldData.checkmarks.containsKey(id)) checkmarks[id] =
oldData.checkmarks[id]!! else checkmarks[id] = empty
if (oldData.checkmarks.containsKey(id)) {
checkmarks[id] =
oldData.checkmarks[id]!!
} else {
checkmarks[id] = empty
}
}
}
@@ -228,16 +232,24 @@ class HabitCardListCache @Inject constructor(
fun copyNoteIndicatorsFrom(oldData: CacheData) {
val empty = (0..checkmarkCount).map { "" }.toTypedArray()
for (id in idToHabit.keys) {
if (oldData.notes.containsKey(id)) notes[id] =
oldData.notes[id]!! else notes[id] = empty
if (oldData.notes.containsKey(id)) {
notes[id] =
oldData.notes[id]!!
} else {
notes[id] = empty
}
}
}
@Synchronized
fun copyScoresFrom(oldData: CacheData) {
for (id in idToHabit.keys) {
if (oldData.scores.containsKey(id)) scores[id] =
oldData.scores[id]!! else scores[id] = 0.0
if (oldData.scores.containsKey(id)) {
scores[id] =
oldData.scores[id]!!
} else {
scores[id] = 0.0
}
}
}
@@ -384,11 +396,13 @@ class HabitCardListCache @Inject constructor(
if (prevPosition < 0) {
performInsert(habit, currentPosition)
} else {
if (prevPosition != currentPosition) performMove(
habit,
prevPosition,
currentPosition
)
if (prevPosition != currentPosition) {
performMove(
habit,
prevPosition,
currentPosition
)
}
if (id == null) throw NullPointerException()
performUpdate(id, currentPosition)
}

View File

@@ -24,7 +24,7 @@ import javax.inject.Inject
class HintListFactory
@Inject constructor(
val preferences: Preferences,
val preferences: Preferences
) {
fun create(hints: Array<String>) = HintList(preferences, hints)
}

View File

@@ -60,7 +60,7 @@ open class ListHabitsBehavior @Inject constructor(
screen.showCheckmarkPopup(
entry.value,
entry.notes,
habit.color,
habit.color
) { newValue, newNotes ->
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes))
}
@@ -73,9 +73,13 @@ open class ListHabitsBehavior @Inject constructor(
val outputDir = dirFinder.getCSVOutputDir()
taskRunner.execute(
ExportCSVTask(habitList, selected, outputDir) { filename: String? ->
if (filename != null) screen.showSendFileScreen(filename) else screen.showMessage(
Message.COULD_NOT_EXPORT
)
if (filename != null) {
screen.showSendFileScreen(filename)
} else {
screen.showMessage(
Message.COULD_NOT_EXPORT
)
}
}
)
}
@@ -125,7 +129,7 @@ open class ListHabitsBehavior @Inject constructor(
IMPORT_FAILED,
DATABASE_REPAIRED,
COULD_NOT_GENERATE_BUG_REPORT,
FILE_NOT_RECOGNIZED,
FILE_NOT_RECOGNIZED
}
interface BugReporter {

View File

@@ -106,14 +106,14 @@ class ListHabitsMenuBehavior @Inject constructor(
adapter.setFilter(
HabitMatcher(
isArchivedAllowed = showArchived,
isEnteredAllowed = showCompleted,
isEnteredAllowed = showCompleted
)
)
} else {
adapter.setFilter(
HabitMatcher(
isArchivedAllowed = showArchived,
isCompletedAllowed = showCompleted,
isCompletedAllowed = showCompleted
)
)
}

View File

@@ -57,7 +57,7 @@ data class ShowHabitState(
val frequency: FrequencyCardState,
val history: HistoryCardState,
val bar: BarCardState,
val theme: Theme,
val theme: Theme
)
class ShowHabitPresenter(
@@ -65,31 +65,31 @@ class ShowHabitPresenter(
val habitList: HabitList,
val preferences: Preferences,
val screen: Screen,
val commandRunner: CommandRunner,
val commandRunner: CommandRunner
) {
val historyCardPresenter = HistoryCardPresenter(
commandRunner = commandRunner,
habit = habit,
habitList = habitList,
preferences = preferences,
screen = screen,
screen = screen
)
val barCardPresenter = BarCardPresenter(
preferences = preferences,
screen = screen,
screen = screen
)
val scoreCardPresenter = ScoreCardPresenter(
preferences = preferences,
screen = screen,
screen = screen
)
companion object {
fun buildState(
habit: Habit,
preferences: Preferences,
theme: Theme,
theme: Theme
): ShowHabitState {
return ShowHabitState(
title = habit.name,
@@ -98,47 +98,47 @@ class ShowHabitPresenter(
theme = theme,
subtitle = SubtitleCardPresenter.buildState(
habit = habit,
theme = theme,
theme = theme
),
overview = OverviewCardPresenter.buildState(
habit = habit,
theme = theme,
theme = theme
),
notes = NotesCardPresenter.buildState(
habit = habit,
habit = habit
),
target = TargetCardPresenter.buildState(
habit = habit,
firstWeekday = preferences.firstWeekdayInt,
theme = theme,
theme = theme
),
streaks = StreakCartPresenter.buildState(
habit = habit,
theme = theme,
theme = theme
),
scores = ScoreCardPresenter.buildState(
spinnerPosition = preferences.scoreCardSpinnerPosition,
habit = habit,
firstWeekday = preferences.firstWeekdayInt,
theme = theme,
theme = theme
),
frequency = FrequencyCardPresenter.buildState(
habit = habit,
firstWeekday = preferences.firstWeekdayInt,
theme = theme,
theme = theme
),
history = HistoryCardPresenter.buildState(
habit = habit,
firstWeekday = preferences.firstWeekday,
theme = theme,
theme = theme
),
bar = BarCardPresenter.buildState(
habit = habit,
firstWeekday = preferences.firstWeekdayInt,
boolSpinnerPosition = preferences.barCardBoolSpinnerPosition,
numericalSpinnerPosition = preferences.barCardNumericalSpinnerPosition,
theme = theme,
),
theme = theme
)
)
}
}

View File

@@ -38,7 +38,7 @@ class ShowHabitMenuPresenter(
private val habitList: HabitList,
private val screen: Screen,
private val system: System,
private val taskRunner: TaskRunner,
private val taskRunner: TaskRunner
) {
fun onEditHabit() {
screen.showEditHabitScreen(habit)

View File

@@ -34,12 +34,12 @@ data class BarCardState(
val color: PaletteColor,
val entries: List<Entry>,
val isNumerical: Boolean,
val numericalSpinnerPosition: Int,
val numericalSpinnerPosition: Int
)
class BarCardPresenter(
val preferences: Preferences,
val screen: Screen,
val screen: Screen
) {
companion object {
val numericalBucketSizes = intArrayOf(1, 7, 31, 92, 365)
@@ -50,7 +50,7 @@ class BarCardPresenter(
firstWeekday: Int,
numericalSpinnerPosition: Int,
boolSpinnerPosition: Int,
theme: Theme,
theme: Theme
): BarCardState {
val bucketSize = if (habit.isNumerical) {
numericalBucketSizes[numericalSpinnerPosition]
@@ -62,7 +62,7 @@ class BarCardPresenter(
val entries = habit.computedEntries.getByInterval(oldest, today).groupedSum(
truncateField = ScoreCardPresenter.getTruncateField(bucketSize),
firstWeekday = firstWeekday,
isNumerical = habit.isNumerical,
isNumerical = habit.isNumerical
)
return BarCardState(
theme = theme,
@@ -71,7 +71,7 @@ class BarCardPresenter(
color = habit.color,
isNumerical = habit.isNumerical,
numericalSpinnerPosition = numericalSpinnerPosition,
boolSpinnerPosition = boolSpinnerPosition,
boolSpinnerPosition = boolSpinnerPosition
)
}
}

View File

@@ -46,7 +46,7 @@ class FrequencyCardPresenter {
isNumerical = habit.isNumerical
),
firstWeekday = firstWeekday,
theme = theme,
theme = theme
)
}
}

View File

@@ -53,7 +53,7 @@ data class HistoryCardState(
val defaultSquare: HistoryChart.Square,
val notesIndicators: List<Boolean>,
val theme: Theme,
val today: LocalDate,
val today: LocalDate
)
class HistoryCardPresenter(
@@ -61,7 +61,7 @@ class HistoryCardPresenter(
val habit: Habit,
val habitList: HabitList,
val preferences: Preferences,
val screen: Screen,
val screen: Screen
) : OnDateClickedListener {
override fun onDateLongPress(date: LocalDate) {
@@ -70,8 +70,11 @@ class HistoryCardPresenter(
if (habit.isNumerical) {
showNumberPopup(timestamp)
} else {
if (preferences.isShortToggleEnabled) showCheckmarkPopup(timestamp)
else toggle(timestamp)
if (preferences.isShortToggleEnabled) {
showCheckmarkPopup(timestamp)
} else {
toggle(timestamp)
}
}
}
@@ -81,8 +84,11 @@ class HistoryCardPresenter(
if (habit.isNumerical) {
showNumberPopup(timestamp)
} else {
if (preferences.isShortToggleEnabled) toggle(timestamp)
else showCheckmarkPopup(timestamp)
if (preferences.isShortToggleEnabled) {
toggle(timestamp)
} else {
showCheckmarkPopup(timestamp)
}
}
}
@@ -91,7 +97,7 @@ class HistoryCardPresenter(
screen.showCheckmarkPopup(
entry.value,
entry.notes,
habit.color,
habit.color
) { newValue, newNotes ->
commandRunner.run(
CreateRepetitionCommand(
@@ -99,8 +105,8 @@ class HistoryCardPresenter(
habit,
timestamp,
newValue,
newNotes,
),
newNotes
)
)
}
}
@@ -118,8 +124,8 @@ class HistoryCardPresenter(
habit,
timestamp,
nextValue,
entry.notes,
),
entry.notes
)
)
}
@@ -128,7 +134,7 @@ class HistoryCardPresenter(
val oldValue = entry.value
screen.showNumberPopup(
value = oldValue / 1000.0,
notes = entry.notes,
notes = entry.notes
) { newValue: Double, newNotes: String ->
val thousands = (newValue * 1000).roundToInt()
commandRunner.run(
@@ -137,8 +143,8 @@ class HistoryCardPresenter(
habit,
timestamp,
thousands,
newNotes,
),
newNotes
)
)
}
}
@@ -151,7 +157,7 @@ class HistoryCardPresenter(
fun buildState(
habit: Habit,
firstWeekday: DayOfWeek,
theme: Theme,
theme: Theme
): HistoryCardState {
val today = DateUtils.getTodayWithOffset()
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
@@ -190,7 +196,7 @@ class HistoryCardPresenter(
theme = theme,
series = series,
defaultSquare = OFF,
notesIndicators = notesIndicators,
notesIndicators = notesIndicators
)
}
}
@@ -201,13 +207,13 @@ class HistoryCardPresenter(
fun showNumberPopup(
value: Double,
notes: String,
callback: ListHabitsBehavior.NumberPickerCallback,
callback: ListHabitsBehavior.NumberPickerCallback
)
fun showCheckmarkPopup(
selectedValue: Int,
notes: String,
color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback,
callback: ListHabitsBehavior.CheckMarkDialogCallback
)
}
}

View File

@@ -22,13 +22,13 @@ package org.isoron.uhabits.core.ui.screens.habits.show.views
import org.isoron.uhabits.core.models.Habit
data class NotesCardState(
val description: String,
val description: String
)
class NotesCardPresenter {
companion object {
fun buildState(habit: Habit) = NotesCardState(
description = habit.description,
description = habit.description
)
}
}

View File

@@ -31,7 +31,7 @@ data class OverviewCardState(
val scoreYearDiff: Float,
val scoreToday: Float,
val totalCount: Long,
val theme: Theme,
val theme: Theme
)
class OverviewCardPresenter {
@@ -54,7 +54,7 @@ class OverviewCardPresenter {
scoreMonthDiff = scoreToday - scoreLastMonth,
scoreYearDiff = scoreToday - scoreLastYear,
totalCount = totalCount,
theme = theme,
theme = theme
)
}
}

View File

@@ -31,12 +31,12 @@ data class ScoreCardState(
val bucketSize: Int,
val spinnerPosition: Int,
val color: PaletteColor,
val theme: Theme,
val theme: Theme
)
class ScoreCardPresenter(
val preferences: Preferences,
val screen: Screen,
val screen: Screen
) {
companion object {
val BUCKET_SIZES = intArrayOf(1, 7, 31, 92, 365)
@@ -55,7 +55,7 @@ class ScoreCardPresenter(
habit: Habit,
firstWeekday: Int,
spinnerPosition: Int,
theme: Theme,
theme: Theme
): ScoreCardState {
val bucketSize = BUCKET_SIZES[spinnerPosition]
val today = DateUtils.getTodayWithOffset()
@@ -80,7 +80,7 @@ class ScoreCardPresenter(
scores = scores,
bucketSize = bucketSize,
spinnerPosition = spinnerPosition,
theme = theme,
theme = theme
)
}
}

View File

@@ -27,7 +27,7 @@ import org.isoron.uhabits.core.ui.views.Theme
data class StreakCardState(
val color: PaletteColor,
val bestStreaks: List<Streak>,
val theme: Theme,
val theme: Theme
)
class StreakCartPresenter {
@@ -36,7 +36,7 @@ class StreakCartPresenter {
return StreakCardState(
color = habit.color,
bestStreaks = habit.streaks.getBest(10),
theme = theme,
theme = theme
)
}
}

View File

@@ -35,14 +35,14 @@ data class SubtitleCardState(
val targetValue: Double = 0.0,
val targetType: NumericalHabitType = NumericalHabitType.AT_LEAST,
val unit: String = "",
val theme: Theme,
val theme: Theme
)
class SubtitleCardPresenter {
companion object {
fun buildState(
habit: Habit,
theme: Theme,
theme: Theme
): SubtitleCardState = SubtitleCardState(
color = habit.color,
frequency = habit.frequency,
@@ -52,7 +52,7 @@ class SubtitleCardPresenter {
targetValue = habit.targetValue,
targetType = habit.targetType,
unit = habit.unit,
theme = theme,
theme = theme
)
}
}

View File

@@ -34,7 +34,7 @@ data class TargetCardState(
val values: List<Double> = listOf(),
val targets: List<Double> = listOf(),
val intervals: List<Int> = listOf(),
val theme: Theme,
val theme: Theme
)
class TargetCardPresenter {
@@ -42,7 +42,7 @@ class TargetCardPresenter {
fun buildState(
habit: Habit,
firstWeekday: Int,
theme: Theme,
theme: Theme
): TargetCardState {
val today = DateUtils.getTodayWithOffset()
val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today
@@ -74,7 +74,7 @@ class TargetCardPresenter {
).firstOrNull()?.value ?: 0
val skippedDaysThisMonth = entries.countSkippedDays(
truncateField = DateUtils.TruncateField.MONTH,
truncateField = DateUtils.TruncateField.MONTH
).firstOrNull()?.value ?: 0
val valueThisQuarter = entries.groupedSum(
@@ -162,7 +162,7 @@ class TargetCardPresenter {
values = values,
targets = targets,
intervals = intervals,
theme = theme,
theme = theme
)
}
}

View File

@@ -31,7 +31,7 @@ import kotlin.math.round
class BarChart(
var theme: Theme,
var dateFormatter: LocalDateFormatter,
var dateFormatter: LocalDateFormatter
) : DataView {
// Data

View File

@@ -47,7 +47,7 @@ class HistoryChart(
var theme: Theme,
var today: LocalDate,
var onDateClickedListener: OnDateClickedListener = object : OnDateClickedListener {},
var padding: Double = 0.0,
var padding: Double = 0.0
) : DataView {
enum class Square {
@@ -55,7 +55,7 @@ class HistoryChart(
OFF,
GREY,
DIMMED,
HATCHED,
HATCHED
}
var squareSpacing = 1.0
@@ -147,7 +147,7 @@ class HistoryChart(
canvas: Canvas,
column: Int,
topDate: LocalDate,
topOffset: Int,
topOffset: Int
) {
drawHeader(canvas, column, topDate)
repeat(7) { row ->
@@ -202,9 +202,8 @@ class HistoryChart(
width: Double,
height: Double,
date: LocalDate,
offset: Int,
offset: Int
) {
val value = if (offset >= series.size) defaultSquare else series[offset]
val hasNotes = if (offset >= notesIndicators.size) false else notesIndicators[offset]
val squareColor: Color

View File

@@ -138,7 +138,7 @@ abstract class DateUtils {
(firstWeekday + 2) % 7 + 1,
(firstWeekday + 3) % 7 + 1,
(firstWeekday + 4) % 7 + 1,
(firstWeekday + 5) % 7 + 1,
(firstWeekday + 5) % 7 + 1
)
}
@@ -279,7 +279,6 @@ abstract class DateUtils {
val cal = getCalendar(timestamp)
return when (field) {
TruncateField.DAY -> { cal.timeInMillis }
TruncateField.MONTH -> {