206 lines
11 KiB
Swift
206 lines
11 KiB
Swift
//
|
|
// LegacyPreferences.swift
|
|
// TuskerPreferences
|
|
//
|
|
// Created by Shadowfacts on 8/28/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Pachyderm
|
|
import Combine
|
|
|
|
public final class LegacyPreferences: Decodable {
|
|
|
|
init() {}
|
|
|
|
public required init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
self.theme = try container.decode(UIUserInterfaceStyle.self, forKey: .theme)
|
|
self.pureBlackDarkMode = try container.decodeIfPresent(Bool.self, forKey: .pureBlackDarkMode) ?? true
|
|
self.accentColor = try container.decodeIfPresent(AccentColor.self, forKey: .accentColor) ?? .default
|
|
self.avatarStyle = try container.decode(AvatarStyle.self, forKey: .avatarStyle)
|
|
self.hideCustomEmojiInUsernames = try container.decode(Bool.self, forKey: .hideCustomEmojiInUsernames)
|
|
self.showIsStatusReplyIcon = try container.decode(Bool.self, forKey: .showIsStatusReplyIcon)
|
|
self.alwaysShowStatusVisibilityIcon = try container.decode(Bool.self, forKey: .alwaysShowStatusVisibilityIcon)
|
|
self.hideActionsInTimeline = try container.decodeIfPresent(Bool.self, forKey: .hideActionsInTimeline) ?? false
|
|
self.showLinkPreviews = try container.decodeIfPresent(Bool.self, forKey: .showLinkPreviews) ?? true
|
|
self.leadingStatusSwipeActions = try container.decodeIfPresent([StatusSwipeAction].self, forKey: .leadingStatusSwipeActions) ?? leadingStatusSwipeActions
|
|
self.trailingStatusSwipeActions = try container.decodeIfPresent([StatusSwipeAction].self, forKey: .trailingStatusSwipeActions) ?? trailingStatusSwipeActions
|
|
self.widescreenNavigationMode = try container.decodeIfPresent(WidescreenNavigationMode.self, forKey: .widescreenNavigationMode) ?? Self.defaultWidescreenNavigationMode
|
|
self.underlineTextLinks = try container.decodeIfPresent(Bool.self, forKey: .underlineTextLinks) ?? false
|
|
self.showAttachmentsInTimeline = try container.decodeIfPresent(Bool.self, forKey: .showAttachmentsInTimeline) ?? true
|
|
|
|
if let existing = try? container.decode(Visibility.self, forKey: .defaultPostVisibility) {
|
|
self.defaultPostVisibility = .visibility(existing)
|
|
} else {
|
|
self.defaultPostVisibility = try container.decode(PostVisibility.self, forKey: .defaultPostVisibility)
|
|
}
|
|
self.defaultReplyVisibility = try container.decodeIfPresent(ReplyVisibility.self, forKey: .defaultReplyVisibility) ?? .sameAsPost
|
|
self.requireAttachmentDescriptions = try container.decode(Bool.self, forKey: .requireAttachmentDescriptions)
|
|
self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode)
|
|
self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger)
|
|
self.useTwitterKeyboard = try container.decodeIfPresent(Bool.self, forKey: .useTwitterKeyboard) ?? false
|
|
|
|
if let blurAllMedia = try? container.decodeIfPresent(Bool.self, forKey: .blurAllMedia) {
|
|
self.attachmentBlurMode = blurAllMedia ? .always : .useStatusSetting
|
|
} else {
|
|
self.attachmentBlurMode = try container.decode(AttachmentBlurMode.self, forKey: .attachmentBlurMode)
|
|
}
|
|
self.blurMediaBehindContentWarning = try container.decodeIfPresent(Bool.self, forKey: .blurMediaBehindContentWarning) ?? true
|
|
self.automaticallyPlayGifs = try container.decode(Bool.self, forKey: .automaticallyPlayGifs)
|
|
self.showUncroppedMediaInline = try container.decodeIfPresent(Bool.self, forKey: .showUncroppedMediaInline) ?? true
|
|
self.showAttachmentBadges = try container.decodeIfPresent(Bool.self, forKey: .showAttachmentBadges) ?? true
|
|
self.attachmentAltBadgeInverted = try container.decodeIfPresent(Bool.self, forKey: .attachmentAltBadgeInverted) ?? false
|
|
|
|
self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps)
|
|
self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
|
|
self.inAppSafariAutomaticReaderMode = try container.decode(Bool.self, forKey: .inAppSafariAutomaticReaderMode)
|
|
self.expandAllContentWarnings = try container.decodeIfPresent(Bool.self, forKey: .expandAllContentWarnings) ?? false
|
|
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.timelineSyncMode = try container.decodeIfPresent(TimelineSyncMode.self, forKey: .timelineSyncMode) ?? .icloud
|
|
self.hideReblogsInTimelines = try container.decodeIfPresent(Bool.self, forKey: .hideReblogsInTimelines) ?? false
|
|
self.hideRepliesInTimelines = try container.decodeIfPresent(Bool.self, forKey: .hideRepliesInTimelines) ?? false
|
|
|
|
self.showFavoriteAndReblogCounts = try container.decode(Bool.self, forKey: .showFavoriteAndReblogCounts)
|
|
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
|
|
self.grayscaleImages = try container.decodeIfPresent(Bool.self, forKey: .grayscaleImages) ?? false
|
|
self.disableInfiniteScrolling = try container.decodeIfPresent(Bool.self, forKey: .disableInfiniteScrolling) ?? false
|
|
self.hideTrends = try container.decodeIfPresent(Bool.self, forKey: .hideTrends) ?? false
|
|
|
|
self.statusContentType = try container.decode(StatusContentType.self, forKey: .statusContentType)
|
|
self.reportErrorsAutomatically = try container.decodeIfPresent(Bool.self, forKey: .reportErrorsAutomatically) ?? true
|
|
let featureFlagNames = (try? container.decodeIfPresent([String].self, forKey: .enabledFeatureFlags)) ?? []
|
|
self.enabledFeatureFlags = Set(featureFlagNames.compactMap(FeatureFlag.init))
|
|
|
|
self.hasShownLocalTimelineDescription = try container.decodeIfPresent(Bool.self, forKey: .hasShownLocalTimelineDescription) ?? false
|
|
self.hasShownFederatedTimelineDescription = try container.decodeIfPresent(Bool.self, forKey: .hasShownFederatedTimelineDescription) ?? false
|
|
}
|
|
|
|
// MARK: Appearance
|
|
@Published public var theme = UIUserInterfaceStyle.unspecified
|
|
@Published public var pureBlackDarkMode = true
|
|
@Published public var accentColor = AccentColor.default
|
|
@Published public var avatarStyle = AvatarStyle.roundRect
|
|
@Published public var hideCustomEmojiInUsernames = false
|
|
@Published public var showIsStatusReplyIcon = false
|
|
@Published public var alwaysShowStatusVisibilityIcon = false
|
|
@Published public var hideActionsInTimeline = false
|
|
@Published public var showLinkPreviews = true
|
|
@Published public var leadingStatusSwipeActions: [StatusSwipeAction] = [.favorite, .reblog]
|
|
@Published public var trailingStatusSwipeActions: [StatusSwipeAction] = [.reply, .share]
|
|
private static var defaultWidescreenNavigationMode = WidescreenNavigationMode.splitScreen
|
|
@Published public var widescreenNavigationMode = LegacyPreferences.defaultWidescreenNavigationMode
|
|
@Published public var underlineTextLinks = false
|
|
@Published public var showAttachmentsInTimeline = true
|
|
|
|
// MARK: Composing
|
|
@Published public var defaultPostVisibility = PostVisibility.serverDefault
|
|
@Published public var defaultReplyVisibility = ReplyVisibility.sameAsPost
|
|
@Published public var requireAttachmentDescriptions = false
|
|
@Published public var contentWarningCopyMode = ContentWarningCopyMode.asIs
|
|
@Published public var mentionReblogger = false
|
|
@Published public var useTwitterKeyboard = false
|
|
|
|
// MARK: Media
|
|
@Published public var attachmentBlurMode = AttachmentBlurMode.useStatusSetting
|
|
@Published public var blurMediaBehindContentWarning = true
|
|
@Published public var automaticallyPlayGifs = true
|
|
@Published public var showUncroppedMediaInline = true
|
|
@Published public var showAttachmentBadges = true
|
|
@Published public var attachmentAltBadgeInverted = false
|
|
|
|
// MARK: Behavior
|
|
@Published public var openLinksInApps = true
|
|
@Published public var useInAppSafari = true
|
|
@Published public var inAppSafariAutomaticReaderMode = false
|
|
@Published public var expandAllContentWarnings = false
|
|
@Published public var collapseLongPosts = true
|
|
@Published public var oppositeCollapseKeywords: [String] = []
|
|
@Published public var confirmBeforeReblog = false
|
|
@Published public var timelineStateRestoration = true
|
|
@Published public var timelineSyncMode = TimelineSyncMode.icloud
|
|
@Published public var hideReblogsInTimelines = false
|
|
@Published public var hideRepliesInTimelines = false
|
|
|
|
// MARK: Digital Wellness
|
|
@Published public var showFavoriteAndReblogCounts = true
|
|
@Published public var defaultNotificationsMode = NotificationsMode.allNotifications
|
|
@Published public var grayscaleImages = false
|
|
@Published public var disableInfiniteScrolling = false
|
|
@Published public var hideTrends = false
|
|
|
|
// MARK: Advanced
|
|
@Published public var statusContentType: StatusContentType = .plain
|
|
@Published public var reportErrorsAutomatically = true
|
|
@Published public var enabledFeatureFlags: Set<FeatureFlag> = []
|
|
|
|
// MARK:
|
|
@Published public var hasShownLocalTimelineDescription = false
|
|
@Published public var hasShownFederatedTimelineDescription = false
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case theme
|
|
case pureBlackDarkMode
|
|
case accentColor
|
|
case avatarStyle
|
|
case hideCustomEmojiInUsernames
|
|
case showIsStatusReplyIcon
|
|
case alwaysShowStatusVisibilityIcon
|
|
case hideActionsInTimeline
|
|
case showLinkPreviews
|
|
case leadingStatusSwipeActions
|
|
case trailingStatusSwipeActions
|
|
case widescreenNavigationMode
|
|
case underlineTextLinks
|
|
case showAttachmentsInTimeline
|
|
|
|
case defaultPostVisibility
|
|
case defaultReplyVisibility
|
|
case requireAttachmentDescriptions
|
|
case contentWarningCopyMode
|
|
case mentionReblogger
|
|
case useTwitterKeyboard
|
|
|
|
case blurAllMedia // only used for migration
|
|
case attachmentBlurMode
|
|
case blurMediaBehindContentWarning
|
|
case automaticallyPlayGifs
|
|
case showUncroppedMediaInline
|
|
case showAttachmentBadges
|
|
case attachmentAltBadgeInverted
|
|
|
|
case openLinksInApps
|
|
case useInAppSafari
|
|
case inAppSafariAutomaticReaderMode
|
|
case expandAllContentWarnings
|
|
case collapseLongPosts
|
|
case oppositeCollapseKeywords
|
|
case confirmBeforeReblog
|
|
case timelineStateRestoration
|
|
case timelineSyncMode
|
|
case hideReblogsInTimelines
|
|
case hideRepliesInTimelines
|
|
|
|
case showFavoriteAndReblogCounts
|
|
case defaultNotificationsType
|
|
case grayscaleImages
|
|
case disableInfiniteScrolling
|
|
case hideTrends = "hideDiscover"
|
|
|
|
case statusContentType
|
|
case reportErrorsAutomatically
|
|
case enabledFeatureFlags
|
|
|
|
case hasShownLocalTimelineDescription
|
|
case hasShownFederatedTimelineDescription
|
|
}
|
|
|
|
}
|
|
|
|
extension UIUserInterfaceStyle: Codable {}
|