code cleanup

This commit is contained in:
Milos Kozak 2021-06-01 22:51:16 +02:00
parent db95670be5
commit fedba23405
28 changed files with 56 additions and 103 deletions

View file

@ -48,7 +48,7 @@ data class TherapyEvent(
enum class GlucoseUnit { enum class GlucoseUnit {
MGDL, MGDL,
MMOL; MMOL;
companion object { } companion object
} }
enum class MeterType(val text: String) { enum class MeterType(val text: String) {

View file

@ -4,5 +4,4 @@ import dagger.Module
@Module @Module
@Suppress("unused") @Suppress("unused")
abstract class InsightCommModule { abstract class InsightCommModule
}

View file

@ -322,7 +322,7 @@ class MedtronicFragment : DaggerFragment() {
val tbrRemainingTime: Int? = medtronicPumpStatus.tbrRemainingTime val tbrRemainingTime: Int? = medtronicPumpStatus.tbrRemainingTime
if (tbrRemainingTime != null) { if (tbrRemainingTime != null) {
tbrStr = resourceHelper.gs(R.string.mdt_tbr_remaining, medtronicPumpStatus.tempBasalAmount, tbrRemainingTime); tbrStr = resourceHelper.gs(R.string.mdt_tbr_remaining, medtronicPumpStatus.tempBasalAmount, tbrRemainingTime)
} }
binding.tempBasal.text = tbrStr binding.tempBasal.text = tbrStr

View file

@ -109,7 +109,7 @@ class MedtronicConverter @Inject constructor(
} }
} }
public fun decodeSettingsLoop(rd: ByteArray): Map<String, PumpSettingDTO> { fun decodeSettingsLoop(rd: ByteArray): Map<String, PumpSettingDTO> {
val map: MutableMap<String, PumpSettingDTO> = HashMap() val map: MutableMap<String, PumpSettingDTO> = HashMap()
addSettingToMap("PCFG_MAX_BOLUS", "" + decodeMaxBolus(rd), PumpConfigurationGroup.Bolus, map) addSettingToMap("PCFG_MAX_BOLUS", "" + decodeMaxBolus(rd), PumpConfigurationGroup.Bolus, map)
addSettingToMap( addSettingToMap(

View file

@ -92,7 +92,7 @@ abstract class MedtronicHistoryDecoder<T : MedtronicHistoryEntry?>(var aapsLogge
StringUtil.appendToStringBuilder(sb, key1, ", ") StringUtil.appendToStringBuilder(sb, key1, ", ")
} }
val spaces = StringUtils.repeat(" ", 14 - key.name.length) val spaces = StringUtils.repeat(" ", 14 - key.name.length)
aapsLogger.info(LTag.PUMPCOMM, " ${key.name}$spaces - ${value.size}. Elements: ${sb.toString()}") aapsLogger.info(LTag.PUMPCOMM, " ${key.name}$spaces - ${value.size}. Elements: $sb")
} else { } else {
aapsLogger.info(LTag.PUMPCOMM, " ${key.name} - ${value.size}") aapsLogger.info(LTag.PUMPCOMM, " ${key.name} - ${value.size}")
} }

View file

@ -17,24 +17,18 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
lateinit var rawData: List<Byte> lateinit var rawData: List<Byte>
protected var sizes = IntArray(3) protected var sizes = IntArray(3)
get() = field
lateinit var head: ByteArray lateinit var head: ByteArray
lateinit var datetime: ByteArray lateinit var datetime: ByteArray
lateinit var body: ByteArray lateinit var body: ByteArray
var id: Long = 0 var id: Long = 0
set(value) {
field = value
}
@Expose @Expose
var DT: String? = null var DT: String? = null
get() = field
@Expose @Expose
var atechDateTime: Long = 0L var atechDateTime: Long = 0L
get() = field
set(value) { set(value) {
field = value field = value
DT = DateTimeUtil.toString(value) DT = DateTimeUtil.toString(value)
@ -43,7 +37,6 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
@Expose @Expose
var decodedData: MutableMap<String, Any> = mutableMapOf() var decodedData: MutableMap<String, Any> = mutableMapOf()
get() = field
/** /**
* Pump id that will be used with AAPS object (time * 1000 + historyType (max is FF = 255) * Pump id that will be used with AAPS object (time * 1000 + historyType (max is FF = 255)
@ -61,7 +54,6 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
* Linked object, see linked * Linked object, see linked
*/ */
var linkedObject: Any? = null var linkedObject: Any? = null
get() = field
set(value) { set(value) {
linked = true linked = true
field = value field = value

View file

@ -24,16 +24,9 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
override var opCode: Byte? = null override var opCode: Byte? = null
// this is set only when we have unknown entry... // this is set only when we have unknown entry...
get() = if (field == null) entryType.code else field get() = if (field == null) entryType.code else field
set(value) {
field = value
}
var offset = 0 var offset = 0
var displayableValue = "" var displayableValue = ""
get() = field
set(value) {
field = value
}
fun setEntryType(medtronicDeviceType: MedtronicDeviceType, entryType: PumpHistoryEntryType, opCode: Byte? = null) { fun setEntryType(medtronicDeviceType: MedtronicDeviceType, entryType: PumpHistoryEntryType, opCode: Byte? = null) {
this.entryType = entryType this.entryType = entryType
@ -57,17 +50,6 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
+ StringUtil.getStringInLength("" + opCode, 3) + ", 0x" + StringUtil.getStringInLength("" + opCode, 3) + ", 0x"
+ ByteUtil.shortHexString(opCode!!) + "]") + ByteUtil.shortHexString(opCode!!) + "]")
override fun toString(): String {
return super.toString()
// Object object = this.getDecodedDataEntry("Object");
//
// if (object == null) {
// return super.toString();
// } else {
// return super.toString() + "PumpHistoryEntry [type=" + StringUtil.getStringInLength(entryType.name(), 20) + ", DT: " + DT + ", Object=" + object.toString() + "]";
// }
}
override val entryTypeName: String override val entryTypeName: String
get() = entryType.name get() = entryType.name
@ -117,9 +99,6 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
} }
return field return field
} }
set(pumpId) {
field = pumpId
}
fun hasBolusChanged(entry: PumpHistoryEntry): Boolean { fun hasBolusChanged(entry: PumpHistoryEntry): Boolean {
if (entryType == PumpHistoryEntryType.Bolus) { if (entryType == PumpHistoryEntryType.Bolus) {

View file

@ -205,7 +205,6 @@ constructor(var code: Byte,
private var specialRulesHead: MutableList<SpecialRule>? = null private var specialRulesHead: MutableList<SpecialRule>? = null
private var specialRulesBody: MutableList<SpecialRule>? = null private var specialRulesBody: MutableList<SpecialRule>? = null
private var hasSpecialRules = false private var hasSpecialRules = false
get() = field
fun getTotalLength(medtronicDeviceType: MedtronicDeviceType): Int { fun getTotalLength(medtronicDeviceType: MedtronicDeviceType): Int {
return if (hasSpecialRules) { return if (hasSpecialRules) {

View file

@ -22,10 +22,6 @@ class GetHistoryPageCarelinkMessageBody : CarelinkLongMessageBody {
override val length: Int override val length: Int
get() = data!!.size get() = data!!.size
override fun init(rxData: ByteArray?) {
super.init(rxData)
}
fun init(pageNum: Int) { fun init(pageNum: Int) {
val numArgs: Byte = 1 val numArgs: Byte = 1
super.init(byteArrayOf(numArgs, pageNum.toByte())) super.init(byteArrayOf(numArgs, pageNum.toByte()))

View file

@ -91,7 +91,7 @@ class MedtronicHistoryData @Inject constructor(
.filter { f -> f.pumpId == pumpId } .filter { f -> f.pumpId == pumpId }
.findFirst() .findFirst()
return if (findFirst.isPresent()) findFirst.get() else null return if (findFirst.isPresent) findFirst.get() else null
} }
private fun showLogs(header: String?, data: String) { private fun showLogs(header: String?, data: String) {

View file

@ -314,7 +314,7 @@ class BasalProfile {
fun isBasalProfileByHourUndefined(basalByHour: DoubleArray): Boolean { fun isBasalProfileByHourUndefined(basalByHour: DoubleArray): Boolean {
for (i in 0..23) { for (i in 0..23) {
if (basalByHour[i] > 0.0) { if (basalByHour[i] > 0.0) {
return false; return false
} }
} }
return true return true

View file

@ -15,16 +15,9 @@ class BasalProfileEntry {
var rate_raw: ByteArray var rate_raw: ByteArray
var rate = 0.0 var rate = 0.0
set(value) {
field = value
}
var startTime_raw: Byte var startTime_raw: Byte
var startTime : LocalTime? = null // Just a "time of day" var startTime : LocalTime? = null // Just a "time of day"
set(value) {
field = value
}
constructor() { constructor() {
rate = -9.999E6 rate = -9.999E6

View file

@ -62,7 +62,7 @@ class TempBasalPair : TempBasalPair {
aapsLogger.warn(LTag.PUMPBTCOMM, String.format(Locale.ENGLISH, "TempBasalPair (with %d byte response): %s", response.size, toString())) aapsLogger.warn(LTag.PUMPBTCOMM, String.format(Locale.ENGLISH, "TempBasalPair (with %d byte response): %s", response.size, toString()))
} }
constructor(insulinRate: Double, isPercent: Boolean, durationMinutes: Int) : super(insulinRate, isPercent, durationMinutes) {} constructor(insulinRate: Double, isPercent: Boolean, durationMinutes: Int) : super(insulinRate, isPercent, durationMinutes)
// list.add((byte) 0); // ? // list.add((byte) 0); // ?

View file

@ -19,5 +19,5 @@ enum class MedtronicNotificationType(var notificationType: Int,
PumpWrongMaxBasalSet(R.string.medtronic_error_pump_wrong_max_basal_set, Notification.NORMAL), // PumpWrongMaxBasalSet(R.string.medtronic_error_pump_wrong_max_basal_set, Notification.NORMAL), //
PumpWrongTimeUrgent(R.string.medtronic_notification_check_time_date, Notification.URGENT), PumpWrongTimeNormal(R.string.medtronic_notification_check_time_date, Notification.NORMAL), TimeChangeOver24h(Notification.OVER_24H_TIME_CHANGE_REQUESTED, R.string.medtronic_error_pump_24h_time_change_requested, Notification.URGENT); PumpWrongTimeUrgent(R.string.medtronic_notification_check_time_date, Notification.URGENT), PumpWrongTimeNormal(R.string.medtronic_notification_check_time_date, Notification.NORMAL), TimeChangeOver24h(Notification.OVER_24H_TIME_CHANGE_REQUESTED, R.string.medtronic_error_pump_24h_time_change_requested, Notification.URGENT);
constructor(resourceId: Int, notificationUrgency: Int) : this(Notification.MEDTRONIC_PUMP_ALARM, resourceId, notificationUrgency) {} constructor(resourceId: Int, notificationUrgency: Int) : this(Notification.MEDTRONIC_PUMP_ALARM, resourceId, notificationUrgency)
} }

View file

@ -30,6 +30,6 @@ abstract class MedtronicModule {
companion object { companion object {
@Provides @Provides
fun byteUtilProvider(): ByteUtil = ByteUtil(); fun byteUtilProvider(): ByteUtil = ByteUtil()
} }
} }

View file

@ -84,10 +84,6 @@ class MedtronicHistoryActivity : DaggerActivity() {
manualChange = false manualChange = false
} }
override fun onPause() {
super.onPause()
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.medtronic_history_activity) setContentView(R.layout.medtronic_history_activity)
@ -96,17 +92,17 @@ class MedtronicHistoryActivity : DaggerActivity() {
recyclerView = findViewById(R.id.medtronic_history_recyclerview) recyclerView = findViewById(R.id.medtronic_history_recyclerview)
recyclerView.setHasFixedSize(true) recyclerView.setHasFixedSize(true)
llm = LinearLayoutManager(this) llm = LinearLayoutManager(this)
recyclerView.setLayoutManager(llm) recyclerView.layoutManager = llm
recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList) recyclerViewAdapter = RecyclerViewAdapter(filteredHistoryList)
recyclerView.setAdapter(recyclerViewAdapter) recyclerView.adapter = recyclerViewAdapter
statusView.setVisibility(View.GONE) statusView.visibility = View.GONE
typeListFull = getTypeList(PumpHistoryEntryGroup.getTranslatedList(resourceHelper)) typeListFull = getTypeList(PumpHistoryEntryGroup.getTranslatedList(resourceHelper))
val spinnerAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull) val spinnerAdapter = ArrayAdapter(this, R.layout.spinner_centered, typeListFull)
historyTypeSpinner.setAdapter(spinnerAdapter) historyTypeSpinner.adapter = spinnerAdapter
historyTypeSpinner.setOnItemSelectedListener(object : AdapterView.OnItemSelectedListener { historyTypeSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) { override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
if (manualChange) return if (manualChange) return
val selected = historyTypeSpinner.getSelectedItem() as TypeList val selected = historyTypeSpinner.selectedItem as TypeList
showingType = selected showingType = selected
selectedGroup = selected.entryGroup selectedGroup = selected.entryGroup
filterHistory(selectedGroup) filterHistory(selectedGroup)
@ -116,7 +112,7 @@ class MedtronicHistoryActivity : DaggerActivity() {
if (manualChange) return if (manualChange) return
filterHistory(PumpHistoryEntryGroup.All) filterHistory(PumpHistoryEntryGroup.All)
} }
}) }
} }
private fun getTypeList(list: List<PumpHistoryEntryGroup>): List<TypeList> { private fun getTypeList(list: List<PumpHistoryEntryGroup>): List<TypeList> {

View file

@ -4,5 +4,4 @@ import dagger.Module
@Module @Module
@Suppress("unused") @Suppress("unused")
abstract class OmnipodDashModule { abstract class OmnipodDashModule
}

View file

@ -3,7 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.command.
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class BolusShortInsulinProgramElement implements ShortInsulinProgramElement { public class BolusShortInsulinProgramElement implements ShortInsulinProgramElement {
private short numberOfPulses; private final short numberOfPulses;
public BolusShortInsulinProgramElement(short numberOfPulses) { public BolusShortInsulinProgramElement(short numberOfPulses) {
this.numberOfPulses = numberOfPulses; this.numberOfPulses = numberOfPulses;

View file

@ -157,7 +157,7 @@ public enum AlarmType {
ALARM_BLE_QN_CRIT_VAR_FAIL((byte) 0xc2), ALARM_BLE_QN_CRIT_VAR_FAIL((byte) 0xc2),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
AlarmType(byte value) { AlarmType(byte value) {
this.value = value; this.value = value;

View file

@ -5,14 +5,14 @@ import androidx.annotation.NonNull;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
public class AlertConfiguration implements Encodable { public class AlertConfiguration implements Encodable {
private AlertSlot slot; private final AlertSlot slot;
private boolean enabled; private final boolean enabled;
private short durationInMinutes; private final short durationInMinutes;
private boolean autoOff; private final boolean autoOff;
private AlertTriggerType triggerType; private final AlertTriggerType triggerType;
private short offsetInMinutesOrThresholdInMicroLiters; private final short offsetInMinutesOrThresholdInMicroLiters;
private BeepType beepType; private final BeepType beepType;
private BeepRepetitionType beepRepetition; private final BeepRepetitionType beepRepetition;
public AlertConfiguration(AlertSlot slot, boolean enabled, short durationInMinutes, boolean autoOff, AlertTriggerType triggerType, short offsetInMinutesOrThresholdInMicroLiters, BeepType beepType, BeepRepetitionType beepRepetition) { public AlertConfiguration(AlertSlot slot, boolean enabled, short durationInMinutes, boolean autoOff, AlertTriggerType triggerType, short offsetInMinutesOrThresholdInMicroLiters, BeepType beepType, BeepRepetitionType beepRepetition) {
this.slot = slot; this.slot = slot;

View file

@ -11,7 +11,7 @@ public enum AlertSlot {
EXPIRATION((byte) 0x07), EXPIRATION((byte) 0x07),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
AlertSlot(byte value) { AlertSlot(byte value) {
this.value = value; this.value = value;

View file

@ -8,7 +8,7 @@ public enum BeepRepetitionType {
XXX4((byte) 0x06), // Used in imminent pod expiration alert XXX4((byte) 0x06), // Used in imminent pod expiration alert
XXX5((byte) 0x08); // Used in lump of coal alert XXX5((byte) 0x08); // Used in lump of coal alert
private byte value; private final byte value;
BeepRepetitionType(byte value) { BeepRepetitionType(byte value) {
this.value = value; this.value = value;

View file

@ -5,7 +5,7 @@ public enum BeepType {
FOUR_TIMES_BIP_BEEP((byte) 0x02), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert FOUR_TIMES_BIP_BEEP((byte) 0x02), // Used in low reservoir alert, user expiration alert, expiration alert, imminent expiration alert, lump of coal alert
LONG_SINGLE_BEEP((byte) 0x06); // Used in stop delivery command LONG_SINGLE_BEEP((byte) 0x06); // Used in stop delivery command
private byte value; private final byte value;
BeepType(byte value) { BeepType(byte value) {
this.value = value; this.value = value;

View file

@ -9,7 +9,7 @@ public enum DeliveryStatus {
BOLUS_AND_TEMP_BASAL_ACTIVE((byte) 0x06), BOLUS_AND_TEMP_BASAL_ACTIVE((byte) 0x06),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
DeliveryStatus(byte value) { DeliveryStatus(byte value) {
this.value = value; this.value = value;

View file

@ -32,7 +32,7 @@ public enum NakErrorType {
INVALID_CRC((byte) 0x1d), INVALID_CRC((byte) 0x1d),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
NakErrorType(byte value) { NakErrorType(byte value) {
this.value = value; this.value = value;

View file

@ -19,7 +19,7 @@ public enum PodStatus {
DEACTIVATED((byte) 0x0f), DEACTIVATED((byte) 0x0f),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
PodStatus(byte value) { PodStatus(byte value) {
this.value = value; this.value = value;

View file

@ -7,7 +7,7 @@ public enum ResponseType {
NAK_RESPONSE((byte) 0x06), NAK_RESPONSE((byte) 0x06),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
ResponseType(byte value) { ResponseType(byte value) {
this.value = value; this.value = value;
@ -37,7 +37,7 @@ public enum ResponseType {
STATUS_RESPONSE_PAGE_81((byte) 0x51), STATUS_RESPONSE_PAGE_81((byte) 0x51),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte value; private final byte value;
AdditionalStatusResponseType(byte value) { AdditionalStatusResponseType(byte value) {
this.value = value; this.value = value;
@ -62,7 +62,7 @@ public enum ResponseType {
SET_UNIQUE_ID_RESPONSE((byte) 0x1b), SET_UNIQUE_ID_RESPONSE((byte) 0x1b),
UNKNOWN((byte) 0xff); UNKNOWN((byte) 0xff);
private byte length; private final byte length;
ActivationResponseType(byte length) { ActivationResponseType(byte length) {
this.length = length; this.length = length;

View file

@ -6,25 +6,25 @@ import java.util.Arrays;
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus; import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus;
public final class SetUniqueIdResponse extends ActivationResponseBase { public final class SetUniqueIdResponse extends ActivationResponseBase {
private byte messageType; private final byte messageType;
private short messageLength; private final short messageLength;
private short pulseVolumeInTenThousandthMicroLiter; private final short pulseVolumeInTenThousandthMicroLiter;
private short pumpRate; private final short pumpRate;
private short primePumpRate; private final short primePumpRate;
private short numberOfEngagingClutchDrivePulses; private final short numberOfEngagingClutchDrivePulses;
private short numberOfPrimePulses; private final short numberOfPrimePulses;
private short podExpirationTimeInHours; private final short podExpirationTimeInHours;
private short firmwareVersionMajor; private final short firmwareVersionMajor;
private short firmwareVersionMinor; private final short firmwareVersionMinor;
private short firmwareVersionInterim; private final short firmwareVersionInterim;
private short bleVersionMajor; private final short bleVersionMajor;
private short bleVersionMinor; private final short bleVersionMinor;
private short bleVersionInterim; private final short bleVersionInterim;
private short productId; private final short productId;
private PodStatus podStatus; private final PodStatus podStatus;
private long lotNumber; private final long lotNumber;
private long podSequenceNumber; private final long podSequenceNumber;
private long uniqueIdReceivedInCommand; private final long uniqueIdReceivedInCommand;
public SetUniqueIdResponse(byte[] encoded) { public SetUniqueIdResponse(byte[] encoded) {
super(ResponseType.ActivationResponseType.SET_UNIQUE_ID_RESPONSE, encoded); super(ResponseType.ActivationResponseType.SET_UNIQUE_ID_RESPONSE, encoded);