Eliminate @JvmStatic
This commit is contained in:
parent
dceca8d194
commit
211c86deb7
|
@ -182,7 +182,7 @@ public class TimeListEdit {
|
|||
numberPickers1[position].setTextWatcher(new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
Double value1 = SafeParse.stringToDouble(numberPickers1[position].getText());
|
||||
Double value1 = SafeParse.INSTANCE.stringToDouble(numberPickers1[position].getText());
|
||||
Double value2 = value2(position);
|
||||
if (data2 != null && value1 > value2) {
|
||||
value2 = value1;
|
||||
|
@ -209,7 +209,7 @@ public class TimeListEdit {
|
|||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
Double value1 = value1(position);
|
||||
Double value2 = SafeParse.stringToDouble(numberPickers2[position].getText());
|
||||
Double value2 = SafeParse.INSTANCE.stringToDouble(numberPickers2[position].getText());
|
||||
if (data2 != null && value2 < value1) {
|
||||
value1 = value2;
|
||||
numberPickers1[position].setValue(value1);
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.dialogs.ErrorDialog
|
|||
import info.nightscout.androidaps.dialogs.NtpProgressDialog
|
||||
import info.nightscout.androidaps.dialogs.ProfileViewerDialog
|
||||
import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity
|
||||
import info.nightscout.androidaps.utils.ui.SingleClickButton
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
|
@ -25,4 +26,6 @@ abstract class CoreFragmentsModule {
|
|||
@ContributesAndroidInjector abstract fun contributesNtpProgressDialog(): NtpProgressDialog
|
||||
@ContributesAndroidInjector abstract fun contributesProfileViewerDialog(): ProfileViewerDialog
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesSingleClickButton(): SingleClickButton
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.math.BigDecimal
|
|||
import kotlin.math.abs
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.round
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
/**
|
||||
|
@ -12,22 +11,18 @@ import kotlin.math.roundToLong
|
|||
*/
|
||||
object Round {
|
||||
|
||||
@JvmStatic
|
||||
fun roundTo(x: Double, step: Double): Double =
|
||||
if (x == 0.0) 0.0
|
||||
else BigDecimal.valueOf((x / step).roundToLong()).multiply(BigDecimal.valueOf(step)).toDouble()
|
||||
|
||||
@JvmStatic
|
||||
fun floorTo(x: Double, step: Double): Double =
|
||||
if (x != 0.0) floor(x / step) * step
|
||||
else 0.0
|
||||
|
||||
@JvmStatic
|
||||
fun ceilTo(x: Double, step: Double): Double =
|
||||
if (x != 0.0) ceil(x / step) * step
|
||||
else 0.0
|
||||
|
||||
@JvmStatic
|
||||
fun isSame(d1: Double, d2: Double): Boolean =
|
||||
abs(d1 - d2) <= 0.000001
|
||||
}
|
|
@ -2,25 +2,32 @@ package info.nightscout.androidaps.utils.ui
|
|||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.shared.logging.StacktraceLoggerWrapper
|
||||
import org.slf4j.Logger
|
||||
import info.nightscout.shared.logging.AAPSLogger
|
||||
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 callOnClick(): Boolean = guardClick { super.callOnClick() }
|
||||
|
||||
private fun guardClick(block: () -> Boolean): Boolean {
|
||||
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()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private val log: Logger = StacktraceLoggerWrapper.getLogger(SingleClickButton::class.java)
|
||||
|
||||
companion object {
|
||||
|
||||
const val BUTTON_REFRACTION_PERIOD = 3000L
|
||||
}
|
||||
}
|
|
@ -232,8 +232,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
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.
|
||||
if (absoluteRate < 0.10d) percentRate = 0;
|
||||
if (percentRate < 100) percentRate = (int) Round.ceilTo((double) percentRate, 10d);
|
||||
else percentRate = (int) Round.floorTo((double) percentRate, 10d);
|
||||
if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo((double) percentRate, 10d);
|
||||
else percentRate = (int) Round.INSTANCE.floorTo((double) percentRate, 10d);
|
||||
if (percentRate > 500) // Special high temp 500/15min
|
||||
percentRate = 500;
|
||||
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();
|
||||
// needs to be rounded
|
||||
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());
|
||||
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < pumpDescription.getExtendedBolusStep()) {
|
||||
|
|
|
@ -267,7 +267,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
|
|||
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
|
||||
// needs to be rounded
|
||||
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());
|
||||
if (danaPump.isExtendedInProgress() && Math.abs(danaPump.getExtendedBolusAmount() - insulin) < getPumpDescription().getExtendedBolusStep()) {
|
||||
|
|
|
@ -217,8 +217,8 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
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.
|
||||
if (absoluteRate < 0.10d) percentRate = 0;
|
||||
if (percentRate < 100) percentRate = (int) Round.ceilTo((double) percentRate, 10d);
|
||||
else percentRate = (int) Round.floorTo((double) percentRate, 10d);
|
||||
if (percentRate < 100) percentRate = (int) Round.INSTANCE.ceilTo((double) percentRate, 10d);
|
||||
else percentRate = (int) Round.INSTANCE.floorTo((double) percentRate, 10d);
|
||||
if (percentRate > getPumpDescription().getMaxTempPercent()) {
|
||||
percentRate = getPumpDescription().getMaxTempPercent();
|
||||
}
|
||||
|
@ -288,7 +288,8 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
||||
extendedRateToSet = constraintChecker.applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value();
|
||||
// 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?
|
||||
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (danaPump.isExtendedInProgress()) + " rate: " + danaPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaPump.getExtendedBolusRemainingMinutes() + "min");
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.slf4j.Logger;
|
|||
|
||||
public class HistoryEvent implements Comparable<HistoryEvent> {
|
||||
@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 eventMonth;
|
||||
|
|
|
@ -705,7 +705,7 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
|
|||
}
|
||||
|
||||
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.");
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(false);
|
||||
}
|
||||
|
|
|
@ -200,7 +200,7 @@ public abstract class RileyLinkCommunicationManager<T extends RLMessage> {
|
|||
double[] scanFrequencies = rileyLinkServiceData.rileyLinkTargetFrequency.getScanFrequencies();
|
||||
|
||||
if (scanFrequencies.length == 1) {
|
||||
return Round.isSame(scanFrequencies[0], frequency);
|
||||
return Round.INSTANCE.isSame(scanFrequencies[0], frequency);
|
||||
} else {
|
||||
return (scanFrequencies[0] <= frequency && scanFrequencies[scanFrequencies.length - 1] >= frequency);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,8 @@ public class InitializePumpManagerTask extends ServiceTask {
|
|||
}
|
||||
} else {
|
||||
|
||||
if (!Round.isSame(lastGoodFrequency, RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0])) {
|
||||
if (!Round.INSTANCE.isSame(lastGoodFrequency,
|
||||
RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0])) {
|
||||
lastGoodFrequency = RileyLinkTargetFrequency.Omnipod.getScanFrequencies()[0];
|
||||
lastGoodFrequency = Math.round(lastGoodFrequency * 1000d) / 1000d;
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package info.nightscout.shared
|
||||
|
||||
import java.lang.Exception
|
||||
|
||||
object SafeParse {
|
||||
|
||||
// TODO return logging with dagger
|
||||
// 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 result = 0.0
|
||||
input = input.replace(",", ".")
|
||||
|
@ -20,7 +17,7 @@ object SafeParse {
|
|||
return result
|
||||
}
|
||||
|
||||
@JvmStatic fun stringToFloat(inputString: String?): Float {
|
||||
fun stringToFloat(inputString: String?): Float {
|
||||
var input = inputString ?: return 0f
|
||||
var result = 0f
|
||||
input = input.replace(",", ".")
|
||||
|
@ -34,7 +31,7 @@ object SafeParse {
|
|||
return result
|
||||
}
|
||||
|
||||
@JvmStatic fun stringToInt(inputString: String?): Int {
|
||||
fun stringToInt(inputString: String?): Int {
|
||||
var input = inputString ?: return 0
|
||||
var result = 0
|
||||
input = input.replace(",", ".")
|
||||
|
|
|
@ -32,7 +32,7 @@ class StacktraceLoggerWrapper(private val delegate: Logger) : Logger by delegate
|
|||
// all other methods will be implemented by delegate
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
|
||||
@Deprecated("please inject AAPSLogger")
|
||||
fun getLogger(clazz: Class<*>) = StacktraceLoggerWrapper(LoggerFactory.getLogger(clazz))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue