Skip to content

Commit

Permalink
Merge pull request #3098 from nightscout/dev
Browse files Browse the repository at this point in the history
3.2.0.3
  • Loading branch information
MilosKozak committed Dec 16, 2023
2 parents c31617f + 8d50cb7 commit bb1a276
Show file tree
Hide file tree
Showing 102 changed files with 2,699 additions and 216 deletions.
22 changes: 15 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 2.1
# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
orbs:
android: circleci/android@2.3.0
codecov: codecov/codecov@3.2.4
codecov: codecov/codecov@3.3.0

jobs:
# Below is the definition of your job to build and test your app, you can rename and customize it as you want.
Expand All @@ -14,7 +14,7 @@ jobs:
executor:
name: android/android-machine
resource-class: large
tag: 2023.07.1
tag: 2023.11.1

steps:
- checkout
Expand All @@ -34,11 +34,19 @@ jobs:
- android/run-tests:
test-command: ./gradlew --stacktrace jacocoAllDebugReport

# And finally run the release build
# - run:
# name: Assemble release build
# command: |
# ./gradlew assembleRelease
- run:
name: Save test results
command: |
mkdir -p ~/test-results/junit/
find . -type f -regex ".*/build/outputs/androidTest-results/.*xml" -exec cp {} ~/test-results/junit/ \;
when: always

- store_test_results:
path: ~/test-results

- store_artifacts:
path: ~/test-results/junit

- codecov/upload:
file: './build/reports/jacoco/jacocoAllDebugReport/jacocoAllDebugReport.xml'

Expand Down
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ android {
//Deleting it causes a binding error
buildFeatures {
dataBinding = true
buildConfig = true
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/app/aaps/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
})
// Setup views on 2nd and next activity start
// On 1st start app is still initializing, start() is delayed and run from EventAppInitialized
if (config.appInitialized) start()
if (config.appInitialized) setupViews()
}

private fun start() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/app/aaps/di/PluginsListModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import app.aaps.plugins.source.PoctechPlugin
import app.aaps.plugins.source.RandomBgPlugin
import app.aaps.plugins.source.TomatoPlugin
import app.aaps.plugins.source.XdripSourcePlugin
import app.aaps.plugins.sync.dataBroadcaster.DataBroadcastPlugin
import app.aaps.plugins.sync.tizen.TizenPlugin
import app.aaps.plugins.sync.nsclient.NSClientPlugin
import app.aaps.plugins.sync.nsclientV3.NSClientV3Plugin
import app.aaps.plugins.sync.openhumans.OpenHumansUploaderPlugin
Expand Down Expand Up @@ -350,7 +350,7 @@ abstract class PluginsListModule {
@AllConfigs
@IntoMap
@IntKey(368)
abstract fun bindDataBroadcastPlugin(plugin: DataBroadcastPlugin): PluginBase
abstract fun bindDataBroadcastPlugin(plugin: TizenPlugin): PluginBase

@Binds
@AllConfigs
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.1.3")
classpath("com.android.tools.build:gradle:8.2.0")
classpath("com.google.gms:google-services:4.4.0")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.9")

Expand All @@ -22,7 +22,7 @@ buildscript {
}

plugins {
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
id("org.jlleitschuh.gradle.ktlint") version "12.0.3"
}

allprojects {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object KtsBuildVersions {

const val gradle = "8.1.3"
const val kotlin = "1.9.0"
const val gradle = "8.2.0"
const val kotlin = "1.9.10"
}

plugins {
Expand Down
21 changes: 5 additions & 16 deletions buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ object Libs {
}

object Mockito {
private const val mockitoVersion = "5.6.0"

const val jupiter = "org.mockito:mockito-junit-jupiter:5.6.0"
const val android = "org.mockito:mockito-android:$mockitoVersion"
const val core = "org.mockito:mockito-core:$mockitoVersion"
const val jupiter = "org.mockito:mockito-junit-jupiter:$mockitoVersion"
const val kotlin = "org.mockito.kotlin:mockito-kotlin:5.1.0"
}

Expand Down Expand Up @@ -197,19 +200,5 @@ object Libs {
const val commonCodecs = "commons-codec:commons-codec:1.16.0"
const val kulid = "com.github.guepardoapps:kulid:2.0.0.0"
const val xstream = "com.thoughtworks.xstream:xstream:1.4.20"

const val ormLite = "4.46"

const val junit = "4.13.2"
const val mockito = "5.6.0"
const val dexmaker = "1.2"
const val byteBuddy = "1.12.8"

const val androidx_junit = "1.1.5"
const val androidx_rules = "1.5.0"

const val kotlinx_datetime = "0.4.1"
const val kotlinx_serialization = "1.6.0"

const val caverock_androidsvg = "1.4"
const val connectiqSdk = "com.garmin.connectiq:ciq-companion-app-sdk:2.0.3@aar"
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.gradle.api.JavaVersion

object Versions {

const val appVersion = "3.2.0.2"
const val appVersion = "3.2.0.3"
const val versionCode = 1500

const val ndkVersion = "21.1.6352462"
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/test-module-dependencies.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dependencies {
androidTestImplementation(Libs.AndroidX.Test.rules)
androidTestImplementation(Libs.Google.truth)
androidTestImplementation(Libs.AndroidX.Test.uiAutomator)
androidTestImplementation(Libs.Mockito.core)
androidTestImplementation(Libs.Mockito.android)
androidTestImplementation(Libs.Mockito.kotlin)
}

tasks.withType<Test> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.aaps.core.interfaces.pump

import app.aaps.core.interfaces.db.GlucoseUnit
import app.aaps.core.interfaces.profile.Profile
import app.aaps.core.interfaces.pump.defs.PumpType
import app.aaps.core.interfaces.utils.DateUtil
Expand Down Expand Up @@ -257,6 +258,26 @@ interface PumpSync {
**/
fun insertTherapyEventIfNewWithTimestamp(timestamp: Long, type: DetailedBolusInfo.EventType, note: String? = null, pumpId: Long? = null, pumpType: PumpType, pumpSerial: String): Boolean

/**
* Synchronization of FINGER_STICK_BG_VALUE events
*
* Assuming there will be no clash on timestamp from different pumps
* only timestamp and type is compared
*
* If db record doesn't exist, new record is created.
* If exists, data is ignored
*
* @param timestamp timestamp of event from pump history
* @param glucose glucose value
* @param glucoseUnit glucose unit
* @param note note
* @param pumpId pump id from history if available
* @param pumpType pump type like PumpType.ACCU_CHEK_COMBO
* @param pumpSerial pump serial number
* @return true if new record is created
**/
fun insertFingerBgIfNewWithTimestamp(timestamp: Long, glucose: Double, glucoseUnit: GlucoseUnit, note: String? = null, pumpId: Long? = null, pumpType: PumpType, pumpSerial: String): Boolean

/**
* Create an announcement
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Intents {
const val EXTRA_BG_SLOPE = "com.eveningoutpost.dexdrip.Extras.BgSlope"
const val EXTRA_BG_SLOPE_NAME = "com.eveningoutpost.dexdrip.Extras.BgSlopeName"
const val EXTRA_SENSOR_BATTERY = "com.eveningoutpost.dexdrip.Extras.SensorBattery"
const val EXTRA_SENSOR_STARTED_AT = "com.eveningoutpost.dexdrip.Extras.SensorStartedAt"
const val EXTRA_TIMESTAMP = "com.eveningoutpost.dexdrip.Extras.Time"
const val EXTRA_RAW = "com.eveningoutpost.dexdrip.Extras.Raw"
const val XDRIP_DATA_SOURCE_DESCRIPTION = "com.eveningoutpost.dexdrip.Extras.SourceDesc"
Expand Down
54 changes: 44 additions & 10 deletions core/utils/src/main/kotlin/app/aaps/core/utils/MidnightUtils.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
package app.aaps.core.utils

import org.joda.time.DateTime
import java.time.Duration
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime

object MidnightUtils {
/*
/**
* Midnight time conversion
*/
object MidnightUtils {

/**
* Actual passed seconds from midnight ignoring DST change
* (thus always having 24 hours in a day, not 23 or 25 in days where DST changes)
*
* @return seconds
*/
fun secondsFromMidnight(): Int {
val passed = DateTime().millisOfDay.toLong()
return (passed / 1000).toInt()
val nowZoned = ZonedDateTime.now()
val localTime = nowZoned.toLocalTime()
val midnight = nowZoned.toLocalDate().atStartOfDay(nowZoned.zone).toLocalTime()
val duration = Duration.between(midnight, localTime)
return duration.seconds.toInt()
}

fun secondsFromMidnight(date: Long): Int {
val passed = DateTime(date).millisOfDay.toLong()
return (passed / 1000).toInt()
/**
* Passed seconds from midnight for specified time ignoring DST change
* (thus always having 24 hours in a day, not 23 or 25 in days where DST changes)
*
* @param timestamp time
* @return seconds
*/
fun secondsFromMidnight(timestamp: Long): Int {
val timeZoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault())
val localTime = timeZoned.toLocalTime()
val midnight = timeZoned.toLocalDate().atStartOfDay(timeZoned.zone).toLocalTime()
val duration: Duration = Duration.between(midnight, localTime)
return duration.seconds.toInt()
}

fun milliSecFromMidnight(date: Long): Long {
return DateTime(date).millisOfDay.toLong()
/**
* Passed milliseconds from midnight for specified time ignoring DST change
* (thus always having 24 hours in a day, not 23 or 25 in days where DST changes)
*
* @param timestamp time
* @return milliseconds
*/
fun milliSecFromMidnight(timestamp: Long): Long {
val timeZoned = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault())
val localTime = timeZoned.toLocalTime()
val midnight = timeZoned.toLocalDate().atStartOfDay(timeZoned.zone).toLocalTime()
val duration = Duration.between(midnight, localTime)
return duration.toMillis()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package app.aaps.core.utils

import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.util.TimeZone

class MidnightUtilsTest {

@BeforeEach fun setUp() {
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Amsterdam"))
}

@Test
fun secondsFromMidnight() {
val time = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(time)).isIn(0..24 * 3600)
}

@Test
fun testSecondsFromMidnight() {
val midnight = LocalDate.now().atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(midnight)).isEqualTo(0)
val oneHourAfter = LocalDateTime.ofInstant(Instant.ofEpochMilli(midnight), ZoneId.systemDefault()).atZone(ZoneId.systemDefault()).plusHours(1).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(oneHourAfter)).isEqualTo(3600)
}

@Test
fun milliSecFromMidnight() {
val midnight = LocalDate.now().atTime(LocalTime.MIDNIGHT).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(midnight)).isEqualTo(0)
val oneHourAfter = LocalDateTime.ofInstant(Instant.ofEpochMilli(midnight), ZoneId.systemDefault()).atZone(ZoneId.systemDefault()).plusHours(1).toInstant().toEpochMilli()
assertThat(MidnightUtils.milliSecFromMidnight(oneHourAfter)).isEqualTo(3600 * 1000)
}

@Test fun testDateTimeToDuration() {
val dateTime = ZonedDateTime.of(1991, 8, 13, 23, 5, 1, 0, ZoneId.of("Europe/Amsterdam")).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101)
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L)
}

@Test fun testDateTimeToDurationAtDstChange() {
val dateTime = ZonedDateTime.of(2020, 10, 25, 23, 5, 1, 0, ZoneId.of("Europe/Amsterdam")).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101)
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L)
}

@Test fun testDateTimeToDurationAtDstReverseChange() {
val dateTime = ZonedDateTime.of(2020, 3, 29, 23, 5, 1, 0, ZoneId.of("Europe/Amsterdam")).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101)
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L)
}

@Test fun testDateTimeInOtherZone() {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"))
assertThat(ZoneId.systemDefault().id).isEqualTo("America/Los_Angeles")
val dateTime = ZonedDateTime.of(2020, 3, 29, 23, 5, 1, 0, ZoneId.of("America/Los_Angeles")).toInstant().toEpochMilli()
assertThat(MidnightUtils.secondsFromMidnight(dateTime)).isEqualTo(83101)
assertThat(MidnightUtils.milliSecFromMidnight(dateTime)).isEqualTo(83101 * 1000L)
}
}
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
org.gradle.warning.mode=all
org.gradle.jvmargs=-Xmx3g -XX:+UseParallelGC
org.gradle.jvmargs=-Xmx4g -XX:+UseParallelGC

android.enableJetifier=false
android.useAndroidX=true
Expand All @@ -32,5 +32,4 @@ android.nonTransitiveRClass=true
# null: KtCallExpression
# https://youtrack.jetbrains.com/issue/KT-58027
kapt.use.jvm.ir=false
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=true

0 comments on commit bb1a276

Please sign in to comment.