Created callFunctionAndShareFile at SettingsSelectedRowAction.

Created and implemented a new SettingsSelectedRowAction: callFunctionAndShareFile.
This commit is contained in:
eduardopietre 2022-05-08 12:48:11 -03:00
parent 22bba1c37e
commit 7c1a4efa84
2 changed files with 25 additions and 0 deletions

View File

@ -34,6 +34,11 @@ enum SettingsSelectedRowAction {
///
/// example, the chosen unit, is either mgdl or mmol. When user clicks, there's no need to show pop up with the two options. Just switch immediately. The function would do that in this case (ie change the setting)
case callFunction(function :(() -> Void))
/// when clicked, the function parameter needs to be called
/// but takes as argument a callback that when called returns an optional URL,
/// that if not nil the user should be presented with a share menu.
case callFunctionAndShareFile(function: ((_ callback: @escaping ((_ file: URL?) -> Void)) -> Void))
/// when clicked a list of items must be presented form which the user needs to pick one, for example transmitter type
/// - title: title that can be shown when asking for input

View File

@ -100,6 +100,26 @@ class SettingsViewUtilities {
// check if refresh is needed, either complete settingsview or individual section
self.checkIfReloadNeededAndReloadIfNeeded(tableView: tableView, viewModel: settingsViewModel, rowIndex: rowIndex, sectionIndex: sectionIndex)
case let .callFunctionAndShareFile(function):
// call function and in the callback present the share file menu.
function({ fileURL in
if let fileURL = fileURL {
// UI Code must be done at main thread.
DispatchQueue.main.async {
// Present the user with a share file menu.
let activityViewController = UIActivityViewController(activityItems: [fileURL], applicationActivities: [])
uIViewController.present(activityViewController, animated: true)
}
} else {
// TODO: add trace
}
})
// check if refresh is needed, either complete settingsview or individual section
self.checkIfReloadNeededAndReloadIfNeeded(tableView: tableView, viewModel: settingsViewModel, rowIndex: rowIndex, sectionIndex: sectionIndex)
case let .selectFromList(title, data, selectedRow, actionTitle, cancelTitle, actionHandler, cancelHandler, didSelectRowHandler):