CallFunctionAndShareFile now displays a loading icon (ActivityIndicatorViewController).
This commit is contained in:
parent
c9d63fd399
commit
75ec8e89da
|
@ -35,6 +35,7 @@
|
||||||
D4028CC02774A50600341476 /* TreatmentsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4028CBF2774A50600341476 /* TreatmentsViewController.swift */; };
|
D4028CC02774A50600341476 /* TreatmentsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4028CBF2774A50600341476 /* TreatmentsViewController.swift */; };
|
||||||
D40C3DA4277542C400111B73 /* TreatmentEntry+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40C3DA3277542C400111B73 /* TreatmentEntry+CoreDataClass.swift */; };
|
D40C3DA4277542C400111B73 /* TreatmentEntry+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40C3DA3277542C400111B73 /* TreatmentEntry+CoreDataClass.swift */; };
|
||||||
D40C3DA62775438F00111B73 /* TreatmentEntry+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40C3DA52775438F00111B73 /* TreatmentEntry+CoreDataProperties.swift */; };
|
D40C3DA62775438F00111B73 /* TreatmentEntry+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40C3DA52775438F00111B73 /* TreatmentEntry+CoreDataProperties.swift */; };
|
||||||
|
D417E51C282EC8DB008DC467 /* ActivityIndicatorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D417E51B282EC8DB008DC467 /* ActivityIndicatorViewController.swift */; };
|
||||||
D41F32922827240E00861B3D /* SettingsViewHousekeeperSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D41F32912827240E00861B3D /* SettingsViewHousekeeperSettingsViewModel.swift */; };
|
D41F32922827240E00861B3D /* SettingsViewHousekeeperSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D41F32912827240E00861B3D /* SettingsViewHousekeeperSettingsViewModel.swift */; };
|
||||||
D41F32942827332000861B3D /* DataExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D41F32932827332000861B3D /* DataExporter.swift */; };
|
D41F32942827332000861B3D /* DataExporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = D41F32932827332000861B3D /* DataExporter.swift */; };
|
||||||
D482BD942776153F003C4FB2 /* TreatmentsNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D482BD932776153F003C4FB2 /* TreatmentsNavigationController.swift */; };
|
D482BD942776153F003C4FB2 /* TreatmentsNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D482BD932776153F003C4FB2 /* TreatmentsNavigationController.swift */; };
|
||||||
|
@ -728,6 +729,7 @@
|
||||||
D4028CBF2774A50600341476 /* TreatmentsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreatmentsViewController.swift; sourceTree = "<group>"; };
|
D4028CBF2774A50600341476 /* TreatmentsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreatmentsViewController.swift; sourceTree = "<group>"; };
|
||||||
D40C3DA3277542C400111B73 /* TreatmentEntry+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TreatmentEntry+CoreDataClass.swift"; sourceTree = "<group>"; };
|
D40C3DA3277542C400111B73 /* TreatmentEntry+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TreatmentEntry+CoreDataClass.swift"; sourceTree = "<group>"; };
|
||||||
D40C3DA52775438F00111B73 /* TreatmentEntry+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TreatmentEntry+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
D40C3DA52775438F00111B73 /* TreatmentEntry+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TreatmentEntry+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
||||||
|
D417E51B282EC8DB008DC467 /* ActivityIndicatorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityIndicatorViewController.swift; sourceTree = "<group>"; };
|
||||||
D41F32912827240E00861B3D /* SettingsViewHousekeeperSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewHousekeeperSettingsViewModel.swift; sourceTree = "<group>"; };
|
D41F32912827240E00861B3D /* SettingsViewHousekeeperSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewHousekeeperSettingsViewModel.swift; sourceTree = "<group>"; };
|
||||||
D41F32932827332000861B3D /* DataExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExporter.swift; sourceTree = "<group>"; };
|
D41F32932827332000861B3D /* DataExporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataExporter.swift; sourceTree = "<group>"; };
|
||||||
D482BD932776153F003C4FB2 /* TreatmentsNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreatmentsNavigationController.swift; sourceTree = "<group>"; };
|
D482BD932776153F003C4FB2 /* TreatmentsNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TreatmentsNavigationController.swift; sourceTree = "<group>"; };
|
||||||
|
@ -2406,6 +2408,7 @@
|
||||||
F8B3A82E227F085A004BA588 /* SettingsTableViewCell */,
|
F8B3A82E227F085A004BA588 /* SettingsTableViewCell */,
|
||||||
F8B3A7F22278E0E7004BA588 /* SettingsViewModelProtocol.swift */,
|
F8B3A7F22278E0E7004BA588 /* SettingsViewModelProtocol.swift */,
|
||||||
F8B3A807227A2933004BA588 /* SettingsSelectedRowAction.swift */,
|
F8B3A807227A2933004BA588 /* SettingsSelectedRowAction.swift */,
|
||||||
|
D417E51B282EC8DB008DC467 /* ActivityIndicatorViewController.swift */,
|
||||||
);
|
);
|
||||||
path = Helpers;
|
path = Helpers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -3662,6 +3665,7 @@
|
||||||
F8B3A830227F085A004BA588 /* SettingsTableViewCell.swift in Sources */,
|
F8B3A830227F085A004BA588 /* SettingsTableViewCell.swift in Sources */,
|
||||||
F82436FC24BE014000BED341 /* TextsLibreStates.swift in Sources */,
|
F82436FC24BE014000BED341 /* TextsLibreStates.swift in Sources */,
|
||||||
F8F7B8EB259A7B1C00C47B04 /* SavitzkyGolaySmoothableArray.swift in Sources */,
|
F8F7B8EB259A7B1C00C47B04 /* SavitzkyGolaySmoothableArray.swift in Sources */,
|
||||||
|
D417E51C282EC8DB008DC467 /* ActivityIndicatorViewController.swift in Sources */,
|
||||||
F830991C23C2909E005741DF /* Watlaa+CoreDataClass.swift in Sources */,
|
F830991C23C2909E005741DF /* Watlaa+CoreDataClass.swift in Sources */,
|
||||||
F808D2CC240328FA0084B5DB /* Bubble+CoreDataClass.swift in Sources */,
|
F808D2CC240328FA0084B5DB /* Bubble+CoreDataClass.swift in Sources */,
|
||||||
F8A1586122EDB844007F5B5D /* ConstantsNotifications.swift in Sources */,
|
F8A1586122EDB844007F5B5D /* ConstantsNotifications.swift in Sources */,
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
//
|
||||||
|
// ActivityIndicatorViewController.swift
|
||||||
|
// xdrip
|
||||||
|
//
|
||||||
|
// Created by Eduardo Pietre on 13/05/22.
|
||||||
|
// Copyright © 2022 Johan Degraeve. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
|
/// ActivityIndicatorViewController is an utility UIViewController
|
||||||
|
/// that creates a spinner loading indicator.
|
||||||
|
public class ActivityIndicatorViewController : UIViewController {
|
||||||
|
|
||||||
|
/// Reference to the loading indicator.
|
||||||
|
private var indicator = UIActivityIndicatorView(style: .whiteLarge)
|
||||||
|
|
||||||
|
/// loadView will ofuscate the background and centralize the indicator, starting it.
|
||||||
|
public override func loadView() {
|
||||||
|
view = UIView()
|
||||||
|
/// Change the backgroundColor to ofuscate the stuff behind.
|
||||||
|
view.backgroundColor = UIColor(white: 0, alpha: 0.7)
|
||||||
|
|
||||||
|
/// Centralizes the indicator
|
||||||
|
self.indicator.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
self.indicator.startAnimating()
|
||||||
|
view.addSubview(self.indicator)
|
||||||
|
|
||||||
|
self.indicator.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
|
||||||
|
self.indicator.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Starts the ActivityIndicator.
|
||||||
|
/// This method can be called from any thread in a safe way.
|
||||||
|
/// - parameters:
|
||||||
|
/// - onParent: UIViewController: the parent UIViewController.
|
||||||
|
public func start(onParent: UIViewController) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
onParent.addChild(self)
|
||||||
|
self.view.frame = onParent.view.frame
|
||||||
|
onParent.view.addSubview(self.view)
|
||||||
|
self.didMove(toParent: onParent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ends the ActivityIndicator.
|
||||||
|
/// This method can be called from any thread in a safe way.
|
||||||
|
public func end() {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.willMove(toParent: nil)
|
||||||
|
self.view.removeFromSuperview()
|
||||||
|
self.removeFromParent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,6 +38,8 @@ enum SettingsSelectedRowAction {
|
||||||
/// when clicked, the function parameter needs to be called
|
/// when clicked, the function parameter needs to be called
|
||||||
/// but takes as argument a callback that when called returns an optional URL,
|
/// 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.
|
/// that if not nil the user should be presented with a share menu.
|
||||||
|
/// Important: Displays a loading indicator, so all routies MUST call the callback or will
|
||||||
|
/// result in an endless loading indicator.
|
||||||
case callFunctionAndShareFile(function: ((_ callback: @escaping ((_ file: URL?) -> Void)) -> Void))
|
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
|
/// when clicked a list of items must be presented form which the user needs to pick one, for example transmitter type
|
||||||
|
|
|
@ -103,6 +103,9 @@ struct SettingsViewHousekeeperSettingsViewModel: SettingsViewModelProtocol {
|
||||||
/// coreDataManager must not be nil.
|
/// coreDataManager must not be nil.
|
||||||
if let coreDataManager = coreDataManager {
|
if let coreDataManager = coreDataManager {
|
||||||
DataExporter(coreDataManager: coreDataManager).exportAllData(callback: callback)
|
DataExporter(coreDataManager: coreDataManager).exportAllData(callback: callback)
|
||||||
|
} else {
|
||||||
|
/// All routines MUST call callback
|
||||||
|
callback(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,8 +103,16 @@ class SettingsViewUtilities {
|
||||||
|
|
||||||
case let .callFunctionAndShareFile(function):
|
case let .callFunctionAndShareFile(function):
|
||||||
|
|
||||||
|
// Start loading indicator
|
||||||
|
let loadingIndicator = ActivityIndicatorViewController()
|
||||||
|
loadingIndicator.start(onParent: uIViewController)
|
||||||
|
|
||||||
// call function and in the callback present the share file menu.
|
// call function and in the callback present the share file menu.
|
||||||
function({ fileURL in
|
function({ fileURL in
|
||||||
|
|
||||||
|
// Stop loading indicator
|
||||||
|
loadingIndicator.end()
|
||||||
|
|
||||||
if let fileURL = fileURL {
|
if let fileURL = fileURL {
|
||||||
// UI Code must be done at main thread.
|
// UI Code must be done at main thread.
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
Loading…
Reference in New Issue