Merge branch 'tt' into adrian/tt
This commit is contained in:
commit
e5b15a3f11
17 changed files with 174 additions and 50 deletions
|
@ -2,6 +2,22 @@
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<option name="AUTODETECT_INDENTS" value="false" />
|
<option name="AUTODETECT_INDENTS" value="false" />
|
||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
|
<value>
|
||||||
|
<package name="java.util" alias="false" withSubpackages="false" />
|
||||||
|
<package name="kotlinx.android.synthetic" alias="false" withSubpackages="true" />
|
||||||
|
<package name="io.ktor" alias="false" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="PACKAGES_IMPORT_LAYOUT">
|
||||||
|
<value>
|
||||||
|
<package name="" alias="false" withSubpackages="true" />
|
||||||
|
<package name="java" alias="false" withSubpackages="true" />
|
||||||
|
<package name="javax" alias="false" withSubpackages="true" />
|
||||||
|
<package name="kotlin" alias="false" withSubpackages="true" />
|
||||||
|
<package name="" alias="true" withSubpackages="true" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
<option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" />
|
<option name="ALIGN_IN_COLUMNS_CASE_BRANCH" value="true" />
|
||||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="6" />
|
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="6" />
|
||||||
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="6" />
|
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="6" />
|
||||||
|
|
|
@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
|
||||||
import com.j256.ormlite.dao.CloseableIterator;
|
import com.j256.ormlite.dao.CloseableIterator;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -13,7 +14,9 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
||||||
|
@ -77,8 +80,8 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
||||||
MainApp.getDbHelper().createOrUpdateTDD(record);
|
MainApp.getDbHelper().createOrUpdateTDD(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void createOrUpdate(@NonNull TemporaryBasal tempBasal) {
|
@Override public boolean createOrUpdate(@NonNull TemporaryBasal tempBasal) {
|
||||||
MainApp.getDbHelper().createOrUpdate(tempBasal);
|
return MainApp.getDbHelper().createOrUpdate(tempBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull @Override public TemporaryBasal findTempBasalByPumpId(long id) {
|
@NonNull @Override public TemporaryBasal findTempBasalByPumpId(long id) {
|
||||||
|
@ -140,4 +143,56 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
||||||
@Nullable @Override public InsightPumpID getPumpStoppedEvent(@NonNull String pumpSerial, long before) {
|
@Nullable @Override public InsightPumpID getPumpStoppedEvent(@NonNull String pumpSerial, long before) {
|
||||||
return MainApp.getDbHelper().getPumpStoppedEvent(pumpSerial, before);
|
return MainApp.getDbHelper().getPumpStoppedEvent(pumpSerial, before);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public boolean createOrUpdate(@NonNull ExtendedBolus extendedBolus) {
|
||||||
|
return MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void createOrUpdate(@NonNull ProfileSwitch profileSwitch) {
|
||||||
|
MainApp.getDbHelper().createOrUpdate(profileSwitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void delete(@NonNull TemporaryBasal tempBasal) {
|
||||||
|
MainApp.getDbHelper().delete(tempBasal);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull @Override public List<ExtendedBolus> getExtendedBolusDataFromTime(long mills, boolean ascending) {
|
||||||
|
return MainApp.getDbHelper().getExtendedBolusDataFromTime(mills, ascending);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void deleteTempBasalById(@NonNull String _id) {
|
||||||
|
MainApp.getDbHelper().deleteTempBasalById(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void deleteExtendedBolusById(@NonNull String _id) {
|
||||||
|
MainApp.getDbHelper().deleteExtendedBolusById(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void deleteCareportalEventById(@NonNull String _id) {
|
||||||
|
MainApp.getDbHelper().deleteCareportalEventById(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void deleteProfileSwitchById(@NonNull String _id) {
|
||||||
|
MainApp.getDbHelper().deleteProfileSwitchById(_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void createTempBasalFromJsonIfNotExists(@NonNull JSONObject json) {
|
||||||
|
MainApp.getDbHelper().createTempBasalFromJsonIfNotExists(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void createExtendedBolusFromJsonIfNotExists(@NonNull JSONObject json) {
|
||||||
|
MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void createCareportalEventFromJsonIfNotExists(@NonNull JSONObject json) {
|
||||||
|
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void createProfileSwitchFromJsonIfNotExists(@NonNull ActivePluginProvider activePluginProvider, @NonNull NSUpload nsUpload, @NonNull JSONObject trJson) {
|
||||||
|
MainApp.getDbHelper().createProfileSwitchFromJsonIfNotExists(activePluginProvider, nsUpload, trJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public void resetDatabases() {
|
||||||
|
MainApp.getDbHelper().resetDatabases();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.databinding.DialogCareBinding
|
import info.nightscout.androidaps.databinding.DialogCareBinding
|
||||||
import info.nightscout.androidaps.db.CareportalEvent
|
import info.nightscout.androidaps.db.CareportalEvent
|
||||||
import info.nightscout.androidaps.db.Source
|
import info.nightscout.androidaps.db.Source
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
@ -39,6 +40,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
@Inject lateinit var nsUpload: NSUpload
|
@Inject lateinit var nsUpload: NSUpload
|
||||||
@Inject lateinit var translator: Translator
|
@Inject lateinit var translator: Translator
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||||
|
|
||||||
enum class EventType {
|
enum class EventType {
|
||||||
BGCHECK,
|
BGCHECK,
|
||||||
|
@ -112,7 +114,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
when (options) {
|
when (options) {
|
||||||
EventType.QUESTION,
|
EventType.QUESTION,
|
||||||
EventType.ANNOUNCEMENT,
|
EventType.ANNOUNCEMENT,
|
||||||
EventType.BGCHECK -> {
|
EventType.BGCHECK -> {
|
||||||
binding.durationLayout.visibility = View.GONE
|
binding.durationLayout.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +126,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
EventType.NOTE,
|
EventType.NOTE,
|
||||||
EventType.EXERCISE -> {
|
EventType.EXERCISE -> {
|
||||||
binding.bgLayout.visibility = View.GONE
|
binding.bgLayout.visibility = View.GONE
|
||||||
binding.bgsource.visibility = View.GONE
|
binding.bgsource.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
@ -223,7 +225,7 @@ class CareDialog : DialogFragmentWithDate() {
|
||||||
}
|
}
|
||||||
careportalEvent.json = json.toString()
|
careportalEvent.json = json.toString()
|
||||||
uel.log("CAREPORTAL", careportalEvent.eventType)
|
uel.log("CAREPORTAL", careportalEvent.eventType)
|
||||||
MainApp.getDbHelper().createOrUpdate(careportalEvent)
|
databaseHelper.createOrUpdate(careportalEvent)
|
||||||
nsUpload.uploadCareportalEntryToNS(json, eventTime)
|
nsUpload.uploadCareportalEntryToNS(json, eventTime)
|
||||||
}, null)
|
}, null)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
@ -34,8 +35,9 @@ class TreatmentsPluginHistory @Inject constructor(
|
||||||
fabricPrivacy: FabricPrivacy,
|
fabricPrivacy: FabricPrivacy,
|
||||||
dateUtil: DateUtil,
|
dateUtil: DateUtil,
|
||||||
uploadQueue: UploadQueue,
|
uploadQueue: UploadQueue,
|
||||||
|
databaseHelper: DatabaseHelperInterface,
|
||||||
repository: AppRepository
|
repository: AppRepository
|
||||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue, repository) {
|
) : TreatmentsPlugin(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue, databaseHelper, repository) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onStart()
|
onStart()
|
||||||
|
|
|
@ -75,6 +75,7 @@ open class LoopPlugin @Inject constructor(
|
||||||
private val receiverStatusStore: ReceiverStatusStore,
|
private val receiverStatusStore: ReceiverStatusStore,
|
||||||
private val fabricPrivacy: FabricPrivacy,
|
private val fabricPrivacy: FabricPrivacy,
|
||||||
private val nsUpload: NSUpload,
|
private val nsUpload: NSUpload,
|
||||||
|
private val databaseHelper: DatabaseHelperInterface,
|
||||||
private val hardLimits: HardLimits
|
private val hardLimits: HardLimits
|
||||||
) : PluginBase(PluginDescription()
|
) : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.LOOP)
|
.mainType(PluginType.LOOP)
|
||||||
|
@ -663,7 +664,7 @@ open class LoopPlugin @Inject constructor(
|
||||||
event.source = Source.USER
|
event.source = Source.USER
|
||||||
event.eventType = CareportalEvent.OPENAPSOFFLINE
|
event.eventType = CareportalEvent.OPENAPSOFFLINE
|
||||||
event.json = data.toString()
|
event.json = data.toString()
|
||||||
MainApp.getDbHelper().createOrUpdate(event)
|
databaseHelper.createOrUpdate(event)
|
||||||
nsUpload.uploadOpenAPSOffline(event)
|
nsUpload.uploadOpenAPSOffline(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,11 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import dagger.android.support.DaggerFragment
|
import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
||||||
import info.nightscout.androidaps.events.EventNewBG
|
import info.nightscout.androidaps.events.EventNewBG
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||||
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||||
|
@ -37,6 +37,7 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface
|
@Inject lateinit var importExportPrefs: ImportExportPrefsInterface
|
||||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||||
@Inject lateinit var repository: AppRepository
|
@Inject lateinit var repository: AppRepository
|
||||||
|
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||||
@Inject lateinit var uel: UserEntryLogger
|
@Inject lateinit var uel: UserEntryLogger
|
||||||
|
|
||||||
private val compositeDisposable = CompositeDisposable()
|
private val compositeDisposable = CompositeDisposable()
|
||||||
|
@ -65,7 +66,7 @@ class MaintenanceFragment : DaggerFragment() {
|
||||||
uel.log("RESET DATABASES")
|
uel.log("RESET DATABASES")
|
||||||
compositeDisposable.add(
|
compositeDisposable.add(
|
||||||
fromAction {
|
fromAction {
|
||||||
MainApp.getDbHelper().resetDatabases()
|
databaseHelper.resetDatabases()
|
||||||
// should be handled by Plugin-Interface and
|
// should be handled by Plugin-Interface and
|
||||||
// additional service interface and plugin registry
|
// additional service interface and plugin registry
|
||||||
foodPlugin.service?.resetFood()
|
foodPlugin.service?.resetFood()
|
||||||
|
|
|
@ -27,7 +27,6 @@ import javax.inject.Singleton;
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.database.AppRepository;
|
import info.nightscout.androidaps.database.AppRepository;
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryTarget;
|
import info.nightscout.androidaps.database.entities.TemporaryTarget;
|
||||||
|
@ -39,6 +38,7 @@ import info.nightscout.androidaps.events.EventNetworkChange;
|
||||||
import info.nightscout.androidaps.events.EventNsTreatment;
|
import info.nightscout.androidaps.events.EventNsTreatment;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
@ -86,6 +86,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
private final ActivePluginProvider activePlugin;
|
private final ActivePluginProvider activePlugin;
|
||||||
private final NSUpload nsUpload;
|
private final NSUpload nsUpload;
|
||||||
private final AppRepository repository;
|
private final AppRepository repository;
|
||||||
|
private final DatabaseHelperInterface databaseHelper;
|
||||||
private final UserEntryLogger uel;
|
private final UserEntryLogger uel;
|
||||||
|
|
||||||
public Handler handler;
|
public Handler handler;
|
||||||
|
@ -117,6 +118,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
BuildHelper buildHelper,
|
BuildHelper buildHelper,
|
||||||
ActivePluginProvider activePlugin,
|
ActivePluginProvider activePlugin,
|
||||||
NSUpload nsUpload,
|
NSUpload nsUpload,
|
||||||
|
DatabaseHelperInterface databaseHelper,
|
||||||
AppRepository repository,
|
AppRepository repository,
|
||||||
UserEntryLogger uel
|
UserEntryLogger uel
|
||||||
) {
|
) {
|
||||||
|
@ -143,6 +145,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
this.buildHelper = buildHelper;
|
this.buildHelper = buildHelper;
|
||||||
this.activePlugin = activePlugin;
|
this.activePlugin = activePlugin;
|
||||||
this.nsUpload = nsUpload;
|
this.nsUpload = nsUpload;
|
||||||
|
this.databaseHelper = databaseHelper;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.uel = uel;
|
this.uel = uel;
|
||||||
|
|
||||||
|
@ -426,10 +429,10 @@ public class NSClientPlugin extends PluginBase {
|
||||||
EventNsTreatment evtTreatment = new EventNsTreatment(EventNsTreatment.Companion.getREMOVE(), json);
|
EventNsTreatment evtTreatment = new EventNsTreatment(EventNsTreatment.Companion.getREMOVE(), json);
|
||||||
rxBus.send(evtTreatment);
|
rxBus.send(evtTreatment);
|
||||||
// old DB model
|
// old DB model
|
||||||
MainApp.getDbHelper().deleteTempBasalById(_id);
|
databaseHelper.deleteTempBasalById(_id);
|
||||||
MainApp.getDbHelper().deleteExtendedBolusById(_id);
|
databaseHelper.deleteExtendedBolusById(_id);
|
||||||
MainApp.getDbHelper().deleteCareportalEventById(_id);
|
databaseHelper.deleteCareportalEventById(_id);
|
||||||
MainApp.getDbHelper().deleteProfileSwitchById(_id);
|
databaseHelper.deleteProfileSwitchById(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleTreatmentFromNS(JSONObject json, String action) {
|
private void handleTreatmentFromNS(JSONObject json, String action) {
|
||||||
|
@ -459,11 +462,11 @@ public class NSClientPlugin extends PluginBase {
|
||||||
aapsLogger.error("Error parsing TT json " + json.toString());
|
aapsLogger.error("Error parsing TT json " + json.toString());
|
||||||
}
|
}
|
||||||
} else if (eventType.equals(CareportalEvent.TEMPBASAL)) {
|
} else if (eventType.equals(CareportalEvent.TEMPBASAL)) {
|
||||||
MainApp.getDbHelper().createTempBasalFromJsonIfNotExists(json);
|
databaseHelper.createTempBasalFromJsonIfNotExists(json);
|
||||||
} else if (eventType.equals(CareportalEvent.COMBOBOLUS)) {
|
} else if (eventType.equals(CareportalEvent.COMBOBOLUS)) {
|
||||||
MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(json);
|
databaseHelper.createExtendedBolusFromJsonIfNotExists(json);
|
||||||
} else if (eventType.equals(CareportalEvent.PROFILESWITCH)) {
|
} else if (eventType.equals(CareportalEvent.PROFILESWITCH)) {
|
||||||
MainApp.getDbHelper().createProfileSwitchFromJsonIfNotExists(activePlugin, nsUpload, json);
|
databaseHelper.createProfileSwitchFromJsonIfNotExists(activePlugin, nsUpload, json);
|
||||||
} else if (eventType.equals(CareportalEvent.SITECHANGE) ||
|
} else if (eventType.equals(CareportalEvent.SITECHANGE) ||
|
||||||
eventType.equals(CareportalEvent.INSULINCHANGE) ||
|
eventType.equals(CareportalEvent.INSULINCHANGE) ||
|
||||||
eventType.equals(CareportalEvent.SENSORCHANGE) ||
|
eventType.equals(CareportalEvent.SENSORCHANGE) ||
|
||||||
|
@ -475,7 +478,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
eventType.equals(CareportalEvent.EXERCISE) ||
|
eventType.equals(CareportalEvent.EXERCISE) ||
|
||||||
eventType.equals(CareportalEvent.OPENAPSOFFLINE) ||
|
eventType.equals(CareportalEvent.OPENAPSOFFLINE) ||
|
||||||
eventType.equals(CareportalEvent.PUMPBATTERYCHANGE)) {
|
eventType.equals(CareportalEvent.PUMPBATTERYCHANGE)) {
|
||||||
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(json);
|
databaseHelper.createCareportalEventFromJsonIfNotExists(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventType.equals(CareportalEvent.ANNOUNCEMENT)) {
|
if (eventType.equals(CareportalEvent.ANNOUNCEMENT)) {
|
||||||
|
@ -497,7 +500,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
private void storeMbg(JSONObject mbgJson) {
|
private void storeMbg(JSONObject mbgJson) {
|
||||||
NSMbg nsMbg = new NSMbg(mbgJson);
|
NSMbg nsMbg = new NSMbg(mbgJson);
|
||||||
CareportalEvent careportalEvent = new CareportalEvent(nsMbg);
|
CareportalEvent careportalEvent = new CareportalEvent(nsMbg);
|
||||||
MainApp.getDbHelper().createOrUpdate(careportalEvent);
|
databaseHelper.createOrUpdate(careportalEvent);
|
||||||
aapsLogger.debug(LTag.DATASERVICE, "Adding/Updating new MBG: " + careportalEvent.toString());
|
aapsLogger.debug(LTag.DATASERVICE, "Adding/Updating new MBG: " + careportalEvent.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
|
@ -36,6 +35,7 @@ import info.nightscout.androidaps.events.EventReloadProfileSwitchData;
|
||||||
import info.nightscout.androidaps.events.EventReloadTempBasalData;
|
import info.nightscout.androidaps.events.EventReloadTempBasalData;
|
||||||
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
import info.nightscout.androidaps.events.EventReloadTreatmentData;
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
@ -77,6 +77,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
private final UploadQueue uploadQueue;
|
private final UploadQueue uploadQueue;
|
||||||
private final FabricPrivacy fabricPrivacy;
|
private final FabricPrivacy fabricPrivacy;
|
||||||
private final DateUtil dateUtil;
|
private final DateUtil dateUtil;
|
||||||
|
private final DatabaseHelperInterface databaseHelper;
|
||||||
private final AppRepository repository;
|
private final AppRepository repository;
|
||||||
|
|
||||||
private final CompositeDisposable disposable = new CompositeDisposable();
|
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
@ -106,6 +107,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
FabricPrivacy fabricPrivacy,
|
FabricPrivacy fabricPrivacy,
|
||||||
DateUtil dateUtil,
|
DateUtil dateUtil,
|
||||||
UploadQueue uploadQueue,
|
UploadQueue uploadQueue,
|
||||||
|
DatabaseHelperInterface databaseHelper,
|
||||||
AppRepository repository
|
AppRepository repository
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
|
@ -130,6 +132,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
this.dateUtil = dateUtil;
|
this.dateUtil = dateUtil;
|
||||||
this.nsUpload = nsUpload;
|
this.nsUpload = nsUpload;
|
||||||
this.uploadQueue = uploadQueue;
|
this.uploadQueue = uploadQueue;
|
||||||
|
this.databaseHelper = databaseHelper;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +207,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
private void initializeTempBasalData(long range) {
|
private void initializeTempBasalData(long range) {
|
||||||
getAapsLogger().debug(LTag.DATATREATMENTS, "initializeTempBasalData");
|
getAapsLogger().debug(LTag.DATATREATMENTS, "initializeTempBasalData");
|
||||||
synchronized (tempBasals) {
|
synchronized (tempBasals) {
|
||||||
tempBasals.reset().add(MainApp.getDbHelper().getTemporaryBasalsDataFromTime(DateUtil.now() - range, false));
|
tempBasals.reset().add(databaseHelper.getTemporaryBasalsDataFromTime(DateUtil.now() - range, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -212,7 +215,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
private void initializeExtendedBolusData(long range) {
|
private void initializeExtendedBolusData(long range) {
|
||||||
getAapsLogger().debug(LTag.DATATREATMENTS, "initializeExtendedBolusData");
|
getAapsLogger().debug(LTag.DATATREATMENTS, "initializeExtendedBolusData");
|
||||||
synchronized (extendedBoluses) {
|
synchronized (extendedBoluses) {
|
||||||
extendedBoluses.reset().add(MainApp.getDbHelper().getExtendedBolusDataFromTime(DateUtil.now() - range, false));
|
extendedBoluses.reset().add(databaseHelper.getExtendedBolusDataFromTime(DateUtil.now() - range, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -220,7 +223,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
private void initializeProfileSwitchData(long range) {
|
private void initializeProfileSwitchData(long range) {
|
||||||
getAapsLogger().debug(LTag.DATATREATMENTS, "initializeProfileSwitchData");
|
getAapsLogger().debug(LTag.DATATREATMENTS, "initializeProfileSwitchData");
|
||||||
synchronized (profiles) {
|
synchronized (profiles) {
|
||||||
profiles.reset().add(MainApp.getDbHelper().getProfileSwitchData(DateUtil.now() - range, false));
|
profiles.reset().add(databaseHelper.getProfileSwitchData(DateUtil.now() - range, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +388,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
} else {
|
} else {
|
||||||
uploadQueue.removeID("dbAdd", tempBasalId);
|
uploadQueue.removeID("dbAdd", tempBasalId);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(tempBasal);
|
databaseHelper.delete(tempBasal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -560,7 +563,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
@Override
|
@Override
|
||||||
public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) {
|
public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) {
|
||||||
//log.debug("Adding new ExtentedBolus record" + extendedBolus.log());
|
//log.debug("Adding new ExtentedBolus record" + extendedBolus.log());
|
||||||
boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(extendedBolus);
|
boolean newRecordCreated = databaseHelper.createOrUpdate(extendedBolus);
|
||||||
if (newRecordCreated) {
|
if (newRecordCreated) {
|
||||||
if (extendedBolus.durationInMinutes == 0) {
|
if (extendedBolus.durationInMinutes == 0) {
|
||||||
if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses())
|
if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses())
|
||||||
|
@ -594,7 +597,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
@Override
|
@Override
|
||||||
public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) {
|
public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) {
|
||||||
//log.debug("Adding new TemporaryBasal record" + tempBasal.toString());
|
//log.debug("Adding new TemporaryBasal record" + tempBasal.toString());
|
||||||
boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(tempBasal);
|
boolean newRecordCreated = databaseHelper.createOrUpdate(tempBasal);
|
||||||
if (newRecordCreated) {
|
if (newRecordCreated) {
|
||||||
if (tempBasal.durationInMinutes == 0)
|
if (tempBasal.durationInMinutes == 0)
|
||||||
nsUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId);
|
nsUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId);
|
||||||
|
@ -714,7 +717,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) {
|
public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) {
|
||||||
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
|
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
|
||||||
rxBus.send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING));
|
rxBus.send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING));
|
||||||
MainApp.getDbHelper().createOrUpdate(profileSwitch);
|
databaseHelper.createOrUpdate(profileSwitch);
|
||||||
nsUpload.uploadProfileSwitch(profileSwitch, profileSwitch.date);
|
nsUpload.uploadProfileSwitch(profileSwitch, profileSwitch.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.db.TDD
|
import info.nightscout.androidaps.db.TDD
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
|
@ -40,8 +41,9 @@ class TddCalculator @Inject constructor(
|
||||||
nsUpload: NSUpload,
|
nsUpload: NSUpload,
|
||||||
private val dateUtil: DateUtil,
|
private val dateUtil: DateUtil,
|
||||||
uploadQueue: UploadQueue,
|
uploadQueue: UploadQueue,
|
||||||
|
databaseHelper: DatabaseHelperInterface,
|
||||||
repository: AppRepository
|
repository: AppRepository
|
||||||
) : TreatmentsPlugin(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue, repository) {
|
) : TreatmentsPlugin(injector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePlugin, nsUpload, fabricPrivacy, dateUtil, uploadQueue, databaseHelper, repository) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
service = TreatmentService(injector) // plugin is not started
|
service = TreatmentService(injector) // plugin is not started
|
||||||
|
|
|
@ -53,7 +53,7 @@ import java.util.*
|
||||||
MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class,
|
MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class,
|
||||||
OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class,
|
OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class,
|
||||||
VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class, Profiler::class,
|
VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class, Profiler::class,
|
||||||
UserEntryLogger::class, IobCobCalculatorPlugin::class, LoggerUtils::class)
|
UserEntryLogger::class, IobCobCalculatorPlugin::class, LoggerUtils::class, AppRepository::class)
|
||||||
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
|
|
|
@ -7,11 +7,7 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.Config
|
import info.nightscout.androidaps.Config
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.TestBase
|
import info.nightscout.androidaps.TestBase
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.*
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
@ -53,15 +49,16 @@ class LoopPluginTest : TestBase() {
|
||||||
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
|
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
|
||||||
@Mock lateinit var nsUpload: NSUpload
|
@Mock lateinit var nsUpload: NSUpload
|
||||||
@Mock lateinit var notificationManager: NotificationManager
|
@Mock lateinit var notificationManager: NotificationManager
|
||||||
|
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
||||||
private lateinit var hardLimits: HardLimits
|
private lateinit var hardLimits: HardLimits
|
||||||
|
|
||||||
lateinit var loopPlugin: LoopPlugin
|
private lateinit var loopPlugin: LoopPlugin
|
||||||
|
|
||||||
val injector = HasAndroidInjector { AndroidInjector { } }
|
val injector = HasAndroidInjector { AndroidInjector { } }
|
||||||
@Before fun prepareMock() {
|
@Before fun prepareMock() {
|
||||||
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
|
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context, nsUpload)
|
||||||
|
|
||||||
loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, hardLimits)
|
loopPlugin = LoopPlugin(injector, aapsLogger, aapsSchedulers, rxBus, sp, Config(), constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, nsUpload, databaseHelper, hardLimits)
|
||||||
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||||
`when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager)
|
`when`(context.getSystemService(Context.NOTIFICATION_SERVICE)).thenReturn(notificationManager)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import info.nightscout.androidaps.data.IobTotal
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult
|
import info.nightscout.androidaps.data.PumpEnactResult
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.database.entities.GlucoseValue
|
import info.nightscout.androidaps.database.entities.GlucoseValue
|
||||||
|
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
|
@ -39,6 +40,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.XdripCalibrations
|
import info.nightscout.androidaps.utils.XdripCalibrations
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import io.reactivex.Single
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
@ -116,6 +118,11 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
`when`(SmsManager.getDefault()).thenReturn(smsManager)
|
`when`(SmsManager.getDefault()).thenReturn(smsManager)
|
||||||
`when`(sp.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678")
|
`when`(sp.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678")
|
||||||
|
|
||||||
|
`when`(
|
||||||
|
repository.runTransactionForResult(anyObject<InsertTemporaryTargetAndCancelCurrentTransaction>())
|
||||||
|
).thenReturn(Single.just(InsertTemporaryTargetAndCancelCurrentTransaction.TransactionResult().apply {
|
||||||
|
}))
|
||||||
|
|
||||||
smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, resourceHelper, aapsSchedulers, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, loopPlugin, iobCobCalculatorPlugin, xdripCalibrations, otp, Config(), DateUtil(context), uel, nsUpload, repository)
|
smsCommunicatorPlugin = SmsCommunicatorPlugin(injector, aapsLogger, resourceHelper, aapsSchedulers, sp, constraintChecker, rxBus, profileFunction, fabricPrivacy, activePlugin, commandQueue, loopPlugin, iobCobCalculatorPlugin, xdripCalibrations, otp, Config(), DateUtil(context), uel, nsUpload, repository)
|
||||||
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true)
|
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true)
|
||||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||||
|
|
|
@ -3,11 +3,10 @@ package info.nightscout.androidaps.plugins.treatments
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
import info.nightscout.androidaps.database.AppRepository
|
import info.nightscout.androidaps.database.AppRepository
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper
|
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal
|
import info.nightscout.androidaps.db.TemporaryBasal
|
||||||
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue
|
||||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin
|
||||||
|
@ -27,16 +26,16 @@ import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(FabricPrivacy::class, MainApp::class, DatabaseHelper::class, AppRepository::class)
|
@PrepareForTest(FabricPrivacy::class, DatabaseHelperInterface::class, AppRepository::class)
|
||||||
class TreatmentsPluginTest : TestBaseWithProfile() {
|
class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var context: Context
|
@Mock lateinit var context: Context
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var databaseHelper: DatabaseHelper
|
|
||||||
@Mock lateinit var treatmentService: TreatmentService
|
@Mock lateinit var treatmentService: TreatmentService
|
||||||
@Mock lateinit var nsUpload: NSUpload
|
@Mock lateinit var nsUpload: NSUpload
|
||||||
@Mock lateinit var uploadQueue: UploadQueue
|
@Mock lateinit var uploadQueue: UploadQueue
|
||||||
@Mock lateinit var repository: AppRepository
|
@Mock lateinit var repository: AppRepository
|
||||||
|
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
val injector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -45,6 +44,7 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
it.activePlugin = activePluginProvider
|
it.activePlugin = activePluginProvider
|
||||||
it.profileFunction = profileFunction
|
it.profileFunction = profileFunction
|
||||||
it.sp = sp
|
it.sp = sp
|
||||||
|
it.dateUtil = DateUtil(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,14 +54,12 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
`when`(MainApp.getDbHelper()).thenReturn(databaseHelper)
|
|
||||||
|
|
||||||
insulinOrefRapidActingPlugin = InsulinOrefRapidActingPlugin(profileInjector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
insulinOrefRapidActingPlugin = InsulinOrefRapidActingPlugin(profileInjector, resourceHelper, profileFunction, rxBus, aapsLogger)
|
||||||
|
|
||||||
`when`(profileFunction.getProfile(ArgumentMatchers.anyLong())).thenReturn(validProfile)
|
`when`(profileFunction.getProfile(ArgumentMatchers.anyLong())).thenReturn(validProfile)
|
||||||
`when`(activePluginProvider.activeInsulin).thenReturn(insulinOrefRapidActingPlugin)
|
`when`(activePluginProvider.activeInsulin).thenReturn(insulinOrefRapidActingPlugin)
|
||||||
|
|
||||||
sot = TreatmentsPlugin(profileInjector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePluginProvider, nsUpload, fabricPrivacy, dateUtil, uploadQueue, repository)
|
sot = TreatmentsPlugin(profileInjector, aapsLogger, rxBus, aapsSchedulers, resourceHelper, context, sp, profileFunction, activePluginProvider, nsUpload, fabricPrivacy, dateUtil, uploadQueue, databaseHelper, repository)
|
||||||
sot.service = treatmentService
|
sot.service = treatmentService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import info.nightscout.androidaps.Constants
|
||||||
import info.nightscout.androidaps.automation.R
|
import info.nightscout.androidaps.automation.R
|
||||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||||
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
|
import info.nightscout.androidaps.database.transactions.InsertTemporaryTargetAndCancelCurrentTransaction
|
||||||
|
import info.nightscout.androidaps.database.transactions.Transaction
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputTempTarget
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
@ -13,6 +14,7 @@ import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.ArgumentMatcher
|
import org.mockito.ArgumentMatcher
|
||||||
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@ -44,9 +46,8 @@ class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
//`when`(activePlugin.activeTreatments).thenReturn(treatmentsInterface)
|
|
||||||
|
|
||||||
val expectedTarget = TemporaryTarget(
|
val expectedTarget = TemporaryTarget(
|
||||||
id = 0,
|
id = 0,
|
||||||
version = 0,
|
version = 0,
|
||||||
dateCreated = -1,
|
dateCreated = -1,
|
||||||
|
@ -85,7 +86,7 @@ class ActionStartTempTargetTest : ActionsTestBase() {
|
||||||
Assert.assertTrue(result.success)
|
Assert.assertTrue(result.success)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
//Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject())
|
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject<Transaction<InsertTemporaryTargetAndCancelCurrentTransaction.TransactionResult>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package info.nightscout.androidaps.plugins.general.automation.actions
|
package info.nightscout.androidaps.plugins.general.automation.actions
|
||||||
|
|
||||||
import info.nightscout.androidaps.automation.R
|
import info.nightscout.androidaps.automation.R
|
||||||
|
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||||
|
import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction
|
||||||
|
import info.nightscout.androidaps.database.transactions.Transaction
|
||||||
import info.nightscout.androidaps.queue.Callback
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import io.reactivex.Single
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@ -34,13 +39,26 @@ class ActionStopTempTargetTest : ActionsTestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun doActionTest() {
|
@Test fun doActionTest() {
|
||||||
//`when`(repository.activeTreatments).thenReturn(treatmentsInterface)
|
val inserted = mutableListOf<TemporaryTarget>().apply {
|
||||||
|
// insert all inserted TTs
|
||||||
|
}
|
||||||
|
val updated = mutableListOf<TemporaryTarget>().apply {
|
||||||
|
// add(TemporaryTarget(id = 0, version = 0, dateCreated = 0, isValid = false, referenceId = null, interfaceIDs_backing = null, timestamp = 0, utcOffset = 0, reason =, highTarget = 0.0, lowTarget = 0.0, duration = 0))
|
||||||
|
// insert all updated TTs
|
||||||
|
}
|
||||||
|
`when`(
|
||||||
|
repository.runTransactionForResult(anyObject<Transaction<CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult>>())
|
||||||
|
).thenReturn(Single.just(CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult().apply {
|
||||||
|
inserted.addAll(inserted)
|
||||||
|
updated.addAll(updated)
|
||||||
|
}))
|
||||||
|
|
||||||
sut.doAction(object : Callback() {
|
sut.doAction(object : Callback() {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
Assert.assertTrue(result.success)
|
Assert.assertTrue(result.success)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
//Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject())
|
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult((anyObject<Transaction<CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult>>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun hasDialogTest() {
|
@Test fun hasDialogTest() {
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class TemporaryBasal implements Interval, DbObjectBase {
|
||||||
@Inject public ProfileFunction profileFunction;
|
@Inject public ProfileFunction profileFunction;
|
||||||
@Inject public ActivePluginProvider activePlugin;
|
@Inject public ActivePluginProvider activePlugin;
|
||||||
@Inject public SP sp;
|
@Inject public SP sp;
|
||||||
@Inject DateUtil dateUtil;
|
@Inject public DateUtil dateUtil;
|
||||||
|
|
||||||
private HasAndroidInjector injector;
|
private HasAndroidInjector injector;
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,16 @@ package info.nightscout.androidaps.interfaces
|
||||||
|
|
||||||
import com.j256.ormlite.dao.CloseableIterator
|
import com.j256.ormlite.dao.CloseableIterator
|
||||||
import info.nightscout.androidaps.db.*
|
import info.nightscout.androidaps.db.*
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
interface DatabaseHelperInterface {
|
interface DatabaseHelperInterface {
|
||||||
|
|
||||||
|
fun resetDatabases()
|
||||||
|
|
||||||
fun createOrUpdate(careportalEvent: CareportalEvent)
|
fun createOrUpdate(careportalEvent: CareportalEvent)
|
||||||
|
fun createOrUpdate(extendedBolus: ExtendedBolus): Boolean
|
||||||
|
fun createOrUpdate(profileSwitch: ProfileSwitch)
|
||||||
fun createOrUpdate(record: DanaRHistoryRecord)
|
fun createOrUpdate(record: DanaRHistoryRecord)
|
||||||
fun createOrUpdate(record: OmnipodHistoryRecord)
|
fun createOrUpdate(record: OmnipodHistoryRecord)
|
||||||
fun createOrUpdate(record: InsightBolusID)
|
fun createOrUpdate(record: InsightBolusID)
|
||||||
|
@ -17,14 +23,16 @@ interface DatabaseHelperInterface {
|
||||||
fun size(table: String): Long
|
fun size(table: String): Long
|
||||||
fun deleteAllDbRequests()
|
fun deleteAllDbRequests()
|
||||||
fun deleteDbRequest(id: String): Int
|
fun deleteDbRequest(id: String): Int
|
||||||
|
fun delete(tempBasal: TemporaryBasal)
|
||||||
fun delete(extendedBolus: ExtendedBolus)
|
fun delete(extendedBolus: ExtendedBolus)
|
||||||
fun deleteDbRequestbyMongoId(action: String, _id: String)
|
fun deleteDbRequestbyMongoId(action: String, _id: String)
|
||||||
fun getDbRequestInterator(): CloseableIterator<DbRequest>
|
fun getDbRequestInterator(): CloseableIterator<DbRequest>
|
||||||
fun roundDateToSec(date: Long): Long
|
fun roundDateToSec(date: Long): Long
|
||||||
fun createOrUpdateTDD(record: TDD)
|
fun createOrUpdateTDD(record: TDD)
|
||||||
fun createOrUpdate(tempBasal: TemporaryBasal)
|
fun createOrUpdate(tempBasal: TemporaryBasal): Boolean
|
||||||
fun findTempBasalByPumpId(id: Long): TemporaryBasal
|
fun findTempBasalByPumpId(id: Long): TemporaryBasal
|
||||||
fun getTemporaryBasalsDataFromTime(mills: Long, ascending: Boolean): List<TemporaryBasal>
|
fun getTemporaryBasalsDataFromTime(mills: Long, ascending: Boolean): List<TemporaryBasal>
|
||||||
|
fun getExtendedBolusDataFromTime(mills: Long, ascending: Boolean): List<ExtendedBolus>
|
||||||
fun getCareportalEventFromTimestamp(timestamp: Long): CareportalEvent?
|
fun getCareportalEventFromTimestamp(timestamp: Long): CareportalEvent?
|
||||||
fun getAllOmnipodHistoryRecordsFromTimestamp(timestamp: Long, ascending: Boolean): List<OmnipodHistoryRecord>
|
fun getAllOmnipodHistoryRecordsFromTimestamp(timestamp: Long, ascending: Boolean): List<OmnipodHistoryRecord>
|
||||||
fun findOmnipodHistoryRecordByPumpId(pumpId: Long): OmnipodHistoryRecord?
|
fun findOmnipodHistoryRecordByPumpId(pumpId: Long): OmnipodHistoryRecord?
|
||||||
|
@ -32,6 +40,16 @@ interface DatabaseHelperInterface {
|
||||||
fun getProfileSwitchData(from: Long, ascending: Boolean): List<ProfileSwitch>
|
fun getProfileSwitchData(from: Long, ascending: Boolean): List<ProfileSwitch>
|
||||||
fun getExtendedBolusByPumpId(pumpId: Long): ExtendedBolus?
|
fun getExtendedBolusByPumpId(pumpId: Long): ExtendedBolus?
|
||||||
|
|
||||||
|
// old DB model
|
||||||
|
fun deleteTempBasalById(_id: String)
|
||||||
|
fun deleteExtendedBolusById(_id: String)
|
||||||
|
fun deleteCareportalEventById(_id: String)
|
||||||
|
fun deleteProfileSwitchById(_id: String)
|
||||||
|
fun createTempBasalFromJsonIfNotExists(json: JSONObject)
|
||||||
|
fun createExtendedBolusFromJsonIfNotExists(json: JSONObject)
|
||||||
|
fun createCareportalEventFromJsonIfNotExists(json: JSONObject)
|
||||||
|
fun createProfileSwitchFromJsonIfNotExists(activePluginProvider: ActivePluginProvider, nsUpload: NSUpload, trJson: JSONObject)
|
||||||
|
|
||||||
fun getInsightBolusID(pumpSerial: String, bolusID: Int, timestamp: Long): InsightBolusID?
|
fun getInsightBolusID(pumpSerial: String, bolusID: Int, timestamp: Long): InsightBolusID?
|
||||||
fun getInsightHistoryOffset(pumpSerial: String): InsightHistoryOffset?
|
fun getInsightHistoryOffset(pumpSerial: String): InsightHistoryOffset?
|
||||||
fun getPumpStoppedEvent(pumpSerial: String, before: Long): InsightPumpID?
|
fun getPumpStoppedEvent(pumpSerial: String, before: Long): InsightPumpID?
|
||||||
|
|
Loading…
Reference in a new issue