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 {
String regexSN = "[0-9]{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));
//MedtronicHistoryData.doubleBolusDebug = bolusDebug;
reconfigureService();
reconfigureService(forceRileyLinkAddressRenewal);
return true;
@ -327,7 +327,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
}
}
private boolean reconfigureService() {
private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) {
if (!inPreInit) {
@ -336,7 +336,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
serialChanged = false;
}
if (rileyLinkAddressChanged) {
if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false;
}
@ -380,6 +380,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
public boolean setNotInPreInit() {
this.inPreInit = false;
return reconfigureService();
return reconfigureService(false);
}
}

View file

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

View file

@ -79,6 +79,8 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
private String actionTitleStart, actionTitleStop;
private MenuItem menuItem;
private boolean rlDisconnected;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -106,7 +108,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump();
rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address
rileyLinkPump.getRileyLinkService().verifyConfiguration(true); // force reloading of address
rileyLinkPump.triggerPumpConfigurationChangedEvent();
finish();
@ -115,10 +117,12 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
toolbarBTScan = findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
setSupportActionBar(toolbarBTScan);
prepareForScanning();
}
@Override protected void onResume() {
super.onResume();
prepareForScanning();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@ -138,6 +142,10 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
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);
return true;
} 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);
if (checkOK) {
@ -158,9 +179,6 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity {
filters = Collections.singletonList(new ScanFilter.Builder().setServiceUuid(
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,8 +151,8 @@ public class RileyLinkBLE {
} else if ((newState == BluetoothProfile.STATE_CONNECTING) || //
(newState == BluetoothProfile.STATE_DISCONNECTING)) {
aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
"Disconnecting");
aapsLogger.debug(LTag.PUMPBTCOMM, "We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" :
"Disconnecting");
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected, context);
if (manualDisconnect)
@ -392,6 +392,9 @@ public class RileyLinkBLE {
if (gattDebugEnabled) {
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 info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
import info.nightscout.androidaps.plugins.pump.common.R;
import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface;
@ -66,50 +65,14 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity {
RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter
.getItem(tabLayout.getSelectedTabPosition());
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.configuredAddress = findViewById(R.id.rls_t1_configured_address);
this.connectedDevice = findViewById(R.id.rls_t1_connected_device);
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) {
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

View file

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

View file

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