Merge branch 'dev' of github.com:MilosKozak/AndroidAPS into update-oref
This commit is contained in:
commit
4c2c92087a
|
@ -109,7 +109,7 @@ android {
|
|||
targetSdkVersion 28
|
||||
multiDexEnabled true
|
||||
versionCode 1500
|
||||
version "2.4-dev-f"
|
||||
version "2.4-dev-g"
|
||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
||||
|
@ -225,12 +225,12 @@ dependencies {
|
|||
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.google.android.gms:play-services-wearable:17.0.0'
|
||||
implementation 'com.google.firebase:firebase-core:17.1.0'
|
||||
implementation 'com.google.firebase:firebase-core:17.2.0'
|
||||
implementation("com.crashlytics.sdk.android:crashlytics:2.9.9@aar") {
|
||||
transitive = true;
|
||||
}
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
|
@ -291,9 +291,11 @@ dependencies {
|
|||
}
|
||||
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
||||
testImplementation "org.hamcrest:hamcrest-all:1.3"
|
||||
/*
|
||||
testImplementation("uk.org.lidalia:slf4j-test:1.2.0") {
|
||||
exclude group: "com.google.guava", module: "guava"
|
||||
}
|
||||
*/
|
||||
|
||||
androidTestImplementation "org.mockito:mockito-core:2.8.47"
|
||||
androidTestImplementation "com.google.dexmaker:dexmaker:${dexmakerVersion}"
|
||||
|
|
|
@ -36,6 +36,8 @@ public class Constants {
|
|||
public static final int CPP_MIN_TIMESHIFT = -6;
|
||||
public static final int CPP_MAX_TIMESHIFT = 23;
|
||||
|
||||
public static final double MAX_PROFILE_SWITCH_DURATION = 7 * 24 * 60; // [min] ~ 7 days
|
||||
|
||||
//DanaR
|
||||
public static final double dailyLimitWarning = 0.95d;
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
} else {
|
||||
try { // activity may be destroyed
|
||||
setupTabs();
|
||||
setupViews(true);
|
||||
setupViews(false);
|
||||
} catch (IllegalStateException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -54,7 +54,6 @@ import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
|||
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.signatureVerifier.SignatureVerifier;
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
|
||||
|
@ -169,7 +168,7 @@ public class MainApp extends Application {
|
|||
if (pluginsList == null) {
|
||||
pluginsList = new ArrayList<>();
|
||||
// Register all tabs in app here
|
||||
pluginsList.add(OverviewPlugin.getPlugin());
|
||||
pluginsList.add(OverviewPlugin.INSTANCE);
|
||||
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
||||
if (Config.ACTION) pluginsList.add(ActionsPlugin.INSTANCE);
|
||||
pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin());
|
||||
|
|
|
@ -230,8 +230,8 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
|||
}
|
||||
|
||||
final String units = profile.getUnits();
|
||||
final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units);
|
||||
final double highLine = OverviewPlugin.getPlugin().determineHighLine(units);
|
||||
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
|
||||
final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
|
||||
|
||||
buttonDate.setText(DateUtil.dateAndTimeString(start));
|
||||
buttonZoom.setText(String.valueOf(rangeToDisplay));
|
||||
|
|
|
@ -209,6 +209,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
|
||||
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
|
||||
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights)));
|
||||
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights_extended)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
@ -230,7 +231,7 @@ public class Profile {
|
|||
if (notify && secondsFromMidnight % 3600 != 0) {
|
||||
if (Config.APS) {
|
||||
Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, String.format(MainApp.gs(R.string.basalprofilenotaligned), from), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -262,11 +263,11 @@ public class Profile {
|
|||
}
|
||||
|
||||
protected void sendBelowMinimumNotification(String from) {
|
||||
MainApp.bus().post(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL)));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL)));
|
||||
}
|
||||
|
||||
protected void sendAboveMaximumNotification(String from) {
|
||||
MainApp.bus().post(new EventNewNotification(new Notification(Notification.MAXIMUM_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.maximumbasalvaluereplaced), from), Notification.NORMAL)));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.MAXIMUM_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.maximumbasalvaluereplaced), from), Notification.NORMAL)));
|
||||
}
|
||||
|
||||
private void validate(LongSparseArray array) {
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
package info.nightscout.androidaps.data;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 12.10.2016.
|
||||
*/
|
||||
|
||||
public class QuickWizard {
|
||||
private static Logger log = LoggerFactory.getLogger(QuickWizard.class);
|
||||
|
||||
private JSONArray storage = new JSONArray();
|
||||
|
||||
public void setData(JSONArray newData) {
|
||||
storage = newData;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
SP.putString("QuickWizard", storage.toString());
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return storage.length();
|
||||
}
|
||||
|
||||
public QuickWizardEntry get(int position) {
|
||||
try {
|
||||
return new QuickWizardEntry((JSONObject) storage.get(position), position);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Boolean isActive() {
|
||||
for (int i = 0; i < storage.length(); i++) {
|
||||
try {
|
||||
if (new QuickWizardEntry((JSONObject) storage.get(i), i).isActive()) return true;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public QuickWizardEntry getActive() {
|
||||
for (int i = 0; i < storage.length(); i++) {
|
||||
QuickWizardEntry entry;
|
||||
try {
|
||||
entry = new QuickWizardEntry((JSONObject) storage.get(i), i);
|
||||
} catch (JSONException e) {
|
||||
continue;
|
||||
}
|
||||
if (entry.isActive()) return entry;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public QuickWizardEntry newEmptyItem() {
|
||||
return new QuickWizardEntry();
|
||||
}
|
||||
|
||||
public void addOrUpdate(QuickWizardEntry newItem) {
|
||||
if (newItem.position == -1)
|
||||
storage.put(newItem.storage);
|
||||
else {
|
||||
try {
|
||||
storage.put(newItem.position, newItem.storage);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void remove(int position) {
|
||||
storage.remove(position);
|
||||
save();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
object QuickWizard {
|
||||
private var storage = JSONArray()
|
||||
|
||||
init {
|
||||
setData(JSONArray(SP.getString("QuickWizard", "[]")))
|
||||
}
|
||||
|
||||
fun getActive(): QuickWizardEntry? {
|
||||
for (i in 0 until storage.length()) {
|
||||
val entry = QuickWizardEntry(storage.get(i) as JSONObject, i)
|
||||
if (entry.isActive) return entry
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun setData(newData: JSONArray) {
|
||||
storage = newData
|
||||
}
|
||||
|
||||
fun save() {
|
||||
SP.putString("QuickWizard", storage.toString())
|
||||
}
|
||||
|
||||
fun size(): Int = storage.length()
|
||||
|
||||
operator fun get(position: Int): QuickWizardEntry =
|
||||
QuickWizardEntry(storage.get(position) as JSONObject, position)
|
||||
|
||||
|
||||
fun newEmptyItem(): QuickWizardEntry {
|
||||
return QuickWizardEntry()
|
||||
}
|
||||
|
||||
fun addOrUpdate(newItem: QuickWizardEntry) {
|
||||
if (newItem.position == -1)
|
||||
storage.put(newItem.storage)
|
||||
else
|
||||
storage.put(newItem.position, newItem.storage)
|
||||
save()
|
||||
}
|
||||
|
||||
fun remove(position: Int) {
|
||||
storage.remove(position)
|
||||
save()
|
||||
}
|
||||
}
|
|
@ -216,8 +216,8 @@ public class BgReading implements DataPointWithLabelInterface {
|
|||
@Override
|
||||
public int getColor() {
|
||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
||||
Double lowLine = OverviewPlugin.getPlugin().determineLowLine(units);
|
||||
Double highLine = OverviewPlugin.getPlugin().determineHighLine(units);
|
||||
Double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
|
||||
Double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
|
||||
int color = MainApp.gc(R.color.inrange);
|
||||
if (isPrediction())
|
||||
return getPredectionColor();
|
||||
|
|
|
@ -93,12 +93,22 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
|
|||
return (System.currentTimeMillis() - date) / (60 * 60 * 1000.0);
|
||||
}
|
||||
|
||||
public String age() {
|
||||
public String age(boolean useShortText) {
|
||||
Map<TimeUnit, Long> diff = computeDiff(date, System.currentTimeMillis());
|
||||
if (OverviewFragment.shorttextmode)
|
||||
return diff.get(TimeUnit.DAYS) + "d" + diff.get(TimeUnit.HOURS) + "h";
|
||||
else
|
||||
return diff.get(TimeUnit.DAYS) + " " + MainApp.gs(R.string.days) + " " + diff.get(TimeUnit.HOURS) + " " + MainApp.gs(R.string.hours);
|
||||
|
||||
String days = " " + MainApp.gs(R.string.days) + " ";
|
||||
String hours = " " + MainApp.gs(R.string.hours) + " ";
|
||||
|
||||
if (useShortText) {
|
||||
days = "d";
|
||||
hours = "h";
|
||||
}
|
||||
|
||||
return diff.get(TimeUnit.DAYS) + days + diff.get(TimeUnit.HOURS) + hours;
|
||||
}
|
||||
|
||||
public String age() {
|
||||
return age(OverviewFragment.shorttextmode);
|
||||
}
|
||||
|
||||
public boolean isOlderThan(double hours) {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
|
@ -18,11 +20,13 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.interfaces.Interval;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
|
@ -78,12 +82,12 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ProfileSwitch source(int source) {
|
||||
public ProfileSwitch source(int source) {
|
||||
this.source = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProfileSwitch duration(int duration) {
|
||||
public ProfileSwitch duration(int duration) {
|
||||
this.durationInMinutes = duration;
|
||||
return this;
|
||||
}
|
||||
|
@ -107,7 +111,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
*/
|
||||
public String getCustomizedName() {
|
||||
String name = profileName;
|
||||
if(LocalProfilePlugin.LOCAL_PROFILE.equals(name)){
|
||||
if (LocalProfilePlugin.LOCAL_PROFILE.equals(name)) {
|
||||
name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U ";
|
||||
}
|
||||
if (isCPP) {
|
||||
|
@ -156,7 +160,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
|
||||
// -------- Interval interface ---------
|
||||
|
||||
Long cuttedEnd = null;
|
||||
private Long cuttedEnd = null;
|
||||
|
||||
public long durationInMsec() {
|
||||
return durationInMinutes * 60 * 1000L;
|
||||
|
@ -212,16 +216,17 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
|
||||
boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date));
|
||||
if (!isValid)
|
||||
ProfileSwitch active = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now());
|
||||
long activeProfileSwitchDate = active != null ? active.date : -1L;
|
||||
if (!isValid && date == activeProfileSwitchDate)
|
||||
createNotificationInvalidProfile(DateUtil.dateAndTimeString(date));
|
||||
return isValid;
|
||||
}
|
||||
|
||||
public void createNotificationInvalidProfile(String detail) {
|
||||
private void createNotificationInvalidProfile(String detail) {
|
||||
Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
|
||||
public static boolean isEvent5minBack(List<ProfileSwitch> list, long time, boolean zeroDurationOnly) {
|
||||
|
@ -290,6 +295,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
|||
return Color.CYAN;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String toString() {
|
||||
return "ProfileSwitch{" +
|
||||
"date=" + date +
|
||||
|
|
|
@ -68,6 +68,7 @@ class ConfigBuilderFragment : Fragment() {
|
|||
|
||||
@Synchronized
|
||||
private fun updateGUI() {
|
||||
configbuilder_categories.removeAllViews()
|
||||
createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE))
|
||||
createViewsForPlugins(R.string.configbuilder_insulin, R.string.configbuilder_insulin_description, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface::class.java, PluginType.INSULIN))
|
||||
createViewsForPlugins(R.string.configbuilder_bgsource, R.string.configbuilder_bgsource_description, PluginType.BGSOURCE, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface::class.java, PluginType.BGSOURCE))
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.configBuilder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
|
||||
/**
|
||||
* Created by mike on 08.08.2017.
|
||||
*/
|
||||
|
||||
public class DetailedBolusInfoStorage {
|
||||
private static Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||
private static List<DetailedBolusInfo> store = new ArrayList<>();
|
||||
|
||||
public static synchronized void add(DetailedBolusInfo detailedBolusInfo) {
|
||||
log.debug("Stored bolus info: " + detailedBolusInfo);
|
||||
store.add(detailedBolusInfo);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static synchronized DetailedBolusInfo findDetailedBolusInfo(long bolustime) {
|
||||
DetailedBolusInfo found = null;
|
||||
for (int i = 0; i < store.size(); i++) {
|
||||
long infoTime = store.get(i).date;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Existing bolus info: " + store.get(i));
|
||||
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
|
||||
found = store.get(i);
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Using & removing bolus info: " + store.get(i));
|
||||
store.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
}
|
|
@ -102,7 +102,8 @@ public class ProfileFunctions {
|
|||
}
|
||||
|
||||
public boolean isProfileValid(String from) {
|
||||
return getProfile() != null && getProfile().isValid(from);
|
||||
Profile profile = getProfile();
|
||||
return profile != null && profile.isValid(from);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -15,6 +15,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
|
|||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
@ -89,6 +90,6 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
|
|||
|
||||
private void warnUser(int id, String warningText) {
|
||||
Notification notification = new Notification(id, warningText, Notification.LOW);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
|
@ -18,19 +18,20 @@ import androidx.recyclerview.widget.LinearSmoothScroller
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.HtmlHelper
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver
|
||||
import info.nightscout.androidaps.utils.*
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.objectives_fragment.*
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
class ObjectivesFragment : Fragment() {
|
||||
private val log = LoggerFactory.getLogger(L.CONSTRAINTS)
|
||||
private val objectivesAdapter = ObjectivesAdapter()
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
|
@ -168,10 +169,17 @@ class ObjectivesFragment : Fragment() {
|
|||
holder.progress.removeAllViews()
|
||||
for (task in objective.tasks) {
|
||||
if (task.shouldBeIgnored()) continue
|
||||
// name
|
||||
val name = TextView(holder.progress.context)
|
||||
name.text = MainApp.gs(task.task) + ":"
|
||||
name.setTextColor(-0x1)
|
||||
holder.progress.addView(name, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
|
||||
// hint
|
||||
task.hints.forEach { h ->
|
||||
if (!task.isCompleted)
|
||||
holder.progress.addView(h.generate(context))
|
||||
}
|
||||
// state
|
||||
val state = TextView(holder.progress.context)
|
||||
state.setTextColor(-0x1)
|
||||
val basicHTML = "<font color=\"%1\$s\"><b>%2\$s</b></font>"
|
||||
|
@ -183,13 +191,14 @@ class ObjectivesFragment : Fragment() {
|
|||
state.setOnClickListener {
|
||||
val dialog = ObjectivesExamDialog()
|
||||
val bundle = Bundle()
|
||||
val position = objective.tasks.indexOf(task)
|
||||
bundle.putInt("currentTask", position)
|
||||
val taskPosition = objective.tasks.indexOf(task)
|
||||
bundle.putInt("currentTask", taskPosition)
|
||||
dialog.arguments = bundle
|
||||
ObjectivesExamDialog.objective = objective
|
||||
fragmentManager?.let { dialog.show(it, "ObjectivesFragment") }
|
||||
}
|
||||
}
|
||||
// horizontal line
|
||||
val separator = View(holder.progress.context)
|
||||
separator.setBackgroundColor(Color.DKGRAY)
|
||||
holder.progress.addView(separator, LinearLayout.LayoutParams.MATCH_PARENT, 2)
|
||||
|
@ -198,16 +207,50 @@ class ObjectivesFragment : Fragment() {
|
|||
holder.accomplished.text = MainApp.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn))
|
||||
holder.accomplished.setTextColor(-0x3e3e3f)
|
||||
holder.verify.setOnClickListener {
|
||||
objective.accomplishedOn = DateUtil.now()
|
||||
notifyDataSetChanged()
|
||||
scrollToCurrentObjective()
|
||||
startUpdateTimer()
|
||||
holder.verify.visibility = View.INVISIBLE
|
||||
SntpClient.ntpTime(object : SntpClient.Callback() {
|
||||
override fun run() {
|
||||
activity?.runOnUiThread {
|
||||
holder.verify.visibility = View.VISIBLE
|
||||
log.debug("NTP time: $time System time: ${DateUtil.now()}")
|
||||
if (!networkConnected) {
|
||||
ToastUtils.showToastInUiThread(context, R.string.notconnected)
|
||||
} else if (success) {
|
||||
if (objective.isCompleted(time)) {
|
||||
objective.accomplishedOn = time
|
||||
notifyDataSetChanged()
|
||||
scrollToCurrentObjective()
|
||||
startUpdateTimer()
|
||||
} else {
|
||||
ToastUtils.showToastInUiThread(context, R.string.requirementnotmet)
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showToastInUiThread(context, R.string.failedretrievetime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, NetworkChangeReceiver.isConnected())
|
||||
}
|
||||
holder.start.setOnClickListener {
|
||||
objective.startedOn = DateUtil.now()
|
||||
notifyDataSetChanged()
|
||||
scrollToCurrentObjective()
|
||||
startUpdateTimer()
|
||||
holder.start.visibility = View.INVISIBLE
|
||||
SntpClient.ntpTime(object : SntpClient.Callback() {
|
||||
override fun run() {
|
||||
activity?.runOnUiThread {
|
||||
holder.start.visibility = View.VISIBLE
|
||||
log.debug("NTP time: $time System time: ${DateUtil.now()}")
|
||||
if (!networkConnected) {
|
||||
ToastUtils.showToastInUiThread(context, R.string.notconnected)
|
||||
} else if (success) {
|
||||
objective.startedOn = time
|
||||
notifyDataSetChanged()
|
||||
scrollToCurrentObjective()
|
||||
startUpdateTimer()
|
||||
} else {
|
||||
ToastUtils.showToastInUiThread(context, R.string.failedretrievetime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, NetworkChangeReceiver.isConnected())
|
||||
}
|
||||
holder.revert.setOnClickListener {
|
||||
objective.accomplishedOn = 0
|
||||
|
|
|
@ -64,7 +64,7 @@ object ObjectivesPlugin : PluginBase(PluginDescription()
|
|||
|
||||
private fun doConvertSP(number: Int, name: String) {
|
||||
if (!SP.contains("Objectives_" + name + "_started")) {
|
||||
SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "accomplished", 0L))
|
||||
SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "started", 0L))
|
||||
SP.putLong("Objectives_" + name + "_accomplished", SP.getLong("Objectives" + number + "accomplished", 0L))
|
||||
}
|
||||
// TODO: we can remove Objectives1accomplished sometimes later
|
||||
|
|
|
@ -36,8 +36,8 @@ class ObjectivesExamDialog : DialogFragment() {
|
|||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -70,8 +70,7 @@ class ObjectivesExamDialog : DialogFragment() {
|
|||
// Hints
|
||||
objectives_exam_hints.removeAllViews()
|
||||
for (h in task.hints) {
|
||||
val hint: Hint = h as Hint;
|
||||
objectives_exam_hints.addView(hint.generate(context))
|
||||
objectives_exam_hints.addView(h.generate(context))
|
||||
}
|
||||
// Disabled to
|
||||
objectives_exam_disabledto.text = MainApp.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo))
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -27,7 +28,7 @@ public abstract class Objective {
|
|||
private int gate;
|
||||
private long startedOn;
|
||||
private long accomplishedOn;
|
||||
private List<Task> tasks = new ArrayList<>();
|
||||
List<Task> tasks = new ArrayList<>();
|
||||
public boolean hasSpecialInput = false;
|
||||
|
||||
public Objective(String spName, @StringRes int objective, @StringRes int gate) {
|
||||
|
@ -36,6 +37,10 @@ public abstract class Objective {
|
|||
this.gate = gate;
|
||||
startedOn = SP.getLong("Objectives_" + spName + "_started", 0L);
|
||||
accomplishedOn = SP.getLong("Objectives_" + spName + "_accomplished", 0L);
|
||||
if ((accomplishedOn - DateUtil.now()) > T.hours(3).msecs() || (startedOn - DateUtil.now()) > T.hours(3).msecs()) { // more than 3 hours in the future
|
||||
startedOn = 0;
|
||||
accomplishedOn = 0;
|
||||
}
|
||||
setupTasks(tasks);
|
||||
for (Task task : tasks) task.objective = this;
|
||||
}
|
||||
|
@ -48,12 +53,20 @@ public abstract class Objective {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean isCompleted(long trueTime) {
|
||||
for (Task task : tasks) {
|
||||
if (!task.shouldBeIgnored() && !task.isCompleted(trueTime))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isRevertable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAccomplished() {
|
||||
return accomplishedOn != 0;
|
||||
return accomplishedOn != 0 && accomplishedOn < DateUtil.now();
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
|
@ -100,6 +113,7 @@ public abstract class Objective {
|
|||
@StringRes
|
||||
private int task;
|
||||
private Objective objective;
|
||||
ArrayList<Hint> hints = new ArrayList<>();
|
||||
|
||||
public Task(@StringRes int task) {
|
||||
this.task = task;
|
||||
|
@ -114,11 +128,21 @@ public abstract class Objective {
|
|||
}
|
||||
|
||||
public abstract boolean isCompleted();
|
||||
public boolean isCompleted(long trueTime) { return isCompleted(); };
|
||||
|
||||
public String getProgress() {
|
||||
return MainApp.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet);
|
||||
}
|
||||
|
||||
Task hint(Hint hint) {
|
||||
hints.add(hint);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayList<Hint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public boolean shouldBeIgnored() {
|
||||
return false;
|
||||
}
|
||||
|
@ -138,6 +162,11 @@ public abstract class Objective {
|
|||
return getObjective().isStarted() && System.currentTimeMillis() - getObjective().getStartedOn() >= minimumDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompleted(long trueTime) {
|
||||
return getObjective().isStarted() && trueTime - getObjective().getStartedOn() >= minimumDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProgress() {
|
||||
return getDurationText(System.currentTimeMillis() - getObjective().getStartedOn())
|
||||
|
@ -157,8 +186,7 @@ public abstract class Objective {
|
|||
public class ExamTask extends Task {
|
||||
@StringRes
|
||||
int question;
|
||||
List hints = new ArrayList<>();
|
||||
List options = new ArrayList<>();
|
||||
ArrayList<Option> options = new ArrayList<>();
|
||||
private String spIdentifier;
|
||||
private boolean answered;
|
||||
private long disabledTo;
|
||||
|
@ -198,11 +226,6 @@ public abstract class Objective {
|
|||
return this;
|
||||
}
|
||||
|
||||
ExamTask hint(Hint hint) {
|
||||
hints.add(hint);
|
||||
return this;
|
||||
}
|
||||
|
||||
public @StringRes int getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
@ -211,10 +234,6 @@ public abstract class Objective {
|
|||
return options;
|
||||
}
|
||||
|
||||
public List getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return answered;
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.List;
|
|||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
|
@ -28,36 +27,36 @@ public class Objective1 extends Objective {
|
|||
public boolean isCompleted() {
|
||||
return SP.getBoolean(R.string.key_objectiveusedisconnect, false);
|
||||
}
|
||||
});
|
||||
}.hint(new Hint(R.string.disconnectpump_hint)));
|
||||
tasks.add(new Task(R.string.objectives_usereconnectpump) {
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return SP.getBoolean(R.string.key_objectiveusereconnect, false);
|
||||
}
|
||||
});
|
||||
}.hint(new Hint(R.string.disconnectpump_hint)));
|
||||
tasks.add(new Task(R.string.objectives_usetemptarget) {
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return SP.getBoolean(R.string.key_objectiveusetemptarget, false);
|
||||
}
|
||||
});
|
||||
}.hint(new Hint(R.string.usetemptarget_hint)));
|
||||
tasks.add(new Task(R.string.objectives_useactions) {
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return SP.getBoolean(R.string.key_objectiveuseactions, false) && ActionsPlugin.INSTANCE.isEnabled(PluginType.GENERAL) && ActionsPlugin.INSTANCE.isFragmentVisible();
|
||||
}
|
||||
});
|
||||
}.hint(new Hint(R.string.useaction_hint)));
|
||||
tasks.add(new Task(R.string.objectives_useloop) {
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return SP.getBoolean(R.string.key_objectiveuseloop, false);
|
||||
}
|
||||
});
|
||||
}.hint(new Hint(R.string.useaction_hint)));
|
||||
tasks.add(new Task(R.string.objectives_usescale) {
|
||||
@Override
|
||||
public boolean isCompleted() {
|
||||
return SP.getBoolean(R.string.key_objectiveusescale, false);
|
||||
}
|
||||
});
|
||||
}.hint(new Hint(R.string.usescale_hint)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,61 +10,194 @@ public class Objective2 extends Objective {
|
|||
|
||||
public Objective2() {
|
||||
super("exam", R.string.objectives_exam_objective, R.string.objectives_exam_gate);
|
||||
for (Task task : tasks) {
|
||||
if (!task.isCompleted()) setAccomplishedOn(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupTasks(List<Task> tasks) {
|
||||
tasks.add(new ExamTask(R.string.dia_meaningofdia, R.string.dia_whatmeansdia,"dia")
|
||||
tasks.add(new ExamTask(R.string.dia_label, R.string.dia_whatmeansdia,"dia")
|
||||
.option(new Option(R.string.dia_minimumis3h, false))
|
||||
.option(new Option(R.string.dia_minimumis5h, true))
|
||||
.option(new Option(R.string.dia_meaningisequaltodiapump, false))
|
||||
.option(new Option(R.string.dia_valuemustbedetermined, true))
|
||||
.hint(new Hint(R.string.dia_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.hypott, R.string.hypott_whenhypott,"hypott")
|
||||
.option(new Option(R.string.hypott_goinglow, true))
|
||||
.option(new Option(R.string.hypott_havinglow, true))
|
||||
.option(new Option(R.string.hypott_notlowanymorebutrising, false))
|
||||
.option(new Option(R.string.hypott_havehadalowbg, false))
|
||||
tasks.add(new ExamTask(R.string.hypott_label, R.string.hypott_whenhypott,"hypott")
|
||||
.option(new Option(R.string.hypott_goinglow, false))
|
||||
.option(new Option(R.string.hypott_preventoversmb, true))
|
||||
.hint(new Hint(R.string.hypott_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.offlineprofile, R.string.offlineprofile_whatprofile,"offlineprofile")
|
||||
tasks.add(new ExamTask(R.string.offlineprofile_label, R.string.offlineprofile_whatprofile,"offlineprofile")
|
||||
.option(new Option(R.string.localprofile, true))
|
||||
.option(new Option(R.string.nsprofile, false))
|
||||
.option(new Option(R.string.offlineprofile_nsprofile, true))
|
||||
.hint(new Hint(R.string.offlineprofile_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.pumpdisconnect, R.string.pumpdisconnect_whattodo,"pumpdisconnect")
|
||||
tasks.add(new ExamTask(R.string.pumpdisconnect_label, R.string.pumpdisconnect_label,"pumpdisconnect")
|
||||
.option(new Option(R.string.pumpdisconnect_letknow, true))
|
||||
.option(new Option(R.string.pumpdisconnect_dontchnage, false))
|
||||
.hint(new Hint(R.string.pumpdisconnect_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.objectives, R.string.objectives_howtosave,"objectives")
|
||||
.option(new Option(R.string.objectives_writetopaper, false))
|
||||
tasks.add(new ExamTask(R.string.objectives_label, R.string.objectives_howtosave,"objectives")
|
||||
.option(new Option(R.string.objectives_exportsettings, true))
|
||||
.option(new Option(R.string.objectives_storeelsewhere, true))
|
||||
.option(new Option(R.string.objectives_doexportonstart, false))
|
||||
.option(new Option(R.string.objectives_doexportafterchange, true))
|
||||
.option(new Option(R.string.objectives_doexportafterfirtssettings, true))
|
||||
.hint(new Hint(R.string.objectives_hint1))
|
||||
.hint(new Hint(R.string.objectives_hint2))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.noisycgm, R.string.noisycgm_whattodo,"noisycgm")
|
||||
tasks.add(new ExamTask(R.string.noisycgm_label, R.string.noisycgm_whattodo,"noisycgm")
|
||||
.option(new Option(R.string.nothing, false))
|
||||
.option(new Option(R.string.disconnectpumpfor1h, false))
|
||||
.option(new Option(R.string.noisycgm_pause, true))
|
||||
.option(new Option(R.string.noisycgm_replacesensor, true))
|
||||
.option(new Option(R.string.noisycgm_turnoffcgmreceiver, false))
|
||||
.option(new Option(R.string.noisycgm_turnoffphone, false))
|
||||
.option(new Option(R.string.noisycgm_checksmoothing, true))
|
||||
.hint(new Hint(R.string.noisycgm_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.exercise_label, R.string.exercise_whattodo,"exercise")
|
||||
.option(new Option(R.string.nothing, false))
|
||||
.option(new Option(R.string.exercise_setactivitytt, true))
|
||||
.option(new Option(R.string.exercise_switchprofilebelow100, true))
|
||||
.option(new Option(R.string.exercise_switchprofileabove100, false))
|
||||
.option(new Option(R.string.exercise_stoploop, false))
|
||||
.option(new Option(R.string.exercise_doitbeforestart, true))
|
||||
.hint(new Hint(R.string.exercise_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.suspendloop_label, R.string.suspendloop_doigetinsulin,"suspendloop")
|
||||
.option(new Option(R.string.suspendloop_yes, true))
|
||||
.option(new Option(R.string.suspendloop_no, false))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.basaltest_label, R.string.basaltest_when,"basaltest")
|
||||
.option(new Option(R.string.basaltest_beforeloop, true))
|
||||
.option(new Option(R.string.basaltest_havingregularhypo, true))
|
||||
.option(new Option(R.string.basaltest_havingregularhyper, true))
|
||||
.hint(new Hint(R.string.basaltest_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.basalhelp_label, R.string.basalhelp_where,"basalhelp")
|
||||
.option(new Option(R.string.basalhelp_diabetesteam, true))
|
||||
.option(new Option(R.string.basalhelp_google, false))
|
||||
.option(new Option(R.string.basalhelp_facebook, false))
|
||||
.hint(new Hint(R.string.basalhelp_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.prerequisites_label, R.string.prerequisites_what, "prerequisites")
|
||||
.option(new Option(R.string.prerequisites_determinedcorrectprofile, true))
|
||||
.option(new Option(R.string.prerequisites_computer, true))
|
||||
.option(new Option(R.string.prerequisites_phone, true))
|
||||
.option(new Option(R.string.prerequisites_car, false))
|
||||
.option(new Option(R.string.prerequisites_nightscout, true))
|
||||
.option(new Option(R.string.prerequisites_tidepoolaccount, false))
|
||||
.option(new Option(R.string.prerequisites_googleaccount, false))
|
||||
.option(new Option(R.string.prerequisites_githubaccount, false))
|
||||
.option(new Option(R.string.prerequisites_beanandroiddeveloper, false))
|
||||
.option(new Option(R.string.prerequisites_own670g, false))
|
||||
.option(new Option(R.string.prerequisites_smartwatch, false))
|
||||
.option(new Option(R.string.prerequisites_supportedcgm, true))
|
||||
.hint(new Hint(R.string.prerequisites_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.update_label, R.string.whatistrue,"update")
|
||||
.option(new Option(R.string.update_git, true))
|
||||
.option(new Option(R.string.update_asap, true))
|
||||
.option(new Option(R.string.update_keys, true))
|
||||
.option(new Option(R.string.update_neverupdate, false))
|
||||
.option(new Option(R.string.update_askfriend, false))
|
||||
.hint(new Hint(R.string.update_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.troubleshooting_label, R.string.troubleshooting_wheretoask,"troubleshooting")
|
||||
.option(new Option(R.string.troubleshooting_fb, true))
|
||||
.option(new Option(R.string.troubleshooting_wiki, true))
|
||||
.option(new Option(R.string.troubleshooting_gitter, true))
|
||||
.option(new Option(R.string.troubleshooting_googlesupport, false))
|
||||
.option(new Option(R.string.troubleshooting_yourendo, false))
|
||||
.hint(new Hint(R.string.troubleshooting_hint1))
|
||||
.hint(new Hint(R.string.troubleshooting_hint2))
|
||||
.hint(new Hint(R.string.troubleshooting_hint3))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.insulin_label, R.string.insulin_ultrarapid,"insulin")
|
||||
.option(new Option(R.string.insulin_fiasp, true))
|
||||
.option(new Option(R.string.insulin_novorapid, false))
|
||||
.option(new Option(R.string.insulin_humalog, false))
|
||||
.option(new Option(R.string.insulin_actrapid, false))
|
||||
.hint(new Hint(R.string.insulin_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.sensitivity_label, R.string.sensitivity_which,"sensitivity")
|
||||
.option(new Option(R.string.sensitivityweightedaverage, true))
|
||||
.option(new Option(R.string.sensitivityoref0, false))
|
||||
.option(new Option(R.string.sensitivityoref1, false))
|
||||
.option(new Option(R.string.sensitivityaaps, true))
|
||||
.hint(new Hint(R.string.sensitivity_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.sensitivity_label, R.string.sensitivityuam_which,"sensitivityuam")
|
||||
.option(new Option(R.string.sensitivityweightedaverage, false))
|
||||
.option(new Option(R.string.sensitivityoref0, false))
|
||||
.option(new Option(R.string.sensitivityoref1, true))
|
||||
.option(new Option(R.string.sensitivityaaps, false))
|
||||
.hint(new Hint(R.string.sensitivity_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.wrongcarbs_label, R.string.wrongcarbs_whattodo,"wrongcarbs")
|
||||
.option(new Option(R.string.wrongcarbs_addfakeinsulin, false))
|
||||
.option(new Option(R.string.wrongcarbs_treatmentstab, true))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.extendedcarbs_label, R.string.extendedcarbs_handling,"extendedcarbs")
|
||||
.option(new Option(R.string.extendedcarbs_useextendedcarbs, true))
|
||||
.option(new Option(R.string.extendedcarbs_add, false))
|
||||
.option(new Option(R.string.extendedcarbs_useextendedbolus, false))
|
||||
.hint(new Hint(R.string.extendedcarbs_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.nsclient_label, R.string.nsclient_howcanyou,"nsclient")
|
||||
.option(new Option(R.string.nsclient_nightscout, true))
|
||||
.option(new Option(R.string.nsclientinternal, true))
|
||||
.option(new Option(R.string.nsclient_dexcomfollow, true))
|
||||
.option(new Option(R.string.nsclient_dexcomfollowxdrip, false))
|
||||
.option(new Option(R.string.nsclient_xdripfollower, true))
|
||||
.option(new Option(R.string.nsclient_looponiphone, false))
|
||||
.option(new Option(R.string.nsclient_spikeiphone, true))
|
||||
.hint(new Hint(R.string.nsclient_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.isf_label, R.string.whatistrue,"isf")
|
||||
.option(new Option(R.string.isf_increasingvalue, true))
|
||||
.option(new Option(R.string.isf_decreasingvalue, false))
|
||||
.option(new Option(R.string.isf_noeffect, false))
|
||||
.option(new Option(R.string.isf_preferences, false))
|
||||
.option(new Option(R.string.isf_profile, false))
|
||||
.hint(new Hint(R.string.isf_hint1))
|
||||
.hint(new Hint(R.string.isf_hint2))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.ic_label, R.string.whatistrue,"ic")
|
||||
.option(new Option(R.string.ic_increasingvalue, true))
|
||||
.option(new Option(R.string.ic_decreasingvalue, false))
|
||||
.option(new Option(R.string.ic_noeffect, false))
|
||||
.option(new Option(R.string.ic_different, false))
|
||||
.option(new Option(R.string.ic_meaning, false))
|
||||
.hint(new Hint(R.string.ic_hint1))
|
||||
);
|
||||
tasks.add(new ExamTask(R.string.profileswitch_label, R.string.profileswitch_pctwillchange,"profileswitch")
|
||||
.option(new Option(R.string.profileswitch_basalhigher, false))
|
||||
.option(new Option(R.string.profileswitch_basallower, true))
|
||||
.option(new Option(R.string.profileswitch_ichigher, true))
|
||||
.option(new Option(R.string.profileswitch_iclower, false))
|
||||
.option(new Option(R.string.profileswitch_isfhigher, true))
|
||||
.option(new Option(R.string.profileswitch_isflower, false))
|
||||
.option(new Option(R.string.profileswitch_overall, true))
|
||||
.option(new Option(R.string.profileswitch_targethigher, false))
|
||||
.option(new Option(R.string.profileswitch_targetlower, false))
|
||||
.option(new Option(R.string.profileswitch_targetbottom, false))
|
||||
.hint(new Hint(R.string.profileswitch_hint1))
|
||||
);
|
||||
|
||||
tasks.add(new ExamTask(R.string.profileswitch_label, R.string.profileswitchtime_iwant,"profileswitchtime")
|
||||
.option(new Option(R.string.profileswitchtime_1, false))
|
||||
.option(new Option(R.string.profileswitchtime__1, true))
|
||||
.option(new Option(R.string.profileswitchtime_60, false))
|
||||
.option(new Option(R.string.profileswitchtime__60, false))
|
||||
.hint(new Hint(R.string.profileswitchtime_hint1))
|
||||
);
|
||||
|
||||
for (Task task : tasks)
|
||||
Collections.shuffle(((ExamTask)task).options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRevertable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
|||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
@ -68,7 +69,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
|||
if (!MainApp.isEngineeringModeOrRelease()) {
|
||||
if (value.value()) {
|
||||
Notification n = new Notification(Notification.TOAST_ALARM, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(n));
|
||||
}
|
||||
value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), this);
|
||||
}
|
||||
|
@ -125,6 +126,10 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
|||
|
||||
if (Config.APS) {
|
||||
double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d);
|
||||
if (maxBasal < profile.getMaxDailyBasal()) {
|
||||
maxBasal = profile.getMaxDailyBasal();
|
||||
absoluteRate.addReason(MainApp.gs(R.string.increasingmaxbasal), this);
|
||||
}
|
||||
absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this);
|
||||
|
||||
// Check percentRate but absolute rate too, because we know real current basal in pump
|
||||
|
|
|
@ -17,6 +17,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
|||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.notifications.Notification;
|
||||
|
@ -56,9 +57,9 @@ public class StorageConstraintPlugin extends PluginBase implements ConstraintsIn
|
|||
if (diskfree < Constants.MINIMUM_FREE_SPACE) {
|
||||
value.set(false, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), this);
|
||||
Notification notification = new Notification(Notification.DISKFULL, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.DISKFULL));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.DISKFULL));
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
|
@ -77,7 +77,7 @@ class AutomationFragment : Fragment() {
|
|||
if (eventListAdapter == null) return
|
||||
eventListAdapter?.notifyDataSetChanged()
|
||||
val sb = StringBuilder()
|
||||
for (l in AutomationPlugin.executionLog) {
|
||||
for (l in AutomationPlugin.executionLog.reversed()) {
|
||||
sb.append(l)
|
||||
sb.append("\n")
|
||||
}
|
||||
|
|
|
@ -201,7 +201,9 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
|||
ActionStartTempTarget(),
|
||||
ActionStopTempTarget(),
|
||||
ActionNotification(),
|
||||
ActionProfileSwitchPercent()
|
||||
ActionProfileSwitchPercent(),
|
||||
ActionProfileSwitch(),
|
||||
ActionSendSMS()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -209,6 +211,7 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
|||
return listOf(
|
||||
TriggerTime(),
|
||||
TriggerRecurringTime(),
|
||||
TriggerTimeRange(),
|
||||
TriggerBg(),
|
||||
TriggerDelta(),
|
||||
TriggerIob(),
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputProfileName;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
|
||||
public class ActionProfileSwitch extends Action {
|
||||
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
||||
public InputProfileName inputProfileName = new InputProfileName(ProfileFunctions.getInstance().getProfileName());
|
||||
String profileName = "";
|
||||
|
||||
public ActionProfileSwitch() {
|
||||
// Prevent action if active profile is already active
|
||||
// but we don't have a trigger IS_NOT_EQUAL
|
||||
// so check is in the doRun()
|
||||
}
|
||||
|
||||
@Override
|
||||
public int friendlyName() {
|
||||
return R.string.profilename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortDescription() {
|
||||
String returned = MainApp.gs(R.string.changengetoprofilename, inputProfileName.getValue());
|
||||
return returned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(Callback callback) {
|
||||
|
||||
String activeProfileName = ProfileFunctions.getInstance().getProfileName();
|
||||
//Check for uninitialized profileName
|
||||
if ( profileName.equals("")){ profileName = activeProfileName; }
|
||||
|
||||
if (profileName.equals(activeProfileName)) {
|
||||
// Profile is already switched
|
||||
return;
|
||||
}
|
||||
ProfileInterface activeProfile = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface();
|
||||
if (activeProfile == null) return;
|
||||
ProfileStore profileStore = activeProfile.getProfile();
|
||||
if (profileStore == null) return;
|
||||
if(profileStore.getSpecificProfile(profileName) == null) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.error("Selected profile does not exist! - "+ profileName);
|
||||
return;
|
||||
}
|
||||
|
||||
ProfileFunctions.doProfileSwitch(profileStore, profileName, 0, 100, 0);
|
||||
if (callback != null)
|
||||
callback.result(new PumpEnactResult().success(true).comment(R.string.ok)).run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root) {
|
||||
new LayoutBuilder()
|
||||
.add(new LabelWithElement(MainApp.gs(R.string.profilename), "", inputProfileName))
|
||||
.build(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDialog() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JSONObject o = new JSONObject();
|
||||
try {
|
||||
o.put("type", ActionProfileSwitch.class.getName());
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("profileToSwitchTo", inputProfileName.getValue());
|
||||
o.put("data", data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action fromJSON(String data) {
|
||||
|
||||
try {
|
||||
JSONObject d = new JSONObject(data);
|
||||
profileName = JsonHelper.safeGetString(d, "profileToSwitchTo");
|
||||
inputProfileName.setValue(profileName);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> icon() {
|
||||
return Optional.of(R.drawable.icon_actions_profileswitch);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.actions;
|
||||
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputString;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
|
||||
public class ActionSendSMS extends Action {
|
||||
|
||||
public InputString text = new InputString();
|
||||
|
||||
@Override
|
||||
public int friendlyName() {
|
||||
return R.string.sendsmsactiondescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String shortDescription() {
|
||||
return MainApp.gs(R.string.sendsmsactionlabel, text.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(Callback callback) {
|
||||
boolean result = SmsCommunicatorPlugin.getPlugin().sendNotificationToAllNumbers(text.getValue());
|
||||
if (callback != null)
|
||||
callback.result(new PumpEnactResult().success(result).comment(result ? R.string.ok : R.string.danar_error)).run();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> icon() {
|
||||
return Optional.of(R.drawable.ic_notifications);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JSONObject o = new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
try {
|
||||
data.put("text", text.getValue());
|
||||
o.put("type", this.getClass().getName());
|
||||
o.put("data", data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action fromJSON(String data) {
|
||||
try {
|
||||
JSONObject o = new JSONObject(data);
|
||||
text.setValue(JsonHelper.safeGetString(o, "text"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDialog() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root) {
|
||||
|
||||
new LayoutBuilder()
|
||||
.add(new LabelWithElement(MainApp.gs(R.string.sendsmsactiontext), "", text))
|
||||
.build(root);
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,7 @@ class ChooseActionDialog : DialogFragment() {
|
|||
checkedIndex = bundle.getInt("checkedIndex")
|
||||
}
|
||||
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
return inflater.inflate(R.layout.automation_dialog_choose_action, container, false)
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,11 @@ class ChooseActionDialog : DialogFragment() {
|
|||
cancel.setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(bundle: Bundle) {
|
||||
bundle.putInt("checkedIndex", determineCheckedIndex())
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ChooseTriggerDialog : DialogFragment() {
|
|||
checkedIndex = bundle.getInt("checkedIndex")
|
||||
}
|
||||
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
return inflater.inflate(R.layout.automation_dialog_choose_trigger, container, false)
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,11 @@ class ChooseTriggerDialog : DialogFragment() {
|
|||
cancel.setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
fun setOnClickListener(clickListener: OnClickListener) {
|
||||
this.clickListener = clickListener
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ import kotlinx.android.synthetic.main.okcancel.*
|
|||
import org.json.JSONObject
|
||||
|
||||
class EditActionDialog : DialogFragment() {
|
||||
|
||||
private var action: Action? = null
|
||||
private var actionPosition: Int = -1
|
||||
|
||||
|
@ -26,7 +25,7 @@ class EditActionDialog : DialogFragment() {
|
|||
bundle.getString("action")?.let { action = Action.instantiate(JSONObject(it)) }
|
||||
}
|
||||
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
return inflater.inflate(R.layout.automation_dialog_action, container, false)
|
||||
}
|
||||
|
||||
|
@ -51,6 +50,11 @@ class EditActionDialog : DialogFragment() {
|
|||
cancel.setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(bundle: Bundle) {
|
||||
super.onSaveInstanceState(bundle)
|
||||
action?.let {
|
||||
|
|
|
@ -35,7 +35,7 @@ class EditEventDialog : DialogFragment() {
|
|||
bundle.getString("event")?.let { event = AutomationEvent().fromJSON(it) }
|
||||
}
|
||||
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
return inflater.inflate(R.layout.automation_dialog_event, container, false)
|
||||
}
|
||||
|
||||
|
@ -137,6 +137,11 @@ class EditEventDialog : DialogFragment() {
|
|||
)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
disposable.clear()
|
||||
|
|
|
@ -23,7 +23,7 @@ class EditTriggerDialog : DialogFragment() {
|
|||
bundle.getString("trigger")?.let { trigger = Trigger.instantiate(it) }
|
||||
}
|
||||
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
return inflater.inflate(R.layout.automation_dialog_edit_trigger, container, false)
|
||||
}
|
||||
|
||||
|
@ -31,18 +31,23 @@ class EditTriggerDialog : DialogFragment() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// display root trigger
|
||||
trigger?.let { it.generateDialog(automation_layoutTrigger, fragmentManager) }
|
||||
trigger?.generateDialog(automation_layoutTrigger, fragmentManager)
|
||||
|
||||
// OK button
|
||||
ok.setOnClickListener {
|
||||
dismiss()
|
||||
RxBus.send(EventAutomationUpdateTrigger(trigger!!))
|
||||
trigger?.let { trigger -> RxBus.send(EventAutomationUpdateTrigger(trigger)) }
|
||||
}
|
||||
|
||||
// Cancel button
|
||||
cancel.setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(bundle: Bundle) {
|
||||
super.onSaveInstanceState(bundle)
|
||||
trigger?.let { bundle.putString("trigger", it.toJSON()) }
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.elements;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
|
||||
public class InputProfileName extends Element {
|
||||
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
||||
ProfileStore profileStore;
|
||||
|
||||
String profileName;
|
||||
|
||||
public InputProfileName(String name) {
|
||||
super();
|
||||
this.profileName = name;
|
||||
}
|
||||
|
||||
public InputProfileName(InputProfileName another) {
|
||||
super();
|
||||
profileName = another.getValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addToLayout(LinearLayout root) {
|
||||
ArrayList<CharSequence> profileList = new ArrayList<>();
|
||||
profileStore = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile();
|
||||
if (profileStore == null) {
|
||||
log.error("ProfileStore is empty");
|
||||
} else {
|
||||
profileList = profileStore.getProfileList();
|
||||
}
|
||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(root.getContext(),
|
||||
R.layout.spinner_centered, profileList);
|
||||
Spinner spinner = new Spinner(root.getContext());
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(adapter);
|
||||
LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
spinnerParams.setMargins(0, MainApp.dpToPx(4), 0, MainApp.dpToPx(4));
|
||||
spinner.setLayoutParams(spinnerParams);
|
||||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
setValue(listNames().get(position).toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
spinner.setSelection(0);
|
||||
LinearLayout l = new LinearLayout(root.getContext());
|
||||
l.setOrientation(LinearLayout.VERTICAL);
|
||||
l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
l.addView(spinner);
|
||||
root.addView(l);
|
||||
}
|
||||
|
||||
public InputProfileName setValue(String name) {
|
||||
this.profileName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return profileName;
|
||||
}
|
||||
|
||||
public ArrayList<CharSequence> listNames(){
|
||||
ArrayList<CharSequence> profileList = new ArrayList<>();
|
||||
// profile
|
||||
profileStore = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile();
|
||||
if (profileStore == null) {
|
||||
log.error("ProfileStore is empty");
|
||||
} else {
|
||||
profileList = profileStore.getProfileList();
|
||||
}
|
||||
return profileList;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -39,9 +39,9 @@ public class InputTempTarget extends Element {
|
|||
super();
|
||||
setUnits(ProfileFunctions.getInstance().getProfileUnits());
|
||||
if (getUnits().equals(Constants.MMOL))
|
||||
value = Constants.MIN_TT_MMOL;
|
||||
value = 6;
|
||||
else
|
||||
value = Constants.MIN_TT_MGDL;
|
||||
value = 110;
|
||||
}
|
||||
|
||||
public InputTempTarget(InputTempTarget another) {
|
||||
|
|
|
@ -63,16 +63,22 @@ public class TriggerBg extends Trigger {
|
|||
public synchronized boolean shouldRun() {
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
|
||||
if (lastRun > DateUtil.now() - T.mins(5).msecs())
|
||||
if (lastRun > DateUtil.now() - T.mins(5).msecs()) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("NOT ready for execution: " + friendlyDescription());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null && comparator.getValue().equals(Comparator.Compare.IS_NOT_AVAILABLE)) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("Ready for execution: " + friendlyDescription());
|
||||
return true;
|
||||
}
|
||||
if (glucoseStatus == null)
|
||||
if (glucoseStatus == null) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("NOT ready for execution: " + friendlyDescription());
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean doRun = comparator.getValue().check(glucoseStatus.glucose, Profile.toMgdl(bg.getValue(), bg.getUnits()));
|
||||
if (doRun) {
|
||||
|
@ -80,6 +86,9 @@ public class TriggerBg extends Trigger {
|
|||
log.debug("Ready for execution: " + friendlyDescription());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("NOT ready for execution: " + friendlyDescription());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,236 @@
|
|||
package info.nightscout.androidaps.plugins.general.automation.triggers;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Typeface;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
|
||||
|
||||
// Trigger for time range ( from 10:00AM till 13:00PM )
|
||||
|
||||
public class TriggerTimeRange extends Trigger {
|
||||
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
||||
|
||||
// in minutes since midnight 60 means 1AM
|
||||
private int start;
|
||||
private int end;
|
||||
long timeZoneOffset = DateUtil.getTimeZoneOffsetMs();
|
||||
|
||||
public TriggerTimeRange() {
|
||||
|
||||
start = getMinSinceMidnight(DateUtil.now());
|
||||
end = getMinSinceMidnight(DateUtil.now());
|
||||
}
|
||||
|
||||
private TriggerTimeRange(TriggerTimeRange triggerTimeRange) {
|
||||
super();
|
||||
lastRun = triggerTimeRange.lastRun;
|
||||
start = triggerTimeRange.start;
|
||||
end = triggerTimeRange.end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRun() {
|
||||
int currentMinSinceMidnight = getMinSinceMidnight(DateUtil.now());
|
||||
|
||||
if (lastRun > DateUtil.now() - T.mins(5).msecs())
|
||||
return false;
|
||||
|
||||
boolean doRun = false;
|
||||
if ( start < end && start < currentMinSinceMidnight && currentMinSinceMidnight < end)
|
||||
doRun = true;
|
||||
|
||||
// handle cases like 10PM to 6AM
|
||||
else if ( start > end && (start < currentMinSinceMidnight || currentMinSinceMidnight < end))
|
||||
doRun = true;
|
||||
|
||||
if (doRun) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("Ready for execution: " + friendlyDescription());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJSON() {
|
||||
JSONObject object = new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
|
||||
// check for too big values
|
||||
if (start > 1440)
|
||||
start = getMinSinceMidnight(start);
|
||||
if (end > 1440)
|
||||
end = getMinSinceMidnight(end);
|
||||
|
||||
try {
|
||||
data.put("start", getMinSinceMidnight(start));
|
||||
data.put("end", getMinSinceMidnight(end));
|
||||
data.put("lastRun", lastRun);
|
||||
object.put("type", TriggerTimeRange.class.getName());
|
||||
object.put("data", data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.debug(object.toString());
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
TriggerTimeRange fromJSON(String data) {
|
||||
JSONObject o;
|
||||
try {
|
||||
o = new JSONObject(data);
|
||||
lastRun = JsonHelper.safeGetLong(o, "lastRun");
|
||||
start = JsonHelper.safeGetInt(o, "start");
|
||||
end = JsonHelper.safeGetInt(o, "end");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int friendlyName() {
|
||||
return R.string.time_range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String friendlyDescription() {
|
||||
return MainApp.gs(R.string.timerange_value, DateUtil.timeString(toMilis(start) - timeZoneOffset), DateUtil.timeString(toMilis(end) - timeZoneOffset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Integer> icon() {
|
||||
return Optional.of(R.drawable.ic_access_alarm_24dp);
|
||||
}
|
||||
|
||||
TriggerTimeRange period(int start, int end) {
|
||||
this.start = getMinSinceMidnight(start*60000);
|
||||
this.end = getMinSinceMidnight(end*60000);
|
||||
return this;
|
||||
}
|
||||
|
||||
TriggerTimeRange lastRun(long lastRun) {
|
||||
this.lastRun = lastRun;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Trigger duplicate() {
|
||||
return new TriggerTimeRange(this);
|
||||
}
|
||||
|
||||
long toMilis(long minutesSinceMidnight) {
|
||||
return minutesSinceMidnight*60*1000;
|
||||
}
|
||||
|
||||
public int getMinSinceMidnight(long time) {
|
||||
// if passed argument is smaller than 1440 ( 24 h * 60 min ) that value is already converted
|
||||
if (0 < time && time < 1441)
|
||||
return (int) time;
|
||||
Calendar calendar = DateUtil.gregorianCalendar();
|
||||
calendar.setTimeInMillis(time);
|
||||
return (calendar.get(Calendar.HOUR_OF_DAY) * 60) + calendar.get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
int getStart(){
|
||||
return start;
|
||||
}
|
||||
|
||||
int getEnd(){
|
||||
return end;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
|
||||
TextView label = new TextView(root.getContext());
|
||||
TextView startButton = new TextView(root.getContext());
|
||||
TextView endButton = new TextView(root.getContext());
|
||||
log.debug("Start is: " + start );
|
||||
log.debug("End is: " + end );
|
||||
startButton.setText(DateUtil.timeString(toMilis(start) - timeZoneOffset));
|
||||
endButton.setText(MainApp.gs(R.string.and) + " " + DateUtil.timeString(toMilis(end) - timeZoneOffset));
|
||||
|
||||
startButton.setOnClickListener(view -> {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
//setTimeInMillis sets time in milliseconds after
|
||||
// * January 1, 1970, 0:00:00 GMT., but our time contains timezone offsset
|
||||
calendar.setTimeInMillis(toMilis(start) - timeZoneOffset);
|
||||
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
||||
(view12, hourOfDay, minute, second) -> {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
start = getMinSinceMidnight(calendar.getTimeInMillis());
|
||||
startButton.setText(DateUtil.timeString(toMilis(start) - timeZoneOffset));
|
||||
},
|
||||
calendar.get(Calendar.HOUR_OF_DAY),
|
||||
calendar.get(Calendar.MINUTE),
|
||||
DateFormat.is24HourFormat(root.getContext())
|
||||
);
|
||||
tpd.setThemeDark(true);
|
||||
tpd.dismissOnPause(true);
|
||||
Activity a = scanForActivity(root.getContext());
|
||||
if (a != null)
|
||||
tpd.show(a.getFragmentManager(), "TimePickerDialog");
|
||||
});
|
||||
endButton.setOnClickListener(view -> {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTimeInMillis(toMilis(end) - timeZoneOffset);
|
||||
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
||||
(view12, hourOfDay, minute, second) -> {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
end = getMinSinceMidnight(calendar.getTimeInMillis());
|
||||
endButton.setText(MainApp.gs(R.string.and) + " " + DateUtil.timeString(toMilis(end) - timeZoneOffset));
|
||||
},
|
||||
calendar.get(Calendar.HOUR_OF_DAY),
|
||||
calendar.get(Calendar.MINUTE),
|
||||
DateFormat.is24HourFormat(root.getContext())
|
||||
);
|
||||
tpd.setThemeDark(true);
|
||||
tpd.dismissOnPause(true);
|
||||
Activity a = scanForActivity(root.getContext());
|
||||
if (a != null)
|
||||
tpd.show(a.getFragmentManager(), "TimePickerDialog");
|
||||
});
|
||||
|
||||
int px = MainApp.dpToPx(10);
|
||||
label.setText(MainApp.gs(R.string.between));
|
||||
label.setTypeface(label.getTypeface(), Typeface.BOLD);
|
||||
startButton.setPadding(px, px, px, px);
|
||||
endButton.setPadding(px, px, px, px);
|
||||
|
||||
LinearLayout l = new LinearLayout(root.getContext());
|
||||
l.setOrientation(LinearLayout.HORIZONTAL);
|
||||
l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
l.addView(label);
|
||||
l.addView(startButton);
|
||||
l.addView(endButton);
|
||||
root.addView(l);
|
||||
}
|
||||
}
|
|
@ -65,7 +65,7 @@ public class TriggerWifiSsid extends Trigger {
|
|||
return true;
|
||||
}
|
||||
|
||||
boolean doRun = eventNetworkChange.wifiConnected && comparator.getValue().check(eventNetworkChange.ssid, getValue());
|
||||
boolean doRun = eventNetworkChange.wifiConnected && comparator.getValue().check(eventNetworkChange.getSsid(), getValue());
|
||||
if (doRun) {
|
||||
if (L.isEnabled(L.AUTOMATION))
|
||||
log.debug("Ready for execution: " + friendlyDescription());
|
||||
|
|
|
@ -22,12 +22,16 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.SetWarnColor;
|
||||
|
||||
public class CareportalFragment extends SubscriberFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(CareportalFragment.class);
|
||||
|
@ -91,15 +95,15 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
|||
view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this);
|
||||
view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this);
|
||||
|
||||
iage = (TextView) view.findViewById(R.id.careportal_insulinage);
|
||||
cage = (TextView) view.findViewById(R.id.careportal_canulaage);
|
||||
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
|
||||
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
|
||||
iage = view.findViewById(R.id.careportal_insulinage);
|
||||
cage = view.findViewById(R.id.careportal_canulaage);
|
||||
sage = view.findViewById(R.id.careportal_sensorage);
|
||||
pbage = view.findViewById(R.id.careportal_pbage);
|
||||
|
||||
statsLayout = view.findViewById(R.id.careportal_stats);
|
||||
|
||||
noProfileView = view.findViewById(R.id.profileview_noprofile);
|
||||
butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons);
|
||||
butonsLayout = view.findViewById(R.id.careportal_buttons);
|
||||
|
||||
ProfileStore profileStore = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null ? ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile() : null;
|
||||
if (profileStore == null) {
|
||||
|
@ -249,13 +253,17 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
|||
}
|
||||
|
||||
private static TextView handleAge(final TextView age, String eventType, double warnThreshold, double urgentThreshold) {
|
||||
String notavailable = OverviewFragment.shorttextmode ? "-" : MainApp.gs(R.string.notavailable);
|
||||
return handleAge(age, "", eventType, warnThreshold, urgentThreshold, OverviewFragment.shorttextmode);
|
||||
}
|
||||
|
||||
public static TextView handleAge(final TextView age, String prefix, String eventType, double warnThreshold, double urgentThreshold, boolean useShortText) {
|
||||
String notavailable = useShortText ? "-" : MainApp.gs(R.string.notavailable);
|
||||
|
||||
if (age != null) {
|
||||
CareportalEvent careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(eventType);
|
||||
if (careportalEvent != null) {
|
||||
age.setTextColor(CareportalFragment.determineTextColor(careportalEvent, warnThreshold, urgentThreshold));
|
||||
age.setText(careportalEvent.age());
|
||||
age.setText(prefix + careportalEvent.age(useShortText));
|
||||
} else {
|
||||
age.setText(notavailable);
|
||||
}
|
||||
|
|
|
@ -296,7 +296,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
editSplit = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_splitinput);
|
||||
editSplit.setParams(100d, 0d, 100d, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok));
|
||||
editDuration = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_durationinput);
|
||||
editDuration.setParams(0d, 0d, 24 * 60d, 10d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||
editDuration.setParams(0d, 0d, Constants.MAX_PROFILE_SWITCH_DURATION, 10d, new DecimalFormat("0"), false, view.findViewById(R.id.ok));
|
||||
|
||||
TextWatcher percentTextWatcher = new TextWatcher() {
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.nsclient.data;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
@ -16,12 +17,13 @@ import java.util.Objects;
|
|||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.BundleLogger;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
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.notifications.Notification;
|
||||
import info.nightscout.androidaps.logging.BundleLogger;
|
||||
|
||||
/*
|
||||
{
|
||||
|
@ -154,22 +156,22 @@ public class NSSettingsStatus {
|
|||
try {
|
||||
if (nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) {
|
||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NSCLIENT));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.OLD_NSCLIENT));
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
if (nightscoutVersionCode < Config.SUPPORTEDNSVERSION) {
|
||||
Notification notification = new Notification(Notification.OLD_NS, MainApp.gs(R.string.unsupportednsversion), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.OLD_NS));
|
||||
}
|
||||
} else {
|
||||
Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
if (bundle.containsKey("status")) {
|
||||
try {
|
||||
|
@ -180,9 +182,9 @@ public class NSSettingsStatus {
|
|||
Double targetHigh = getThreshold("bgTargetTop");
|
||||
Double targetlow = getThreshold("bgTargetBottom");
|
||||
if (targetHigh != null)
|
||||
OverviewPlugin.bgTargetHigh = targetHigh;
|
||||
OverviewPlugin.INSTANCE.setBgTargetHigh(targetHigh);
|
||||
if (targetlow != null)
|
||||
OverviewPlugin.bgTargetLow = targetlow;
|
||||
OverviewPlugin.INSTANCE.setBgTargetLow(targetlow);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
|||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAddAck;
|
||||
|
@ -177,7 +178,7 @@ public class NSClientService extends Service {
|
|||
if (ev.isChanged(R.string.key_nsclientinternal_url) ||
|
||||
ev.isChanged(R.string.key_nsclientinternal_api_secret) ||
|
||||
ev.isChanged(R.string.key_nsclientinternal_paused)
|
||||
) {
|
||||
) {
|
||||
latestDateInReceivedData = 0;
|
||||
destroy();
|
||||
initialize();
|
||||
|
@ -269,7 +270,7 @@ public class NSClientService extends Service {
|
|||
MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "connections in last " + WATCHDOG_INTERVAL_MINUTES + " mins: " + reconnections.size() + "/" + WATCHDOG_MAXCONNECTIONS));
|
||||
if (reconnections.size() >= WATCHDOG_MAXCONNECTIONS) {
|
||||
Notification n = new Notification(Notification.NSMALFUNCTION, MainApp.gs(R.string.nsmalfunction), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(n));
|
||||
MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "pausing for " + WATCHDOG_RECONNECT_IN + " mins"));
|
||||
NSClientPlugin.getPlugin().pause(true);
|
||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
||||
|
@ -347,9 +348,9 @@ public class NSClientService extends Service {
|
|||
}
|
||||
if (!hasWriteAuth) {
|
||||
Notification noperm = new Notification(Notification.NSCLIENT_NO_WRITE_PERMISSION, MainApp.gs(R.string.nowritepermission), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(noperm));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(noperm));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.NSCLIENT_NO_WRITE_PERMISSION));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.NSCLIENT_NO_WRITE_PERMISSION));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -686,7 +687,7 @@ public class NSClientService extends Service {
|
|||
if ((System.currentTimeMillis() - latestDateInReceivedData) / (60 * 1000L) < 15L)
|
||||
lessThan15MinAgo = true;
|
||||
if (Notification.isAlarmForStaleData() && lessThan15MinAgo) {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.NSALARM));
|
||||
}
|
||||
BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.app.NotificationManager;
|
||||
|
||||
import androidx.arch.core.util.Function;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -58,9 +56,9 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.QuickWizard;
|
||||
import info.nightscout.androidaps.data.QuickWizardEntry;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
|
@ -92,7 +90,6 @@ import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatm
|
|||
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.CalibrationDialog;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.NewCarbsDialog;
|
||||
|
@ -258,17 +255,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
|
||||
tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget);
|
||||
|
||||
iage = (TextView) view.findViewById(R.id.careportal_insulinage);
|
||||
cage = (TextView) view.findViewById(R.id.careportal_canulaage);
|
||||
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
|
||||
pbage = (TextView) view.findViewById(R.id.careportal_pbage);
|
||||
iage = view.findViewById(R.id.careportal_insulinage);
|
||||
cage = view.findViewById(R.id.careportal_canulaage);
|
||||
sage = view.findViewById(R.id.careportal_sensorage);
|
||||
pbage = view.findViewById(R.id.careportal_pbage);
|
||||
|
||||
iageView = (TextView) view.findViewById(R.id.overview_insulinage);
|
||||
cageView = (TextView) view.findViewById(R.id.overview_canulaage);
|
||||
reservoirView = (TextView) view.findViewById(R.id.overview_reservoirlevel);
|
||||
sageView = (TextView) view.findViewById(R.id.overview_sensorage);
|
||||
batteryView = (TextView) view.findViewById(R.id.overview_batterylevel);
|
||||
statuslightsLayout = (LinearLayout) view.findViewById(R.id.overview_statuslights);
|
||||
iageView = view.findViewById(R.id.overview_insulinage);
|
||||
cageView = view.findViewById(R.id.overview_canulaage);
|
||||
reservoirView = view.findViewById(R.id.overview_reservoirlevel);
|
||||
sageView = view.findViewById(R.id.overview_sensorage);
|
||||
batteryView = view.findViewById(R.id.overview_batterylevel);
|
||||
statuslightsLayout = view.findViewById(R.id.overview_statuslights);
|
||||
|
||||
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
|
||||
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
|
||||
|
@ -831,7 +828,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
final String profileName = ProfileFunctions.getInstance().getProfileName();
|
||||
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
|
||||
final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
|
||||
final QuickWizardEntry quickWizardEntry = QuickWizard.INSTANCE.getActive();
|
||||
if (quickWizardEntry != null && actualBg != null && profile != null && pump != null) {
|
||||
quickWizardButton.setVisibility(View.VISIBLE);
|
||||
final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true);
|
||||
|
@ -1012,7 +1009,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
timeView.setText(DateUtil.timeString(new Date()));
|
||||
}
|
||||
|
||||
OverviewPlugin.getPlugin().notificationStore.updateNotifications(notificationsView);
|
||||
OverviewPlugin.INSTANCE.getNotificationStore().updateNotifications(notificationsView);
|
||||
|
||||
pumpStatusLayout.setVisibility(View.GONE);
|
||||
loopStatusLayout.setVisibility(View.GONE);
|
||||
|
@ -1034,8 +1031,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
final String profileName = ProfileFunctions.getInstance().getProfileName();
|
||||
|
||||
final String units = profile.getUnits();
|
||||
final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units);
|
||||
final double highLine = OverviewPlugin.getPlugin().determineHighLine(units);
|
||||
final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
|
||||
final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
|
||||
|
||||
//Start with updating the BG as it is unaffected by loop.
|
||||
// **** BG value ****
|
||||
|
@ -1225,7 +1222,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
|
||||
// QuickWizard button
|
||||
QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
|
||||
QuickWizardEntry quickWizardEntry = QuickWizard.INSTANCE.getActive();
|
||||
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
|
||||
quickWizardButton.setVisibility(View.VISIBLE);
|
||||
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
||||
|
@ -1327,55 +1324,19 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
cobView.setText(cobText);
|
||||
}
|
||||
|
||||
if (statuslightsLayout != null) {
|
||||
if (statuslightsLayout != null)
|
||||
if (SP.getBoolean(R.string.key_show_statuslights, false)) {
|
||||
CareportalEvent careportalEvent;
|
||||
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
|
||||
double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 96);
|
||||
double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 72);
|
||||
double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72);
|
||||
double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48);
|
||||
double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166);
|
||||
double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164);
|
||||
//double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360);
|
||||
//double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240);
|
||||
double batUrgent = SP.getDouble(R.string.key_statuslights_bat_critical, 5.0);
|
||||
double batWarn = SP.getDouble(R.string.key_statuslights_bat_warning, 25.0);
|
||||
double resUrgent = SP.getDouble(R.string.key_statuslights_res_critical, 10.0);
|
||||
double resWarn = SP.getDouble(R.string.key_statuslights_res_warning, 80.0);
|
||||
|
||||
if (cageView != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||
double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
|
||||
applyStatuslight(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE, true);
|
||||
StatuslightHandler handler = new StatuslightHandler();
|
||||
if (SP.getBoolean(R.string.key_show_statuslights_extended, false)) {
|
||||
handler.extendedStatuslight(cageView, iageView, reservoirView, sageView, batteryView);
|
||||
statuslightsLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
handler.statuslight(cageView, iageView, reservoirView, sageView, batteryView);
|
||||
statuslightsLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (iageView != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||
double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
|
||||
applyStatuslight(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE, true);
|
||||
}
|
||||
|
||||
if (reservoirView != null) {
|
||||
double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
|
||||
applyStatuslight(reservoirView, "RES", reservoirLevel, resWarn, resUrgent, -1, false);
|
||||
}
|
||||
|
||||
if (sageView != null) {
|
||||
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
||||
double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
|
||||
applyStatuslight(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE, true);
|
||||
}
|
||||
|
||||
if (batteryView != null) {
|
||||
double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
|
||||
applyStatuslight(batteryView, "BAT", batteryLevel, batWarn, batUrgent, -1, false);
|
||||
}
|
||||
statuslightsLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
statuslightsLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
boolean predictionsAvailable;
|
||||
if (Config.APS)
|
||||
|
@ -1562,21 +1523,5 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
Profiler.log(log, from, updateGUIStart);
|
||||
}
|
||||
|
||||
public static void applyStatuslight(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid, boolean checkAscending) {
|
||||
Function<Double, Boolean> check = checkAscending ? (Double threshold) -> value >= threshold : (Double threshold) -> value <= threshold;
|
||||
if (value != invalid) {
|
||||
view.setText(text);
|
||||
if (check.apply(urgentThreshold)) {
|
||||
view.setTextColor(MainApp.gc(R.color.ribbonCritical));
|
||||
} else if (check.apply(warnThreshold)) {
|
||||
view.setTextColor(MainApp.gc(R.color.ribbonWarning));
|
||||
} else {
|
||||
view.setTextColor(MainApp.gc(R.color.ribbonDefault));
|
||||
}
|
||||
view.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.QuickWizard;
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
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.notifications.NotificationStore;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class OverviewPlugin extends PluginBase {
|
||||
private static Logger log = LoggerFactory.getLogger(L.OVERVIEW);
|
||||
|
||||
private static OverviewPlugin overviewPlugin = new OverviewPlugin();
|
||||
|
||||
public static OverviewPlugin getPlugin() {
|
||||
if (overviewPlugin == null)
|
||||
overviewPlugin = new OverviewPlugin();
|
||||
return overviewPlugin;
|
||||
}
|
||||
|
||||
public static double bgTargetLow = 80d;
|
||||
public static double bgTargetHigh = 180d;
|
||||
|
||||
public QuickWizard quickWizard = new QuickWizard();
|
||||
|
||||
public NotificationStore notificationStore = new NotificationStore();
|
||||
|
||||
public OverviewPlugin() {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
.fragmentClass(OverviewFragment.class.getName())
|
||||
.alwaysVisible(true)
|
||||
.alwaysEnabled(true)
|
||||
.pluginName(R.string.overview)
|
||||
.shortName(R.string.overview_shortname)
|
||||
.preferencesId(R.xml.pref_overview)
|
||||
.description(R.string.description_overview)
|
||||
);
|
||||
String storedData = SP.getString("QuickWizard", "[]");
|
||||
try {
|
||||
quickWizard.setData(new JSONArray(storedData));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
MainApp.bus().register(this);
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewNotification n) {
|
||||
if (notificationStore.add(n.notification))
|
||||
MainApp.bus().post(new EventRefreshOverview("EventNewNotification"));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDismissNotification n) {
|
||||
if (notificationStore.remove(n.id))
|
||||
MainApp.bus().post(new EventRefreshOverview("EventDismissNotification"));
|
||||
}
|
||||
|
||||
public double determineHighLine(String units) {
|
||||
double highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units));
|
||||
if (highLineSetting < 1)
|
||||
highLineSetting = Profile.fromMgdlToUnits(180d, units);
|
||||
return highLineSetting;
|
||||
}
|
||||
|
||||
public double determineLowLine() {
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||
if (profile == null) {
|
||||
return bgTargetLow;
|
||||
}
|
||||
return determineLowLine(profile.getUnits());
|
||||
}
|
||||
|
||||
public double determineLowLine(String units) {
|
||||
double lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units));
|
||||
if (lowLineSetting < 1)
|
||||
lowLineSetting = Profile.fromMgdlToUnits(76d, units);
|
||||
return lowLineSetting;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview
|
||||
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.Profile
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
|
||||
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.notifications.NotificationStore
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import info.nightscout.androidaps.utils.plusAssign
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
object OverviewPlugin : PluginBase(PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
.fragmentClass(OverviewFragment::class.qualifiedName)
|
||||
.alwaysVisible(true)
|
||||
.alwaysEnabled(true)
|
||||
.pluginName(R.string.overview)
|
||||
.shortName(R.string.overview_shortname)
|
||||
.preferencesId(R.xml.pref_overview)
|
||||
.description(R.string.description_overview)) {
|
||||
|
||||
private val log = LoggerFactory.getLogger(L.OVERVIEW)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
var bgTargetLow = 80.0
|
||||
var bgTargetHigh = 180.0
|
||||
|
||||
var notificationStore = NotificationStore()
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
disposable += RxBus
|
||||
.toObservable(EventNewNotification::class.java)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe({ n ->
|
||||
if (notificationStore.add(n.notification))
|
||||
MainApp.bus().post(EventRefreshOverview("EventNewNotification"))
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
disposable += RxBus
|
||||
.toObservable(EventDismissNotification::class.java)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe({ n ->
|
||||
if (notificationStore.remove(n.id))
|
||||
MainApp.bus().post(EventRefreshOverview("EventDismissNotification"))
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
disposable.clear()
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
fun determineHighLine(units: String): Double {
|
||||
var highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(bgTargetHigh, units))!!
|
||||
if (highLineSetting < 1)
|
||||
highLineSetting = Profile.fromMgdlToUnits(180.0, units)
|
||||
return highLineSetting
|
||||
}
|
||||
|
||||
fun determineLowLine(): Double {
|
||||
val profile = ProfileFunctions.getInstance().profile ?: return bgTargetLow
|
||||
return determineLowLine(profile.units)
|
||||
}
|
||||
|
||||
fun determineLowLine(units: String): Double {
|
||||
var lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(bgTargetLow, units))!!
|
||||
if (lowLineSetting < 1)
|
||||
lowLineSetting = Profile.fromMgdlToUnits(76.0, units)
|
||||
return lowLineSetting
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.arch.core.util.Function;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.CareportalEvent;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.SetWarnColor;
|
||||
|
||||
class StatuslightHandler {
|
||||
|
||||
/**
|
||||
* applies the statuslight subview on the overview fragement
|
||||
*/
|
||||
void statuslight(TextView cageView, TextView iageView, TextView reservoirView,
|
||||
TextView sageView, TextView batteryView) {
|
||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
|
||||
applyStatuslight("cage", CareportalEvent.SITECHANGE, cageView, "CAN", 48, 72);
|
||||
applyStatuslight("iage", CareportalEvent.INSULINCHANGE, iageView, "INS", 72, 96);
|
||||
|
||||
double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
|
||||
applyStatuslightLevel(R.string.key_statuslights_res_critical, 10.0,
|
||||
R.string.key_statuslights_res_warning, 80.0, reservoirView, "RES", reservoirLevel);
|
||||
|
||||
applyStatuslight("sage", CareportalEvent.SENSORCHANGE, sageView, "SEN", 164, 166);
|
||||
|
||||
double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
|
||||
applyStatuslightLevel(R.string.key_statuslights_bat_critical, 5.0,
|
||||
R.string.key_statuslights_bat_warning, 22.0,
|
||||
batteryView, "BAT", batteryLevel);
|
||||
|
||||
}
|
||||
|
||||
void applyStatuslight(String nsSettingPlugin, String eventName, TextView view, String text,
|
||||
int defaultWarnThreshold, int defaultUrgentThreshold) {
|
||||
NSSettingsStatus nsSettings = NSSettingsStatus.getInstance();
|
||||
|
||||
if (view != null) {
|
||||
double urgent = nsSettings.getExtendedWarnValue(nsSettingPlugin, "urgent", defaultUrgentThreshold);
|
||||
double warn = nsSettings.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold);
|
||||
CareportalEvent event = MainApp.getDbHelper().getLastCareportalEvent(eventName);
|
||||
double age = event != null ? event.getHoursFromStart() : Double.MAX_VALUE;
|
||||
applyStatuslight(view, text, age, warn, urgent, Double.MAX_VALUE, true);
|
||||
}
|
||||
}
|
||||
|
||||
void applyStatuslightLevel(int criticalSetting, double criticalDefaultValue,
|
||||
int warnSetting, double warnDefaultValue,
|
||||
TextView view, String text, double level) {
|
||||
if (view != null) {
|
||||
double resUrgent = SP.getDouble(criticalSetting, criticalDefaultValue);
|
||||
double resWarn = SP.getDouble(warnSetting, warnDefaultValue);
|
||||
applyStatuslight(view, text, level, resWarn, resUrgent, -1, false);
|
||||
}
|
||||
}
|
||||
|
||||
void applyStatuslight(TextView view, String text, double value, double warnThreshold,
|
||||
double urgentThreshold, double invalid, boolean checkAscending) {
|
||||
Function<Double, Boolean> check = checkAscending ? (Double threshold) -> value >= threshold :
|
||||
(Double threshold) -> value <= threshold;
|
||||
if (value != invalid) {
|
||||
view.setText(text);
|
||||
if (check.apply(urgentThreshold)) {
|
||||
view.setTextColor(MainApp.gc(R.color.ribbonCritical));
|
||||
} else if (check.apply(warnThreshold)) {
|
||||
view.setTextColor(MainApp.gc(R.color.ribbonWarning));
|
||||
} else {
|
||||
view.setTextColor(MainApp.gc(R.color.ribbonDefault));
|
||||
}
|
||||
view.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* applies the extended statuslight subview on the overview fragement
|
||||
*/
|
||||
void extendedStatuslight(TextView cageView, TextView iageView,
|
||||
TextView reservoirView, TextView sageView,
|
||||
TextView batteryView) {
|
||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
|
||||
handleAge("cage", CareportalEvent.SITECHANGE, cageView, "CAN ",
|
||||
48, 72);
|
||||
|
||||
handleAge("iage", CareportalEvent.INSULINCHANGE, iageView, "INS ",
|
||||
72, 96);
|
||||
|
||||
handleLevel(R.string.key_statuslights_res_critical, 10.0,
|
||||
R.string.key_statuslights_res_warning, 80.0,
|
||||
reservoirView, "RES ", pump.getReservoirLevel());
|
||||
|
||||
handleAge("sage", CareportalEvent.SENSORCHANGE, sageView, "SEN ",
|
||||
164, 166);
|
||||
|
||||
handleLevel(R.string.key_statuslights_bat_critical, 26.0,
|
||||
R.string.key_statuslights_bat_warning, 51.0,
|
||||
batteryView, "BAT ", pump.getBatteryLevel());
|
||||
}
|
||||
|
||||
void handleAge(String nsSettingPlugin, String eventName, TextView view, String text,
|
||||
int defaultUrgentThreshold, int defaultWarnThreshold) {
|
||||
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
|
||||
|
||||
if (view != null) {
|
||||
double urgent = nsSettings.getExtendedWarnValue(nsSettingPlugin, "urgent", defaultUrgentThreshold);
|
||||
double warn = nsSettings.getExtendedWarnValue(nsSettingPlugin, "warn", defaultWarnThreshold);
|
||||
CareportalFragment.handleAge(view, text, eventName, warn, urgent, true);
|
||||
}
|
||||
}
|
||||
|
||||
void handleLevel(int criticalSetting, double criticalDefaultValue,
|
||||
int warnSetting, double warnDefaultValue,
|
||||
TextView view, String text, double level) {
|
||||
if (view != null) {
|
||||
double resUrgent = SP.getDouble(criticalSetting, criticalDefaultValue);
|
||||
double resWarn = SP.getDouble(warnSetting, warnDefaultValue);
|
||||
view.setText(text + DecimalFormatter.to0Decimal(level));
|
||||
SetWarnColor.setColorInverse(view, level, resWarn, resUrgent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.data.QuickWizard;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.EditQuickWizardDialog;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
|
||||
public class QuickWizardListActivity extends NoSplashAppCompatActivity implements View.OnClickListener {
|
||||
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
|
||||
Button adButton;
|
||||
|
||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.QuickWizardEntryViewHolder> {
|
||||
|
||||
QuickWizard qvData;
|
||||
FragmentManager fragmentManager;
|
||||
|
||||
RecyclerViewAdapter(QuickWizard data, FragmentManager fragmentManager) {
|
||||
this.qvData = data;
|
||||
this.fragmentManager = fragmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuickWizardEntryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_quickwizardlist_item, viewGroup, false);
|
||||
QuickWizardEntryViewHolder quickWizardEntryViewHolder = new QuickWizardEntryViewHolder(v, fragmentManager, qvData);
|
||||
return quickWizardEntryViewHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(QuickWizardEntryViewHolder holder, int position) {
|
||||
holder.from.setText(DateUtil.timeString(qvData.get(position).validFromDate()));
|
||||
holder.to.setText(DateUtil.timeString(qvData.get(position).validToDate()));
|
||||
holder.buttonText.setText(qvData.get(position).buttonText());
|
||||
holder.carbs.setText(DecimalFormatter.to0Decimal(qvData.get(position).carbs()) + " g");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return qvData.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
public static class QuickWizardEntryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
CardView cv;
|
||||
TextView buttonText;
|
||||
TextView carbs;
|
||||
TextView from;
|
||||
TextView to;
|
||||
Button editButton;
|
||||
Button removeButton;
|
||||
FragmentManager fragmentManager;
|
||||
QuickWizard qvData;
|
||||
|
||||
QuickWizardEntryViewHolder(View itemView, FragmentManager fragmentManager, QuickWizard qvData) {
|
||||
super(itemView);
|
||||
cv = (CardView) itemView.findViewById(R.id.overview_quickwizard_cardview);
|
||||
buttonText = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_buttonText);
|
||||
carbs = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_carbs);
|
||||
from = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_from);
|
||||
to = (TextView) itemView.findViewById(R.id.overview_quickwizard_item_to);
|
||||
editButton = (Button) itemView.findViewById(R.id.overview_quickwizard_item_edit_button);
|
||||
removeButton = (Button) itemView.findViewById(R.id.overview_quickwizard_item_remove_button);
|
||||
editButton.setOnClickListener(this);
|
||||
removeButton.setOnClickListener(this);
|
||||
this.fragmentManager = fragmentManager;
|
||||
this.qvData = qvData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getAdapterPosition();
|
||||
switch (v.getId()) {
|
||||
case R.id.overview_quickwizard_item_edit_button:
|
||||
FragmentManager manager = fragmentManager;
|
||||
EditQuickWizardDialog editQuickWizardDialog = new EditQuickWizardDialog();
|
||||
editQuickWizardDialog.setData(qvData.get(position));
|
||||
editQuickWizardDialog.show(manager, "EditQuickWizardDialog");
|
||||
break;
|
||||
case R.id.overview_quickwizard_item_remove_button:
|
||||
qvData.remove(position);
|
||||
MainApp.bus().post(new EventQuickWizardChange());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.overview_quickwizardlist_activity);
|
||||
|
||||
recyclerView = (RecyclerView) findViewById(R.id.overview_quickwizardactivity_recyclerview);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
llm = new LinearLayoutManager(this);
|
||||
recyclerView.setLayoutManager(llm);
|
||||
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard, getSupportFragmentManager());
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
adButton = (Button) findViewById(R.id.overview_quickwizardactivity_add_button);
|
||||
adButton.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.overview_quickwizardactivity_add_button:
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
EditQuickWizardDialog editQuickWizardDialog = new EditQuickWizardDialog();
|
||||
editQuickWizardDialog.show(manager, "EditQuickWizardDialog");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventQuickWizardChange ev) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
Activity activity = this;
|
||||
if (activity != null && recyclerView != null) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard, getSupportFragmentManager());
|
||||
recyclerView.swapAdapter(adapter, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
||||
import info.nightscout.androidaps.data.QuickWizard
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.EditQuickWizardDialog
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.plusAssign
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.overview_quickwizardlist_activity.*
|
||||
|
||||
class QuickWizardListActivity : NoSplashAppCompatActivity() {
|
||||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
private inner class RecyclerViewAdapter internal constructor(internal var fragmentManager: FragmentManager) : RecyclerView.Adapter<RecyclerViewAdapter.QuickWizardEntryViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QuickWizardEntryViewHolder {
|
||||
return QuickWizardEntryViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.overview_quickwizardlist_item, parent, false), fragmentManager)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: QuickWizardEntryViewHolder, position: Int) {
|
||||
holder.from.text = DateUtil.timeString(QuickWizard[position].validFromDate())
|
||||
holder.to.text = DateUtil.timeString(QuickWizard[position].validToDate())
|
||||
holder.buttonText.text = QuickWizard[position].buttonText()
|
||||
holder.carbs.text = DecimalFormatter.to0Decimal(QuickWizard[position].carbs().toDouble()) + " g"
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = QuickWizard.size()
|
||||
|
||||
private inner class QuickWizardEntryViewHolder internal constructor(itemView: View, internal var fragmentManager: FragmentManager) : RecyclerView.ViewHolder(itemView) {
|
||||
val buttonText: TextView = itemView.findViewById(R.id.overview_quickwizard_item_buttonText)
|
||||
val carbs: TextView = itemView.findViewById(R.id.overview_quickwizard_item_carbs)
|
||||
val from: TextView = itemView.findViewById(R.id.overview_quickwizard_item_from)
|
||||
val to: TextView = itemView.findViewById(R.id.overview_quickwizard_item_to)
|
||||
private val editButton: Button = itemView.findViewById(R.id.overview_quickwizard_item_edit_button)
|
||||
private val removeButton: Button = itemView.findViewById(R.id.overview_quickwizard_item_remove_button)
|
||||
|
||||
init {
|
||||
editButton.setOnClickListener {
|
||||
val manager = fragmentManager
|
||||
val editQuickWizardDialog = EditQuickWizardDialog()
|
||||
editQuickWizardDialog.entry = QuickWizard[adapterPosition]
|
||||
editQuickWizardDialog.show(manager, "EditQuickWizardDialog")
|
||||
}
|
||||
removeButton.setOnClickListener {
|
||||
QuickWizard.remove(adapterPosition)
|
||||
RxBus.send(EventQuickWizardChange())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.overview_quickwizardlist_activity)
|
||||
|
||||
overview_quickwizardactivity_recyclerview?.setHasFixedSize(true)
|
||||
overview_quickwizardactivity_recyclerview?.layoutManager = LinearLayoutManager(this)
|
||||
overview_quickwizardactivity_recyclerview?.adapter = RecyclerViewAdapter(supportFragmentManager)
|
||||
|
||||
overview_quickwizardactivity_add_button.setOnClickListener {
|
||||
val manager = supportFragmentManager
|
||||
val editQuickWizardDialog = EditQuickWizardDialog()
|
||||
editQuickWizardDialog.show(manager, "EditQuickWizardDialog")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable += RxBus
|
||||
.toObservable(EventQuickWizardChange::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({
|
||||
val adapter = RecyclerViewAdapter(supportFragmentManager)
|
||||
overview_quickwizardactivity_recyclerview?.swapAdapter(adapter, false)
|
||||
}, {
|
||||
FabricPrivacy.logException(it)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
disposable.clear()
|
||||
super.onPause()
|
||||
}
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.dialogs;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.QuickWizard;
|
||||
import info.nightscout.androidaps.data.QuickWizardEntry;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.SafeParse;
|
||||
|
||||
public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class);
|
||||
|
||||
QuickWizardEntry entry = new QuickWizard().newEmptyItem();
|
||||
QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard;
|
||||
|
||||
EditText buttonEdit;
|
||||
EditText carbsEdit;
|
||||
Spinner fromSpinner;
|
||||
Spinner toSpinner;
|
||||
Spinner useBGSpinner;
|
||||
Spinner useCOBSpinner;
|
||||
Spinner useBolusIOBSpinner;
|
||||
Spinner useBasalIOBSpinner;
|
||||
Spinner useTrendSpinner;
|
||||
Spinner useSuperBolusSpinner;
|
||||
Spinner useTempTargetSpinner;
|
||||
|
||||
public EditQuickWizardDialog() {
|
||||
}
|
||||
|
||||
public void setData(QuickWizardEntry data) {
|
||||
entry = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
|
||||
View view = inflater.inflate(R.layout.overview_editquickwizard_dialog, container, false);
|
||||
buttonEdit = view.findViewById(R.id.overview_editquickwizard_button_edit);
|
||||
carbsEdit = view.findViewById(R.id.overview_editquickwizard_carbs_edit);
|
||||
fromSpinner = view.findViewById(R.id.overview_editquickwizard_from_spinner);
|
||||
toSpinner = view.findViewById(R.id.overview_editquickwizard_to_spinner);
|
||||
useBGSpinner = view.findViewById(R.id.overview_editquickwizard_usebg_spinner);
|
||||
useCOBSpinner = view.findViewById(R.id.overview_editquickwizard_usecob_spinner);
|
||||
useBolusIOBSpinner = view.findViewById(R.id.overview_editquickwizard_usebolusiob_spinner);
|
||||
useBasalIOBSpinner = view.findViewById(R.id.overview_editquickwizard_usebasaliob_spinner);
|
||||
useTrendSpinner = view.findViewById(R.id.overview_editquickwizard_usetrend_spinner);
|
||||
useSuperBolusSpinner = view.findViewById(R.id.overview_editquickwizard_usesuperbolus_spinner);
|
||||
useTempTargetSpinner = view.findViewById(R.id.overview_editquickwizard_usetemptarget_spinner);
|
||||
|
||||
view.findViewById(R.id.ok).setOnClickListener(this);
|
||||
view.findViewById(R.id.cancel).setOnClickListener(this);
|
||||
|
||||
int posFrom = 0;
|
||||
int posTo = 95;
|
||||
ArrayList<CharSequence> timeList = new ArrayList<>();
|
||||
int pos = 0;
|
||||
for (int t = 0; t < 24 * 60 * 60; t += 15 * 60) {
|
||||
timeList.add(DateUtil.timeString(DateUtil.toDate(t)));
|
||||
if (entry.validFrom() == t) posFrom = pos;
|
||||
if (entry.validTo() == t) posTo = pos;
|
||||
pos++;
|
||||
}
|
||||
timeList.add(DateUtil.timeString(DateUtil.toDate(24 * 60 * 60 - 60)));
|
||||
|
||||
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
|
||||
R.layout.spinner_centered, timeList);
|
||||
fromSpinner.setAdapter(adapter);
|
||||
toSpinner.setAdapter(adapter);
|
||||
|
||||
buttonEdit.setText(entry.buttonText());
|
||||
carbsEdit.setText(entry.carbs().toString());
|
||||
fromSpinner.setSelection(posFrom);
|
||||
toSpinner.setSelection(posTo);
|
||||
|
||||
setSelection(useBGSpinner, entry.useBG());
|
||||
setSelection(useCOBSpinner, entry.useCOB());
|
||||
setSelection(useBolusIOBSpinner, entry.useBolusIOB());
|
||||
setSelection(useBasalIOBSpinner, entry.useBasalIOB());
|
||||
setSelection(useTrendSpinner, entry.useTrend());
|
||||
setSelection(useSuperBolusSpinner, entry.useSuperBolus());
|
||||
setSelection(useTempTargetSpinner, entry.useTempTarget());
|
||||
|
||||
useCOBSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
processCob();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
});
|
||||
processCob();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getDialog() != null)
|
||||
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.ok:
|
||||
if (fromSpinner.getSelectedItem() == null) return;
|
||||
if (toSpinner.getSelectedItem() == null) return;
|
||||
try {
|
||||
entry.storage.put("buttonText", buttonEdit.getText().toString());
|
||||
entry.storage.put("carbs", SafeParse.stringToInt(carbsEdit.getText().toString()));
|
||||
int validFromInt = DateUtil.toSeconds(fromSpinner.getSelectedItem().toString());
|
||||
entry.storage.put("validFrom", validFromInt);
|
||||
int validToInt = DateUtil.toSeconds(toSpinner.getSelectedItem().toString());
|
||||
entry.storage.put("validTo", validToInt);
|
||||
entry.storage.put("useBG", getSelection(useBGSpinner));
|
||||
entry.storage.put("useCOB", getSelection(useCOBSpinner));
|
||||
entry.storage.put("useBolusIOB", getSelection(useBolusIOBSpinner));
|
||||
entry.storage.put("useBasalIOB", getSelection(useBasalIOBSpinner));
|
||||
entry.storage.put("useTrend", getSelection(useTrendSpinner));
|
||||
entry.storage.put("useSuperBolus", getSelection(useSuperBolusSpinner));
|
||||
entry.storage.put("useTempTarget", getSelection(useTempTargetSpinner));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
quickWizard.addOrUpdate(entry);
|
||||
dismiss();
|
||||
MainApp.bus().post(new EventQuickWizardChange());
|
||||
break;
|
||||
case R.id.cancel:
|
||||
dismiss();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void processCob() {
|
||||
if (getSelection(useCOBSpinner) == QuickWizardEntry.YES) {
|
||||
useBolusIOBSpinner.setEnabled(false);
|
||||
useBasalIOBSpinner.setEnabled(false);
|
||||
setSelection(useBolusIOBSpinner, QuickWizardEntry.YES);
|
||||
setSelection(useBasalIOBSpinner, QuickWizardEntry.YES);
|
||||
} else {
|
||||
useBolusIOBSpinner.setEnabled(true);
|
||||
useBasalIOBSpinner.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
int getSelection(Spinner spinner) {
|
||||
String value = spinner.getSelectedItem().toString();
|
||||
if (value.equals(MainApp.gs(R.string.yes)))
|
||||
return QuickWizardEntry.YES;
|
||||
if (value.equals(MainApp.gs(R.string.no)))
|
||||
return QuickWizardEntry.NO;
|
||||
if (value.equals(MainApp.gs(R.string.positiveonly)))
|
||||
return QuickWizardEntry.POSITIVE_ONLY;
|
||||
if (value.equals(MainApp.gs(R.string.negativeonly)))
|
||||
return QuickWizardEntry.NEGATIVE_ONLY;
|
||||
return QuickWizardEntry.NO;
|
||||
}
|
||||
|
||||
void setSelection(Spinner spinner, int value) {
|
||||
String selection;
|
||||
switch (value) {
|
||||
case QuickWizardEntry.YES:
|
||||
selection = MainApp.gs(R.string.yes);
|
||||
break;
|
||||
case QuickWizardEntry.NO:
|
||||
selection = MainApp.gs(R.string.no);
|
||||
break;
|
||||
case QuickWizardEntry.POSITIVE_ONLY:
|
||||
selection = MainApp.gs(R.string.positiveonly);
|
||||
break;
|
||||
case QuickWizardEntry.NEGATIVE_ONLY:
|
||||
selection = MainApp.gs(R.string.negativeonly);
|
||||
break;
|
||||
default:
|
||||
selection = MainApp.gs(R.string.no);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < spinner.getCount(); i++) {
|
||||
if (spinner.getItemAtPosition(i).toString().equalsIgnoreCase(selection)) {
|
||||
spinner.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.dialogs
|
||||
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.data.QuickWizard
|
||||
import info.nightscout.androidaps.data.QuickWizardEntry
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventQuickWizardChange
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.SafeParse
|
||||
import kotlinx.android.synthetic.main.okcancel.*
|
||||
import kotlinx.android.synthetic.main.overview_editquickwizard_dialog.*
|
||||
import org.json.JSONException
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.*
|
||||
|
||||
|
||||
class EditQuickWizardDialog : DialogFragment() {
|
||||
private val log = LoggerFactory.getLogger(EditQuickWizardDialog::class.java)
|
||||
internal var entry = QuickWizard.newEmptyItem()
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
||||
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
||||
isCancelable = true
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
return inflater.inflate(R.layout.overview_editquickwizard_dialog, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
ok.setOnClickListener {
|
||||
if (overview_editquickwizard_from_spinner.selectedItem == null) return@setOnClickListener
|
||||
if (overview_editquickwizard_to_spinner.selectedItem == null) return@setOnClickListener
|
||||
try {
|
||||
entry.storage.put("buttonText", overview_editquickwizard_button_edit.text.toString())
|
||||
entry.storage.put("carbs", SafeParse.stringToInt(overview_editquickwizard_carbs_edit.text.toString()))
|
||||
val validFromInt = DateUtil.toSeconds(overview_editquickwizard_from_spinner.selectedItem.toString())
|
||||
entry.storage.put("validFrom", validFromInt)
|
||||
val validToInt = DateUtil.toSeconds(overview_editquickwizard_to_spinner.selectedItem.toString())
|
||||
entry.storage.put("validTo", validToInt)
|
||||
entry.storage.put("useBG", overview_editquickwizard_usebg_spinner.selectedItemPosition)
|
||||
entry.storage.put("useCOB", overview_editquickwizard_usecob_spinner.selectedItemPosition)
|
||||
entry.storage.put("useBolusIOB", overview_editquickwizard_usebolusiob_spinner.selectedItemPosition)
|
||||
entry.storage.put("useBasalIOB", overview_editquickwizard_usebasaliob_spinner.selectedItemPosition)
|
||||
entry.storage.put("useTrend", overview_editquickwizard_usetrend_spinner.selectedItemPosition)
|
||||
entry.storage.put("useSuperBolus", overview_editquickwizard_usesuperbolus_spinner.selectedItemPosition)
|
||||
entry.storage.put("useTempTarget", overview_editquickwizard_usetemptarget_spinner.selectedItemPosition)
|
||||
} catch (e: JSONException) {
|
||||
log.error("Unhandled exception", e)
|
||||
}
|
||||
|
||||
QuickWizard.addOrUpdate(entry)
|
||||
RxBus.send(EventQuickWizardChange())
|
||||
dismiss()
|
||||
}
|
||||
cancel.setOnClickListener { dismiss() }
|
||||
|
||||
var posFrom = 0
|
||||
var posTo = 95
|
||||
val timeList = ArrayList<CharSequence>()
|
||||
var pos = 0
|
||||
var t = 0
|
||||
while (t < 24 * 60 * 60) {
|
||||
timeList.add(DateUtil.timeString(DateUtil.toDate(t)))
|
||||
if (entry.validFrom() == t) posFrom = pos
|
||||
if (entry.validTo() == t) posTo = pos
|
||||
pos++
|
||||
t += 15 * 60
|
||||
}
|
||||
timeList.add(DateUtil.timeString(DateUtil.toDate(24 * 60 * 60 - 60)))
|
||||
|
||||
val adapter = context?.let { context -> ArrayAdapter(context, R.layout.spinner_centered, timeList) }
|
||||
overview_editquickwizard_from_spinner.adapter = adapter
|
||||
overview_editquickwizard_to_spinner.adapter = adapter
|
||||
|
||||
overview_editquickwizard_button_edit.setText(entry.buttonText())
|
||||
overview_editquickwizard_carbs_edit.setText(entry.carbs().toString())
|
||||
overview_editquickwizard_from_spinner.setSelection(posFrom)
|
||||
overview_editquickwizard_to_spinner.setSelection(posTo)
|
||||
|
||||
overview_editquickwizard_usebg_spinner.setSelection(entry.useBG())
|
||||
overview_editquickwizard_usecob_spinner.setSelection(entry.useCOB())
|
||||
overview_editquickwizard_usebolusiob_spinner.setSelection(entry.useBolusIOB())
|
||||
overview_editquickwizard_usebasaliob_spinner.setSelection(entry.useBasalIOB())
|
||||
overview_editquickwizard_usetrend_spinner.setSelection(entry.useTrend())
|
||||
overview_editquickwizard_usesuperbolus_spinner.setSelection(entry.useSuperBolus())
|
||||
overview_editquickwizard_usetemptarget_spinner.setSelection(entry.useTempTarget())
|
||||
|
||||
overview_editquickwizard_usecob_spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) = processCob()
|
||||
override fun onNothingSelected(parent: AdapterView<*>) {}
|
||||
}
|
||||
processCob()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
private fun processCob() {
|
||||
if (overview_editquickwizard_usecob_spinner.selectedItemPosition == QuickWizardEntry.YES) {
|
||||
overview_editquickwizard_usebolusiob_spinner.isEnabled = false
|
||||
overview_editquickwizard_usebasaliob_spinner.isEnabled = false
|
||||
overview_editquickwizard_usebolusiob_spinner.setSelection(QuickWizardEntry.YES)
|
||||
overview_editquickwizard_usebasaliob_spinner.setSelection(QuickWizardEntry.YES)
|
||||
} else {
|
||||
overview_editquickwizard_usebolusiob_spinner.isEnabled = true
|
||||
overview_editquickwizard_usebasaliob_spinner.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ class ErrorDialog : DialogFragment() {
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
dialog.setTitle(title)
|
||||
dialog?.setTitle(title)
|
||||
isCancelable = false
|
||||
|
||||
savedInstanceState?.let { bundle ->
|
||||
|
|
|
@ -53,7 +53,7 @@ class WizardDialog : DialogFragment() {
|
|||
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
override fun onAttach(context: Context?) {
|
||||
override fun onAttach(context: Context) {
|
||||
super.onAttach(context)
|
||||
this.parentContext = context
|
||||
}
|
||||
|
@ -78,10 +78,10 @@ class WizardDialog : DialogFragment() {
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
dialog.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
||||
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
||||
dialog?.window?.requestFeature(Window.FEATURE_NO_TITLE)
|
||||
dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
|
||||
isCancelable = true
|
||||
dialog.setCanceledOnTouchOutside(false)
|
||||
dialog?.setCanceledOnTouchOutside(false)
|
||||
|
||||
return inflater.inflate(R.layout.overview_wizard_dialog, container, false)
|
||||
}
|
||||
|
@ -107,6 +107,7 @@ class WizardDialog : DialogFragment() {
|
|||
?: 0.0, -60.0, 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
|
||||
initDialog()
|
||||
|
||||
treatments_wizard_percent_used.text = SP.getInt(R.string.key_boluswizard_percentage, 100).toString() + "%"
|
||||
// ok button
|
||||
ok.setOnClickListener {
|
||||
if (okClicked) {
|
||||
|
@ -128,6 +129,7 @@ class WizardDialog : DialogFragment() {
|
|||
treatments_wizard_basaliobcheckbox.setOnCheckedChangeListener { buttonView, _ -> onCheckedChanged(buttonView) }
|
||||
treatments_wizard_bolusiobcheckbox.setOnCheckedChangeListener { buttonView, _ -> onCheckedChanged(buttonView) }
|
||||
treatments_wizard_bgtrendcheckbox.setOnCheckedChangeListener { buttonView, _ -> onCheckedChanged(buttonView) }
|
||||
treatments_wizard_sbcheckbox.setOnCheckedChangeListener { buttonView, _ -> onCheckedChanged(buttonView) }
|
||||
// profile spinner
|
||||
treatments_wizard_profile.onItemSelectedListener = object : OnItemSelectedListener {
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events;
|
||||
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
|
||||
/**
|
||||
* Created by mike on 03.12.2016.
|
||||
*/
|
||||
|
||||
public class EventDismissNotification extends Event {
|
||||
public int id;
|
||||
|
||||
public EventDismissNotification(int did) {
|
||||
id = did;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events
|
||||
|
||||
import info.nightscout.androidaps.events.Event
|
||||
|
||||
class EventDismissNotification(var id: Int) : Event()
|
|
@ -1,16 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events;
|
||||
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
||||
/**
|
||||
* Created by mike on 03.12.2016.
|
||||
*/
|
||||
|
||||
public class EventNewNotification extends Event {
|
||||
public Notification notification;
|
||||
|
||||
public EventNewNotification(Notification n) {
|
||||
notification = n;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events
|
||||
|
||||
import info.nightscout.androidaps.events.Event
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||
|
||||
class EventNewNotification(var notification: Notification) : Event()
|
|
@ -1,10 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events;
|
||||
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
|
||||
/**
|
||||
* Created by mike on 20.10.2016.
|
||||
*/
|
||||
|
||||
public class EventQuickWizardChange extends Event {
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.general.overview.events
|
||||
|
||||
import info.nightscout.androidaps.events.Event
|
||||
|
||||
class EventQuickWizardChange : Event()
|
|
@ -3,9 +3,11 @@ package info.nightscout.androidaps.plugins.general.overview.notifications;
|
|||
import android.app.IntentService;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
|
||||
public class DismissNotificationService extends IntentService {
|
||||
|
@ -19,16 +21,16 @@ public class DismissNotificationService extends IntentService {
|
|||
super(name);
|
||||
}
|
||||
|
||||
public DismissNotificationService(){
|
||||
public DismissNotificationService() {
|
||||
super("DismissNotificationService");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(@Nullable Intent intent) {
|
||||
MainApp.bus().post(new EventDismissNotification(intent.getIntExtra("alertID", -1)));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(intent.getIntExtra("alertID", -1)));
|
||||
}
|
||||
|
||||
public static PendingIntent deleteIntent(int id){
|
||||
public static PendingIntent deleteIntent(int id) {
|
||||
Intent intent = new Intent(MainApp.instance(), DismissNotificationService.class);
|
||||
intent.putExtra("alertID", id);
|
||||
return PendingIntent.getService(MainApp.instance(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
|
|
@ -33,11 +33,12 @@ public class Notification {
|
|||
public static final int OLD_NSCLIENT = 8;
|
||||
public static final int OLD_NS = 9;
|
||||
public static final int INVALID_PHONE_NUMBER = 10;
|
||||
public static final int APPROACHING_DAILY_LIMIT = 11;
|
||||
public static final int NSCLIENT_NO_WRITE_PERMISSION = 12;
|
||||
public static final int MISSING_SMS_PERMISSION = 13;
|
||||
public static final int PUMPERROR = 14;
|
||||
public static final int WRONGSERIALNUMBER = 15;
|
||||
public static final int INVALID_MESSAGE_BODY = 11;
|
||||
public static final int APPROACHING_DAILY_LIMIT = 12;
|
||||
public static final int NSCLIENT_NO_WRITE_PERMISSION = 13;
|
||||
public static final int MISSING_SMS_PERMISSION = 14;
|
||||
public static final int PUMPERROR = 15;
|
||||
public static final int WRONGSERIALNUMBER = 16;
|
||||
|
||||
public static final int NSANNOUNCEMENT = 18;
|
||||
public static final int NSALARM = 19;
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Objects;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAckAlarm;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
|
@ -90,7 +91,7 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
Notification notification = (Notification) v.getTag();
|
||||
MainApp.bus().post(new EventDismissNotification(notification.id));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(notification.id));
|
||||
if (notification.nsAlarm != null) {
|
||||
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
|
||||
}
|
||||
|
@ -98,7 +99,7 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<Notifi
|
|||
if (L.isEnabled(L.NOTIFICATION))
|
||||
log.debug("Notification text is: " + notification.text);
|
||||
if (notification.text.equals(MainApp.gs(R.string.nsalarm_staledata))) {
|
||||
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
|
||||
NotificationStore nstore = OverviewPlugin.INSTANCE.getNotificationStore();
|
||||
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
|
||||
if (L.isEnabled(L.NOTIFICATION))
|
||||
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
|
||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
|||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
@ -103,7 +104,7 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
|
|||
|
||||
private void showNotification() {
|
||||
Notification notification = new Notification(Notification.INVALID_VERSION, MainApp.gs(R.string.running_invalid_version), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
|
||||
private boolean hasIllegalSignature() {
|
||||
|
@ -147,7 +148,7 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
|
|||
private void loadLocalRevokedCerts() {
|
||||
try {
|
||||
String revokedCerts = readCachedDownloadedRevokedCerts();
|
||||
if (revokedCerts == null) revokedCerts = readRevokedCertsInAssets();
|
||||
if (revokedCerts == null) revokedCerts = readRevokedCertsInAssets();
|
||||
synchronized ($lock) {
|
||||
this.revokedCerts = parseRevokedCertsFile(revokedCerts);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
|
@ -106,9 +107,8 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
|||
if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
|
||||
String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
|
||||
|
||||
String pattern = ";";
|
||||
|
||||
String[] substrings = settings.split(pattern);
|
||||
allowedNumbers.clear();
|
||||
String[] substrings = settings.split(";");
|
||||
for (String number : substrings) {
|
||||
String cleaned = number.replaceAll("\\s+", "");
|
||||
allowedNumbers.add(cleaned);
|
||||
|
@ -737,11 +737,13 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
|||
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||
}
|
||||
|
||||
public void sendNotificationToAllNumbers(String text) {
|
||||
public boolean sendNotificationToAllNumbers(String text) {
|
||||
boolean result = true;
|
||||
for (int i = 0; i < allowedNumbers.size(); i++) {
|
||||
Sms sms = new Sms(allowedNumbers.get(i), text);
|
||||
sendSMS(sms);
|
||||
result = result && sendSMS(sms);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void sendSMSToAllNumbers(Sms sms) {
|
||||
|
@ -751,7 +753,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
void sendSMS(Sms sms) {
|
||||
boolean sendSMS(Sms sms) {
|
||||
SmsManager smsManager = SmsManager.getDefault();
|
||||
sms.text = stripAccents(sms.text);
|
||||
|
||||
|
@ -768,13 +770,22 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
|||
|
||||
messages.add(sms);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
if (e.getMessage().equals("Invalid message body")) {
|
||||
Notification notification = new Notification(Notification.INVALID_MESSAGE_BODY, MainApp.gs(R.string.smscommunicator_messagebody), Notification.NORMAL);
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return false;
|
||||
} else {
|
||||
Notification notification = new Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL);
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return false;
|
||||
}
|
||||
} catch (java.lang.SecurityException e) {
|
||||
Notification notification = new Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return false;
|
||||
}
|
||||
MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
|
||||
return true;
|
||||
}
|
||||
|
||||
private String generatePasscode() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.versionChecker
|
|||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
|
@ -46,7 +47,7 @@ object VersionCheckerPlugin : PluginBase(PluginDescription()
|
|||
//notify
|
||||
val message = MainApp.gs(R.string.new_version_warning, Math.round((now - SP.getLong(R.string.key_last_time_this_version_detected, now)) / TimeUnit.DAYS.toMillis(1).toDouble()))
|
||||
val notification = Notification(Notification.OLDVERSION, message, Notification.NORMAL)
|
||||
MainApp.bus().post(EventNewNotification(notification))
|
||||
RxBus.send(EventNewNotification(notification))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import info.nightscout.androidaps.BuildConfig
|
|||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
|
@ -82,7 +83,7 @@ fun onNewVersionDetected(currentVersion: String, newVersion: String?) {
|
|||
if (now > SP.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) {
|
||||
log.debug("Version ${currentVersion} outdated. Found $newVersion")
|
||||
val notification = Notification(Notification.NEWVERSIONDETECTED, String.format(MainApp.gs(R.string.versionavailable), newVersion.toString()), Notification.LOW)
|
||||
MainApp.bus().post(EventNewNotification(notification))
|
||||
RxBus.send(EventNewNotification(notification))
|
||||
SP.putLong(R.string.key_last_versionchecker_warning, now)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.general.wear;
|
|||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.HandlerThread;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.text.DateFormat;
|
||||
|
@ -31,15 +31,15 @@ import info.nightscout.androidaps.interfaces.APSInterface;
|
|||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog;
|
||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
|
||||
|
@ -214,7 +214,7 @@ public class ActionStringHandler {
|
|||
}
|
||||
|
||||
CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "Wizard wear");
|
||||
if (useCOB && (cobInfo == null || cobInfo.displayCob == null)) {
|
||||
if (useCOB && (cobInfo == null || cobInfo.displayCob == null)) {
|
||||
sendError("Unknown COB! BG reading missing or recent app restart?");
|
||||
return;
|
||||
}
|
||||
|
@ -244,7 +244,8 @@ public class ActionStringHandler {
|
|||
rMessage += "\nFrom Carbs: " + format.format(bolusWizard.getInsulinFromCarbs()) + "U";
|
||||
if (useCOB)
|
||||
rMessage += "\nFrom" + formatInt.format(cobInfo.displayCob) + "g COB : " + format.format(bolusWizard.getInsulinFromCOB()) + "U";
|
||||
if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U";
|
||||
if (useBG)
|
||||
rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U";
|
||||
if (useBolusIOB)
|
||||
rMessage += "\nBolus IOB: " + format.format(bolusWizard.getInsulinFromBolusIOB()) + "U";
|
||||
if (useBasalIOB)
|
||||
|
@ -327,17 +328,17 @@ public class ActionStringHandler {
|
|||
int carbs = SafeParse.stringToInt(act[1]);
|
||||
int starttime = SafeParse.stringToInt(act[2]);
|
||||
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();
|
||||
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";
|
||||
|
||||
|
||||
if ( (carbsAfterConstraints - carbs != 0)) {
|
||||
if ((carbsAfterConstraints - carbs != 0)) {
|
||||
rMessage += "\n" + MainApp.gs(R.string.constraintapllied);
|
||||
}
|
||||
if(carbsAfterConstraints <= 0){
|
||||
if (carbsAfterConstraints <= 0) {
|
||||
sendError("Carbs = 0! No action taken!");
|
||||
return;
|
||||
}
|
||||
|
@ -627,14 +628,14 @@ public class ActionStringHandler {
|
|||
int timeshift = SafeParse.stringToInt(act[1]);
|
||||
int percentage = SafeParse.stringToInt(act[2]);
|
||||
setCPP(timeshift, percentage);
|
||||
} else if ("ecarbs".equals(act[0])) {
|
||||
} else if ("ecarbs".equals(act[0])) {
|
||||
int carbs = SafeParse.stringToInt(act[1]);
|
||||
long starttime = SafeParse.stringToLong(act[2]);
|
||||
int duration = SafeParse.stringToInt(act[3]);
|
||||
|
||||
doECarbs(carbs, starttime, duration);
|
||||
} else if ("dismissoverviewnotification".equals(act[0])) {
|
||||
MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1])));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(SafeParse.stringToInt(act[1])));
|
||||
} else if ("changeRequest".equals(act[0])) {
|
||||
LoopPlugin.getPlugin().acceptChangeRequest();
|
||||
NotificationManager notificationManager =
|
||||
|
|
|
@ -316,11 +316,11 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
|
|||
}
|
||||
|
||||
if (lowLine < 1) {
|
||||
lowLine = OverviewPlugin.bgTargetLow;
|
||||
lowLine = OverviewPlugin.INSTANCE.getBgTargetLow();
|
||||
}
|
||||
|
||||
if (highLine < 1) {
|
||||
highLine = OverviewPlugin.bgTargetHigh;
|
||||
highLine = OverviewPlugin.INSTANCE.getBgTargetHigh();
|
||||
}
|
||||
|
||||
long sgvLevel = 0l;
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
package info.nightscout.androidaps.plugins.insulin;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
|
||||
/**
|
||||
* Created by adrian on 13.08.2017.
|
||||
|
@ -35,10 +34,6 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli
|
|||
);
|
||||
}
|
||||
|
||||
public Bus getBus() {
|
||||
return MainApp.bus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDia() {
|
||||
double dia = getUserDefinedDia();
|
||||
|
@ -54,7 +49,7 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli
|
|||
if ((System.currentTimeMillis() - lastWarned) > 60 * 1000) {
|
||||
lastWarned = System.currentTimeMillis();
|
||||
Notification notification = new Notification(Notification.SHORT_DIA, String.format(this.getNotificationPattern(), dia, MIN_DIA), Notification.URGENT);
|
||||
this.getBus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator;
|
|||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import androidx.collection.LongSparseArray;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -24,6 +25,7 @@ import info.nightscout.androidaps.db.TempTarget;
|
|||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
|
@ -199,7 +201,7 @@ public class IobCobOref1Thread extends Thread {
|
|||
log.debug(bucketed_data.toString());
|
||||
log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString());
|
||||
Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
SP.putBoolean("log_AUTOSENS", true);
|
||||
break;
|
||||
}
|
||||
|
@ -225,7 +227,7 @@ public class IobCobOref1Thread extends Thread {
|
|||
log.debug(bucketed_data.toString());
|
||||
log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString());
|
||||
Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
SP.putBoolean("log_AUTOSENS", true);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ public class IobCobThread extends Thread {
|
|||
log.debug(bucketed_data.toString());
|
||||
log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString());
|
||||
Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
SP.putBoolean("log_AUTOSENS", true);
|
||||
break;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ public class IobCobThread extends Thread {
|
|||
log.debug(bucketed_data.toString());
|
||||
log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString());
|
||||
Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
SP.putBoolean("log_AUTOSENS", true);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
|
|||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
|
@ -66,6 +67,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.InstanceId;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
|
@ -231,15 +233,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
// issues a READSTATE when starting to issue commands which initializes the pump
|
||||
log.error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.pumpNotInitializedProfileNotSet));
|
||||
}
|
||||
|
||||
BasalProfile requestedBasalProfile = convertProfileToComboProfile(profile);
|
||||
if (pump.basalProfile.equals(requestedBasalProfile)) {
|
||||
//dismiss previously "FAILED" overview notifications
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
return new PumpEnactResult().success(true).enacted(false);
|
||||
}
|
||||
|
||||
|
@ -252,18 +254,18 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
() -> ruffyScripter.setBasalProfile(requestedBasalProfile));
|
||||
if (!setResult.success) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.failedupdatebasalprofile));
|
||||
}
|
||||
|
||||
pump.basalProfile = requestedBasalProfile;
|
||||
|
||||
//dismiss previously "FAILED" overview notifications
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
//issue success notification
|
||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return new PumpEnactResult().success(true).enacted(true);
|
||||
}
|
||||
|
||||
|
@ -339,7 +341,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
// trigger a connect, which will update state and check history
|
||||
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
|
||||
if (stateResult.invalidSetup) {
|
||||
MainApp.bus().post(new EventNewNotification(
|
||||
RxBus.INSTANCE.send(new EventNewNotification(
|
||||
new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_invalid_setup), Notification.URGENT)));
|
||||
return;
|
||||
}
|
||||
|
@ -360,7 +362,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
MainApp.gs(R.string.combo_force_disabled_notification),
|
||||
Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(n));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -382,7 +384,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
long now = System.currentTimeMillis();
|
||||
if (lastBolusTimestamp < now - 24 * 60 * 60 * 1000 || lastBolusTimestamp > now + 5 * 60 * 1000) {
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_check_date), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -600,7 +602,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
long now = System.currentTimeMillis();
|
||||
if (lastPumpBolus.timestamp < now - 10 * 60 * 1000 || lastPumpBolus.timestamp > now + 10 * 60 * 1000) {
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
|
||||
// update `recentBoluses` so the bolus was just delivered won't be detected as a new
|
||||
|
@ -627,7 +629,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
} finally {
|
||||
pump.activity = null;
|
||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||
MainApp.bus().post(new EventRefreshOverview("Bolus"));
|
||||
RxBus.INSTANCE.send(new EventRefreshOverview("Bolus"));
|
||||
cancelBolus = false;
|
||||
}
|
||||
}
|
||||
|
@ -648,7 +650,9 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
}
|
||||
}
|
||||
|
||||
/** Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. */
|
||||
/**
|
||||
* Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus.
|
||||
*/
|
||||
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
|
||||
DetailedBolusInfo dbi = detailedBolusInfo.copy();
|
||||
dbi.date = calculateFakeBolusDate(lastPumpBolus);
|
||||
|
@ -661,7 +665,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
log.error("Adding treatment record failed", e);
|
||||
if (dbi.isSMB) {
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -880,7 +884,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
MainApp.gs(R.string.combo_force_disabled_notification),
|
||||
Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(n));
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, null);
|
||||
}
|
||||
updateLocalData(commandResult);
|
||||
|
@ -926,7 +930,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
notification.id = Notification.COMBO_PUMP_ALARM;
|
||||
notification.level = Notification.URGENT;
|
||||
notification.text = MainApp.gs(R.string.combo_is_in_error_state, activeAlert.errorCode, activeAlert.message);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
return preCheckResult.success(false);
|
||||
}
|
||||
}
|
||||
|
@ -989,10 +993,10 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
if (readBasalResult.success) {
|
||||
pump.basalProfile = readBasalResult.basalProfile;
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_warning_pump_basal_rate_changed), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_failure_reading_changed_basal_rate), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1008,12 +1012,12 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump clock needs update, pump time: " + state.pumpTime + " (" + new Date(state.pumpTime) + ")");
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_notification_check_time_date), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else if (Math.abs(state.pumpTime - System.currentTimeMillis()) >= 3 * 60 * 1000) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump clock needs update, pump time: " + state.pumpTime + " (" + new Date(state.pumpTime) + ")");
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_notification_check_time_date), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1035,7 +1039,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
} else if (activeAlert.warningCode == PumpWarningCodes.TBR_CANCELLED) {
|
||||
notification.text = MainApp.gs(R.string.combo_pump_tbr_cancelled_warrning);
|
||||
}
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
|
||||
private void checkForUnsafeUsage(CommandResult commandResult) {
|
||||
|
@ -1058,7 +1062,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
MainApp.gs(R.string.combo_low_suspend_forced_notification),
|
||||
Notification.URGENT);
|
||||
n.soundId = R.raw.alarm;
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(n));
|
||||
violationWarningRaisedForBolusAt = lowSuspendOnlyLoopEnforcedUntil;
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, null);
|
||||
}
|
||||
|
@ -1132,7 +1136,9 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
return historyResult.success;
|
||||
}
|
||||
|
||||
/** Return value indicates whether a new record was created. */
|
||||
/**
|
||||
* Return value indicates whether a new record was created.
|
||||
*/
|
||||
private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) {
|
||||
boolean updated = false;
|
||||
for (Bolus pumpBolus : history.bolusHistory) {
|
||||
|
@ -1216,7 +1222,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
|
|||
log.debug("Bolus with same amount within the same minute imported. Only one will make it to the DB.");
|
||||
Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.
|
||||
combo_error_multiple_boluses_with_identical_timestamp), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
}
|
||||
|
||||
pumpHistoryChanged = updateDbFromPumpHistory(historyResult.history);
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.bolusInfo
|
||||
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.util.*
|
||||
import kotlin.math.abs
|
||||
|
||||
object DetailedBolusInfoStorage {
|
||||
private val log = LoggerFactory.getLogger(L.PUMP)
|
||||
val store = ArrayList<DetailedBolusInfo>()
|
||||
|
||||
@Synchronized
|
||||
fun add(detailedBolusInfo: DetailedBolusInfo) {
|
||||
log.debug("Stored bolus info: $detailedBolusInfo")
|
||||
store.add(detailedBolusInfo)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun findDetailedBolusInfo(bolusTime: Long, bolus: Double): DetailedBolusInfo? {
|
||||
// Look for info with bolus
|
||||
for (i in store.indices) {
|
||||
val d = store[i]
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Existing bolus info: " + store[i])
|
||||
if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Using & removing bolus info: " + store[i])
|
||||
store.removeAt(i)
|
||||
return d
|
||||
}
|
||||
}
|
||||
// If not found use time only
|
||||
for (i in store.indices) {
|
||||
val d = store[i]
|
||||
if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && bolus <= store[i].insulin + 0.01) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Using & removing bolus info: " + store[i])
|
||||
store.removeAt(i)
|
||||
return d
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||
|
@ -107,22 +108,22 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
|
|||
if (!isInitialized()) {
|
||||
log.error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
result.comment = MainApp.gs(R.string.pumpNotInitializedProfileNotSet);
|
||||
return result;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
}
|
||||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
result.comment = MainApp.gs(R.string.failedupdatebasalprofile);
|
||||
return result;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.comment = "OK";
|
||||
|
@ -481,7 +482,6 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte
|
|||
if (!veryShort) {
|
||||
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
|
||||
}
|
||||
ret += "IOB: " + pump.iob + "U\n";
|
||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
|
||||
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||
return ret;
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.io.OutputStream;
|
|||
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageHashTable;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageHashTableBase;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread;
|
||||
import info.nightscout.androidaps.utils.CRC;
|
||||
|
||||
|
@ -30,9 +30,11 @@ public class SerialIOThread extends AbstractSerialIOThread {
|
|||
private byte[] mReadBuff = new byte[0];
|
||||
|
||||
private MessageBase processedMessage;
|
||||
private MessageHashTableBase hashTable;
|
||||
|
||||
public SerialIOThread(BluetoothSocket rfcommSocket) {
|
||||
public SerialIOThread(BluetoothSocket rfcommSocket, MessageHashTableBase hashTable) {
|
||||
super();
|
||||
this.hashTable = hashTable;
|
||||
|
||||
mRfCommSocket = rfcommSocket;
|
||||
try {
|
||||
|
@ -68,11 +70,11 @@ public class SerialIOThread extends AbstractSerialIOThread {
|
|||
message = processedMessage;
|
||||
} else {
|
||||
// get it from hash table
|
||||
message = MessageHashTable.findMessage(command);
|
||||
message = hashTable.findMessage(command);
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug("<<<<< " + message.getMessageName() + " " + message.toHexString(extractedBuff));
|
||||
log.debug("<<<<< " + message.getMessageName() + " " + MessageBase.toHexString(extractedBuff));
|
||||
|
||||
// process the message content
|
||||
message.received = true;
|
||||
|
@ -83,14 +85,14 @@ public class SerialIOThread extends AbstractSerialIOThread {
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage().indexOf("bt socket closed") < 0)
|
||||
if (!e.getMessage().contains("bt socket closed"))
|
||||
log.error("Thread exception: ", e);
|
||||
mKeepRunning = false;
|
||||
}
|
||||
disconnect("EndOfLoop");
|
||||
}
|
||||
|
||||
void appendToBuffer(byte[] newData, int gotBytes) {
|
||||
private void appendToBuffer(byte[] newData, int gotBytes) {
|
||||
// add newData to mReadBuff
|
||||
byte[] newReadBuff = new byte[mReadBuff.length + gotBytes];
|
||||
System.arraycopy(mReadBuff, 0, newReadBuff, 0, mReadBuff.length);
|
||||
|
@ -98,7 +100,7 @@ public class SerialIOThread extends AbstractSerialIOThread {
|
|||
mReadBuff = newReadBuff;
|
||||
}
|
||||
|
||||
byte[] cutMessageFromBuffer() {
|
||||
private byte[] cutMessageFromBuffer() {
|
||||
if (mReadBuff[0] == (byte) 0x7E && mReadBuff[1] == (byte) 0x7E) {
|
||||
int length = (mReadBuff[2] & 0xFF) + 7;
|
||||
// Check if we have enough data
|
||||
|
@ -148,7 +150,7 @@ public class SerialIOThread extends AbstractSerialIOThread {
|
|||
|
||||
byte[] messageBytes = message.getRawMessageBytes();
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug(">>>>> " + message.getMessageName() + " " + message.toHexString(messageBytes));
|
||||
log.debug(">>>>> " + message.getMessageName() + " " + MessageBase.toHexString(messageBytes));
|
||||
|
||||
try {
|
||||
mOutputStream.write(messageBytes);
|
||||
|
@ -165,8 +167,10 @@ public class SerialIOThread extends AbstractSerialIOThread {
|
|||
}
|
||||
|
||||
SystemClock.sleep(200);
|
||||
if (!message.received) {
|
||||
log.warn("Reply not received " + message.getMessageName());
|
||||
if (!message.isReceived()) {
|
||||
message.handleMessageNotReceived();
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.error("Reply not received " + message.getMessageName());
|
||||
if (message.getCommand() == 0xF0F1) {
|
||||
DanaRPump.getInstance().isNewPump = false;
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
|
|
|
@ -105,6 +105,9 @@ public class MessageBase {
|
|||
}
|
||||
}
|
||||
|
||||
public void handleMessageNotReceived() {
|
||||
}
|
||||
|
||||
public int getCommand() {
|
||||
int command = byteFromRawBuff(buffer, 5) | (byteFromRawBuff(buffer, 4) << 8);
|
||||
return command;
|
||||
|
@ -189,4 +192,8 @@ public class MessageBase {
|
|||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public boolean isReceived() {
|
||||
return received;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaR.comm;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Created by mike on 28.05.2016.
|
||||
*/
|
||||
public class MessageHashTable {
|
||||
public static HashMap<Integer, MessageBase> messages = null;
|
||||
|
||||
static {
|
||||
if (messages == null) {
|
||||
messages = new HashMap<Integer, MessageBase>();
|
||||
put(new MsgBolusStop()); // 0x0101 CMD_MEALINS_STOP
|
||||
put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA
|
||||
put(new MsgBolusStartWithSpeed()); // 0x0104 CMD_MEALINS_START_DATA_SPEED
|
||||
put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
|
||||
put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING
|
||||
put(new MsgStatusTempBasal()); // 0x0205 CMD_PUMP_EXERCISE_MODE
|
||||
put(new MsgStatusBolusExtended()); // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||
put(new MsgStatusBasic()); // 0x020A CMD_PUMP_INITVIEW_I
|
||||
put(new MsgStatus()); // 0x020B CMD_PUMP_STATUS
|
||||
put(new MsgInitConnStatusTime()); // 0x0301 CMD_PUMPINIT_TIME_INFO
|
||||
put(new MsgInitConnStatusBolus()); // 0x0302 CMD_PUMPINIT_BOLUS_INFO
|
||||
put(new MsgInitConnStatusBasic()); // 0x0303 CMD_PUMPINIT_INIT_INFO
|
||||
put(new MsgInitConnStatusOption()); // 0x0304 CMD_PUMPINIT_OPTION
|
||||
put(new MsgSetTempBasalStart()); // 0x0401 CMD_PUMPSET_EXERCISE_S
|
||||
put(new MsgSetCarbsEntry()); // 0x0402 CMD_PUMPSET_HIS_S
|
||||
put(new MsgSetTempBasalStop()); // 0x0403 CMD_PUMPSET_EXERCISE_STOP
|
||||
put(new MsgSetExtendedBolusStop()); // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
|
||||
put(new MsgSetExtendedBolusStart()); // 0x0407 CMD_PUMPSET_EXPANS_INS_S
|
||||
put(new MsgError()); // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
|
||||
put(new MsgPCCommStart()); // 0x3001 CMD_CONNECT
|
||||
put(new MsgPCCommStop()); // 0x3002 CMD_DISCONNECT
|
||||
put(new MsgHistoryBolus()); // 0x3101 CMD_HISTORY_MEAL_INS
|
||||
put(new MsgHistoryDailyInsulin()); // 0x3102 CMD_HISTORY_DAY_INS
|
||||
put(new MsgHistoryGlucose()); // 0x3104 CMD_HISTORY_GLUCOSE
|
||||
put(new MsgHistoryAlarm()); // 0x3105 CMD_HISTORY_ALARM
|
||||
put(new MsgHistoryError()); // 0x3106 CMD_HISTORY_ERROR
|
||||
put(new MsgHistoryCarbo()); // 0x3107 CMD_HISTORY_CARBOHY
|
||||
put(new MsgHistoryRefill()); // 0x3108 CMD_HISTORY_REFILL
|
||||
put(new MsgHistorySuspend()); // 0x3109 CMD_HISTORY_SUSPEND
|
||||
put(new MsgHistoryBasalHour()); // 0x310A CMD_HISTORY_BASAL_HOUR
|
||||
put(new MsgHistoryDone()); // 0x31F1 CMD_HISTORY_DONT_USED
|
||||
put(new MsgSettingBasal()); // 0x3202 CMD_SETTING_V_BASAL_INS_I
|
||||
put(new MsgSettingMeal()); // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
|
||||
put(new MsgSettingProfileRatios()); // 0x3204 CMD_SETTING_V_CCC_I
|
||||
put(new MsgSettingMaxValues()); // 0x3205 CMD_SETTING_V_MAX_VALUE_I
|
||||
put(new MsgSettingBasalProfileAll()); // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
|
||||
put(new MsgSettingShippingInfo()); // 0x3207 CMD_SETTING_V_SHIPPING_I
|
||||
put(new MsgSettingGlucose()); // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
|
||||
put(new MsgSettingPumpTime()); // 0x320A CMD_SETTING_V_TIME_I
|
||||
put(new MsgSettingUserOptions()); // 0x320B CMD_SETTING_V_USER_OPTIONS
|
||||
put(new MsgSettingActiveProfile()); // 0x320C CMD_SETTING_V_PROFILE_NUMBER
|
||||
put(new MsgSettingProfileRatiosAll()); // 0x320D CMD_SETTING_V_CIR_CF_VALUE
|
||||
put(new MsgSetSingleBasalProfile()); // 0x3302 CMD_SETTING_BASAL_INS_S
|
||||
put(new MsgSetBasalProfile()); // 0x3306 CMD_SETTING_BASAL_PROFILE_S
|
||||
put(new MsgSetUserOptions()); // 0x330B CMD_SETTING_USER_OPTIONS_S
|
||||
put(new MsgSetActivateBasalProfile()); // 0x330C CMD_SETTING_PROFILE_NUMBER_S
|
||||
put(new MsgHistoryAllDone()); // 0x41F1 CMD_HISTORY_ALL_DONE
|
||||
put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL
|
||||
put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE
|
||||
put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW
|
||||
put(new MsgCheckValue()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
public static void put(MessageBase message) {
|
||||
int command = message.getCommand();
|
||||
//String name = MessageOriginalNames.getName(command);
|
||||
messages.put(command, message);
|
||||
//log.debug(String.format("%04x ", command) + " " + name);
|
||||
}
|
||||
|
||||
public static MessageBase findMessage(Integer command) {
|
||||
if (messages.containsKey(command)) {
|
||||
return messages.get(command);
|
||||
} else {
|
||||
return new MessageBase();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaR.comm
|
||||
|
||||
interface MessageHashTableBase {
|
||||
fun put(message: MessageBase)
|
||||
fun findMessage(command: Int): MessageBase
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaR.comm
|
||||
|
||||
import java.util.*
|
||||
|
||||
object MessageHashTableR : MessageHashTableBase {
|
||||
var messages: HashMap<Int, MessageBase> = HashMap()
|
||||
|
||||
init {
|
||||
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
|
||||
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
|
||||
put(MsgBolusStartWithSpeed()) // 0x0104 CMD_MEALINS_START_DATA_SPEED
|
||||
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
|
||||
put(MsgStatusProfile()) // 0x0204 CMD_PUMP_CALCULATION_SETTING
|
||||
put(MsgStatusTempBasal()) // 0x0205 CMD_PUMP_EXERCISE_MODE
|
||||
put(MsgStatusBolusExtended()) // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||
put(MsgStatusBasic()) // 0x020A CMD_PUMP_INITVIEW_I
|
||||
put(MsgStatus()) // 0x020B CMD_PUMP_STATUS
|
||||
put(MsgInitConnStatusTime()) // 0x0301 CMD_PUMPINIT_TIME_INFO
|
||||
put(MsgInitConnStatusBolus()) // 0x0302 CMD_PUMPINIT_BOLUS_INFO
|
||||
put(MsgInitConnStatusBasic()) // 0x0303 CMD_PUMPINIT_INIT_INFO
|
||||
put(MsgInitConnStatusOption()) // 0x0304 CMD_PUMPINIT_OPTION
|
||||
put(MsgSetTempBasalStart()) // 0x0401 CMD_PUMPSET_EXERCISE_S
|
||||
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
|
||||
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
|
||||
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
|
||||
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
|
||||
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
|
||||
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
|
||||
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT
|
||||
put(MsgHistoryBolus()) // 0x3101 CMD_HISTORY_MEAL_INS
|
||||
put(MsgHistoryDailyInsulin()) // 0x3102 CMD_HISTORY_DAY_INS
|
||||
put(MsgHistoryGlucose()) // 0x3104 CMD_HISTORY_GLUCOSE
|
||||
put(MsgHistoryAlarm()) // 0x3105 CMD_HISTORY_ALARM
|
||||
put(MsgHistoryError()) // 0x3106 CMD_HISTORY_ERROR
|
||||
put(MsgHistoryCarbo()) // 0x3107 CMD_HISTORY_CARBOHY
|
||||
put(MsgHistoryRefill()) // 0x3108 CMD_HISTORY_REFILL
|
||||
put(MsgHistorySuspend()) // 0x3109 CMD_HISTORY_SUSPEND
|
||||
put(MsgHistoryBasalHour()) // 0x310A CMD_HISTORY_BASAL_HOUR
|
||||
put(MsgHistoryDone()) // 0x31F1 CMD_HISTORY_DONT_USED
|
||||
put(MsgSettingBasal()) // 0x3202 CMD_SETTING_V_BASAL_INS_I
|
||||
put(MsgSettingMeal()) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
|
||||
put(MsgSettingProfileRatios()) // 0x3204 CMD_SETTING_V_CCC_I
|
||||
put(MsgSettingMaxValues()) // 0x3205 CMD_SETTING_V_MAX_VALUE_I
|
||||
put(MsgSettingBasalProfileAll()) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
|
||||
put(MsgSettingShippingInfo()) // 0x3207 CMD_SETTING_V_SHIPPING_I
|
||||
put(MsgSettingGlucose()) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
|
||||
put(MsgSettingPumpTime()) // 0x320A CMD_SETTING_V_TIME_I
|
||||
put(MsgSettingUserOptions()) // 0x320B CMD_SETTING_V_USER_OPTIONS
|
||||
put(MsgSettingActiveProfile()) // 0x320C CMD_SETTING_V_PROFILE_NUMBER
|
||||
put(MsgSettingProfileRatiosAll()) // 0x320D CMD_SETTING_V_CIR_CF_VALUE
|
||||
put(MsgSetSingleBasalProfile()) // 0x3302 CMD_SETTING_BASAL_INS_S
|
||||
put(MsgSetBasalProfile()) // 0x3306 CMD_SETTING_BASAL_PROFILE_S
|
||||
put(MsgSetUserOptions()) // 0x330B CMD_SETTING_USER_OPTIONS_S
|
||||
put(MsgSetActivateBasalProfile()) // 0x330C CMD_SETTING_PROFILE_NUMBER_S
|
||||
put(MsgHistoryAllDone()) // 0x41F1 CMD_HISTORY_ALL_DONE
|
||||
put(MsgHistoryAll()) // 0x41F2 CMD_HISTORY_ALL
|
||||
put(MsgHistoryNewDone()) // 0x42F1 CMD_HISTORY_NEW_DONE
|
||||
put(MsgHistoryNew()) // 0x42F2 CMD_HISTORY_NEW
|
||||
put(MsgCheckValue()) // 0xF0F1 CMD_PUMP_CHECK_VALUE
|
||||
}
|
||||
|
||||
override fun put(message: MessageBase) {
|
||||
messages[message.command] = message
|
||||
}
|
||||
|
||||
override fun findMessage(command: Int): MessageBase {
|
||||
return messages[command] ?: MessageBase()
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.notifications.Notification;
|
||||
|
@ -45,9 +46,9 @@ public class MsgInitConnStatusBolus extends MessageBase {
|
|||
|
||||
if (!pump.isExtendedBolusEnabled) {
|
||||
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
|
@ -45,13 +46,13 @@ public class MsgInitConnStatusOption extends MessageBase {
|
|||
|
||||
if (!DanaRPump.getInstance().isPasswordOK()) {
|
||||
Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD));
|
||||
}
|
||||
|
||||
// This is last message of initial sequence
|
||||
if (ConfigBuilderPlugin.getPlugin().getActivePump() != null )
|
||||
if (ConfigBuilderPlugin.getPlugin().getActivePump() != null)
|
||||
ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
@ -29,7 +30,7 @@ public class MsgInitConnStatusTime extends MessageBase {
|
|||
public void handleMessage(byte[] bytes) {
|
||||
if (bytes.length - 10 > 7) {
|
||||
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
|
||||
log.error("Wrong model selected. Switching to Korean DanaR");
|
||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true);
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
||||
|
@ -37,12 +38,12 @@ public class MsgSetBasalProfile extends MessageBase {
|
|||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Set basal profile result: " + result + " FAILED!!!");
|
||||
Notification reportFail = new Notification(Notification.PROFILE_SET_FAILED, MainApp.gs(R.string.profile_set_failed), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(reportFail));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(reportFail));
|
||||
} else {
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Set basal profile result: " + result);
|
||||
Notification reportOK = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
MainApp.bus().post(new EventNewNotification(reportOK));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(reportOK));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
|
||||
|
@ -34,12 +35,12 @@ public class MsgSetSingleBasalProfile extends MessageBase {
|
|||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Set basal profile result: " + result + " FAILED!!!");
|
||||
Notification reportFail = new Notification(Notification.PROFILE_SET_FAILED, MainApp.gs(R.string.profile_set_failed), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(reportFail));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(reportFail));
|
||||
} else {
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Set basal profile result: " + result);
|
||||
Notification reportOK = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
MainApp.bus().post(new EventNewNotification(reportOK));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(reportOK));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.notifications.Notification;
|
||||
|
@ -51,16 +52,16 @@ public class MsgSettingMeal extends MessageBase {
|
|||
|
||||
if (pump.basalStep != 0.01d) {
|
||||
Notification notification = new Notification(Notification.WRONGBASALSTEP, MainApp.gs(R.string.danar_setbasalstep001), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.WRONGBASALSTEP));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONGBASALSTEP));
|
||||
}
|
||||
|
||||
if (pump.isConfigUD) {
|
||||
Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.gs(R.string.danar_switchtouhmode), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.UD_MODE_ENABLED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.UD_MODE_ENABLED));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,4 +34,10 @@ public class MsgSettingPumpTime extends MessageBase {
|
|||
|
||||
DanaRPump.getInstance().pumpTime = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessageNotReceived() {
|
||||
DanaRPump.getInstance().pumpTime = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
|
|||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageHashTableR;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
|
||||
|
@ -124,7 +125,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
if (mSerialIOThread != null) {
|
||||
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
||||
}
|
||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||
mSerialIOThread = new SerialIOThread(mRfcommSocket, MessageHashTableR.INSTANCE);
|
||||
mHandshakeInProgress = true;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0));
|
||||
}
|
||||
|
@ -186,6 +187,15 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
mSerialIOThread.sendMessage(new MsgSettingUserOptions());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
|
||||
if (danaRPump.pumpTime == 0) {
|
||||
// initial handshake was not successfull
|
||||
// deinitialize pump
|
||||
danaRPump.lastConnection = 0;
|
||||
danaRPump.lastSettingsRead = 0;
|
||||
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||
MainApp.bus().post(new EventInitializationChanged());
|
||||
return;
|
||||
}
|
||||
long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
|
@ -207,7 +217,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
|
||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(reportFail));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(reportFail));
|
||||
NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
|
||||
lastApproachingDailyLimit = System.currentTimeMillis();
|
||||
}
|
||||
|
|
|
@ -1,210 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRKorean;
|
||||
|
||||
import android.bluetooth.BluetoothSocket;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractSerialIOThread;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MessageHashTable_k;
|
||||
import info.nightscout.androidaps.utils.CRC;
|
||||
|
||||
/**
|
||||
* Created by mike on 17.07.2016.
|
||||
*/
|
||||
public class SerialIOThread extends AbstractSerialIOThread {
|
||||
private static Logger log = LoggerFactory.getLogger(L.PUMPBTCOMM);
|
||||
|
||||
private InputStream mInputStream = null;
|
||||
private OutputStream mOutputStream = null;
|
||||
private BluetoothSocket mRfCommSocket;
|
||||
|
||||
private boolean mKeepRunning = true;
|
||||
private byte[] mReadBuff = new byte[0];
|
||||
|
||||
private MessageBase processedMessage;
|
||||
|
||||
public SerialIOThread(BluetoothSocket rfcommSocket) {
|
||||
super();
|
||||
|
||||
mRfCommSocket = rfcommSocket;
|
||||
try {
|
||||
mOutputStream = mRfCommSocket.getOutputStream();
|
||||
mInputStream = mRfCommSocket.getInputStream();
|
||||
} catch (IOException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
this.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
try {
|
||||
while (mKeepRunning) {
|
||||
int availableBytes = mInputStream.available();
|
||||
// Ask for 1024 byte (or more if available)
|
||||
byte[] newData = new byte[Math.max(1024, availableBytes)];
|
||||
int gotBytes = mInputStream.read(newData);
|
||||
// When we are here there is some new data available
|
||||
appendToBuffer(newData, gotBytes);
|
||||
|
||||
// process all messages we already got
|
||||
while (mReadBuff.length > 3) { // 3rd byte is packet size. continue only if we an determine packet size
|
||||
byte[] extractedBuff = cutMessageFromBuffer();
|
||||
if (extractedBuff == null)
|
||||
break; // message is not complete in buffer (wrong packet calls disconnection)
|
||||
|
||||
int command = (extractedBuff[5] & 0xFF) | ((extractedBuff[4] << 8) & 0xFF00);
|
||||
|
||||
MessageBase message;
|
||||
if (processedMessage != null && processedMessage.getCommand() == command) {
|
||||
message = processedMessage;
|
||||
} else {
|
||||
// get it from hash table
|
||||
message = MessageHashTable_k.findMessage(command);
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug("<<<<< " + message.getMessageName() + " " + message.toHexString(extractedBuff));
|
||||
|
||||
// process the message content
|
||||
message.received = true;
|
||||
message.handleMessage(extractedBuff);
|
||||
synchronized (message) {
|
||||
message.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e.getMessage().indexOf("bt socket closed") < 0)
|
||||
log.error("Thread exception: ", e);
|
||||
mKeepRunning = false;
|
||||
}
|
||||
disconnect("EndOfLoop");
|
||||
}
|
||||
|
||||
void appendToBuffer(byte[] newData, int gotBytes) {
|
||||
// add newData to mReadBuff
|
||||
byte[] newReadBuff = new byte[mReadBuff.length + gotBytes];
|
||||
System.arraycopy(mReadBuff, 0, newReadBuff, 0, mReadBuff.length);
|
||||
System.arraycopy(newData, 0, newReadBuff, mReadBuff.length, gotBytes);
|
||||
mReadBuff = newReadBuff;
|
||||
}
|
||||
|
||||
byte[] cutMessageFromBuffer() {
|
||||
if (mReadBuff[0] == (byte) 0x7E && mReadBuff[1] == (byte) 0x7E) {
|
||||
int length = (mReadBuff[2] & 0xFF) + 7;
|
||||
// Check if we have enough data
|
||||
if (mReadBuff.length < length) {
|
||||
return null;
|
||||
}
|
||||
if (mReadBuff[length - 2] != (byte) 0x2E || mReadBuff[length - 1] != (byte) 0x2E) {
|
||||
log.error("wrong packet lenght=" + length + " data " + MessageBase.toHexString(mReadBuff));
|
||||
disconnect("wrong packet");
|
||||
return null;
|
||||
}
|
||||
|
||||
short crc = CRC.getCrc16(mReadBuff, 3, length - 7);
|
||||
byte crcByte0 = (byte) (crc >> 8 & 0xFF);
|
||||
byte crcByte1 = (byte) (crc & 0xFF);
|
||||
|
||||
byte crcByte0received = mReadBuff[length - 4];
|
||||
byte crcByte1received = mReadBuff[length - 3];
|
||||
|
||||
if (crcByte0 != crcByte0received || crcByte1 != crcByte1received) {
|
||||
log.error("CRC Error" + String.format("%02x ", crcByte0) + String.format("%02x ", crcByte1) + String.format("%02x ", crcByte0received) + String.format("%02x ", crcByte1received));
|
||||
disconnect("crc error");
|
||||
return null;
|
||||
}
|
||||
// Packet is verified here. extract data
|
||||
byte[] extractedBuff = new byte[length];
|
||||
System.arraycopy(mReadBuff, 0, extractedBuff, 0, length);
|
||||
// remove extracted data from read buffer
|
||||
byte[] unprocessedData = new byte[mReadBuff.length - length];
|
||||
System.arraycopy(mReadBuff, length, unprocessedData, 0, unprocessedData.length);
|
||||
mReadBuff = unprocessedData;
|
||||
return extractedBuff;
|
||||
} else {
|
||||
log.error("Wrong beginning of packet len=" + mReadBuff.length + " " + MessageBase.toHexString(mReadBuff));
|
||||
disconnect("Wrong beginning of packet");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void sendMessage(MessageBase message) {
|
||||
if (!mRfCommSocket.isConnected()) {
|
||||
log.error("Socket not connected on sendMessage");
|
||||
return;
|
||||
}
|
||||
processedMessage = message;
|
||||
|
||||
byte[] messageBytes = message.getRawMessageBytes();
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug(">>>>> " + message.getMessageName() + " " + message.toHexString(messageBytes));
|
||||
|
||||
try {
|
||||
mOutputStream.write(messageBytes);
|
||||
} catch (Exception e) {
|
||||
log.error("sendMessage write exception: ", e);
|
||||
}
|
||||
|
||||
synchronized (message) {
|
||||
try {
|
||||
message.wait(5000);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("sendMessage InterruptedException", e);
|
||||
}
|
||||
}
|
||||
|
||||
SystemClock.sleep(200);
|
||||
if (!message.received) {
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.warn("Reply not received " + message.getMessageName());
|
||||
if (message.getCommand() == 0xF0F1) {
|
||||
DanaRPump.getInstance().isNewPump = false;
|
||||
log.error("Old firmware detected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(String reason) {
|
||||
mKeepRunning = false;
|
||||
try {
|
||||
mInputStream.close();
|
||||
} catch (Exception e) {
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
try {
|
||||
mOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
try {
|
||||
mRfCommSocket.close();
|
||||
} catch (Exception e) {
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
try {
|
||||
System.runFinalization();
|
||||
} catch (Exception e) {
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug(e.getMessage());
|
||||
}
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug("Disconnected: " + reason);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.*
|
||||
import java.util.*
|
||||
|
||||
object MessageHashTableRkorean : MessageHashTableBase {
|
||||
var messages: HashMap<Int, MessageBase> = HashMap()
|
||||
|
||||
init {
|
||||
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
|
||||
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
|
||||
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
|
||||
put(MsgStatusProfile()) // 0x0204 CMD_PUMP_CALCULATION_SETTING
|
||||
put(MsgStatusTempBasal()) // 0x0205 CMD_PUMP_EXERCISE_MODE
|
||||
put(MsgStatusBolusExtended()) // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||
put(MsgStatusBasic_k()) // 0x020A CMD_PUMP_INITVIEW_I
|
||||
put(MsgStatus_k()) // 0x020B CMD_PUMP_STATUS
|
||||
put(MsgInitConnStatusTime_k()) // 0x0301 CMD_PUMPINIT_TIME_INFO
|
||||
put(MsgInitConnStatusBolus_k()) // 0x0302 CMD_PUMPINIT_BOLUS_INFO
|
||||
put(MsgInitConnStatusBasic_k()) // 0x0303 CMD_PUMPINIT_INIT_INFO
|
||||
put(MsgSetTempBasalStart()) // 0x0401 CMD_PUMPSET_EXERCISE_S
|
||||
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
|
||||
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
|
||||
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
|
||||
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
|
||||
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
|
||||
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
|
||||
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT
|
||||
put(MsgHistoryBolus()) // 0x3101 CMD_HISTORY_MEAL_INS
|
||||
put(MsgHistoryDailyInsulin()) // 0x3102 CMD_HISTORY_DAY_INS
|
||||
put(MsgHistoryGlucose()) // 0x3104 CMD_HISTORY_GLUCOSE
|
||||
put(MsgHistoryAlarm()) // 0x3105 CMD_HISTORY_ALARM
|
||||
put(MsgHistoryCarbo()) // 0x3107 CMD_HISTORY_CARBOHY
|
||||
put(MsgSettingBasal_k()) // 0x3202 CMD_SETTING_V_BASAL_INS_I
|
||||
put(MsgSettingMeal()) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
|
||||
put(MsgSettingProfileRatios()) // 0x3204 CMD_SETTING_V_CCC_I
|
||||
put(MsgSettingMaxValues()) // 0x3205 CMD_SETTING_V_MAX_VALUE_I
|
||||
put(MsgSettingBasalProfileAll_k()) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
|
||||
put(MsgSettingShippingInfo()) // 0x3207 CMD_SETTING_V_SHIPPING_I
|
||||
put(MsgSettingGlucose()) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
|
||||
put(MsgSettingPumpTime()) // 0x320A CMD_SETTING_V_TIME_I
|
||||
put(MsgSetSingleBasalProfile()) // 0x3302 CMD_SETTING_BASAL_INS_S
|
||||
put(MsgHistoryAll()) // 0x41F2 CMD_HISTORY_ALL
|
||||
put(MsgHistoryNewDone()) // 0x42F1 CMD_HISTORY_NEW_DONE
|
||||
put(MsgHistoryNew()) // 0x42F2 CMD_HISTORY_NEW
|
||||
put(MsgCheckValue_k()) // 0xF0F1 CMD_PUMP_CHECK_VALUE
|
||||
}
|
||||
|
||||
override fun put(message: MessageBase) {
|
||||
messages[message.command] = message
|
||||
}
|
||||
|
||||
override fun findMessage(command: Int): MessageBase {
|
||||
return messages[command] ?: MessageBase()
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.*;
|
||||
|
||||
/**
|
||||
* Created by mike on 28.05.2016.
|
||||
*/
|
||||
public class MessageHashTable_k {
|
||||
private static Logger log = LoggerFactory.getLogger(MessageHashTable_k.class);
|
||||
|
||||
public static HashMap<Integer, MessageBase> messages = null;
|
||||
|
||||
static {
|
||||
if (messages == null) {
|
||||
messages = new HashMap<Integer, MessageBase>();
|
||||
put(new MsgBolusStop()); // 0x0101 CMD_MEALINS_STOP
|
||||
put(new MsgBolusStart()); // 0x0102 CMD_MEALINS_START_DATA
|
||||
put(new MsgBolusProgress()); // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
|
||||
put(new MsgStatusProfile()); // 0x0204 CMD_PUMP_CALCULATION_SETTING
|
||||
put(new MsgStatusTempBasal()); // 0x0205 CMD_PUMP_EXERCISE_MODE
|
||||
put(new MsgStatusBolusExtended()); // 0x0207 CMD_PUMP_EXPANS_INS_I
|
||||
put(new MsgStatusBasic_k()); // 0x020A CMD_PUMP_INITVIEW_I
|
||||
put(new MsgStatus_k()); // 0x020B CMD_PUMP_STATUS
|
||||
put(new MsgInitConnStatusTime_k()); // 0x0301 CMD_PUMPINIT_TIME_INFO
|
||||
put(new MsgInitConnStatusBolus_k()); // 0x0302 CMD_PUMPINIT_BOLUS_INFO
|
||||
put(new MsgInitConnStatusBasic_k()); // 0x0303 CMD_PUMPINIT_INIT_INFO
|
||||
put(new MsgSetTempBasalStart()); // 0x0401 CMD_PUMPSET_EXERCISE_S
|
||||
put(new MsgSetCarbsEntry()); // 0x0402 CMD_PUMPSET_HIS_S
|
||||
put(new MsgSetTempBasalStop()); // 0x0403 CMD_PUMPSET_EXERCISE_STOP
|
||||
put(new MsgSetExtendedBolusStop()); // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
|
||||
put(new MsgSetExtendedBolusStart()); // 0x0407 CMD_PUMPSET_EXPANS_INS_S
|
||||
put(new MsgError()); // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
|
||||
put(new MsgPCCommStart()); // 0x3001 CMD_CONNECT
|
||||
put(new MsgPCCommStop()); // 0x3002 CMD_DISCONNECT
|
||||
put(new MsgHistoryBolus()); // 0x3101 CMD_HISTORY_MEAL_INS
|
||||
put(new MsgHistoryDailyInsulin()); // 0x3102 CMD_HISTORY_DAY_INS
|
||||
put(new MsgHistoryGlucose()); // 0x3104 CMD_HISTORY_GLUCOSE
|
||||
put(new MsgHistoryAlarm()); // 0x3105 CMD_HISTORY_ALARM
|
||||
put(new MsgHistoryCarbo()); // 0x3107 CMD_HISTORY_CARBOHY
|
||||
put(new MsgSettingBasal_k()); // 0x3202 CMD_SETTING_V_BASAL_INS_I
|
||||
put(new MsgSettingMeal()); // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
|
||||
put(new MsgSettingProfileRatios()); // 0x3204 CMD_SETTING_V_CCC_I
|
||||
put(new MsgSettingMaxValues()); // 0x3205 CMD_SETTING_V_MAX_VALUE_I
|
||||
put(new MsgSettingBasalProfileAll_k()); // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
|
||||
put(new MsgSettingShippingInfo()); // 0x3207 CMD_SETTING_V_SHIPPING_I
|
||||
put(new MsgSettingGlucose()); // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
|
||||
put(new MsgSettingPumpTime()); // 0x320A CMD_SETTING_V_TIME_I
|
||||
put(new MsgSetSingleBasalProfile()); // 0x3302 CMD_SETTING_BASAL_INS_S
|
||||
put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL
|
||||
put(new MsgHistoryNewDone()); // 0x42F1 CMD_HISTORY_NEW_DONE
|
||||
put(new MsgHistoryNew()); // 0x42F2 CMD_HISTORY_NEW
|
||||
put(new MsgCheckValue_k()); // 0xF0F1 CMD_PUMP_CHECK_VALUE
|
||||
}
|
||||
}
|
||||
|
||||
public static void put(MessageBase message) {
|
||||
int command = message.getCommand();
|
||||
//String name = MessageOriginalNames.getName(command);
|
||||
messages.put(command, message);
|
||||
//log.debug(String.format("%04x ", command) + " " + name);
|
||||
}
|
||||
|
||||
public static MessageBase findMessage(Integer command) {
|
||||
if (messages.containsKey(command)) {
|
||||
return messages.get(command);
|
||||
} else {
|
||||
return new MessageBase();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.notifications.Notification;
|
||||
|
@ -42,16 +43,16 @@ public class MsgInitConnStatusBasic_k extends MessageBase {
|
|||
|
||||
if (pump.isEasyModeEnabled) {
|
||||
Notification notification = new Notification(Notification.EASYMODE_ENABLED, MainApp.gs(R.string.danar_disableeasymode), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.EASYMODE_ENABLED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.EASYMODE_ENABLED));
|
||||
}
|
||||
|
||||
if (!DanaRPump.getInstance().isPasswordOK()) {
|
||||
Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
|
@ -48,9 +49,9 @@ public class MsgInitConnStatusBolus_k extends MessageBase {
|
|||
|
||||
if (!pump.isExtendedBolusEnabled) {
|
||||
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
|
||||
}
|
||||
|
||||
// This is last message of initial sequence
|
||||
|
|
|
@ -8,6 +8,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
|
@ -31,7 +32,7 @@ public class MsgInitConnStatusTime_k extends MessageBase {
|
|||
|
||||
if (bytes.length - 10 < 10) {
|
||||
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
|
||||
log.error("Wrong model selected. Switching to export DanaR");
|
||||
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, false);
|
||||
|
|
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgress
|
|||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStop;
|
||||
|
@ -51,7 +52,7 @@ import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended
|
|||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.SerialIOThread;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MessageHashTableRkorean;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgCheckValue_k;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgSettingBasal_k;
|
||||
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgStatusBasic_k;
|
||||
|
@ -129,7 +130,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
if (mSerialIOThread != null) {
|
||||
mSerialIOThread.disconnect("Recreate SerialIOThread");
|
||||
}
|
||||
mSerialIOThread = new SerialIOThread(mRfcommSocket);
|
||||
mSerialIOThread = new SerialIOThread(mRfcommSocket, MessageHashTableRkorean.INSTANCE);
|
||||
mHandshakeInProgress = true;
|
||||
MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.HANDSHAKING, 0));
|
||||
}
|
||||
|
@ -187,6 +188,15 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
|
||||
MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
|
||||
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
|
||||
if (danaRPump.pumpTime == 0) {
|
||||
// initial handshake was not successfull
|
||||
// deinitialize pump
|
||||
danaRPump.lastConnection = 0;
|
||||
danaRPump.lastSettingsRead = 0;
|
||||
RxBus.INSTANCE.send(new EventDanaRNewStatus());
|
||||
MainApp.bus().post(new EventInitializationChanged());
|
||||
return;
|
||||
}
|
||||
long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("Pump time difference: " + timeDiff + " seconds");
|
||||
|
@ -210,7 +220,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
|
||||
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
|
||||
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(reportFail));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(reportFail));
|
||||
NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
|
||||
lastApproachingDailyLimit = System.currentTimeMillis();
|
||||
}
|
||||
|
|
|
@ -38,8 +38,9 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
|||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.common.ManufacturerType;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
|
||||
|
@ -305,22 +306,22 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
if (!isInitialized()) {
|
||||
log.error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
result.comment = MainApp.gs(R.string.pumpNotInitializedProfileNotSet);
|
||||
return result;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
}
|
||||
if (!danaRSService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
result.comment = MainApp.gs(R.string.failedupdatebasalprofile);
|
||||
return result;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.comment = "OK";
|
||||
|
@ -361,10 +362,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getReservoirLevel() { return DanaRPump.getInstance().reservoirRemainingUnits; }
|
||||
public double getReservoirLevel() {
|
||||
return DanaRPump.getInstance().reservoirRemainingUnits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatteryLevel() { return DanaRPump.getInstance().batteryRemaining; }
|
||||
public int getBatteryLevel() {
|
||||
return DanaRPump.getInstance().batteryRemaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) {
|
||||
|
@ -394,7 +399,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
if (carbTime == 0) carbTime--; // better set 1 min back to prevents clash with insulin
|
||||
detailedBolusInfo.carbTime = 0;
|
||||
|
||||
DetailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
|
||||
DetailedBolusInfoStorage.INSTANCE.add(detailedBolusInfo); // will be picked up on reading history
|
||||
|
||||
Treatment t = new Treatment();
|
||||
t.isSMB = detailedBolusInfo.isSMB;
|
||||
|
@ -794,7 +799,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
if (!veryShort) {
|
||||
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
|
||||
}
|
||||
ret += "IOB: " + pump.iob + "U\n";
|
||||
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
|
||||
ret += "Batt: " + pump.batteryRemaining + "\n";
|
||||
return ret;
|
||||
|
|
|
@ -58,6 +58,9 @@ public class DanaRS_Packet {
|
|||
public void handleMessage(byte[] data) {
|
||||
}
|
||||
|
||||
public void handleMessageNotReceived() {
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return "UNKNOWN_PACKET";
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import info.nightscout.androidaps.db.Source;
|
|||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
|
@ -129,7 +129,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.BOLUS:
|
||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
|
||||
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(datetime, param1 / 100d);
|
||||
if (detailedBolusInfo == null) {
|
||||
detailedBolusInfo = new DetailedBolusInfo();
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
|
|||
status = "BOLUS " + DateUtil.timeString(datetime);
|
||||
break;
|
||||
case DanaRPump.DUALBOLUS:
|
||||
detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime);
|
||||
detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(datetime, param1 / 100d);
|
||||
if (detailedBolusInfo == null) {
|
||||
detailedBolusInfo = new DetailedBolusInfo();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Locale;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.notifications.Notification;
|
||||
|
@ -57,9 +58,9 @@ public class DanaRS_Packet_Basal_Get_Basal_Rate extends DanaRS_Packet {
|
|||
if (pump.basalStep != 0.01d) {
|
||||
failed = true;
|
||||
Notification notification = new Notification(Notification.WRONGBASALSTEP, MainApp.gs(R.string.danar_setbasalstep001), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.WRONGBASALSTEP));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONGBASALSTEP));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.notifications.Notification;
|
||||
|
@ -105,10 +106,10 @@ public class DanaRS_Packet_Bolus_Get_Bolus_Option extends DanaRS_Packet {
|
|||
|
||||
if (!pump.isExtendedBolusEnabled) {
|
||||
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(notification));
|
||||
failed = true;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
|
||||
RxBus.INSTANCE.send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.PUMPCOMM)) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
|
@ -24,7 +25,7 @@ public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
|
|||
|
||||
@Override
|
||||
public void handleMessage(byte[] data) {
|
||||
if (data.length <5){
|
||||
if (data.length < 5) {
|
||||
failed = true;
|
||||
return;
|
||||
}
|
||||
|
@ -49,7 +50,7 @@ public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet {
|
|||
}
|
||||
|
||||
if (pump.productCode < 2) {
|
||||
MainApp.bus().post(new EventNewNotification(new Notification(Notification.UNSUPPORTED_FIRMWARE, MainApp.gs(R.string.unsupportedfirmware), Notification.URGENT)));
|
||||
RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.UNSUPPORTED_FIRMWARE, MainApp.gs(R.string.unsupportedfirmware), Notification.URGENT)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ public class DanaRS_Packet_Option_Get_Pump_Time extends DanaRS_Packet {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessageNotReceived() {
|
||||
DanaRPump.getInstance().pumpTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFriendlyName() {
|
||||
return "OPTION__GET_PUMP_TIME";
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue