Compare commits

..

No commits in common. '96e20f751f945ea052d6ffc30cdfd510aa52ff2c' and '97b98a872d765801cdc47d94ec1b432357672604' have entirely different histories.

@ -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.
*/
kotlin {
jvmToolchain(17)
jvmToolchain(11)
}
android {
@ -79,11 +79,11 @@ android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
targetCompatibility(JavaVersion.VERSION_17)
sourceCompatibility(JavaVersion.VERSION_17)
targetCompatibility(JavaVersion.VERSION_11)
sourceCompatibility(JavaVersion.VERSION_11)
}
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
buildFeatures.viewBinding = true
lint.abortOnError = false
}

@ -204,7 +204,7 @@ class RingView : View {
val res = StyledResources(context)
if (backgroundColor == null) backgroundColor = res.getColor(R.attr.cardBgColor)
if (inactiveColor == null) inactiveColor = res.getColor(R.attr.contrast100)
inactiveColor = setAlpha(inactiveColor!!, 0.15f)
inactiveColor = setAlpha(inactiveColor!!, 0.1f)
rect = RectF()
}

@ -126,9 +126,8 @@
<item name="highlightedBackgroundColor">@color/black</item>
<item name="contrast0">@color/black</item>
<item name="contrast20">@color/grey_900</item>
<item name="contrast40">@color/grey_800</item>
<item name="contrast60">@color/grey_500</item>
<item name="contrast80">@color/grey_400</item>
<item name="contrast60">@color/grey_700</item>
<item name="contrast80">@color/grey_700</item>
<item name="contrast100">@color/grey_200</item>
<item name="selectedBackground">@drawable/selected_box</item>
<item name="textColorAlertDialogListItem">@color/grey_100</item>

@ -1 +0,0 @@
Date,Value,Notes
1 Date Value Notes
Date Value Notes

@ -1,2 +1 @@
Date,Score
2015-01-25,0.0000

1 Date 2015-01-25 Score 0.0000
Date Score
1 2015-01-25 2015-01-25 0.0000 0.0000

@ -1,11 +1,10 @@
Date,Value,Notes
2015-01-25,YES_MANUAL,
2015-01-24,NO,Sick
2015-01-23,YES_AUTO,"Forgot to do it, really"
2015-01-22,YES_MANUAL,
2015-01-21,YES_MANUAL,
2015-01-20,YES_MANUAL,
2015-01-19,YES_AUTO,"""Vacation"""
2015-01-18,YES_AUTO,
2015-01-17,YES_MANUAL,
2015-01-16,YES_MANUAL,
2015-01-25,2
2015-01-24,0
2015-01-23,1
2015-01-22,2
2015-01-21,2
2015-01-20,2
2015-01-19,1
2015-01-18,1
2015-01-17,2
2015-01-16,2

1 Date 2015-01-25 Value 2 Notes
2 2015-01-25 2015-01-24 YES_MANUAL 0
3 2015-01-24 2015-01-23 NO 1 Sick
4 2015-01-23 2015-01-22 YES_AUTO 2 Forgot to do it, really
5 2015-01-22 2015-01-21 YES_MANUAL 2
6 2015-01-21 2015-01-20 YES_MANUAL 2
7 2015-01-20 2015-01-19 YES_MANUAL 1
8 2015-01-19 2015-01-18 YES_AUTO 1 "Vacation"
9 2015-01-18 2015-01-17 YES_AUTO 2
10 2015-01-17 2015-01-16 YES_MANUAL 2
2015-01-16 YES_MANUAL

@ -1,4 +1,3 @@
Date,Score
2015-01-25,0.2557
2015-01-24,0.2226
2015-01-23,0.1991

1 Date 2015-01-25 Score 0.2557
Date Score
1 2015-01-25 2015-01-25 0.2557 0.2557
2 2015-01-24 2015-01-24 0.2226 0.2226
3 2015-01-23 2015-01-23 0.1991 0.1991

@ -1,11 +1,11 @@
Date,Meditate,Wake up early,
2015-01-25,UNKNOWN,YES_MANUAL,
2015-01-24,UNKNOWN,NO,
2015-01-23,UNKNOWN,YES_AUTO,
2015-01-22,UNKNOWN,YES_MANUAL,
2015-01-21,UNKNOWN,YES_MANUAL,
2015-01-20,UNKNOWN,YES_MANUAL,
2015-01-19,UNKNOWN,YES_AUTO,
2015-01-18,UNKNOWN,YES_AUTO,
2015-01-17,UNKNOWN,YES_MANUAL,
2015-01-16,UNKNOWN,YES_MANUAL,
2015-01-25,-1,2,
2015-01-24,-1,0,
2015-01-23,-1,1,
2015-01-22,-1,2,
2015-01-21,-1,2,
2015-01-20,-1,2,
2015-01-19,-1,1,
2015-01-18,-1,1,
2015-01-17,-1,2,
2015-01-16,-1,2,

1 Date Meditate Wake up early
2 2015-01-25 UNKNOWN -1 YES_MANUAL 2
3 2015-01-24 UNKNOWN -1 NO 0
4 2015-01-23 UNKNOWN -1 YES_AUTO 1
5 2015-01-22 UNKNOWN -1 YES_MANUAL 2
6 2015-01-21 UNKNOWN -1 YES_MANUAL 2
7 2015-01-20 UNKNOWN -1 YES_MANUAL 2
8 2015-01-19 UNKNOWN -1 YES_AUTO 1
9 2015-01-18 UNKNOWN -1 YES_AUTO 1
10 2015-01-17 UNKNOWN -1 YES_MANUAL 2
11 2015-01-16 UNKNOWN -1 YES_MANUAL 2

@ -1,3 +1,3 @@
Position,Name,Type,Question,Description,FrequencyNumerator,FrequencyDenominator,Color,Unit,Target Type,Target Value,Archived?
001,Meditate,YES_NO,Did you meditate this morning?,,1,1,#FF8F00,,,,false
002,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#00897B,,,,false
Position,Name,Question,Description,NumRepetitions,Interval,Color
001,Meditate,Did you meditate this morning?,,1,1,#FF8F00
002,Wake up early,Did you wake up before 6am?,,2,3,#00897B

1 Position Name Type Question Description NumRepetitions FrequencyNumerator Interval FrequencyDenominator Color Unit Target Type Target Value Archived?
2 001 Meditate YES_NO Did you meditate this morning? 1 1 1 1 #FF8F00 false
3 002 Wake up early YES_NO Did you wake up before 6am? 2 2 3 3 #00897B false

@ -24,7 +24,7 @@ plugins {
kotlin {
jvm().withJava()
jvmToolchain(17)
jvmToolchain(11)
sourceSets {
val commonMain by getting {

@ -18,7 +18,6 @@
*/
package org.isoron.uhabits.core.io
import com.opencsv.CSVWriter
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.EntryList
import org.isoron.uhabits.core.models.Habit
@ -33,6 +32,7 @@ import java.io.FileOutputStream
import java.io.FileWriter
import java.io.IOException
import java.io.Writer
import java.util.ArrayList
import java.util.LinkedList
import java.util.Locale
import java.util.zip.ZipEntry
@ -109,14 +109,11 @@ class HabitsCSVExporter(
var oldest = today
val known = habit.computedEntries.getKnown()
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)) {
val timestamp = dateFormat.format(timestamp1.unixTime)
val score = String.format(Locale.US, "%.4f", value)
csv.writeNext(arrayOf(timestamp, score), false)
out.write(String.format("%s,%s\n", timestamp, score))
}
csv.close()
out.close()
}
@ -125,20 +122,10 @@ class HabitsCSVExporter(
val out = FileWriter(exportDirName + filename)
generatedFilenames.add(filename)
val dateFormat = DateFormats.getCSVDateFormat()
val csv = CSVWriter(out)
csv.writeNext(arrayOf("Date", "Value", "Notes"), false)
for (entry in entries.getKnown()) {
val date = dateFormat.format(entry.timestamp.toJavaDate())
csv.writeNext(
arrayOf(
date,
entry.formattedValue,
entry.notes
),
false
)
for ((timestamp, value) in entries.getKnown()) {
val date = dateFormat.format(timestamp.toJavaDate())
out.write(String.format(Locale.US, "%s,%d\n", date, value))
}
csv.close()
out.close()
}
@ -180,7 +167,7 @@ class HabitsCSVExporter(
checksWriter.write(sb.toString())
scoresWriter.write(sb.toString())
for (j in selectedHabits.indices) {
checksWriter.write(checkmarks[j][i].formattedValue)
checksWriter.write(checkmarks[j][i].value.toString())
checksWriter.write(delimiter)
val score = String.format(Locale.US, "%.4f", scores[j][i].value)
scoresWriter.write(score)

@ -23,16 +23,6 @@ data class Entry(
val value: Int,
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 {
/**
* Value indicating that the habit is not applicable for this timestamp.

@ -22,7 +22,6 @@ import com.opencsv.CSVWriter
import java.io.IOException
import java.io.Writer
import java.util.LinkedList
import java.util.Locale
import javax.annotation.concurrent.ThreadSafe
/**
@ -183,34 +182,24 @@ abstract class HabitList : Iterable<Habit> {
val header = arrayOf(
"Position",
"Name",
"Type",
"Question",
"Description",
"FrequencyNumerator",
"FrequencyDenominator",
"Color",
"Unit",
"Target Type",
"Target Value",
"Archived?"
"NumRepetitions",
"Interval",
"Color"
)
val csv = CSVWriter(out)
csv.writeNext(header, false)
for (habit in this) {
val (numerator, denominator) = habit.frequency
val cols = arrayOf(
String.format(Locale.US, "%03d", indexOf(habit) + 1),
String.format("%03d", indexOf(habit) + 1),
habit.name,
habit.type.name,
habit.question,
habit.description,
numerator.toString(),
denominator.toString(),
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()
habit.color.toCsvColor()
)
csv.writeNext(cols, false)
}

@ -35,10 +35,6 @@ class HabitFixtures(private val modelFactory: ModelFactory, private val habitLis
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(
name: String = "Meditate",
color: PaletteColor = PaletteColor(3),
@ -145,10 +141,10 @@ class HabitFixtures(private val modelFactory: ModelFactory, private val habitLis
habit.frequency = Frequency(2, 3)
saveIfSQLite(habit)
var timestamp = getToday()
for (i in NON_DAILY_HABIT_CHECKS.indices) {
for (c in NON_DAILY_HABIT_CHECKS) {
var value = Entry.NO
if (NON_DAILY_HABIT_CHECKS[i]) value = Entry.YES_MANUAL
habit.originalEntries.add(Entry(timestamp, value, NON_DAILY_HABIT_NOTES[i]))
if (c) value = Entry.YES_MANUAL
habit.originalEntries.add(Entry(timestamp, value))
timestamp = timestamp.minus(1)
}
habit.recompute()

@ -18,6 +18,7 @@
*/
package org.isoron.uhabits.core.io
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.models.Habit
@ -29,7 +30,6 @@ import java.io.IOException
import java.nio.file.Files
import java.util.*
import java.util.zip.ZipFile
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class HabitsCSVExporterTest : BaseUnitTest() {
@ -108,12 +108,15 @@ class HabitsCSVExporterTest : BaseUnitTest() {
private fun assertFileAndReferenceAreEqual(s: String) {
val assetFilename = String.format("csv_export/%s", s)
val actualFile = File(String.format("%s/%s", baseDir.absolutePath, s))
val expectedFile = File.createTempFile("asset", "")
expectedFile.deleteOnExit()
copyAssetToFile(assetFilename, expectedFile)
val actualContents = actualFile.readText()
val expectedContents = expectedFile.readText()
assertEquals(expectedContents, actualContents, "content mismatch for $s")
val file = File.createTempFile("asset", "")
file.deleteOnExit()
copyAssetToFile(assetFilename, file)
assertTrue(
FileUtils.contentEquals(
file,
File(String.format("%s/%s", baseDir.absolutePath, s))
)
)
}
}

@ -202,16 +202,13 @@ class HabitListTest : BaseUnitTest() {
h2.description = ""
h2.frequency = Frequency(2, 3)
h2.color = PaletteColor(5)
val h3 = fixtures.createNumericalHabit()
list.add(h1)
list.add(h2)
list.add(h3)
val expectedCSV =
"""
Position,Name,Type,Question,Description,FrequencyNumerator,FrequencyDenominator,Color,Unit,Target Type,Target Value,Archived?
001,Meditate,YES_NO,Did you meditate this morning?,this is a test description,1,1,#FF8F00,,,,false
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
Position,Name,Question,Description,NumRepetitions,Interval,Color
001,Meditate,Did you meditate this morning?,this is a test description,1,1,#FF8F00
002,Wake up early,Did you wake up before 6am?,,2,3,#AFB42B
""".trimIndent()
val writer = StringWriter()

Loading…
Cancel
Save