diff --git a/NineAnimator/Controllers/RootViewController.swift b/NineAnimator/Controllers/RootViewController.swift index 91d1c335..ab446080 100644 --- a/NineAnimator/Controllers/RootViewController.swift +++ b/NineAnimator/Controllers/RootViewController.swift @@ -24,12 +24,23 @@ class RootViewController: UITabBarController, Themable { private weak var castControllerDelegate: AnyObject? + /// The top view controller visible by the user private var topViewController: UIViewController { - var topViewController: UIViewController = self - while let next = topViewController.presentedViewController { - topViewController = next + var topController: UIViewController = self + while true { + if let presentedController = topController.presentedViewController { + topController = presentedController + } // Special case for UINavigationController + else if let nav = topController as? UINavigationController, + let presentedController = nav.visibleViewController { + topController = presentedController + } // Special case for UITabBarController + else if let tab = topController as? UITabBarController, + let presentedController = tab.selectedViewController { + topController = presentedController + } else { break } } - return topViewController + return topController } override func viewDidLoad() { @@ -203,9 +214,9 @@ extension RootViewController { if let navigationController = viewController.navigationController { navigationController.pushViewController(targetViewController, animated: true) } else { viewController.present(targetViewController, animated: true) } - } else { // If no view controller is provided, present the link in the featured tab - // Jump to Featured tab - selectedIndex = 0 + } else { + // If no view controller is provided, present the link in the watch next tab + navigate(toScene: .toWatch) guard let navigationController = viewControllers?.first as? ApplicationNavigationController else { Log.error("The first view controller is not ApplicationNavigationController.") @@ -242,8 +253,8 @@ extension RootViewController { fileprivate func _restore(_ config: URL) { let alert = UIAlertController( - title: "Import Configurations", - message: "How do you want to import this configuration?", + title: "Import Backup", + message: "How do you want to import this backup?", preferredStyle: .alert ) @@ -256,10 +267,22 @@ extension RootViewController { presentOnTop(errorAlert) } + func showConfirmationMessage() { + let confirmationAlert = UIAlertController( + title: "Backup Imported", + message: "Backup was imported successfully", + preferredStyle: .alert + ) + + confirmationAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + presentOnTop(confirmationAlert) + } + alert.addAction(UIAlertAction(title: "Replace Current", style: .destructive) { _ in do { try replace(NineAnimator.default.user, with: config) + showConfirmationMessage() } catch { showErrorAlert(error: error) } @@ -269,6 +292,7 @@ extension RootViewController { _ in do { try merge(NineAnimator.default.user, with: config, policy: .localFirst) + showConfirmationMessage() } catch { showErrorAlert(error: error) } @@ -278,6 +302,7 @@ extension RootViewController { _ in do { try merge(NineAnimator.default.user, with: config, policy: .remoteFirst) + showConfirmationMessage() } catch { showErrorAlert(error: error) }