Make uhabits-core a Kotlin multiplatform module
@@ -1 +1 @@
|
|||||||
include ':uhabits-android', ':uhabits-core', ':android-pickers'
|
include ':uhabits-android', ':uhabits-core-legacy', ':android-pickers', ':uhabits-core'
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ plugins {
|
|||||||
id 'com.android.application'
|
id 'com.android.application'
|
||||||
id 'kotlin-android'
|
id 'kotlin-android'
|
||||||
id 'kotlin-kapt'
|
id 'kotlin-kapt'
|
||||||
id 'com.github.triplet.play' version '2.6.2'
|
//id 'com.github.triplet.play' version '2.6.2'
|
||||||
id 'kotlin-android-extensions'
|
id 'kotlin-android-extensions'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ dependencies {
|
|||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
|
||||||
androidTestImplementation 'androidx.test:rules:1.3.0'
|
androidTestImplementation 'androidx.test:rules:1.3.0'
|
||||||
androidTestImplementation project(":uhabits-core")
|
androidTestImplementation project(':uhabits-core-legacy')
|
||||||
annotationProcessor "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
annotationProcessor "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
||||||
compileOnly "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
compileOnly "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
||||||
compileOnly "javax.annotation:jsr250-api:1.0"
|
compileOnly "javax.annotation:jsr250-api:1.0"
|
||||||
@@ -114,7 +114,7 @@ dependencies {
|
|||||||
implementation 'com.google.android.material:material:1.2.1'
|
implementation 'com.google.android.material:material:1.2.1'
|
||||||
implementation 'com.google.zxing:core:3.4.1'
|
implementation 'com.google.zxing:core:3.4.1'
|
||||||
implementation 'com.opencsv:opencsv:3.10'
|
implementation 'com.opencsv:opencsv:3.10'
|
||||||
implementation project(":uhabits-core")
|
implementation project(':uhabits-core-legacy')
|
||||||
implementation project(":android-pickers")
|
implementation project(":android-pickers")
|
||||||
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
kapt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
||||||
kaptAndroidTest "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
kaptAndroidTest "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
|
||||||
@@ -128,7 +128,7 @@ kapt {
|
|||||||
correctErrorTypes = true
|
correctErrorTypes = true
|
||||||
}
|
}
|
||||||
|
|
||||||
play {
|
//play {
|
||||||
serviceAccountCredentials = file("../../.secret/gcp-key.json")
|
// serviceAccountCredentials = file("../../.secret/gcp-key.json")
|
||||||
track = "alpha"
|
// track = "alpha"
|
||||||
}
|
//}
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 9.7 KiB |
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.7 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 350 B After Width: | Height: | Size: 350 B |
|
Before Width: | Height: | Size: 345 B After Width: | Height: | Size: 345 B |
|
Before Width: | Height: | Size: 424 B After Width: | Height: | Size: 424 B |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
32
android/uhabits-core-legacy/build.gradle
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'java'
|
||||||
|
apply plugin: 'kotlin'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
annotationProcessor "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
||||||
|
annotationProcessor "com.google.dagger:dagger:$DAGGER_VERSION"
|
||||||
|
compileOnly "com.google.auto.factory:auto-factory:$AUTO_FACTORY_VERSION"
|
||||||
|
compileOnly "com.google.dagger:dagger:$DAGGER_VERSION"
|
||||||
|
compileOnly 'javax.annotation:jsr250-api:1.0'
|
||||||
|
compileOnly 'org.jetbrains:annotations:18.0.0'
|
||||||
|
implementation "com.google.guava:guava:30.0-jre"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
|
||||||
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:$KX_COROUTINES_VERSION"
|
||||||
|
implementation 'androidx.annotation:annotation:1.1.0'
|
||||||
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
|
implementation 'commons-codec:commons-codec:1.15'
|
||||||
|
implementation 'org.apache.commons:commons-lang3:3.5'
|
||||||
|
implementation 'com.opencsv:opencsv:3.10'
|
||||||
|
implementation project(':uhabits-core')
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test:$KOTLIN_VERSION"
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
testImplementation 'nl.jqno.equalsverifier:equalsverifier:2.4.8'
|
||||||
|
testImplementation 'org.apache.commons:commons-io:1.3.2'
|
||||||
|
testImplementation 'org.hamcrest:hamcrest-library:1.4-atlassian-1'
|
||||||
|
testImplementation 'org.mockito:mockito-core:2.28.2'
|
||||||
|
testImplementation 'org.xerial:sqlite-jdbc:3.18.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceCompatibility = "1.8"
|
||||||
|
targetCompatibility = "1.8"
|
||||||
@@ -19,31 +19,29 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.core.models;
|
package org.isoron.uhabits.core.models;
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.*;
|
|
||||||
import org.isoron.platform.time.LocalDate;
|
import org.isoron.platform.time.LocalDate;
|
||||||
|
import org.apache.commons.lang3.builder.*;
|
||||||
import org.isoron.uhabits.core.utils.*;
|
import org.isoron.uhabits.core.utils.*;
|
||||||
import org.jetbrains.annotations.*;
|
|
||||||
|
|
||||||
import java.time.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import kotlin.*;
|
|
||||||
|
|
||||||
import static java.util.Calendar.*;
|
import static java.util.Calendar.*;
|
||||||
|
|
||||||
public final class Timestamp implements Comparable<Timestamp>
|
public final class Timestamp implements Comparable<Timestamp> {
|
||||||
{
|
|
||||||
public static final long DAY_LENGTH = 86400000;
|
public static final long DAY_LENGTH = 86400000;
|
||||||
|
|
||||||
public static final Timestamp ZERO = new Timestamp(0);
|
public static final Timestamp ZERO = new Timestamp(0);
|
||||||
|
|
||||||
private final long unixTime;
|
private final long unixTime;
|
||||||
|
|
||||||
public Timestamp(long unixTime)
|
public static Timestamp fromLocalDate(LocalDate date) {
|
||||||
{
|
return new Timestamp(946684800000L + date.getDaysSince2000() * 86400000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp(long unixTime) {
|
||||||
if (unixTime < 0)
|
if (unixTime < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Invalid unix time: " + unixTime);
|
"Invalid unix time: " + unixTime);
|
||||||
|
|
||||||
if (unixTime % DAY_LENGTH != 0)
|
if (unixTime % DAY_LENGTH != 0)
|
||||||
unixTime = (unixTime / DAY_LENGTH) * DAY_LENGTH;
|
unixTime = (unixTime / DAY_LENGTH) * DAY_LENGTH;
|
||||||
@@ -51,25 +49,21 @@ public final class Timestamp implements Comparable<Timestamp>
|
|||||||
this.unixTime = unixTime;
|
this.unixTime = unixTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp(GregorianCalendar cal)
|
public Timestamp(GregorianCalendar cal) {
|
||||||
{
|
|
||||||
this(cal.getTimeInMillis());
|
this(cal.getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Timestamp from(int year, int javaMonth, int day)
|
public static Timestamp from(int year, int javaMonth, int day) {
|
||||||
{
|
|
||||||
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
GregorianCalendar cal = DateUtils.getStartOfTodayCalendar();
|
||||||
cal.set(year, javaMonth, day, 0, 0, 0);
|
cal.set(year, javaMonth, day, 0, 0, 0);
|
||||||
return new Timestamp(cal.getTimeInMillis());
|
return new Timestamp(cal.getTimeInMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getUnixTime()
|
public long getUnixTime() {
|
||||||
{
|
|
||||||
return unixTime;
|
return unixTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate toLocalDate()
|
public LocalDate toLocalDate() {
|
||||||
{
|
|
||||||
long millisSince2000 = unixTime - 946684800000L;
|
long millisSince2000 = unixTime - 946684800000L;
|
||||||
int daysSince2000 = (int) (millisSince2000 / 86400000);
|
int daysSince2000 = (int) (millisSince2000 / 86400000);
|
||||||
return new LocalDate(daysSince2000);
|
return new LocalDate(daysSince2000);
|
||||||
@@ -80,14 +74,12 @@ public final class Timestamp implements Comparable<Timestamp>
|
|||||||
* timestamp is newer, or zero if they are equal.
|
* timestamp is newer, or zero if they are equal.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Timestamp other)
|
public int compareTo(Timestamp other) {
|
||||||
{
|
|
||||||
return Long.signum(this.unixTime - other.unixTime);
|
return Long.signum(this.unixTime - other.unixTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o) {
|
||||||
{
|
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
@@ -95,31 +87,27 @@ public final class Timestamp implements Comparable<Timestamp>
|
|||||||
Timestamp timestamp = (Timestamp) o;
|
Timestamp timestamp = (Timestamp) o;
|
||||||
|
|
||||||
return new EqualsBuilder()
|
return new EqualsBuilder()
|
||||||
.append(unixTime, timestamp.unixTime)
|
.append(unixTime, timestamp.unixTime)
|
||||||
.isEquals();
|
.isEquals();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
|
||||||
return new HashCodeBuilder(17, 37).append(unixTime).toHashCode();
|
return new HashCodeBuilder(17, 37).append(unixTime).toHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given two timestamps, returns whichever timestamp is the oldest one.
|
* Given two timestamps, returns whichever timestamp is the oldest one.
|
||||||
*/
|
*/
|
||||||
public static Timestamp oldest(Timestamp first, Timestamp second)
|
public static Timestamp oldest(Timestamp first, Timestamp second) {
|
||||||
{
|
|
||||||
return first.unixTime < second.unixTime ? first : second;
|
return first.unixTime < second.unixTime ? first : second;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp minus(int days)
|
public Timestamp minus(int days) {
|
||||||
{
|
|
||||||
return plus(-days);
|
return plus(-days);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp plus(int days)
|
public Timestamp plus(int days) {
|
||||||
{
|
|
||||||
return new Timestamp(unixTime + DAY_LENGTH * days);
|
return new Timestamp(unixTime + DAY_LENGTH * days);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,38 +116,32 @@ public final class Timestamp implements Comparable<Timestamp>
|
|||||||
* the other timestamp equals this one, returns zero. If the other timestamp
|
* the other timestamp equals this one, returns zero. If the other timestamp
|
||||||
* is older than this one, returns a negative number.
|
* is older than this one, returns a negative number.
|
||||||
*/
|
*/
|
||||||
public int daysUntil(Timestamp other)
|
public int daysUntil(Timestamp other) {
|
||||||
{
|
|
||||||
return (int) ((other.unixTime - this.unixTime) / DAY_LENGTH);
|
return (int) ((other.unixTime - this.unixTime) / DAY_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewerThan(Timestamp other)
|
public boolean isNewerThan(Timestamp other) {
|
||||||
{
|
|
||||||
return compareTo(other) > 0;
|
return compareTo(other) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOlderThan(Timestamp other)
|
public boolean isOlderThan(Timestamp other) {
|
||||||
{
|
|
||||||
return compareTo(other) < 0;
|
return compareTo(other) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date toJavaDate()
|
public Date toJavaDate() {
|
||||||
{
|
|
||||||
return new Date(unixTime);
|
return new Date(unixTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GregorianCalendar toCalendar()
|
public GregorianCalendar toCalendar() {
|
||||||
{
|
|
||||||
GregorianCalendar day =
|
GregorianCalendar day =
|
||||||
new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
||||||
day.setTimeInMillis(unixTime);
|
day.setTimeInMillis(unixTime);
|
||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString() {
|
||||||
{
|
|
||||||
return DateFormats.getCSVDateFormat().format(new Date(unixTime));
|
return DateFormats.getCSVDateFormat().format(new Date(unixTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,13 +149,11 @@ public final class Timestamp implements Comparable<Timestamp>
|
|||||||
* Returns an integer corresponding to the day of the week. Saturday maps
|
* Returns an integer corresponding to the day of the week. Saturday maps
|
||||||
* to 0, Sunday maps to 1, and so on.
|
* to 0, Sunday maps to 1, and so on.
|
||||||
*/
|
*/
|
||||||
public int getWeekday()
|
public int getWeekday() {
|
||||||
{
|
|
||||||
return toCalendar().get(DAY_OF_WEEK) % 7;
|
return toCalendar().get(DAY_OF_WEEK) % 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timestamp truncate(DateUtils.TruncateField field, int firstWeekday)
|
Timestamp truncate(DateUtils.TruncateField field, int firstWeekday) {
|
||||||
{
|
|
||||||
return new Timestamp(DateUtils.truncate(field, unixTime, firstWeekday));
|
return new Timestamp(DateUtils.truncate(field, unixTime, firstWeekday));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||