From b340fb9df7340a6a600efd9cd2a13c19f535d774 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 3 Sep 2018 19:11:37 -0400 Subject: [PATCH] Add default post visibility preference UI --- Tusker.xcodeproj/project.pbxproj | 8 +- .../Preferences/Preferences.storyboard | 77 ++++++++++++++++++- .../PreferencesTableViewController.swift | 7 ++ .../VisibilityTableViewController.swift | 60 +++++++++++++++ 4 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 Tusker/Screens/Preferences/VisibilityTableViewController.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 9c5c7fb8..9b84c491 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ D641C77B213CB017004B4513 /* FollowNotificationTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D641C77A213CB017004B4513 /* FollowNotificationTableViewCell.xib */; }; D641C77D213CB024004B4513 /* FollowNotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D641C77C213CB024004B4513 /* FollowNotificationTableViewCell.swift */; }; D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */; }; + D641C78F213DF2AA004B4513 /* VisibilityTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */; }; D646C956213B365700269FB5 /* LargeImageExpandAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C955213B365700269FB5 /* LargeImageExpandAnimationController.swift */; }; D646C958213B367000269FB5 /* LargeImageShrinkAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */; }; D646C95A213B5D0500269FB5 /* LargeImageInteractionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C959213B5D0500269FB5 /* LargeImageInteractionController.swift */; }; @@ -114,6 +115,7 @@ D641C77A213CB017004B4513 /* FollowNotificationTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FollowNotificationTableViewCell.xib; sourceTree = ""; }; D641C77C213CB024004B4513 /* FollowNotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FollowNotificationTableViewCell.swift; sourceTree = ""; }; D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineTextAttachment.swift; sourceTree = ""; }; + D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VisibilityTableViewController.swift; sourceTree = ""; }; D646C955213B365700269FB5 /* LargeImageExpandAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageExpandAnimationController.swift; sourceTree = ""; }; D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageShrinkAnimationController.swift; sourceTree = ""; }; D646C959213B5D0500269FB5 /* LargeImageInteractionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageInteractionController.swift; sourceTree = ""; }; @@ -276,8 +278,8 @@ isa = PBXGroup; children = ( D646C954213B364600269FB5 /* Transitions */, - D6C94D862139E62700CB5196 /* LargeImageViewController.swift */, D6C94D842139DFD800CB5196 /* LargeImage.storyboard */, + D6C94D862139E62700CB5196 /* LargeImageViewController.swift */, ); path = "Large Image"; sourceTree = ""; @@ -285,8 +287,9 @@ D641C789213DD87E004B4513 /* Preferences */ = { isa = PBXGroup; children = ( - D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */, D663626521360DD700C9CBA2 /* Preferences.storyboard */, + D663626721360E2C00C9CBA2 /* PreferencesTableViewController.swift */, + D641C78E213DF2AA004B4513 /* VisibilityTableViewController.swift */, ); path = Preferences; sourceTree = ""; @@ -600,6 +603,7 @@ D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */, D663626221360B1900C9CBA2 /* Preferences.swift in Sources */, D6333B792139AEFD00CE884A /* Date+TimeAgo.swift in Sources */, + D641C78F213DF2AA004B4513 /* VisibilityTableViewController.swift in Sources */, D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */, D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */, D6333B372137838300CE884A /* AttributedString+Trim.swift in Sources */, diff --git a/Tusker/Screens/Preferences/Preferences.storyboard b/Tusker/Screens/Preferences/Preferences.storyboard index 90d41585..5fbe1d3f 100644 --- a/Tusker/Screens/Preferences/Preferences.storyboard +++ b/Tusker/Screens/Preferences/Preferences.storyboard @@ -105,6 +105,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -114,6 +149,7 @@ + @@ -122,6 +158,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -138,7 +213,7 @@ - + diff --git a/Tusker/Screens/Preferences/PreferencesTableViewController.swift b/Tusker/Screens/Preferences/PreferencesTableViewController.swift index 24e24d9f..efa44086 100644 --- a/Tusker/Screens/Preferences/PreferencesTableViewController.swift +++ b/Tusker/Screens/Preferences/PreferencesTableViewController.swift @@ -18,6 +18,7 @@ class PreferencesTableViewController: UITableViewController { @IBOutlet weak var showRepliesInProfilesSwitch: UISwitch! @IBOutlet weak var circularAvatarsSwitch: UISwitch! @IBOutlet weak var hideCustomEmojiInUsernamesSwitch: UISwitch! + @IBOutlet weak var defaultPostVisibilityLabel: UILabel! override func viewDidLoad() { super.viewDidLoad() @@ -26,6 +27,12 @@ class PreferencesTableViewController: UITableViewController { circularAvatarsSwitch.setOn(Preferences.shared.avatarStyle == .circle, animated: false) hideCustomEmojiInUsernamesSwitch.setOn(Preferences.shared.hideCustomEmojiInUsernames, animated: false) } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + defaultPostVisibilityLabel.text = Preferences.shared.defaultPostVisibility.displayName + } /* // MARK: - Navigation diff --git a/Tusker/Screens/Preferences/VisibilityTableViewController.swift b/Tusker/Screens/Preferences/VisibilityTableViewController.swift new file mode 100644 index 00000000..851e3226 --- /dev/null +++ b/Tusker/Screens/Preferences/VisibilityTableViewController.swift @@ -0,0 +1,60 @@ +// +// VisibilityTableViewController.swift +// Tusker +// +// Created by Shadowfacts on 9/3/18. +// Copyright © 2018 Shadowfacts. All rights reserved. +// + +import UIKit +import MastodonKit + +class VisibilityTableViewController: UITableViewController { + + // todo: description of visibility types + + override func viewDidLoad() { + super.viewDidLoad() + } + + // MARK: - Table view data source + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return Visibility.allCases.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let visibility = Visibility.allCases[indexPath.row] + + let cell = tableView.dequeueReusableCell(withIdentifier: "visibilityCell", for: indexPath) + cell.textLabel!.text = visibility.displayName + cell.accessoryType = visibility == Preferences.shared.defaultPostVisibility ? .checkmark : .none + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let oldVisibility = Preferences.shared.defaultPostVisibility + let oldIndexPath = IndexPath(row: Visibility.allCases.firstIndex(of: oldVisibility)!, section: 0) + + let visibility = Visibility.allCases[indexPath.row] + Preferences.shared.defaultPostVisibility = visibility + + tableView.reloadRows(at: [indexPath], with: .automatic) + tableView.reloadRows(at: [oldIndexPath], with: .none) + } + + /* + // 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. + } + */ + +}