Merge pull request #242 from paulplant/disconnect-confirm

Disconnect confirm
This commit is contained in:
Johan Degraeve 2021-06-04 15:55:15 +02:00 committed by GitHub
commit 1b0903c2d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 19 deletions

View File

@ -85,3 +85,6 @@
/// when M5Stack is shown, title of the cell with the address
"address" = "Adresse:";
"confirmDisconnectTitle" = "Verbindung trennen";
"confirmDisconnectMessage" = "Klicke 'Verbindung trennen' um zu bestätigen, dass du die Verbindung zum Transmitter wirklich beenden möchtest.";

View File

@ -27,3 +27,5 @@
"transmitterResultResult" = "Transmitter Reset Result";
"bootLoader" = "Bootloader";
"cannotActiveCGMInFollowerMode" = "You can not activate a CGM in Follower Mode";
"confirmDisconnectTitle" = "Confirm Disconnect";
"confirmDisconnectMessage" = "Click 'Disconnect' to confirm that you really want to disconnect from the transmitter.";

View File

@ -27,3 +27,5 @@
"bootLoader" = "Bootloader";
"cannotActiveCGMInFollowerMode" = "No puedes añadir un transmisor MGC estando en modo Follower/Seguidor";
"sensorType" = "Tipo de Sensor:";
"confirmDisconnectTitle" = "Confirmar Desconexión";
"confirmDisconnectMessage" = "Haz click en 'Desconectar' para confirmar que deseas desconectar el transmisor.";

View File

@ -27,6 +27,6 @@
"bootLoader" = "Bootloader";
"cannotActiveCGMInFollowerMode" = "Vous ne pouvez pas activer le capteur en mode Suiveur";
"cgmDeActivateBecauseMovingToFollowerMode" = "Le capteur a été désactivé en raison d'un passage en mode Suiveur";
/// BluetoothPeripheral view, text of the cell with the sensor type (only used for Libre)
"sensorType" = "Type de capteur:";
"confirmDisconnectTitle" = "Confirmer la déconnexion";
"confirmDisconnectMessage" = "Sélectionner 'Déconnecter' pour confirmer que vous voulez vraiment déconnecter le transmetteur.";

View File

@ -30,3 +30,5 @@
/// The English word Bootloader does not have a sufficient Dutch translation.
/// [Wikipedia (Bootloader)](https://nl.wikipedia.org/wiki/Bootloader)
"bootLoader" = "Bootloader";
"confirmDisconnectTitle" = "Bevestig Loskoppelen";
"confirmDisconnectMessage" = "Klik 'Loskoppelen' om te bevestigen dat je de zender wil loskoppelen.";

View File

@ -27,3 +27,5 @@
"transmitterResultResult" = "Sändaråterställningsresultat";
"bootLoader" = "'Bootloader'";
"cannotActiveCGMInFollowerMode" = "Du kan inte aktivera en CGM medan du är i följarläge";
"confirmDisconnectTitle" = "Bekräfta frånkoppling";
"confirmDisconnectMessage" = "Klicka 'Koppla från' för att bekräfta att du verkligen vill koppla från sändaren.";

View File

@ -116,4 +116,12 @@ class Texts_BluetoothPeripheralView {
return NSLocalizedString("cannotActiveCGMInFollowerMode", tableName: filename, bundle: Bundle.main, value: "You can not activate a CGM in follower mode", comment: "User tries to add a CGM or connect an already existing CGM, while in follower mode.")
}()
static let confirmDisconnectTitle: String = {
return NSLocalizedString("confirmDisconnectTitle", tableName: filename, bundle: Bundle.main, value: "Confirm Disconnect", comment: "Disconnect transmitter, title")
}()
static let confirmDisconnectMessage: String = {
return NSLocalizedString("confirmDisconnectMessage", tableName: filename, bundle: Bundle.main, value: "Click 'Disconnect' to confirm that you really want to disconnect from the transmitter.", comment: "Confirm that the user wants to really disconnect the transmitter, title")
}()
}

View File

@ -215,24 +215,45 @@ class BluetoothPeripheralViewController: UIViewController {
guard let bluetoothPeripheralManager = bluetoothPeripheralManager else {return}
// device should not automaticaly connect in future, which means, each time the app restarts, it will not try to connect to this bluetoothPeripheral
bluetoothPeripheral.blePeripheral.shouldconnect = false
// save in coredata
coreDataManager?.saveChanges()
// connect button label text needs to change because shouldconnect value has changed
_ = BluetoothPeripheralViewController.setConnectButtonLabelTextAndGetStatusDetailedText(bluetoothPeripheral: bluetoothPeripheral, isScanning: isScanning, connectButtonOutlet: connectButtonOutlet, expectedBluetoothPeripheralType: expectedBluetoothPeripheralType, transmitterId: transmitterIdTempValue, bluetoothPeripheralManager: bluetoothPeripheralManager as! BluetoothPeripheralManager)
// this will set bluetoothTransmitter to nil which will result in disconnecting also
bluetoothPeripheralManager.setBluetoothTransmitterToNil(forBluetoothPeripheral: bluetoothPeripheral)
// as transmitter is now set to nil, call again configure. Maybe not necessary, but it can't hurt
bluetoothPeripheralViewModel?.configure(bluetoothPeripheral: bluetoothPeripheral, bluetoothPeripheralManager: bluetoothPeripheralManager, tableView: tableView, bluetoothPeripheralViewController: self)
// delegate doesn't work here anymore, because the delegate is set to zero, so reset the row with the connection status by calling reloadRows
tableView.reloadRows(at: [IndexPath(row: Setting.connectionStatus.rawValue, section: 0)], with: .none)
// create uialertcontroller to ask the user if they really want to disconnect
let confirmDisconnectAlertController = UIAlertController(title: Texts_BluetoothPeripheralView.confirmDisconnectTitle , message: Texts_BluetoothPeripheralView.confirmDisconnectMessage, preferredStyle: .alert)
// create buttons for uialertcontroller
let OKAction = UIAlertAction(title: Texts_BluetoothPeripheralView.disconnect, style: .default) {
(action:UIAlertAction!) in
// device should not automaticaly connect in future, which means, each time the app restarts, it will not try to connect to this bluetoothPeripheral
bluetoothPeripheral.blePeripheral.shouldconnect = false
// save in coredata
self.coreDataManager?.saveChanges()
// connect button label text needs to change because shouldconnect value has changed
_ = BluetoothPeripheralViewController.setConnectButtonLabelTextAndGetStatusDetailedText(bluetoothPeripheral: bluetoothPeripheral, isScanning: self.isScanning, connectButtonOutlet: self.connectButtonOutlet, expectedBluetoothPeripheralType: self.expectedBluetoothPeripheralType, transmitterId: self.transmitterIdTempValue, bluetoothPeripheralManager: bluetoothPeripheralManager as! BluetoothPeripheralManager)
// this will set bluetoothTransmitter to nil which will result in disconnecting also
bluetoothPeripheralManager.setBluetoothTransmitterToNil(forBluetoothPeripheral: bluetoothPeripheral)
// as transmitter is now set to nil, call again configure. Maybe not necessary, but it can't hurt
self.bluetoothPeripheralViewModel?.configure(bluetoothPeripheral: bluetoothPeripheral, bluetoothPeripheralManager: bluetoothPeripheralManager, tableView: self.tableView, bluetoothPeripheralViewController: self)
// delegate doesn't work here anymore, because the delegate is set to zero, so reset the row with the connection status by calling reloadRows
self.tableView.reloadRows(at: [IndexPath(row: Setting.connectionStatus.rawValue, section: 0)], with: .none)
}
// create a cancel button. If the user clicks it then we will just return directly
let cancelAction = UIAlertAction(title: Texts_Common.Cancel, style: .cancel) {
(action:UIAlertAction!) in
}
// add buttons to the alert
confirmDisconnectAlertController.addAction(OKAction)
confirmDisconnectAlertController.addAction(cancelAction)
// show alert
present(confirmDisconnectAlertController, animated: true, completion:nil)
}
/// the BluetoothPeripheralViewController has already a few sections defined (eg bluetooth, weboop). This is the amount of sections defined in BluetoothPeripheralViewController.