...
 
Commits (59)
......@@ -3,7 +3,7 @@ version: 2.1
executors:
diab-android-executor:
docker:
- image: circleci/android:api-28-alpha
- image: circleci/android:api-29
environment:
JVM_OPTS: "-Xmx1024m"
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2"
......@@ -25,36 +25,17 @@ jobs:
- store_artifacts:
path: app/build/reports
destination: app-reports
- store_artifacts:
path: core/build/reports
destination: core-reports
- store_artifacts:
path: data/build/reports
destination: data-reports
- store_artifacts:
path: export/build/reports
destination: export-reports
- store_artifacts:
path: glucose/build/reports
destination: glucose-reports
- store_artifacts:
path: insulin/build/reports
destination: insulin-reports
- store_artifacts:
path: settings/build/reports
destination: settings-reports
- store_artifacts:
path: ui/build/reports
destination: ui-reports
# Store test results
- store_test_results:
path: app/build/test-results
- store_test_results:
path: core/build/test-results
path: libraries/core/build/test-results
- store_test_results:
path: libraries/data/build/test-results
- store_test_results:
path: data/build/test-results
path: features/glucose/build/test-results
- store_test_results:
path: glucose/build/test-results
path: features/overview/build/test-results
# Save build dir
- persist_to_workspace:
root: .
......
image: openjdk:8-jdk
variables:
ANDROID_COMPILE_SDK: "28"
ANDROID_BUILD_TOOLS: "28.0.3"
ANDROID_COMPILE_SDK: "29"
ANDROID_BUILD_TOOLS: "29.0.1"
# https://developer.android.com/studio/ -> Command line tools only
ANDROID_SDK_TOOLS: "4333796"
......
......@@ -9,18 +9,21 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
import it.diab.build.Config
import it.diab.build.Deps.Feature
import it.diab.build.Deps.Lib
android {
compileSdkVersion 28
compileSdkVersion Config.compileSdk
defaultConfig {
applicationId "it.diab"
minSdkVersion 23
targetSdkVersion 28
applicationId Config.packageName
minSdkVersion Config.minSdk
targetSdkVersion Config.targetSdk
versionCode appVersionCode
versionName "1.3"
versionName Config.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
......@@ -50,18 +53,15 @@ android {
}
dependencies {
implementation project(':core')
implementation project(':data')
implementation project(':ui')
implementation project(':glucose')
implementation project(':insulin')
implementation project(':settings')
googleFitImplementation project(':googlefit')
implementation project(Lib.core)
implementation project(Lib.ui)
// UI
implementation "androidx.cardview:cardview:1.0.0"
implementation project(Feature.overview)
implementation project(Feature.glucose)
implementation project(Feature.insulin)
implementation project(Feature.settings)
implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
googleFitImplementation project(Feature.googleFit)
}
// Testing dependencies
......
......@@ -27,12 +27,11 @@
# AndroidViewModel
-keep class * extends androidx.lifecycle.AndroidViewModel { <init>(...); }
# Coroutines
-keepclassmembernames class kotlinx.** { volatile <fields>; }
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keep class kotlinx.coroutines.android.AndroidExceptionPreHandler { *; }
-keep class kotlinx.coroutines.android.AndroidDispatcherFactory { *; }
# Ensure the custom, fast service loader implementation is removed.
-assumevalues class kotlinx.coroutines.internal.MainDispatcherLoader {
boolean FAST_SERVICE_LOADER_ENABLED return false;
}
# -checkdiscard class kotlinx.coroutines.internal.FastServiceLoader
# Keep fitness classes
-keep class it.diab.fit.** {}
......
......@@ -22,7 +22,7 @@
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.Main">
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
......
......@@ -9,7 +9,7 @@
package it.diab
import android.app.Application
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager
import it.diab.core.util.Activities.Settings.PREF_UI_STYLE
import it.diab.core.util.extensions.get
import it.diab.ui.util.UIUtils
......
......@@ -11,6 +11,7 @@ package it.diab
import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import it.diab.overview.fragments.OverviewFragment
import it.diab.util.ShortcutUtils
class MainActivity : AppCompatActivity() {
......@@ -18,7 +19,9 @@ class MainActivity : AppCompatActivity() {
public override fun onCreate(savedInstance: Bundle?) {
super.onCreate(savedInstance)
setContentView(R.layout.activity_main)
supportFragmentManager.beginTransaction()
.replace(android.R.id.content, OverviewFragment())
.commit()
createShortcuts()
}
......
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.adapters
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.AsyncDifferConfig
import androidx.recyclerview.widget.DiffUtil
import it.diab.R
import it.diab.core.util.PreferencesUtil
import it.diab.core.util.event.Event
import it.diab.data.entities.Glucose
import it.diab.data.entities.Insulin
import it.diab.holders.GlucoseHolder
import it.diab.holders.GlucoseHolderCallbacks
import it.diab.holders.HeaderHolder
import it.diab.holders.MainHolder
import it.diab.ui.ShiftedAdapter
import it.diab.ui.models.DataSetsModel
import it.diab.ui.models.LastGlucoseModel
import it.diab.util.UIUtils
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class MainAdapter(
private val context: Context,
private val callbacks: Callbacks
) : ShiftedAdapter<Glucose, MainHolder>(CONFIG, 1), GlucoseHolderCallbacks {
private val _openGlucose = MutableLiveData<Event<Long>>()
val openGlucose: LiveData<Event<Long>> = _openGlucose
// Store the these for better performance
private val lowIndicator by lazy { buildIndicator(R.color.glucoseIndicator_low) }
private val highIndicator by lazy { buildIndicator(R.color.glucoseIndicator_high) }
private val highThreshold by lazy { PreferencesUtil.getGlucoseHighThreshold(context) }
private val lowThreshold by lazy { PreferencesUtil.getGlucoseLowThreshold(context) }
private val hourFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
if (viewType == VIEW_HEADER) {
HeaderHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_header, parent, false)
)
} else {
GlucoseHolder(
LayoutInflater.from(parent.context).inflate(R.layout.item_glucose, parent, false),
this
)
}
override fun onBindViewHolder(holder: MainHolder, position: Int) {
if (holder is HeaderHolder) {
bindHeader(holder)
} else if (holder is GlucoseHolder) {
bindGlucose(holder, position)
}
}
private fun bindHeader(holder: HeaderHolder) {
holder.bind(
callbacks.getLastGlucose(),
callbacks.getDataSets()
)
}
private fun bindGlucose(holder: GlucoseHolder, position: Int) {
val item = getItem(position)
if (item == null) {
holder.onLoading()
} else {
holder.onBind(item)
}
}
override fun fetchHourText(date: Date, onFetch: (String) -> Unit) {
onFetch(hourFormat.format(date))
}
override fun getIndicator(value: Int) = when {
value < lowThreshold -> lowIndicator
value > highThreshold -> highIndicator
else -> null
}
override fun getInsulinName(uid: Long) = callbacks.getInsulin(uid).name
override fun onClick(uid: Long) {
_openGlucose.value = Event(uid)
}
override fun getItemViewType(position: Int) = if (position == 0) VIEW_HEADER else VIEW_GLUCOSE
private fun buildIndicator(@ColorRes colorId: Int): Drawable? {
val resources = context.resources
val color = ContextCompat.getColor(context, colorId)
val size = resources.getDimensionPixelSize(R.dimen.item_glucose_indicator)
return UIUtils.createRoundDrawable(resources, size, color)
}
interface Callbacks {
fun getInsulin(uid: Long): Insulin
fun getLastGlucose(): LastGlucoseModel
fun getDataSets(): DataSetsModel
}
companion object {
private val CONFIG = AsyncDifferConfig.Builder(object : DiffUtil.ItemCallback<Glucose>() {
override fun areContentsTheSame(oldItem: Glucose, newItem: Glucose) =
oldItem == newItem
override fun areItemsTheSame(oldItem: Glucose, newItem: Glucose) =
oldItem.uid == newItem.uid
}).build()
private const val VIEW_HEADER = 0
private const val VIEW_GLUCOSE = 1
}
}
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.fragments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.app.ActivityOptionsCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.paging.PagedList
import com.google.android.material.floatingactionbutton.FloatingActionButton
import it.diab.R
import it.diab.adapters.MainAdapter
import it.diab.core.util.Activities
import it.diab.core.util.event.EventObserver
import it.diab.core.util.intentTo
import it.diab.data.entities.Glucose
import it.diab.data.repositories.GlucoseRepository
import it.diab.data.repositories.InsulinRepository
import it.diab.ui.TimeHeaderDecoration
import it.diab.ui.models.DataSetsModel
import it.diab.ui.models.LastGlucoseModel
import it.diab.ui.widgets.RecyclerViewExt
import it.diab.util.extensions.doOnNextLayout
import it.diab.util.extensions.removeAllItemDecorators
import it.diab.viewmodels.MainViewModel
import it.diab.viewmodels.MainViewModelFactory
class MainFragment : Fragment(), MainAdapter.Callbacks {
private lateinit var viewModel: MainViewModel
private lateinit var listAdapter: MainAdapter
private lateinit var fab: FloatingActionButton
private lateinit var glucoseList: RecyclerViewExt
private var last: LastGlucoseModel = LastGlucoseModel.Loading
private var dataSetsModel: DataSetsModel = DataSetsModel.Loading
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val context = context ?: return
val factory = MainViewModelFactory(
GlucoseRepository.getInstance(context),
InsulinRepository.getInstance(context)
)
viewModel = ViewModelProviders.of(this, factory)[MainViewModel::class.java]
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = inflater.inflate(R.layout.fragment_main, container, false)
fab = view.findViewById(R.id.fab)
glucoseList = view.findViewById(R.id.main_list)
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val context = context ?: return
listAdapter = MainAdapter(context, this)
fab.setOnClickListener { onFabClick() }
viewModel.prepare {
val activity = activity ?: return@prepare
viewModel.pagedList.observe(activity, Observer(this::onPagedListChanged))
viewModel.liveList.observe(activity, Observer(this::onLiveListChanged))
listAdapter.openGlucose.observe(activity, EventObserver(this::onItemClick))
}
}
override fun getInsulin(uid: Long) = viewModel.getInsulin(uid)
private fun onItemClick(uid: Long) {
val activity = activity ?: return
val intent = intentTo(Activities.Glucose.Editor).apply {
putExtra(Activities.Glucose.Editor.EXTRA_UID, uid)
}
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(
activity,
fab,
fab.transitionName
)
startActivity(intent, options.toBundle())
}
private fun onFabClick() {
onItemClick(-1)
}
private fun onPagedListChanged(data: PagedList<Glucose>?) {
listAdapter.submitList(data)
if (glucoseList.adapter == null) {
glucoseList.adapter = listAdapter
}
}
private fun onLiveListChanged(data: List<Glucose>?) {
if (data == null) {
return
}
if (data.isEmpty()) {
last = LastGlucoseModel.Empty
dataSetsModel = DataSetsModel.Empty
} else {
last = LastGlucoseModel.Available(data[0])
}
updateHeaders(data)
viewModel.getDataSets(this::onGraphDataSetChanged)
}
override fun getLastGlucose() = last
override fun getDataSets() = dataSetsModel
private fun onGraphDataSetChanged(model: DataSetsModel) {
dataSetsModel = model
listAdapter.notifyItemChanged(0)
}
private fun updateHeaders(list: List<Glucose>) {
glucoseList.doOnNextLayout {
glucoseList.removeAllItemDecorators()
glucoseList.addItemDecoration(TimeHeaderDecoration(requireContext(), list, 1))
}
}
}
\ No newline at end of file
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.holders
import android.view.View
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatTextView
import it.diab.R
import it.diab.data.entities.Glucose
import it.diab.ui.util.extensions.setPreText
class GlucoseHolder(
view: View,
private val callbacks: GlucoseHolderCallbacks
) : MainHolder(view) {
private val titleView = view.findViewById<AppCompatTextView>(R.id.item_glucose_value)
private val summaryView = view.findViewById<AppCompatTextView>(R.id.item_glucose_insulin)
private val indicatorView = view.findViewById<ImageView>(R.id.item_glucose_status)
fun onBind(glucose: Glucose) {
itemView.visibility = View.VISIBLE
bindValue(glucose)
bindInsulin(glucose)
itemView.setOnClickListener { callbacks.onClick(glucose.uid) }
}
fun onLoading() {
itemView.visibility = View.INVISIBLE
}
private fun bindValue(glucose: Glucose) {
val title = "${glucose.value} (%1\$s)"
callbacks.fetchHourText(glucose.date) { text ->
titleView.setPreText(title.format(text))
}
val indicatorDrawable = callbacks.getIndicator(glucose.value)
if (indicatorDrawable == null) {
indicatorView.visibility = View.GONE
} else {
indicatorView.visibility = View.VISIBLE
indicatorView.setImageDrawable(indicatorDrawable)
}
}
private fun bindInsulin(glucose: Glucose) {
val builder = StringBuilder()
val insulinId = glucose.insulinId0
val basalId = glucose.insulinId1
builder.apply {
if (insulinId >= 0) {
append(glucose.insulinValue0)
append(" ")
append(callbacks.getInsulinName(insulinId))
}
if (basalId >= 0) {
if (insulinId >= 0) {
append(", ")
}
append(glucose.insulinValue1)
append(" ")
append(callbacks.getInsulinName(basalId))
}
}
if (builder.isEmpty()) {
summaryView.visibility = View.GONE
} else {
summaryView.visibility = View.VISIBLE
summaryView.setPreText(builder.toString())
}
}
}
\ No newline at end of file
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.holders
import android.graphics.drawable.Drawable
import java.util.Date
interface GlucoseHolderCallbacks {
/**
* Fetch a String that represents hours of a given [Date]
*
* @param date date to be put in the string
* @param onFetch callback for fetch completion
*/
fun fetchHourText(
date: Date,
onFetch: (String) -> Unit
)
/**
* Get the indicator drawable for
* a given glucose value
*/
fun getIndicator(value: Int): Drawable?
/**
* Get the name of an insulin
*
* @param uid uid of the insulin
*/
fun getInsulinName(uid: Long): String
/**
* OnClick event callback
*/
fun onClick(uid: Long)
}
......@@ -16,10 +16,10 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Icon
import android.preference.PreferenceManager
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import it.diab.R
import it.diab.core.util.Activities
import it.diab.core.util.extensions.get
......@@ -84,9 +84,7 @@ object ShortcutUtils {
return drawable.bitmap
}
if (drawable == null) {
throw IllegalArgumentException("Could not get a valid drawable from argument")
}
requireNotNull(drawable) { "Could not get a valid drawable from argument" }
val bm = Bitmap.createBitmap(
drawable.intrinsicWidth, drawable.intrinsicHeight,
......
/*
* Copyright (c) 2018 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.util.extensions
import it.diab.core.util.extensions.getCalendar
import java.util.Calendar
import java.util.Date
operator fun Date.get(diff: Int): Date {
val calendar = getCalendar()
calendar.add(Calendar.DAY_OF_YEAR, diff)
return calendar.time
}
fun Date.isToday(): Boolean {
val calendar = getCalendar()
val today = Calendar.getInstance()
return calendar[Calendar.YEAR] == today[Calendar.YEAR] &&
calendar[Calendar.DAY_OF_YEAR] == today[Calendar.DAY_OF_YEAR]
}
fun Date.getAsMinutes(): Float {
return getCalendar().run {
get(Calendar.HOUR_OF_DAY) * 60f + get(Calendar.MINUTE)
}
}
fun Date.diff(other: Date): Int {
val a = getCalendar()
val b = other.getCalendar()
return (a[Calendar.YEAR] - b[Calendar.YEAR]) * 365 +
a[Calendar.DAY_OF_YEAR] - b[Calendar.DAY_OF_YEAR]
}
/*
* Copyright (c) 2018 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.util.extensions
fun Float.isZeroOrNan() = 0f == this || isNaN()
\ No newline at end of file
......@@ -7,8 +7,6 @@
The text of the license can be found in the LICENSE file
or at https://www.gnu.org/licenses/gpl.txt
-->
<!--suppress AndroidElementNotAllowed -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
......@@ -21,14 +19,6 @@
</shape>
</item>
<item>
<vector
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M9,11.24L9,7.5C9,6.12 10.12,5 11.5,5S14,6.12 14,7.5v3.74c1.21,-0.81 2,-2.18 2,-3.74C16,5.01 13.99,3 11.5,3S7,5.01 7,7.5c0,1.56 0.79,2.93 2,3.74zM18.84,15.87l-4.54,-2.26c-0.17,-0.07 -0.35,-0.11 -0.54,-0.11L13,13.5v-6c0,-0.83 -0.67,-1.5 -1.5,-1.5S10,6.67 10,7.5v10.74l-3.43,-0.72c-0.08,-0.01 -0.15,-0.03 -0.24,-0.03 -0.31,0 -0.59,0.13 -0.79,0.33l-0.79,0.8 4.94,4.94c0.27,0.27 0.65,0.44 1.06,0.44h6.79c0.75,0 1.33,-0.55 1.44,-1.28l0.75,-5.27c0.01,-0.07 0.02,-0.14 0.02,-0.2 0,-0.62 -0.38,-1.16 -0.91,-1.38z" />
</vector>
<inset android:drawable="@drawable/ic_add_glucose" />
</item>
</layer-list>
<!--
Copyright (c) 2018 Bevilacqua Joey
Licensed under the GNU GPLv3 license
The text of the license can be found in the LICENSE file
or at https://www.gnu.org/licenses/gpl.txt
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="it.diab.fragments.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:tag="it.diab.fragments.MainFragment" />
......@@ -9,12 +9,4 @@
<resources>
<string name="app_name">Diab</string>
<string name="app_shortcut_add_glucose">ग्लूकोज जोड़ें</string>
<!-- Overview -->
<string name="overview_last_desc">अंतिम मान %1$s</string>
<string name="overview_last_fallback">नमस्ते</string>
<string name="overview_last_desc_fallback">नीले बटन को दबाकर एक मान जोड़ें</string>
<string name="overview_graph_loading">Loading\u2026</string>
<string name="overview_graph_empty">No recent glucose found</string>
</resources>
......@@ -9,12 +9,4 @@
<resources>
<string name="app_name">Diab</string>
<string name="app_shortcut_add_glucose">Aggiungi glicemia</string>
<!-- Overview -->
<string name="overview_last_desc">Ultimo valore%1$s</string>
<string name="overview_last_fallback">Ciao</string>
<string name="overview_last_desc_fallback">Aggiungi un valore toccando il pulsante blu</string>
<string name="overview_graph_loading">Caricamento\u2026</string>
<string name="overview_graph_empty">Non sono state registrate glicemie recentemente</string>
</resources>
......@@ -9,10 +9,4 @@
-->
<resources>
<color name="ic_launcher_background">#243FE0</color>
<color name="overviewGraph_today">@color/colorAccentDark</color>
<color name="overviewGraph_average">@color/colorAccentLight</color>
<color name="glucoseIndicator_high">#ffcd80</color>
<color name="glucoseIndicator_low">#ff90b5</color>
</resources>
......@@ -9,12 +9,4 @@
<resources>
<string name="app_name">Diab</string>
<string name="app_shortcut_add_glucose">Add glucose</string>
<!-- Overview -->
<string name="overview_last_desc">Last value%1$s</string>
<string name="overview_last_fallback">Hello</string>
<string name="overview_last_desc_fallback">Add a value by touching the blue button</string>
<string name="overview_graph_loading">Loading\u2026</string>
<string name="overview_graph_empty">No recent glucose found</string>
</resources>
<!--
Copyright (c) 2018 Bevilacqua Joey
Licensed under the GNU GPLv3 license
The text of the license can be found in the LICENSE file
or at https://www.gnu.org/licenses/gpl.txt
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Main -->
<style name="AppTheme.Main" parent="AppTheme.NoActionBar">
<item name="android:navigationBarDividerColor" tools:targetApi="27">@color/navigationBar_color</item>
</style>
<style name="AppTheme.TimeHeaders">
<item name="android:width">@dimen/header_keyline</item>
<item name="android:paddingTop">@dimen/date_header_padding_top</item>
<item name="android:textColor">?attr/colorAccent</item>
<item name="dayTextSize">@dimen/time_header_day_text_size</item>
<item name="monthTextSize">@dimen/time_header_month_text_size</item>
</style>
</resources>
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.util.extensions
import it.diab.core.util.DateUtils
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.Calendar
import java.util.Date
class DateExtTest {
@Test
fun get() {
val now = System.currentTimeMillis()
val diff = 2
assertEquals(now + (DateUtils.DAY * diff), Date(now)[diff].time)
}
@Test
fun isToday() {
val a = Date()
val b = Calendar.getInstance().apply {
this[Calendar.YEAR] -= 1
}.time
val c = Calendar.getInstance().apply {
this[Calendar.DAY_OF_YEAR] += 3
}.time
assertTrue(a.isToday())
assertFalse(b.isToday())
assertFalse(c.isToday())
}
@Test
fun getAsMinutes() {
val calendar = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 10)
set(Calendar.MINUTE, 30)
}
assertEquals(10 * 60f + 30, calendar.time.getAsMinutes())
}
@Test
fun diff() {
val a = Calendar.getInstance().apply {
set(Calendar.YEAR, 2000)
set(Calendar.DAY_OF_YEAR, 1)
}
val b = Calendar.getInstance().apply {
set(Calendar.YEAR, 2000)
set(Calendar.DAY_OF_YEAR, 3)
}
assertEquals(-2, a.time.diff(b.time))
b[Calendar.YEAR] -= 1
b[Calendar.DAY_OF_YEAR] -= 8
assertEquals(371, a.time.diff(b.time))
}
}
\ No newline at end of file
......@@ -16,8 +16,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31"
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
......
/build
\ No newline at end of file
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
// Leave me empty
\ No newline at end of file
......@@ -6,13 +6,14 @@
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.ui.models
package it.diab.build
import it.diab.data.entities.Glucose
class Config {
public static final String packageName = "it.diab"
sealed class LastGlucoseModel {
public static final int compileSdk = 29
public static final int minSdk = 23
public static final int targetSdk = 29
object Empty : LastGlucoseModel()
object Loading : LastGlucoseModel()
data class Available(val glucose: Glucose) : LastGlucoseModel()
public static final String versionName = "1.3"
}
\ No newline at end of file
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.build
class Deps {
class AndroidX {
public static final String appCompat = "androidx.appcompat:appcompat:1.1.0"
public static final String constraintLayout = "androidx.constraintlayout:constraintlayout:2.0.0-beta1"
public static final String paging = "androidx.paging:paging-runtime:2.1.0"
public static final String preference = "androidx.preference:preference:1.1.0"
public static final String workManager = "androidx.work:work-runtime-ktx:2.2.0"
class Lifecycle {
private static final String VERSION = "2.1.0"
public static final String compiler = "androidx.lifecycle:lifecycle-compiler:$VERSION"
public static final String extensions = "androidx.lifecycle:lifecycle-extensions:$VERSION"
public static final String viewModel = "androidx.lifecycle:lifecycle-viewmodel-ktx:$VERSION"
}
class Room {
private static final String VERSION = "2.2.0-rc01"
public static final String compiler = "androidx.room:room-compiler:$VERSION"
public static final String ktx = "androidx.room:room-ktx:$VERSION"
public static final String runtime = "androidx.room:room-runtime:$VERSION"
}