FabricPrivacy & GraphData dagger
This commit is contained in:
parent
69b177ed06
commit
1a485f9e11
|
@ -86,6 +86,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
@Inject NSSettingsStatus nsSettingsStatus;
|
@Inject NSSettingsStatus nsSettingsStatus;
|
||||||
@Inject BuildHelper buildHelper;
|
@Inject BuildHelper buildHelper;
|
||||||
@Inject ActivePluginProvider activePlugin;
|
@Inject ActivePluginProvider activePlugin;
|
||||||
|
@Inject FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -130,7 +131,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
if (!loopPlugin.isEnabled(PluginType.LOOP))
|
if (!loopPlugin.isEnabled(PluginType.LOOP))
|
||||||
versionCheckerUtils.triggerCheckVersion();
|
versionCheckerUtils.triggerCheckVersion();
|
||||||
|
|
||||||
FabricPrivacy.getInstance().setUserStats();
|
fabricPrivacy.setUserStats();
|
||||||
|
|
||||||
setupTabs();
|
setupTabs();
|
||||||
setupViews();
|
setupViews();
|
||||||
|
@ -147,12 +148,12 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
setupViews();
|
setupViews();
|
||||||
}
|
}
|
||||||
setWakeLock();
|
setWakeLock();
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, exception -> fabricPrivacy.logException(exception))
|
||||||
);
|
);
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventPreferenceChange.class)
|
.toObservable(EventPreferenceChange.class)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::processPreferenceChange, exception -> FabricPrivacy.getInstance().logException(exception))
|
.subscribe(this::processPreferenceChange, exception -> fabricPrivacy.logException(exception))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) {
|
if (!sp.getBoolean(R.string.key_setupwizard_processed, false) && !isRunningRealPumpTest()) {
|
||||||
|
|
|
@ -17,9 +17,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
@ -39,7 +36,7 @@ import info.nightscout.androidaps.db.TDD;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
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.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||||
|
@ -58,6 +55,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class TDDStatsActivity extends NoSplashAppCompatActivity {
|
public class TDDStatsActivity extends NoSplashAppCompatActivity {
|
||||||
|
@Inject AAPSLogger aapsLogger;
|
||||||
@Inject ResourceHelper resourceHelper;
|
@Inject ResourceHelper resourceHelper;
|
||||||
@Inject RxBusWrapper rxBus;
|
@Inject RxBusWrapper rxBus;
|
||||||
@Inject SP sp;
|
@Inject SP sp;
|
||||||
|
@ -70,8 +68,8 @@ public class TDDStatsActivity extends NoSplashAppCompatActivity {
|
||||||
@Inject LocalInsightPlugin localInsightPlugin;
|
@Inject LocalInsightPlugin localInsightPlugin;
|
||||||
@Inject ConfigBuilderPlugin configBuilderPlugin;
|
@Inject ConfigBuilderPlugin configBuilderPlugin;
|
||||||
@Inject CommandQueueProvider commandQueue;
|
@Inject CommandQueueProvider commandQueue;
|
||||||
|
@Inject FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
private static Logger log = StacktraceLoggerWrapper.getLogger(TDDStatsActivity.class);
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
TextView statusView, statsMessage, totalBaseBasal2;
|
TextView statusView, statsMessage, totalBaseBasal2;
|
||||||
|
@ -96,15 +94,15 @@ public class TDDStatsActivity extends NoSplashAppCompatActivity {
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventPumpStatusChanged.class)
|
.toObservable(EventPumpStatusChanged.class)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(event -> statusView.setText(event.getStatus(resourceHelper)), exception -> FabricPrivacy.getInstance().logException(exception))
|
.subscribe(event -> statusView.setText(event.getStatus(resourceHelper)), exception -> fabricPrivacy.logException(exception))
|
||||||
);
|
);
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventDanaRSyncStatus.class)
|
.toObservable(EventDanaRSyncStatus.class)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
log.debug("EventDanaRSyncStatus: " + event.getMessage());
|
aapsLogger.debug("EventDanaRSyncStatus: " + event.getMessage());
|
||||||
statusView.setText(event.getMessage());
|
statusView.setText(event.getMessage());
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, exception -> fabricPrivacy.logException(exception))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.general.automation.AutomationEvent
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.*
|
import info.nightscout.androidaps.plugins.general.automation.actions.*
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.*
|
import info.nightscout.androidaps.plugins.general.automation.elements.*
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.*
|
import info.nightscout.androidaps.plugins.general.automation.triggers.*
|
||||||
|
import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
|
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
||||||
|
@ -175,6 +176,8 @@ interface AppComponent : AndroidInjector<MainApp> {
|
||||||
fun injectProfile(profile: Profile)
|
fun injectProfile(profile: Profile)
|
||||||
fun injectGlucoseStatus(glucoseStatus: GlucoseStatus)
|
fun injectGlucoseStatus(glucoseStatus: GlucoseStatus)
|
||||||
|
|
||||||
|
fun injectGraphData(graphData: GraphData)
|
||||||
|
|
||||||
@Component.Builder
|
@Component.Builder
|
||||||
interface Builder {
|
interface Builder {
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.general.automation.AutomationEvent
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.*
|
import info.nightscout.androidaps.plugins.general.automation.actions.*
|
||||||
import info.nightscout.androidaps.plugins.general.automation.elements.*
|
import info.nightscout.androidaps.plugins.general.automation.elements.*
|
||||||
import info.nightscout.androidaps.plugins.general.automation.triggers.*
|
import info.nightscout.androidaps.plugins.general.automation.triggers.*
|
||||||
|
import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
|
import info.nightscout.androidaps.plugins.general.overview.notifications.NotificationWithAction
|
||||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest
|
import info.nightscout.androidaps.plugins.general.smsCommunicator.AuthRequest
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData
|
||||||
|
@ -45,6 +46,7 @@ import info.nightscout.androidaps.setupwizard.SWDefinition
|
||||||
import info.nightscout.androidaps.setupwizard.SWEventListener
|
import info.nightscout.androidaps.setupwizard.SWEventListener
|
||||||
import info.nightscout.androidaps.setupwizard.SWScreen
|
import info.nightscout.androidaps.setupwizard.SWScreen
|
||||||
import info.nightscout.androidaps.setupwizard.elements.*
|
import info.nightscout.androidaps.setupwizard.elements.*
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation
|
import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
@ -64,8 +66,8 @@ open class AppModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
fun provideProfileFunction(injector: HasAndroidInjector, aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider): ProfileFunction {
|
fun provideProfileFunction(injector: HasAndroidInjector, aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePluginProvider, fabricPrivacy: FabricPrivacy): ProfileFunction {
|
||||||
return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin)
|
return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin, fabricPrivacy)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -230,6 +232,8 @@ open class AppModule {
|
||||||
@ContributesAndroidInjector fun profileInjector(): Profile
|
@ContributesAndroidInjector fun profileInjector(): Profile
|
||||||
@ContributesAndroidInjector fun glucoseStatusInjector(): GlucoseStatus
|
@ContributesAndroidInjector fun glucoseStatusInjector(): GlucoseStatus
|
||||||
|
|
||||||
|
@ContributesAndroidInjector fun graphDataInjector(): GraphData
|
||||||
|
|
||||||
@Binds fun bindContext(mainApp: MainApp): Context
|
@Binds fun bindContext(mainApp: MainApp): Context
|
||||||
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
@Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Date;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
@ -48,6 +49,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||||
|
@Inject HasAndroidInjector injector;
|
||||||
@Inject AAPSLogger aapsLogger;
|
@Inject AAPSLogger aapsLogger;
|
||||||
@Inject RxBusWrapper rxBus;
|
@Inject RxBusWrapper rxBus;
|
||||||
@Inject SP sp;
|
@Inject SP sp;
|
||||||
|
@ -57,6 +59,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||||
@Inject IobCobStaticCalculatorPlugin iobCobStaticCalculatorPlugin;
|
@Inject IobCobStaticCalculatorPlugin iobCobStaticCalculatorPlugin;
|
||||||
@Inject ActivePluginProvider activePlugin;
|
@Inject ActivePluginProvider activePlugin;
|
||||||
@Inject BuildHelper buildHelper;
|
@Inject BuildHelper buildHelper;
|
||||||
|
@Inject FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
|
@ -191,7 +194,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||||
updateGUI("EventAutosensCalculationFinished");
|
updateGUI("EventAutosensCalculationFinished");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, exception -> fabricPrivacy.logException(exception))
|
||||||
);
|
);
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventIobCalculationProgress.class)
|
.toObservable(EventIobCalculationProgress.class)
|
||||||
|
@ -199,7 +202,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
if (iobCalculationProgressView != null)
|
if (iobCalculationProgressView != null)
|
||||||
iobCalculationProgressView.setText(event.getProgress());
|
iobCalculationProgressView.setText(event.getProgress());
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, exception -> fabricPrivacy.logException(exception))
|
||||||
);
|
);
|
||||||
// set start of current day
|
// set start of current day
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
@ -276,7 +279,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
// ------------------ 1st graph
|
// ------------------ 1st graph
|
||||||
|
|
||||||
final GraphData graphData = new GraphData(bgGraph, iobCobStaticCalculatorPlugin);
|
final GraphData graphData = new GraphData(injector, bgGraph, iobCobStaticCalculatorPlugin);
|
||||||
|
|
||||||
// **** In range Area ****
|
// **** In range Area ****
|
||||||
graphData.addInRangeArea(fromTime, toTime, lowLine, highLine);
|
graphData.addInRangeArea(fromTime, toTime, lowLine, highLine);
|
||||||
|
@ -309,7 +312,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||||
// ------------------ 2nd graph
|
// ------------------ 2nd graph
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
final GraphData secondGraphData = new GraphData(iobGraph, iobCobStaticCalculatorPlugin);
|
final GraphData secondGraphData = new GraphData(injector, iobGraph, iobCobStaticCalculatorPlugin);
|
||||||
|
|
||||||
boolean useIobForScale = false;
|
boolean useIobForScale = false;
|
||||||
boolean useCobForScale = false;
|
boolean useCobForScale = false;
|
||||||
|
|
|
@ -26,7 +26,8 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
private val aapsLogger: AAPSLogger,
|
private val aapsLogger: AAPSLogger,
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val resourceHelper: ResourceHelper,
|
private val resourceHelper: ResourceHelper,
|
||||||
private val activePlugin: ActivePluginProvider
|
private val activePlugin: ActivePluginProvider,
|
||||||
|
private val fabricPrivacy: FabricPrivacy
|
||||||
) : ProfileFunction {
|
) : ProfileFunction {
|
||||||
|
|
||||||
override fun getProfileName(): String =
|
override fun getProfileName(): String =
|
||||||
|
@ -54,10 +55,10 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showRemainingTime && profileSwitch.durationInMinutes != 0) {
|
if (showRemainingTime && profileSwitch.durationInMinutes != 0) {
|
||||||
profileName += DateUtil.untilString(profileSwitch.originalEnd(), resourceHelper);
|
profileName += DateUtil.untilString(profileSwitch.originalEnd(), resourceHelper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return profileName;
|
return profileName
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getProfileNameWithDuration(): String =
|
override fun getProfileNameWithDuration(): String =
|
||||||
|
@ -89,7 +90,7 @@ class ProfileFunctionImplementation @Inject constructor(
|
||||||
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, BuildConfig.BUILDVERSION)
|
bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, BuildConfig.BUILDVERSION)
|
||||||
bundle.putString(FirebaseAnalytics.Param.START_DATE, time.toString())
|
bundle.putString(FirebaseAnalytics.Param.START_DATE, time.toString())
|
||||||
bundle.putString(FirebaseAnalytics.Param.VALUE, activeTreatments.profileSwitchesFromHistory.toString())
|
bundle.putString(FirebaseAnalytics.Param.VALUE, activeTreatments.profileSwitchesFromHistory.toString())
|
||||||
FabricPrivacy.getInstance().logCustom(bundle)
|
fabricPrivacy.logCustom(bundle)
|
||||||
}
|
}
|
||||||
aapsLogger.error("getProfile at the end: returning null")
|
aapsLogger.error("getProfile at the end: returning null")
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
textLog = Html.fromHtml(newTextLog.toString());
|
textLog = Html.fromHtml(newTextLog.toString());
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
ToastUtils.showToastInUiThread(context, "Out of memory!\nStop using this phone !!!", R.raw.error);
|
ToastUtils.showToastInUiThread(context, rxBus, "Out of memory!\nStop using this phone !!!", R.raw.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1428,7 +1428,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
||||||
// ------------------ 1st graph
|
// ------------------ 1st graph
|
||||||
Profiler.log(aapsLogger, LTag.OVERVIEW, from + " - 1st graph - START", updateGUIStart);
|
Profiler.log(aapsLogger, LTag.OVERVIEW, from + " - 1st graph - START", updateGUIStart);
|
||||||
|
|
||||||
final GraphData graphData = new GraphData(bgGraph, iobCobCalculatorPlugin);
|
final GraphData graphData = new GraphData(injector, bgGraph, iobCobCalculatorPlugin);
|
||||||
|
|
||||||
// **** In range Area ****
|
// **** In range Area ****
|
||||||
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
||||||
|
@ -1464,7 +1464,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
||||||
// ------------------ 2nd graph
|
// ------------------ 2nd graph
|
||||||
Profiler.log(aapsLogger, LTag.OVERVIEW, from + " - 2nd graph - START", updateGUIStart);
|
Profiler.log(aapsLogger, LTag.OVERVIEW, from + " - 2nd graph - START", updateGUIStart);
|
||||||
|
|
||||||
final GraphData secondGraphData = new GraphData(iobGraph, iobCobCalculatorPlugin);
|
final GraphData secondGraphData = new GraphData(injector, iobGraph, iobCobCalculatorPlugin);
|
||||||
|
|
||||||
boolean useIobForScale = false;
|
boolean useIobForScale = false;
|
||||||
boolean useCobForScale = false;
|
boolean useCobForScale = false;
|
||||||
|
|
|
@ -5,18 +5,18 @@ import android.graphics.DashPathEffect;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.jjoe64.graphview.ValueDependentColor;
|
|
||||||
import com.jjoe64.graphview.series.BarGraphSeries;
|
import com.jjoe64.graphview.series.BarGraphSeries;
|
||||||
import com.jjoe64.graphview.series.DataPoint;
|
import com.jjoe64.graphview.series.DataPoint;
|
||||||
import com.jjoe64.graphview.series.LineGraphSeries;
|
import com.jjoe64.graphview.series.LineGraphSeries;
|
||||||
import com.jjoe64.graphview.series.Series;
|
import com.jjoe64.graphview.series.Series;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
@ -27,13 +27,14 @@ import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.PluginStore;
|
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.AreaGraphSeries;
|
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.AreaGraphSeries;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
|
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint;
|
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DoubleDataPoint;
|
||||||
|
@ -47,30 +48,38 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.BasalData;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.BasalData;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.Round;
|
import info.nightscout.androidaps.utils.Round;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 18.10.2017.
|
* Created by mike on 18.10.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class GraphData {
|
public class GraphData {
|
||||||
private static Logger log = StacktraceLoggerWrapper.getLogger(L.OVERVIEW);
|
|
||||||
|
@Inject AAPSLogger aapsLogger;
|
||||||
|
@Inject ProfileFunction profileFunction;
|
||||||
|
@Inject ResourceHelper resourceHelper;
|
||||||
|
@Inject ActivePluginProvider activePlugin;
|
||||||
|
|
||||||
private GraphView graph;
|
private GraphView graph;
|
||||||
public double maxY = Double.MIN_VALUE;
|
public double maxY = Double.MIN_VALUE;
|
||||||
public double minY = Double.MAX_VALUE;
|
private double minY = Double.MAX_VALUE;
|
||||||
private List<BgReading> bgReadingsArray;
|
private List<BgReading> bgReadingsArray;
|
||||||
private String units;
|
private String units;
|
||||||
private List<Series> series = new ArrayList<>();
|
private List<Series> series = new ArrayList<>();
|
||||||
|
private TreatmentsInterface treatmentsPlugin;
|
||||||
|
|
||||||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
|
||||||
|
|
||||||
public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) {
|
private IobCobCalculatorPlugin iobCobCalculatorPlugin; // Cannot be injected: HistoryBrowser
|
||||||
units = ConfigBuilderPlugin.getPlugin().getProfileFunction().getUnits();
|
|
||||||
|
public GraphData(HasAndroidInjector injector, GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) {
|
||||||
|
injector.androidInjector().inject(this);
|
||||||
|
units = profileFunction.getUnits();
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
||||||
|
treatmentsPlugin = activePlugin.getActiveTreatments();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, List<BgReading> predictions) {
|
public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, List<BgReading> predictions) {
|
||||||
|
@ -80,8 +89,7 @@ public class GraphData {
|
||||||
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
||||||
|
|
||||||
if (bgReadingsArray == null || bgReadingsArray.size() == 0) {
|
if (bgReadingsArray == null || bgReadingsArray.size() == 0) {
|
||||||
if (L.isEnabled(L.OVERVIEW))
|
aapsLogger.debug(LTag.OVERVIEW, "No BG data.");
|
||||||
log.debug("No BG data.");
|
|
||||||
maxY = 10;
|
maxY = 10;
|
||||||
minY = 0;
|
minY = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -127,7 +135,7 @@ public class GraphData {
|
||||||
inRangeAreaSeries = new AreaGraphSeries<>(inRangeAreaDataPoints);
|
inRangeAreaSeries = new AreaGraphSeries<>(inRangeAreaDataPoints);
|
||||||
inRangeAreaSeries.setColor(0);
|
inRangeAreaSeries.setColor(0);
|
||||||
inRangeAreaSeries.setDrawBackground(true);
|
inRangeAreaSeries.setDrawBackground(true);
|
||||||
inRangeAreaSeries.setBackgroundColor(MainApp.gc(R.color.inrangebackground));
|
inRangeAreaSeries.setBackgroundColor(resourceHelper.gc(R.color.inrangebackground));
|
||||||
|
|
||||||
addSeries(inRangeAreaSeries);
|
addSeries(inRangeAreaSeries);
|
||||||
}
|
}
|
||||||
|
@ -151,7 +159,7 @@ public class GraphData {
|
||||||
double lastBaseBasal = 0;
|
double lastBaseBasal = 0;
|
||||||
double lastTempBasal = 0;
|
double lastTempBasal = 0;
|
||||||
for (long time = fromTime; time < toTime; time += 60 * 1000L) {
|
for (long time = fromTime; time < toTime; time += 60 * 1000L) {
|
||||||
Profile profile = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfile(time);
|
Profile profile = profileFunction.getProfile(time);
|
||||||
if (profile == null) continue;
|
if (profile == null) continue;
|
||||||
BasalData basalData = iobCobCalculatorPlugin.getBasalData(profile, time);
|
BasalData basalData = iobCobCalculatorPlugin.getBasalData(profile, time);
|
||||||
double baseBasalValue = basalData.basal;
|
double baseBasalValue = basalData.basal;
|
||||||
|
@ -205,14 +213,14 @@ public class GraphData {
|
||||||
baseBasal = baseBasalArray.toArray(baseBasal);
|
baseBasal = baseBasalArray.toArray(baseBasal);
|
||||||
baseBasalsSeries = new LineGraphSeries<>(baseBasal);
|
baseBasalsSeries = new LineGraphSeries<>(baseBasal);
|
||||||
baseBasalsSeries.setDrawBackground(true);
|
baseBasalsSeries.setDrawBackground(true);
|
||||||
baseBasalsSeries.setBackgroundColor(MainApp.gc(R.color.basebasal));
|
baseBasalsSeries.setBackgroundColor(resourceHelper.gc(R.color.basebasal));
|
||||||
baseBasalsSeries.setThickness(0);
|
baseBasalsSeries.setThickness(0);
|
||||||
|
|
||||||
ScaledDataPoint[] tempBasal = new ScaledDataPoint[tempBasalArray.size()];
|
ScaledDataPoint[] tempBasal = new ScaledDataPoint[tempBasalArray.size()];
|
||||||
tempBasal = tempBasalArray.toArray(tempBasal);
|
tempBasal = tempBasalArray.toArray(tempBasal);
|
||||||
tempBasalsSeries = new LineGraphSeries<>(tempBasal);
|
tempBasalsSeries = new LineGraphSeries<>(tempBasal);
|
||||||
tempBasalsSeries.setDrawBackground(true);
|
tempBasalsSeries.setDrawBackground(true);
|
||||||
tempBasalsSeries.setBackgroundColor(MainApp.gc(R.color.tempbasal));
|
tempBasalsSeries.setBackgroundColor(resourceHelper.gc(R.color.tempbasal));
|
||||||
tempBasalsSeries.setThickness(0);
|
tempBasalsSeries.setThickness(0);
|
||||||
|
|
||||||
ScaledDataPoint[] basalLine = new ScaledDataPoint[basalLineArray.size()];
|
ScaledDataPoint[] basalLine = new ScaledDataPoint[basalLineArray.size()];
|
||||||
|
@ -220,9 +228,9 @@ public class GraphData {
|
||||||
basalsLineSeries = new LineGraphSeries<>(basalLine);
|
basalsLineSeries = new LineGraphSeries<>(basalLine);
|
||||||
Paint paint = new Paint();
|
Paint paint = new Paint();
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
paint.setStrokeWidth(MainApp.instance().getApplicationContext().getResources().getDisplayMetrics().scaledDensity * 2);
|
paint.setStrokeWidth(resourceHelper.getDisplayMetrics().scaledDensity * 2);
|
||||||
paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0));
|
paint.setPathEffect(new DashPathEffect(new float[]{2, 4}, 0));
|
||||||
paint.setColor(MainApp.gc(R.color.basal));
|
paint.setColor(resourceHelper.gc(R.color.basal));
|
||||||
basalsLineSeries.setCustomPaint(paint);
|
basalsLineSeries.setCustomPaint(paint);
|
||||||
|
|
||||||
ScaledDataPoint[] absoluteBasalLine = new ScaledDataPoint[absoluteBasalLineArray.size()];
|
ScaledDataPoint[] absoluteBasalLine = new ScaledDataPoint[absoluteBasalLineArray.size()];
|
||||||
|
@ -230,8 +238,8 @@ public class GraphData {
|
||||||
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
|
absoluteBasalsLineSeries = new LineGraphSeries<>(absoluteBasalLine);
|
||||||
Paint absolutePaint = new Paint();
|
Paint absolutePaint = new Paint();
|
||||||
absolutePaint.setStyle(Paint.Style.STROKE);
|
absolutePaint.setStyle(Paint.Style.STROKE);
|
||||||
absolutePaint.setStrokeWidth(MainApp.instance().getApplicationContext().getResources().getDisplayMetrics().scaledDensity * 2);
|
absolutePaint.setStrokeWidth(resourceHelper.getDisplayMetrics().scaledDensity * 2);
|
||||||
absolutePaint.setColor(MainApp.gc(R.color.basal));
|
absolutePaint.setColor(resourceHelper.gc(R.color.basal));
|
||||||
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
|
absoluteBasalsLineSeries.setCustomPaint(absolutePaint);
|
||||||
|
|
||||||
basalScale.setMultiplier(maxY * scale / maxBasalValueFound);
|
basalScale.setMultiplier(maxY * scale / maxBasalValueFound);
|
||||||
|
@ -260,12 +268,12 @@ public class GraphData {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (long time = fromTime; time < toTime; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time < toTime; time += 5 * 60 * 1000L) {
|
||||||
TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time);
|
TempTarget tt = treatmentsPlugin.getTempTargetFromHistory(time);
|
||||||
double value;
|
double value;
|
||||||
if (tt == null) {
|
if (tt == null) {
|
||||||
value = Profile.fromMgdlToUnits((profile.getTargetLowMgdl(time) + profile.getTargetHighMgdl(time)) / 2, ConfigBuilderPlugin.getPlugin().getProfileFunction().getUnits());
|
value = Profile.fromMgdlToUnits((profile.getTargetLowMgdl(time) + profile.getTargetHighMgdl(time)) / 2, profileFunction.getUnits());
|
||||||
} else {
|
} else {
|
||||||
value = Profile.fromMgdlToUnits(tt.target(), ConfigBuilderPlugin.getPlugin().getProfileFunction().getUnits());
|
value = Profile.fromMgdlToUnits(tt.target(), profileFunction.getUnits());
|
||||||
}
|
}
|
||||||
if (lastTarget != value) {
|
if (lastTarget != value) {
|
||||||
if (lastTarget != -1)
|
if (lastTarget != -1)
|
||||||
|
@ -280,7 +288,7 @@ public class GraphData {
|
||||||
targets = targetsSeriesArray.toArray(targets);
|
targets = targetsSeriesArray.toArray(targets);
|
||||||
targetsSeries = new LineGraphSeries<>(targets);
|
targetsSeries = new LineGraphSeries<>(targets);
|
||||||
targetsSeries.setDrawBackground(false);
|
targetsSeries.setDrawBackground(false);
|
||||||
targetsSeries.setColor(MainApp.gc(R.color.tempTargetBackground));
|
targetsSeries.setColor(resourceHelper.gc(R.color.tempTargetBackground));
|
||||||
targetsSeries.setThickness(2);
|
targetsSeries.setThickness(2);
|
||||||
|
|
||||||
addSeries(targetsSeries);
|
addSeries(targetsSeries);
|
||||||
|
@ -289,7 +297,7 @@ public class GraphData {
|
||||||
public void addTreatments(long fromTime, long endTime) {
|
public void addTreatments(long fromTime, long endTime) {
|
||||||
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
List<DataPointWithLabelInterface> filteredTreatments = new ArrayList<>();
|
||||||
|
|
||||||
List<Treatment> treatments = TreatmentsPlugin.getPlugin().getTreatmentsFromHistory();
|
List<Treatment> treatments = treatmentsPlugin.getTreatmentsFromHistory();
|
||||||
|
|
||||||
for (int tx = 0; tx < treatments.size(); tx++) {
|
for (int tx = 0; tx < treatments.size(); tx++) {
|
||||||
Treatment t = treatments.get(tx);
|
Treatment t = treatments.get(tx);
|
||||||
|
@ -300,7 +308,7 @@ public class GraphData {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProfileSwitch
|
// ProfileSwitch
|
||||||
List<ProfileSwitch> profileSwitches = TreatmentsPlugin.getPlugin().getProfileSwitchesFromHistory().getList();
|
List<ProfileSwitch> profileSwitches = treatmentsPlugin.getProfileSwitchesFromHistory().getList();
|
||||||
|
|
||||||
for (int tx = 0; tx < profileSwitches.size(); tx++) {
|
for (int tx = 0; tx < profileSwitches.size(); tx++) {
|
||||||
DataPointWithLabelInterface t = profileSwitches.get(tx);
|
DataPointWithLabelInterface t = profileSwitches.get(tx);
|
||||||
|
@ -309,8 +317,8 @@ public class GraphData {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extended bolus
|
// Extended bolus
|
||||||
if (!PluginStore.Companion.getInstance().getActivePump().isFakingTempsByExtendedBoluses()) {
|
if (!activePlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
|
||||||
List<ExtendedBolus> extendedBoluses = TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory().getList();
|
List<ExtendedBolus> extendedBoluses = treatmentsPlugin.getExtendedBolusesFromHistory().getList();
|
||||||
|
|
||||||
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
for (int tx = 0; tx < extendedBoluses.size(); tx++) {
|
||||||
DataPointWithLabelInterface t = extendedBoluses.get(tx);
|
DataPointWithLabelInterface t = extendedBoluses.get(tx);
|
||||||
|
@ -360,8 +368,8 @@ public class GraphData {
|
||||||
double maxIAValue = 0;
|
double maxIAValue = 0;
|
||||||
|
|
||||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
Profile profile = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfile(time);
|
Profile profile = profileFunction.getProfile(time);
|
||||||
double act = 0d;
|
double act;
|
||||||
if (profile == null) continue;
|
if (profile == null) continue;
|
||||||
total = iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time, profile);
|
total = iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time, profile);
|
||||||
act = total.activity;
|
act = total.activity;
|
||||||
|
@ -378,7 +386,7 @@ public class GraphData {
|
||||||
actData = actArrayHist.toArray(actData);
|
actData = actArrayHist.toArray(actData);
|
||||||
actSeriesHist = new FixedLineGraphSeries<>(actData);
|
actSeriesHist = new FixedLineGraphSeries<>(actData);
|
||||||
actSeriesHist.setDrawBackground(false);
|
actSeriesHist.setDrawBackground(false);
|
||||||
actSeriesHist.setColor(MainApp.gc(R.color.activity));
|
actSeriesHist.setColor(resourceHelper.gc(R.color.activity));
|
||||||
actSeriesHist.setThickness(3);
|
actSeriesHist.setThickness(3);
|
||||||
|
|
||||||
addSeries(actSeriesHist);
|
addSeries(actSeriesHist);
|
||||||
|
@ -391,7 +399,7 @@ public class GraphData {
|
||||||
paint.setStyle(Paint.Style.STROKE);
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
paint.setStrokeWidth(3);
|
paint.setStrokeWidth(3);
|
||||||
paint.setPathEffect(new DashPathEffect(new float[]{4, 4}, 0));
|
paint.setPathEffect(new DashPathEffect(new float[]{4, 4}, 0));
|
||||||
paint.setColor(MainApp.gc(R.color.activity));
|
paint.setColor(resourceHelper.gc(R.color.activity));
|
||||||
actSeriesPred.setCustomPaint(paint);
|
actSeriesPred.setCustomPaint(paint);
|
||||||
|
|
||||||
if (useForScale) {
|
if (useForScale) {
|
||||||
|
@ -412,7 +420,7 @@ public class GraphData {
|
||||||
Scale iobScale = new Scale();
|
Scale iobScale = new Scale();
|
||||||
|
|
||||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
Profile profile = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfile(time);
|
Profile profile = profileFunction.getProfile(time);
|
||||||
double iob = 0d;
|
double iob = 0d;
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
iob = iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time, profile).iob;
|
iob = iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time, profile).iob;
|
||||||
|
@ -429,23 +437,23 @@ public class GraphData {
|
||||||
iobData = iobArray.toArray(iobData);
|
iobData = iobArray.toArray(iobData);
|
||||||
iobSeries = new FixedLineGraphSeries<>(iobData);
|
iobSeries = new FixedLineGraphSeries<>(iobData);
|
||||||
iobSeries.setDrawBackground(true);
|
iobSeries.setDrawBackground(true);
|
||||||
iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.gc(R.color.iob)); //50%
|
iobSeries.setBackgroundColor(0x80FFFFFF & resourceHelper.gc(R.color.iob)); //50%
|
||||||
iobSeries.setColor(MainApp.gc(R.color.iob));
|
iobSeries.setColor(resourceHelper.gc(R.color.iob));
|
||||||
iobSeries.setThickness(3);
|
iobSeries.setThickness(3);
|
||||||
|
|
||||||
if (showPrediction) {
|
if (showPrediction) {
|
||||||
AutosensResult lastAutosensResult;
|
AutosensResult lastAutosensResult;
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("GraphData");
|
AutosensData autosensData = iobCobCalculatorPlugin.getLastAutosensDataSynchronized("GraphData");
|
||||||
if (autosensData == null)
|
if (autosensData == null)
|
||||||
lastAutosensResult = new AutosensResult();
|
lastAutosensResult = new AutosensResult();
|
||||||
else
|
else
|
||||||
lastAutosensResult = autosensData.autosensResult;
|
lastAutosensResult = autosensData.autosensResult;
|
||||||
boolean isTempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis()) != null;
|
boolean isTempTarget = treatmentsPlugin.getTempTargetFromHistory(System.currentTimeMillis()) != null;
|
||||||
|
|
||||||
List<DataPointWithLabelInterface> iobPred = new ArrayList<>();
|
List<DataPointWithLabelInterface> iobPred = new ArrayList<>();
|
||||||
IobTotal[] iobPredArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
IobTotal[] iobPredArray = iobCobCalculatorPlugin.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
||||||
for (IobTotal i : iobPredArray) {
|
for (IobTotal i : iobPredArray) {
|
||||||
iobPred.add(i.setColor(MainApp.gc(R.color.iobPredAS)));
|
iobPred.add(i.setColor(resourceHelper.gc(R.color.iobPredAS)));
|
||||||
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(i.iob));
|
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(i.iob));
|
||||||
}
|
}
|
||||||
DataPointWithLabelInterface[] iobp = new DataPointWithLabelInterface[iobPred.size()];
|
DataPointWithLabelInterface[] iobp = new DataPointWithLabelInterface[iobPred.size()];
|
||||||
|
@ -454,19 +462,17 @@ public class GraphData {
|
||||||
|
|
||||||
|
|
||||||
List<DataPointWithLabelInterface> iobPred2 = new ArrayList<>();
|
List<DataPointWithLabelInterface> iobPred2 = new ArrayList<>();
|
||||||
IobTotal[] iobPredArray2 = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(new AutosensResult(), SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
IobTotal[] iobPredArray2 = iobCobCalculatorPlugin.calculateIobArrayForSMB(new AutosensResult(), SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
||||||
for (IobTotal i : iobPredArray2) {
|
for (IobTotal i : iobPredArray2) {
|
||||||
iobPred2.add(i.setColor(MainApp.gc(R.color.iobPred)));
|
iobPred2.add(i.setColor(resourceHelper.gc(R.color.iobPred)));
|
||||||
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(i.iob));
|
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(i.iob));
|
||||||
}
|
}
|
||||||
DataPointWithLabelInterface[] iobp2 = new DataPointWithLabelInterface[iobPred2.size()];
|
DataPointWithLabelInterface[] iobp2 = new DataPointWithLabelInterface[iobPred2.size()];
|
||||||
iobp2 = iobPred2.toArray(iobp2);
|
iobp2 = iobPred2.toArray(iobp2);
|
||||||
addSeries(new PointsWithLabelGraphSeries<>(iobp2));
|
addSeries(new PointsWithLabelGraphSeries<>(iobp2));
|
||||||
|
|
||||||
if (L.isEnabled(L.AUTOSENS)) {
|
aapsLogger.debug(LTag.AUTOSENS, "IOB pred for AS=" + DecimalFormatter.to2Decimal(lastAutosensResult.ratio) + ": " + iobCobCalculatorPlugin.iobArrayToString(iobPredArray));
|
||||||
log.debug("IOB pred for AS=" + DecimalFormatter.to2Decimal(lastAutosensResult.ratio) + ": " + IobCobCalculatorPlugin.getPlugin().iobArrayToString(iobPredArray));
|
aapsLogger.debug(LTag.AUTOSENS, "IOB pred for AS=" + DecimalFormatter.to2Decimal(1) + ": " + iobCobCalculatorPlugin.iobArrayToString(iobPredArray2));
|
||||||
log.debug("IOB pred for AS=" + DecimalFormatter.to2Decimal(1) + ": " + IobCobCalculatorPlugin.getPlugin().iobArrayToString(iobPredArray2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useForScale) {
|
if (useForScale) {
|
||||||
|
@ -512,8 +518,8 @@ public class GraphData {
|
||||||
cobData = cobArray.toArray(cobData);
|
cobData = cobArray.toArray(cobData);
|
||||||
cobSeries = new FixedLineGraphSeries<>(cobData);
|
cobSeries = new FixedLineGraphSeries<>(cobData);
|
||||||
cobSeries.setDrawBackground(true);
|
cobSeries.setDrawBackground(true);
|
||||||
cobSeries.setBackgroundColor(0x80FFFFFF & MainApp.gc(R.color.cob)); //50%
|
cobSeries.setBackgroundColor(0x80FFFFFF & resourceHelper.gc(R.color.cob)); //50%
|
||||||
cobSeries.setColor(MainApp.gc(R.color.cob));
|
cobSeries.setColor(resourceHelper.gc(R.color.cob));
|
||||||
cobSeries.setThickness(3);
|
cobSeries.setThickness(3);
|
||||||
|
|
||||||
if (useForScale) {
|
if (useForScale) {
|
||||||
|
@ -535,7 +541,7 @@ public class GraphData {
|
||||||
class DeviationDataPoint extends ScaledDataPoint {
|
class DeviationDataPoint extends ScaledDataPoint {
|
||||||
public int color;
|
public int color;
|
||||||
|
|
||||||
public DeviationDataPoint(double x, double y, int color, Scale scale) {
|
private DeviationDataPoint(double x, double y, int color, Scale scale) {
|
||||||
super(x, y, scale);
|
super(x, y, scale);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
@ -549,18 +555,18 @@ public class GraphData {
|
||||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
AutosensData autosensData = iobCobCalculatorPlugin.getAutosensData(time);
|
AutosensData autosensData = iobCobCalculatorPlugin.getAutosensData(time);
|
||||||
if (autosensData != null) {
|
if (autosensData != null) {
|
||||||
int color = MainApp.gc(R.color.deviationblack); // "="
|
int color = resourceHelper.gc(R.color.deviationblack); // "="
|
||||||
if (autosensData.type.equals("") || autosensData.type.equals("non-meal")) {
|
if (autosensData.type.equals("") || autosensData.type.equals("non-meal")) {
|
||||||
if (autosensData.pastSensitivity.equals("C"))
|
if (autosensData.pastSensitivity.equals("C"))
|
||||||
color = MainApp.gc(R.color.deviationgrey);
|
color = resourceHelper.gc(R.color.deviationgrey);
|
||||||
if (autosensData.pastSensitivity.equals("+"))
|
if (autosensData.pastSensitivity.equals("+"))
|
||||||
color = MainApp.gc(R.color.deviationgreen);
|
color = resourceHelper.gc(R.color.deviationgreen);
|
||||||
if (autosensData.pastSensitivity.equals("-"))
|
if (autosensData.pastSensitivity.equals("-"))
|
||||||
color = MainApp.gc(R.color.deviationred);
|
color = resourceHelper.gc(R.color.deviationred);
|
||||||
} else if (autosensData.type.equals("uam")) {
|
} else if (autosensData.type.equals("uam")) {
|
||||||
color = MainApp.gc(R.color.uam);
|
color = resourceHelper.gc(R.color.uam);
|
||||||
} else if (autosensData.type.equals("csf")) {
|
} else if (autosensData.type.equals("csf")) {
|
||||||
color = MainApp.gc(R.color.deviationgrey);
|
color = resourceHelper.gc(R.color.deviationgrey);
|
||||||
}
|
}
|
||||||
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color, devScale));
|
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color, devScale));
|
||||||
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
||||||
|
@ -571,12 +577,7 @@ public class GraphData {
|
||||||
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
|
DeviationDataPoint[] devData = new DeviationDataPoint[devArray.size()];
|
||||||
devData = devArray.toArray(devData);
|
devData = devArray.toArray(devData);
|
||||||
devSeries = new BarGraphSeries<>(devData);
|
devSeries = new BarGraphSeries<>(devData);
|
||||||
devSeries.setValueDependentColor(new ValueDependentColor<DeviationDataPoint>() {
|
devSeries.setValueDependentColor(data -> data.color);
|
||||||
@Override
|
|
||||||
public int get(DeviationDataPoint data) {
|
|
||||||
return data.color;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (useForScale) {
|
if (useForScale) {
|
||||||
maxY = maxDevValueFound;
|
maxY = maxDevValueFound;
|
||||||
|
@ -592,8 +593,8 @@ public class GraphData {
|
||||||
public void addRatio(long fromTime, long toTime, boolean useForScale, double scale) {
|
public void addRatio(long fromTime, long toTime, boolean useForScale, double scale) {
|
||||||
LineGraphSeries<ScaledDataPoint> ratioSeries;
|
LineGraphSeries<ScaledDataPoint> ratioSeries;
|
||||||
List<ScaledDataPoint> ratioArray = new ArrayList<>();
|
List<ScaledDataPoint> ratioArray = new ArrayList<>();
|
||||||
Double maxRatioValueFound = Double.MIN_VALUE;
|
double maxRatioValueFound = Double.MIN_VALUE;
|
||||||
Double minRatioValueFound = Double.MAX_VALUE;
|
double minRatioValueFound = Double.MAX_VALUE;
|
||||||
Scale ratioScale = new Scale();
|
Scale ratioScale = new Scale();
|
||||||
|
|
||||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||||
|
@ -609,7 +610,7 @@ public class GraphData {
|
||||||
ScaledDataPoint[] ratioData = new ScaledDataPoint[ratioArray.size()];
|
ScaledDataPoint[] ratioData = new ScaledDataPoint[ratioArray.size()];
|
||||||
ratioData = ratioArray.toArray(ratioData);
|
ratioData = ratioArray.toArray(ratioData);
|
||||||
ratioSeries = new LineGraphSeries<>(ratioData);
|
ratioSeries = new LineGraphSeries<>(ratioData);
|
||||||
ratioSeries.setColor(MainApp.gc(R.color.ratio));
|
ratioSeries.setColor(resourceHelper.gc(R.color.ratio));
|
||||||
ratioSeries.setThickness(3);
|
ratioSeries.setThickness(3);
|
||||||
|
|
||||||
if (useForScale) {
|
if (useForScale) {
|
||||||
|
@ -628,8 +629,8 @@ public class GraphData {
|
||||||
LineGraphSeries<ScaledDataPoint> dsMinSeries;
|
LineGraphSeries<ScaledDataPoint> dsMinSeries;
|
||||||
List<ScaledDataPoint> dsMaxArray = new ArrayList<>();
|
List<ScaledDataPoint> dsMaxArray = new ArrayList<>();
|
||||||
List<ScaledDataPoint> dsMinArray = new ArrayList<>();
|
List<ScaledDataPoint> dsMinArray = new ArrayList<>();
|
||||||
Double maxFromMaxValueFound = 0d;
|
double maxFromMaxValueFound = 0d;
|
||||||
Double maxFromMinValueFound = 0d;
|
double maxFromMinValueFound = 0d;
|
||||||
Scale dsMaxScale = new Scale();
|
Scale dsMaxScale = new Scale();
|
||||||
Scale dsMinScale = new Scale();
|
Scale dsMinScale = new Scale();
|
||||||
|
|
||||||
|
@ -647,13 +648,13 @@ public class GraphData {
|
||||||
ScaledDataPoint[] ratioMaxData = new ScaledDataPoint[dsMaxArray.size()];
|
ScaledDataPoint[] ratioMaxData = new ScaledDataPoint[dsMaxArray.size()];
|
||||||
ratioMaxData = dsMaxArray.toArray(ratioMaxData);
|
ratioMaxData = dsMaxArray.toArray(ratioMaxData);
|
||||||
dsMaxSeries = new LineGraphSeries<>(ratioMaxData);
|
dsMaxSeries = new LineGraphSeries<>(ratioMaxData);
|
||||||
dsMaxSeries.setColor(MainApp.gc(R.color.devslopepos));
|
dsMaxSeries.setColor(resourceHelper.gc(R.color.devslopepos));
|
||||||
dsMaxSeries.setThickness(3);
|
dsMaxSeries.setThickness(3);
|
||||||
|
|
||||||
ScaledDataPoint[] ratioMinData = new ScaledDataPoint[dsMinArray.size()];
|
ScaledDataPoint[] ratioMinData = new ScaledDataPoint[dsMinArray.size()];
|
||||||
ratioMinData = dsMinArray.toArray(ratioMinData);
|
ratioMinData = dsMinArray.toArray(ratioMinData);
|
||||||
dsMinSeries = new LineGraphSeries<>(ratioMinData);
|
dsMinSeries = new LineGraphSeries<>(ratioMinData);
|
||||||
dsMinSeries.setColor(MainApp.gc(R.color.devslopeneg));
|
dsMinSeries.setColor(resourceHelper.gc(R.color.devslopeneg));
|
||||||
dsMinSeries.setThickness(3);
|
dsMinSeries.setThickness(3);
|
||||||
|
|
||||||
if (useForScale) {
|
if (useForScale) {
|
||||||
|
|
|
@ -178,7 +178,7 @@ class TidepoolPlugin @Inject constructor(
|
||||||
}
|
}
|
||||||
textLog = HtmlHelper.fromHtml(newTextLog.toString())
|
textLog = HtmlHelper.fromHtml(newTextLog.toString())
|
||||||
} catch (e: OutOfMemoryError) {
|
} catch (e: OutOfMemoryError) {
|
||||||
ToastUtils.showToastInUiThread(context, "Out of memory!\nStop using this phone !!!", R.raw.error)
|
ToastUtils.showToastInUiThread(context, rxBus, "Out of memory!\nStop using this phone !!!", R.raw.error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,24 @@
|
||||||
package info.nightscout.androidaps.plugins.general.tidepool.comm
|
package info.nightscout.androidaps.plugins.general.tidepool.comm
|
||||||
|
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
|
import info.nightscout.androidaps.plugins.general.tidepool.events.EventTidepoolStatus
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
|
||||||
internal class TidepoolCallback<T>(private val rxBus: RxBusWrapper, private val session: Session, val name: String, val onSuccess: () -> Unit, val onFail: () -> Unit) : Callback<T> {
|
internal class TidepoolCallback<T>(private val aapsLogger: AAPSLogger, private val rxBus: RxBusWrapper, private val session: Session, val name: String, val onSuccess: () -> Unit, val onFail: () -> Unit) : Callback<T> {
|
||||||
private val log = StacktraceLoggerWrapper.getLogger(L.TIDEPOOL)
|
|
||||||
|
|
||||||
override fun onResponse(call: Call<T>, response: Response<T>) {
|
override fun onResponse(call: Call<T>, response: Response<T>) {
|
||||||
if (response.isSuccessful && response.body() != null) {
|
if (response.isSuccessful && response.body() != null) {
|
||||||
if (L.isEnabled(L.TIDEPOOL)) log.debug("$name success")
|
aapsLogger.debug(LTag.TIDEPOOL, "$name success")
|
||||||
session.populateBody(response.body())
|
session.populateBody(response.body())
|
||||||
session.populateHeaders(response.headers())
|
session.populateHeaders(response.headers())
|
||||||
onSuccess()
|
onSuccess()
|
||||||
} else {
|
} else {
|
||||||
val msg = name + " was not successful: " + response.code() + " " + response.message()
|
val msg = name + " was not successful: " + response.code() + " " + response.message()
|
||||||
if (L.isEnabled(L.TIDEPOOL)) log.debug(msg)
|
aapsLogger.debug(LTag.TIDEPOOL, msg)
|
||||||
rxBus.send(EventTidepoolStatus(msg))
|
rxBus.send(EventTidepoolStatus(msg))
|
||||||
onFail()
|
onFail()
|
||||||
}
|
}
|
||||||
|
@ -28,7 +26,7 @@ internal class TidepoolCallback<T>(private val rxBus: RxBusWrapper, private val
|
||||||
|
|
||||||
override fun onFailure(call: Call<T>, t: Throwable) {
|
override fun onFailure(call: Call<T>, t: Throwable) {
|
||||||
val msg = "$name Failed: $t"
|
val msg = "$name Failed: $t"
|
||||||
if (L.isEnabled(L.TIDEPOOL)) log.debug(msg)
|
aapsLogger.debug(LTag.TIDEPOOL, msg)
|
||||||
rxBus.send(EventTidepoolStatus(msg))
|
rxBus.send(EventTidepoolStatus(msg))
|
||||||
onFail()
|
onFail()
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ class TidepoolUploader @Inject constructor(
|
||||||
rxBus.send(EventTidepoolStatus(("Connecting")))
|
rxBus.send(EventTidepoolStatus(("Connecting")))
|
||||||
val call = session?.service?.getLogin(authHeader)
|
val call = session?.service?.getLogin(authHeader)
|
||||||
|
|
||||||
call?.enqueue(TidepoolCallback<AuthReplyMessage>(rxBus, session!!, "Login", {
|
call?.enqueue(TidepoolCallback<AuthReplyMessage>(aapsLogger, rxBus, session!!, "Login", {
|
||||||
startSession(session!!, doUpload)
|
startSession(session!!, doUpload)
|
||||||
}, {
|
}, {
|
||||||
connectionStatus = ConnectionStatus.FAILED
|
connectionStatus = ConnectionStatus.FAILED
|
||||||
|
@ -128,7 +128,7 @@ class TidepoolUploader @Inject constructor(
|
||||||
session.authHeader?.let {
|
session.authHeader?.let {
|
||||||
val call = session.service?.getLogin(it)
|
val call = session.service?.getLogin(it)
|
||||||
|
|
||||||
call?.enqueue(TidepoolCallback<AuthReplyMessage>(rxBus, session, "Login", {
|
call?.enqueue(TidepoolCallback<AuthReplyMessage>(aapsLogger, rxBus, session, "Login", {
|
||||||
OKDialog.show(rootContext, resourceHelper.gs(R.string.tidepool), "Successfully logged into Tidepool.")
|
OKDialog.show(rootContext, resourceHelper.gs(R.string.tidepool), "Successfully logged into Tidepool.")
|
||||||
}, {
|
}, {
|
||||||
OKDialog.show(rootContext, resourceHelper.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.")
|
OKDialog.show(rootContext, resourceHelper.gs(R.string.tidepool), "Failed to log into Tidepool.\nCheck that your user name and password are correct.")
|
||||||
|
@ -146,12 +146,12 @@ class TidepoolUploader @Inject constructor(
|
||||||
val datasetCall = session.service!!.getOpenDataSets(session.token!!,
|
val datasetCall = session.service!!.getOpenDataSets(session.token!!,
|
||||||
session.authReply!!.userid!!, BuildConfig.APPLICATION_ID, 1)
|
session.authReply!!.userid!!, BuildConfig.APPLICATION_ID, 1)
|
||||||
|
|
||||||
datasetCall.enqueue(TidepoolCallback<List<DatasetReplyMessage>>(rxBus, session, "Get Open Datasets", {
|
datasetCall.enqueue(TidepoolCallback<List<DatasetReplyMessage>>(aapsLogger, rxBus, session, "Get Open Datasets", {
|
||||||
if (session.datasetReply == null) {
|
if (session.datasetReply == null) {
|
||||||
rxBus.send(EventTidepoolStatus(("Creating new dataset")))
|
rxBus.send(EventTidepoolStatus(("Creating new dataset")))
|
||||||
val call = session.service.openDataSet(session.token!!, session.authReply!!.userid!!,
|
val call = session.service.openDataSet(session.token!!, session.authReply!!.userid!!,
|
||||||
OpenDatasetRequestMessage(activePlugin.activePump.serialNumber()).getBody())
|
OpenDatasetRequestMessage(activePlugin.activePump.serialNumber()).getBody())
|
||||||
call.enqueue(TidepoolCallback<DatasetReplyMessage>(rxBus, session, "Open New Dataset", {
|
call.enqueue(TidepoolCallback<DatasetReplyMessage>(aapsLogger, rxBus, session, "Open New Dataset", {
|
||||||
connectionStatus = ConnectionStatus.CONNECTED
|
connectionStatus = ConnectionStatus.CONNECTED
|
||||||
rxBus.send(EventTidepoolStatus(("New dataset OK")))
|
rxBus.send(EventTidepoolStatus(("New dataset OK")))
|
||||||
if (doUpload) doUpload()
|
if (doUpload) doUpload()
|
||||||
|
@ -215,7 +215,7 @@ class TidepoolUploader @Inject constructor(
|
||||||
rxBus.send(EventTidepoolStatus(("Uploading")))
|
rxBus.send(EventTidepoolStatus(("Uploading")))
|
||||||
if (session.service != null && session.token != null && session.datasetReply != null) {
|
if (session.service != null && session.token != null && session.datasetReply != null) {
|
||||||
val call = session.service.doUpload(session.token!!, session.datasetReply!!.getUploadId()!!, body)
|
val call = session.service.doUpload(session.token!!, session.datasetReply!!.getUploadId()!!, body)
|
||||||
call.enqueue(TidepoolCallback<UploadReplyMessage>(rxBus, session, "Data Upload", {
|
call.enqueue(TidepoolCallback<UploadReplyMessage>(aapsLogger, rxBus, session, "Data Upload", {
|
||||||
uploadChunk.setLastEnd(session.end)
|
uploadChunk.setLastEnd(session.end)
|
||||||
rxBus.send(EventTidepoolStatus(("Upload completed OK")))
|
rxBus.send(EventTidepoolStatus(("Upload completed OK")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
|
@ -242,7 +242,7 @@ class TidepoolUploader @Inject constructor(
|
||||||
if (session?.datasetReply?.id != null) {
|
if (session?.datasetReply?.id != null) {
|
||||||
extendWakeLock(60000)
|
extendWakeLock(60000)
|
||||||
val call = session!!.service?.deleteDataSet(session!!.token!!, session!!.datasetReply!!.id!!)
|
val call = session!!.service?.deleteDataSet(session!!.token!!, session!!.datasetReply!!.id!!)
|
||||||
call?.enqueue(TidepoolCallback(rxBus, session!!, "Delete Dataset", {
|
call?.enqueue(TidepoolCallback(aapsLogger, rxBus, session!!, "Delete Dataset", {
|
||||||
connectionStatus = ConnectionStatus.DISCONNECTED
|
connectionStatus = ConnectionStatus.DISCONNECTED
|
||||||
rxBus.send(EventTidepoolStatus(("Dataset removed OK")))
|
rxBus.send(EventTidepoolStatus(("Dataset removed OK")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
|
@ -267,7 +267,7 @@ class TidepoolUploader @Inject constructor(
|
||||||
requireNotNull(userId)
|
requireNotNull(userId)
|
||||||
extendWakeLock(60000)
|
extendWakeLock(60000)
|
||||||
val call = session.service?.deleteAllData(token, userId)
|
val call = session.service?.deleteAllData(token, userId)
|
||||||
call?.enqueue(TidepoolCallback(rxBus, session, "Delete all data", {
|
call?.enqueue(TidepoolCallback(aapsLogger, rxBus, session, "Delete all data", {
|
||||||
connectionStatus = ConnectionStatus.DISCONNECTED
|
connectionStatus = ConnectionStatus.DISCONNECTED
|
||||||
rxBus.send(EventTidepoolStatus(("All data removed OK")))
|
rxBus.send(EventTidepoolStatus(("All data removed OK")))
|
||||||
releaseWakeLock()
|
releaseWakeLock()
|
||||||
|
|
|
@ -36,6 +36,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
@Inject lateinit var loopPlugin: LoopPlugin
|
@Inject lateinit var loopPlugin: LoopPlugin
|
||||||
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||||
@Inject lateinit var localAlertUtils: LocalAlertUtils
|
@Inject lateinit var localAlertUtils: LocalAlertUtils
|
||||||
|
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||||
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -133,7 +134,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
}
|
}
|
||||||
if (lastRun != 0L && System.currentTimeMillis() - lastRun > T.mins(10).msecs()) {
|
if (lastRun != 0L && System.currentTimeMillis() - lastRun > T.mins(10).msecs()) {
|
||||||
aapsLogger.error(LTag.CORE, "KeepAlive fail")
|
aapsLogger.error(LTag.CORE, "KeepAlive fail")
|
||||||
FabricPrivacy.getInstance().logCustom("KeepAliveFail")
|
fabricPrivacy.logCustom("KeepAliveFail")
|
||||||
}
|
}
|
||||||
lastRun = System.currentTimeMillis()
|
lastRun = System.currentTimeMillis()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.utils
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
@ -12,6 +13,7 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
class HardLimits @Inject constructor(
|
class HardLimits @Inject constructor(
|
||||||
val aapsLogger: AAPSLogger,
|
val aapsLogger: AAPSLogger,
|
||||||
|
val rxBus: RxBusWrapper,
|
||||||
val sp: SP,
|
val sp: SP,
|
||||||
val resourceHelper: ResourceHelper,
|
val resourceHelper: ResourceHelper,
|
||||||
val context: Context
|
val context: Context
|
||||||
|
@ -85,7 +87,7 @@ class HardLimits @Inject constructor(
|
||||||
msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newvalue)
|
msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newvalue)
|
||||||
aapsLogger.error(msg)
|
aapsLogger.error(msg)
|
||||||
NSUpload.uploadError(msg)
|
NSUpload.uploadError(msg)
|
||||||
ToastUtils.showToastInUiThread(context, msg, R.raw.error)
|
ToastUtils.showToastInUiThread(context, rxBus, msg, R.raw.error)
|
||||||
}
|
}
|
||||||
return newvalue
|
return newvalue
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||||
|
|
||||||
|
@ -22,13 +23,13 @@ public class ToastUtils {
|
||||||
mainThread.post(() -> Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show());
|
mainThread.post(() -> Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showToastInUiThread(final Context ctx,
|
public static void showToastInUiThread(final Context ctx, final RxBusWrapper rxBus,
|
||||||
final String string, int soundID) {
|
final String string, int soundID) {
|
||||||
|
|
||||||
showToastInUiThread(ctx, string);
|
showToastInUiThread(ctx, string);
|
||||||
playSound(ctx, soundID);
|
playSound(ctx, soundID);
|
||||||
Notification notification = new Notification(Notification.TOAST_ALARM, string, Notification.URGENT);
|
Notification notification = new Notification(Notification.TOAST_ALARM, string, Notification.URGENT);
|
||||||
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
|
rxBus.send(new EventNewNotification(notification));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void playSound(final Context ctx, final int soundID) {
|
private static void playSound(final Context ctx, final int soundID) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.utils.resources
|
||||||
|
|
||||||
import android.content.res.AssetFileDescriptor
|
import android.content.res.AssetFileDescriptor
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import androidx.annotation.*
|
import androidx.annotation.*
|
||||||
|
|
||||||
interface ResourceHelper {
|
interface ResourceHelper {
|
||||||
|
@ -17,5 +18,6 @@ interface ResourceHelper {
|
||||||
fun getIcon() : Int
|
fun getIcon() : Int
|
||||||
fun getNotificationIcon() : Int
|
fun getNotificationIcon() : Int
|
||||||
fun decodeResource(id : Int) : Bitmap
|
fun decodeResource(id : Int) : Bitmap
|
||||||
|
fun getDisplayMetrics(): DisplayMetrics
|
||||||
fun dpToPx(dp: Int): Int
|
fun dpToPx(dp: Int): Int
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ import android.content.Context
|
||||||
import android.content.res.AssetFileDescriptor
|
import android.content.res.AssetFileDescriptor
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
|
import android.util.DisplayMetrics
|
||||||
import androidx.annotation.ArrayRes
|
import androidx.annotation.ArrayRes
|
||||||
import androidx.annotation.BoolRes
|
import androidx.annotation.BoolRes
|
||||||
import androidx.annotation.ColorRes
|
import androidx.annotation.ColorRes
|
||||||
|
@ -60,6 +61,9 @@ class ResourceHelperImplementation @Inject constructor(private val context: Cont
|
||||||
override fun decodeResource(id: Int): Bitmap =
|
override fun decodeResource(id: Int): Bitmap =
|
||||||
BitmapFactory.decodeResource(context.resources, id)
|
BitmapFactory.decodeResource(context.resources, id)
|
||||||
|
|
||||||
|
override fun getDisplayMetrics():DisplayMetrics =
|
||||||
|
context.resources.getDisplayMetrics()
|
||||||
|
|
||||||
override fun dpToPx(dp: Int): Int {
|
override fun dpToPx(dp: Int): Int {
|
||||||
val scale = context.resources.displayMetrics.density
|
val scale = context.resources.displayMetrics.density
|
||||||
return (dp * scale + 0.5f).toInt()
|
return (dp * scale + 0.5f).toInt()
|
||||||
|
|
|
@ -6,11 +6,9 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
|
@ -31,7 +29,6 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
import info.nightscout.androidaps.utils.HardLimits
|
import info.nightscout.androidaps.utils.HardLimits
|
||||||
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
import info.nightscout.androidaps.utils.buildHelper.BuildHelper
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
|
@ -106,10 +103,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
|
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
|
||||||
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
|
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
|
||||||
|
|
||||||
// PowerMockito.mockStatic(FabricPrivacy::class.java)
|
|
||||||
// val mainApp = AAPSMocker.mockMainApp()
|
|
||||||
// `when`(mainApp.packageName).thenReturn("info.nightscout.androidaps")
|
|
||||||
|
|
||||||
// RS constructor
|
// RS constructor
|
||||||
`when`(sp.getString(R.string.key_danars_address, "")).thenReturn("")
|
`when`(sp.getString(R.string.key_danars_address, "")).thenReturn("")
|
||||||
|
|
||||||
|
@ -118,7 +111,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
constraintChecker = ConstraintChecker(activePlugin)
|
constraintChecker = ConstraintChecker(activePlugin)
|
||||||
|
|
||||||
danaRPump = DanaRPump(aapsLogger, sp, injector)
|
danaRPump = DanaRPump(aapsLogger, sp, injector)
|
||||||
hardLimits = HardLimits(aapsLogger, sp, resourceHelper, context)
|
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context)
|
||||||
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp)
|
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp)
|
||||||
comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context)
|
comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context)
|
||||||
danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump)
|
danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||||
|
|
|
@ -74,7 +74,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
`when`(activePlugin.activePump).thenReturn(virtualPumpPlugin)
|
||||||
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
|
||||||
hardLimits = HardLimits(aapsLogger, sp, resourceHelper, context)
|
hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context)
|
||||||
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin)
|
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue