From 905b6a0a213d376eae5228584799c55b7be68b52 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 14 Sep 2019 13:02:33 -0400 Subject: [PATCH] Add preference for default notifications display mode --- Tusker.xcodeproj/project.pbxproj | 8 ++++ Tusker/Preferences/NotificationsMode.swift | 25 ++++++++++++ Tusker/Preferences/Preferences.swift | 9 +++++ .../NotificationsPageViewController.swift | 14 +++++++ .../Preferences/BehaviorPrefsView.swift | 4 +- .../Screens/Preferences/PreferencesView.swift | 3 ++ .../Preferences/WellnessPrefsView.swift | 39 +++++++++++++++++++ 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 Tusker/Preferences/NotificationsMode.swift create mode 100644 Tusker/Screens/Preferences/WellnessPrefsView.swift diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index f5a6e8b9..1aa2e483 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -167,6 +167,8 @@ D6BC874621961F73006163F1 /* Gifu.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D6BC874421961F73006163F1 /* Gifu.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D6BC8748219738E1006163F1 /* EnhancedTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC8747219738E1006163F1 /* EnhancedTableViewController.swift */; }; D6BC9DB1232C61BC002CA326 /* NotificationsPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC9DB0232C61BC002CA326 /* NotificationsPageViewController.swift */; }; + D6BC9DB3232D4C07002CA326 /* WellnessPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC9DB2232D4C07002CA326 /* WellnessPrefsView.swift */; }; + D6BC9DB5232D4CE3002CA326 /* NotificationsMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6BC9DB4232D4CE3002CA326 /* NotificationsMode.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 */; }; D6C693EF216192C2007D6A6D /* TuskerNavigationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */; }; @@ -414,6 +416,8 @@ D6BC874421961F73006163F1 /* Gifu.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Gifu.framework; sourceTree = BUILT_PRODUCTS_DIR; }; D6BC8747219738E1006163F1 /* EnhancedTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnhancedTableViewController.swift; sourceTree = ""; }; D6BC9DB0232C61BC002CA326 /* NotificationsPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsPageViewController.swift; sourceTree = ""; }; + D6BC9DB2232D4C07002CA326 /* WellnessPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WellnessPrefsView.swift; sourceTree = ""; }; + D6BC9DB4232D4CE3002CA326 /* NotificationsMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsMode.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 = ""; }; D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TuskerNavigationDelegate.swift; sourceTree = ""; }; @@ -773,6 +777,7 @@ 04586B4022B2FFB10021BD04 /* PreferencesView.swift */, 04586B4222B301470021BD04 /* AppearancePrefsView.swift */, 0427033722B30F5F000D31B6 /* BehaviorPrefsView.swift */, + D6BC9DB2232D4C07002CA326 /* WellnessPrefsView.swift */, 0427033922B31269000D31B6 /* AdvancedPrefsView.swift */, 0427037B22B316B9000D31B6 /* SilentActionPrefs.swift */, ); @@ -835,6 +840,7 @@ 0427033522B30B3D000D31B6 /* Preference.swift */, D6DD353C22F28CD000A9563A /* ContentWarningCopyMode.swift */, D6DD353E22F502EC00A9563A /* Preferences+Notification.swift */, + D6BC9DB4232D4CE3002CA326 /* NotificationsMode.swift */, ); path = Preferences; sourceTree = ""; @@ -1499,6 +1505,7 @@ D6AEBB412321642700E5038B /* SendMesasgeActivity.swift in Sources */, D6BC9DB1232C61BC002CA326 /* NotificationsPageViewController.swift in Sources */, D6C693F92162E4DB007D6A6D /* StatusContentLabel.swift in Sources */, + D6BC9DB3232D4C07002CA326 /* WellnessPrefsView.swift in Sources */, D6D58DF922074B74009C8DD9 /* LinkLabel.swift in Sources */, 0454DDAF22B462EF00B8BB8E /* GalleryExpandAnimationController.swift in Sources */, D6A3BC8A2321F79B00FD64D5 /* AccountTableViewCell.swift in Sources */, @@ -1563,6 +1570,7 @@ D6A3BC7C232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift in Sources */, D6F953EC212519E700CF0F2B /* TimelineTableViewController.swift in Sources */, 04586B4122B2FFB10021BD04 /* PreferencesView.swift in Sources */, + D6BC9DB5232D4CE3002CA326 /* NotificationsMode.swift in Sources */, D667E5EB21349EF80057A976 /* ProfileHeaderTableViewCell.swift in Sources */, 04D14BB022B34A2800642648 /* GalleryViewController.swift in Sources */, D641C773213CAA25004B4513 /* NotificationsTableViewController.swift in Sources */, diff --git a/Tusker/Preferences/NotificationsMode.swift b/Tusker/Preferences/NotificationsMode.swift new file mode 100644 index 00000000..03d03d1b --- /dev/null +++ b/Tusker/Preferences/NotificationsMode.swift @@ -0,0 +1,25 @@ +// +// NotificationsMode.swift +// Tusker +// +// Created by Shadowfacts on 9/14/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import Foundation + +enum NotificationsMode: String, Codable, CaseIterable { + case allNotifications + case mentionsOnly +} + +extension NotificationsMode { + var displayName: String { + switch self { + case .allNotifications: + return NSLocalizedString("All Notifications", comment: "display all notifications mode") + case .mentionsOnly: + return NSLocalizedString("Mentions Only", comment: "display only mentions mode") + } + } +} diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index e8e60836..4c0e349e 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -47,6 +47,8 @@ class Preferences: Codable, ObservableObject { self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode) self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps) + self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType) + self.silentActions = try container.decode([String: Permission].self, forKey: .silentActions) self.statusContentType = try container.decode(StatusContentType.self, forKey: .statusContentType) } @@ -63,6 +65,8 @@ class Preferences: Codable, ObservableObject { try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode) try container.encode(openLinksInApps, forKey: .openLinksInApps) + try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType) + try container.encode(silentActions, forKey: .silentActions) try container.encode(statusContentType, forKey: .statusContentType) } @@ -81,6 +85,9 @@ class Preferences: Codable, ObservableObject { @Published var contentWarningCopyMode = ContentWarningCopyMode.asIs @Published var openLinksInApps = true + // MARK: - Digital Wellness + @Published var defaultNotificationsMode = NotificationsMode.allNotifications + // MARK: - Advanced @Published var silentActions: [String: Permission] = [:] @Published var statusContentType: StatusContentType = .plain @@ -95,6 +102,8 @@ class Preferences: Codable, ObservableObject { case contentWarningCopyMode case openLinksInApps + case defaultNotificationsType + case silentActions case statusContentType } diff --git a/Tusker/Screens/Notifications/NotificationsPageViewController.swift b/Tusker/Screens/Notifications/NotificationsPageViewController.swift index b78fa5c0..e3df2dc3 100644 --- a/Tusker/Screens/Notifications/NotificationsPageViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsPageViewController.swift @@ -36,5 +36,19 @@ class NotificationsPageViewController: SegmentedPageViewController { required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + override func viewDidLoad() { + super.viewDidLoad() + + let index: Int + switch Preferences.shared.defaultNotificationsMode { + case .allNotifications: + index = 0 + case .mentionsOnly: + index = 1 + } + segmentedControl.selectedSegmentIndex = index + selectPage(at: index, animated: false) + } } diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index 0f392252..e34765c8 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -23,7 +23,7 @@ struct BehaviorPrefsView : View { } var section1: some View { - Section { + Section(header: Text("COMPOSING")) { Picker(selection: _defaultPostVisibility.binding, label: Text("Default Post Visibility")) { ForEach(Status.Visibility.allCases, id: \.self) { visibility in HStack { @@ -46,7 +46,7 @@ struct BehaviorPrefsView : View { } var section2: some View { - Section { + Section(header: Text("READING")) { Toggle(isOn: _openLinksInApps.binding) { Text("Open Links in Apps") } diff --git a/Tusker/Screens/Preferences/PreferencesView.swift b/Tusker/Screens/Preferences/PreferencesView.swift index e2b0beb1..033402ce 100644 --- a/Tusker/Screens/Preferences/PreferencesView.swift +++ b/Tusker/Screens/Preferences/PreferencesView.swift @@ -18,6 +18,9 @@ struct PreferencesView : View { NavigationLink(destination: BehaviorPrefsView()) { Text("Behavior") } + NavigationLink(destination: WellnessPrefsView()) { + Text("Digital Wellness") + } NavigationLink(destination: AdvancedPrefsView()) { Text("Advanced") } diff --git a/Tusker/Screens/Preferences/WellnessPrefsView.swift b/Tusker/Screens/Preferences/WellnessPrefsView.swift new file mode 100644 index 00000000..4c3ae3a7 --- /dev/null +++ b/Tusker/Screens/Preferences/WellnessPrefsView.swift @@ -0,0 +1,39 @@ +// +// WellnessPrefsView.swift +// Tusker +// +// Created by Shadowfacts on 9/14/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import SwiftUI + +struct WellnessPrefsView: View { + @Preference(\.defaultNotificationsMode) var defaultNotificationsMode: NotificationsMode + var body: some View { + List { + notificationsModeSection + }.listStyle(GroupedListStyle()) + .navigationBarTitle(Text("Digital Wellness")) + } + + var notificationsModeSection: some View { + Section(footer: notificationsModeFooter) { + Picker(selection: _defaultNotificationsMode.binding, label: Text("Default Notifications Mode")) { + ForEach(NotificationsMode.allCases, id: \.self) { type in + Text(type.displayName).tag(type) + } + } + } + } + + var notificationsModeFooter: some View { + Text("Choose which kinds of notifications will be shown by default in the Notifications tab.") + } +} + +struct WellnessPrefsView_Previews: PreviewProvider { + static var previews: some View { + WellnessPrefsView() + } +}