Add preference to disable Discover
This commit is contained in:
parent
c6d158a8a3
commit
e49859e5ea
|
@ -64,6 +64,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
|
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
|
||||||
self.grayscaleImages = try container.decodeIfPresent(Bool.self, forKey: .grayscaleImages) ?? false
|
self.grayscaleImages = try container.decodeIfPresent(Bool.self, forKey: .grayscaleImages) ?? false
|
||||||
self.disableInfiniteScrolling = try container.decodeIfPresent(Bool.self, forKey: .disableInfiniteScrolling) ?? false
|
self.disableInfiniteScrolling = try container.decodeIfPresent(Bool.self, forKey: .disableInfiniteScrolling) ?? false
|
||||||
|
self.hideDiscover = try container.decodeIfPresent(Bool.self, forKey: .hideDiscover) ?? false
|
||||||
|
|
||||||
self.silentActions = try container.decode([String: Permission].self, forKey: .silentActions)
|
self.silentActions = try container.decode([String: Permission].self, forKey: .silentActions)
|
||||||
self.statusContentType = try container.decode(StatusContentType.self, forKey: .statusContentType)
|
self.statusContentType = try container.decode(StatusContentType.self, forKey: .statusContentType)
|
||||||
|
@ -102,6 +103,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType)
|
try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType)
|
||||||
try container.encode(grayscaleImages, forKey: .grayscaleImages)
|
try container.encode(grayscaleImages, forKey: .grayscaleImages)
|
||||||
try container.encode(disableInfiniteScrolling, forKey: .disableInfiniteScrolling)
|
try container.encode(disableInfiniteScrolling, forKey: .disableInfiniteScrolling)
|
||||||
|
try container.encode(hideDiscover, forKey: .hideDiscover)
|
||||||
|
|
||||||
try container.encode(silentActions, forKey: .silentActions)
|
try container.encode(silentActions, forKey: .silentActions)
|
||||||
try container.encode(statusContentType, forKey: .statusContentType)
|
try container.encode(statusContentType, forKey: .statusContentType)
|
||||||
|
@ -142,6 +144,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
@Published var defaultNotificationsMode = NotificationsMode.allNotifications
|
@Published var defaultNotificationsMode = NotificationsMode.allNotifications
|
||||||
@Published var grayscaleImages = false
|
@Published var grayscaleImages = false
|
||||||
@Published var disableInfiniteScrolling = false
|
@Published var disableInfiniteScrolling = false
|
||||||
|
@Published var hideDiscover = false
|
||||||
|
|
||||||
// MARK: Advanced
|
// MARK: Advanced
|
||||||
@Published var silentActions: [String: Permission] = [:]
|
@Published var silentActions: [String: Permission] = [:]
|
||||||
|
@ -179,6 +182,7 @@ class Preferences: Codable, ObservableObject {
|
||||||
case defaultNotificationsType
|
case defaultNotificationsType
|
||||||
case grayscaleImages
|
case grayscaleImages
|
||||||
case disableInfiniteScrolling
|
case disableInfiniteScrolling
|
||||||
|
case hideDiscover
|
||||||
|
|
||||||
case silentActions
|
case silentActions
|
||||||
case statusContentType
|
case statusContentType
|
||||||
|
|
|
@ -68,6 +68,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(savedHashtagsChanged), name: .savedHashtagsChanged, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(savedHashtagsChanged), name: .savedHashtagsChanged, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(savedInstancesChanged), name: .savedInstancesChanged, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(savedInstancesChanged), name: .savedInstancesChanged, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
@ -138,9 +139,9 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||||
snapshot.appendSections(Section.allCases.filter { $0 != .discover })
|
snapshot.appendSections(Section.allCases.filter { $0 != .discover })
|
||||||
snapshot.appendItems([.bookmarks], toSection: .bookmarks)
|
snapshot.appendItems([.bookmarks], toSection: .bookmarks)
|
||||||
if mastodonController.instanceFeatures.instanceType.isMastodon {
|
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
||||||
snapshot.insertSections([.discover], afterSection: .bookmarks)
|
!Preferences.shared.hideDiscover {
|
||||||
snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover)
|
addDiscoverSection(to: &snapshot)
|
||||||
}
|
}
|
||||||
snapshot.appendItems([.addList], toSection: .lists)
|
snapshot.appendItems([.addList], toSection: .lists)
|
||||||
snapshot.appendItems(SavedDataManager.shared.sortedHashtags(for: account).map { .savedHashtag($0) }, toSection: .savedHashtags)
|
snapshot.appendItems(SavedDataManager.shared.sortedHashtags(for: account).map { .savedHashtag($0) }, toSection: .savedHashtags)
|
||||||
|
@ -152,6 +153,11 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
reloadLists()
|
reloadLists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func addDiscoverSection(to snapshot: inout NSDiffableDataSourceSnapshot<Section, Item>) {
|
||||||
|
snapshot.insertSections([.discover], afterSection: .bookmarks)
|
||||||
|
snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover)
|
||||||
|
}
|
||||||
|
|
||||||
private func ownInstanceLoaded(_ instance: Instance) {
|
private func ownInstanceLoaded(_ instance: Instance) {
|
||||||
var snapshot = self.dataSource.snapshot()
|
var snapshot = self.dataSource.snapshot()
|
||||||
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
||||||
|
@ -198,6 +204,20 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
dataSource.apply(snapshot)
|
dataSource.apply(snapshot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func preferencesChanged() {
|
||||||
|
var snapshot = dataSource.snapshot()
|
||||||
|
let hasSection = snapshot.sectionIdentifiers.contains(.discover)
|
||||||
|
let hide = Preferences.shared.hideDiscover
|
||||||
|
if hasSection && hide {
|
||||||
|
snapshot.deleteSections([.discover])
|
||||||
|
} else if !hasSection && !hide {
|
||||||
|
addDiscoverSection(to: &snapshot)
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataSource.apply(snapshot)
|
||||||
|
}
|
||||||
|
|
||||||
private func deleteList(_ list: List, completion: @escaping (Bool) -> Void) {
|
private func deleteList(_ list: List, completion: @escaping (Bool) -> Void) {
|
||||||
let titleFormat = NSLocalizedString("Are you sure you want to delete the '%@' list?", comment: "delete list alert title")
|
let titleFormat = NSLocalizedString("Are you sure you want to delete the '%@' list?", comment: "delete list alert title")
|
||||||
let title = String(format: titleFormat, list.title)
|
let title = String(format: titleFormat, list.title)
|
||||||
|
|
|
@ -94,6 +94,7 @@ class MainSidebarViewController: UIViewController {
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedHashtags), name: .savedHashtagsChanged, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedHashtags), name: .savedHashtagsChanged, object: nil)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedInstances), name: .savedInstancesChanged, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedInstances), name: .savedInstancesChanged, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func select(item: Item, animated: Bool) {
|
func select(item: Item, animated: Bool) {
|
||||||
|
@ -145,12 +146,9 @@ class MainSidebarViewController: UIViewController {
|
||||||
snapshot.appendItems([
|
snapshot.appendItems([
|
||||||
.tab(.compose)
|
.tab(.compose)
|
||||||
], toSection: .compose)
|
], toSection: .compose)
|
||||||
if mastodonController.instanceFeatures.instanceType.isMastodon {
|
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
||||||
snapshot.insertSections([.discover], afterSection: .compose)
|
!Preferences.shared.hideDiscover {
|
||||||
snapshot.appendItems([
|
addDiscoverSection(to: &snapshot)
|
||||||
.trendingTags,
|
|
||||||
.profileDirectory,
|
|
||||||
], toSection: .discover)
|
|
||||||
}
|
}
|
||||||
dataSource.apply(snapshot, animatingDifferences: false)
|
dataSource.apply(snapshot, animatingDifferences: false)
|
||||||
|
|
||||||
|
@ -159,6 +157,14 @@ class MainSidebarViewController: UIViewController {
|
||||||
reloadSavedInstances()
|
reloadSavedInstances()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func addDiscoverSection(to snapshot: inout NSDiffableDataSourceSnapshot<Section, Item>) {
|
||||||
|
snapshot.insertSections([.discover], afterSection: .compose)
|
||||||
|
snapshot.appendItems([
|
||||||
|
.trendingTags,
|
||||||
|
.profileDirectory,
|
||||||
|
], toSection: .discover)
|
||||||
|
}
|
||||||
|
|
||||||
private func ownInstanceLoaded(_ instance: Instance) {
|
private func ownInstanceLoaded(_ instance: Instance) {
|
||||||
var snapshot = self.dataSource.snapshot()
|
var snapshot = self.dataSource.snapshot()
|
||||||
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
||||||
|
@ -231,6 +237,20 @@ class MainSidebarViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func preferencesChanged() {
|
||||||
|
var snapshot = dataSource.snapshot()
|
||||||
|
let hasSection = snapshot.sectionIdentifiers.contains(.discover)
|
||||||
|
let hide = Preferences.shared.hideDiscover
|
||||||
|
if hasSection && hide {
|
||||||
|
snapshot.deleteSections([.discover])
|
||||||
|
} else if !hasSection && !hide {
|
||||||
|
addDiscoverSection(to: &snapshot)
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dataSource.apply(snapshot)
|
||||||
|
}
|
||||||
|
|
||||||
// todo: deduplicate with ExploreViewController
|
// todo: deduplicate with ExploreViewController
|
||||||
private func showAddList() {
|
private func showAddList() {
|
||||||
|
|
|
@ -19,6 +19,7 @@ struct WellnessPrefsView: View {
|
||||||
if #available(iOS 15.0, *) {
|
if #available(iOS 15.0, *) {
|
||||||
disableInfiniteScrolling
|
disableInfiniteScrolling
|
||||||
}
|
}
|
||||||
|
hideDiscover
|
||||||
}
|
}
|
||||||
.listStyle(InsetGroupedListStyle())
|
.listStyle(InsetGroupedListStyle())
|
||||||
.navigationBarTitle(Text("Digital Wellness"))
|
.navigationBarTitle(Text("Digital Wellness"))
|
||||||
|
@ -57,6 +58,14 @@ struct WellnessPrefsView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var hideDiscover: some View {
|
||||||
|
Section(footer: Text("Do not show the Discover section (Trends, Profile Directory) of the Explore screen or sidebar.")) {
|
||||||
|
Toggle(isOn: $preferences.hideDiscover) {
|
||||||
|
Text("Hide Discover Section")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WellnessPrefsView_Previews: PreviewProvider {
|
struct WellnessPrefsView_Previews: PreviewProvider {
|
||||||
|
|
Loading…
Reference in New Issue