more AAPSLogger and ResourceHelper injections

This commit is contained in:
Milos Kozak 2020-03-22 16:29:08 +01:00
parent 1ab0938a38
commit 2b62f801c5
21 changed files with 236 additions and 241 deletions

View file

@ -5,6 +5,7 @@ import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService
import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService
import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService
import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService
import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService
import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService
@ -12,6 +13,7 @@ import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService
import info.nightscout.androidaps.plugins.pump.danaRv2.services.DanaRv2ExecutionService
import info.nightscout.androidaps.plugins.pump.insight.InsightAlertService
import info.nightscout.androidaps.plugins.pump.insight.connection_service.InsightConnectionService
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService
import info.nightscout.androidaps.services.AlarmSoundService
import info.nightscout.androidaps.services.DataService
import info.nightscout.androidaps.services.LocationService
@ -33,4 +35,6 @@ abstract class ServicesModule {
@ContributesAndroidInjector abstract fun contributesWatchUpdaterService(): WatchUpdaterService
@ContributesAndroidInjector abstract fun contributesInsightAlertService(): InsightAlertService
@ContributesAndroidInjector abstract fun contributesInsightConnectionService(): InsightConnectionService
@ContributesAndroidInjector abstract fun contributesRileyLinkService(): RileyLinkService
@ContributesAndroidInjector abstract fun contributesRileyLinkMedtronicService(): RileyLinkMedtronicService
}

View file

@ -12,6 +12,7 @@ interface AAPSLogger {
fun debug(tag: LTag, format: String, vararg arguments: Any?)
fun warn(tag: LTag, message: String)
fun info(tag: LTag, message: String)
fun info(tag: LTag, format: String, vararg arguments: Any?)
fun error(tag: LTag, message: String)
fun error(tag: LTag, message: String, throwable: Throwable)
fun error(tag: LTag, format: String, vararg arguments: Any?)

View file

@ -32,6 +32,10 @@ class AAPSLoggerDebug : AAPSLogger {
Log.i(tag.tag, message)
}
override fun info(tag: LTag, format: String, vararg arguments: Any?) {
Log.i(tag.tag, String.format(format, arguments))
}
override fun error(tag: LTag, message: String) {
Log.e(tag.tag, message)

View file

@ -42,6 +42,10 @@ class AAPSLoggerProduction : AAPSLogger {
}
}
override fun info(tag: LTag, format: String, vararg arguments: Any?) {
LoggerFactory.getLogger(tag.tag).info(stackLogMarker() + String.format(format, arguments))
}
override fun error(tag: LTag, message: String) {
if (L.isEnabled(tag.tag)) {
LoggerFactory.getLogger(tag.tag).error(stackLogMarker() + message)

View file

@ -21,7 +21,6 @@ import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
@ -37,6 +36,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SafeParse;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
public class DetermineBasalAdapterSMBJS {
@ -44,6 +44,7 @@ public class DetermineBasalAdapterSMBJS {
@Inject AAPSLogger aapsLogger;
@Inject ConstraintChecker constraintChecker;
@Inject SP sp;
@Inject ResourceHelper resourceHelper;
@Inject ProfileFunction profileFunction;
@Inject TreatmentsPlugin treatmentsPlugin;
@ -265,7 +266,7 @@ public class DetermineBasalAdapterSMBJS {
mProfile.put("enableUAM", uamAllowed);
mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable);
boolean smbEnabled = sp.getBoolean(MainApp.gs(R.string.key_use_smb), false);
boolean smbEnabled = sp.getBoolean(resourceHelper.gs(R.string.key_use_smb), false);
mProfile.put("enableSMB_with_COB", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_COB, false));
mProfile.put("enableSMB_with_temptarget", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_temptarget, false));
mProfile.put("allowSMB_with_high_temptarget", smbEnabled && sp.getBoolean(R.string.key_allowSMB_with_high_temptarget, false));

View file

@ -15,7 +15,6 @@ import java.util.List;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T;
@ -141,7 +140,7 @@ public abstract class Objective {
;
public String getProgress() {
return MainApp.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet);
return resourceHelper.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet);
}
Task hint(Hint hint) {

View file

@ -16,9 +16,8 @@ import android.widget.TextView;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
@ -33,6 +32,8 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
@Inject NSClientPlugin nsClientPlugin;
@Inject SP sp;
@Inject ResourceHelper resourceHelper;
@Inject RxBusWrapper rxBus;
@Inject FabricPrivacy fabricPrivacy;
private CompositeDisposable disposable = new CompositeDisposable();
@ -54,31 +55,31 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
autoscrollCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_autoscroll);
logScrollview = view.findViewById(R.id.nsclientinternal_logscrollview);
autoscrollCheckbox = view.findViewById(R.id.nsclientinternal_autoscroll);
autoscrollCheckbox.setChecked(nsClientPlugin.autoscroll);
autoscrollCheckbox.setOnCheckedChangeListener(this);
pausedCheckbox = (CheckBox) view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox = view.findViewById(R.id.nsclientinternal_paused);
pausedCheckbox.setChecked(nsClientPlugin.paused);
pausedCheckbox.setOnCheckedChangeListener(this);
logTextView = (TextView) view.findViewById(R.id.nsclientinternal_log);
queueTextView = (TextView) view.findViewById(R.id.nsclientinternal_queue);
urlTextView = (TextView) view.findViewById(R.id.nsclientinternal_url);
statusTextView = (TextView) view.findViewById(R.id.nsclientinternal_status);
logTextView = view.findViewById(R.id.nsclientinternal_log);
queueTextView = view.findViewById(R.id.nsclientinternal_queue);
urlTextView = view.findViewById(R.id.nsclientinternal_url);
statusTextView = view.findViewById(R.id.nsclientinternal_status);
clearlog = (TextView) view.findViewById(R.id.nsclientinternal_clearlog);
clearlog = view.findViewById(R.id.nsclientinternal_clearlog);
clearlog.setOnClickListener(this);
clearlog.setPaintFlags(clearlog.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
restart = (TextView) view.findViewById(R.id.nsclientinternal_restart);
restart = view.findViewById(R.id.nsclientinternal_restart);
restart.setOnClickListener(this);
restart.setPaintFlags(restart.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
delivernow = (TextView) view.findViewById(R.id.nsclientinternal_delivernow);
delivernow = view.findViewById(R.id.nsclientinternal_delivernow);
delivernow.setOnClickListener(this);
delivernow.setPaintFlags(delivernow.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
clearqueue = (TextView) view.findViewById(R.id.nsclientinternal_clearqueue);
clearqueue = view.findViewById(R.id.nsclientinternal_clearqueue);
clearqueue.setOnClickListener(this);
clearqueue.setPaintFlags(clearqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
showqueue = (TextView) view.findViewById(R.id.nsclientinternal_showqueue);
showqueue = view.findViewById(R.id.nsclientinternal_showqueue);
showqueue.setOnClickListener(this);
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
@ -88,10 +89,10 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
@Override
public synchronized void onResume() {
super.onResume();
disposable.add(RxBus.Companion.getINSTANCE()
disposable.add(rxBus
.toObservable(EventNSClientUpdateGUI.class)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> updateGui(), exception -> FabricPrivacy.getInstance().logException(exception))
.subscribe(event -> updateGui(), fabricPrivacy::logException)
);
updateGui();
}
@ -106,25 +107,25 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
public void onClick(View view) {
switch (view.getId()) {
case R.id.nsclientinternal_restart:
RxBus.Companion.getINSTANCE().send(new EventNSClientRestart());
FabricPrivacy.getInstance().logCustom("NSClientRestart");
rxBus.send(new EventNSClientRestart());
fabricPrivacy.logCustom("NSClientRestart");
break;
case R.id.nsclientinternal_delivernow:
nsClientPlugin.resend("GUI");
FabricPrivacy.getInstance().logCustom("NSClientDeliverNow");
fabricPrivacy.logCustom("NSClientDeliverNow");
break;
case R.id.nsclientinternal_clearlog:
nsClientPlugin.clearLog();
break;
case R.id.nsclientinternal_clearqueue:
OKDialog.showConfirmation(getContext(), MainApp.gs(R.string.nsclientinternal), MainApp.gs(R.string.clearqueueconfirm), () -> {
OKDialog.showConfirmation(getContext(), resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.clearqueueconfirm), () -> {
UploadQueue.clearQueue();
updateGui();
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
fabricPrivacy.logCustom("NSClientClearQueue");
});
break;
case R.id.nsclientinternal_showqueue:
RxBus.Companion.getINSTANCE().send(new EventNSClientNewLog("QUEUE", nsClientPlugin.queue().textList()));
rxBus.send(new EventNSClientNewLog("QUEUE", nsClientPlugin.queue().textList()));
break;
}
}
@ -135,7 +136,7 @@ public class NSClientFragment extends DaggerFragment implements View.OnClickList
case R.id.nsclientinternal_paused:
nsClientPlugin.pause(isChecked);
updateGui();
FabricPrivacy.getInstance().logCustom("NSClientPause");
fabricPrivacy.logCustom("NSClientPause");
break;
case R.id.nsclientinternal_autoscroll:
sp.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);

View file

@ -211,7 +211,7 @@ public class NSDeviceStatus {
}
if (fields.contains("clock")) {
string.append(DateUtil.minAgo(deviceStatusPumpData.clock)).append(" ");
string.append(DateUtil.minAgo(resourceHelper, deviceStatusPumpData.clock)).append(" ");
}
if (fields.contains("status")) {
@ -341,7 +341,7 @@ public class NSDeviceStatus {
if (level == Levels.URGENT) string.append("red\">");
if (deviceStatusOpenAPSData.clockSuggested != 0) {
string.append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append(" ");
string.append(DateUtil.minAgo(resourceHelper, deviceStatusOpenAPSData.clockSuggested)).append(" ");
}
string.append("</span>"); // color
@ -362,9 +362,9 @@ public class NSDeviceStatus {
try {
if (deviceStatusOpenAPSData.enacted != null && deviceStatusOpenAPSData.clockEnacted != deviceStatusOpenAPSData.clockSuggested)
string.append("<b>").append(DateUtil.minAgo(deviceStatusOpenAPSData.clockEnacted)).append("</b> ").append(deviceStatusOpenAPSData.enacted.getString("reason")).append("<br>");
string.append("<b>").append(DateUtil.minAgo(resourceHelper, deviceStatusOpenAPSData.clockEnacted)).append("</b> ").append(deviceStatusOpenAPSData.enacted.getString("reason")).append("<br>");
if (deviceStatusOpenAPSData.suggested != null)
string.append("<b>").append(DateUtil.minAgo(deviceStatusOpenAPSData.clockSuggested)).append("</b> ").append(deviceStatusOpenAPSData.suggested.getString("reason")).append("<br>");
string.append("<b>").append(DateUtil.minAgo(resourceHelper, deviceStatusOpenAPSData.clockSuggested)).append("</b> ").append(deviceStatusOpenAPSData.suggested.getString("reason")).append("<br>");
return Html.fromHtml(string.toString());
} catch (JSONException e) {
aapsLogger.error("Unhandled exception", e);

View file

@ -1187,7 +1187,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
if (activeTemp != null) {
basalText = "T: " + activeTemp.toStringVeryShort();
} else {
basalText = MainApp.gs(R.string.pump_basebasalrate, profile.getBasal());
basalText = resourceHelper.gs(R.string.pump_basebasalrate, profile.getBasal());
}
} else {
if (activeTemp != null) {
@ -1293,7 +1293,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
bgView.setPaintFlags(flag);
if (timeAgoView != null)
timeAgoView.setText(DateUtil.minAgo(lastBG.date));
timeAgoView.setText(DateUtil.minAgo(resourceHelper, lastBG.date));
if (timeAgoShortView != null)
timeAgoShortView.setText("(" + DateUtil.minAgoShort(lastBG.date) + ")");

View file

@ -197,7 +197,7 @@ public class ComboFragment extends DaggerFragment implements View.OnClickListene
}
// last connection
String minAgo = DateUtil.minAgo(comboPlugin.getPump().lastSuccessfulCmdTime);
String minAgo = DateUtil.minAgo(resourceHelper, comboPlugin.getPump().lastSuccessfulCmdTime);
long min = (System.currentTimeMillis() - comboPlugin.getPump().lastSuccessfulCmdTime) / 1000 / 60;
if (comboPlugin.getPump().lastSuccessfulCmdTime + 60 * 1000 > System.currentTimeMillis()) {
lastConnectionView.setText(R.string.combo_pump_connected_now);
@ -220,7 +220,7 @@ public class ComboFragment extends DaggerFragment implements View.OnClickListene
if ((agoMsc < 60 * 1000)) {
ago = resourceHelper.gs(R.string.combo_pump_connected_now);
} else if (bolusMinAgo < 60) {
ago = DateUtil.minAgo(bolus.timestamp);
ago = DateUtil.minAgo(resourceHelper, bolus.timestamp);
} else {
ago = DateUtil.hourAgo(bolus.timestamp, resourceHelper);
}

View file

@ -25,14 +25,11 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
@ -40,11 +37,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import javax.inject.Inject;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
@ -52,12 +50,16 @@ import info.nightscout.androidaps.plugins.pump.common.utils.LocationHelper;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
// IMPORTANT: This activity needs to be called from RileyLinkSelectPreference (see pref_medtronic.xml as example)
public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(RileyLinkBLEScanActivity.class);
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
private static final int PERMISSION_REQUEST_COARSE_LOCATION = 30241; // arbitrary.
private static final int REQUEST_ENABLE_BT = 30242; // arbitrary
@ -91,7 +93,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
mHandler = new Handler();
mLeDeviceListAdapter = new LeDeviceListAdapter();
listBTScan = (ListView) findViewById(R.id.rileylink_listBTScan);
listBTScan = findViewById(R.id.rileylink_listBTScan);
listBTScan.setAdapter(mLeDeviceListAdapter);
listBTScan.setOnItemClickListener((parent, view, position, id) -> {
@ -101,22 +103,22 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
mLEScanner.stopScan(mScanCallback2);
}
TextView textview = (TextView) view.findViewById(R.id.rileylink_device_address);
TextView textview = view.findViewById(R.id.rileylink_device_address);
String bleAddress = textview.getText().toString();
SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
RileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
pumpStatus.verifyConfiguration(); // force reloading of address
RxBus.Companion.getINSTANCE().send(new EventMedtronicPumpConfigurationChanged());
rxBus.send(new EventMedtronicPumpConfigurationChanged());
finish();
});
toolbarBTScan = (Toolbar) findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan = findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
setSupportActionBar(toolbarBTScan);
@ -128,8 +130,8 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_rileylink_ble_scan, menu);
actionTitleStart = MainApp.gs(R.string.rileylink_scanner_scan_scan);
actionTitleStop = MainApp.gs(R.string.rileylink_scanner_scan_stop);
actionTitleStart = resourceHelper.gs(R.string.rileylink_scanner_scan_scan);
actionTitleStop = resourceHelper.gs(R.string.rileylink_scanner_scan_stop);
menuItem = menu.getItem(0);
@ -272,7 +274,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
@Override
public void onScanFailed(int errorCode) {
Log.e("Scan Failed", "Error Code: " + errorCode);
Toast.makeText(mContext, MainApp.gs(R.string.rileylink_scanner_scanning_error, errorCode),
Toast.makeText(mContext, resourceHelper.gs(R.string.rileylink_scanner_scanning_error, errorCode),
Toast.LENGTH_LONG).show();
}
@ -295,7 +297,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
if (mScanning) {
mScanning = false;
mLEScanner.stopScan(mScanCallback2);
LOG.debug("scanLeDevice: Scanning Stop");
aapsLogger.debug("scanLeDevice: Scanning Stop");
Toast.makeText(mContext, R.string.rileylink_scanner_scanning_finished, Toast.LENGTH_SHORT).show();
menuItem.setTitle(actionTitleStart);
}
@ -303,7 +305,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
mScanning = true;
mLEScanner.startScan(filters, settings, mScanCallback2);
LOG.debug("scanLeDevice: Scanning Start");
aapsLogger.debug("scanLeDevice: Scanning Start");
Toast.makeText(this, R.string.rileylink_scanner_scanning, Toast.LENGTH_SHORT).show();
menuItem.setTitle(actionTitleStop);
@ -313,7 +315,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
mScanning = false;
mLEScanner.stopScan(mScanCallback2);
LOG.debug("scanLeDevice: Scanning Stop");
aapsLogger.debug("scanLeDevice: Scanning Stop");
Toast.makeText(this, R.string.rileylink_scanner_scanning_finished, Toast.LENGTH_SHORT).show();
menuItem.setTitle(actionTitleStart);
@ -334,7 +336,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
mLeDevices = new ArrayList<>();
rileyLinkDevices = new HashMap<>();
mInflator = RileyLinkBLEScanActivity.this.getLayoutInflater();
currentlySelectedAddress = SP.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
currentlySelectedAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
}
@ -381,8 +383,8 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
if (view == null) {
view = mInflator.inflate(R.layout.rileylink_scan_item, null);
viewHolder = new ViewHolder();
viewHolder.deviceAddress = (TextView) view.findViewById(R.id.rileylink_device_address);
viewHolder.deviceName = (TextView) view.findViewById(R.id.rileylink_device_name);
viewHolder.deviceAddress = view.findViewById(R.id.rileylink_device_address);
viewHolder.deviceName = view.findViewById(R.id.rileylink_device_name);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();

View file

@ -14,15 +14,19 @@ import com.google.android.material.tabs.TabLayout;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import javax.inject.Inject;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
@Inject ResourceHelper resourceHelper;
TextView connectionStatus;
TextView configuredAddress;
TextView connectedDevice;
@ -47,14 +51,14 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
// primary sections of the activity.
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.rileylink_settings_container);
mViewPager = findViewById(R.id.rileylink_settings_container);
// mViewPager.setAdapter(mSectionsPagerAdapter);
setupViewPager(mViewPager);
tabLayout = (TabLayout) findViewById(R.id.rileylink_settings_tabs);
tabLayout = findViewById(R.id.rileylink_settings_tabs);
tabLayout.setupWithViewPager(mViewPager);
floatingActionButton = (FloatingActionButton) findViewById(R.id.rileylink_settings_fab);
floatingActionButton = findViewById(R.id.rileylink_settings_fab);
floatingActionButton.setOnClickListener(v -> {
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter
@ -110,8 +114,8 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneral(), MainApp.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistory(), MainApp.gs(R.string.rileylink_settings_tab2));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusGeneral(), resourceHelper.gs(R.string.rileylink_settings_tab1));
mSectionsPagerAdapter.addFragment(new RileyLinkStatusHistory(), resourceHelper.gs(R.string.rileylink_settings_tab2));
//mSectionsPagerAdapter.addFragment(new RileyLinkStatusDevice(), "Medtronic");
mViewPager.setAdapter(mSectionsPagerAdapter);

View file

@ -1,18 +1,15 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service;
import static info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import javax.inject.Inject;
import dagger.android.DaggerService;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
@ -26,33 +23,47 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import static info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil.getRileyLinkCommunicationManager;
/**
* Created by andy on 5/6/18.
* Split from original file and renamed.
*/
public abstract class RileyLinkService extends Service {
public abstract class RileyLinkService extends DaggerService {
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@Inject Context context;
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public RileyLinkBLE rileyLinkBLE; // android-bluetooth management
protected BluetoothAdapter bluetoothAdapter;
protected RFSpy rfspy; // interface for RL xxx Mhz radio.
protected Context context;
protected RileyLinkBroadcastReceiver mBroadcastReceiver;
protected RileyLinkServiceData rileyLinkServiceData;
protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver;
public RileyLinkService(Context context) {
super();
this.context = context;
@Override
public void onCreate() {
super.onCreate();
//LOG.debug("onCreate");
RileyLinkUtil.setContext(this.context);
RileyLinkUtil.setRileyLinkService(this);
RileyLinkUtil.setEncoding(getEncoding());
initRileyLinkServiceData();
}
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this, this.context);
mBroadcastReceiver.registerBroadcasts();
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
bluetoothStateReceiver.registerBroadcasts(this);
//LOG.debug("onCreate(): It's ALIVE!");
}
/**
* Get Encoding for RileyLink communication
@ -68,14 +79,14 @@ public abstract class RileyLinkService extends Service {
@Override
public boolean onUnbind(Intent intent) {
//LOG.warn("onUnbind");
//aapsLogger.warn(LTag.PUMPCOMM, "onUnbind");
return super.onUnbind(intent);
}
@Override
public void onRebind(Intent intent) {
//LOG.warn("onRebind");
//aapsLogger.warn(LTag.PUMPCOMM, "onRebind");
super.onRebind(intent);
}
@ -90,33 +101,17 @@ public abstract class RileyLinkService extends Service {
rileyLinkBLE = null;
}
if (mBroadcastReceiver!=null) {
if (mBroadcastReceiver != null) {
mBroadcastReceiver.unregisterBroadcasts();
}
if (bluetoothStateReceiver!=null) {
if (bluetoothStateReceiver != null) {
bluetoothStateReceiver.unregisterBroadcasts(this);
}
}
@Override
public void onCreate() {
super.onCreate();
//LOG.debug("onCreate");
mBroadcastReceiver = new RileyLinkBroadcastReceiver(this, this.context);
mBroadcastReceiver.registerBroadcasts();
bluetoothStateReceiver = new RileyLinkBluetoothStateReceiver();
bluetoothStateReceiver.registerBroadcasts(this);
//LOG.debug("onCreate(): It's ALIVE!");
}
/**
* Prefix for Device specific broadcast identifier prefix (for example MSG_PUMP_ for pump or
* MSG_POD_ for Omnipod)
@ -145,19 +140,18 @@ public abstract class RileyLinkService extends Service {
public boolean bluetoothInit() {
if (isLogEnabled())
LOG.debug("bluetoothInit: attempting to get an adapter");
aapsLogger.debug(LTag.PUMPCOMM, "bluetoothInit: attempting to get an adapter");
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothInitializing);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
LOG.error("Unable to obtain a BluetoothAdapter.");
aapsLogger.error("Unable to obtain a BluetoothAdapter.");
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.NoBluetoothAdapter);
} else {
if (!bluetoothAdapter.isEnabled()) {
LOG.error("Bluetooth is not enabled.");
aapsLogger.error("Bluetooth is not enabled.");
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
} else {
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
@ -181,13 +175,11 @@ public abstract class RileyLinkService extends Service {
if (rileyLinkBLE.isConnected()) {
if (deviceAddress.equals(rileyLinkServiceData.rileylinkAddress)) {
if (isLogEnabled())
LOG.info("No change to RL address. Not reconnecting.");
aapsLogger.info(LTag.PUMPCOMM, "No change to RL address. Not reconnecting.");
return false;
} else {
if (isLogEnabled())
LOG.warn("Disconnecting from old RL (" + rileyLinkServiceData.rileylinkAddress
+ "), reconnecting to new: " + deviceAddress);
aapsLogger.warn(LTag.PUMPCOMM, "Disconnecting from old RL (" + rileyLinkServiceData.rileylinkAddress
+ "), reconnecting to new: " + deviceAddress);
rileyLinkBLE.disconnect();
// prolly need to shut down listening thread too?
@ -198,12 +190,11 @@ public abstract class RileyLinkService extends Service {
return true;
}
} else {
if (isLogEnabled())
LOG.debug("Using RL " + deviceAddress);
aapsLogger.debug(LTag.PUMPCOMM, "Using RL " + deviceAddress);
if (RileyLinkUtil.getServiceState() == RileyLinkServiceState.NotStarted) {
if (!bluetoothInit()) {
LOG.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
aapsLogger.error("RileyLink can't get activated, Bluetooth is not functioning correctly. {}",
RileyLinkUtil.getError() != null ? RileyLinkUtil.getError().name() : "Unknown error (null)");
return false;
}
@ -229,7 +220,7 @@ public abstract class RileyLinkService extends Service {
double lastGoodFrequency = 0.0d;
if (rileyLinkServiceData.lastGoodFrequency == null) {
lastGoodFrequency = SP.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
lastGoodFrequency = sp.getDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, 0.0d);
} else {
lastGoodFrequency = rileyLinkServiceData.lastGoodFrequency;
}
@ -239,9 +230,8 @@ public abstract class RileyLinkService extends Service {
newFrequency = getDeviceCommunicationManager().tuneForDevice();
if ((newFrequency != 0.0) && (newFrequency != lastGoodFrequency)) {
if (isLogEnabled())
LOG.info("Saving new pump frequency of {} MHz", newFrequency);
SP.putDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, newFrequency);
aapsLogger.info(LTag.PUMPCOMM, "Saving new pump frequency of {} MHz", newFrequency);
sp.putDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, newFrequency);
rileyLinkServiceData.lastGoodFrequency = newFrequency;
rileyLinkServiceData.tuneUpDone = true;
rileyLinkServiceData.lastTuneUpTime = System.currentTimeMillis();
@ -277,11 +267,6 @@ public abstract class RileyLinkService extends Service {
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPCOMM);
}
public void changeRileyLinkEncoding(RileyLinkEncodingType encodingType) {
if (rfspy != null) {
rfspy.setRileyLinkEncoding(encodingType);

View file

@ -257,7 +257,7 @@ class MedtronicFragment : DaggerFragment() {
// last connection
if (pumpStatus.lastConnection != 0L) {
val minAgo = DateUtil.minAgo(pumpStatus.lastConnection)
val minAgo = DateUtil.minAgo(resourceHelper, pumpStatus.lastConnection)
val min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60
if (pumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) {
medtronic_lastconnection.setText(R.string.combo_pump_connected_now)
@ -295,7 +295,7 @@ class MedtronicFragment : DaggerFragment() {
if (agoMsc < 60 * 1000) {
ago = resourceHelper.gs(R.string.combo_pump_connected_now)
} else if (bolusMinAgo < 60) {
ago = DateUtil.minAgo(pumpStatus.lastBolusTime.time)
ago = DateUtil.minAgo(resourceHelper, pumpStatus.lastBolusTime.time)
} else {
ago = DateUtil.hourAgo(pumpStatus.lastBolusTime.time, resourceHelper)
}

View file

@ -177,7 +177,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
@Override
protected void onStart() {
super.onStart();
medtronicUIComm = new MedtronicUIComm();
medtronicUIComm = new MedtronicUIComm(aapsLogger, rxBus, getResourceHelper());
medtronicHistoryData = new MedtronicHistoryData(aapsLogger, sp, activePlugin);
}
@ -432,12 +432,12 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (isPumpNotReachable()) {
aapsLogger.error("Pump unreachable.");
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable, getResourceHelper(), rxBus);
return;
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
if (hasTimeDateOrTimeZoneChanged) {
@ -532,14 +532,14 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (isRefresh) {
if (isPumpNotReachable()) {
aapsLogger.error(getLogPrefix() + "initializePump::Pump unreachable.");
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpUnreachable, getResourceHelper(), rxBus);
setRefreshButtonEnabled(true);
return;
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
}
// model (once)
@ -548,7 +548,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} else {
if (pumpStatusLocal.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
aapsLogger.warn(LTag.PUMP, getLogPrefix() + "Configured pump is not the same as one detected.");
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame);
MedtronicUtil.sendNotification(MedtronicNotificationType.PumpTypeNotSame, getResourceHelper(), rxBus);
}
}
@ -737,7 +737,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return;
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
medtronicUIComm.executeCommand(MedtronicCommandType.GetRealTimeClock);
@ -769,7 +769,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
} else {
if ((clock.localDeviceTime.getYear() > 2015)) {
aapsLogger.error("MedtronicPumpPlugin::checkTimeAndOptionallySetTime - Time difference over 24h requested [diff={}]. Doing nothing." + timeDiff);
sendNotification(MedtronicNotificationType.TimeChangeOver24h);
sendNotification(MedtronicNotificationType.TimeChangeOver24h, getResourceHelper(), rxBus);
}
}
@ -806,7 +806,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return setNotReachable(true, false);
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
if (bolusDeliveryType == BolusDeliveryType.CancelDelivery) {
// LOG.debug("MedtronicPumpPlugin::deliverBolus - Delivery Canceled.");
@ -957,7 +957,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
getMDTPumpStatus();
@ -1344,7 +1344,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
setRefreshButtonEnabled(false);
TempBasalPair tbrCurrent = readTBR();
@ -1427,7 +1427,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
.comment(getResourceHelper().gs(R.string.medtronic_pump_status_pump_unreachable));
}
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable);
MedtronicUtil.dismissNotification(MedtronicNotificationType.PumpUnreachable, rxBus);
BasalProfile basalProfile = convertProfileToMedtronicProfile(profile);

View file

@ -1,25 +1,35 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/**
* Created by andy on 6/14/18.
*/
public class MedtronicUIComm {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
private final AAPSLogger aapsLogger;
MedtronicCommunicationManager mcmInstance = null;
MedtronicUIPostprocessor uiPostprocessor = new MedtronicUIPostprocessor();
MedtronicUIPostprocessor uiPostprocessor;
public MedtronicUIComm(
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
ResourceHelper resourceHelper
) {
this.aapsLogger = aapsLogger;
uiPostprocessor = new MedtronicUIPostprocessor(aapsLogger, rxBus, resourceHelper);
}
private MedtronicCommunicationManager getCommunicationManager() {
@ -34,7 +44,7 @@ public class MedtronicUIComm {
public synchronized MedtronicUITask executeCommand(MedtronicCommandType commandType, Object... parameters) {
if (isLogEnabled())
LOG.warn("Execute Command: " + commandType.name());
aapsLogger.warn(LTag.PUMP, "Execute Command: " + commandType.name());
MedtronicUITask task = new MedtronicUITask(commandType, parameters);
@ -69,7 +79,7 @@ public class MedtronicUIComm {
// }
if (!task.isReceived() && isLogEnabled()) {
LOG.warn("Reply not received for " + commandType);
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
}
task.postProcess(uiPostprocessor);

View file

@ -2,14 +2,13 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
import org.joda.time.DateTimeZone;
import org.joda.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.Map;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BatteryStatusDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
@ -19,6 +18,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicNotificat
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil.sendNotification;
@ -26,14 +26,21 @@ import static info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUt
* Created by andy on 6/15/18.
*/
public class MedtronicUIPostprocessor {
class MedtronicUIPostprocessor {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
MedtronicPumpStatus pumpStatus;
private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;
private final ResourceHelper resourceHelper;
public MedtronicUIPostprocessor() {
private MedtronicPumpStatus pumpStatus;
public MedtronicUIPostprocessor(AAPSLogger aapsLogger, RxBusWrapper rxBus, ResourceHelper resourceHelper) {
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.resourceHelper = resourceHelper;
pumpStatus = MedtronicUtil.getPumpStatus();
}
@ -67,10 +74,10 @@ public class MedtronicUIPostprocessor {
} else {
uiTask.responseType = MedtronicUIResponseType.Error;
uiTask.errorDescription = "No profile found.";
LOG.error("Basal Profile was NOT valid. [{}]", basalProfile.basalProfileToStringError());
aapsLogger.error("Basal Profile was NOT valid. [{}]", basalProfile.basalProfileToStringError());
}
} catch (Exception ex) {
LOG.error("Basal Profile was returned, but was invalid. [{}]", basalProfile.basalProfileToStringError());
aapsLogger.error("Basal Profile was returned, but was invalid. [{}]", basalProfile.basalProfileToStringError());
uiTask.responseType = MedtronicUIResponseType.Error;
uiTask.errorDescription = "No profile found.";
}
@ -103,8 +110,7 @@ public class MedtronicUIPostprocessor {
case SetRealTimeClock: {
boolean response = (Boolean) uiTask.returnData;
if (isLogEnabled())
LOG.debug("New time was {} set.", response ? "" : "NOT");
aapsLogger.debug(LTag.PUMP, "New time was {} set.", response ? "" : "NOT");
if (response) {
MedtronicUtil.getPumpTime().timeDifference = 0;
@ -122,17 +128,15 @@ public class MedtronicUIPostprocessor {
pumpStatus.batteryVoltage = batteryStatusDTO.voltage;
}
if (isLogEnabled())
LOG.info("BatteryStatus: {}", batteryStatusDTO.toString());
aapsLogger.debug(LTag.PUMP, "BatteryStatus: {}", batteryStatusDTO.toString());
}
break;
case PumpModel: {
if (pumpStatus.medtronicDeviceType != MedtronicUtil.getMedtronicPumpModel()) {
if (isLogEnabled())
LOG.warn("Configured pump is different then pump detected !");
sendNotification(MedtronicNotificationType.PumpTypeNotSame);
aapsLogger.warn(LTag.PUMP, "Configured pump is different then pump detected !");
sendNotification(MedtronicNotificationType.PumpTypeNotSame, resourceHelper, rxBus);
}
}
break;
@ -146,8 +150,7 @@ public class MedtronicUIPostprocessor {
// no postprocessing
default:
if (isLogEnabled())
LOG.trace("Post-processing not implemented for {}.", uiTask.commandType.name());
aapsLogger.error(LTag.PUMP, "Post-processing not implemented for {}.", uiTask.commandType.name());
}
@ -165,9 +168,8 @@ public class MedtronicUIPostprocessor {
MedtronicUtil.setPumpTime(clockDTO);
if (isLogEnabled())
LOG.debug("Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
", diff: " + dur.getStandardSeconds() + " s");
aapsLogger.debug(LTag.PUMP, "Pump Time: " + clockDTO.localDeviceTime + ", DeviceTime=" + clockDTO.pumpTime + //
", diff: " + dur.getStandardSeconds() + " s");
// if (dur.getStandardMinutes() >= 10) {
// if (isLogEnabled())
@ -193,28 +195,24 @@ public class MedtronicUIPostprocessor {
PumpSettingDTO checkValue = null;
if (pumpStatus == null) {
if (isLogEnabled())
LOG.debug("Pump Status: was null");
aapsLogger.debug(LTag.PUMP, "Pump Status: was null");
pumpStatus = MedtronicUtil.getPumpStatus();
if (isLogEnabled())
LOG.debug("Pump Status: " + this.pumpStatus);
aapsLogger.debug(LTag.PUMP, "Pump Status: " + this.pumpStatus);
}
this.pumpStatus.verifyConfiguration();
// check profile
if (!"Yes".equals(settings.get("PCFG_BASAL_PROFILES_ENABLED").value)) {
if (isLogEnabled())
LOG.error("Basal profiles are not enabled on pump.");
sendNotification(MedtronicNotificationType.PumpBasalProfilesNotEnabled);
aapsLogger.error(LTag.PUMP, "Basal profiles are not enabled on pump.");
sendNotification(MedtronicNotificationType.PumpBasalProfilesNotEnabled, resourceHelper, rxBus);
} else {
checkValue = settings.get("PCFG_ACTIVE_BASAL_PROFILE");
if (!"STD".equals(checkValue.value)) {
if (isLogEnabled())
LOG.error("Basal profile set on pump is incorrect (must be STD).");
sendNotification(MedtronicNotificationType.PumpIncorrectBasalProfileSelected);
aapsLogger.error("Basal profile set on pump is incorrect (must be STD).");
sendNotification(MedtronicNotificationType.PumpIncorrectBasalProfileSelected, resourceHelper, rxBus);
}
}
@ -223,9 +221,8 @@ public class MedtronicUIPostprocessor {
checkValue = settings.get("PCFG_TEMP_BASAL_TYPE");
if (!"Units".equals(checkValue.value)) {
if (isLogEnabled())
LOG.error("Wrong TBR type set on pump (must be Absolute).");
sendNotification(MedtronicNotificationType.PumpWrongTBRTypeSet);
aapsLogger.error("Wrong TBR type set on pump (must be Absolute).");
sendNotification(MedtronicNotificationType.PumpWrongTBRTypeSet, resourceHelper, rxBus);
}
// MAXes
@ -233,22 +230,16 @@ public class MedtronicUIPostprocessor {
checkValue = settings.get("PCFG_MAX_BOLUS");
if (!MedtronicUtil.isSame(Double.parseDouble(checkValue.value), pumpStatus.maxBolus)) {
LOG.error("Wrong Max Bolus set on Pump (current={}, required={}).", checkValue.value, pumpStatus.maxBolus);
sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, pumpStatus.maxBolus);
aapsLogger.error("Wrong Max Bolus set on Pump (current={}, required={}).", checkValue.value, pumpStatus.maxBolus);
sendNotification(MedtronicNotificationType.PumpWrongMaxBolusSet, resourceHelper, rxBus, pumpStatus.maxBolus);
}
checkValue = settings.get("PCFG_MAX_BASAL");
if (!MedtronicUtil.isSame(Double.parseDouble(checkValue.value), pumpStatus.maxBasal)) {
if (isLogEnabled())
LOG.error("Wrong Max Basal set on Pump (current={}, required={}).", checkValue.value, pumpStatus.maxBasal);
sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, pumpStatus.maxBasal);
aapsLogger.error("Wrong Max Basal set on Pump (current={}, required={}).", checkValue.value, pumpStatus.maxBasal);
sendNotification(MedtronicNotificationType.PumpWrongMaxBasalSet, resourceHelper, rxBus, pumpStatus.maxBasal);
}
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMP);
}
}

View file

@ -13,23 +13,20 @@ import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryGroup;
public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
private static Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMP);
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
Spinner historyTypeSpinner;
TextView statusView;
@ -46,17 +43,12 @@ public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
List<TypeList> typeListFull;
public MedtronicHistoryActivity() {
super();
}
private void filterHistory(PumpHistoryEntryGroup group) {
this.filteredHistoryList.clear();
List<PumpHistoryEntry> list = new ArrayList<>();
list.addAll(MedtronicPumpPlugin.getPlugin().getMedtronicHistoryData().getAllHistory());
list.addAll(medtronicPumpPlugin.getMedtronicHistoryData().getAllHistory());
//LOG.debug("Items on full list: {}", list.size());
@ -113,9 +105,9 @@ public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.medtronic_history_activity);
historyTypeSpinner = (Spinner) findViewById(R.id.medtronic_historytype);
statusView = (TextView) findViewById(R.id.medtronic_historystatus);
recyclerView = (RecyclerView) findViewById(R.id.medtronic_history_recyclerview);
historyTypeSpinner = findViewById(R.id.medtronic_historytype);
statusView = findViewById(R.id.medtronic_historystatus);
recyclerView = findViewById(R.id.medtronic_history_recyclerview);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(this);
@ -245,9 +237,9 @@ public class MedtronicHistoryActivity extends NoSplashAppCompatActivity {
HistoryViewHolder(View itemView) {
super(itemView);
// cv = (CardView)itemView.findViewById(R.id.rileylink_history_item);
timeView = (TextView) itemView.findViewById(R.id.medtronic_history_time);
typeView = (TextView) itemView.findViewById(R.id.medtronic_history_source);
valueView = (TextView) itemView.findViewById(R.id.medtronic_history_description);
timeView = itemView.findViewById(R.id.medtronic_history_time);
typeView = itemView.findViewById(R.id.medtronic_history_source);
valueView = itemView.findViewById(R.id.medtronic_history_description);
}
}
}

View file

@ -1,17 +1,16 @@
package info.nightscout.androidaps.plugins.pump.medtronic.service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.IBinder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
@ -30,14 +29,17 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* RileyLinkMedtronicService is intended to stay running when the gui-app is closed.
*/
public class RileyLinkMedtronicService extends RileyLinkService {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
@Inject AAPSLogger aapsLogger;
@Inject Context context;
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
@Inject SP sp;
private static RileyLinkMedtronicService instance;
private static ServiceTask currentTask = null;
@ -49,12 +51,11 @@ public class RileyLinkMedtronicService extends RileyLinkService {
public RileyLinkMedtronicService() {
super(MainApp.instance().getApplicationContext());
super();
instance = this;
if (isLogEnabled())
LOG.debug("RileyLinkMedtronicService newly constructed");
aapsLogger.debug(LTag.PUMPCOMM, "RileyLinkMedtronicService newly constructed");
MedtronicUtil.setMedtronicService(this);
pumpStatus = (MedtronicPumpStatus) MedtronicPumpPlugin.getPlugin().getPumpStatusData();
pumpStatus = (MedtronicPumpStatus) medtronicPumpPlugin.getPumpStatusData();
}
@ -70,8 +71,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
@Override
public void onConfigurationChanged(Configuration newConfig) {
if (isLogEnabled())
LOG.warn("onConfigurationChanged");
aapsLogger.warn(LTag.PUMPCOMM, "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
}
@ -98,10 +98,10 @@ public class RileyLinkMedtronicService extends RileyLinkService {
RileyLinkUtil.setRileyLinkServiceData(rileyLinkServiceData);
RileyLinkUtil.setTargetDevice(RileyLinkTargetDevice.MedtronicPump);
setPumpIDString(SP.getString(MedtronicConst.Prefs.PumpSerial, "000000"));
setPumpIDString(sp.getString(MedtronicConst.Prefs.PumpSerial, "000000"));
// get most recently used RileyLink address
rileyLinkServiceData.rileylinkAddress = SP.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rileyLinkBLE = new RileyLinkBLE(this.context); // or this
rfspy = new RFSpy(rileyLinkBLE);
@ -127,29 +127,29 @@ public class RileyLinkMedtronicService extends RileyLinkService {
public void setPumpIDString(String pumpID) {
if (pumpID.length() != 6) {
LOG.error("setPumpIDString: invalid pump id string: " + pumpID);
aapsLogger.error("setPumpIDString: invalid pump id string: " + pumpID);
return;
}
byte[] pumpIDBytes = ByteUtil.fromHexString(pumpID);
if (pumpIDBytes == null) {
LOG.error("Invalid pump ID? - PumpID is null.");
aapsLogger.error("Invalid pump ID? - PumpID is null.");
rileyLinkServiceData.setPumpID("000000", new byte[]{0, 0, 0});
} else if (pumpIDBytes.length != 3) {
LOG.error("Invalid pump ID? " + ByteUtil.shortHexString(pumpIDBytes));
aapsLogger.error("Invalid pump ID? " + ByteUtil.shortHexString(pumpIDBytes));
rileyLinkServiceData.setPumpID("000000", new byte[]{0, 0, 0});
} else if (pumpID.equals("000000")) {
LOG.error("Using pump ID " + pumpID);
aapsLogger.error("Using pump ID " + pumpID);
rileyLinkServiceData.setPumpID(pumpID, new byte[]{0, 0, 0});
} else {
LOG.info("Using pump ID " + pumpID);
aapsLogger.info(LTag.PUMPBTCOMM, "Using pump ID " + pumpID);
String oldId = rileyLinkServiceData.pumpID;
@ -198,9 +198,4 @@ public class RileyLinkMedtronicService extends RileyLinkService {
@Override
public void registerDeviceSpecificBroadcasts(IntentFilter intentFilter) {
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPCOMM);
}
}

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
@ -41,6 +42,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpSta
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/**
* Created by andy on 5/9/18.
@ -227,26 +229,26 @@ public class MedtronicUtil extends RileyLinkUtil {
}
public static void sendNotification(MedtronicNotificationType notificationType) {
public static void sendNotification(MedtronicNotificationType notificationType, ResourceHelper resourceHelper, RxBusWrapper rxBus) {
Notification notification = new Notification( //
notificationType.getNotificationType(), //
MainApp.gs(notificationType.getResourceId()), //
resourceHelper.gs(notificationType.getResourceId()), //
notificationType.getNotificationUrgency());
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
rxBus.send(new EventNewNotification(notification));
}
public static void sendNotification(MedtronicNotificationType notificationType, Object... parameters) {
public static void sendNotification(MedtronicNotificationType notificationType, ResourceHelper resourceHelper, RxBusWrapper rxBus, Object... parameters) {
Notification notification = new Notification( //
notificationType.getNotificationType(), //
MainApp.gs(notificationType.getResourceId(), parameters), //
resourceHelper.gs(notificationType.getResourceId(), parameters), //
notificationType.getNotificationUrgency());
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
rxBus.send(new EventNewNotification(notification));
}
public static void dismissNotification(MedtronicNotificationType notificationType) {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(notificationType.getNotificationType()));
public static void dismissNotification(MedtronicNotificationType notificationType, RxBusWrapper rxBus) {
rxBus.send(new EventDismissNotification(notificationType.getNotificationType()));
}

View file

@ -176,9 +176,9 @@ public class DateUtil {
return dateString(mills) + " " + timeFullString(mills);
}
public static String minAgo(long time) {
public static String minAgo(ResourceHelper resourceHelper, long time) {
int mins = (int) ((now() - time) / 1000 / 60);
return MainApp.gs(R.string.minago, mins);
return resourceHelper.gs(R.string.minago, mins);
}
public static String minAgoShort(long time) {