diff --git a/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt
index 22d7c89f11..25864eed1e 100644
--- a/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt
+++ b/app/src/main/java/info/nightscout/androidaps/activities/StatsActivity.kt
@@ -4,14 +4,15 @@ import android.os.Bundle
import info.nightscout.androidaps.R
import info.nightscout.androidaps.utils.ActivityMonitor
import info.nightscout.androidaps.utils.OKDialog
-import info.nightscout.androidaps.utils.TddCalculator
-import info.nightscout.androidaps.utils.TirCalculator
+import info.nightscout.androidaps.utils.stats.TddCalculator
+import info.nightscout.androidaps.utils.stats.TirCalculator
import info.nightscout.androidaps.utils.resources.ResourceHelper
import kotlinx.android.synthetic.main.stats_activity.*
import javax.inject.Inject
class StatsActivity : NoSplashAppCompatActivity() {
@Inject lateinit var tddCalculator: TddCalculator
+ @Inject lateinit var tirCalculator: TirCalculator
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var activityMonitor: ActivityMonitor
@@ -20,7 +21,7 @@ class StatsActivity : NoSplashAppCompatActivity() {
setContentView(R.layout.stats_activity)
stats_tdds.text = tddCalculator.stats()
- stats_tir.text = TirCalculator.stats()
+ stats_tir.text = tirCalculator.stats()
stats_activity.text = activityMonitor.stats()
ok.setOnClickListener { finish() }
diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt
index c08896c847..b840bf4f6b 100644
--- a/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt
+++ b/app/src/main/java/info/nightscout/androidaps/activities/SurveyActivity.kt
@@ -13,6 +13,8 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.resources.ResourceHelper
+import info.nightscout.androidaps.utils.stats.TddCalculator
+import info.nightscout.androidaps.utils.stats.TirCalculator
import kotlinx.android.synthetic.main.survey_activity.*
import javax.inject.Inject
@@ -21,6 +23,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
@Inject lateinit var tddCalculator: TddCalculator
+ @Inject lateinit var tirCalculator: TirCalculator
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var activityMonitor: ActivityMonitor
@@ -35,7 +38,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
survey_spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, profileList)
survey_tdds.text = tddCalculator.stats()
- survey_tir.text = TirCalculator.stats()
+ survey_tir.text = tirCalculator.stats()
survey_activity.text = activityMonitor.stats()
survey_profile.setOnClickListener {
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TIR.kt b/app/src/main/java/info/nightscout/androidaps/utils/stats/TIR.kt
similarity index 58%
rename from app/src/main/java/info/nightscout/androidaps/utils/TIR.kt
rename to app/src/main/java/info/nightscout/androidaps/utils/stats/TIR.kt
index 5f2ea9bbaf..f6db77e09f 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/TIR.kt
+++ b/app/src/main/java/info/nightscout/androidaps/utils/stats/TIR.kt
@@ -1,7 +1,8 @@
-package info.nightscout.androidaps.utils
+package info.nightscout.androidaps.utils.stats
-import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
+import info.nightscout.androidaps.utils.DateUtil
+import info.nightscout.androidaps.utils.resources.ResourceHelper
import kotlin.math.roundToInt
class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
@@ -20,7 +21,7 @@ class TIR(val date: Long, val lowThreshold: Double, val highThreshold: Double) {
fun inRangePct() = if (count > 0) (inRange.toDouble() / count * 100.0).roundToInt() else 0
fun abovePct() = if (count > 0) (above.toDouble() / count * 100.0).roundToInt() else 0
- fun toText(): String = MainApp.gs(R.string.tirformat, DateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct())
+ fun toText(resourceHelper: ResourceHelper): String = resourceHelper.gs(R.string.tirformat, DateUtil.dateStringShort(date), belowPct(), inRangePct(), abovePct())
- fun toText(days: Int): String = MainApp.gs(R.string.tirformat, "%02d".format(days) + " " + MainApp.gs(R.string.days), belowPct(), inRangePct(), abovePct())
+ fun toText(resourceHelper: ResourceHelper, days: Int): String = resourceHelper.gs(R.string.tirformat, "%02d".format(days) + " " + resourceHelper.gs(R.string.days), belowPct(), inRangePct(), abovePct())
}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TddCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt
similarity index 90%
rename from app/src/main/java/info/nightscout/androidaps/utils/TddCalculator.kt
rename to app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt
index 4a72b18721..62fe9c49ff 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/TddCalculator.kt
+++ b/app/src/main/java/info/nightscout/androidaps/utils/stats/TddCalculator.kt
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.utils
+package info.nightscout.androidaps.utils.stats
import android.text.Spanned
import android.util.LongSparseArray
@@ -12,6 +12,10 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.treatments.TreatmentService
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
+import info.nightscout.androidaps.utils.DateUtil
+import info.nightscout.androidaps.utils.HtmlHelper
+import info.nightscout.androidaps.utils.MidnightTime
+import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Inject
@@ -81,9 +85,9 @@ class TddCalculator @Inject constructor(
val tdds = calculate(7)
val averageTdd = averageTDD(tdds)
return HtmlHelper.fromHtml(
- "" + MainApp.gs(R.string.tdd) + ":
" +
+ "" + resourceHelper.gs(R.string.tdd) + ":
" +
toText(tdds) +
- "" + MainApp.gs(R.string.average) + ":
" +
+ "" + resourceHelper.gs(R.string.average) + ":
" +
averageTdd.toText(tdds.size())
)
}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/TirCalculator.kt b/app/src/main/java/info/nightscout/androidaps/utils/stats/TirCalculator.kt
similarity index 66%
rename from app/src/main/java/info/nightscout/androidaps/utils/TirCalculator.kt
rename to app/src/main/java/info/nightscout/androidaps/utils/stats/TirCalculator.kt
index 4e41f9a331..ae8cf652c2 100644
--- a/app/src/main/java/info/nightscout/androidaps/utils/TirCalculator.kt
+++ b/app/src/main/java/info/nightscout/androidaps/utils/stats/TirCalculator.kt
@@ -1,4 +1,4 @@
-package info.nightscout.androidaps.utils
+package info.nightscout.androidaps.utils.stats
import android.text.Spanned
import android.util.LongSparseArray
@@ -6,8 +6,18 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
+import info.nightscout.androidaps.utils.DateUtil
+import info.nightscout.androidaps.utils.HtmlHelper
+import info.nightscout.androidaps.utils.MidnightTime
+import info.nightscout.androidaps.utils.T
+import info.nightscout.androidaps.utils.resources.ResourceHelper
+import javax.inject.Inject
+import javax.inject.Singleton
-object TirCalculator {
+@Singleton
+class TirCalculator @Inject constructor(
+ private val resourceHelper: ResourceHelper
+){
fun calculate(days: Long, lowMgdl: Double, highMgdl: Double): LongSparseArray {
if (lowMgdl < 39) throw RuntimeException("Low below 39")
if (lowMgdl > highMgdl) throw RuntimeException("Low > High")
@@ -63,21 +73,21 @@ object TirCalculator {
val tit30 = calculate(30, lowTitMgdl, highTitMgdl)
val averageTit30 = averageTIR(tit30)
return HtmlHelper.fromHtml(
- "
" + MainApp.gs(R.string.tir) + ":
" +
- toText(tir7) +
- "
" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):
" +
- averageTir7.toText(tir7.size()) + "
" +
- averageTir30.toText(tir30.size()) +
- "
" + MainApp.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):
" +
- averageTit7.toText(tit7.size()) + "
" +
- averageTit30.toText(tit30.size())
+ "
" + resourceHelper.gs(R.string.tir) + ":
" +
+ toText(resourceHelper, tir7) +
+ "
" + resourceHelper.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTirMgdl) + "-" + Profile.toCurrentUnitsString(highTirMgdl) + "):
" +
+ averageTir7.toText(resourceHelper, tir7.size()) + "
" +
+ averageTir30.toText(resourceHelper, tir30.size()) +
+ "
" + resourceHelper.gs(R.string.average) + " (" + Profile.toCurrentUnitsString(lowTitMgdl) + "-" + Profile.toCurrentUnitsString(highTitMgdl) + "):
" +
+ averageTit7.toText(resourceHelper, tit7.size()) + "
" +
+ averageTit30.toText(resourceHelper, tit30.size())
)
}
- fun toText(tirs: LongSparseArray): String {
+ fun toText(resourceHelper: ResourceHelper, tirs: LongSparseArray): String {
var t = ""
for (i in 0 until tirs.size()) {
- t += "${tirs.valueAt(i).toText()}
"
+ t += "${tirs.valueAt(i).toText(resourceHelper)}
"
}
return t
}