diff --git a/xdrip/View Controllers/Helpers/SettingsSelectedRowAction.swift b/xdrip/View Controllers/Helpers/SettingsSelectedRowAction.swift index 0bc9752b..f7a639f6 100644 --- a/xdrip/View Controllers/Helpers/SettingsSelectedRowAction.swift +++ b/xdrip/View Controllers/Helpers/SettingsSelectedRowAction.swift @@ -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 diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewUtilities.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewUtilities.swift index d47afbef..9917e797 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewUtilities.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewUtilities.swift @@ -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):