Constraints, Dialogs daggerize
This commit is contained in:
parent
dc037cc248
commit
7f8abcf591
52 changed files with 808 additions and 578 deletions
|
@ -27,7 +27,6 @@ import javax.inject.Inject;
|
||||||
|
|
||||||
import dagger.android.AndroidInjector;
|
import dagger.android.AndroidInjector;
|
||||||
import dagger.android.DaggerApplication;
|
import dagger.android.DaggerApplication;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent;
|
import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent;
|
||||||
|
@ -112,7 +111,6 @@ public class MainApp extends DaggerApplication {
|
||||||
static FirebaseAnalytics mFirebaseAnalytics;
|
static FirebaseAnalytics mFirebaseAnalytics;
|
||||||
|
|
||||||
static DatabaseHelper sDatabaseHelper = null;
|
static DatabaseHelper sDatabaseHelper = null;
|
||||||
static ConstraintChecker sConstraintsChecker = null;
|
|
||||||
|
|
||||||
static ArrayList<PluginBase> pluginsList = null;
|
static ArrayList<PluginBase> pluginsList = null;
|
||||||
|
|
||||||
|
@ -138,7 +136,6 @@ public class MainApp extends DaggerApplication {
|
||||||
sInstance = this;
|
sInstance = this;
|
||||||
sResources = getResources();
|
sResources = getResources();
|
||||||
LocaleHelper.INSTANCE.update(this);
|
LocaleHelper.INSTANCE.update(this);
|
||||||
sConstraintsChecker = new ConstraintChecker();
|
|
||||||
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
||||||
|
|
||||||
Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> {
|
Thread.setDefaultUncaughtExceptionHandler((thread, ex) -> {
|
||||||
|
@ -258,7 +255,6 @@ public class MainApp extends DaggerApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void doMigrations() {
|
private void doMigrations() {
|
||||||
|
|
||||||
// guarantee that the unreachable threshold is at least 30 and of type String
|
// guarantee that the unreachable threshold is at least 30 and of type String
|
||||||
|
@ -345,10 +341,6 @@ public class MainApp extends DaggerApplication {
|
||||||
return mFirebaseAnalytics;
|
return mFirebaseAnalytics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConstraintChecker getConstraintChecker() {
|
|
||||||
return sConstraintsChecker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArrayList<PluginBase> getPluginsList() {
|
public static ArrayList<PluginBase> getPluginsList() {
|
||||||
return pluginsList;
|
return pluginsList;
|
||||||
}
|
}
|
||||||
|
@ -382,7 +374,7 @@ public class MainApp extends DaggerApplication {
|
||||||
return newList;
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
public ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
||||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||||
|
|
||||||
if (pluginsList != null) {
|
if (pluginsList != null) {
|
||||||
|
|
|
@ -1,237 +0,0 @@
|
||||||
package info.nightscout.androidaps.data;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
|
||||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 19.03.2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ConstraintChecker implements ConstraintsInterface {
|
|
||||||
|
|
||||||
public Constraint<Boolean> isLoopInvokationAllowed() {
|
|
||||||
return isLoopInvocationAllowed(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isClosedLoopAllowed() {
|
|
||||||
return isClosedLoopAllowed(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isAutosensModeEnabled() {
|
|
||||||
return isAutosensModeEnabled(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isAMAModeEnabled() {
|
|
||||||
return isAMAModeEnabled(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isSMBModeEnabled() {
|
|
||||||
return isSMBModeEnabled(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isUAMEnabled() {
|
|
||||||
return isUAMEnabled(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isAdvancedFilteringEnabled() {
|
|
||||||
return isAdvancedFilteringEnabled(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Boolean> isSuperBolusEnabled() {
|
|
||||||
return isSuperBolusEnabled(new Constraint<>(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Double> getMaxBasalAllowed(Profile profile) {
|
|
||||||
return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Integer> getMaxBasalPercentAllowed(Profile profile) {
|
|
||||||
return applyBasalPercentConstraints(new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE), profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Double> getMaxBolusAllowed() {
|
|
||||||
return applyBolusConstraints(new Constraint<>(Constants.REALLYHIGHBOLUS));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Double> getMaxExtendedBolusAllowed() {
|
|
||||||
return applyExtendedBolusConstraints(new Constraint<>(Constants.REALLYHIGHBOLUS));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Integer> getMaxCarbsAllowed() {
|
|
||||||
return applyCarbsConstraints(new Constraint<>(Constants.REALLYHIGHCARBS));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Constraint<Double> getMaxIOBAllowed() {
|
|
||||||
return applyMaxIOBConstraints(new Constraint<>(Constants.REALLYHIGHIOB));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isLoopInvocationAllowed(@NonNull Constraint<Boolean> value) {
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isLoopInvocationAllowed(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isClosedLoopAllowed(@NonNull Constraint<Boolean> value) {
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isClosedLoopAllowed(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isAutosensModeEnabled(@NonNull Constraint<Boolean> value) {
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isAutosensModeEnabled(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isAMAModeEnabled(@NonNull Constraint<Boolean> value) {
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constrain.isAMAModeEnabled(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isSMBModeEnabled(@NonNull Constraint<Boolean> value) {
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isSMBModeEnabled(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isUAMEnabled(@NonNull Constraint<Boolean> value) {
|
|
||||||
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isUAMEnabled(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isAdvancedFilteringEnabled(@NonNull Constraint<Boolean> value) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isAdvancedFilteringEnabled(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Boolean> isSuperBolusEnabled(@NonNull Constraint<Boolean> value) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.isSuperBolusEnabled(value);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Double> applyBasalConstraints(@NonNull Constraint<Double> absoluteRate, Profile profile) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constraint.applyBasalConstraints(absoluteRate, profile);
|
|
||||||
}
|
|
||||||
return absoluteRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Integer> applyBasalPercentConstraints(@NonNull Constraint<Integer> percentRate, Profile profile) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constrain.applyBasalPercentConstraints(percentRate, profile);
|
|
||||||
}
|
|
||||||
return percentRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Double> applyBolusConstraints(@NonNull Constraint<Double> insulin) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constrain.applyBolusConstraints(insulin);
|
|
||||||
}
|
|
||||||
return insulin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Double> applyExtendedBolusConstraints(@NonNull Constraint<Double> insulin) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constrain.applyExtendedBolusConstraints(insulin);
|
|
||||||
}
|
|
||||||
return insulin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Integer> applyCarbsConstraints(@NonNull Constraint<Integer> carbs) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constrain.applyCarbsConstraints(carbs);
|
|
||||||
}
|
|
||||||
return carbs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Constraint<Double> applyMaxIOBConstraints(@NonNull Constraint<Double> maxIob) {
|
|
||||||
ArrayList<PluginBase> constraintsPlugins = MainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
|
||||||
for (PluginBase p : constraintsPlugins) {
|
|
||||||
ConstraintsInterface constrain = (ConstraintsInterface) p;
|
|
||||||
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
|
||||||
constrain.applyMaxIOBConstraints(maxIob);
|
|
||||||
}
|
|
||||||
return maxIob;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,6 +7,7 @@ import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS
|
import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS
|
||||||
|
@ -33,6 +34,12 @@ class AppModule {
|
||||||
return ProfileFunctionImplementation(sp)
|
return ProfileFunctionImplementation(sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
fun provideConstraintChecker(mainApp: MainApp): ConstraintChecker {
|
||||||
|
return ConstraintChecker(mainApp)
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideResources(mainApp: MainApp): ResourceHelper {
|
fun provideResources(mainApp: MainApp): ResourceHelper {
|
||||||
|
|
|
@ -3,13 +3,51 @@ package info.nightscout.androidaps.dependencyInjection
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
import info.nightscout.androidaps.activities.MyPreferenceFragment
|
import info.nightscout.androidaps.activities.MyPreferenceFragment
|
||||||
|
import info.nightscout.androidaps.dialogs.*
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorFragment
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorFragment
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
abstract class FragmentsModule {
|
abstract class FragmentsModule {
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract fun contributesPreferencesFragment(): MyPreferenceFragment
|
abstract fun contributesPreferencesFragment(): MyPreferenceFragment
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment
|
abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesCalibrationDialog(): CalibrationDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesCarbsDialog(): CarbsDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesCareDialog(): CareDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesExtendedBolusDialog(): ExtendedBolusDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesFillDialog(): FillDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesInsulinDialog(): InsulinDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesProfileSwitchDialog(): ProfileSwitchDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesProfileViewerDialog(): ProfileViewerDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesTempBasalDialog(): TempBasalDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesTempTargetDialog(): TempTargetDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesTreatmentDialog(): TreatmentDialog
|
||||||
|
|
||||||
|
@ContributesAndroidInjector
|
||||||
|
abstract fun contributesWizardDialog(): WizardDialog
|
||||||
}
|
}
|
|
@ -6,21 +6,28 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.google.common.base.Joiner
|
import com.google.common.base.Joiner
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
import info.nightscout.androidaps.utils.XdripCalibrations
|
import info.nightscout.androidaps.utils.XdripCalibrations
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_calibration.*
|
import kotlinx.android.synthetic.main.dialog_calibration.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CalibrationDialog : DialogFragmentWithDate() {
|
class CalibrationDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var profileFunction: ProfileFunction
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("overview_calibration_bg", overview_calibration_bg.value)
|
savedInstanceState.putDouble("overview_calibration_bg", overview_calibration_bg.value)
|
||||||
|
@ -35,7 +42,7 @@ class CalibrationDialog : DialogFragmentWithDate() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = profileFunction.getUnits()
|
||||||
val bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData()?.glucose
|
val bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData()?.glucose
|
||||||
?: 0.0, units)
|
?: 0.0, units)
|
||||||
if (units == Constants.MMOL)
|
if (units == Constants.MMOL)
|
||||||
|
@ -44,24 +51,24 @@ class CalibrationDialog : DialogFragmentWithDate() {
|
||||||
else
|
else
|
||||||
overview_calibration_bg.setParams(savedInstanceState?.getDouble("overview_calibration_bg")
|
overview_calibration_bg.setParams(savedInstanceState?.getDouble("overview_calibration_bg")
|
||||||
?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, ok)
|
?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, ok)
|
||||||
overview_calibration_units.text = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
|
overview_calibration_units.text = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun submit(): Boolean {
|
override fun submit(): Boolean {
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = profileFunction.getUnits()
|
||||||
val unitLabel = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
|
val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
|
||||||
val actions: LinkedList<String?> = LinkedList()
|
val actions: LinkedList<String?> = LinkedList()
|
||||||
val bg = overview_calibration_bg.value
|
val bg = overview_calibration_bg.value
|
||||||
actions.add(MainApp.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(bg) + " " + unitLabel)
|
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(bg) + " " + unitLabel)
|
||||||
if (bg > 0) {
|
if (bg > 0) {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.overview_calibration), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_calibration), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
XdripCalibrations.confirmAndSendCalibration(bg, context)
|
XdripCalibrations.confirmAndSendCalibration(bg, context)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.show(activity, MainApp.gs(R.string.overview_calibration), MainApp.gs(R.string.no_action_selected))
|
OKDialog.show(activity, resourceHelper.gs(R.string.overview_calibration), resourceHelper.gs(R.string.no_action_selected))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,28 +16,38 @@ import info.nightscout.androidaps.db.DatabaseHelper
|
||||||
import info.nightscout.androidaps.db.Source
|
import info.nightscout.androidaps.db.Source
|
||||||
import info.nightscout.androidaps.db.TempTarget
|
import info.nightscout.androidaps.db.TempTarget
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.plugins.treatments.CarbsGenerator
|
import info.nightscout.androidaps.plugins.treatments.CarbsGenerator
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.*
|
import info.nightscout.androidaps.utils.*
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_carbs.*
|
import kotlinx.android.synthetic.main.dialog_carbs.*
|
||||||
import kotlinx.android.synthetic.main.notes.*
|
import kotlinx.android.synthetic.main.notes.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
class CarbsDialog : DialogFragmentWithDate() {
|
class CarbsDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val FAV1_DEFAULT = 5
|
private const val FAV1_DEFAULT = 5
|
||||||
private const val FAV2_DEFAULT = 10
|
private const val FAV2_DEFAULT = 10
|
||||||
private const val FAV3_DEFAULT = 20
|
private const val FAV3_DEFAULT = 20
|
||||||
}
|
}
|
||||||
|
|
||||||
private val maxCarbs = MainApp.getConstraintChecker().maxCarbsAllowed.value().toDouble()
|
|
||||||
|
|
||||||
private val textWatcher: TextWatcher = object : TextWatcher {
|
private val textWatcher: TextWatcher = object : TextWatcher {
|
||||||
override fun afterTextChanged(s: Editable) {
|
override fun afterTextChanged(s: Editable) {
|
||||||
validateInputs()
|
validateInputs()
|
||||||
|
@ -48,18 +58,19 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateInputs() {
|
private fun validateInputs() {
|
||||||
|
val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble()
|
||||||
val time = overview_carbs_time.value.toInt()
|
val time = overview_carbs_time.value.toInt()
|
||||||
if (time > 12 * 60 || time < -12 * 60) {
|
if (time > 12 * 60 || time < -12 * 60) {
|
||||||
overview_carbs_time.value = 0.0
|
overview_carbs_time.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.constraintapllied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.constraintapllied))
|
||||||
}
|
}
|
||||||
if (overview_carbs_duration.value > 10) {
|
if (overview_carbs_duration.value > 10) {
|
||||||
overview_carbs_duration.value = 0.0
|
overview_carbs_duration.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.constraintapllied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.constraintapllied))
|
||||||
}
|
}
|
||||||
if (overview_carbs_carbs.value.toInt() > maxCarbs) {
|
if (overview_carbs_carbs.value.toInt() > maxCarbs) {
|
||||||
overview_carbs_carbs.value = 0.0
|
overview_carbs_carbs.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.carbsconstraintapplied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.carbsconstraintapplied))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +90,7 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble()
|
||||||
overview_carbs_time.setParams(savedInstanceState?.getDouble("overview_carbs_time")
|
overview_carbs_time.setParams(savedInstanceState?.getDouble("overview_carbs_time")
|
||||||
?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
||||||
|
|
||||||
|
@ -133,7 +145,7 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
override fun submit(): Boolean {
|
override fun submit(): Boolean {
|
||||||
val carbs = overview_carbs_carbs.value.toInt()
|
val carbs = overview_carbs_carbs.value.toInt()
|
||||||
val carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(carbs)).value()
|
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value()
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = ProfileFunctions.getSystemUnits()
|
||||||
val activityTTDuration = DefaultValueHelper.determineActivityTTDuration()
|
val activityTTDuration = DefaultValueHelper.determineActivityTTDuration()
|
||||||
val activityTT = DefaultValueHelper.determineActivityTT()
|
val activityTT = DefaultValueHelper.determineActivityTT()
|
||||||
|
@ -142,42 +154,42 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
val hypoTTDuration = DefaultValueHelper.determineHypoTTDuration()
|
val hypoTTDuration = DefaultValueHelper.determineHypoTTDuration()
|
||||||
val hypoTT = DefaultValueHelper.determineHypoTT()
|
val hypoTT = DefaultValueHelper.determineHypoTT()
|
||||||
val actions: LinkedList<String?> = LinkedList()
|
val actions: LinkedList<String?> = LinkedList()
|
||||||
val unitLabel = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
|
val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
|
||||||
|
|
||||||
val activitySelected = overview_carbs_activity_tt.isChecked
|
val activitySelected = overview_carbs_activity_tt.isChecked
|
||||||
if (activitySelected)
|
if (activitySelected)
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")</font>")
|
actions.add(resourceHelper.gs(R.string.temptargetshort) + ": " + "<font color='" + resourceHelper.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " " + resourceHelper.gs(R.string.unit_minute_short) + ")</font>")
|
||||||
val eatingSoonSelected = overview_carbs_eating_soon_tt.isChecked
|
val eatingSoonSelected = overview_carbs_eating_soon_tt.isChecked
|
||||||
if (eatingSoonSelected)
|
if (eatingSoonSelected)
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + eatingSoonTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")</font>")
|
actions.add(resourceHelper.gs(R.string.temptargetshort) + ": " + "<font color='" + resourceHelper.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + eatingSoonTTDuration + " " + resourceHelper.gs(R.string.unit_minute_short) + ")</font>")
|
||||||
val hypoSelected = overview_carbs_hypo_tt.isChecked
|
val hypoSelected = overview_carbs_hypo_tt.isChecked
|
||||||
if (hypoSelected)
|
if (hypoSelected)
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(hypoTT) + " " + unitLabel + " (" + hypoTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")</font>")
|
actions.add(resourceHelper.gs(R.string.temptargetshort) + ": " + "<font color='" + resourceHelper.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(hypoTT) + " " + unitLabel + " (" + hypoTTDuration + " " + resourceHelper.gs(R.string.unit_minute_short) + ")</font>")
|
||||||
|
|
||||||
val timeOffset = overview_carbs_time.value.toInt()
|
val timeOffset = overview_carbs_time.value.toInt()
|
||||||
val time = DateUtil.now() + timeOffset * 1000 * 60
|
val time = DateUtil.now() + timeOffset * 1000 * 60
|
||||||
if (timeOffset != 0)
|
if (timeOffset != 0)
|
||||||
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time))
|
actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time))
|
||||||
val duration = overview_carbs_duration.value.toInt()
|
val duration = overview_carbs_duration.value.toInt()
|
||||||
if (duration > 0)
|
if (duration > 0)
|
||||||
actions.add(MainApp.gs(R.string.duration) + ": " + duration + MainApp.gs(R.string.shorthour))
|
actions.add(resourceHelper.gs(R.string.duration) + ": " + duration + resourceHelper.gs(R.string.shorthour))
|
||||||
if (carbsAfterConstraints > 0) {
|
if (carbsAfterConstraints > 0) {
|
||||||
actions.add(MainApp.gs(R.string.carbs) + ": " + "<font color='" + MainApp.gc(R.color.carbs) + "'>" + MainApp.gs(R.string.format_carbs, carbsAfterConstraints) + "</font>")
|
actions.add(resourceHelper.gs(R.string.carbs) + ": " + "<font color='" + resourceHelper.gc(R.color.carbs) + "'>" + resourceHelper.gs(R.string.format_carbs, carbsAfterConstraints) + "</font>")
|
||||||
if (carbsAfterConstraints != carbs)
|
if (carbsAfterConstraints != carbs)
|
||||||
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.carbsconstraintapplied) + "</font>")
|
actions.add("<font color='" + resourceHelper.gc(R.color.warning) + "'>" + resourceHelper.gs(R.string.carbsconstraintapplied) + "</font>")
|
||||||
}
|
}
|
||||||
val notes = notes.text.toString()
|
val notes = notes.text.toString()
|
||||||
if (notes.isNotEmpty())
|
if (notes.isNotEmpty())
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
||||||
|
|
||||||
if (carbsAfterConstraints > 0 || activitySelected || eatingSoonSelected || hypoSelected) {
|
if (carbsAfterConstraints > 0 || activitySelected || eatingSoonSelected || hypoSelected) {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
if (activitySelected) {
|
if (activitySelected) {
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.duration(activityTTDuration)
|
.duration(activityTTDuration)
|
||||||
.reason(MainApp.gs(R.string.activity))
|
.reason(resourceHelper.gs(R.string.activity))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits()))
|
.low(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits()))
|
.high(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits()))
|
||||||
|
@ -186,7 +198,7 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.duration(eatingSoonTTDuration)
|
.duration(eatingSoonTTDuration)
|
||||||
.reason(MainApp.gs(R.string.eatingsoon))
|
.reason(resourceHelper.gs(R.string.eatingsoon))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
|
.low(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
|
.high(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
|
||||||
|
@ -195,7 +207,7 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.duration(hypoTTDuration)
|
.duration(hypoTTDuration)
|
||||||
.reason(MainApp.gs(R.string.hypo))
|
.reason(resourceHelper.gs(R.string.hypo))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits()))
|
.low(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits()))
|
||||||
.high(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits()))
|
.high(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits()))
|
||||||
|
@ -206,14 +218,14 @@ class CarbsDialog : DialogFragmentWithDate() {
|
||||||
CarbsGenerator.createCarb(carbsAfterConstraints, time, CareportalEvent.CARBCORRECTION, notes)
|
CarbsGenerator.createCarb(carbsAfterConstraints, time, CareportalEvent.CARBCORRECTION, notes)
|
||||||
} else {
|
} else {
|
||||||
CarbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes)
|
CarbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes)
|
||||||
NSUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, MainApp.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset))
|
NSUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.show(activity, MainApp.gs(R.string.carbs), MainApp.gs(R.string.no_action_selected))
|
OKDialog.show(activity, resourceHelper.gs(R.string.carbs), resourceHelper.gs(R.string.no_action_selected))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,15 +21,23 @@ import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
import info.nightscout.androidaps.utils.SP
|
import info.nightscout.androidaps.utils.SP
|
||||||
import info.nightscout.androidaps.utils.Translator
|
import info.nightscout.androidaps.utils.Translator
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_care.*
|
import kotlinx.android.synthetic.main.dialog_care.*
|
||||||
import kotlinx.android.synthetic.main.notes.*
|
import kotlinx.android.synthetic.main.notes.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CareDialog : DialogFragmentWithDate() {
|
class CareDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
enum class EventType {
|
enum class EventType {
|
||||||
BGCHECK,
|
BGCHECK,
|
||||||
SENSOR_INSERT,
|
SENSOR_INSERT,
|
||||||
|
@ -65,7 +73,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
EventType.SENSOR_INSERT -> R.drawable.icon_cp_cgm_insert
|
EventType.SENSOR_INSERT -> R.drawable.icon_cp_cgm_insert
|
||||||
EventType.BATTERY_CHANGE -> R.drawable.icon_cp_pump_battery
|
EventType.BATTERY_CHANGE -> R.drawable.icon_cp_pump_battery
|
||||||
})
|
})
|
||||||
actions_care_title.text = MainApp.gs(when (options) {
|
actions_care_title.text = resourceHelper.gs(when (options) {
|
||||||
EventType.BGCHECK -> R.string.careportal_bgcheck
|
EventType.BGCHECK -> R.string.careportal_bgcheck
|
||||||
EventType.SENSOR_INSERT -> R.string.careportal_cgmsensorinsert
|
EventType.SENSOR_INSERT -> R.string.careportal_cgmsensorinsert
|
||||||
EventType.BATTERY_CHANGE -> R.string.careportal_pumpbatterychange
|
EventType.BATTERY_CHANGE -> R.string.careportal_pumpbatterychange
|
||||||
|
@ -93,11 +101,11 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ProfileFunctions.getSystemUnits() == Constants.MMOL) {
|
if (ProfileFunctions.getSystemUnits() == Constants.MMOL) {
|
||||||
actions_care_bgunits.text = MainApp.gs(R.string.mmol)
|
actions_care_bgunits.text = resourceHelper.gs(R.string.mmol)
|
||||||
actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg")
|
actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg")
|
||||||
?: bg, 2.0, 30.0, 0.1, DecimalFormat("0.0"), false, ok, bgTextWatcher)
|
?: bg, 2.0, 30.0, 0.1, DecimalFormat("0.0"), false, ok, bgTextWatcher)
|
||||||
} else {
|
} else {
|
||||||
actions_care_bgunits.text = MainApp.gs(R.string.mgdl)
|
actions_care_bgunits.text = resourceHelper.gs(R.string.mgdl)
|
||||||
actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg")
|
actions_care_bg.setParams(savedInstanceState?.getDouble("actions_care_bg")
|
||||||
?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, ok, bgTextWatcher)
|
?: bg, 36.0, 500.0, 1.0, DecimalFormat("0"), false, ok, bgTextWatcher)
|
||||||
}
|
}
|
||||||
|
@ -116,18 +124,18 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
actions_care_sensor.isChecked -> "Sensor"
|
actions_care_sensor.isChecked -> "Sensor"
|
||||||
else -> "Manual"
|
else -> "Manual"
|
||||||
}
|
}
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + Translator.translate(type))
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_glucosetype) + ": " + Translator.translate(type))
|
||||||
actions.add(MainApp.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(actions_care_bg.value) + " " + MainApp.gs(unitResId))
|
actions.add(resourceHelper.gs(R.string.treatments_wizard_bg_label) + ": " + Profile.toCurrentUnitsString(actions_care_bg.value) + " " + resourceHelper.gs(unitResId))
|
||||||
json.put("glucose", actions_care_bg.value)
|
json.put("glucose", actions_care_bg.value)
|
||||||
json.put("glucoseType", type)
|
json.put("glucoseType", type)
|
||||||
}
|
}
|
||||||
val notes = notes.text.toString()
|
val notes = notes.text.toString()
|
||||||
if (notes.isNotEmpty()) {
|
if (notes.isNotEmpty()) {
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
||||||
json.put("notes", notes)
|
json.put("notes", notes)
|
||||||
}
|
}
|
||||||
if (eventTimeChanged)
|
if (eventTimeChanged)
|
||||||
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
||||||
|
|
||||||
json.put("created_at", DateUtil.toISOString(eventTime))
|
json.put("created_at", DateUtil.toISOString(eventTime))
|
||||||
json.put("eventType", when (options) {
|
json.put("eventType", when (options) {
|
||||||
|
@ -140,7 +148,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
json.put("enteredBy", enteredBy)
|
json.put("enteredBy", enteredBy)
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(event), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(json)
|
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(json)
|
||||||
NSUpload.uploadCareportalEntryToNS(json)
|
NSUpload.uploadCareportalEntryToNS(json)
|
||||||
}, null)
|
}, null)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.fragment.app.DialogFragment
|
import dagger.android.support.DaggerDialogFragment
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.SP
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
@ -19,7 +19,7 @@ import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class DialogFragmentWithDate : DialogFragment() {
|
abstract class DialogFragmentWithDate : DaggerDialogFragment() {
|
||||||
private val log = LoggerFactory.getLogger(DialogFragmentWithDate::class.java)
|
private val log = LoggerFactory.getLogger(DialogFragmentWithDate::class.java)
|
||||||
|
|
||||||
var eventTime = DateUtil.now()
|
var eventTime = DateUtil.now()
|
||||||
|
|
|
@ -11,18 +11,30 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
import info.nightscout.androidaps.utils.SafeParse
|
import info.nightscout.androidaps.utils.SafeParse
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_extendedbolus.*
|
import kotlinx.android.synthetic.main.dialog_extendedbolus.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class ExtendedBolusDialog : DialogFragmentWithDate() {
|
class ExtendedBolusDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("actions_extendedbolus_insulin", actions_extendedbolus_insulin.value)
|
savedInstanceState.putDouble("actions_extendedbolus_insulin", actions_extendedbolus_insulin.value)
|
||||||
|
@ -40,7 +52,7 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
||||||
|
|
||||||
val maxInsulin = MainApp.getConstraintChecker().maxExtendedBolusAllowed.value()
|
val maxInsulin = constraintChecker.getMaxExtendedBolusAllowed().value()
|
||||||
val extendedStep = pumpDescription.extendedBolusStep
|
val extendedStep = pumpDescription.extendedBolusStep
|
||||||
actions_extendedbolus_insulin.setParams(savedInstanceState?.getDouble("actions_extendedbolus_insulin")
|
actions_extendedbolus_insulin.setParams(savedInstanceState?.getDouble("actions_extendedbolus_insulin")
|
||||||
?: extendedStep, extendedStep, maxInsulin, extendedStep, DecimalFormat("0.00"), false, ok)
|
?: extendedStep, extendedStep, maxInsulin, extendedStep, DecimalFormat("0.00"), false, ok)
|
||||||
|
@ -55,23 +67,23 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
|
||||||
val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin.text)
|
val insulin = SafeParse.stringToDouble(actions_extendedbolus_insulin.text)
|
||||||
val durationInMinutes = SafeParse.stringToInt(actions_extendedbolus_duration.text)
|
val durationInMinutes = SafeParse.stringToInt(actions_extendedbolus_duration.text)
|
||||||
val actions: LinkedList<String> = LinkedList()
|
val actions: LinkedList<String> = LinkedList()
|
||||||
val insulinAfterConstraint = MainApp.getConstraintChecker().applyExtendedBolusConstraints(Constraint(insulin)).value()
|
val insulinAfterConstraint = constraintChecker.applyExtendedBolusConstraints(Constraint(insulin)).value()
|
||||||
actions.add(MainApp.gs(R.string.formatinsulinunits, insulinAfterConstraint))
|
actions.add(resourceHelper.gs(R.string.formatinsulinunits, insulinAfterConstraint))
|
||||||
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
|
actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_mins, durationInMinutes))
|
||||||
if (abs(insulinAfterConstraint - insulin) > 0.01)
|
if (abs(insulinAfterConstraint - insulin) > 0.01)
|
||||||
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.constraintapllied) + "</font>")
|
actions.add("<font color='" + resourceHelper.gc(R.color.warning) + "'>" + resourceHelper.gs(R.string.constraintapllied) + "</font>")
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.extended_bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() {
|
ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(insulinAfterConstraint, durationInMinutes, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
|
val i = Intent(mainApp, ErrorHelperActivity::class.java)
|
||||||
i.putExtra("soundid", R.raw.boluserror)
|
i.putExtra("soundid", R.raw.boluserror)
|
||||||
i.putExtra("status", result.comment)
|
i.putExtra("status", result.comment)
|
||||||
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
|
i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror))
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
MainApp.instance().startActivity(i)
|
mainApp.startActivity(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,17 +14,37 @@ import info.nightscout.androidaps.db.CareportalEvent
|
||||||
import info.nightscout.androidaps.db.Source
|
import info.nightscout.androidaps.db.Source
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.*
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
|
import info.nightscout.androidaps.utils.SafeParse
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import kotlinx.android.synthetic.main.dialog_fill.*
|
import kotlinx.android.synthetic.main.dialog_fill.*
|
||||||
import kotlinx.android.synthetic.main.notes.*
|
import kotlinx.android.synthetic.main.notes.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class FillDialog : DialogFragmentWithDate() {
|
class FillDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var sp: SP
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("fill_insulinamount", fill_insulinamount.value)
|
savedInstanceState.putDouble("fill_insulinamount", fill_insulinamount.value)
|
||||||
|
@ -39,11 +59,11 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val maxInsulin = MainApp.getConstraintChecker().maxBolusAllowed.value()
|
val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
|
||||||
val bolusStep = ConfigBuilderPlugin.getPlugin().activePump!!.pumpDescription.bolusStep
|
val bolusStep = ConfigBuilderPlugin.getPlugin().activePump!!.pumpDescription.bolusStep
|
||||||
fill_insulinamount.setParams(savedInstanceState?.getDouble("fill_insulinamount")
|
fill_insulinamount.setParams(savedInstanceState?.getDouble("fill_insulinamount")
|
||||||
?: 0.0, 0.0, maxInsulin, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), true, ok)
|
?: 0.0, 0.0, maxInsulin, bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), true, ok)
|
||||||
val amount1 = SP.getDouble("fill_button1", 0.3)
|
val amount1 = sp.getDouble("fill_button1", 0.3)
|
||||||
if (amount1 > 0) {
|
if (amount1 > 0) {
|
||||||
fill_preset_button1.visibility = View.VISIBLE
|
fill_preset_button1.visibility = View.VISIBLE
|
||||||
fill_preset_button1.text = DecimalFormatter.toPumpSupportedBolus(amount1) // + "U");
|
fill_preset_button1.text = DecimalFormatter.toPumpSupportedBolus(amount1) // + "U");
|
||||||
|
@ -51,7 +71,7 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
} else {
|
} else {
|
||||||
fill_preset_button1.visibility = View.GONE
|
fill_preset_button1.visibility = View.GONE
|
||||||
}
|
}
|
||||||
val amount2 = SP.getDouble("fill_button2", 0.0)
|
val amount2 = sp.getDouble("fill_button2", 0.0)
|
||||||
if (amount2 > 0) {
|
if (amount2 > 0) {
|
||||||
fill_preset_button2.visibility = View.VISIBLE
|
fill_preset_button2.visibility = View.VISIBLE
|
||||||
fill_preset_button2.text = DecimalFormatter.toPumpSupportedBolus(amount2) // + "U");
|
fill_preset_button2.text = DecimalFormatter.toPumpSupportedBolus(amount2) // + "U");
|
||||||
|
@ -59,7 +79,7 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
} else {
|
} else {
|
||||||
fill_preset_button2.visibility = View.GONE
|
fill_preset_button2.visibility = View.GONE
|
||||||
}
|
}
|
||||||
val amount3 = SP.getDouble("fill_button3", 0.0)
|
val amount3 = sp.getDouble("fill_button3", 0.0)
|
||||||
if (amount3 > 0) {
|
if (amount3 > 0) {
|
||||||
fill_preset_button3.visibility = View.VISIBLE
|
fill_preset_button3.visibility = View.VISIBLE
|
||||||
fill_preset_button3.text = DecimalFormatter.toPumpSupportedBolus(amount3) // + "U");
|
fill_preset_button3.text = DecimalFormatter.toPumpSupportedBolus(amount3) // + "U");
|
||||||
|
@ -74,29 +94,29 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
val insulin = SafeParse.stringToDouble(fill_insulinamount.text)
|
val insulin = SafeParse.stringToDouble(fill_insulinamount.text)
|
||||||
val actions: LinkedList<String?> = LinkedList()
|
val actions: LinkedList<String?> = LinkedList()
|
||||||
|
|
||||||
val insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(insulin)).value()
|
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value()
|
||||||
if (insulinAfterConstraints > 0) {
|
if (insulinAfterConstraints > 0) {
|
||||||
actions.add(MainApp.gs(R.string.fillwarning))
|
actions.add(resourceHelper.gs(R.string.fillwarning))
|
||||||
actions.add("")
|
actions.add("")
|
||||||
actions.add(MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.colorInsulinButton) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + MainApp.gs(R.string.insulin_unit_shortname) + "</font>")
|
actions.add(resourceHelper.gs(R.string.bolus) + ": " + "<font color='" + resourceHelper.gc(R.color.colorInsulinButton) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + MainApp.gs(R.string.insulin_unit_shortname) + "</font>")
|
||||||
if (abs(insulinAfterConstraints - insulin) > 0.01)
|
if (abs(insulinAfterConstraints - insulin) > 0.01)
|
||||||
actions.add(MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), insulin, insulinAfterConstraints))
|
actions.add(resourceHelper.gs(R.string.bolusconstraintappliedwarning, resourceHelper.gc(R.color.warning), insulin, insulinAfterConstraints))
|
||||||
}
|
}
|
||||||
val siteChange = fill_catheter_change.isChecked
|
val siteChange = fill_catheter_change.isChecked
|
||||||
if (siteChange)
|
if (siteChange)
|
||||||
actions.add("" + "<font color='" + MainApp.gc(R.color.actionsConfirm) + "'>" + MainApp.gs(R.string.record_pump_site_change) + "</font>")
|
actions.add("" + "<font color='" + resourceHelper.gc(R.color.actionsConfirm) + "'>" + resourceHelper.gs(R.string.record_pump_site_change) + "</font>")
|
||||||
val insulinChange = fill_cartridge_change.isChecked
|
val insulinChange = fill_cartridge_change.isChecked
|
||||||
if (insulinChange)
|
if (insulinChange)
|
||||||
actions.add("" + "<font color='" + MainApp.gc(R.color.actionsConfirm) + "'>" + MainApp.gs(R.string.record_insulin_cartridge_change) + "</font>")
|
actions.add("" + "<font color='" + resourceHelper.gc(R.color.actionsConfirm) + "'>" + resourceHelper.gs(R.string.record_insulin_cartridge_change) + "</font>")
|
||||||
val notes = notes.text.toString()
|
val notes = notes.text.toString()
|
||||||
if (notes.isNotEmpty())
|
if (notes.isNotEmpty())
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
||||||
if (eventTimeChanged)
|
if (eventTimeChanged)
|
||||||
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
||||||
|
|
||||||
if (insulinAfterConstraints > 0 || fill_catheter_change.isChecked || fill_cartridge_change.isChecked) {
|
if (insulinAfterConstraints > 0 || fill_catheter_change.isChecked || fill_cartridge_change.isChecked) {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.primefill), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
if (insulinAfterConstraints > 0) {
|
if (insulinAfterConstraints > 0) {
|
||||||
val detailedBolusInfo = DetailedBolusInfo()
|
val detailedBolusInfo = DetailedBolusInfo()
|
||||||
detailedBolusInfo.insulin = insulinAfterConstraints
|
detailedBolusInfo.insulin = insulinAfterConstraints
|
||||||
|
@ -107,12 +127,12 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
|
val i = Intent(mainApp, ErrorHelperActivity::class.java)
|
||||||
i.putExtra("soundid", R.raw.boluserror)
|
i.putExtra("soundid", R.raw.boluserror)
|
||||||
i.putExtra("status", result.comment)
|
i.putExtra("status", result.comment)
|
||||||
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
|
i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror))
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
MainApp.instance().startActivity(i)
|
mainApp.startActivity(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -123,7 +143,7 @@ class FillDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.show(activity, MainApp.gs(R.string.primefill), MainApp.gs(R.string.no_action_selected))
|
OKDialog.show(activity, resourceHelper.gs(R.string.primefill), resourceHelper.gs(R.string.no_action_selected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
|
|
|
@ -19,28 +19,41 @@ import info.nightscout.androidaps.db.Source
|
||||||
import info.nightscout.androidaps.db.TempTarget
|
import info.nightscout.androidaps.db.TempTarget
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.*
|
import info.nightscout.androidaps.utils.*
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_insulin.*
|
import kotlinx.android.synthetic.main.dialog_insulin.*
|
||||||
import kotlinx.android.synthetic.main.notes.*
|
import kotlinx.android.synthetic.main.notes.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
class InsulinDialog : DialogFragmentWithDate() {
|
class InsulinDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var profileFunction: ProfileFunction
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PLUS1_DEFAULT = 0.5
|
private const val PLUS1_DEFAULT = 0.5
|
||||||
private const val PLUS2_DEFAULT = 1.0
|
private const val PLUS2_DEFAULT = 1.0
|
||||||
private const val PLUS3_DEFAULT = 2.0
|
private const val PLUS3_DEFAULT = 2.0
|
||||||
}
|
}
|
||||||
|
|
||||||
private val maxInsulin = MainApp.getConstraintChecker().maxBolusAllowed.value()
|
|
||||||
|
|
||||||
private val textWatcher: TextWatcher = object : TextWatcher {
|
private val textWatcher: TextWatcher = object : TextWatcher {
|
||||||
override fun afterTextChanged(s: Editable) {
|
override fun afterTextChanged(s: Editable) {
|
||||||
validateInputs()
|
validateInputs()
|
||||||
|
@ -51,13 +64,14 @@ class InsulinDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateInputs() {
|
private fun validateInputs() {
|
||||||
|
val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
|
||||||
if (abs(overview_insulin_time.value.toInt()) > 12 * 60) {
|
if (abs(overview_insulin_time.value.toInt()) > 12 * 60) {
|
||||||
overview_insulin_time.value = 0.0
|
overview_insulin_time.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.constraintapllied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.constraintapllied))
|
||||||
}
|
}
|
||||||
if (overview_insulin_amount.value > maxInsulin) {
|
if (overview_insulin_amount.value > maxInsulin) {
|
||||||
overview_insulin_amount.value = 0.0
|
overview_insulin_amount.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.bolusconstraintapplied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.bolusconstraintapplied))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,27 +90,29 @@ class InsulinDialog : DialogFragmentWithDate() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
|
||||||
|
|
||||||
overview_insulin_time.setParams(savedInstanceState?.getDouble("overview_insulin_time")
|
overview_insulin_time.setParams(savedInstanceState?.getDouble("overview_insulin_time")
|
||||||
?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
||||||
overview_insulin_amount.setParams(savedInstanceState?.getDouble("overview_insulin_amount")
|
overview_insulin_amount.setParams(savedInstanceState?.getDouble("overview_insulin_amount")
|
||||||
?: 0.0, 0.0, maxInsulin, ConfigBuilderPlugin.getPlugin().activePump!!.pumpDescription.bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), false, ok, textWatcher)
|
?: 0.0, 0.0, maxInsulin, ConfigBuilderPlugin.getPlugin().activePump!!.pumpDescription.bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), false, ok, textWatcher)
|
||||||
|
|
||||||
overview_insulin_plus05.text = toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT))
|
overview_insulin_plus05.text = toSignedString(SP.getDouble(resourceHelper.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT))
|
||||||
overview_insulin_plus05.setOnClickListener {
|
overview_insulin_plus05.setOnClickListener {
|
||||||
overview_insulin_amount.value = max(0.0, overview_insulin_amount.value
|
overview_insulin_amount.value = max(0.0, overview_insulin_amount.value
|
||||||
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT))
|
+ SP.getDouble(resourceHelper.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT))
|
||||||
validateInputs()
|
validateInputs()
|
||||||
}
|
}
|
||||||
overview_insulin_plus10.text = toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT))
|
overview_insulin_plus10.text = toSignedString(SP.getDouble(resourceHelper.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT))
|
||||||
overview_insulin_plus10.setOnClickListener {
|
overview_insulin_plus10.setOnClickListener {
|
||||||
overview_insulin_amount.value = max(0.0, overview_insulin_amount.value
|
overview_insulin_amount.value = max(0.0, overview_insulin_amount.value
|
||||||
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT))
|
+ SP.getDouble(resourceHelper.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT))
|
||||||
validateInputs()
|
validateInputs()
|
||||||
}
|
}
|
||||||
overview_insulin_plus20.text = toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT))
|
overview_insulin_plus20.text = toSignedString(SP.getDouble(resourceHelper.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT))
|
||||||
overview_insulin_plus20.setOnClickListener {
|
overview_insulin_plus20.setOnClickListener {
|
||||||
overview_insulin_amount.value = Math.max(0.0, overview_insulin_amount.value
|
overview_insulin_amount.value = Math.max(0.0, overview_insulin_amount.value
|
||||||
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT))
|
+ SP.getDouble(resourceHelper.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT))
|
||||||
validateInputs()
|
validateInputs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,45 +131,45 @@ class InsulinDialog : DialogFragmentWithDate() {
|
||||||
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription
|
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription
|
||||||
?: return false
|
?: return false
|
||||||
val insulin = SafeParse.stringToDouble(overview_insulin_amount.text)
|
val insulin = SafeParse.stringToDouble(overview_insulin_amount.text)
|
||||||
val insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(insulin)).value()
|
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value()
|
||||||
val actions: LinkedList<String?> = LinkedList()
|
val actions: LinkedList<String?> = LinkedList()
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = profileFunction.getUnits()
|
||||||
val unitLabel = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
|
val unitLabel = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
|
||||||
val recordOnlyChecked = overview_insulin_record_only.isChecked
|
val recordOnlyChecked = overview_insulin_record_only.isChecked
|
||||||
val eatingSoonChecked = overview_insulin_start_eating_soon_tt.isChecked
|
val eatingSoonChecked = overview_insulin_start_eating_soon_tt.isChecked
|
||||||
|
|
||||||
if (insulinAfterConstraints > 0) {
|
if (insulinAfterConstraints > 0) {
|
||||||
actions.add(MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + MainApp.gs(R.string.insulin_unit_shortname) + "</font>")
|
actions.add(resourceHelper.gs(R.string.bolus) + ": " + "<font color='" + resourceHelper.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + resourceHelper.gs(R.string.insulin_unit_shortname) + "</font>")
|
||||||
if (recordOnlyChecked)
|
if (recordOnlyChecked)
|
||||||
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>")
|
actions.add("<font color='" + resourceHelper.gc(R.color.warning) + "'>" + resourceHelper.gs(R.string.bolusrecordedonly) + "</font>")
|
||||||
if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints))
|
if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints))
|
||||||
actions.add(MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), insulin, insulinAfterConstraints))
|
actions.add(resourceHelper.gs(R.string.bolusconstraintappliedwarning, resourceHelper.gc(R.color.warning), insulin, insulinAfterConstraints))
|
||||||
}
|
}
|
||||||
val eatingSoonTTDuration = DefaultValueHelper.determineEatingSoonTTDuration()
|
val eatingSoonTTDuration = DefaultValueHelper.determineEatingSoonTTDuration()
|
||||||
val eatingSoonTT = DefaultValueHelper.determineEatingSoonTT()
|
val eatingSoonTT = DefaultValueHelper.determineEatingSoonTT()
|
||||||
if (eatingSoonChecked)
|
if (eatingSoonChecked)
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + eatingSoonTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")</font>")
|
actions.add(resourceHelper.gs(R.string.temptargetshort) + ": " + "<font color='" + resourceHelper.gc(R.color.tempTargetConfirmation) + "'>" + DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + eatingSoonTTDuration + " " + resourceHelper.gs(R.string.unit_minute_short) + ")</font>")
|
||||||
|
|
||||||
val timeOffset = overview_insulin_time.value.toInt()
|
val timeOffset = overview_insulin_time.value.toInt()
|
||||||
val time = DateUtil.now() + T.mins(timeOffset.toLong()).msecs()
|
val time = DateUtil.now() + T.mins(timeOffset.toLong()).msecs()
|
||||||
if (timeOffset != 0)
|
if (timeOffset != 0)
|
||||||
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time))
|
actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time))
|
||||||
|
|
||||||
val notes = notes.text.toString()
|
val notes = notes.text.toString()
|
||||||
if (notes.isNotEmpty())
|
if (notes.isNotEmpty())
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
||||||
|
|
||||||
if (insulinAfterConstraints > 0 || eatingSoonChecked) {
|
if (insulinAfterConstraints > 0 || eatingSoonChecked) {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
if (eatingSoonChecked) {
|
if (eatingSoonChecked) {
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
.duration(eatingSoonTTDuration)
|
.duration(eatingSoonTTDuration)
|
||||||
.reason(MainApp.gs(R.string.eatingsoon))
|
.reason(resourceHelper.gs(R.string.eatingsoon))
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
|
.low(Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()))
|
||||||
.high(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
|
.high(Profile.toMgdl(eatingSoonTT, profileFunction.getUnits()))
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
||||||
}
|
}
|
||||||
if (insulinAfterConstraints > 0) {
|
if (insulinAfterConstraints > 0) {
|
||||||
|
@ -171,12 +187,12 @@ class InsulinDialog : DialogFragmentWithDate() {
|
||||||
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
|
val i = Intent(mainApp, ErrorHelperActivity::class.java)
|
||||||
i.putExtra("soundid", R.raw.boluserror)
|
i.putExtra("soundid", R.raw.boluserror)
|
||||||
i.putExtra("status", result.comment)
|
i.putExtra("status", result.comment)
|
||||||
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
|
i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror))
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
MainApp.instance().startActivity(i)
|
mainApp.startActivity(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -186,7 +202,7 @@ class InsulinDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.show(activity, MainApp.gs(R.string.bolus), MainApp.gs(R.string.no_action_selected))
|
OKDialog.show(activity, resourceHelper.gs(R.string.bolus), resourceHelper.gs(R.string.no_action_selected))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,22 +7,29 @@ import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import com.google.common.base.Joiner
|
import com.google.common.base.Joiner
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_profileswitch.*
|
import kotlinx.android.synthetic.main.dialog_profileswitch.*
|
||||||
import kotlinx.android.synthetic.main.notes.*
|
import kotlinx.android.synthetic.main.notes.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ProfileSwitchDialog : DialogFragmentWithDate() {
|
class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var profileFunction: ProfileFunction
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("overview_profileswitch_duration", overview_profileswitch_duration.value)
|
savedInstanceState.putDouble("overview_profileswitch_duration", overview_profileswitch_duration.value)
|
||||||
|
@ -55,14 +62,14 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
overview_profileswitch_profile.adapter = adapter
|
overview_profileswitch_profile.adapter = adapter
|
||||||
// set selected to actual profile
|
// set selected to actual profile
|
||||||
for (p in profileList.indices)
|
for (p in profileList.indices)
|
||||||
if (profileList[p] == ProfileFunctions.getInstance().getProfileName(false))
|
if (profileList[p] == profileFunction.getProfileName(false))
|
||||||
overview_profileswitch_profile.setSelection(p)
|
overview_profileswitch_profile.setSelection(p)
|
||||||
} ?: return
|
} ?: return
|
||||||
|
|
||||||
TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now())?.let { ps ->
|
TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now())?.let { ps ->
|
||||||
if (ps.isCPP) {
|
if (ps.isCPP) {
|
||||||
overview_profileswitch_reuselayout.visibility = View.VISIBLE
|
overview_profileswitch_reuselayout.visibility = View.VISIBLE
|
||||||
overview_profileswitch_reusebutton.text = MainApp.gs(R.string.reuse) + " " + ps.percentage + "% " + ps.timeshift + "h"
|
overview_profileswitch_reusebutton.text = resourceHelper.gs(R.string.reuse) + " " + ps.percentage + "% " + ps.timeshift + "h"
|
||||||
overview_profileswitch_reusebutton.setOnClickListener {
|
overview_profileswitch_reusebutton.setOnClickListener {
|
||||||
overview_profileswitch_percentage.value = ps.percentage.toDouble()
|
overview_profileswitch_percentage.value = ps.percentage.toDouble()
|
||||||
overview_profileswitch_timeshift.value = ps.timeshift.toDouble()
|
overview_profileswitch_timeshift.value = ps.timeshift.toDouble()
|
||||||
|
@ -80,24 +87,24 @@ class ProfileSwitchDialog : DialogFragmentWithDate() {
|
||||||
val actions: LinkedList<String> = LinkedList()
|
val actions: LinkedList<String> = LinkedList()
|
||||||
val duration = overview_profileswitch_duration.value
|
val duration = overview_profileswitch_duration.value
|
||||||
if (duration > 0)
|
if (duration > 0)
|
||||||
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_hours, duration))
|
actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_hours, duration))
|
||||||
val profile = overview_profileswitch_profile.selectedItem.toString()
|
val profile = overview_profileswitch_profile.selectedItem.toString()
|
||||||
actions.add(MainApp.gs(R.string.profile) + ": " + profile)
|
actions.add(resourceHelper.gs(R.string.profile) + ": " + profile)
|
||||||
val percent = overview_profileswitch_percentage.value.toInt()
|
val percent = overview_profileswitch_percentage.value.toInt()
|
||||||
if (percent != 100)
|
if (percent != 100)
|
||||||
actions.add(MainApp.gs(R.string.percent) + ": " + percent + "%")
|
actions.add(resourceHelper.gs(R.string.percent) + ": " + percent + "%")
|
||||||
val timeShift = overview_profileswitch_timeshift.value.toInt()
|
val timeShift = overview_profileswitch_timeshift.value.toInt()
|
||||||
if (timeShift != 0)
|
if (timeShift != 0)
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_timeshift_label) + ": " + MainApp.gs(R.string.format_hours, timeShift.toDouble()))
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_timeshift_label) + ": " + resourceHelper.gs(R.string.format_hours, timeShift.toDouble()))
|
||||||
val notes = notes.text.toString()
|
val notes = notes.text.toString()
|
||||||
if (notes.isNotEmpty())
|
if (notes.isNotEmpty())
|
||||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
|
||||||
if (eventTimeChanged)
|
if (eventTimeChanged)
|
||||||
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_profileswitch), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
ProfileFunctions.getInstance().doProfileSwitch(profileStore, profile, duration.toInt(), percent, timeShift, eventTime)
|
profileFunction.doProfileSwitch(profileStore, profile, duration.toInt(), percent, timeShift, eventTime)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -6,18 +6,23 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.Window
|
import android.view.Window
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.fragment.app.DialogFragment
|
import dagger.android.support.DaggerDialogFragment
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.close.*
|
import kotlinx.android.synthetic.main.close.*
|
||||||
import kotlinx.android.synthetic.main.dialog_profileviewer.*
|
import kotlinx.android.synthetic.main.dialog_profileviewer.*
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class ProfileViewerDialog : DaggerDialogFragment() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
class ProfileViewerDialog : DialogFragment() {
|
|
||||||
private var time: Long = 0
|
private var time: Long = 0
|
||||||
|
|
||||||
enum class Mode(val i: Int) {
|
enum class Mode(val i: Int) {
|
||||||
|
@ -77,7 +82,7 @@ class ProfileViewerDialog : DialogFragment() {
|
||||||
|
|
||||||
profile?.let {
|
profile?.let {
|
||||||
profileview_units.text = it.units
|
profileview_units.text = it.units
|
||||||
profileview_dia.text = MainApp.gs(R.string.format_hours, it.dia)
|
profileview_dia.text = resourceHelper.gs(R.string.format_hours, it.dia)
|
||||||
profileview_activeprofile.text = profileName
|
profileview_activeprofile.text = profileName
|
||||||
profileview_date.text = date
|
profileview_date.text = date
|
||||||
profileview_ic.text = it.icList
|
profileview_ic.text = it.icList
|
||||||
|
|
|
@ -12,18 +12,34 @@ import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription
|
import info.nightscout.androidaps.interfaces.PumpDescription
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
import info.nightscout.androidaps.utils.SafeParse
|
import info.nightscout.androidaps.utils.SafeParse
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_tempbasal.*
|
import kotlinx.android.synthetic.main.dialog_tempbasal.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class TempBasalDialog : DialogFragmentWithDate() {
|
class TempBasalDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var profileFunction: ProfileFunction
|
||||||
|
|
||||||
private var isPercentPump = true
|
private var isPercentPump = true
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
|
@ -43,7 +59,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
||||||
val profile = ProfileFunctions.getInstance().getProfile() ?: return
|
val profile = profileFunction.getProfile() ?: return
|
||||||
|
|
||||||
val maxTempPercent = pumpDescription.maxTempPercent.toDouble()
|
val maxTempPercent = pumpDescription.maxTempPercent.toDouble()
|
||||||
val tempPercentStep = pumpDescription.tempPercentStep.toDouble()
|
val tempPercentStep = pumpDescription.tempPercentStep.toDouble()
|
||||||
|
@ -73,33 +89,33 @@ class TempBasalDialog : DialogFragmentWithDate() {
|
||||||
var percent = 0
|
var percent = 0
|
||||||
var absolute = 0.0
|
var absolute = 0.0
|
||||||
val durationInMinutes = SafeParse.stringToInt(actions_tempbasal_duration.text)
|
val durationInMinutes = SafeParse.stringToInt(actions_tempbasal_duration.text)
|
||||||
val profile = ProfileFunctions.getInstance().getProfile() ?: return false
|
val profile = profileFunction.getProfile() ?: return false
|
||||||
val actions: LinkedList<String> = LinkedList()
|
val actions: LinkedList<String> = LinkedList()
|
||||||
if (isPercentPump) {
|
if (isPercentPump) {
|
||||||
val basalPercentInput = SafeParse.stringToInt(actions_tempbasal_basalpercentinput.text)
|
val basalPercentInput = SafeParse.stringToInt(actions_tempbasal_basalpercentinput.text)
|
||||||
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(Constraint(basalPercentInput), profile).value()
|
percent = constraintChecker.applyBasalPercentConstraints(Constraint(basalPercentInput), profile).value()
|
||||||
actions.add(MainApp.gs(R.string.pump_tempbasal_label)+ ": $percent%")
|
actions.add(resourceHelper.gs(R.string.pump_tempbasal_label) + ": $percent%")
|
||||||
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
|
actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_mins, durationInMinutes))
|
||||||
if (percent != basalPercentInput) actions.add(MainApp.gs(R.string.constraintapllied))
|
if (percent != basalPercentInput) actions.add(resourceHelper.gs(R.string.constraintapllied))
|
||||||
} else {
|
} else {
|
||||||
val basalAbsoluteInput = SafeParse.stringToDouble(actions_tempbasal_basalabsoluteinput.text)
|
val basalAbsoluteInput = SafeParse.stringToDouble(actions_tempbasal_basalabsoluteinput.text)
|
||||||
absolute = MainApp.getConstraintChecker().applyBasalConstraints(Constraint(basalAbsoluteInput), profile).value()
|
absolute = constraintChecker.applyBasalConstraints(Constraint(basalAbsoluteInput), profile).value()
|
||||||
actions.add(MainApp.gs(R.string.pump_tempbasal_label)+ ": " + MainApp.gs(R.string.pump_basebasalrate, absolute))
|
actions.add(resourceHelper.gs(R.string.pump_tempbasal_label) + ": " + resourceHelper.gs(R.string.pump_basebasalrate, absolute))
|
||||||
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
|
actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_mins, durationInMinutes))
|
||||||
if (abs(absolute - basalAbsoluteInput) > 0.01)
|
if (abs(absolute - basalAbsoluteInput) > 0.01)
|
||||||
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.constraintapllied) + "</font>")
|
actions.add("<font color='" + resourceHelper.gc(R.color.warning) + "'>" + resourceHelper.gs(R.string.constraintapllied) + "</font>")
|
||||||
}
|
}
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.pump_tempbasal_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, MainApp.gs(R.string.pump_tempbasal_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
val callback: Callback = object : Callback() {
|
val callback: Callback = object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
|
val i = Intent(mainApp, ErrorHelperActivity::class.java)
|
||||||
i.putExtra("soundid", R.raw.boluserror)
|
i.putExtra("soundid", R.raw.boluserror)
|
||||||
i.putExtra("status", result.comment)
|
i.putExtra("status", result.comment)
|
||||||
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror))
|
i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror))
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
MainApp.instance().startActivity(i)
|
mainApp.startActivity(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,25 +9,39 @@ import android.widget.ArrayAdapter
|
||||||
import com.google.common.base.Joiner
|
import com.google.common.base.Joiner
|
||||||
import com.google.common.collect.Lists
|
import com.google.common.collect.Lists
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.db.Source
|
import info.nightscout.androidaps.db.Source
|
||||||
import info.nightscout.androidaps.db.TempTarget
|
import info.nightscout.androidaps.db.TempTarget
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
import info.nightscout.androidaps.utils.HtmlHelper
|
import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
import info.nightscout.androidaps.utils.SP
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import kotlinx.android.synthetic.main.dialog_temptarget.*
|
import kotlinx.android.synthetic.main.dialog_temptarget.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class TempTargetDialog : DialogFragmentWithDate() {
|
class TempTargetDialog : DialogFragmentWithDate() {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var sp: SP
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var profileFunction: ProfileFunction
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("overview_temptarget_duration", overview_temptarget_duration.value)
|
savedInstanceState.putDouble("overview_temptarget_duration", overview_temptarget_duration.value)
|
||||||
|
@ -46,7 +60,7 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
||||||
overview_temptarget_duration.setParams(savedInstanceState?.getDouble("overview_temptarget_duration")
|
overview_temptarget_duration.setParams(savedInstanceState?.getDouble("overview_temptarget_duration")
|
||||||
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, ok)
|
?: 0.0, 0.0, Constants.MAX_PROFILE_SWITCH_DURATION, 10.0, DecimalFormat("0"), false, ok)
|
||||||
|
|
||||||
if (ProfileFunctions.getSystemUnits() == Constants.MMOL)
|
if (profileFunction.getUnits() == Constants.MMOL)
|
||||||
overview_temptarget_temptarget.setParams(
|
overview_temptarget_temptarget.setParams(
|
||||||
savedInstanceState?.getDouble("overview_temptarget_temptarget")
|
savedInstanceState?.getDouble("overview_temptarget_temptarget")
|
||||||
?: Constants.MIN_TT_MMOL,
|
?: Constants.MIN_TT_MMOL,
|
||||||
|
@ -57,16 +71,16 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
||||||
?: Constants.MIN_TT_MGDL,
|
?: Constants.MIN_TT_MGDL,
|
||||||
Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 1.0, DecimalFormat("0"), false, ok)
|
Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 1.0, DecimalFormat("0"), false, ok)
|
||||||
|
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = profileFunction.getUnits()
|
||||||
overview_temptarget_units.text = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
|
overview_temptarget_units.text = if (units == Constants.MMOL) resourceHelper.gs(R.string.mmol) else resourceHelper.gs(R.string.mgdl)
|
||||||
// temp target
|
// temp target
|
||||||
context?.let { context ->
|
context?.let { context ->
|
||||||
val reasonList: List<String> = Lists.newArrayList(
|
val reasonList: List<String> = Lists.newArrayList(
|
||||||
MainApp.gs(R.string.manual),
|
resourceHelper.gs(R.string.manual),
|
||||||
MainApp.gs(R.string.cancel),
|
resourceHelper.gs(R.string.cancel),
|
||||||
MainApp.gs(R.string.eatingsoon),
|
resourceHelper.gs(R.string.eatingsoon),
|
||||||
MainApp.gs(R.string.activity),
|
resourceHelper.gs(R.string.activity),
|
||||||
MainApp.gs(R.string.hypo)
|
resourceHelper.gs(R.string.hypo)
|
||||||
)
|
)
|
||||||
val adapterReason = ArrayAdapter(context, R.layout.spinner_centered, reasonList)
|
val adapterReason = ArrayAdapter(context, R.layout.spinner_centered, reasonList)
|
||||||
overview_temptarget_reason.adapter = adapterReason
|
overview_temptarget_reason.adapter = adapterReason
|
||||||
|
@ -75,22 +89,22 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
||||||
val defaultDuration: Double
|
val defaultDuration: Double
|
||||||
val defaultTarget: Double
|
val defaultTarget: Double
|
||||||
when (reasonList[position]) {
|
when (reasonList[position]) {
|
||||||
MainApp.gs(R.string.eatingsoon) -> {
|
resourceHelper.gs(R.string.eatingsoon) -> {
|
||||||
defaultDuration = DefaultValueHelper.determineEatingSoonTTDuration().toDouble()
|
defaultDuration = DefaultValueHelper.determineEatingSoonTTDuration().toDouble()
|
||||||
defaultTarget = DefaultValueHelper.determineEatingSoonTT()
|
defaultTarget = DefaultValueHelper.determineEatingSoonTT()
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.gs(R.string.activity) -> {
|
resourceHelper.gs(R.string.activity) -> {
|
||||||
defaultDuration = DefaultValueHelper.determineActivityTTDuration().toDouble()
|
defaultDuration = DefaultValueHelper.determineActivityTTDuration().toDouble()
|
||||||
defaultTarget = DefaultValueHelper.determineActivityTT()
|
defaultTarget = DefaultValueHelper.determineActivityTT()
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.gs(R.string.hypo) -> {
|
resourceHelper.gs(R.string.hypo) -> {
|
||||||
defaultDuration = DefaultValueHelper.determineHypoTTDuration().toDouble()
|
defaultDuration = DefaultValueHelper.determineHypoTTDuration().toDouble()
|
||||||
defaultTarget = DefaultValueHelper.determineHypoTT()
|
defaultTarget = DefaultValueHelper.determineHypoTT()
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.gs(R.string.cancel) -> {
|
resourceHelper.gs(R.string.cancel) -> {
|
||||||
defaultDuration = 0.0
|
defaultDuration = 0.0
|
||||||
defaultTarget = 0.0
|
defaultTarget = 0.0
|
||||||
}
|
}
|
||||||
|
@ -112,21 +126,21 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
||||||
override fun submit(): Boolean {
|
override fun submit(): Boolean {
|
||||||
val actions: LinkedList<String> = LinkedList()
|
val actions: LinkedList<String> = LinkedList()
|
||||||
val reason = overview_temptarget_reason.selectedItem.toString()
|
val reason = overview_temptarget_reason.selectedItem.toString()
|
||||||
val unitResId = if (ProfileFunctions.getSystemUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol
|
val unitResId = if (profileFunction.getUnits() == Constants.MGDL) R.string.mgdl else R.string.mmol
|
||||||
val target = overview_temptarget_temptarget.value
|
val target = overview_temptarget_temptarget.value
|
||||||
val duration = overview_temptarget_duration.value
|
val duration = overview_temptarget_duration.value
|
||||||
if (target != 0.0 && duration != 0.0) {
|
if (target != 0.0 && duration != 0.0) {
|
||||||
actions.add(MainApp.gs(R.string.reason) + ": " + reason)
|
actions.add(resourceHelper.gs(R.string.reason) + ": " + reason)
|
||||||
actions.add(MainApp.gs(R.string.nsprofileview_target_label) + ": " + Profile.toCurrentUnitsString(target) + " " + MainApp.gs(unitResId))
|
actions.add(resourceHelper.gs(R.string.nsprofileview_target_label) + ": " + Profile.toCurrentUnitsString(target) + " " + resourceHelper.gs(unitResId))
|
||||||
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_hours, duration))
|
actions.add(resourceHelper.gs(R.string.duration) + ": " + resourceHelper.gs(R.string.format_hours, duration))
|
||||||
} else {
|
} else {
|
||||||
actions.add(MainApp.gs(R.string.stoptemptarget))
|
actions.add(resourceHelper.gs(R.string.stoptemptarget))
|
||||||
}
|
}
|
||||||
if (eventTimeChanged)
|
if (eventTimeChanged)
|
||||||
actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
actions.add(resourceHelper.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime))
|
||||||
|
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
if (target == 0.0 || duration == 0.0) {
|
if (target == 0.0 || duration == 0.0) {
|
||||||
val tempTarget = TempTarget()
|
val tempTarget = TempTarget()
|
||||||
.date(eventTime)
|
.date(eventTime)
|
||||||
|
@ -140,11 +154,11 @@ class TempTargetDialog : DialogFragmentWithDate() {
|
||||||
.duration(duration.toInt())
|
.duration(duration.toInt())
|
||||||
.reason(reason)
|
.reason(reason)
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(target, ProfileFunctions.getSystemUnits()))
|
.low(Profile.toMgdl(target, profileFunction.getUnits()))
|
||||||
.high(Profile.toMgdl(target, ProfileFunctions.getSystemUnits()))
|
.high(Profile.toMgdl(target, profileFunction.getUnits()))
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
|
||||||
}
|
}
|
||||||
if (duration == 10.0) SP.putBoolean(R.string.key_objectiveusetemptarget, true)
|
if (duration == 10.0) sp.putBoolean(R.string.key_objectiveusetemptarget, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.db.CareportalEvent
|
||||||
import info.nightscout.androidaps.db.Source
|
import info.nightscout.androidaps.db.Source
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||||
|
@ -23,15 +24,24 @@ import info.nightscout.androidaps.utils.HtmlHelper
|
||||||
import info.nightscout.androidaps.utils.OKDialog
|
import info.nightscout.androidaps.utils.OKDialog
|
||||||
import info.nightscout.androidaps.utils.SafeParse
|
import info.nightscout.androidaps.utils.SafeParse
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.dialog_treatment.*
|
import kotlinx.android.synthetic.main.dialog_treatment.*
|
||||||
import kotlinx.android.synthetic.main.okcancel.*
|
import kotlinx.android.synthetic.main.okcancel.*
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class TreatmentDialog : DialogFragmentWithDate() {
|
class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
private var maxCarbs = MainApp.getConstraintChecker().maxCarbsAllowed.value().toDouble()
|
|
||||||
private var maxInsulin = MainApp.getConstraintChecker().maxBolusAllowed.value()
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
private val textWatcher: TextWatcher = object : TextWatcher {
|
private val textWatcher: TextWatcher = object : TextWatcher {
|
||||||
override fun afterTextChanged(s: Editable) {}
|
override fun afterTextChanged(s: Editable) {}
|
||||||
|
@ -42,13 +52,15 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateInputs() {
|
private fun validateInputs() {
|
||||||
|
val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble()
|
||||||
|
val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
|
||||||
if (SafeParse.stringToInt(overview_treatment_carbs.text) > maxCarbs) {
|
if (SafeParse.stringToInt(overview_treatment_carbs.text) > maxCarbs) {
|
||||||
overview_treatment_carbs.value = 0.0
|
overview_treatment_carbs.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.carbsconstraintapplied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.carbsconstraintapplied))
|
||||||
}
|
}
|
||||||
if (SafeParse.stringToDouble(overview_treatment_insulin.text) > maxInsulin) {
|
if (SafeParse.stringToDouble(overview_treatment_insulin.text) > maxInsulin) {
|
||||||
overview_treatment_insulin.value = 0.0
|
overview_treatment_insulin.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.bolusconstraintapplied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.bolusconstraintapplied))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +79,8 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val maxCarbs = constraintChecker.getMaxCarbsAllowed().value().toDouble()
|
||||||
|
val maxInsulin = constraintChecker.getMaxBolusAllowed().value()
|
||||||
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
val pumpDescription = ConfigBuilderPlugin.getPlugin().activePump?.pumpDescription ?: return
|
||||||
overview_treatment_carbs.setParams(savedInstanceState?.getDouble("overview_treatment_carbs")
|
overview_treatment_carbs.setParams(savedInstanceState?.getDouble("overview_treatment_carbs")
|
||||||
?: 0.0, 0.0, maxCarbs, 1.0, DecimalFormat("0"), false, ok, textWatcher)
|
?: 0.0, 0.0, maxCarbs, 1.0, DecimalFormat("0"), false, ok, textWatcher)
|
||||||
|
@ -81,24 +95,24 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
val carbs = SafeParse.stringToInt(overview_treatment_carbs.text)
|
val carbs = SafeParse.stringToInt(overview_treatment_carbs.text)
|
||||||
val recordOnlyChecked = overview_treatment_record_only.isChecked
|
val recordOnlyChecked = overview_treatment_record_only.isChecked
|
||||||
val actions: LinkedList<String?> = LinkedList()
|
val actions: LinkedList<String?> = LinkedList()
|
||||||
val insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(insulin)).value()
|
val insulinAfterConstraints = constraintChecker.applyBolusConstraints(Constraint(insulin)).value()
|
||||||
val carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(carbs)).value()
|
val carbsAfterConstraints = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value()
|
||||||
|
|
||||||
if (insulinAfterConstraints > 0) {
|
if (insulinAfterConstraints > 0) {
|
||||||
actions.add(MainApp.gs(R.string.bolus) + ": " + "<font color='" + MainApp.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + MainApp.gs(R.string.insulin_unit_shortname) + "</font>")
|
actions.add(resourceHelper.gs(R.string.bolus) + ": " + "<font color='" + resourceHelper.gc(R.color.bolus) + "'>" + DecimalFormatter.toPumpSupportedBolus(insulinAfterConstraints) + resourceHelper.gs(R.string.insulin_unit_shortname) + "</font>")
|
||||||
if (recordOnlyChecked)
|
if (recordOnlyChecked)
|
||||||
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.bolusrecordedonly) + "</font>")
|
actions.add("<font color='" + resourceHelper.gc(R.color.warning) + "'>" + resourceHelper.gs(R.string.bolusrecordedonly) + "</font>")
|
||||||
if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints))
|
if (abs(insulinAfterConstraints - insulin) > pumpDescription.pumpType.determineCorrectBolusStepSize(insulinAfterConstraints))
|
||||||
actions.add(MainApp.gs(R.string.bolusconstraintappliedwarning, MainApp.gc(R.color.warning), insulin, insulinAfterConstraints))
|
actions.add(resourceHelper.gs(R.string.bolusconstraintappliedwarning, resourceHelper.gc(R.color.warning), insulin, insulinAfterConstraints))
|
||||||
}
|
}
|
||||||
if (carbsAfterConstraints > 0) {
|
if (carbsAfterConstraints > 0) {
|
||||||
actions.add(MainApp.gs(R.string.carbs) + ": " + "<font color='" + MainApp.gc(R.color.carbs) + "'>" + MainApp.gs(R.string.format_carbs, carbsAfterConstraints) + "</font>")
|
actions.add(resourceHelper.gs(R.string.carbs) + ": " + "<font color='" + resourceHelper.gc(R.color.carbs) + "'>" + resourceHelper.gs(R.string.format_carbs, carbsAfterConstraints) + "</font>")
|
||||||
if (carbsAfterConstraints != carbs)
|
if (carbsAfterConstraints != carbs)
|
||||||
actions.add("<font color='" + MainApp.gc(R.color.warning) + "'>" + MainApp.gs(R.string.carbsconstraintapplied) + "</font>")
|
actions.add("<font color='" + resourceHelper.gc(R.color.warning) + "'>" + resourceHelper.gs(R.string.carbsconstraintapplied) + "</font>")
|
||||||
}
|
}
|
||||||
if (insulinAfterConstraints > 0 || carbsAfterConstraints > 0) {
|
if (insulinAfterConstraints > 0 || carbsAfterConstraints > 0) {
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.showConfirmation(activity, MainApp.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("<br/>").join(actions)), Runnable {
|
||||||
val detailedBolusInfo = DetailedBolusInfo()
|
val detailedBolusInfo = DetailedBolusInfo()
|
||||||
if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION
|
if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION
|
||||||
if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS
|
if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS
|
||||||
|
@ -110,12 +124,12 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
val i = Intent(MainApp.instance(), ErrorHelperActivity::class.java)
|
val i = Intent(mainApp, ErrorHelperActivity::class.java)
|
||||||
i.putExtra("soundid", R.raw.boluserror)
|
i.putExtra("soundid", R.raw.boluserror)
|
||||||
i.putExtra("status", result.comment)
|
i.putExtra("status", result.comment)
|
||||||
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror))
|
i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror))
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
MainApp.instance().startActivity(i)
|
mainApp.startActivity(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -125,7 +139,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
activity?.let { activity ->
|
activity?.let { activity ->
|
||||||
OKDialog.show(activity, MainApp.gs(R.string.overview_treatment_label), MainApp.gs(R.string.no_action_selected))
|
OKDialog.show(activity, resourceHelper.gs(R.string.overview_treatment_label), resourceHelper.gs(R.string.no_action_selected))
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import android.widget.AdapterView
|
||||||
import android.widget.AdapterView.OnItemSelectedListener
|
import android.widget.AdapterView.OnItemSelectedListener
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.CompoundButton
|
import android.widget.CompoundButton
|
||||||
import androidx.fragment.app.DialogFragment
|
import dagger.android.support.DaggerDialogFragment
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
|
@ -22,22 +22,41 @@ import info.nightscout.androidaps.db.DatabaseHelper
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.*
|
import info.nightscout.androidaps.utils.*
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
import kotlinx.android.synthetic.main.dialog_wizard.*
|
import kotlinx.android.synthetic.main.dialog_wizard.*
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class WizardDialog : DialogFragment() {
|
class WizardDialog : DaggerDialogFragment() {
|
||||||
private val log = LoggerFactory.getLogger(WizardDialog::class.java)
|
private val log = LoggerFactory.getLogger(WizardDialog::class.java)
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var constraintChecker: ConstraintChecker
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var mainApp: MainApp
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var profileFunction: ProfileFunction
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var sp: SP
|
||||||
|
|
||||||
private var wizard: BolusWizard? = null
|
private var wizard: BolusWizard? = null
|
||||||
|
|
||||||
//one shot guards
|
//one shot guards
|
||||||
|
@ -79,11 +98,11 @@ class WizardDialog : DialogFragment() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
loadCheckedStates()
|
loadCheckedStates()
|
||||||
processCobCheckBox()
|
processCobCheckBox()
|
||||||
treatments_wizard_sbcheckbox.visibility = SP.getBoolean(R.string.key_usesuperbolus, false).toVisibility()
|
treatments_wizard_sbcheckbox.visibility = sp.getBoolean(R.string.key_usesuperbolus, false).toVisibility()
|
||||||
treatments_wizard_notes_layout.visibility = SP.getBoolean(R.string.key_show_notes_entry_dialogs, false).toVisibility()
|
treatments_wizard_notes_layout.visibility = sp.getBoolean(R.string.key_show_notes_entry_dialogs, false).toVisibility()
|
||||||
|
|
||||||
val maxCarbs = MainApp.getConstraintChecker().maxCarbsAllowed.value()
|
val maxCarbs = constraintChecker.getMaxCarbsAllowed().value()
|
||||||
val maxCorrection = MainApp.getConstraintChecker().maxBolusAllowed.value()
|
val maxCorrection = constraintChecker.getMaxBolusAllowed().value()
|
||||||
|
|
||||||
treatments_wizard_bg_input.setParams(savedInstanceState?.getDouble("treatments_wizard_bg_input")
|
treatments_wizard_bg_input.setParams(savedInstanceState?.getDouble("treatments_wizard_bg_input")
|
||||||
?: 0.0, 0.0, 500.0, 0.1, DecimalFormat("0.0"), false, ok, textWatcher)
|
?: 0.0, 0.0, 500.0, 0.1, DecimalFormat("0.0"), false, ok, textWatcher)
|
||||||
|
@ -97,7 +116,7 @@ class WizardDialog : DialogFragment() {
|
||||||
?: 0.0, -60.0, 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
?: 0.0, -60.0, 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
||||||
initDialog()
|
initDialog()
|
||||||
|
|
||||||
treatments_wizard_percent_used.text = MainApp.gs(R.string.format_percent, SP.getInt(R.string.key_boluswizard_percentage, 100))
|
treatments_wizard_percent_used.text = resourceHelper.gs(R.string.format_percent, sp.getInt(R.string.key_boluswizard_percentage, 100))
|
||||||
// ok button
|
// ok button
|
||||||
ok.setOnClickListener {
|
ok.setOnClickListener {
|
||||||
if (okClicked) {
|
if (okClicked) {
|
||||||
|
@ -122,13 +141,13 @@ class WizardDialog : DialogFragment() {
|
||||||
treatments_wizard_bgtrendcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
treatments_wizard_bgtrendcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
||||||
treatments_wizard_sbcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
treatments_wizard_sbcheckbox.setOnCheckedChangeListener(::onCheckedChanged)
|
||||||
|
|
||||||
val showCalc = SP.getBoolean(MainApp.gs(R.string.key_wizard_calculation_visible), false)
|
val showCalc = sp.getBoolean(resourceHelper.gs(R.string.key_wizard_calculation_visible), false)
|
||||||
treatments_wizard_delimiter.visibility = showCalc.toVisibility()
|
treatments_wizard_delimiter.visibility = showCalc.toVisibility()
|
||||||
treatments_wizard_resulttable.visibility = showCalc.toVisibility()
|
treatments_wizard_resulttable.visibility = showCalc.toVisibility()
|
||||||
treatments_wizard_calculationcheckbox.isChecked = showCalc
|
treatments_wizard_calculationcheckbox.isChecked = showCalc
|
||||||
treatments_wizard_calculationcheckbox.setOnCheckedChangeListener { _, isChecked ->
|
treatments_wizard_calculationcheckbox.setOnCheckedChangeListener { _, isChecked ->
|
||||||
run {
|
run {
|
||||||
SP.putBoolean(MainApp.gs(R.string.key_wizard_calculation_visible), isChecked)
|
sp.putBoolean(resourceHelper.gs(R.string.key_wizard_calculation_visible), isChecked)
|
||||||
treatments_wizard_delimiter.visibility = isChecked.toVisibility()
|
treatments_wizard_delimiter.visibility = isChecked.toVisibility()
|
||||||
treatments_wizard_resulttable.visibility = isChecked.toVisibility()
|
treatments_wizard_resulttable.visibility = isChecked.toVisibility()
|
||||||
}
|
}
|
||||||
|
@ -136,7 +155,7 @@ class WizardDialog : DialogFragment() {
|
||||||
// profile spinner
|
// profile spinner
|
||||||
treatments_wizard_profile.onItemSelectedListener = object : OnItemSelectedListener {
|
treatments_wizard_profile.onItemSelectedListener = object : OnItemSelectedListener {
|
||||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.noprofileselected))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.noprofileselected))
|
||||||
ok.visibility = View.GONE
|
ok.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,34 +203,34 @@ class WizardDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveCheckedStates() {
|
private fun saveCheckedStates() {
|
||||||
SP.putBoolean(MainApp.gs(R.string.key_wizard_include_cob), treatments_wizard_cobcheckbox.isChecked)
|
sp.putBoolean(resourceHelper.gs(R.string.key_wizard_include_cob), treatments_wizard_cobcheckbox.isChecked)
|
||||||
SP.putBoolean(MainApp.gs(R.string.key_wizard_include_trend_bg), treatments_wizard_bgtrendcheckbox.isChecked)
|
sp.putBoolean(resourceHelper.gs(R.string.key_wizard_include_trend_bg), treatments_wizard_bgtrendcheckbox.isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadCheckedStates() {
|
private fun loadCheckedStates() {
|
||||||
treatments_wizard_bgtrendcheckbox.isChecked = SP.getBoolean(MainApp.gs(R.string.key_wizard_include_trend_bg), false)
|
treatments_wizard_bgtrendcheckbox.isChecked = sp.getBoolean(resourceHelper.gs(R.string.key_wizard_include_trend_bg), false)
|
||||||
treatments_wizard_cobcheckbox.isChecked = SP.getBoolean(MainApp.gs(R.string.key_wizard_include_cob), false)
|
treatments_wizard_cobcheckbox.isChecked = sp.getBoolean(resourceHelper.gs(R.string.key_wizard_include_cob), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initDialog() {
|
private fun initDialog() {
|
||||||
val profile = ProfileFunctions.getInstance().getProfile()
|
val profile = profileFunction.getProfile()
|
||||||
val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile
|
val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface.profile
|
||||||
|
|
||||||
if (profile == null || profileStore == null) {
|
if (profile == null || profileStore == null) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.noprofile))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.noprofile))
|
||||||
dismiss()
|
dismiss()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val profileList: ArrayList<CharSequence>
|
val profileList: ArrayList<CharSequence>
|
||||||
profileList = profileStore.getProfileList()
|
profileList = profileStore.getProfileList()
|
||||||
profileList.add(0, MainApp.gs(R.string.active))
|
profileList.add(0, resourceHelper.gs(R.string.active))
|
||||||
context?.let { context ->
|
context?.let { context ->
|
||||||
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
val adapter = ArrayAdapter(context, R.layout.spinner_centered, profileList)
|
||||||
treatments_wizard_profile.adapter = adapter
|
treatments_wizard_profile.adapter = adapter
|
||||||
} ?: return
|
} ?: return
|
||||||
|
|
||||||
val units = ProfileFunctions.getSystemUnits()
|
val units = profileFunction.getUnits()
|
||||||
treatments_wizard_bgunits.text = units
|
treatments_wizard_bgunits.text = units
|
||||||
if (units == Constants.MGDL)
|
if (units == Constants.MGDL)
|
||||||
treatments_wizard_bg_input.setStep(1.0)
|
treatments_wizard_bg_input.setStep(1.0)
|
||||||
|
@ -239,18 +258,18 @@ class WizardDialog : DialogFragment() {
|
||||||
|
|
||||||
calculateInsulin()
|
calculateInsulin()
|
||||||
|
|
||||||
treatments_wizard_percent_used.visibility = (SP.getInt(R.string.key_boluswizard_percentage, 100) != 100).toVisibility()
|
treatments_wizard_percent_used.visibility = (sp.getInt(R.string.key_boluswizard_percentage, 100) != 100).toVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateInsulin() {
|
private fun calculateInsulin() {
|
||||||
val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile
|
val profileStore = ConfigBuilderPlugin.getPlugin().activeProfileInterface.profile
|
||||||
if (treatments_wizard_profile.selectedItem == null || profileStore == null)
|
if (treatments_wizard_profile.selectedItem == null || profileStore == null)
|
||||||
return // not initialized yet
|
return // not initialized yet
|
||||||
var profileName = treatments_wizard_profile.selectedItem.toString()
|
var profileName = treatments_wizard_profile.selectedItem.toString()
|
||||||
val specificProfile: Profile?
|
val specificProfile: Profile?
|
||||||
if (profileName == MainApp.gs(R.string.active)) {
|
if (profileName == resourceHelper.gs(R.string.active)) {
|
||||||
specificProfile = ProfileFunctions.getInstance().getProfile()
|
specificProfile = profileFunction.getProfile()
|
||||||
profileName = ProfileFunctions.getInstance().getProfileName() ?: return
|
profileName = profileFunction.getProfileName() ?: return
|
||||||
} else
|
} else
|
||||||
specificProfile = profileStore.getSpecificProfile(profileName)
|
specificProfile = profileStore.getSpecificProfile(profileName)
|
||||||
|
|
||||||
|
@ -260,10 +279,10 @@ class WizardDialog : DialogFragment() {
|
||||||
var bg = SafeParse.stringToDouble(treatments_wizard_bg_input.text)
|
var bg = SafeParse.stringToDouble(treatments_wizard_bg_input.text)
|
||||||
val carbs = SafeParse.stringToInt(treatments_wizard_carbs_input.text)
|
val carbs = SafeParse.stringToInt(treatments_wizard_carbs_input.text)
|
||||||
val correction = SafeParse.stringToDouble(treatments_wizard_correction_input.text)
|
val correction = SafeParse.stringToDouble(treatments_wizard_correction_input.text)
|
||||||
val carbsAfterConstraint = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(carbs)).value()
|
val carbsAfterConstraint = constraintChecker.applyCarbsConstraints(Constraint(carbs)).value()
|
||||||
if (abs(carbs - carbsAfterConstraint) > 0.01) {
|
if (abs(carbs - carbsAfterConstraint) > 0.01) {
|
||||||
treatments_wizard_carbs_input.value = 0.0
|
treatments_wizard_carbs_input.value = 0.0
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.carbsconstraintapplied))
|
ToastUtils.showToastInUiThread(mainApp, resourceHelper.gs(R.string.carbsconstraintapplied))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +299,7 @@ class WizardDialog : DialogFragment() {
|
||||||
val carbTime = SafeParse.stringToInt(treatments_wizard_carb_time_input.text)
|
val carbTime = SafeParse.stringToInt(treatments_wizard_carb_time_input.text)
|
||||||
|
|
||||||
wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, cob, bg, correction,
|
wizard = BolusWizard(specificProfile, profileName, tempTarget, carbsAfterConstraint, cob, bg, correction,
|
||||||
SP.getInt(R.string.key_boluswizard_percentage, 100).toDouble(),
|
sp.getInt(R.string.key_boluswizard_percentage, 100).toDouble(),
|
||||||
treatments_wizard_bgcheckbox.isChecked,
|
treatments_wizard_bgcheckbox.isChecked,
|
||||||
treatments_wizard_cobcheckbox.isChecked,
|
treatments_wizard_cobcheckbox.isChecked,
|
||||||
treatments_wizard_bolusiobcheckbox.isChecked,
|
treatments_wizard_bolusiobcheckbox.isChecked,
|
||||||
|
@ -291,10 +310,10 @@ class WizardDialog : DialogFragment() {
|
||||||
treatment_wizard_notes.text.toString(), carbTime)
|
treatment_wizard_notes.text.toString(), carbTime)
|
||||||
|
|
||||||
wizard?.let { wizard ->
|
wizard?.let { wizard ->
|
||||||
treatments_wizard_bg.text = String.format(MainApp.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, ProfileFunctions.getSystemUnits())).valueToUnitsToString(ProfileFunctions.getSystemUnits()), wizard.sens)
|
treatments_wizard_bg.text = String.format(resourceHelper.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, profileFunction.getUnits())).valueToUnitsToString(profileFunction.getUnits()), wizard.sens)
|
||||||
treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG)
|
treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG)
|
||||||
|
|
||||||
treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic)
|
treatments_wizard_carbs.text = String.format(resourceHelper.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic)
|
||||||
treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCarbs)
|
treatments_wizard_carbsinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCarbs)
|
||||||
|
|
||||||
treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromBolusIOB)
|
treatments_wizard_bolusiobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromBolusIOB)
|
||||||
|
@ -303,14 +322,14 @@ class WizardDialog : DialogFragment() {
|
||||||
treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(wizard.insulinFromCorrection)
|
treatments_wizard_correctioninsulin.text = StringUtils.formatInsulin(wizard.insulinFromCorrection)
|
||||||
|
|
||||||
// Superbolus
|
// Superbolus
|
||||||
treatments_wizard_sb.text = if (treatments_wizard_sbcheckbox.isChecked) MainApp.gs(R.string.twohours) else ""
|
treatments_wizard_sb.text = if (treatments_wizard_sbcheckbox.isChecked) resourceHelper.gs(R.string.twohours) else ""
|
||||||
treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(wizard.insulinFromSuperBolus)
|
treatments_wizard_sbinsulin.text = StringUtils.formatInsulin(wizard.insulinFromSuperBolus)
|
||||||
|
|
||||||
// Trend
|
// Trend
|
||||||
if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) {
|
if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) {
|
||||||
treatments_wizard_bgtrend.text = ((if (wizard.trend > 0) "+" else "")
|
treatments_wizard_bgtrend.text = ((if (wizard.trend > 0) "+" else "")
|
||||||
+ Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, ProfileFunctions.getSystemUnits())
|
+ Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, profileFunction.getUnits())
|
||||||
+ " " + ProfileFunctions.getSystemUnits())
|
+ " " + profileFunction.getUnits())
|
||||||
} else {
|
} else {
|
||||||
treatments_wizard_bgtrend.text = ""
|
treatments_wizard_bgtrend.text = ""
|
||||||
}
|
}
|
||||||
|
@ -318,7 +337,7 @@ class WizardDialog : DialogFragment() {
|
||||||
|
|
||||||
// COB
|
// COB
|
||||||
if (treatments_wizard_cobcheckbox.isChecked) {
|
if (treatments_wizard_cobcheckbox.isChecked) {
|
||||||
treatments_wizard_cob.text = String.format(MainApp.gs(R.string.format_cob_ic), cob, wizard.ic)
|
treatments_wizard_cob.text = String.format(resourceHelper.gs(R.string.format_cob_ic), cob, wizard.ic)
|
||||||
treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCOB)
|
treatments_wizard_cobinsulin.text = StringUtils.formatInsulin(wizard.insulinFromCOB)
|
||||||
} else {
|
} else {
|
||||||
treatments_wizard_cob.text = ""
|
treatments_wizard_cob.text = ""
|
||||||
|
@ -326,12 +345,12 @@ class WizardDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wizard.calculatedTotalInsulin > 0.0 || carbsAfterConstraint > 0.0) {
|
if (wizard.calculatedTotalInsulin > 0.0 || carbsAfterConstraint > 0.0) {
|
||||||
val insulinText = if (wizard.calculatedTotalInsulin > 0.0) MainApp.gs(R.string.formatinsulinunits, wizard.calculatedTotalInsulin) else ""
|
val insulinText = if (wizard.calculatedTotalInsulin > 0.0) resourceHelper.gs(R.string.formatinsulinunits, wizard.calculatedTotalInsulin) else ""
|
||||||
val carbsText = if (carbsAfterConstraint > 0.0) MainApp.gs(R.string.format_carbs, carbsAfterConstraint) else ""
|
val carbsText = if (carbsAfterConstraint > 0.0) resourceHelper.gs(R.string.format_carbs, carbsAfterConstraint) else ""
|
||||||
treatments_wizard_total.text = MainApp.gs(R.string.result_insulin_carbs, insulinText, carbsText)
|
treatments_wizard_total.text = resourceHelper.gs(R.string.result_insulin_carbs, insulinText, carbsText)
|
||||||
ok.visibility = View.VISIBLE
|
ok.visibility = View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
treatments_wizard_total.text = MainApp.gs(R.string.missing_carbs, wizard.carbsEquivalent.toInt())
|
treatments_wizard_total.text = resourceHelper.gs(R.string.missing_carbs, wizard.carbsEquivalent.toInt())
|
||||||
ok.visibility = View.INVISIBLE
|
ok.visibility = View.INVISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
|
||||||
|
interface ConstraintsInterface {
|
||||||
|
|
||||||
|
fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun applyBasalConstraints(absoluteRate: Constraint<Double>, profile: Profile): Constraint<Double> {
|
||||||
|
return absoluteRate
|
||||||
|
}
|
||||||
|
|
||||||
|
fun applyBasalPercentConstraints(percentRate: Constraint<Int>, profile: Profile): Constraint<Int> {
|
||||||
|
return percentRate
|
||||||
|
}
|
||||||
|
|
||||||
|
fun applyBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
|
||||||
|
return insulin
|
||||||
|
}
|
||||||
|
|
||||||
|
fun applyExtendedBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
|
||||||
|
return insulin
|
||||||
|
}
|
||||||
|
|
||||||
|
fun applyCarbsConstraints(carbs: Constraint<Int>): Constraint<Int> {
|
||||||
|
return carbs
|
||||||
|
}
|
||||||
|
|
||||||
|
fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||||
|
return maxIob
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
|
@ -287,7 +288,7 @@ public class APSResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChangeRequested() {
|
public boolean isChangeRequested() {
|
||||||
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
|
Constraint<Boolean> closedLoopEnabled = ConstraintChecker.getInstance().isClosedLoopAllowed();
|
||||||
// closed loop mode: handle change at driver level
|
// closed loop mode: handle change at driver level
|
||||||
if (closedLoopEnabled.value()) {
|
if (closedLoopEnabled.value()) {
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
|
|
|
@ -19,6 +19,8 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainActivity;
|
import info.nightscout.androidaps.MainActivity;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -48,6 +50,7 @@ import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
||||||
|
@ -271,7 +274,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
try {
|
try {
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
log.debug("invoke from " + initiator);
|
log.debug("invoke from " + initiator);
|
||||||
Constraint<Boolean> loopEnabled = MainApp.getConstraintChecker().isLoopInvokationAllowed();
|
Constraint<Boolean> loopEnabled = ConstraintChecker.getInstance().isLoopInvocationAllowed();
|
||||||
|
|
||||||
if (!loopEnabled.value()) {
|
if (!loopEnabled.value()) {
|
||||||
String message = MainApp.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons();
|
String message = MainApp.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons();
|
||||||
|
@ -319,13 +322,13 @@ public class LoopPlugin extends PluginBase {
|
||||||
// check rate for constrais
|
// check rate for constrais
|
||||||
final APSResult resultAfterConstraints = result.clone();
|
final APSResult resultAfterConstraints = result.clone();
|
||||||
resultAfterConstraints.rateConstraint = new Constraint<>(resultAfterConstraints.rate);
|
resultAfterConstraints.rateConstraint = new Constraint<>(resultAfterConstraints.rate);
|
||||||
resultAfterConstraints.rate = MainApp.getConstraintChecker().applyBasalConstraints(resultAfterConstraints.rateConstraint, profile).value();
|
resultAfterConstraints.rate = ConstraintChecker.getInstance().applyBasalConstraints(resultAfterConstraints.rateConstraint, profile).value();
|
||||||
|
|
||||||
resultAfterConstraints.percentConstraint = new Constraint<>(resultAfterConstraints.percent);
|
resultAfterConstraints.percentConstraint = new Constraint<>(resultAfterConstraints.percent);
|
||||||
resultAfterConstraints.percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(resultAfterConstraints.percentConstraint, profile).value();
|
resultAfterConstraints.percent = ConstraintChecker.getInstance().applyBasalPercentConstraints(resultAfterConstraints.percentConstraint, profile).value();
|
||||||
|
|
||||||
resultAfterConstraints.smbConstraint = new Constraint<>(resultAfterConstraints.smb);
|
resultAfterConstraints.smbConstraint = new Constraint<>(resultAfterConstraints.smb);
|
||||||
resultAfterConstraints.smb = MainApp.getConstraintChecker().applyBolusConstraints(resultAfterConstraints.smbConstraint).value();
|
resultAfterConstraints.smb = ConstraintChecker.getInstance().applyBolusConstraints(resultAfterConstraints.smbConstraint).value();
|
||||||
|
|
||||||
// safety check for multiple SMBs
|
// safety check for multiple SMBs
|
||||||
long lastBolusTime = TreatmentsPlugin.getPlugin().getLastBolusTime();
|
long lastBolusTime = TreatmentsPlugin.getPlugin().getLastBolusTime();
|
||||||
|
@ -359,7 +362,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
|
Constraint<Boolean> closedLoopEnabled = ConstraintChecker.getInstance().isClosedLoopAllowed();
|
||||||
|
|
||||||
if (closedLoopEnabled.value()) {
|
if (closedLoopEnabled.value()) {
|
||||||
if (resultAfterConstraints.isChangeRequested()
|
if (resultAfterConstraints.isChangeRequested()
|
||||||
|
|
|
@ -21,19 +21,19 @@ import java.nio.charset.StandardCharsets;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ public class DetermineBasalAdapterAMAJS {
|
||||||
mMealData.put("boluses", mealData.boluses);
|
mMealData.put("boluses", mealData.boluses);
|
||||||
mMealData.put("mealCOB", mealData.mealCOB);
|
mMealData.put("mealCOB", mealData.mealCOB);
|
||||||
|
|
||||||
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
|
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
|
||||||
mAutosensData = new JSONObject();
|
mAutosensData = new JSONObject();
|
||||||
mAutosensData.put("ratio", autosensDataRatio);
|
mAutosensData.put("ratio", autosensDataRatio);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.json.JSONException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
|
@ -128,7 +129,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
double maxBasal = ConstraintChecker.getInstance().getMaxBasalAllowed(profile).value();
|
||||||
double minBg = profile.getTargetLowMgdl();
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = profile.getTargetHighMgdl();
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
double targetBg = profile.getTargetMgdl();
|
double targetBg = profile.getTargetMgdl();
|
||||||
|
@ -147,7 +148,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
Profiler.log(log, "getMealData()", startPart);
|
Profiler.log(log, "getMealData()", startPart);
|
||||||
|
|
||||||
double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
||||||
|
|
||||||
minBg = HardLimits.verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
|
minBg = HardLimits.verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
|
||||||
maxBg = HardLimits.verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
maxBg = HardLimits.verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
||||||
|
@ -175,7 +176,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
|
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||||
if (autosensData == null) {
|
if (autosensData == null) {
|
||||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
|
||||||
|
|
|
@ -22,6 +22,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdat
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
|
@ -127,7 +128,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
double maxBasal = ConstraintChecker.getInstance().getMaxBasalAllowed(profile).value();
|
||||||
|
|
||||||
double minBg = profile.getTargetLowMgdl();
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = profile.getTargetHighMgdl();
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
|
@ -146,7 +147,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
|
|
||||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||||
|
|
||||||
double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
Profiler.log(log, "MA data gathering", start);
|
Profiler.log(log, "MA data gathering", start);
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,17 @@ import javax.annotation.Nullable;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
import info.nightscout.androidaps.utils.SafeParse;
|
||||||
|
@ -315,7 +316,7 @@ public class DetermineBasalAdapterSMBJS {
|
||||||
mMealData.put("lastCarbTime", mealData.lastCarbTime);
|
mMealData.put("lastCarbTime", mealData.lastCarbTime);
|
||||||
|
|
||||||
|
|
||||||
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
|
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
|
||||||
mAutosensData = new JSONObject();
|
mAutosensData = new JSONObject();
|
||||||
mAutosensData.put("ratio", autosensDataRatio);
|
mAutosensData.put("ratio", autosensDataRatio);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSSMB;
|
package info.nightscout.androidaps.plugins.aps.openAPSSMB;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -24,6 +25,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdat
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
||||||
|
@ -134,7 +136,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
|
|
||||||
Constraint<Double> inputConstraints = new Constraint<>(0d); // fake. only for collecting all results
|
Constraint<Double> inputConstraints = new Constraint<>(0d); // fake. only for collecting all results
|
||||||
|
|
||||||
Constraint<Double> maxBasalConstraint = MainApp.getConstraintChecker().getMaxBasalAllowed(profile);
|
Constraint<Double> maxBasalConstraint = ConstraintChecker.getInstance().getMaxBasalAllowed(profile);
|
||||||
inputConstraints.copyReasons(maxBasalConstraint);
|
inputConstraints.copyReasons(maxBasalConstraint);
|
||||||
double maxBasal = maxBasalConstraint.value();
|
double maxBasal = maxBasalConstraint.value();
|
||||||
double minBg = profile.getTargetLowMgdl();
|
double minBg = profile.getTargetLowMgdl();
|
||||||
|
@ -151,7 +153,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
Profiler.log(log, "getMealData()", startPart);
|
Profiler.log(log, "getMealData()", startPart);
|
||||||
|
|
||||||
Constraint<Double> maxIOBAllowedConstraint = MainApp.getConstraintChecker().getMaxIOBAllowed();
|
Constraint<Double> maxIOBAllowedConstraint = ConstraintChecker.getInstance().getMaxIOBAllowed();
|
||||||
inputConstraints.copyReasons(maxIOBAllowedConstraint);
|
inputConstraints.copyReasons(maxIOBAllowedConstraint);
|
||||||
double maxIob = maxIOBAllowedConstraint.value();
|
double maxIob = maxIOBAllowedConstraint.value();
|
||||||
|
|
||||||
|
@ -181,7 +183,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
return;
|
return;
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
|
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||||
if (autosensData == null) {
|
if (autosensData == null) {
|
||||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
|
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
|
||||||
|
@ -199,15 +201,15 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
|
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
|
||||||
MainApp.getConstraintChecker().isSMBModeEnabled(smbAllowed);
|
ConstraintChecker.getInstance().isSMBModeEnabled(smbAllowed);
|
||||||
inputConstraints.copyReasons(smbAllowed);
|
inputConstraints.copyReasons(smbAllowed);
|
||||||
|
|
||||||
Constraint<Boolean> advancedFiltering = new Constraint<>(!tempBasalFallback);
|
Constraint<Boolean> advancedFiltering = new Constraint<>(!tempBasalFallback);
|
||||||
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering);
|
ConstraintChecker.getInstance().isAdvancedFilteringEnabled(advancedFiltering);
|
||||||
inputConstraints.copyReasons(advancedFiltering);
|
inputConstraints.copyReasons(advancedFiltering);
|
||||||
|
|
||||||
Constraint<Boolean> uam = new Constraint<>(true);
|
Constraint<Boolean> uam = new Constraint<>(true);
|
||||||
MainApp.getConstraintChecker().isUAMEnabled(uam);
|
ConstraintChecker.getInstance().isUAMEnabled(uam);
|
||||||
inputConstraints.copyReasons(uam);
|
inputConstraints.copyReasons(uam);
|
||||||
|
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.APS))
|
||||||
|
@ -285,6 +287,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
return newvalue;
|
return newvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
public Constraint<Boolean> isSuperBolusEnabled(Constraint<Boolean> value) {
|
public Constraint<Boolean> isSuperBolusEnabled(Constraint<Boolean> value) {
|
||||||
value.set(false);
|
value.set(false);
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -367,7 +367,7 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
*/
|
*/
|
||||||
private <T> T determineActivePlugin(Class<T> pluginInterface, PluginType pluginType) {
|
private <T> T determineActivePlugin(Class<T> pluginInterface, PluginType pluginType) {
|
||||||
ArrayList<PluginBase> pluginsInCategory;
|
ArrayList<PluginBase> pluginsInCategory;
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(pluginInterface);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(pluginInterface);
|
||||||
|
|
||||||
return this.determineActivePlugin(pluginsInCategory, pluginType);
|
return this.determineActivePlugin(pluginsInCategory, pluginType);
|
||||||
}
|
}
|
||||||
|
@ -443,23 +443,23 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
break;
|
break;
|
||||||
// Single selection allowed
|
// Single selection allowed
|
||||||
case INSULIN:
|
case INSULIN:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(InsulinInterface.class);
|
||||||
break;
|
break;
|
||||||
case SENSITIVITY:
|
case SENSITIVITY:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(SensitivityInterface.class);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(SensitivityInterface.class);
|
||||||
break;
|
break;
|
||||||
case APS:
|
case APS:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(APSInterface.class);
|
||||||
break;
|
break;
|
||||||
case PROFILE:
|
case PROFILE:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(ProfileInterface.class);
|
||||||
break;
|
break;
|
||||||
case BGSOURCE:
|
case BGSOURCE:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(BgSourceInterface.class);
|
||||||
break;
|
break;
|
||||||
case TREATMENT:
|
case TREATMENT:
|
||||||
case PUMP:
|
case PUMP:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class);
|
pluginsInCategory = MainApp.instance().getSpecificPluginsListByInterface(PumpInterface.class);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pluginsInCategory != null) {
|
if (pluginsInCategory != null) {
|
||||||
|
|
|
@ -0,0 +1,205 @@
|
||||||
|
package info.nightscout.androidaps.plugins.configBuilder
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class ConstraintChecker @Inject constructor(private val mainApp: MainApp) : ConstraintsInterface {
|
||||||
|
|
||||||
|
init {
|
||||||
|
instance = this
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
lateinit var instance: ConstraintChecker
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isLoopInvocationAllowed(): Constraint<Boolean> =
|
||||||
|
isLoopInvocationAllowed(Constraint(true))
|
||||||
|
|
||||||
|
fun isClosedLoopAllowed(): Constraint<Boolean> =
|
||||||
|
isClosedLoopAllowed(Constraint(true))
|
||||||
|
|
||||||
|
fun isAutosensModeEnabled(): Constraint<Boolean> =
|
||||||
|
isAutosensModeEnabled(Constraint(true))
|
||||||
|
|
||||||
|
fun isAMAModeEnabled(): Constraint<Boolean> =
|
||||||
|
isAMAModeEnabled(Constraint(true))
|
||||||
|
|
||||||
|
fun isSMBModeEnabled(): Constraint<Boolean> =
|
||||||
|
isSMBModeEnabled(Constraint(true))
|
||||||
|
|
||||||
|
fun isUAMEnabled(): Constraint<Boolean> =
|
||||||
|
isUAMEnabled(Constraint(true))
|
||||||
|
|
||||||
|
fun isAdvancedFilteringEnabled(): Constraint<Boolean> =
|
||||||
|
isAdvancedFilteringEnabled(Constraint(true))
|
||||||
|
|
||||||
|
fun isSuperBolusEnabled(): Constraint<Boolean> =
|
||||||
|
isSuperBolusEnabled(Constraint(true))
|
||||||
|
|
||||||
|
fun getMaxBasalAllowed(profile: Profile): Constraint<Double> =
|
||||||
|
applyBasalConstraints(Constraint(Constants.REALLYHIGHBASALRATE), profile)
|
||||||
|
|
||||||
|
fun getMaxBasalPercentAllowed(profile: Profile): Constraint<Int> =
|
||||||
|
applyBasalPercentConstraints(Constraint(Constants.REALLYHIGHPERCENTBASALRATE), profile)
|
||||||
|
|
||||||
|
fun getMaxBolusAllowed(): Constraint<Double> =
|
||||||
|
applyBolusConstraints(Constraint(Constants.REALLYHIGHBOLUS))
|
||||||
|
|
||||||
|
fun getMaxExtendedBolusAllowed(): Constraint<Double> =
|
||||||
|
applyExtendedBolusConstraints(Constraint(Constants.REALLYHIGHBOLUS))
|
||||||
|
|
||||||
|
fun getMaxCarbsAllowed(): Constraint<Int> =
|
||||||
|
applyCarbsConstraints(Constraint(Constants.REALLYHIGHCARBS))
|
||||||
|
|
||||||
|
fun getMaxIOBAllowed(): Constraint<Double> =
|
||||||
|
applyMaxIOBConstraints(Constraint(Constants.REALLYHIGHIOB))
|
||||||
|
|
||||||
|
override fun isLoopInvocationAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isLoopInvocationAllowed(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isClosedLoopAllowed(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isClosedLoopAllowed(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isAutosensModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isAutosensModeEnabled(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isAMAModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constrain = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constrain.isAMAModeEnabled(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSMBModeEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isSMBModeEnabled(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isUAMEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isUAMEnabled(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isAdvancedFilteringEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isAdvancedFilteringEnabled(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSuperBolusEnabled(value: Constraint<Boolean>): Constraint<Boolean> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.isSuperBolusEnabled(value)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyBasalConstraints(absoluteRate: Constraint<Double>, profile: Profile): Constraint<Double> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constraint = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constraint.applyBasalConstraints(absoluteRate, profile)
|
||||||
|
}
|
||||||
|
return absoluteRate
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyBasalPercentConstraints(percentRate: Constraint<Int>, profile: Profile): Constraint<Int> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constrain = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constrain.applyBasalPercentConstraints(percentRate, profile)
|
||||||
|
}
|
||||||
|
return percentRate
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constrain = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constrain.applyBolusConstraints(insulin)
|
||||||
|
}
|
||||||
|
return insulin
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyExtendedBolusConstraints(insulin: Constraint<Double>): Constraint<Double> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constrain = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constrain.applyExtendedBolusConstraints(insulin)
|
||||||
|
}
|
||||||
|
return insulin
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyCarbsConstraints(carbs: Constraint<Int>): Constraint<Int> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constrain = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constrain.applyCarbsConstraints(carbs)
|
||||||
|
}
|
||||||
|
return carbs
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||||
|
val constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface::class.java)
|
||||||
|
for (p in constraintsPlugins) {
|
||||||
|
val constrain = p as ConstraintsInterface
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue
|
||||||
|
constrain.applyMaxIOBConstraints(maxIob)
|
||||||
|
}
|
||||||
|
return maxIob
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,8 +2,8 @@ package info.nightscout.androidaps.plugins.constraints.objectives.objectives;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
|
|
||||||
public class Objective6 extends Objective {
|
public class Objective6 extends Objective {
|
||||||
|
@ -18,7 +18,7 @@ public class Objective6 extends Objective {
|
||||||
tasks.add(new Task(R.string.maxiobset) {
|
tasks.add(new Task(R.string.maxiobset) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isCompleted() {
|
public boolean isCompleted() {
|
||||||
double maxIOB = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
double maxIOB = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
||||||
return maxIOB > 0;
|
return maxIOB > 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.constraints.safety;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
import info.nightscout.androidaps.interfaces.BgSourceInterface;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
|
@ -18,6 +17,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
|
||||||
|
@ -90,8 +90,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
boolean enabled = SP.getBoolean(R.string.key_use_smb, false);
|
boolean enabled = SP.getBoolean(R.string.key_use_smb, false);
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
value.set(false, MainApp.gs(R.string.smbdisabledinpreferences), this);
|
value.set(false, MainApp.gs(R.string.smbdisabledinpreferences), this);
|
||||||
ConstraintChecker constraintChecker = MainApp.getConstraintChecker();
|
Constraint<Boolean> closedLoop = ConstraintChecker.getInstance().isClosedLoopAllowed();
|
||||||
Constraint<Boolean> closedLoop = constraintChecker.isClosedLoopAllowed();
|
|
||||||
if (!closedLoop.value())
|
if (!closedLoop.value())
|
||||||
value.set(false, MainApp.gs(R.string.smbnotallowedinopenloopmode), this);
|
value.set(false, MainApp.gs(R.string.smbnotallowedinopenloopmode), this);
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -46,6 +46,7 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
@ -272,11 +273,11 @@ public class NewNSTreatmentDialog extends AppCompatDialogFragment implements Vie
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Integer maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value();
|
Integer maxCarbs = ConstraintChecker.getInstance().getMaxCarbsAllowed().value();
|
||||||
editCarbs = view.findViewById(R.id.careportal_newnstreatment_carbsinput);
|
editCarbs = view.findViewById(R.id.careportal_newnstreatment_carbsinput);
|
||||||
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
Double maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value();
|
Double maxInsulin = ConstraintChecker.getInstance().getMaxBolusAllowed().value();
|
||||||
editInsulin = view.findViewById(R.id.careportal_newnstreatment_insulininput);
|
editInsulin = view.findViewById(R.id.careportal_newnstreatment_insulininput);
|
||||||
editInsulin.setParams(0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false, view.findViewById(R.id.ok));
|
editInsulin.setParams(0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false, view.findViewById(R.id.ok));
|
||||||
|
|
||||||
|
@ -305,7 +306,7 @@ public class NewNSTreatmentDialog extends AppCompatDialogFragment implements Vie
|
||||||
|
|
||||||
Integer maxPercent = 200;
|
Integer maxPercent = 200;
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
maxPercent = MainApp.getConstraintChecker().getMaxBasalPercentAllowed(profile).value();
|
maxPercent = ConstraintChecker.getInstance().getMaxBasalPercentAllowed(profile).value();
|
||||||
editPercent = view.findViewById(R.id.careportal_newnstreatment_percentinput);
|
editPercent = view.findViewById(R.id.careportal_newnstreatment_percentinput);
|
||||||
editPercent.setParams(0d, -100d, (double) maxPercent, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok), percentTextWatcher);
|
editPercent.setParams(0d, -100d, (double) maxPercent, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok), percentTextWatcher);
|
||||||
|
|
||||||
|
@ -329,7 +330,7 @@ public class NewNSTreatmentDialog extends AppCompatDialogFragment implements Vie
|
||||||
|
|
||||||
Double maxAbsolute = HardLimits.maxBasal();
|
Double maxAbsolute = HardLimits.maxBasal();
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
maxAbsolute = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value();
|
maxAbsolute = ConstraintChecker.getInstance().getMaxBasalAllowed(profile).value();
|
||||||
editAbsolute = view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
|
editAbsolute = view.findViewById(R.id.careportal_newnstreatment_absoluteinput);
|
||||||
editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true, view.findViewById(R.id.ok), absoluteTextWatcher);
|
editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true, view.findViewById(R.id.ok), absoluteTextWatcher);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
@ -90,6 +89,7 @@ import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
|
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
@ -930,7 +930,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true);
|
final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true);
|
||||||
|
|
||||||
if (wizard.getCalculatedTotalInsulin() > 0d && quickWizardEntry.carbs() > 0d) {
|
if (wizard.getCalculatedTotalInsulin() > 0d && quickWizardEntry.carbs() > 0d) {
|
||||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(quickWizardEntry.carbs())).value();
|
Integer carbsAfterConstraints = ConstraintChecker.getInstance().applyCarbsConstraints(new Constraint<>(quickWizardEntry.carbs())).value();
|
||||||
|
|
||||||
if (Math.abs(wizard.getInsulinAfterConstraints() - wizard.getCalculatedTotalInsulin()) >= pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(wizard.getInsulinAfterConstraints()) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
|
if (Math.abs(wizard.getInsulinAfterConstraints() - wizard.getCalculatedTotalInsulin()) >= pump.getPumpDescription().pumpType.determineCorrectBolusStepSize(wizard.getInsulinAfterConstraints()) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
|
||||||
OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
|
OKDialog.show(getContext(), MainApp.gs(R.string.treatmentdeliveryerror), MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput));
|
||||||
|
@ -1059,7 +1059,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
|
Constraint<Boolean> closedLoopEnabled = ConstraintChecker.getInstance().isClosedLoopAllowed();
|
||||||
|
|
||||||
// open loop mode
|
// open loop mode
|
||||||
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
|
||||||
|
|
|
@ -10,7 +10,6 @@ import android.telephony.SmsMessage
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import com.andreabaccega.widget.ValidatingEditTextPreference
|
import com.andreabaccega.widget.ValidatingEditTextPreference
|
||||||
import info.nightscout.androidaps.Constants
|
import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
|
@ -28,6 +27,7 @@ import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus.send
|
import info.nightscout.androidaps.plugins.bus.RxBus.send
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus.toObservable
|
import info.nightscout.androidaps.plugins.bus.RxBus.toObservable
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||||
|
@ -52,7 +52,8 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
class SmsCommunicatorPlugin @Inject constructor(
|
class SmsCommunicatorPlugin @Inject constructor(
|
||||||
val configBuilderPlugin: ConfigBuilderPlugin,
|
val configBuilderPlugin: ConfigBuilderPlugin,
|
||||||
val resourceHelper: ResourceHelper
|
val resourceHelper: ResourceHelper,
|
||||||
|
val constraintChecker: ConstraintChecker
|
||||||
) : PluginBase(PluginDescription()
|
) : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
.fragmentClass(SmsCommunicatorFragment::class.java.name)
|
.fragmentClass(SmsCommunicatorFragment::class.java.name)
|
||||||
|
@ -506,7 +507,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
else if (tempBasalPct == 0 && splitted[1] != "0%") sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
else if (tempBasalPct == 0 && splitted[1] != "0%") sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else if (duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
else if (duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else {
|
else {
|
||||||
tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(Constraint(tempBasalPct), profile).value()
|
tempBasalPct = constraintChecker.applyBasalPercentConstraints(Constraint(tempBasalPct), profile).value()
|
||||||
val passCode = generatePasscode()
|
val passCode = generatePasscode()
|
||||||
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, duration, passCode)
|
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, duration, passCode)
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
|
@ -538,7 +539,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
else if (tempBasal == 0.0 && splitted[1] != "0") sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
else if (tempBasal == 0.0 && splitted[1] != "0") sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else if (duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
else if (duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else {
|
else {
|
||||||
tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(Constraint(tempBasal), profile).value()
|
tempBasal = constraintChecker.applyBasalConstraints(Constraint(tempBasal), profile).value()
|
||||||
val passCode = generatePasscode()
|
val passCode = generatePasscode()
|
||||||
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, duration, passCode)
|
val reply = String.format(resourceHelper.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, duration, passCode)
|
||||||
receivedSms.processed = true
|
receivedSms.processed = true
|
||||||
|
@ -591,7 +592,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
var extended = SafeParse.stringToDouble(splitted[1])
|
var extended = SafeParse.stringToDouble(splitted[1])
|
||||||
val duration = SafeParse.stringToInt(splitted[2])
|
val duration = SafeParse.stringToInt(splitted[2])
|
||||||
extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(Constraint(extended)).value()
|
extended = constraintChecker.applyExtendedBolusConstraints(Constraint(extended)).value()
|
||||||
if (extended == 0.0 || duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
if (extended == 0.0 || duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else {
|
else {
|
||||||
val passCode = generatePasscode()
|
val passCode = generatePasscode()
|
||||||
|
@ -621,7 +622,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
private fun processBOLUS(splitted: Array<String>, receivedSms: Sms) {
|
private fun processBOLUS(splitted: Array<String>, receivedSms: Sms) {
|
||||||
var bolus = SafeParse.stringToDouble(splitted[1])
|
var bolus = SafeParse.stringToDouble(splitted[1])
|
||||||
val isMeal = splitted.size > 2 && splitted[2].equals("MEAL", ignoreCase = true)
|
val isMeal = splitted.size > 2 && splitted[2].equals("MEAL", ignoreCase = true)
|
||||||
bolus = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(bolus)).value()
|
bolus = constraintChecker.applyBolusConstraints(Constraint(bolus)).value()
|
||||||
if (splitted.size == 3 && !isMeal) {
|
if (splitted.size == 3 && !isMeal) {
|
||||||
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
} else if (bolus > 0.0) {
|
} else if (bolus > 0.0) {
|
||||||
|
@ -701,7 +702,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
time = midnight + T.secs(seconds.toLong()).msecs()
|
time = midnight + T.secs(seconds.toLong()).msecs()
|
||||||
}
|
}
|
||||||
grams = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(grams)).value()
|
grams = constraintChecker.applyCarbsConstraints(Constraint(grams)).value()
|
||||||
if (grams == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
if (grams == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
|
||||||
else {
|
else {
|
||||||
val passCode = generatePasscode()
|
val passCode = generatePasscode()
|
||||||
|
|
|
@ -35,6 +35,7 @@ import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
|
@ -95,7 +96,7 @@ public class ActionStringHandler {
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
|
Double insulinAfterConstraints = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
|
||||||
rMessage += MainApp.gs(R.string.primefill) + ": " + insulinAfterConstraints + "U";
|
rMessage += MainApp.gs(R.string.primefill) + ": " + insulinAfterConstraints + "U";
|
||||||
if (insulinAfterConstraints - amount != 0)
|
if (insulinAfterConstraints - amount != 0)
|
||||||
rMessage += "\n" + MainApp.gs(R.string.constraintapllied);
|
rMessage += "\n" + MainApp.gs(R.string.constraintapllied);
|
||||||
|
@ -106,7 +107,7 @@ public class ActionStringHandler {
|
||||||
////////////////////////////////////////////// PRIME/FILL
|
////////////////////////////////////////////// PRIME/FILL
|
||||||
double amount = SafeParse.stringToDouble(act[1]);
|
double amount = SafeParse.stringToDouble(act[1]);
|
||||||
|
|
||||||
Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
|
Double insulinAfterConstraints = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
|
||||||
rMessage += MainApp.gs(R.string.primefill) + ": " + insulinAfterConstraints + "U";
|
rMessage += MainApp.gs(R.string.primefill) + ": " + insulinAfterConstraints + "U";
|
||||||
if (insulinAfterConstraints - amount != 0)
|
if (insulinAfterConstraints - amount != 0)
|
||||||
rMessage += "\n" + MainApp.gs(R.string.constraintapllied);
|
rMessage += "\n" + MainApp.gs(R.string.constraintapllied);
|
||||||
|
@ -117,8 +118,8 @@ public class ActionStringHandler {
|
||||||
////////////////////////////////////////////// BOLUS
|
////////////////////////////////////////////// BOLUS
|
||||||
double insulin = SafeParse.stringToDouble(act[1]);
|
double insulin = SafeParse.stringToDouble(act[1]);
|
||||||
int carbs = SafeParse.stringToInt(act[2]);
|
int carbs = SafeParse.stringToInt(act[2]);
|
||||||
Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(insulin)).value();
|
Double insulinAfterConstraints = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(insulin)).value();
|
||||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
Integer carbsAfterConstraints = ConstraintChecker.getInstance().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
||||||
rMessage += MainApp.gs(R.string.bolus) + ": " + insulinAfterConstraints + "U\n";
|
rMessage += MainApp.gs(R.string.bolus) + ": " + insulinAfterConstraints + "U\n";
|
||||||
rMessage += MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
rMessage += MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
||||||
|
|
||||||
|
@ -180,7 +181,7 @@ public class ActionStringHandler {
|
||||||
} else if ("wizard2".equals(act[0])) {
|
} else if ("wizard2".equals(act[0])) {
|
||||||
////////////////////////////////////////////// WIZARD
|
////////////////////////////////////////////// WIZARD
|
||||||
Integer carbsBeforeConstraints = SafeParse.stringToInt(act[1]);
|
Integer carbsBeforeConstraints = SafeParse.stringToInt(act[1]);
|
||||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbsBeforeConstraints)).value();
|
Integer carbsAfterConstraints = ConstraintChecker.getInstance().applyCarbsConstraints(new Constraint<>(carbsBeforeConstraints)).value();
|
||||||
|
|
||||||
if (carbsAfterConstraints - carbsBeforeConstraints != 0) {
|
if (carbsAfterConstraints - carbsBeforeConstraints != 0) {
|
||||||
sendError("Carb constraint violation!");
|
sendError("Carb constraint violation!");
|
||||||
|
@ -324,7 +325,7 @@ public class ActionStringHandler {
|
||||||
int starttime = SafeParse.stringToInt(act[2]);
|
int starttime = SafeParse.stringToInt(act[2]);
|
||||||
int duration = SafeParse.stringToInt(act[3]);
|
int duration = SafeParse.stringToInt(act[3]);
|
||||||
long starttimestamp = System.currentTimeMillis() + starttime * 60 * 1000;
|
long starttimestamp = System.currentTimeMillis() + starttime * 60 * 1000;
|
||||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
Integer carbsAfterConstraints = ConstraintChecker.getInstance().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
||||||
rMessage += MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
rMessage += MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g";
|
||||||
rMessage += "\n" + MainApp.gs(R.string.time) + ": " + DateUtil.timeString(starttimestamp);
|
rMessage += "\n" + MainApp.gs(R.string.time) + ": " + DateUtil.timeString(starttimestamp);
|
||||||
rMessage += "\n" + MainApp.gs(R.string.duration) + ": " + duration + "h";
|
rMessage += "\n" + MainApp.gs(R.string.duration) + ": " + duration + "h";
|
||||||
|
@ -491,7 +492,7 @@ public class ActionStringHandler {
|
||||||
// decide if enabled/disabled closed/open; what Plugin as APS?
|
// decide if enabled/disabled closed/open; what Plugin as APS?
|
||||||
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
|
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
|
||||||
if (loopPlugin.isEnabled(loopPlugin.getType())) {
|
if (loopPlugin.isEnabled(loopPlugin.getType())) {
|
||||||
if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) {
|
if (ConstraintChecker.getInstance().isClosedLoopAllowed().value()) {
|
||||||
ret += "CLOSED LOOP\n";
|
ret += "CLOSED LOOP\n";
|
||||||
} else {
|
} else {
|
||||||
ret += "OPEN LOOP\n";
|
ret += "OPEN LOOP\n";
|
||||||
|
@ -591,7 +592,7 @@ public class ActionStringHandler {
|
||||||
|
|
||||||
if ("fill".equals(act[0])) {
|
if ("fill".equals(act[0])) {
|
||||||
Double amount = SafeParse.stringToDouble(act[1]);
|
Double amount = SafeParse.stringToDouble(act[1]);
|
||||||
Double insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
|
Double insulinAfterConstraints = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
|
||||||
if (amount - insulinAfterConstraints != 0) {
|
if (amount - insulinAfterConstraints != 0) {
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance(), "aborting: previously applied constraint changed");
|
ToastUtils.showToastInUiThread(MainApp.instance(), "aborting: previously applied constraint changed");
|
||||||
sendError("aborting: previously applied constraint changed");
|
sendError("aborting: previously applied constraint changed");
|
||||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
|
@ -178,7 +179,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
percent = ConstraintChecker.getInstance().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||||
if (percent < 0) {
|
if (percent < 0) {
|
||||||
result.isTempCancel = false;
|
result.isTempCancel = false;
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -227,7 +228,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
insulin = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
|
insulin = ConstraintChecker.getInstance().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().extendedBolusStep);
|
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
|
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService;
|
import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService;
|
||||||
|
@ -139,7 +140,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
Treatment t = new Treatment();
|
Treatment t = new Treatment();
|
||||||
t.isSMB = detailedBolusInfo.isSMB;
|
t.isSMB = detailedBolusInfo.isSMB;
|
||||||
|
@ -183,7 +184,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
absoluteRate = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
absoluteRate = ConstraintChecker.getInstance().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
||||||
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
||||||
|
@ -280,7 +281,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||||
Integer durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
Integer durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||||
// We keep current basal running so need to sub current basal
|
// We keep current basal running so need to sub current basal
|
||||||
Double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
Double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
||||||
extendedRateToSet = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value();
|
extendedRateToSet = ConstraintChecker.getInstance().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.extendedBolusStep * 2); // *2 because of halfhours
|
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
|
||||||
public class MsgBolusStart extends MessageBase {
|
public class MsgBolusStart extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
||||||
|
@ -20,7 +20,7 @@ public class MsgBolusStart extends MessageBase {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
// HARDCODED LIMIT
|
// HARDCODED LIMIT
|
||||||
amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
|
amount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
|
||||||
|
|
||||||
AddParamInt((int) (amount * 100));
|
AddParamInt((int) (amount * 100));
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
|
||||||
public class MsgBolusStartWithSpeed extends MessageBase {
|
public class MsgBolusStartWithSpeed extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
||||||
|
@ -20,7 +20,7 @@ public class MsgBolusStartWithSpeed extends MessageBase {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
// HARDCODED LIMIT
|
// HARDCODED LIMIT
|
||||||
amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
|
amount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
|
||||||
|
|
||||||
AddParamInt((int) (amount * 100));
|
AddParamInt((int) (amount * 100));
|
||||||
AddParamByte((byte) speed);
|
AddParamByte((byte) speed);
|
||||||
|
|
|
@ -3,9 +3,9 @@ package info.nightscout.androidaps.plugins.pump.danaR.comm;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
|
||||||
public class MsgSetExtendedBolusStart extends MessageBase {
|
public class MsgSetExtendedBolusStart extends MessageBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
||||||
|
@ -22,13 +22,8 @@ public class MsgSetExtendedBolusStart extends MessageBase {
|
||||||
// HARDCODED LIMITS
|
// HARDCODED LIMITS
|
||||||
if (halfhours < 1) halfhours = 1;
|
if (halfhours < 1) halfhours = 1;
|
||||||
if (halfhours > 16) halfhours = 16;
|
if (halfhours > 16) halfhours = 16;
|
||||||
Constraint<Double> constrainedAmount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount));
|
Constraint<Double> constrainedAmount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount));
|
||||||
if (constrainedAmount != null) {
|
|
||||||
AddParamInt((int) (constrainedAmount.value() * 100));
|
AddParamInt((int) (constrainedAmount.value() * 100));
|
||||||
} else {
|
|
||||||
log.error("constrainedAmount of insulin is null!!");
|
|
||||||
AddParamInt(0);
|
|
||||||
}
|
|
||||||
AddParamByte(halfhours);
|
AddParamByte(halfhours);
|
||||||
if (L.isEnabled(L.PUMPCOMM))
|
if (L.isEnabled(L.PUMPCOMM))
|
||||||
log.debug("Set extended bolus start: " + (((int) (amount * 100)) / 100d) + "U halfhours: " + (int) halfhours);
|
log.debug("Set extended bolus start: " + (((int) (amount * 100)) / 100d) + "U halfhours: " + (int) halfhours);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||||
|
@ -142,7 +143,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
Treatment t = new Treatment();
|
Treatment t = new Treatment();
|
||||||
t.isSMB = detailedBolusInfo.isSMB;
|
t.isSMB = detailedBolusInfo.isSMB;
|
||||||
|
@ -186,7 +187,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
absoluteRate = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
absoluteRate = ConstraintChecker.getInstance().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
||||||
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
||||||
|
@ -283,7 +284,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
Integer durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
Integer durationInHalfHours = Math.max(durationInMinutes / 30, 1);
|
||||||
// We keep current basal running so need to sub current basal
|
// We keep current basal running so need to sub current basal
|
||||||
Double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
Double extendedRateToSet = absoluteRate - getBaseBasalRate();
|
||||||
extendedRateToSet = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(extendedRateToSet), profile).value();
|
extendedRateToSet = ConstraintChecker.getInstance().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.extendedBolusStep * 2); // *2 because of halfhours
|
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.content.ServiceConnection;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -23,7 +22,6 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -39,6 +37,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||||
|
@ -370,7 +369,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
int preferencesSpeed = SP.getInt(R.string.key_danars_bolusspeed, 0);
|
||||||
int speed = 12;
|
int speed = 12;
|
||||||
|
@ -462,7 +461,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
absoluteRate = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
absoluteRate = ConstraintChecker.getInstance().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
||||||
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
||||||
|
@ -539,7 +538,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
percent = ConstraintChecker.getInstance().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||||
if (percent < 0) {
|
if (percent < 0) {
|
||||||
result.isTempCancel = false;
|
result.isTempCancel = false;
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
@ -616,7 +615,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
||||||
@Override
|
@Override
|
||||||
public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
insulin = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
|
insulin = ConstraintChecker.getInstance().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().extendedBolusStep);
|
insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep);
|
||||||
|
|
|
@ -5,9 +5,9 @@ import com.cozmo.danar.util.BleCommandUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
|
||||||
public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
|
public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
|
||||||
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
||||||
|
@ -28,7 +28,7 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
// HARDCODED LIMIT - if there is one that could be created
|
// HARDCODED LIMIT - if there is one that could be created
|
||||||
amount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)).value();
|
amount = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(amount)).value();
|
||||||
|
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
||||||
|
@ -128,7 +129,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
// Pump interface
|
// Pump interface
|
||||||
@Override
|
@Override
|
||||||
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) {
|
||||||
// v2 stores end time for bolus, we need to adjust time
|
// v2 stores end time for bolus, we need to adjust time
|
||||||
// default delivery speed is 12 sec/U
|
// default delivery speed is 12 sec/U
|
||||||
|
@ -204,7 +205,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
|
|
||||||
absoluteRate = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
absoluteRate = ConstraintChecker.getInstance().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
final boolean doTempOff = getBaseBasalRate() - absoluteRate == 0d;
|
||||||
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
final boolean doLowTemp = absoluteRate < getBaseBasalRate();
|
||||||
|
@ -279,7 +280,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
PumpEnactResult result = new PumpEnactResult();
|
PumpEnactResult result = new PumpEnactResult();
|
||||||
percent = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
percent = ConstraintChecker.getInstance().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||||
if (percent < 0) {
|
if (percent < 0) {
|
||||||
result.isTempCancel = false;
|
result.isTempCancel = false;
|
||||||
result.enacted = false;
|
result.enacted = false;
|
||||||
|
|
|
@ -13,20 +13,23 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.activities.BolusProgressHelperActivity;
|
import info.nightscout.androidaps.activities.BolusProgressHelperActivity;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
||||||
import info.nightscout.androidaps.events.EventBolusRequested;
|
import info.nightscout.androidaps.events.EventBolusRequested;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.dialogs.BolusProgressDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
|
@ -236,8 +239,8 @@ public class CommandQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply constraints
|
// apply constraints
|
||||||
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
detailedBolusInfo.insulin = ConstraintChecker.getInstance().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
|
||||||
detailedBolusInfo.carbs = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>((int) detailedBolusInfo.carbs)).value();
|
detailedBolusInfo.carbs = ConstraintChecker.getInstance().applyCarbsConstraints(new Constraint<>((int) detailedBolusInfo.carbs)).value();
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
if (detailedBolusInfo.isSMB) {
|
if (detailedBolusInfo.isSMB) {
|
||||||
|
@ -293,7 +296,7 @@ public class CommandQueue {
|
||||||
// remove all unfinished
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.TEMPBASAL);
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
Double rateAfterConstraints = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
Double rateAfterConstraints = ConstraintChecker.getInstance().applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
add(new CommandTempBasalAbsolute(rateAfterConstraints, durationInMinutes, enforceNew, profile, callback));
|
add(new CommandTempBasalAbsolute(rateAfterConstraints, durationInMinutes, enforceNew, profile, callback));
|
||||||
|
@ -314,7 +317,7 @@ public class CommandQueue {
|
||||||
// remove all unfinished
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.TEMPBASAL);
|
removeAll(Command.CommandType.TEMPBASAL);
|
||||||
|
|
||||||
Integer percentAfterConstraints = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
Integer percentAfterConstraints = ConstraintChecker.getInstance().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
|
||||||
|
|
||||||
// add new command to queue
|
// add new command to queue
|
||||||
add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, enforceNew, profile, callback));
|
add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, enforceNew, profile, callback));
|
||||||
|
@ -332,7 +335,7 @@ public class CommandQueue {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Double rateAfterConstraints = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
|
Double rateAfterConstraints = ConstraintChecker.getInstance().applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
|
||||||
|
|
||||||
// remove all unfinished
|
// remove all unfinished
|
||||||
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
removeAll(Command.CommandType.EXTENDEDBOLUS);
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.logging.L
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||||
|
@ -186,7 +187,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile,
|
||||||
?: 0.1
|
?: 0.1
|
||||||
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep)
|
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep)
|
||||||
|
|
||||||
insulinAfterConstraints = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
|
insulinAfterConstraints = ConstraintChecker.instance.applyBolusConstraints(Constraint(calculatedTotalInsulin)).value()
|
||||||
|
|
||||||
log.debug(this.toString())
|
log.debug(this.toString())
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import info.nightscout.androidaps.BuildConfig;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin;
|
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,7 +114,7 @@ public class FabricPrivacy {
|
||||||
public static void setUserStats() {
|
public static void setUserStats() {
|
||||||
if (!fabricEnabled()) return;
|
if (!fabricEnabled()) return;
|
||||||
|
|
||||||
String closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed().value() ? "CLOSED_LOOP_ENABLED" : "CLOSED_LOOP_DISABLED";
|
String closedLoopEnabled = ConstraintChecker.getInstance().isClosedLoopAllowed().value() ? "CLOSED_LOOP_ENABLED" : "CLOSED_LOOP_DISABLED";
|
||||||
// Size is limited to 36 chars
|
// Size is limited to 36 chars
|
||||||
String remote = BuildConfig.REMOTE.toLowerCase()
|
String remote = BuildConfig.REMOTE.toLowerCase()
|
||||||
.replace("https://", "")
|
.replace("https://", "")
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info;
|
package info;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
|
@ -15,7 +14,7 @@ import java.util.Locale;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
|
@ -25,9 +24,6 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.CommandQueue;
|
import info.nightscout.androidaps.queue.CommandQueue;
|
||||||
|
|
|
@ -16,7 +16,7 @@ import java.util.ArrayList;
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
||||||
|
@ -63,7 +63,7 @@ public class ConstraintsCheckerTest {
|
||||||
comboPlugin.setPluginEnabled(PluginType.PUMP, true);
|
comboPlugin.setPluginEnabled(PluginType.PUMP, true);
|
||||||
comboPlugin.setValidBasalRateProfileSelectedOnPump(false);
|
comboPlugin.setValidBasalRateProfileSelectedOnPump(false);
|
||||||
|
|
||||||
Constraint<Boolean> c = constraintChecker.isLoopInvokationAllowed();
|
Constraint<Boolean> c = constraintChecker.isLoopInvocationAllowed();
|
||||||
Assert.assertEquals(true, c.getReasonList().size() == 2); // Combo & Objectives
|
Assert.assertEquals(true, c.getReasonList().size() == 2); // Combo & Objectives
|
||||||
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 2); // Combo & Objectives
|
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 2); // Combo & Objectives
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
|
@ -129,7 +129,7 @@ public class ConstraintsCheckerTest {
|
||||||
public void isSMBModeEnabledTest() throws Exception {
|
public void isSMBModeEnabledTest() throws Exception {
|
||||||
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getSMB_OBJECTIVE()).setStartedOn(0);
|
objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getSMB_OBJECTIVE()).setStartedOn(0);
|
||||||
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
||||||
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
when(ConstraintChecker.getInstance().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
||||||
|
|
||||||
Constraint<Boolean> c = constraintChecker.isSMBModeEnabled();
|
Constraint<Boolean> c = constraintChecker.isSMBModeEnabled();
|
||||||
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class SafetyPluginTest {
|
||||||
@Test
|
@Test
|
||||||
public void notEnabledSMBInPreferencesDisablesSMB() {
|
public void notEnabledSMBInPreferencesDisablesSMB() {
|
||||||
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false);
|
||||||
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
when(ConstraintChecker.getInstance().isClosedLoopAllowed()).thenReturn(new Constraint<>(true));
|
||||||
|
|
||||||
Constraint<Boolean> c = new Constraint<>(true);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = safetyPlugin.isSMBModeEnabled(c);
|
c = safetyPlugin.isSMBModeEnabled(c);
|
||||||
|
@ -80,7 +80,7 @@ public class SafetyPluginTest {
|
||||||
@Test
|
@Test
|
||||||
public void openLoopPreventsSMB() {
|
public void openLoopPreventsSMB() {
|
||||||
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(true);
|
when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(true);
|
||||||
when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(false));
|
when(ConstraintChecker.getInstance().isClosedLoopAllowed()).thenReturn(new Constraint<>(false));
|
||||||
|
|
||||||
Constraint<Boolean> c = new Constraint<>(true);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = safetyPlugin.isSMBModeEnabled(c);
|
c = safetyPlugin.isSMBModeEnabled(c);
|
||||||
|
|
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
|
||||||
|
@ -552,7 +553,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20));
|
when(ConstraintChecker.getInstance().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20));
|
||||||
|
|
||||||
//BASAL 20% 20
|
//BASAL 20% 20
|
||||||
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
@ -579,7 +580,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d));
|
when(ConstraintChecker.getInstance().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d));
|
||||||
|
|
||||||
//BASAL 1 20
|
//BASAL 1 20
|
||||||
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
@ -632,7 +633,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
when(ConstraintChecker.getInstance().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
||||||
|
|
||||||
//EXTENDED 1 0
|
//EXTENDED 1 0
|
||||||
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
@ -673,7 +674,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
when(ConstraintChecker.getInstance().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
||||||
|
|
||||||
when(DateUtil.now()).thenReturn(1000L);
|
when(DateUtil.now()).thenReturn(1000L);
|
||||||
//BOLUS 1
|
//BOLUS 1
|
||||||
|
@ -683,7 +684,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d));
|
when(ConstraintChecker.getInstance().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d));
|
||||||
|
|
||||||
when(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L);
|
when(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L);
|
||||||
|
|
||||||
|
@ -701,9 +702,9 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
when(ConstraintChecker.getInstance().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
when(ConstraintChecker.getInstance().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
|
||||||
|
|
||||||
//BOLUS 1
|
//BOLUS 1
|
||||||
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
@ -807,7 +808,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(0));
|
when(ConstraintChecker.getInstance().applyCarbsConstraints(any())).thenReturn(new Constraint<>(0));
|
||||||
|
|
||||||
//CARBS 0
|
//CARBS 0
|
||||||
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
@ -816,7 +817,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertEquals("CARBS 0", smsCommunicatorPlugin.getMessages().get(0).getText());
|
Assert.assertEquals("CARBS 0", smsCommunicatorPlugin.getMessages().get(0).getText());
|
||||||
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
|
||||||
|
|
||||||
when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(1));
|
when(ConstraintChecker.getInstance().applyCarbsConstraints(any())).thenReturn(new Constraint<>(1));
|
||||||
|
|
||||||
//CARBS 1
|
//CARBS 1
|
||||||
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
smsCommunicatorPlugin.setMessages(new ArrayList<>());
|
||||||
|
|
|
@ -17,7 +17,7 @@ import java.util.Date;
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
|
@ -123,14 +123,14 @@ public class CommandQueueTest extends CommandQueue {
|
||||||
when(MainApp.getConstraintChecker()).thenReturn(constraintChecker);
|
when(MainApp.getConstraintChecker()).thenReturn(constraintChecker);
|
||||||
when(MainApp.isEngineeringModeOrRelease()).thenReturn(true);
|
when(MainApp.isEngineeringModeOrRelease()).thenReturn(true);
|
||||||
Constraint<Double> bolusConstraint = new Constraint<>(0d);
|
Constraint<Double> bolusConstraint = new Constraint<>(0d);
|
||||||
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(bolusConstraint);
|
when(ConstraintChecker.getInstance().applyBolusConstraints(any())).thenReturn(bolusConstraint);
|
||||||
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(bolusConstraint);
|
when(ConstraintChecker.getInstance().applyExtendedBolusConstraints(any())).thenReturn(bolusConstraint);
|
||||||
Constraint<Integer> carbsConstraint = new Constraint<>(0);
|
Constraint<Integer> carbsConstraint = new Constraint<>(0);
|
||||||
when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(carbsConstraint);
|
when(ConstraintChecker.getInstance().applyCarbsConstraints(any())).thenReturn(carbsConstraint);
|
||||||
Constraint<Double> rateConstraint = new Constraint<>(0d);
|
Constraint<Double> rateConstraint = new Constraint<>(0d);
|
||||||
when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(rateConstraint);
|
when(ConstraintChecker.getInstance().applyBasalConstraints(any(), any())).thenReturn(rateConstraint);
|
||||||
Constraint<Integer> percentageConstraint = new Constraint<>(0);
|
Constraint<Integer> percentageConstraint = new Constraint<>(0);
|
||||||
when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(percentageConstraint);
|
when(ConstraintChecker.getInstance().applyBasalPercentConstraints(any(), any())).thenReturn(percentageConstraint);
|
||||||
|
|
||||||
PowerMockito.mockStatic(ToastUtils.class);
|
PowerMockito.mockStatic(ToastUtils.class);
|
||||||
Context context = mock(Context.class);
|
Context context = mock(Context.class);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
|
|
Loading…
Reference in a new issue