MDT refactor pass 17

This commit is contained in:
Milos Kozak 2020-04-27 23:02:12 +02:00
parent 52e0e3ec51
commit 1b21b74878
15 changed files with 116 additions and 154 deletions

View file

@ -37,6 +37,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyL
import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightFragment
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment
import info.nightscout.androidaps.plugins.pump.medtronic.dialog.RileyLinkStatusDeviceMedtronic
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpFragment
import info.nightscout.androidaps.plugins.source.BGSourceFragment
import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment
@ -118,4 +119,5 @@ abstract class FragmentsModule {
@ContributesAndroidInjector abstract fun contributesRileyLinkStatusGeneral(): RileyLinkStatusGeneralFragment
@ContributesAndroidInjector abstract fun contributesRileyLinkStatusHistoryFragment(): RileyLinkStatusHistoryFragment
@ContributesAndroidInjector abstract fun contributesRileyLinkStatusDeviceMedtronic(): RileyLinkStatusDeviceMedtronic
}

View file

@ -37,7 +37,6 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewB
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
import info.nightscout.androidaps.plugins.treatments.Treatment;
@ -109,8 +108,11 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
public abstract void initPumpStatusData();
public abstract void resetRileyLinkConfiguration();
public abstract void doTuneUpDevice();
public abstract RileyLinkService getRileyLinkService();
@Override
@ -446,7 +448,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
public ManufacturerType manufacturer() {
return pumpType.getManufacturer() ;
return pumpType.getManufacturer();
}
@NotNull

View file

@ -32,8 +32,8 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by geoff on 5/26/16.
@ -65,7 +65,7 @@ public class RFSpy {
injector.androidInjector().inject(this);
this.injector = injector;
this.rileyLinkBle = rileyLinkBle;
reader = new RFSpyReader(rileyLinkBle);
reader = new RFSpyReader(aapsLogger, rileyLinkBle);
}
public String getBLEVersionCached() {

View file

@ -1,19 +1,15 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble;
import android.os.AsyncTask;
import android.os.SystemClock;
import java.util.UUID;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.os.AsyncTask;
import android.os.SystemClock;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.BLECommOperationResult;
@ -25,7 +21,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
*/
public class RFSpyReader {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM);
private final AAPSLogger aapsLogger;
private static AsyncTask<Void, Void, Void> readerTask;
private RileyLinkBLE rileyLinkBle;
private Semaphore waitForRadioData = new Semaphore(0, true);
@ -35,13 +31,9 @@ public class RFSpyReader {
private boolean stopAtNull = true;
public RFSpyReader(RileyLinkBLE rileyLinkBle) {
RFSpyReader(AAPSLogger aapsLogger, RileyLinkBLE rileyLinkBle) {
this.rileyLinkBle = rileyLinkBle;
}
public void init(RileyLinkBLE rileyLinkBLE) {
this.rileyLinkBle = rileyLinkBLE;
this.aapsLogger = aapsLogger;
}
@ -52,16 +44,15 @@ public class RFSpyReader {
this.rileyLinkBle = rileyLinkBle;
}
public void setRileyLinkEncodingType(RileyLinkEncodingType encodingType) {
void setRileyLinkEncodingType(RileyLinkEncodingType encodingType) {
stopAtNull = !(encodingType == RileyLinkEncodingType.Manchester || //
encodingType == RileyLinkEncodingType.FourByteSixByteRileyLink);
}
// This timeout must be coordinated with the length of the RFSpy radio operation or Bad Things Happen.
public byte[] poll(int timeout_ms) {
if (isLogEnabled())
LOG.trace(ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
byte[] poll(int timeout_ms) {
aapsLogger.debug(LTag.PUMPBTCOMM, ThreadUtil.sig() + "Entering poll at t==" + SystemClock.uptimeMillis() + ", timeout is " + timeout_ms
+ " mDataQueue size is " + mDataQueue.size());
if (mDataQueue.isEmpty()) {
@ -70,16 +61,14 @@ public class RFSpyReader {
// returns null if timeout.
byte[] dataFromQueue = mDataQueue.poll(timeout_ms, TimeUnit.MILLISECONDS);
if (dataFromQueue != null) {
if (isLogEnabled())
LOG.debug("Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t=="
+ SystemClock.uptimeMillis());
aapsLogger.debug(LTag.PUMPBTCOMM, "Got data [" + ByteUtil.shortHexString(dataFromQueue) + "] at t=="
+ SystemClock.uptimeMillis());
} else {
if (isLogEnabled())
LOG.debug("Got data [null] at t==" + SystemClock.uptimeMillis());
aapsLogger.debug(LTag.PUMPBTCOMM, "Got data [null] at t==" + SystemClock.uptimeMillis());
}
return dataFromQueue;
} catch (InterruptedException e) {
LOG.error("poll: Interrupted waiting for data");
aapsLogger.error(LTag.PUMPBTCOMM, "poll: Interrupted waiting for data");
}
}
@ -88,11 +77,10 @@ public class RFSpyReader {
// Call this from the "response count" notification handler.
public void newDataIsAvailable() {
void newDataIsAvailable() {
releaseCount++;
if (isLogEnabled())
LOG.trace(ThreadUtil.sig() + "waitForRadioData released(count=" + releaseCount + ") at t="
aapsLogger.debug(LTag.PUMPBTCOMM, ThreadUtil.sig() + "waitForRadioData released(count=" + releaseCount + ") at t="
+ SystemClock.uptimeMillis());
waitForRadioData.release();
}
@ -110,8 +98,7 @@ public class RFSpyReader {
try {
acquireCount++;
waitForRadioData.acquire();
if (isLogEnabled())
LOG.trace(ThreadUtil.sig() + "waitForRadioData acquired (count=" + acquireCount + ") at t="
aapsLogger.debug(LTag.PUMPBTCOMM, ThreadUtil.sig() + "waitForRadioData acquired (count=" + acquireCount + ") at t="
+ SystemClock.uptimeMillis());
SystemClock.sleep(100);
SystemClock.sleep(1);
@ -130,24 +117,19 @@ public class RFSpyReader {
}
mDataQueue.add(result.value);
} else if (result.resultCode == BLECommOperationResult.RESULT_INTERRUPTED) {
LOG.error("Read operation was interrupted");
aapsLogger.error(LTag.PUMPBTCOMM, "Read operation was interrupted");
} else if (result.resultCode == BLECommOperationResult.RESULT_TIMEOUT) {
LOG.error("Read operation on Radio Data timed out");
aapsLogger.error(LTag.PUMPBTCOMM, "Read operation on Radio Data timed out");
} else if (result.resultCode == BLECommOperationResult.RESULT_BUSY) {
LOG.error("FAIL: RileyLinkBLE reports operation already in progress");
aapsLogger.error(LTag.PUMPBTCOMM, "FAIL: RileyLinkBLE reports operation already in progress");
} else if (result.resultCode == BLECommOperationResult.RESULT_NONE) {
LOG.error("FAIL: got invalid result code: " + result.resultCode);
aapsLogger.error(LTag.PUMPBTCOMM, "FAIL: got invalid result code: " + result.resultCode);
}
} catch (InterruptedException e) {
LOG.error("Interrupted while waiting for data");
aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for data");
}
}
}
}.execute();
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPBTCOMM);
}
}

View file

@ -47,8 +47,8 @@ public class RileyLinkBLE {
@Inject RileyLinkUtil rileyLinkUtil;
private final Context context;
public boolean gattDebugEnabled = true;
boolean manualDisconnect = false;
private boolean gattDebugEnabled = true;
private boolean manualDisconnect = false;
private BluetoothAdapter bluetoothAdapter;
private BluetoothGattCallback bluetoothGattCallback;
private BluetoothDevice rileyLinkDevice;
@ -447,7 +447,7 @@ public class RileyLinkBLE {
}
BluetoothGattDescriptor descr = list.get(0);
// Tell the remote device to send the notifications
mCurrentOperation = new DescriptorWriteOperation(bluetoothConnectionGatt, descr,
mCurrentOperation = new DescriptorWriteOperation(aapsLogger, bluetoothConnectionGatt, descr,
BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
@ -496,7 +496,7 @@ public class RileyLinkBLE {
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID)
.getCharacteristic(charaUUID);
mCurrentOperation = new CharacteristicWriteOperation(bluetoothConnectionGatt, chara, value);
mCurrentOperation = new CharacteristicWriteOperation(aapsLogger, bluetoothConnectionGatt, chara, value);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT;
@ -538,7 +538,7 @@ public class RileyLinkBLE {
} else {
BluetoothGattCharacteristic chara = bluetoothConnectionGatt.getService(serviceUUID).getCharacteristic(
charaUUID);
mCurrentOperation = new CharacteristicReadOperation(bluetoothConnectionGatt, chara);
mCurrentOperation = new CharacteristicReadOperation(aapsLogger, bluetoothConnectionGatt, chara);
mCurrentOperation.execute(this);
if (mCurrentOperation.timedOut) {
rval.resultCode = BLECommOperationResult.RESULT_TIMEOUT;

View file

@ -1,17 +1,14 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.SystemClock;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
@ -20,12 +17,13 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.Gatt
*/
public class CharacteristicReadOperation extends BLECommOperation {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM);
private final AAPSLogger aapsLogger;
private BluetoothGattCharacteristic characteristic;
public CharacteristicReadOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara) {
public CharacteristicReadOperation(AAPSLogger aapsLogger, BluetoothGatt gatt, BluetoothGattCharacteristic chara) {
this.aapsLogger = aapsLogger;
this.gatt = gatt;
this.characteristic = chara;
}
@ -39,15 +37,14 @@ public class CharacteristicReadOperation extends BLECommOperation {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) {
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
// understanding of the sequence of events.
// understanding of the sequence of events.
// success
} else {
LOG.error("Timeout waiting for gatt write operation to complete");
aapsLogger.error(LTag.PUMPBTCOMM, "Timeout waiting for gatt write operation to complete");
timedOut = true;
}
} catch (InterruptedException e) {
if (isLogEnabled())
LOG.error("Interrupted while waiting for gatt write operation to complete");
aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for gatt write operation to complete");
interrupted = true;
}
value = characteristic.getValue();
@ -58,15 +55,10 @@ public class CharacteristicReadOperation extends BLECommOperation {
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
super.gattOperationCompletionCallback(uuid, value);
if (!characteristic.getUuid().equals(uuid)) {
LOG.error(String.format(
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
aapsLogger.error(LTag.PUMPCOMM, String.format(
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
}
operationComplete.release();
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPBTCOMM);
}
}

View file

@ -1,17 +1,14 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.os.SystemClock;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes;
@ -20,12 +17,13 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.Gatt
*/
public class CharacteristicWriteOperation extends BLECommOperation {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPBTCOMM);
private final AAPSLogger aapsLogger;
private BluetoothGattCharacteristic characteristic;
public CharacteristicWriteOperation(BluetoothGatt gatt, BluetoothGattCharacteristic chara, byte[] value) {
public CharacteristicWriteOperation(AAPSLogger aapsLogger, BluetoothGatt gatt, BluetoothGattCharacteristic chara, byte[] value) {
this.aapsLogger = aapsLogger;
this.gatt = gatt;
this.characteristic = chara;
this.value = value;
@ -42,14 +40,14 @@ public class CharacteristicWriteOperation extends BLECommOperation {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) {
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
// understanding of the sequence of events.
// understanding of the sequence of events.
// success
} else {
LOG.error("Timeout waiting for gatt write operation to complete");
aapsLogger.error(LTag.PUMPBTCOMM, "Timeout waiting for gatt write operation to complete");
timedOut = true;
}
} catch (InterruptedException e) {
LOG.error("Interrupted while waiting for gatt write operation to complete");
aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for gatt write operation to complete");
interrupted = true;
}
@ -60,16 +58,10 @@ public class CharacteristicWriteOperation extends BLECommOperation {
@Override
public void gattOperationCompletionCallback(UUID uuid, byte[] value) {
if (!characteristic.getUuid().equals(uuid)) {
LOG.error(String.format(
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
aapsLogger.error(LTag.PUMPCOMM, String.format(
"Completion callback: UUID does not match! out of sequence? Found: %s, should be %s",
GattAttributes.lookup(characteristic.getUuid()), GattAttributes.lookup(uuid)));
}
operationComplete.release();
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPBTCOMM);
}
}

View file

@ -1,16 +1,14 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattDescriptor;
import android.os.SystemClock;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
/**
@ -18,12 +16,13 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLink
*/
public class DescriptorWriteOperation extends BLECommOperation {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(DescriptorWriteOperation.class);
private final AAPSLogger aapsLogger;
private BluetoothGattDescriptor descr;
public DescriptorWriteOperation(BluetoothGatt gatt, BluetoothGattDescriptor descr, byte[] value) {
public DescriptorWriteOperation(AAPSLogger aapsLogger, BluetoothGatt gatt, BluetoothGattDescriptor descr, byte[] value) {
this.aapsLogger = aapsLogger;
this.gatt = gatt;
this.descr = descr;
this.value = value;
@ -46,14 +45,14 @@ public class DescriptorWriteOperation extends BLECommOperation {
boolean didAcquire = operationComplete.tryAcquire(getGattOperationTimeout_ms(), TimeUnit.MILLISECONDS);
if (didAcquire) {
SystemClock.sleep(1); // This is to allow the IBinder thread to exit before we continue, allowing easier
// understanding of the sequence of events.
// understanding of the sequence of events.
// success
} else {
LOG.error("Timeout waiting for descriptor write operation to complete");
aapsLogger.error(LTag.PUMPBTCOMM, "Timeout waiting for descriptor write operation to complete");
timedOut = true;
}
} catch (InterruptedException e) {
LOG.error("Interrupted while waiting for descriptor write operation to complete");
aapsLogger.error(LTag.PUMPBTCOMM, "Interrupted while waiting for descriptor write operation to complete");
interrupted = true;
}
}

View file

@ -2,12 +2,12 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data;
import org.joda.time.LocalDateTime;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/**
* Created by andy on 5/19/18.
@ -26,7 +26,7 @@ public class RLHistoryItem {
public RLHistoryItem(RileyLinkServiceState serviceState, RileyLinkError errorCode,
RileyLinkTargetDevice targetDevice) {
RileyLinkTargetDevice targetDevice) {
this.targetDevice = targetDevice;
this.dateTime = new LocalDateTime();
this.serviceState = serviceState;
@ -65,16 +65,16 @@ public class RLHistoryItem {
}
public String getDescription() {
public String getDescription(ResourceHelper resourceHelper) {
// TODO extend when we have Omnipod
switch (this.source) {
case RileyLink:
return "State: " + MainApp.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
return "State: " + resourceHelper.gs(serviceState.getResourceId(targetDevice))
+ (this.errorCode == null ? "" : ", Error Code: " + errorCode);
case MedtronicPump:
return MainApp.gs(pumpDeviceState.getResourceId());
return resourceHelper.gs(pumpDeviceState.getResourceId());
case MedtronicCommand:
return medtronicCommandType.name();

View file

@ -1,22 +1,20 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
@ -24,9 +22,9 @@ import info.nightscout.androidaps.R;
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.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/**
* Created by andy on 5/19/18.
@ -35,6 +33,7 @@ import info.nightscout.androidaps.utils.DateUtil;
public class RileyLinkStatusHistoryFragment extends DaggerFragment implements RefreshableInterface {
@Inject RileyLinkUtil rileyLinkUtil;
@Inject ResourceHelper resourceHelper;
RecyclerView recyclerView;
RecyclerViewAdapter recyclerViewAdapter;
@ -50,7 +49,7 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re
recyclerView = (RecyclerView) rootView.findViewById(R.id.rileylink_history_list);
recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(getActivity().getApplicationContext());
llm = new LinearLayoutManager(rootView.getContext());
recyclerView.setLayoutManager(llm);
recyclerViewAdapter = new RecyclerViewAdapter(filteredHistoryList);
@ -76,7 +75,7 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re
}
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder> {
List<RLHistoryItem> historyList;
@ -111,11 +110,11 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re
PumpDeviceState pumpState = item.getPumpDeviceState();
if ((pumpState != null) && //
(pumpState == PumpDeviceState.Sleeping || //
pumpState == PumpDeviceState.Active || //
pumpState == PumpDeviceState.WakingUp //
))
//
if ((pumpState == PumpDeviceState.Sleeping || //
pumpState == PumpDeviceState.Active || //
pumpState == PumpDeviceState.WakingUp //
))
return false;
return true;
@ -139,7 +138,7 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re
if (item != null) {
holder.timeView.setText(DateUtil.dateAndTimeAndSecondsString(item.getDateTime().toDateTime().getMillis()));
holder.typeView.setText(item.getSource().getDesc());
holder.valueView.setText(item.getDescription());
holder.valueView.setText(item.getDescription(resourceHelper));
}
}
@ -155,7 +154,7 @@ public class RileyLinkStatusHistoryFragment extends DaggerFragment implements Re
super.onAttachedToRecyclerView(recyclerView);
}
static class HistoryViewHolder extends RecyclerView.ViewHolder {
class HistoryViewHolder extends RecyclerView.ViewHolder {
TextView timeView;
TextView typeView;

View file

@ -11,8 +11,6 @@ import android.content.IntentFilter;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import org.slf4j.Logger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -23,9 +21,7 @@ import javax.inject.Inject;
import dagger.android.DaggerBroadcastReceiver;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
@ -50,8 +46,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
@Inject RileyLinkServiceData rileyLinkServiceData;
@Inject ServiceTaskExecutor serviceTaskExecutor;
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
RileyLinkService serviceInstance;
protected Map<String, List<String>> broadcastIdentifiers = null;
String deviceSpecificPrefix;
@ -98,11 +92,11 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
super.onReceive(context, intent);
if (intent == null) {
LOG.error("onReceive: received null intent");
aapsLogger.error("onReceive: received null intent");
} else {
String action = intent.getAction();
if (action == null) {
LOG.error("onReceive: null action");
aapsLogger.error("onReceive: null action");
} else {
aapsLogger.debug(LTag.PUMPBTCOMM, "Received Broadcast: " + action);
@ -112,7 +106,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
!processDeviceSpecificBroadcasts(action, intent) && //
!processApplicationSpecificBroadcasts(action, intent) //
) {
LOG.error("Unhandled broadcast: action=" + action);
aapsLogger.error("Unhandled broadcast: action=" + action);
}
}
}
@ -176,7 +170,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
} else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) {
String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
if (RileylinkBLEAddress.equals("")) {
LOG.error("No Rileylink BLE Address saved in app");
aapsLogger.error("No Rileylink BLE Address saved in app");
} else {
// showBusy("Configuring Service", 50);
// rileyLinkBLE.findRileyLink(RileylinkBLEAddress);

View file

@ -4,13 +4,11 @@ import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
/**
* Created by geoff on 7/16/16.

View file

@ -20,14 +20,13 @@ import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
*/
public class DateTimeUtil {
private static final Logger LOG = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
/**
* DateTime is packed as long: yyyymmddHHMMss
*
* @param atechDateTime
* @return
*/
@Deprecated // use joda instead
public static LocalDateTime toLocalDateTime(long atechDateTime) {
int year = (int) (atechDateTime / 10000000000L);
atechDateTime -= year * 10000000000L;
@ -49,8 +48,7 @@ public class DateTimeUtil {
try {
return new LocalDateTime(year, month, dayOfMonth, hourOfDay, minute, second);
} catch (Exception ex) {
if (L.isEnabled(L.PUMPCOMM))
LOG.error("Error creating LocalDateTime from values [atechDateTime={}, year={}, month={}, day={}, hour={}, minute={}, second={}]. Exception: {}", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second, ex.getMessage());
//LOG.error("Error creating LocalDateTime from values [atechDateTime={}, year={}, month={}, day={}, hour={}, minute={}, second={}]. Exception: {}", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second, ex.getMessage());
//return null;
throw ex;
}
@ -63,6 +61,7 @@ public class DateTimeUtil {
* @param atechDateTime
* @return
*/
@Deprecated // use joda instead
public static GregorianCalendar toGregorianCalendar(long atechDateTime) {
int year = (int) (atechDateTime / 10000000000L);
atechDateTime -= year * 10000000000L;
@ -84,8 +83,7 @@ public class DateTimeUtil {
try {
return new GregorianCalendar(year, month - 1, dayOfMonth, hourOfDay, minute, second);
} catch (Exception ex) {
if (L.isEnabled(L.PUMPCOMM))
LOG.error("DateTimeUtil", String.format("Error creating GregorianCalendar from values [atechDateTime=%d, year=%d, month=%d, day=%d, hour=%d, minute=%d, second=%d]", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second));
//LOG.error("DateTimeUtil", String.format("Error creating GregorianCalendar from values [atechDateTime=%d, year=%d, month=%d, day=%d, hour=%d, minute=%d, second=%d]", atechDateTime, year, month, dayOfMonth, hourOfDay, minute, second));
//return null;
throw ex;
}

View file

@ -5,7 +5,6 @@ import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.utils.alertDialogs.OKDialog;
@ -44,7 +43,7 @@ public class LocationHelper {
}
// Shamelessly borrowed from http://stackoverflow.com/a/10311877/868533
OKDialog.showConfirmation(parent, MainApp.gs(R.string.location_not_found_title), MainApp.gs(R.string.location_not_found_message), () -> {
OKDialog.showConfirmation(parent, parent.getString(R.string.location_not_found_title), parent.getString(R.string.location_not_found_message), () -> {
parent.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
});
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.medtronic.dialog;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -12,10 +11,14 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
/**
* Created by andy on 5/19/18.
@ -26,7 +29,9 @@ import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
*/
// TODO needs to be implemented
public class RileyLinkStatusDeviceMedtronic extends Fragment implements RefreshableInterface {
public class RileyLinkStatusDeviceMedtronic extends DaggerFragment implements RefreshableInterface {
@Inject ResourceHelper resourceHelper;
// @BindView(R.id.rileylink_history_list)
ListView listView;
@ -150,7 +155,7 @@ public class RileyLinkStatusDeviceMedtronic extends Fragment implements Refresha
RLHistoryItem item = historyItemList.get(i);
viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime()));
viewHolder.itemSource.setText("Riley Link"); // for now
viewHolder.itemDescription.setText(item.getDescription());
viewHolder.itemDescription.setText(item.getDescription(resourceHelper));
return view;
}