From 07f1168270b02b69d5624f765e808b96232fc553 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 14 Nov 2022 14:22:41 +0100 Subject: [PATCH] move UserEntryMapper --- .../androidaps/interfaces/stats/DexcomTIR.kt | 11 +++-- .../androidaps/logging/UserEntryLogger.kt | 8 ++-- .../stats/DexcomTirCalculatorImpl.kt | 10 ++--- .../implementation/stats/DexcomTirImpl.kt | 41 +++++++++---------- .../interfaces}/userEntry/UserEntryMapper.kt | 2 +- .../userEntry/ValueWithUnitMapper.kt | 2 +- .../androidaps/dana/DanaFragment.kt | 4 +- .../ble/task/InternalSuspendedTask.java | 2 +- .../pump/eopatch/ble/task/PauseBasalTask.java | 2 +- .../pump/eopatch/ble/task/StopBasalTask.java | 2 +- 10 files changed, 41 insertions(+), 43 deletions(-) rename {core/core-main/src/main/java/info/nightscout/androidaps/utils => interfaces/src/main/java/info/nightscout/interfaces}/userEntry/UserEntryMapper.kt (99%) rename {core/core-main/src/main/java/info/nightscout/androidaps/utils => interfaces/src/main/java/info/nightscout/interfaces}/userEntry/ValueWithUnitMapper.kt (98%) diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/stats/DexcomTIR.kt b/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/stats/DexcomTIR.kt index 5ac862756d..3bb9389cc8 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/stats/DexcomTIR.kt +++ b/core/core-main/src/main/java/info/nightscout/androidaps/interfaces/stats/DexcomTIR.kt @@ -4,14 +4,13 @@ import android.content.Context import android.widget.TableRow import android.widget.TextView import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.shared.interfaces.ResourceHelper interface DexcomTIR { fun calculateSD(): Double - fun toHbA1cView(context: Context, rh: ResourceHelper): TextView - fun toSDView(context: Context, rh: ResourceHelper, profileFunction: ProfileFunction): TextView - fun toRangeHeaderView(context: Context, rh: ResourceHelper, profileFunction: ProfileFunction): TextView - fun toTableRowHeader(context: Context, rh: ResourceHelper): TableRow - fun toTableRow(context: Context, rh: ResourceHelper): TableRow + fun toHbA1cView(context: Context): TextView + fun toSDView(context: Context, profileFunction: ProfileFunction): TextView + fun toRangeHeaderView(context: Context, profileFunction: ProfileFunction): TextView + fun toTableRowHeader(context: Context): TableRow + fun toTableRow(context: Context): TableRow } diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt b/core/core-main/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt index 1d34a47ac7..5d785ba9b9 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt +++ b/core/core-main/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt @@ -1,13 +1,13 @@ package info.nightscout.androidaps.logging import info.nightscout.androidaps.annotations.OpenForTesting -import info.nightscout.database.impl.AppRepository -import info.nightscout.database.impl.transactions.UserEntryTransaction -import info.nightscout.androidaps.utils.userEntry.UserEntryMapper -import info.nightscout.androidaps.utils.userEntry.ValueWithUnitMapper import info.nightscout.database.entities.UserEntry.Action import info.nightscout.database.entities.UserEntry.Sources import info.nightscout.database.entities.ValueWithUnit +import info.nightscout.database.impl.AppRepository +import info.nightscout.database.impl.transactions.UserEntryTransaction +import info.nightscout.interfaces.userEntry.UserEntryMapper +import info.nightscout.interfaces.userEntry.ValueWithUnitMapper import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.logging.AAPSLogger import info.nightscout.shared.utils.DateUtil diff --git a/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirCalculatorImpl.kt b/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirCalculatorImpl.kt index 5a3ffa64f9..7615a6b690 100644 --- a/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirCalculatorImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirCalculatorImpl.kt @@ -40,10 +40,10 @@ class DexcomTirCalculatorImpl @Inject constructor( TableLayout(context).also { layout -> val tir = calculate() layout.layoutParams = TableLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f) - layout.addView(tir.toRangeHeaderView(context, rh, profileFunction)) - layout.addView(tir.toTableRowHeader(context, rh)) - layout.addView(tir.toTableRow(context, rh)) - layout.addView(tir.toSDView(context, rh, profileFunction)) - layout.addView(tir.toHbA1cView(context, rh)) + layout.addView(tir.toRangeHeaderView(context, profileFunction)) + layout.addView(tir.toTableRowHeader(context)) + layout.addView(tir.toTableRow(context)) + layout.addView(tir.toSDView(context, profileFunction)) + layout.addView(tir.toHbA1cView(context)) } } \ No newline at end of file diff --git a/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirImpl.kt b/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirImpl.kt index 5a3bfbe88f..4292af3e81 100644 --- a/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirImpl.kt +++ b/implementation/src/main/java/info/nightscout/implementation/stats/DexcomTirImpl.kt @@ -13,7 +13,6 @@ import info.nightscout.implementation.R import info.nightscout.interfaces.Constants import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.shared.interfaces.ResourceHelper import java.util.Calendar import kotlin.math.pow import kotlin.math.roundToInt @@ -75,11 +74,11 @@ class DexcomTirImpl : DexcomTIR { return sqrt(standardDeviation / count) } - override fun toHbA1cView(context: Context, rh: ResourceHelper): TextView = + override fun toHbA1cView(context: Context): TextView = TextView(context).apply { text = if (count == 0) "" - else rh.gs(R.string.hba1c) + + else context.getString(R.string.hba1c) + (10 * (mean() + 46.7) / 28.7).roundToInt() / 10.0 + "%" + " (" + (((mean() + 46.7) / 28.7 - 2.15) * 10.929).roundToInt() + @@ -89,20 +88,20 @@ class DexcomTirImpl : DexcomTIR { } @SuppressLint("SetTextI18n") - override fun toSDView(context: Context, rh: ResourceHelper, profileFunction: ProfileFunction): TextView = + override fun toSDView(context: Context, profileFunction: ProfileFunction): TextView = TextView(context).apply { val sd = calculateSD() - text = "\n" + rh.gs(R.string.std_deviation, Profile.toUnitsString(sd, sd * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())) + text = "\n" + context.getString(R.string.std_deviation, Profile.toUnitsString(sd, sd * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())) setTypeface(typeface, Typeface.NORMAL) gravity = Gravity.CENTER_HORIZONTAL } - override fun toRangeHeaderView(context: Context, rh: ResourceHelper, profileFunction: ProfileFunction): TextView = + override fun toRangeHeaderView(context: Context, profileFunction: ProfileFunction): TextView = TextView(context).apply { text = StringBuilder() - .append(rh.gs(R.string.detailed_14_days)) + .append(context.getString(R.string.detailed_14_days)) .append("\n") - .append(rh.gs(R.string.day_tir)) + .append(context.getString(R.string.day_tir)) .append(" (") .append(Profile.toUnitsString(0.0, 0.0, profileFunction.getUnits())) .append("-") @@ -114,7 +113,7 @@ class DexcomTirImpl : DexcomTIR { .append("-") .append(Profile.toCurrentUnitsString(profileFunction, veryHighTirMgdl)) .append("-∞)\n") - .append(rh.gs(R.string.night_tir)) + .append(context.getString(R.string.night_tir)) .append(" (") .append(Profile.toUnitsString(0.0, 0.0, profileFunction.getUnits())) .append("-") @@ -132,28 +131,28 @@ class DexcomTirImpl : DexcomTIR { setTextAppearance(android.R.style.TextAppearance_Material_Medium) } - override fun toTableRowHeader(context: Context, rh: ResourceHelper): TableRow = + override fun toTableRowHeader(context: Context): TableRow = TableRow(context).also { header -> val lp = TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT) header.layoutParams = TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT) header.gravity = Gravity.CENTER_HORIZONTAL - header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 0; weight = 1f }; text = rh.gs(R.string.veryLow) }) - header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 1; weight = 1f }; text = rh.gs(R.string.low) }) - header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 2; weight = 1f }; text = rh.gs(R.string.in_range) }) - header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 3; weight = 1f }; text = rh.gs(R.string.high) }) - header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 4; weight = 1f }; text = rh.gs(R.string.veryHigh) }) + header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 0; weight = 1f }; text = context.getString(R.string.veryLow) }) + header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 1; weight = 1f }; text = context.getString(R.string.low) }) + header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 2; weight = 1f }; text = context.getString(R.string.in_range) }) + header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 3; weight = 1f }; text = context.getString(R.string.high) }) + header.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 4; weight = 1f }; text = context.getString(R.string.veryHigh) }) } @SuppressLint("SetTextI18n") - override fun toTableRow(context: Context, rh: ResourceHelper): TableRow = + override fun toTableRow(context: Context): TableRow = TableRow(context).also { row -> val lp = TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 1f) row.layoutParams = TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT) row.gravity = Gravity.CENTER_HORIZONTAL - row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 0 }; text = rh.gs(R.string.formatPercent, veryLowPct()) }) - row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 1 }; text = rh.gs(R.string.formatPercent, lowPct()) }) - row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 2 }; text = rh.gs(R.string.formatPercent, inRangePct()) }) - row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 3 }; text = rh.gs(R.string.formatPercent, highPct()) }) - row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 4 }; text = rh.gs(R.string.formatPercent, veryHighPct()) }) + row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 0 }; text = context.getString(R.string.formatPercent, veryLowPct()) }) + row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 1 }; text = context.getString(R.string.formatPercent, lowPct()) }) + row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 2 }; text = context.getString(R.string.formatPercent, inRangePct()) }) + row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 3 }; text = context.getString(R.string.formatPercent, highPct()) }) + row.addView(TextView(context).apply { gravity = Gravity.CENTER_HORIZONTAL; layoutParams = lp.apply { column = 4 }; text = context.getString(R.string.formatPercent, veryHighPct()) }) } } diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt b/interfaces/src/main/java/info/nightscout/interfaces/userEntry/UserEntryMapper.kt similarity index 99% rename from core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt rename to interfaces/src/main/java/info/nightscout/interfaces/userEntry/UserEntryMapper.kt index 5833281465..c295bcbe01 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt +++ b/interfaces/src/main/java/info/nightscout/interfaces/userEntry/UserEntryMapper.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.utils.userEntry +package info.nightscout.interfaces.userEntry import info.nightscout.database.entities.UserEntry diff --git a/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt b/interfaces/src/main/java/info/nightscout/interfaces/userEntry/ValueWithUnitMapper.kt similarity index 98% rename from core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt rename to interfaces/src/main/java/info/nightscout/interfaces/userEntry/ValueWithUnitMapper.kt index 73f7b57b6b..0261306094 100644 --- a/core/core-main/src/main/java/info/nightscout/androidaps/utils/userEntry/ValueWithUnitMapper.kt +++ b/interfaces/src/main/java/info/nightscout/interfaces/userEntry/ValueWithUnitMapper.kt @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.utils.userEntry +package info.nightscout.interfaces.userEntry import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TherapyEvent diff --git a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt b/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt index 245a79164b..49525bb952 100644 --- a/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt +++ b/pump/dana/src/main/java/info/nightscout/androidaps/dana/DanaFragment.kt @@ -15,8 +15,6 @@ import info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity import info.nightscout.androidaps.dana.databinding.DanarFragmentBinding import info.nightscout.androidaps.dana.events.EventDanaRNewStatus import info.nightscout.androidaps.logging.UserEntryLogger -import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Action -import info.nightscout.androidaps.utils.userEntry.UserEntryMapper.Sources import info.nightscout.core.fabric.FabricPrivacy import info.nightscout.core.ui.dialogs.OKDialog import info.nightscout.interfaces.plugin.ActivePlugin @@ -26,6 +24,8 @@ import info.nightscout.interfaces.pump.WarnColors import info.nightscout.interfaces.pump.defs.PumpType import info.nightscout.interfaces.queue.CommandQueue import info.nightscout.interfaces.ui.ActivityNames +import info.nightscout.interfaces.userEntry.UserEntryMapper.Action +import info.nightscout.interfaces.userEntry.UserEntryMapper.Sources import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventExtendedBolusChange diff --git a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/InternalSuspendedTask.java b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/InternalSuspendedTask.java index d3a3b37420..8703449ab7 100644 --- a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/InternalSuspendedTask.java +++ b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/InternalSuspendedTask.java @@ -10,11 +10,11 @@ import javax.inject.Singleton; import info.nightscout.androidaps.logging.UserEntryLogger; import info.nightscout.androidaps.plugins.pump.eopatch.core.api.GetInternalSuspendTime; import info.nightscout.androidaps.plugins.pump.eopatch.core.response.PatchInternalSuspendTimeResponse; -import info.nightscout.androidaps.utils.userEntry.UserEntryMapper; import info.nightscout.interfaces.pump.PumpSync; import info.nightscout.interfaces.queue.Callback; import info.nightscout.interfaces.queue.Command; import info.nightscout.interfaces.queue.CommandQueue; +import info.nightscout.interfaces.userEntry.UserEntryMapper; import info.nightscout.rx.logging.AAPSLogger; import info.nightscout.rx.logging.LTag; import io.reactivex.rxjava3.core.Observable; diff --git a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/PauseBasalTask.java b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/PauseBasalTask.java index 8001c78667..6ef3312df7 100644 --- a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/PauseBasalTask.java +++ b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/PauseBasalTask.java @@ -16,11 +16,11 @@ import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager; import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BasalPause; import info.nightscout.androidaps.plugins.pump.eopatch.core.response.PatchBooleanResponse; import info.nightscout.androidaps.plugins.pump.eopatch.vo.PatchState; -import info.nightscout.androidaps.utils.userEntry.UserEntryMapper; import info.nightscout.interfaces.pump.PumpSync; import info.nightscout.interfaces.queue.Callback; import info.nightscout.interfaces.queue.Command; import info.nightscout.interfaces.queue.CommandQueue; +import info.nightscout.interfaces.userEntry.UserEntryMapper; import info.nightscout.rx.logging.AAPSLogger; import info.nightscout.rx.logging.LTag; import io.reactivex.rxjava3.core.Observable; diff --git a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/StopBasalTask.java b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/StopBasalTask.java index b9f285a1c8..9a341a46d3 100644 --- a/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/StopBasalTask.java +++ b/pump/eopatch/src/main/java/info/nightscout/androidaps/plugins/pump/eopatch/ble/task/StopBasalTask.java @@ -11,11 +11,11 @@ import info.nightscout.androidaps.logging.UserEntryLogger; import info.nightscout.androidaps.plugins.pump.eopatch.ble.IPreferenceManager; import info.nightscout.androidaps.plugins.pump.eopatch.core.api.BasalStop; import info.nightscout.androidaps.plugins.pump.eopatch.core.response.BasalStopResponse; -import info.nightscout.androidaps.utils.userEntry.UserEntryMapper; import info.nightscout.interfaces.pump.PumpSync; import info.nightscout.interfaces.queue.Callback; import info.nightscout.interfaces.queue.Command; import info.nightscout.interfaces.queue.CommandQueue; +import info.nightscout.interfaces.userEntry.UserEntryMapper; import info.nightscout.rx.logging.AAPSLogger; import info.nightscout.rx.logging.LTag; import io.reactivex.rxjava3.core.Observable;