From 3366b16c96e89bfd5bebe041ed6d7f3e9fb8e2b1 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 22 Feb 2019 10:20:22 -0500 Subject: [PATCH] Add option to attempt to open links in their respective apps --- Tusker/Preferences/Preferences.swift | 3 +- .../BehaviorTableViewController.swift | 15 ++++++-- .../Preferences/Preferences.storyboard | 38 ++++++++++++++++++- Tusker/TuskerNavigationDelegate.swift | 10 ++++- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 08d386e39d..f29bcc91c6 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -38,9 +38,10 @@ class Preferences: Codable { var avatarStyle = AvatarStyle.roundRect var hideCustomEmojiInUsernames = false + // MARK: - Behavior var defaultPostVisibility = Status.Visibility.public - var automaticallySaveDrafts = true + var openLinksInApps = true // MARK: - Advanced var silentActions: [String: Permission] = [:] diff --git a/Tusker/Screens/Preferences/BehaviorTableViewController.swift b/Tusker/Screens/Preferences/BehaviorTableViewController.swift index a30ec27afa..c72ba06ad6 100644 --- a/Tusker/Screens/Preferences/BehaviorTableViewController.swift +++ b/Tusker/Screens/Preferences/BehaviorTableViewController.swift @@ -12,16 +12,14 @@ class BehaviorTableViewController: UITableViewController { @IBOutlet weak var defaultPostVisibilityLabel: UILabel! @IBOutlet weak var automaticallySaveDraftsSwitch: UISwitch! + @IBOutlet weak var openLinksInAppsSwitch: UISwitch! override func viewDidLoad() { super.viewDidLoad() defaultPostVisibilityLabel.text = Preferences.shared.defaultPostVisibility.displayName automaticallySaveDraftsSwitch.setOn(Preferences.shared.automaticallySaveDrafts, animated: false) - } - - @IBAction func automaticallySaveDraftsChanged(_ sender: Any) { - Preferences.shared.automaticallySaveDrafts = automaticallySaveDraftsSwitch.isOn + openLinksInAppsSwitch.setOn(Preferences.shared.openLinksInApps, animated: false) } override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { @@ -43,4 +41,13 @@ class BehaviorTableViewController: UITableViewController { present(alertController, animated: true) } + @IBAction func automaticallySaveDraftsChanged(_ sender: Any) { + Preferences.shared.automaticallySaveDrafts = automaticallySaveDraftsSwitch.isOn + } + + @IBAction func openLinksInAppsChanged(_ sender: Any) { + Preferences.shared.openLinksInApps = openLinksInAppsSwitch.isOn + } + + } diff --git a/Tusker/Screens/Preferences/Preferences.storyboard b/Tusker/Screens/Preferences/Preferences.storyboard index bb6ea32489..af8c2d0933 100644 --- a/Tusker/Screens/Preferences/Preferences.storyboard +++ b/Tusker/Screens/Preferences/Preferences.storyboard @@ -1,10 +1,10 @@ - + - + @@ -292,6 +292,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -302,6 +335,7 @@ + diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index 13490bcf8f..0d9a41eaa5 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -60,7 +60,15 @@ extension TuskerNavigationDelegate where Self: UIViewController { } func selected(url: URL) { - present(SFSafariViewController(url: url), animated: true) + if (Preferences.shared.openLinksInApps) { + UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { (success) in + if (!success) { + self.present(SFSafariViewController(url: url), animated: true) + } + } + } else { + present(SFSafariViewController(url: url), animated: true) + } } func selected(status statusID: String) {