Workarounds for some bugs in RL scanning UI

This commit is contained in:
Bart Sopers 2020-12-25 02:05:37 +01:00
parent 1e3ea8f74f
commit f596348d85
7 changed files with 46 additions and 61 deletions

View file

@ -180,7 +180,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
} }
public boolean verifyConfiguration() { public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) {
try { try {
String regexSN = "[0-9]{6}"; String regexSN = "[0-9]{6}";
String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}"; String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
@ -316,7 +316,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
//boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(resourceHelper.gs(R.string.common_on)); //boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(resourceHelper.gs(R.string.common_on));
//MedtronicHistoryData.doubleBolusDebug = bolusDebug; //MedtronicHistoryData.doubleBolusDebug = bolusDebug;
reconfigureService(); reconfigureService(forceRileyLinkAddressRenewal);
return true; return true;
@ -327,7 +327,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
} }
} }
private boolean reconfigureService() { private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) {
if (!inPreInit) { if (!inPreInit) {
@ -336,7 +336,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
serialChanged = false; serialChanged = false;
} }
if (rileyLinkAddressChanged) { if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false; rileyLinkAddressChanged = false;
} }
@ -380,6 +380,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
public boolean setNotInPreInit() { public boolean setNotInPreInit() {
this.inPreInit = false; this.inPreInit = false;
return reconfigureService(); return reconfigureService(false);
} }
} }

View file

@ -109,7 +109,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
} }
@Override @Override
public boolean verifyConfiguration() { public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) {
try { try {
errorDescription = null; errorDescription = null;
@ -133,7 +133,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
rileyLinkServiceData.rileyLinkTargetFrequency = RileyLinkTargetFrequency.Omnipod; rileyLinkServiceData.rileyLinkTargetFrequency = RileyLinkTargetFrequency.Omnipod;
reconfigureService(); reconfigureService(forceRileyLinkAddressRenewal);
return true; return true;
@ -144,9 +144,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
} }
} }
private boolean reconfigureService() { private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) {
if (!inPreInit) { if (!inPreInit) {
if (rileyLinkAddressChanged) { if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false; rileyLinkAddressChanged = false;
} }
@ -158,6 +158,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
public boolean setNotInPreInit() { public boolean setNotInPreInit() {
this.inPreInit = false; this.inPreInit = false;
return reconfigureService(); return reconfigureService(false);
} }
} }

View file

@ -79,6 +79,8 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
private String actionTitleStart, actionTitleStop; private String actionTitleStart, actionTitleStop;
private MenuItem menuItem; private MenuItem menuItem;
private boolean rlDisconnected;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -106,7 +108,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress); sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump(); RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump();
rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address rileyLinkPump.getRileyLinkService().verifyConfiguration(true); // force reloading of address
rileyLinkPump.triggerPumpConfigurationChangedEvent(); rileyLinkPump.triggerPumpConfigurationChangedEvent();
finish(); finish();
@ -115,10 +117,12 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
toolbarBTScan = findViewById(R.id.rileylink_toolbarBTScan); toolbarBTScan = findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan.setTitle(R.string.rileylink_scanner_title); toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
setSupportActionBar(toolbarBTScan); setSupportActionBar(toolbarBTScan);
prepareForScanning();
} }
@Override protected void onResume() {
super.onResume();
prepareForScanning();
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
@ -138,6 +142,10 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getTitle().equals(actionTitleStart)) { if (item.getTitle().equals(actionTitleStart)) {
// disable currently selected RL, so that we can discover it
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect, this);
rlDisconnected = true;
scanLeDevice(true); scanLeDevice(true);
return true; return true;
} else if (item.getTitle().equals(actionTitleStop)) { } else if (item.getTitle().equals(actionTitleStop)) {
@ -148,8 +156,21 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
} }
} }
@Override public void onBackPressed() {
super.onBackPressed();
if (rlDisconnected) {
// Reconnect RL if it was disconnected for the scan
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
}
}
public void prepareForScanning() { @Override protected void onDestroy() {
super.onDestroy();
mScanning = false;
mLEScanner.stopScan(mScanCallback2);
}
private void prepareForScanning() {
boolean checkOK = blePrecheck.prerequisitesCheck(this); boolean checkOK = blePrecheck.prerequisitesCheck(this);
if (checkOK) { if (checkOK) {
@ -158,9 +179,6 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
filters = Collections.singletonList(new ScanFilter.Builder().setServiceUuid( filters = Collections.singletonList(new ScanFilter.Builder().setServiceUuid(
ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build());
} }
// disable currently selected RL, so that we can discover it
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect, this);
} }

View file

@ -151,7 +151,7 @@ public class RileyLinkBLE {
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || // } else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
(newState == BluetoothProfile.STATE_DISCONNECTING)) { (newState == BluetoothProfile.STATE_DISCONNECTING)) {
aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : aapsLogger.debug(LTag.PUMPBTCOMM, "We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
"Disconnecting"); "Disconnecting");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) { } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected, context); rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected, context);
@ -392,6 +392,9 @@ public class RileyLinkBLE {
if (gattDebugEnabled) { if (gattDebugEnabled) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Gatt Connected."); aapsLogger.debug(LTag.PUMPBTCOMM, "Gatt Connected.");
} }
rileyLinkServiceData.rileylinkAddress = bluetoothConnectionGatt.getDevice().getAddress();
rileyLinkServiceData.rileyLinkName = bluetoothConnectionGatt.getDevice().getName();
} }
} }

View file

@ -16,7 +16,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.common.R; import info.nightscout.androidaps.plugins.pump.common.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
@ -66,50 +65,14 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter
.getItem(tabLayout.getSelectedTabPosition()); .getItem(tabLayout.getSelectedTabPosition());
selectableInterface.refreshData(); selectableInterface.refreshData();
// refreshData(tabLayout.getSelectedTabPosition());
// Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(),
// Toast.LENGTH_LONG);
}); });
this.connectionStatus = findViewById(R.id.rls_t1_connection_status); this.connectionStatus = findViewById(R.id.rls_t1_connection_status);
this.configuredAddress = findViewById(R.id.rls_t1_configured_address); this.configuredAddress = findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = findViewById(R.id.rls_t1_connected_device); this.connectedDevice = findViewById(R.id.rls_t1_connected_device);
this.connectionError = findViewById(R.id.rls_t1_connection_error); this.connectionError = findViewById(R.id.rls_t1_connection_error);
// // 7-12
// int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, //
// R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12};
//
// for (int id : ids) {
//
// TextView tv = (TextView) findViewById(id);
// tv.setText(tv.getText() + ":");
// }
// refreshData(0);
// refreshData(1);
} }
public void refreshData(int position) {
if (position == 0) {
// FIXME i18n
this.connectionStatus.setText(rileyLinkServiceData.rileyLinkServiceState.name());
this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress);
// FIXME
this.connectedDevice.setText("???");
// FIXME i18n
this.connectionError.setText(rileyLinkServiceData.rileyLinkError.name());
} else {
}
}
public void setupViewPager(ViewPager pager) { public void setupViewPager(ViewPager pager) {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

View file

@ -139,7 +139,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
} else { } else {
rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled); rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled);
} }
rileyLinkServiceData.rileyLinkName = null;
return true; return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) { } else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) {
@ -170,7 +169,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
return true; return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) { } else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) {
String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rileyLinkServiceData.rileyLinkName = null;
if (RileylinkBLEAddress.equals("")) { if (RileylinkBLEAddress.equals("")) {
aapsLogger.error("No Rileylink BLE Address saved in app"); aapsLogger.error("No Rileylink BLE Address saved in app");
} else { } else {
@ -183,8 +181,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver {
return true; return true;
} else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) { } else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) {
rileyLinkService.disconnectRileyLink(); rileyLinkService.disconnectRileyLink();
rileyLinkServiceData.rileyLinkName = null;
return true; return true;
} else { } else {
return false; return false;

View file

@ -230,6 +230,7 @@ public abstract class RileyLinkService extends DaggerService {
if (rileyLinkBLE.isConnected()) { if (rileyLinkBLE.isConnected()) {
rileyLinkBLE.disconnect(); rileyLinkBLE.disconnect();
rileyLinkServiceData.rileylinkAddress = null; rileyLinkServiceData.rileylinkAddress = null;
rileyLinkServiceData.rileyLinkName = null;
} }
rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothReady); rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothReady);
@ -260,5 +261,9 @@ public abstract class RileyLinkService extends DaggerService {
return null; return null;
} }
public abstract boolean verifyConfiguration(); public boolean verifyConfiguration() {
return verifyConfiguration(false);
}
public abstract boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal);
} }