move UserEntryMapper

This commit is contained in:
Milos Kozak 2022-11-14 14:22:41 +01:00
parent d50d1bf9c9
commit 07f1168270
10 changed files with 41 additions and 43 deletions

View file

@ -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
}

View file

@ -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

View file

@ -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))
}
}

View file

@ -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()) })
}
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.utils.userEntry
package info.nightscout.interfaces.userEntry
import info.nightscout.database.entities.UserEntry

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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;