Changed the HelpViewModel to just provide the "share" option again

pull/1053/head
Morgan Pretty 5 months ago
parent 35758b2946
commit 15243f326d

@ -15,7 +15,6 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa
public let navigatableState: NavigatableState = NavigatableState() public let navigatableState: NavigatableState = NavigatableState()
public let state: TableDataState<Section, TableItem> = TableDataState() public let state: TableDataState<Section, TableItem> = TableDataState()
public let observableState: ObservableTableSourceState<Section, TableItem> = ObservableTableSourceState() public let observableState: ObservableTableSourceState<Section, TableItem> = ObservableTableSourceState()
private static var documentPickerResult: DocumentPickerResult?
// MARK: - Initialization // MARK: - Initialization
@ -158,54 +157,41 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa
let viewController: UIViewController = Singleton.appContext.frontmostViewController let viewController: UIViewController = Singleton.appContext.frontmostViewController
else { return } else { return }
#if targetEnvironment(simulator)
// stringlint:ignore_start
let modal: ConfirmationModal = ConfirmationModal( let modal: ConfirmationModal = ConfirmationModal(
info: ConfirmationModal.Info( info: ConfirmationModal.Info(
title: "helpReportABugExportLogs".localized(), title: "Export Logs",
body: .text("helpReportABugExportLogsDescription" body: .text(
.put(key: "app_name", value: Constants.app_name) "How would you like to export the logs?\n\n(This modal only appears on the Simulator)"
.localized()), ),
confirmTitle: "save".localized(), confirmTitle: "Copy Path",
cancelTitle: "share".localized(), cancelTitle: "Share",
cancelStyle: .alert_text, cancelStyle: .alert_text,
hasCloseButton: true, onConfirm: { _ in UIPasteboard.general.string = latestLogFilePath },
dismissOnConfirm: false, onCancel: { _ in
onConfirm: { modal in HelpViewModel.shareLogsInternal(
#if targetEnvironment(simulator) viewControllerToDismiss: viewControllerToDismiss,
UIPasteboard.general.string = latestLogFilePath targetView: targetView,
#endif animated: animated,
onShareComplete: onShareComplete
modal.dismiss(animated: true) { )
HelpViewModel.shareLogsInternal(
viaShareSheet: false,
viewControllerToDismiss: viewControllerToDismiss,
targetView: targetView,
animated: animated,
onShareComplete: onShareComplete
)
}
},
onCancel: { modal in
#if targetEnvironment(simulator)
UIPasteboard.general.string = latestLogFilePath
#endif
modal.dismiss(animated: true) {
HelpViewModel.shareLogsInternal(
viaShareSheet: true,
viewControllerToDismiss: viewControllerToDismiss,
targetView: targetView,
animated: animated,
onShareComplete: onShareComplete
)
}
} }
) )
) )
// stringlint:ignore_stop
viewController.present(modal, animated: animated, completion: nil) viewController.present(modal, animated: animated, completion: nil)
#else
HelpViewModel.shareLogsInternal(
viewControllerToDismiss: viewControllerToDismiss,
targetView: targetView,
animated: animated,
onShareComplete: onShareComplete
)
#endif
} }
private static func shareLogsInternal( private static func shareLogsInternal(
viaShareSheet: Bool,
viewControllerToDismiss: UIViewController? = nil, viewControllerToDismiss: UIViewController? = nil,
targetView: UIView? = nil, targetView: UIView? = nil,
animated: Bool = true, animated: Bool = true,
@ -220,47 +206,29 @@ class HelpViewModel: SessionTableViewModel, NavigatableStateHolder, ObservableTa
let viewController: UIViewController = Singleton.appContext.frontmostViewController let viewController: UIViewController = Singleton.appContext.frontmostViewController
else { return } else { return }
let showExportOption: () -> () = { let showShareSheet: () -> () = {
switch viaShareSheet { let shareVC = UIActivityViewController(
case true: activityItems: [ URL(fileURLWithPath: latestLogFilePath) ],
let shareVC = UIActivityViewController( applicationActivities: nil
activityItems: [ URL(fileURLWithPath: latestLogFilePath) ], )
applicationActivities: nil shareVC.completionWithItemsHandler = { _, _, _, _ in onShareComplete?() }
)
shareVC.completionWithItemsHandler = { _, _, _, _ in onShareComplete?() } if UIDevice.current.isIPad {
shareVC.excludedActivityTypes = []
if UIDevice.current.isIPad { shareVC.popoverPresentationController?.permittedArrowDirections = (targetView != nil ? [.up] : [])
shareVC.excludedActivityTypes = [] shareVC.popoverPresentationController?.sourceView = (targetView ?? viewController.view)
shareVC.popoverPresentationController?.permittedArrowDirections = (targetView != nil ? [.up] : []) shareVC.popoverPresentationController?.sourceRect = (targetView ?? viewController.view).bounds
shareVC.popoverPresentationController?.sourceView = (targetView ?? viewController.view)
shareVC.popoverPresentationController?.sourceRect = (targetView ?? viewController.view).bounds
}
viewController.present(shareVC, animated: animated, completion: nil)
case false:
// Create and present the document picker
let documentPickerResult: DocumentPickerResult = DocumentPickerResult { _ in
HelpViewModel.documentPickerResult = nil
onShareComplete?()
}
HelpViewModel.documentPickerResult = documentPickerResult
let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(
forExporting: [URL(fileURLWithPath: latestLogFilePath)]
)
documentPicker.delegate = documentPickerResult
documentPicker.modalPresentationStyle = .formSheet
viewController.present(documentPicker, animated: animated, completion: nil)
} }
viewController.present(shareVC, animated: animated, completion: nil)
} }
guard let viewControllerToDismiss: UIViewController = viewControllerToDismiss else { guard let viewControllerToDismiss: UIViewController = viewControllerToDismiss else {
showExportOption() showShareSheet()
return return
} }
viewControllerToDismiss.dismiss(animated: animated) { viewControllerToDismiss.dismiss(animated: animated) {
showExportOption() showShareSheet()
} }
} }
} }

Loading…
Cancel
Save