From 3ea7e1057b9519e81d1c9fc61f41fdf13be57cc7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 5 Dec 2022 17:24:01 -0500 Subject: [PATCH] Add preference to disable timeline state restoration --- Tusker/Preferences/Preferences.swift | 4 ++++ Tusker/Screens/Preferences/BehaviorPrefsView.swift | 11 +++++++++++ Tusker/Screens/Timeline/TimelineViewController.swift | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index ac4245ad..6b784898 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -63,6 +63,7 @@ class Preferences: Codable, ObservableObject { self.collapseLongPosts = try container.decodeIfPresent(Bool.self, forKey: .collapseLongPosts) ?? true self.oppositeCollapseKeywords = try container.decodeIfPresent([String].self, forKey: .oppositeCollapseKeywords) ?? [] self.confirmBeforeReblog = try container.decodeIfPresent(Bool.self, forKey: .confirmBeforeReblog) ?? false + self.timelineStateRestoration = try container.decodeIfPresent(Bool.self, forKey: .timelineStateRestoration) ?? true self.showFavoriteAndReblogCounts = try container.decode(Bool.self, forKey: .showFavoriteAndReblogCounts) self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType) @@ -105,6 +106,7 @@ class Preferences: Codable, ObservableObject { try container.encode(collapseLongPosts, forKey: .collapseLongPosts) try container.encode(oppositeCollapseKeywords, forKey: .oppositeCollapseKeywords) try container.encode(confirmBeforeReblog, forKey: .confirmBeforeReblog) + try container.encode(timelineStateRestoration, forKey: .timelineStateRestoration) try container.encode(showFavoriteAndReblogCounts, forKey: .showFavoriteAndReblogCounts) try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType) @@ -156,6 +158,7 @@ class Preferences: Codable, ObservableObject { @Published var collapseLongPosts = true @Published var oppositeCollapseKeywords: [String] = [] @Published var confirmBeforeReblog = false + @Published var timelineStateRestoration = true // MARK: Digital Wellness @Published var showFavoriteAndReblogCounts = true @@ -199,6 +202,7 @@ class Preferences: Codable, ObservableObject { case collapseLongPosts case oppositeCollapseKeywords case confirmBeforeReblog + case timelineStateRestoration case showFavoriteAndReblogCounts case defaultNotificationsType diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index 49956db5..96251c63 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -14,6 +14,7 @@ struct BehaviorPrefsView: View { var body: some View { List { untitledSection + timelineSection linksSection contentWarningsSection } @@ -28,6 +29,16 @@ struct BehaviorPrefsView: View { } } } + + private var timelineSection: some View { + Section { + Toggle(isOn: $preferences.timelineStateRestoration) { + Text("Maintain Position Across App Launches") + } + } header: { + Text("Timeline") + } + } private var linksSection: some View { Section(header: Text("Links")) { diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index cb833424..22d0fef4 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -284,7 +284,8 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } private func doRestore() -> Bool { - guard let activity = activityToRestore else { + guard let activity = activityToRestore, + Preferences.shared.timelineStateRestoration else { return false } guard let statusIDs = activity.userInfo?["statusIDs"] as? [String] else {