mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Compare commits
5 Commits
97b98a872d
...
96e20f751f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96e20f751f | ||
| 0daa4f6a2f | |||
| 035b392ece | |||
| 648c7277cf | |||
| 5006f5128b |
@@ -36,7 +36,7 @@ Updating gradle might fix this, so try again in the future to remove this and ru
|
|||||||
If this doesn't produce any warning, try to remove it.
|
If this doesn't produce any warning, try to remove it.
|
||||||
*/
|
*/
|
||||||
kotlin {
|
kotlin {
|
||||||
jvmToolchain(11)
|
jvmToolchain(17)
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -79,11 +79,11 @@ android {
|
|||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
isCoreLibraryDesugaringEnabled = true
|
isCoreLibraryDesugaringEnabled = true
|
||||||
targetCompatibility(JavaVersion.VERSION_11)
|
targetCompatibility(JavaVersion.VERSION_17)
|
||||||
sourceCompatibility(JavaVersion.VERSION_11)
|
sourceCompatibility(JavaVersion.VERSION_17)
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
|
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
|
||||||
buildFeatures.viewBinding = true
|
buildFeatures.viewBinding = true
|
||||||
lint.abortOnError = false
|
lint.abortOnError = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ class RingView : View {
|
|||||||
val res = StyledResources(context)
|
val res = StyledResources(context)
|
||||||
if (backgroundColor == null) backgroundColor = res.getColor(R.attr.cardBgColor)
|
if (backgroundColor == null) backgroundColor = res.getColor(R.attr.cardBgColor)
|
||||||
if (inactiveColor == null) inactiveColor = res.getColor(R.attr.contrast100)
|
if (inactiveColor == null) inactiveColor = res.getColor(R.attr.contrast100)
|
||||||
inactiveColor = setAlpha(inactiveColor!!, 0.1f)
|
inactiveColor = setAlpha(inactiveColor!!, 0.15f)
|
||||||
rect = RectF()
|
rect = RectF()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,8 +126,9 @@
|
|||||||
<item name="highlightedBackgroundColor">@color/black</item>
|
<item name="highlightedBackgroundColor">@color/black</item>
|
||||||
<item name="contrast0">@color/black</item>
|
<item name="contrast0">@color/black</item>
|
||||||
<item name="contrast20">@color/grey_900</item>
|
<item name="contrast20">@color/grey_900</item>
|
||||||
<item name="contrast60">@color/grey_700</item>
|
<item name="contrast40">@color/grey_800</item>
|
||||||
<item name="contrast80">@color/grey_700</item>
|
<item name="contrast60">@color/grey_500</item>
|
||||||
|
<item name="contrast80">@color/grey_400</item>
|
||||||
<item name="contrast100">@color/grey_200</item>
|
<item name="contrast100">@color/grey_200</item>
|
||||||
<item name="selectedBackground">@drawable/selected_box</item>
|
<item name="selectedBackground">@drawable/selected_box</item>
|
||||||
<item name="textColorAlertDialogListItem">@color/grey_100</item>
|
<item name="textColorAlertDialogListItem">@color/grey_100</item>
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Date,Value,Notes
|
||||||
|
|||||||
|
@@ -1 +1,2 @@
|
|||||||
|
Date,Score
|
||||||
2015-01-25,0.0000
|
2015-01-25,0.0000
|
||||||
|
|||||||
|
@@ -1,10 +1,11 @@
|
|||||||
2015-01-25,2
|
Date,Value,Notes
|
||||||
2015-01-24,0
|
2015-01-25,YES_MANUAL,
|
||||||
2015-01-23,1
|
2015-01-24,NO,Sick
|
||||||
2015-01-22,2
|
2015-01-23,YES_AUTO,"Forgot to do it, really"
|
||||||
2015-01-21,2
|
2015-01-22,YES_MANUAL,
|
||||||
2015-01-20,2
|
2015-01-21,YES_MANUAL,
|
||||||
2015-01-19,1
|
2015-01-20,YES_MANUAL,
|
||||||
2015-01-18,1
|
2015-01-19,YES_AUTO,"""Vacation"""
|
||||||
2015-01-17,2
|
2015-01-18,YES_AUTO,
|
||||||
2015-01-16,2
|
2015-01-17,YES_MANUAL,
|
||||||
|
2015-01-16,YES_MANUAL,
|
||||||
|
|||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
Date,Score
|
||||||
2015-01-25,0.2557
|
2015-01-25,0.2557
|
||||||
2015-01-24,0.2226
|
2015-01-24,0.2226
|
||||||
2015-01-23,0.1991
|
2015-01-23,0.1991
|
||||||
|
|||||||
|
@@ -1,11 +1,11 @@
|
|||||||
Date,Meditate,Wake up early,
|
Date,Meditate,Wake up early,
|
||||||
2015-01-25,-1,2,
|
2015-01-25,UNKNOWN,YES_MANUAL,
|
||||||
2015-01-24,-1,0,
|
2015-01-24,UNKNOWN,NO,
|
||||||
2015-01-23,-1,1,
|
2015-01-23,UNKNOWN,YES_AUTO,
|
||||||
2015-01-22,-1,2,
|
2015-01-22,UNKNOWN,YES_MANUAL,
|
||||||
2015-01-21,-1,2,
|
2015-01-21,UNKNOWN,YES_MANUAL,
|
||||||
2015-01-20,-1,2,
|
2015-01-20,UNKNOWN,YES_MANUAL,
|
||||||
2015-01-19,-1,1,
|
2015-01-19,UNKNOWN,YES_AUTO,
|
||||||
2015-01-18,-1,1,
|
2015-01-18,UNKNOWN,YES_AUTO,
|
||||||
2015-01-17,-1,2,
|
2015-01-17,UNKNOWN,YES_MANUAL,
|
||||||
2015-01-16,-1,2,
|
2015-01-16,UNKNOWN,YES_MANUAL,
|
||||||
|
|||||||
|
@@ -1,3 +1,3 @@
|
|||||||
Position,Name,Question,Description,NumRepetitions,Interval,Color
|
Position,Name,Type,Question,Description,FrequencyNumerator,FrequencyDenominator,Color,Unit,Target Type,Target Value,Archived?
|
||||||
001,Meditate,Did you meditate this morning?,,1,1,#FF8F00
|
001,Meditate,YES_NO,Did you meditate this morning?,,1,1,#FF8F00,,,,false
|
||||||
002,Wake up early,Did you wake up before 6am?,,2,3,#00897B
|
002,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#00897B,,,,false
|
||||||
|
|||||||
|
@@ -24,7 +24,7 @@ plugins {
|
|||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm().withJava()
|
jvm().withJava()
|
||||||
jvmToolchain(11)
|
jvmToolchain(17)
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.io
|
package org.isoron.uhabits.core.io
|
||||||
|
|
||||||
|
import com.opencsv.CSVWriter
|
||||||
import org.isoron.uhabits.core.models.Entry
|
import org.isoron.uhabits.core.models.Entry
|
||||||
import org.isoron.uhabits.core.models.EntryList
|
import org.isoron.uhabits.core.models.EntryList
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
@@ -32,7 +33,6 @@ import java.io.FileOutputStream
|
|||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Writer
|
import java.io.Writer
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
@@ -109,11 +109,14 @@ class HabitsCSVExporter(
|
|||||||
var oldest = today
|
var oldest = today
|
||||||
val known = habit.computedEntries.getKnown()
|
val known = habit.computedEntries.getKnown()
|
||||||
if (known.isNotEmpty()) oldest = known[known.size - 1].timestamp
|
if (known.isNotEmpty()) oldest = known[known.size - 1].timestamp
|
||||||
|
val csv = CSVWriter(out)
|
||||||
|
csv.writeNext(arrayOf("Date", "Score"), false)
|
||||||
for ((timestamp1, value) in habit.scores.getByInterval(oldest, today)) {
|
for ((timestamp1, value) in habit.scores.getByInterval(oldest, today)) {
|
||||||
val timestamp = dateFormat.format(timestamp1.unixTime)
|
val timestamp = dateFormat.format(timestamp1.unixTime)
|
||||||
val score = String.format(Locale.US, "%.4f", value)
|
val score = String.format(Locale.US, "%.4f", value)
|
||||||
out.write(String.format("%s,%s\n", timestamp, score))
|
csv.writeNext(arrayOf(timestamp, score), false)
|
||||||
}
|
}
|
||||||
|
csv.close()
|
||||||
out.close()
|
out.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,10 +125,20 @@ class HabitsCSVExporter(
|
|||||||
val out = FileWriter(exportDirName + filename)
|
val out = FileWriter(exportDirName + filename)
|
||||||
generatedFilenames.add(filename)
|
generatedFilenames.add(filename)
|
||||||
val dateFormat = DateFormats.getCSVDateFormat()
|
val dateFormat = DateFormats.getCSVDateFormat()
|
||||||
for ((timestamp, value) in entries.getKnown()) {
|
val csv = CSVWriter(out)
|
||||||
val date = dateFormat.format(timestamp.toJavaDate())
|
csv.writeNext(arrayOf("Date", "Value", "Notes"), false)
|
||||||
out.write(String.format(Locale.US, "%s,%d\n", date, value))
|
for (entry in entries.getKnown()) {
|
||||||
|
val date = dateFormat.format(entry.timestamp.toJavaDate())
|
||||||
|
csv.writeNext(
|
||||||
|
arrayOf(
|
||||||
|
date,
|
||||||
|
entry.formattedValue,
|
||||||
|
entry.notes
|
||||||
|
),
|
||||||
|
false
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
csv.close()
|
||||||
out.close()
|
out.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +180,7 @@ class HabitsCSVExporter(
|
|||||||
checksWriter.write(sb.toString())
|
checksWriter.write(sb.toString())
|
||||||
scoresWriter.write(sb.toString())
|
scoresWriter.write(sb.toString())
|
||||||
for (j in selectedHabits.indices) {
|
for (j in selectedHabits.indices) {
|
||||||
checksWriter.write(checkmarks[j][i].value.toString())
|
checksWriter.write(checkmarks[j][i].formattedValue)
|
||||||
checksWriter.write(delimiter)
|
checksWriter.write(delimiter)
|
||||||
val score = String.format(Locale.US, "%.4f", scores[j][i].value)
|
val score = String.format(Locale.US, "%.4f", scores[j][i].value)
|
||||||
scoresWriter.write(score)
|
scoresWriter.write(score)
|
||||||
|
|||||||
@@ -23,6 +23,16 @@ data class Entry(
|
|||||||
val value: Int,
|
val value: Int,
|
||||||
val notes: String = ""
|
val notes: String = ""
|
||||||
) {
|
) {
|
||||||
|
val formattedValue: String
|
||||||
|
get() = when (value) {
|
||||||
|
YES_MANUAL -> "YES_MANUAL"
|
||||||
|
YES_AUTO -> "YES_AUTO"
|
||||||
|
NO -> "NO"
|
||||||
|
SKIP -> "SKIP"
|
||||||
|
UNKNOWN -> "UNKNOWN"
|
||||||
|
else -> value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
/**
|
||||||
* Value indicating that the habit is not applicable for this timestamp.
|
* Value indicating that the habit is not applicable for this timestamp.
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.opencsv.CSVWriter
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Writer
|
import java.io.Writer
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
|
import java.util.Locale
|
||||||
import javax.annotation.concurrent.ThreadSafe
|
import javax.annotation.concurrent.ThreadSafe
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,24 +183,34 @@ abstract class HabitList : Iterable<Habit> {
|
|||||||
val header = arrayOf(
|
val header = arrayOf(
|
||||||
"Position",
|
"Position",
|
||||||
"Name",
|
"Name",
|
||||||
|
"Type",
|
||||||
"Question",
|
"Question",
|
||||||
"Description",
|
"Description",
|
||||||
"NumRepetitions",
|
"FrequencyNumerator",
|
||||||
"Interval",
|
"FrequencyDenominator",
|
||||||
"Color"
|
"Color",
|
||||||
|
"Unit",
|
||||||
|
"Target Type",
|
||||||
|
"Target Value",
|
||||||
|
"Archived?"
|
||||||
)
|
)
|
||||||
val csv = CSVWriter(out)
|
val csv = CSVWriter(out)
|
||||||
csv.writeNext(header, false)
|
csv.writeNext(header, false)
|
||||||
for (habit in this) {
|
for (habit in this) {
|
||||||
val (numerator, denominator) = habit.frequency
|
val (numerator, denominator) = habit.frequency
|
||||||
val cols = arrayOf(
|
val cols = arrayOf(
|
||||||
String.format("%03d", indexOf(habit) + 1),
|
String.format(Locale.US, "%03d", indexOf(habit) + 1),
|
||||||
habit.name,
|
habit.name,
|
||||||
|
habit.type.name,
|
||||||
habit.question,
|
habit.question,
|
||||||
habit.description,
|
habit.description,
|
||||||
numerator.toString(),
|
numerator.toString(),
|
||||||
denominator.toString(),
|
denominator.toString(),
|
||||||
habit.color.toCsvColor()
|
habit.color.toCsvColor(),
|
||||||
|
if (habit.isNumerical) habit.unit else "",
|
||||||
|
if (habit.isNumerical) habit.targetType.name else "",
|
||||||
|
if (habit.isNumerical) habit.targetValue.toString() else "",
|
||||||
|
habit.isArchived.toString()
|
||||||
)
|
)
|
||||||
csv.writeNext(cols, false)
|
csv.writeNext(cols, false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ class HabitFixtures(private val modelFactory: ModelFactory, private val habitLis
|
|||||||
true, false, false, true, true, true, false, false, true, true
|
true, false, false, true, true, true, false, false, true, true
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private var NON_DAILY_HABIT_NOTES = arrayOf(
|
||||||
|
"", "Sick", "Forgot to do it, really", "", "", "", "\"Vacation\"", "", "", ""
|
||||||
|
)
|
||||||
|
|
||||||
fun createEmptyHabit(
|
fun createEmptyHabit(
|
||||||
name: String = "Meditate",
|
name: String = "Meditate",
|
||||||
color: PaletteColor = PaletteColor(3),
|
color: PaletteColor = PaletteColor(3),
|
||||||
@@ -141,10 +145,10 @@ class HabitFixtures(private val modelFactory: ModelFactory, private val habitLis
|
|||||||
habit.frequency = Frequency(2, 3)
|
habit.frequency = Frequency(2, 3)
|
||||||
saveIfSQLite(habit)
|
saveIfSQLite(habit)
|
||||||
var timestamp = getToday()
|
var timestamp = getToday()
|
||||||
for (c in NON_DAILY_HABIT_CHECKS) {
|
for (i in NON_DAILY_HABIT_CHECKS.indices) {
|
||||||
var value = Entry.NO
|
var value = Entry.NO
|
||||||
if (c) value = Entry.YES_MANUAL
|
if (NON_DAILY_HABIT_CHECKS[i]) value = Entry.YES_MANUAL
|
||||||
habit.originalEntries.add(Entry(timestamp, value))
|
habit.originalEntries.add(Entry(timestamp, value, NON_DAILY_HABIT_NOTES[i]))
|
||||||
timestamp = timestamp.minus(1)
|
timestamp = timestamp.minus(1)
|
||||||
}
|
}
|
||||||
habit.recompute()
|
habit.recompute()
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.isoron.uhabits.core.io
|
package org.isoron.uhabits.core.io
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils
|
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.isoron.uhabits.core.BaseUnitTest
|
import org.isoron.uhabits.core.BaseUnitTest
|
||||||
import org.isoron.uhabits.core.models.Habit
|
import org.isoron.uhabits.core.models.Habit
|
||||||
@@ -30,6 +29,7 @@ import java.io.IOException
|
|||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class HabitsCSVExporterTest : BaseUnitTest() {
|
class HabitsCSVExporterTest : BaseUnitTest() {
|
||||||
@@ -108,15 +108,12 @@ class HabitsCSVExporterTest : BaseUnitTest() {
|
|||||||
|
|
||||||
private fun assertFileAndReferenceAreEqual(s: String) {
|
private fun assertFileAndReferenceAreEqual(s: String) {
|
||||||
val assetFilename = String.format("csv_export/%s", s)
|
val assetFilename = String.format("csv_export/%s", s)
|
||||||
val file = File.createTempFile("asset", "")
|
val actualFile = File(String.format("%s/%s", baseDir.absolutePath, s))
|
||||||
file.deleteOnExit()
|
val expectedFile = File.createTempFile("asset", "")
|
||||||
copyAssetToFile(assetFilename, file)
|
expectedFile.deleteOnExit()
|
||||||
|
copyAssetToFile(assetFilename, expectedFile)
|
||||||
assertTrue(
|
val actualContents = actualFile.readText()
|
||||||
FileUtils.contentEquals(
|
val expectedContents = expectedFile.readText()
|
||||||
file,
|
assertEquals(expectedContents, actualContents, "content mismatch for $s")
|
||||||
File(String.format("%s/%s", baseDir.absolutePath, s))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,13 +202,16 @@ class HabitListTest : BaseUnitTest() {
|
|||||||
h2.description = ""
|
h2.description = ""
|
||||||
h2.frequency = Frequency(2, 3)
|
h2.frequency = Frequency(2, 3)
|
||||||
h2.color = PaletteColor(5)
|
h2.color = PaletteColor(5)
|
||||||
|
val h3 = fixtures.createNumericalHabit()
|
||||||
list.add(h1)
|
list.add(h1)
|
||||||
list.add(h2)
|
list.add(h2)
|
||||||
|
list.add(h3)
|
||||||
val expectedCSV =
|
val expectedCSV =
|
||||||
"""
|
"""
|
||||||
Position,Name,Question,Description,NumRepetitions,Interval,Color
|
Position,Name,Type,Question,Description,FrequencyNumerator,FrequencyDenominator,Color,Unit,Target Type,Target Value,Archived?
|
||||||
001,Meditate,Did you meditate this morning?,this is a test description,1,1,#FF8F00
|
001,Meditate,YES_NO,Did you meditate this morning?,this is a test description,1,1,#FF8F00,,,,false
|
||||||
002,Wake up early,Did you wake up before 6am?,,2,3,#AFB42B
|
002,Run,NUMERICAL,How many miles did you run today?,,1,1,#E64A19,miles,AT_LEAST,2.0,false
|
||||||
|
003,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#AFB42B,,,,false
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
val writer = StringWriter()
|
val writer = StringWriter()
|
||||||
|
|||||||
Reference in New Issue
Block a user