Eliminate @JvmStatic

This commit is contained in:
Milos Kozak 2022-06-01 09:58:07 +02:00
parent dceca8d194
commit 211c86deb7
13 changed files with 36 additions and 32 deletions

View file

@ -182,7 +182,7 @@ public class TimeListEdit {
numberPickers1[position].setTextWatcher(new TextWatcher() { numberPickers1[position].setTextWatcher(new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
Double value1 = SafeParse.stringToDouble(numberPickers1[position].getText()); Double value1 = SafeParse.INSTANCE.stringToDouble(numberPickers1[position].getText());
Double value2 = value2(position); Double value2 = value2(position);
if (data2 != null && value1 > value2) { if (data2 != null && value1 > value2) {
value2 = value1; value2 = value1;
@ -209,7 +209,7 @@ public class TimeListEdit {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
Double value1 = value1(position); Double value1 = value1(position);
Double value2 = SafeParse.stringToDouble(numberPickers2[position].getText()); Double value2 = SafeParse.INSTANCE.stringToDouble(numberPickers2[position].getText());
if (data2 != null && value2 < value1) { if (data2 != null && value2 < value1) {
value1 = value2; value1 = value2;
numberPickers1[position].setValue(value1); numberPickers1[position].setValue(value1);

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.dialogs.ErrorDialog
import info.nightscout.androidaps.dialogs.NtpProgressDialog import info.nightscout.androidaps.dialogs.NtpProgressDialog
import info.nightscout.androidaps.dialogs.ProfileViewerDialog import info.nightscout.androidaps.dialogs.ProfileViewerDialog
import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity
import info.nightscout.androidaps.utils.ui.SingleClickButton
@Module @Module
@Suppress("unused") @Suppress("unused")
@ -25,4 +26,6 @@ abstract class CoreFragmentsModule {
@ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog @ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog
@ContributesAndroidInjector abstract fun contributesProfileViewerDialog(): ProfileViewerDialog @ContributesAndroidInjector abstract fun contributesProfileViewerDialog(): ProfileViewerDialog
@ContributesAndroidInjector abstract fun contributesSingleClickButton(): SingleClickButton
} }

View file

@ -4,7 +4,6 @@ import java.math.BigDecimal
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.round
import kotlin.math.roundToLong import kotlin.math.roundToLong
/** /**
@ -12,22 +11,18 @@ import kotlin.math.roundToLong
*/ */
object Round { object Round {
@JvmStatic
fun roundTo(x: Double, step: Double): Double = fun roundTo(x: Double, step: Double): Double =
if (x == 0.0) 0.0 if (x == 0.0) 0.0
else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble() else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble()
@JvmStatic
fun floorTo(x: Double, step: Double): Double = fun floorTo(x: Double, step: Double): Double =
if (x != 0.0) floor(x / step) * step if (x != 0.0) floor(x / step) * step
else 0.0 else 0.0
@JvmStatic
fun ceilTo(x: Double, step: Double): Double = fun ceilTo(x: Double, step: Double): Double =
if (x != 0.0) ceil(x / step) * step if (x != 0.0) ceil(x / step) * step
else 0.0 else 0.0
@JvmStatic
fun isSame(d1: Double, d2: Double): Boolean = fun isSame(d1: Double, d2: Double): Boolean =
abs(d1 - d2) <= 0.000001 abs(d1 - d2) <= 0.000001
} }

View file

@ -2,25 +2,32 @@ package info.nightscout.androidaps.utils.ui
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.core.R import info.nightscout.androidaps.core.R
import info.nightscout.shared.logging.StacktraceLoggerWrapper import info.nightscout.shared.logging.AAPSLogger
import org.slf4j.Logger import info.nightscout.shared.logging.LTag
import javax.inject.Inject
class SingleClickButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.style.Widget_MaterialComponents_Button) : com.google.android.material.button.MaterialButton(context, attrs, defStyleAttr) { class SingleClickButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.style.Widget_MaterialComponents_Button) :
com.google.android.material.button.MaterialButton(context, attrs, defStyleAttr) {
init {
(context.applicationContext as HasAndroidInjector).androidInjector().inject(this)
}
@Inject lateinit var aapsLogger: AAPSLogger
override fun performClick(): Boolean = guardClick { super.performClick() } override fun performClick(): Boolean = guardClick { super.performClick() }
override fun callOnClick(): Boolean = guardClick { super.callOnClick() } override fun callOnClick(): Boolean = guardClick { super.callOnClick() }
private fun guardClick(block: () -> Boolean): Boolean { private fun guardClick(block: () -> Boolean): Boolean {
isEnabled = false isEnabled = false
postDelayed({ isEnabled = true; log.debug("Button enabled") }, BUTTON_REFRACTION_PERIOD) postDelayed({ isEnabled = true; aapsLogger.debug(LTag.UI, "Button enabled") }, BUTTON_REFRACTION_PERIOD)
return block() return block()
} }
@Suppress("DEPRECATION")
private val log: Logger = StacktraceLoggerWrapper.getLogger(SingleClickButton::class.java)
companion object { companion object {
const val BUTTON_REFRACTION_PERIOD = 3000L const val BUTTON_REFRACTION_PERIOD = 3000L
} }
} }

View file

@ -232,8 +232,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp. // Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
if (absoluteRate < 0.10d) percentRate = 0; if (absoluteRate < 0.10d) percentRate = 0;
if (percentRate < 100) percentRate = (int) Round.ceilTo((double) percentRate, 10d); if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo((double) percentRate, 10d);
else percentRate = (int) Round.floorTo((double) percentRate, 10d); else percentRate = (int) Round.INSTANCE.floorTo((double) percentRate, 10d);
if (percentRate > 500) // Special high temp 500/15min if (percentRate > 500) // Special high temp 500/15min
percentRate = 500; percentRate = 500;
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate); aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Calculated percent rate: " + percentRate);
@ -353,7 +353,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep());
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) { if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) {

View file

@ -267,7 +267,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value(); insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded // needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1); int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
insulin = Round.roundTo(insulin, getPumpDescription().getExtendedBolusStep()); insulin = Round.INSTANCE.roundTo(insulin, getPumpDescription().getExtendedBolusStep());
PumpEnactResult result = new PumpEnactResult(getInjector()); PumpEnactResult result = new PumpEnactResult(getInjector());
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) { if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) {

View file

@ -217,8 +217,8 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue(); int percentRate = Double.valueOf(absoluteRate / getBaseBasalRate() * 100).intValue();
// Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp. // Any basal less than 0.10u/h will be dumped once per hour, not every 4 minutes. So if it's less than .10u/h, set a zero temp.
if (absoluteRate < 0.10d) percentRate = 0; if (absoluteRate < 0.10d) percentRate = 0;
if (percentRate < 100) percentRate = (int) Round.ceilTo((double) percentRate, 10d); if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo((double) percentRate, 10d);
else percentRate = (int) Round.floorTo((double) percentRate, 10d); else percentRate = (int) Round.INSTANCE.floorTo((double) percentRate, 10d);
if (percentRate > getPumpDescription().getMaxTempPercent()) { if (percentRate > getPumpDescription().getMaxTempPercent()) {
percentRate = getPumpDescription().getMaxTempPercent(); percentRate = getPumpDescription().getMaxTempPercent();
} }
@ -288,7 +288,8 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
double extendedRateToSet = absoluteRate - getBaseBasalRate(); double extendedRateToSet = absoluteRate - getBaseBasalRate();
extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value(); extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value();
// needs to be rounded to 0.1 // needs to be rounded to 0.1
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours extendedRateToSet = Round.INSTANCE.roundTo(extendedRateToSet,
pumpDescription.getExtendedBolusStep() * 2); // *2 because of half hours
// What is current rate of extended bolusing in u/h? // What is current rate of extended bolusing in u/h?
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min"); aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min");

View file

@ -8,7 +8,7 @@ import org.slf4j.Logger;
public class HistoryEvent implements Comparable<HistoryEvent> { public class HistoryEvent implements Comparable<HistoryEvent> {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static final Logger log = StacktraceLoggerWrapper.getLogger(HistoryEvent.class); private static final Logger log = StacktraceLoggerWrapper.Companion.getLogger(HistoryEvent.class);
private int eventYear; private int eventYear;
private int eventMonth; private int eventMonth;

View file

@ -705,7 +705,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
} }
if (tbrCurrent != null && !enforceNew) { if (tbrCurrent != null && !enforceNew) {
if (Round.isSame(tbrCurrent.getRate(), absoluteRate)) { if (Round.INSTANCE.isSame(tbrCurrent.getRate(), absoluteRate)) {
aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting."); aapsLogger.info(LTag.PUMP, "setTempBasalAbsolute - No enforceNew and same rate. Exiting.");
return new PumpEnactResult(getInjector()).success(true).enacted(false); return new PumpEnactResult(getInjector()).success(true).enacted(false);
} }

View file

@ -200,7 +200,7 @@ public abstract class RileyLinkCommunicationManager<T extends RLMessage> {
double[] scanFrequencies = rileyLinkServiceData.rileyLinkTargetFrequency.getScanFrequencies(); double[] scanFrequencies = rileyLinkServiceData.rileyLinkTargetFrequency.getScanFrequencies();
if (scanFrequencies.length == 1) { if (scanFrequencies.length == 1) {
return Round.isSame(scanFrequencies[0], frequency); return Round.INSTANCE.isSame(scanFrequencies[0], frequency);
} else { } else {
return (scanFrequencies[0] <= frequency && scanFrequencies[scanFrequencies.length - 1] >= frequency); return (scanFrequencies[0] <= frequency && scanFrequencies[scanFrequencies.length - 1] >= frequency);
} }

View file

@ -103,7 +103,8 @@ public class InitializePumpManagerTask extends ServiceTask {
} }
} else { } else {
if (!Round.isSame(lastGoodFrequency, RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0])) { if (!Round.INSTANCE.isSame(lastGoodFrequency,
RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0])) {
lastGoodFrequency = RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0]; lastGoodFrequency = RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0];
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d; lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;

View file

@ -1,12 +1,9 @@
package info.nightscout.shared package info.nightscout.shared
import java.lang.Exception
object SafeParse { object SafeParse {
// TODO return logging with dagger
// private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class); // private static Logger log = StacktraceLoggerWrapper.getLogger(SafeParse.class);
@JvmStatic fun stringToDouble(inputString: String?): Double { fun stringToDouble(inputString: String?): Double {
var input = inputString ?: return 0.0 var input = inputString ?: return 0.0
var result = 0.0 var result = 0.0
input = input.replace(",", ".") input = input.replace(",", ".")
@ -20,7 +17,7 @@ object SafeParse {
return result return result
} }
@JvmStatic fun stringToFloat(inputString: String?): Float { fun stringToFloat(inputString: String?): Float {
var input = inputString ?: return 0f var input = inputString ?: return 0f
var result = 0f var result = 0f
input = input.replace(",", ".") input = input.replace(",", ".")
@ -34,7 +31,7 @@ object SafeParse {
return result return result
} }
@JvmStatic fun stringToInt(inputString: String?): Int { fun stringToInt(inputString: String?): Int {
var input = inputString ?: return 0 var input = inputString ?: return 0
var result = 0 var result = 0
input = input.replace(",", ".") input = input.replace(",", ".")

View file

@ -32,7 +32,7 @@ class StacktraceLoggerWrapper(private val delegate: Logger) : Logger by delegate
// all other methods will be implemented by delegate // all other methods will be implemented by delegate
companion object { companion object {
@JvmStatic
@Deprecated("please inject AAPSLogger") @Deprecated("please inject AAPSLogger")
fun getLogger(clazz: Class<*>) = StacktraceLoggerWrapper(LoggerFactory.getLogger(clazz)) fun getLogger(clazz: Class<*>) = StacktraceLoggerWrapper(LoggerFactory.getLogger(clazz))
} }