From 815d4458ea5b185905bd8616a5eb23b42ec93e38 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 30 Sep 2018 11:53:20 -0400 Subject: [PATCH] Add preferences UI for silent XCB actions --- Tusker.xcodeproj/project.pbxproj | 20 ++++ .../Preferences/Preferences.storyboard | 112 ++++++++++++++++-- ...ActionPermissionsTableViewController.swift | 49 ++++++++ .../SilentActionPermissionCell.xib | 47 ++++++++ .../SilentActionPermissionTableViewCell.swift | 36 ++++++ 5 files changed, 255 insertions(+), 9 deletions(-) create mode 100644 Tusker/Screens/Preferences/SilentActionPermissionsTableViewController.swift create mode 100644 Tusker/Views/Silent Action Permissions/SilentActionPermissionCell.xib create mode 100644 Tusker/Views/Silent Action Permissions/SilentActionPermissionTableViewCell.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 44156737..cba3f768 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -99,6 +99,9 @@ D679C09F215850EF00DA27FE /* XCBActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D679C09E215850EF00DA27FE /* XCBActions.swift */; }; D6BED170212663DA00F02DA0 /* SwiftSoup.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D6BED174212667E900F02DA0 /* StatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BED173212667E900F02DA0 /* StatusTableViewCell.swift */; }; + D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */; }; + D6C693CD2161257B007D6A6D /* SilentActionPermissionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */; }; + D6C693CF216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */; }; D6C94D852139DFD800CB5196 /* LargeImage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6C94D842139DFD800CB5196 /* LargeImage.storyboard */; }; D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D862139E62700CB5196 /* LargeImageViewController.swift */; }; D6C94D892139E6EC00CB5196 /* AttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D882139E6EC00CB5196 /* AttachmentView.swift */; }; @@ -261,6 +264,9 @@ D679C09E215850EF00DA27FE /* XCBActions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XCBActions.swift; sourceTree = ""; }; D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftSoup.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D6BED173212667E900F02DA0 /* StatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusTableViewCell.swift; sourceTree = ""; }; + D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionsTableViewController.swift; sourceTree = ""; }; + D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SilentActionPermissionCell.xib; sourceTree = ""; }; + D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionTableViewCell.swift; sourceTree = ""; }; D6C94D842139DFD800CB5196 /* LargeImage.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LargeImage.storyboard; sourceTree = ""; }; D6C94D862139E62700CB5196 /* LargeImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageViewController.swift; sourceTree = ""; }; D6C94D882139E6EC00CB5196 /* AttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentView.swift; sourceTree = ""; }; @@ -506,6 +512,7 @@ D663626521360DD700C9CBA2 /* Preferences.storyboard */, D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */, D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */, + D6C693C92161253F007D6A6D /* SilentActionPermissionsTableViewController.swift */, ); path = Preferences; sourceTree = ""; @@ -607,10 +614,20 @@ D641C78A213DD926004B4513 /* Status */, D641C78B213DD92F004B4513 /* Profile Header */, D641C78C213DD937004B4513 /* Notifications */, + D6C693CB2161256B007D6A6D /* Silent Action Permissions */, ); path = Views; sourceTree = ""; }; + D6C693CB2161256B007D6A6D /* Silent Action Permissions */ = { + isa = PBXGroup; + children = ( + D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */, + D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */, + ); + path = "Silent Action Permissions"; + sourceTree = ""; + }; D6D4DDC3212518A000E1C4BB = { isa = PBXGroup; children = ( @@ -864,6 +881,7 @@ D641C779213CAC56004B4513 /* ActionNotificationTableViewCell.xib in Resources */, D667E5F32135BC260057A976 /* Conversation.storyboard in Resources */, D667E5E921349EE50057A976 /* ProfileHeaderTableViewCell.xib in Resources */, + D6C693CD2161257B007D6A6D /* SilentActionPermissionCell.xib in Resources */, D6D4DDDA212518A200E1C4BB /* LaunchScreen.storyboard in Resources */, D64D0AAF2128D954005A6F37 /* Onboarding.storyboard in Resources */, D6D4DDD7212518A200E1C4BB /* Assets.xcassets in Resources */, @@ -977,6 +995,7 @@ D641C78F213DF2AA004B4513 /* VisibilityTableViewController.swift in Sources */, D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */, D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */, + D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */, D6333B372137838300CE884A /* AttributedString+Trim.swift in Sources */, D667E5EF2134C39F0057A976 /* StatusContentLabel.swift in Sources */, D641C777213CAA9E004B4513 /* ActionNotificationTableViewCell.swift in Sources */, @@ -992,6 +1011,7 @@ D641C773213CAA25004B4513 /* NotificationsTableViewController.swift in Sources */, D6757A7C2157E01900721E32 /* XCBManager.swift in Sources */, D64A0CD32132153900640E3B /* HTMLContentLabel.swift in Sources */, + D6C693CF216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift in Sources */, D6757A7E2157E02600721E32 /* XCBRequestSpec.swift in Sources */, D667E5F12134D5050057A976 /* UIViewController+Delegates.swift in Sources */, D663625F2135C75500C9CBA2 /* ConversationMainStatusTableViewCell.swift in Sources */, diff --git a/Tusker/Screens/Preferences/Preferences.storyboard b/Tusker/Screens/Preferences/Preferences.storyboard index 5fbe1d3f..42cac7ef 100644 --- a/Tusker/Screens/Preferences/Preferences.storyboard +++ b/Tusker/Screens/Preferences/Preferences.storyboard @@ -1,10 +1,10 @@ - + - + @@ -33,7 +33,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -99,7 +99,7 @@ - + @@ -140,6 +140,33 @@ + + + + + + + + + + + + + + + + + + + + + + @@ -195,7 +222,74 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tusker/Screens/Preferences/SilentActionPermissionsTableViewController.swift b/Tusker/Screens/Preferences/SilentActionPermissionsTableViewController.swift new file mode 100644 index 00000000..047bfcb5 --- /dev/null +++ b/Tusker/Screens/Preferences/SilentActionPermissionsTableViewController.swift @@ -0,0 +1,49 @@ +// +// SilentActionPermissionsTableViewController.swift +// Tusker +// +// Created by Shadowfacts on 9/30/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit + +class SilentActionPermissionsTableViewController: UITableViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + tableView.register(UINib(nibName: "SilentActionPermissionCell", bundle: nil), forCellReuseIdentifier: "permissionCell") + } + + // MARK: - Table view data source + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return Preferences.shared.silentActions.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + guard let cell = tableView.dequeueReusableCell(withIdentifier: "permissionCell", for: indexPath) as? SilentActionPermissionTableViewCell else { fatalError() } + + let index = Preferences.shared.silentActions.index(Preferences.shared.silentActions.startIndex, offsetBy: indexPath.row) + let (source, permission) = Preferences.shared.silentActions[index] + cell.updateUI(source: source, permission: permission) + + return cell + } + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} diff --git a/Tusker/Views/Silent Action Permissions/SilentActionPermissionCell.xib b/Tusker/Views/Silent Action Permissions/SilentActionPermissionCell.xib new file mode 100644 index 00000000..c9a4da49 --- /dev/null +++ b/Tusker/Views/Silent Action Permissions/SilentActionPermissionCell.xib @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tusker/Views/Silent Action Permissions/SilentActionPermissionTableViewCell.swift b/Tusker/Views/Silent Action Permissions/SilentActionPermissionTableViewCell.swift new file mode 100644 index 00000000..e7c8c125 --- /dev/null +++ b/Tusker/Views/Silent Action Permissions/SilentActionPermissionTableViewCell.swift @@ -0,0 +1,36 @@ +// +// SilentActionPermissionTableViewCell.swift +// Tusker +// +// Created by Shadowfacts on 9/30/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit + +class SilentActionPermissionTableViewCell: UITableViewCell { + + @IBOutlet weak var sourceLabel: UILabel! + @IBOutlet weak var permissionSwitch: UISwitch! + + var source: String! + + override func awakeFromNib() { + super.awakeFromNib() + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + } + + func updateUI(source: String, permission: Preferences.Permission) { + self.source = source + sourceLabel.text = source + permissionSwitch.setOn(permission == .accepted, animated: false) + } + + @IBAction func permissionSwitchChanged(_ sender: Any) { + Preferences.shared.silentActions[source] = permissionSwitch.isOn ? .accepted : .rejected + } + +}