diff --git a/appdb/Other/Base.lproj/LaunchScreen.storyboard b/appdb/Other/Base.lproj/LaunchScreen.storyboard index 65070776..3ffa3655 100644 --- a/appdb/Other/Base.lproj/LaunchScreen.storyboard +++ b/appdb/Other/Base.lproj/LaunchScreen.storyboard @@ -1,18 +1,15 @@ - - - - + + - + - @@ -21,17 +18,17 @@ - + + - @@ -47,6 +44,7 @@ + diff --git a/appdb/Other/Info.plist b/appdb/Other/Info.plist index 17dc8ca4..2e650200 100644 --- a/appdb/Other/Info.plist +++ b/appdb/Other/Info.plist @@ -99,7 +99,7 @@ UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance - + UTImportedTypeDeclarations diff --git "a/appdb/Resources/\342\200\242 AdaptiveUIAlertController/AdaptiveUIAlertController.swift" "b/appdb/Resources/\342\200\242 AdaptiveUIAlertController/AdaptiveUIAlertController.swift" index 9687f01f..d1ca1d7b 100644 --- "a/appdb/Resources/\342\200\242 AdaptiveUIAlertController/AdaptiveUIAlertController.swift" +++ "b/appdb/Resources/\342\200\242 AdaptiveUIAlertController/AdaptiveUIAlertController.swift" @@ -43,6 +43,7 @@ extension UIAlertController { public convenience init(title: String?, message: String?, preferredStyle: UIAlertController.Style, adaptive: Bool) { self.init(title: title, message: message, preferredStyle: preferredStyle) + if #available(iOS 13.0, *) { return } guard adaptive, !Global.isIpad else { return } let blurStyle: UIBlurEffect.Style = Themes.isNight ? .dark : .light @@ -64,6 +65,7 @@ extension UIAlertController { open override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() + if #available(iOS 13.0, *) { return } if !Global.isIpad { visualEffectView?.effect = UIBlurEffect(style: blurStyle) cancelActionView?.backgroundColor = cancelButtonColor diff --git a/appdb/Startup/AppDelegate.swift b/appdb/Startup/AppDelegate.swift index d8f50770..6ddb1123 100644 --- a/appdb/Startup/AppDelegate.swift +++ b/appdb/Startup/AppDelegate.swift @@ -34,6 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegat Global.deleteEventualKeychainData() Global.restoreLanguage() Themes.restoreLastTheme() + Global.refreshAppearanceForCurrentTheme() Preferences.set(.adBannerHeight, to: 0) // Set main tint color @@ -41,7 +42,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegat self.window?.theme_tintColor = Color.mainTint // Theme Status Bar - UIApplication.shared.theme_setStatusBarStyle([.default, .lightContent, .lightContent], animated: true) + if #available(iOS 13.0, *) { + UIApplication.shared.theme_setStatusBarStyle([.darkContent, .lightContent, .lightContent], animated: true) + } else { + UIApplication.shared.theme_setStatusBarStyle([.default, .lightContent, .lightContent], animated: true) + } // Theme navigation bar let navigationBar = UINavigationBar.appearance() @@ -53,7 +58,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegat } navigationBar.theme_barStyle = [.default, .black, .black] navigationBar.theme_tintColor = Color.mainTint - navigationBar.theme_titleTextAttributes = ThemeDictionaryPicker.pickerWithAttributes(titleAttributes) + navigationBar.theme_titleTextAttributes = ThemeStringAttributesPicker.pickerWithAttributes(titleAttributes) // Theme Tab Bar let tabBar = UITabBar.appearance() @@ -71,6 +76,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegat if let sdk = STAStartAppSDK.sharedInstance() { sdk.appID = AdHelper.appID sdk.devID = AdHelper.devID + sdk.disableReturnAd() } } diff --git a/appdb/Startup/Extensions.swift b/appdb/Startup/Extensions.swift index 98ac5bb7..cf8d2cfd 100644 --- a/appdb/Startup/Extensions.swift +++ b/appdb/Startup/Extensions.swift @@ -11,6 +11,8 @@ import Cartography import Kanna import Localize_Swift import DeepDiff +import SwiftTheme +import Static // Delay function func delay(_ delay: Double, closure: @escaping () -> Void) { @@ -280,6 +282,101 @@ extension NSTextAttachment { } } +// MARK: - UITableViewCell setEnabled +extension UITableViewCell { + func setEnabled(on: Bool) { + isUserInteractionEnabled = on + for view in contentView.subviews { + view.isUserInteractionEnabled = on + view.alpha = on ? 1 : 0.5 + } + } +} + +// MARK: - traitCollectionDidChange + +extension UIViewController { + @available(iOS 13.0, *) + func updateAppearance(style: UIUserInterfaceStyle) { + if Preferences.followSystemAppearance { + switch style { + case .light: + if Themes.isNight { + Themes.switchTo(theme: .light) + } + default: + if !Themes.isNight { + Themes.switchTo(theme: Preferences.shouldSwitchToDarkerTheme ? .darker : .dark) + } + } + } + Global.refreshAppearanceForCurrentTheme() + } +} + +extension TableViewController { + open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + guard #available(iOS 13.0, *), traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else { return } + updateAppearance(style: traitCollection.userInterfaceStyle) + if let self = self as? Settings { + self.refreshSources() + } + } +} + +extension UINavigationController { + override public func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + guard #available(iOS 13.0, *), traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else { return } + updateAppearance(style: traitCollection.userInterfaceStyle) + } +} + +extension UITabBarController { + open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + guard #available(iOS 13.0, *), traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else { return } + updateAppearance(style: traitCollection.userInterfaceStyle) + } +} + +extension UITableViewController { + open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + guard #available(iOS 13.0, *), traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else { return } + updateAppearance(style: traitCollection.userInterfaceStyle) + if self is ThemeChooser { + tableView.reloadData() + } + } +} + +extension UICollectionViewController { + open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + guard #available(iOS 13.0, *), traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) else { return } + updateAppearance(style: traitCollection.userInterfaceStyle) + } +} + +// MARK: - Glue for UITableViewCell iOS 13 background color changes +extension UITableViewCell { + func setBackgroundColor(_ color: ThemeColorPicker) { + if #available(iOS 13.0, *) { + contentView.backgroundColor = nil + contentView.isOpaque = false + } else { + contentView.theme_backgroundColor = color + } + } +} + // MARK: - UIApplication top View Controller & top Navigation View Controller extension UIApplication { diff --git a/appdb/Startup/Global.swift b/appdb/Startup/Global.swift index cb4e27b3..d3b9efe1 100644 --- a/appdb/Startup/Global.swift +++ b/appdb/Startup/Global.swift @@ -38,6 +38,32 @@ enum Global { } } + static var isDarkSystemAppearance: Bool { + if #available(iOS 13.0, *) { + return UIScreen.main.traitCollection.userInterfaceStyle == .dark + } else { + return false + } + } + + static func refreshAppearanceForCurrentTheme() { + if #available(iOS 13.0, *) { + var style: UIUserInterfaceStyle = Themes.current == .light ? .light : .dark + if Preferences.followSystemAppearance { style = .unspecified } + if UINavigationBar.appearance().overrideUserInterfaceStyle != style { + UINavigationBar.appearance().overrideUserInterfaceStyle = style + UITabBar.appearance().overrideUserInterfaceStyle = style + UISegmentedControl.appearance().overrideUserInterfaceStyle = style + UIToolbar.appearance().overrideUserInterfaceStyle = style + UIView.appearance().overrideUserInterfaceStyle = style + UIWindow.appearance().overrideUserInterfaceStyle = style + UILabel.appearance().overrideUserInterfaceStyle = style + UIButton.appearance().overrideUserInterfaceStyle = style + UITableViewHeaderFooterView.appearance().overrideUserInterfaceStyle = style + } + } + } + // Returns App Version static let appVersion: String = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? tilde diff --git a/appdb/Startup/Preferences.swift b/appdb/Startup/Preferences.swift index 67c09a92..841cfdeb 100644 --- a/appdb/Startup/Preferences.swift +++ b/appdb/Startup/Preferences.swift @@ -10,7 +10,7 @@ import Foundation // Non sensitive data can be stored in UserDefaults extension Defaults.Keys { - static let theme = Key("theme", default: 0) + static let theme = Key("theme", default: Global.isDarkSystemAppearance ? 1 : 0) static let didSpecifyPreferredLanguage = Key("didSpecifyPreferredLanguage", default: false) static let appsync = Key("appsync", default: false) static let ignoreCompatibility = Key("ignoreCompatibility", default: false) @@ -21,6 +21,8 @@ extension Defaults.Keys { static let ignoredUpdateableApps = Key<[IgnoredApp]>("ignoredUpdateableApps", default: []) static let resumeQueuedApps = Key<[RequestedApp]>("resumeQueuedApps", default: []) static let genres = Key<[Genre]>("genres", default: []) + static let followSystemAppearance = Key("followSystemAppearance", default: true) + static let shouldSwitchToDarkerTheme = Key("shouldSwitchToDarkerTheme", default: false) } // Sensitive data is stored in Keychain @@ -115,6 +117,14 @@ enum Preferences { static var genres: [Genre] { return defaults[.genres] } + + static var followSystemAppearance: Bool { + return defaults[.followSystemAppearance] + } + + static var shouldSwitchToDarkerTheme: Bool { + return defaults[.shouldSwitchToDarkerTheme] + } } extension Preferences { @@ -153,6 +163,8 @@ extension Preferences { UserDefaults.standard.removeObject(forKey: Defaults.Keys.changeBundleBeforeUpload.name) UserDefaults.standard.removeObject(forKey: Defaults.Keys.ignoredUpdateableApps.name) UserDefaults.standard.removeObject(forKey: Defaults.Keys.resumeQueuedApps.name) + UserDefaults.standard.removeObject(forKey: Defaults.Keys.followSystemAppearance.name) + UserDefaults.standard.removeObject(forKey: Defaults.Keys.shouldSwitchToDarkerTheme.name) } // Remove secure keys diff --git a/appdb/Startup/TabBarController.swift b/appdb/Startup/TabBarController.swift index 9b7682b9..26c72db6 100644 --- a/appdb/Startup/TabBarController.swift +++ b/appdb/Startup/TabBarController.swift @@ -98,6 +98,7 @@ extension TabBarController: STABannerDelegateProtocol { banner.leading ~== banner.superview!.leading banner.trailing ~== banner.superview!.trailing banner.bottom ~== banner.superview!.bottom + (banner.top ~== banner.superview!.top) ~ Global.notMaxPriority } } diff --git a/appdb/Startup/Themes.swift b/appdb/Startup/Themes.swift index 545955ac..93d311b8 100644 --- a/appdb/Startup/Themes.swift +++ b/appdb/Startup/Themes.swift @@ -42,7 +42,15 @@ enum Themes: Int, CaseIterable { } static func restoreLastTheme() { - guard let theme = Themes(rawValue: Preferences.theme) else { return } - switchTo(theme: theme) + if Preferences.followSystemAppearance { + if Global.isDarkSystemAppearance { + switchTo(theme: Preferences.shouldSwitchToDarkerTheme ? .darker : .dark) + } else { + switchTo(theme: .light) + } + } else { + guard let theme = Themes(rawValue: Preferences.theme) else { return } + switchTo(theme: theme) + } } } diff --git a/appdb/Tabs/Featured/Categories/CategoryCell.swift b/appdb/Tabs/Featured/Categories/CategoryCell.swift index e8d5a60d..077adaf3 100644 --- a/appdb/Tabs/Featured/Categories/CategoryCell.swift +++ b/appdb/Tabs/Featured/Categories/CategoryCell.swift @@ -28,7 +28,7 @@ class CategoryCell: UITableViewCell { separatorInset.left = Global.Size.margin.value // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray let bgColorView = UIView() bgColorView.theme_backgroundColor = Color.cellSelectionColor diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Changelog/Details+Changelog.swift b/appdb/Tabs/Featured/Details/Cells/Details/Changelog/Details+Changelog.swift index 877e07bf..37aacd10 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Changelog/Details+Changelog.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Changelog/Details+Changelog.swift @@ -38,7 +38,7 @@ class DetailsChangelog: DetailsCell { addSeparator() theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) title = UILabel() title.theme_textColor = Color.title diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Description/Details+Description.swift b/appdb/Tabs/Featured/Details/Cells/Details/Description/Details+Description.swift index 8c92e983..f7c93896 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Description/Details+Description.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Description/Details+Description.swift @@ -36,7 +36,7 @@ class DetailsDescription: DetailsCell { addSeparator() theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) title = UILabel() title.theme_textColor = Color.title diff --git a/appdb/Tabs/Featured/Details/Cells/Details/ExternalLink/Details+ExternalLink.swift b/appdb/Tabs/Featured/Details/Cells/Details/ExternalLink/Details+ExternalLink.swift index 3830cb07..026b1014 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/ExternalLink/Details+ExternalLink.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/ExternalLink/Details+ExternalLink.swift @@ -32,7 +32,7 @@ class DetailsExternalLink: DetailsCell { self.devName = devName theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) let bgColorView = UIView() bgColorView.theme_backgroundColor = Color.cellSelectionColor diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Information/Details+Information.swift b/appdb/Tabs/Featured/Details/Cells/Details/Information/Details+Information.swift index 7803a040..eafe3ec4 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Information/Details+Information.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Information/Details+Information.swift @@ -50,7 +50,7 @@ class DetailsInformation: DetailsCell { addSeparator() theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) title = UILabel() title.theme_textColor = Color.title diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Publisher/Details+Publisher.swift b/appdb/Tabs/Featured/Details/Cells/Details/Publisher/Details+Publisher.swift index 585d117b..d5c79550 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Publisher/Details+Publisher.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Publisher/Details+Publisher.swift @@ -23,7 +23,7 @@ class DetailsPublisher: DetailsCell { separatorInset.left = 10000 layoutMargins = .zero theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) label = UILabel() label.theme_textColor = Color.copyrightText diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Related/Details+Related.swift b/appdb/Tabs/Featured/Details/Cells/Details/Related/Details+Related.swift index 0ced4640..65da81bb 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Related/Details+Related.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Related/Details+Related.swift @@ -72,7 +72,7 @@ class DetailsRelated: DetailsCell { if !relatedContent.isEmpty { theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) title = UILabel() title.theme_textColor = Color.title diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Screenshots/Screenshots/Details+Screenshots.swift b/appdb/Tabs/Featured/Details/Cells/Details/Screenshots/Screenshots/Details+Screenshots.swift index 2c58afb9..9ff587c1 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Screenshots/Screenshots/Details+Screenshots.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Screenshots/Screenshots/Details+Screenshots.swift @@ -101,7 +101,7 @@ class DetailsScreenshots: DetailsCell { collectionView.theme_backgroundColor = Color.veryVeryLightGray theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) contentView.addSubview(collectionView) diff --git a/appdb/Tabs/Featured/Details/Cells/Details/Tweaked Notice/Details+TweakedNotice.swift b/appdb/Tabs/Featured/Details/Cells/Details/Tweaked Notice/Details+TweakedNotice.swift index 3a679baf..94835285 100644 --- a/appdb/Tabs/Featured/Details/Cells/Details/Tweaked Notice/Details+TweakedNotice.swift +++ b/appdb/Tabs/Featured/Details/Cells/Details/Tweaked Notice/Details+TweakedNotice.swift @@ -40,7 +40,7 @@ class DetailsTweakedNotice: DetailsCell { if !trackid.isEmpty, trackid != "0" { theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) title = UILabel() title.theme_textColor = Color.title diff --git a/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadCell.swift b/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadCell.swift index 1bc0b497..b75064ee 100644 --- a/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadCell.swift +++ b/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadCell.swift @@ -52,7 +52,7 @@ class DetailsDownload: DetailsCell { addSeparator(full: true) // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray selectedBackgroundView = bgColorView @@ -144,7 +144,7 @@ class DetailsDownloadUnified: DetailsCell { addSeparator(full: true) // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray selectedBackgroundView = bgColorView diff --git a/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadEmptyCell.swift b/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadEmptyCell.swift index d1359ecf..fbae33a7 100644 --- a/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadEmptyCell.swift +++ b/appdb/Tabs/Featured/Details/Cells/Download/Details+DownloadEmptyCell.swift @@ -24,7 +24,7 @@ class DetailsDownloadEmptyCell: DetailsCell { selectionStyle = .none // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray error = UILabel() diff --git a/appdb/Tabs/Featured/Details/Cells/Header/Details+Header.swift b/appdb/Tabs/Featured/Details/Cells/Header/Details+Header.swift index 0d635be6..92093fc0 100644 --- a/appdb/Tabs/Featured/Details/Cells/Header/Details+Header.swift +++ b/appdb/Tabs/Featured/Details/Cells/Header/Details+Header.swift @@ -52,7 +52,7 @@ class DetailsHeader: DetailsCell { //UI theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) // Name name = UILabel() diff --git a/appdb/Tabs/Featured/Details/Cells/Reviews/Details+Review.swift b/appdb/Tabs/Featured/Details/Cells/Reviews/Details+Review.swift index 664a5ae3..f19894b0 100644 --- a/appdb/Tabs/Featured/Details/Cells/Reviews/Details+Review.swift +++ b/appdb/Tabs/Featured/Details/Cells/Reviews/Details+Review.swift @@ -37,7 +37,7 @@ class DetailsReview: DetailsCell { addSeparator() // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray // Name diff --git a/appdb/Tabs/Featured/Featured/Cells/Copyright.swift b/appdb/Tabs/Featured/Featured/Cells/Copyright.swift index ece64309..365681e4 100644 --- a/appdb/Tabs/Featured/Featured/Cells/Copyright.swift +++ b/appdb/Tabs/Featured/Featured/Cells/Copyright.swift @@ -22,7 +22,7 @@ class Copyright: FeaturedCell { separatorInset.left = 10000 layoutMargins = .zero theme_backgroundColor = Color.tableViewBackgroundColor - contentView.theme_backgroundColor = Color.tableViewBackgroundColor + setBackgroundColor(Color.tableViewBackgroundColor) // Hide ugly white line on iOS 8 layer.theme_borderColor = Color.tableViewCGBackgroundColor diff --git a/appdb/Tabs/Featured/Featured/Cells/Dummy.swift b/appdb/Tabs/Featured/Featured/Cells/Dummy.swift index e9cd3f9c..fa3a55e4 100644 --- a/appdb/Tabs/Featured/Featured/Cells/Dummy.swift +++ b/appdb/Tabs/Featured/Featured/Cells/Dummy.swift @@ -22,6 +22,6 @@ class Dummy: FeaturedCell { separatorInset.left = 0 layoutMargins.left = 0 theme_backgroundColor = Color.tableViewBackgroundColor - contentView.theme_backgroundColor = Color.tableViewBackgroundColor + setBackgroundColor(Color.tableViewBackgroundColor) } } diff --git a/appdb/Tabs/Featured/See All/SeeAllCell+WithStars.swift b/appdb/Tabs/Featured/See All/SeeAllCell+WithStars.swift index 3b8521f9..c045ff10 100644 --- a/appdb/Tabs/Featured/See All/SeeAllCell+WithStars.swift +++ b/appdb/Tabs/Featured/See All/SeeAllCell+WithStars.swift @@ -64,7 +64,7 @@ class SeeAllCellWithStars: UITableViewCell { private func sharedInit() { //UI theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) let bgColorView = UIView() bgColorView.theme_backgroundColor = Color.cellSelectionColor selectedBackgroundView = bgColorView diff --git a/appdb/Tabs/Featured/See All/SeeAllCell.swift b/appdb/Tabs/Featured/See All/SeeAllCell.swift index 44b845e0..be14c52c 100644 --- a/appdb/Tabs/Featured/See All/SeeAllCell.swift +++ b/appdb/Tabs/Featured/See All/SeeAllCell.swift @@ -72,7 +72,7 @@ class SeeAllCell: UITableViewCell { private func sharedInit() { //UI theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) let bgColorView = UIView() bgColorView.theme_backgroundColor = Color.cellSelectionColor selectedBackgroundView = bgColorView diff --git a/appdb/Tabs/Featured/Update Prompt/AppUpdateHeader.swift b/appdb/Tabs/Featured/Update Prompt/AppUpdateHeader.swift index 09878531..4d257342 100644 --- a/appdb/Tabs/Featured/Update Prompt/AppUpdateHeader.swift +++ b/appdb/Tabs/Featured/Update Prompt/AppUpdateHeader.swift @@ -48,7 +48,7 @@ class AppUpdateHeader: UITableViewCell { //UI theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) // Name name = UILabel() diff --git a/appdb/Tabs/Search/Search+Extension.swift b/appdb/Tabs/Search/Search+Extension.swift index 12cbe3fb..cb4c6d12 100644 --- a/appdb/Tabs/Search/Search+Extension.swift +++ b/appdb/Tabs/Search/Search+Extension.swift @@ -398,7 +398,7 @@ class SmallTableViewController: UITableViewController { default: cell.textLabel?.text = "Books".localized() } cell.accessoryType = indexPath.row == selectedType ? .checkmark : .none - cell.contentView.theme_backgroundColor = Color.veryVeryLightGray + cell.setBackgroundColor(Color.veryVeryLightGray) cell.theme_backgroundColor = Color.veryVeryLightGray cell.textLabel?.theme_textColor = Color.title cell.selectedBackgroundView = bgColorView diff --git a/appdb/Tabs/Search/SuggestionsWhileTyping.swift b/appdb/Tabs/Search/SuggestionsWhileTyping.swift index ac57a099..93403f43 100644 --- a/appdb/Tabs/Search/SuggestionsWhileTyping.swift +++ b/appdb/Tabs/Search/SuggestionsWhileTyping.swift @@ -123,7 +123,7 @@ class SearchSuggestionCell: UITableViewCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray textLabel?.theme_textColor = Color.title selectedBackgroundView = bgColorView diff --git a/appdb/Tabs/Settings/Acknowledgements/Acknowledgements.swift b/appdb/Tabs/Settings/Acknowledgements/Acknowledgements.swift index a0352c94..faca3da4 100644 --- a/appdb/Tabs/Settings/Acknowledgements/Acknowledgements.swift +++ b/appdb/Tabs/Settings/Acknowledgements/Acknowledgements.swift @@ -113,7 +113,7 @@ class Acknowledgements: LoadingTableView { cell.textLabel?.font = .systemFont(ofSize: (15 ~~ 14)) cell.textLabel?.theme_textColor = Color.darkGray cell.textLabel?.makeDynamicFont() - cell.contentView.theme_backgroundColor = Color.veryVeryLightGray + cell.setBackgroundColor(Color.veryVeryLightGray) cell.theme_backgroundColor = Color.veryVeryLightGray cell.textLabel?.numberOfLines = 0 cell.selectionStyle = .none diff --git a/appdb/Tabs/Settings/Device Status/DeviceStatusCell.swift b/appdb/Tabs/Settings/Device Status/DeviceStatusCell.swift index 49947dc5..d6c4dcac 100644 --- a/appdb/Tabs/Settings/Device Status/DeviceStatusCell.swift +++ b/appdb/Tabs/Settings/Device Status/DeviceStatusCell.swift @@ -38,7 +38,7 @@ class DeviceStatusCell: UITableViewCell { super.init(style: style, reuseIdentifier: reuseIdentifier) // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray // Add separator diff --git a/appdb/Tabs/Settings/Language Chooser/LanguageChooser.swift b/appdb/Tabs/Settings/Language Chooser/LanguageChooser.swift index f8181665..70a2b6ae 100644 --- a/appdb/Tabs/Settings/Language Chooser/LanguageChooser.swift +++ b/appdb/Tabs/Settings/Language Chooser/LanguageChooser.swift @@ -90,7 +90,7 @@ class LanguageChooser: UITableViewController { cell.textLabel?.theme_textColor = Color.title cell.textLabel?.makeDynamicFont() cell.accessoryType = language == currentLanguage ? .checkmark : .none - cell.contentView.theme_backgroundColor = Color.veryVeryLightGray + cell.setBackgroundColor(Color.veryVeryLightGray) cell.theme_backgroundColor = Color.veryVeryLightGray cell.selectedBackgroundView = bgColorView return cell diff --git a/appdb/Tabs/Settings/News/News+Detail+HTMLCell.swift b/appdb/Tabs/Settings/News/News+Detail+HTMLCell.swift index 4cf836c8..b1da8668 100644 --- a/appdb/Tabs/Settings/News/News+Detail+HTMLCell.swift +++ b/appdb/Tabs/Settings/News/News+Detail+HTMLCell.swift @@ -21,7 +21,7 @@ class NewsDetailHTMLCell: UITableViewCell { super.init(style: style, reuseIdentifier: reuseIdentifier) // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray selectionStyle = .none diff --git a/appdb/Tabs/Settings/News/News+Detail+TitleDateCell.swift b/appdb/Tabs/Settings/News/News+Detail+TitleDateCell.swift index e7efa7df..0768fc14 100644 --- a/appdb/Tabs/Settings/News/News+Detail+TitleDateCell.swift +++ b/appdb/Tabs/Settings/News/News+Detail+TitleDateCell.swift @@ -22,7 +22,7 @@ class NewsDetailTitleDateCell: UITableViewCell { super.init(style: style, reuseIdentifier: reuseIdentifier) // UI - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) theme_backgroundColor = Color.veryVeryLightGray selectionStyle = .none diff --git a/appdb/Tabs/Settings/Settings+StaticCells.swift b/appdb/Tabs/Settings/Settings+StaticCells.swift index 69514e58..e508aff2 100644 --- a/appdb/Tabs/Settings/Settings+StaticCells.swift +++ b/appdb/Tabs/Settings/Settings+StaticCells.swift @@ -20,7 +20,7 @@ class SimpleStaticCell: UITableViewCell, Cell { super.init(style: .value1, reuseIdentifier: reuseIdentifier) theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) textLabel?.makeDynamicFont() textLabel?.theme_textColor = Color.title @@ -58,7 +58,7 @@ final class SimpleSubtitleCell: UITableViewCell, Cell { super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) let bgColorView = UIView() bgColorView.theme_backgroundColor = Color.cellSelectionColor @@ -103,8 +103,10 @@ final class SimpleStaticButtonCell: UITableViewCell, Cell { textLabel?.textAlignment = .center textLabel?.text = row.text?.uppercased() - theme_backgroundColor = row.context?["bgColor"] as? ThemeColorPicker - contentView.theme_backgroundColor = row.context?["bgColor"] as? ThemeColorPicker + if let color = row.context?["bgColor"] as? ThemeColorPicker { + theme_backgroundColor = color + setBackgroundColor(color) + } let bgColorView = UIView() bgColorView.theme_backgroundColor = row.context?["bgHover"] as? ThemeColorPicker @@ -141,7 +143,7 @@ final class SimpleStaticPROStatusCell: UITableViewCell, Cell { expirationLabel.textAlignment = .right theme_backgroundColor = Color.veryVeryLightGray - contentView.theme_backgroundColor = Color.veryVeryLightGray + setBackgroundColor(Color.veryVeryLightGray) textLabel?.makeDynamicFont() textLabel?.theme_textColor = Color.title diff --git a/appdb/Tabs/Settings/Theme Chooser/ThemeChooser.swift b/appdb/Tabs/Settings/Theme Chooser/ThemeChooser.swift index 8c8b00ef..7731c610 100644 --- a/appdb/Tabs/Settings/Theme Chooser/ThemeChooser.swift +++ b/appdb/Tabs/Settings/Theme Chooser/ThemeChooser.swift @@ -15,6 +15,7 @@ protocol ChangedTheme: class { class ThemeChooser: UITableViewController { weak var changedThemeDelegate: ChangedTheme? + var followSystemAppearanceToggle: UISwitch? private var bgColorView: UIView = { let bgColorView = UIView() @@ -24,6 +25,10 @@ class ThemeChooser: UITableViewController { convenience init() { self.init(style: .grouped) + + if #available(iOS 13.0, *) { + followSystemAppearanceToggle = UISwitch() + } } override func viewDidLoad() { @@ -46,38 +51,109 @@ class ThemeChooser: UITableViewController { let dismissButton = UIBarButtonItem(title: "Dismiss".localized(), style: .done, target: self, action: #selector(self.dismissAnimated)) self.navigationItem.rightBarButtonItems = [dismissButton] } + + disableUserInteractionIfNeeded() } @objc func dismissAnimated() { dismiss(animated: true) } override func numberOfSections(in tableView: UITableView) -> Int { - return 1 + if #available(iOS 13.0, *) { + return 2 + } else { + return 1 + } } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return Themes.allCases.count + if #available(iOS 13.0, *), section > 0 { + return 1 + } else { + return Themes.allCases.count + } } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) - cell.textLabel?.text = Themes(rawValue: indexPath.row)?.toString - cell.textLabel?.makeDynamicFont() - cell.textLabel?.theme_textColor = Color.title - cell.accessoryType = Themes.current == Themes(rawValue: indexPath.row) ? .checkmark : .none - cell.contentView.theme_backgroundColor = Color.veryVeryLightGray - cell.theme_backgroundColor = Color.veryVeryLightGray - cell.selectedBackgroundView = bgColorView - return cell + if #available(iOS 13.0, *), indexPath.section > 0 { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) + cell.textLabel?.text = "Follow System Appearance".localized() // todo localize + cell.textLabel?.makeDynamicFont() + cell.textLabel?.theme_textColor = Color.title + cell.setBackgroundColor(Color.veryVeryLightGray) + cell.accessoryView = followSystemAppearanceToggle + followSystemAppearanceToggle?.setOn(Preferences.followSystemAppearance, animated: false) + followSystemAppearanceToggle?.addTarget(self, action: #selector(appearanceToggleValueChanged), for: .valueChanged) + cell.theme_backgroundColor = Color.veryVeryLightGray + cell.selectedBackgroundView = bgColorView + return cell + } else { + let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) + cell.textLabel?.text = Themes(rawValue: indexPath.row)?.toString + cell.textLabel?.makeDynamicFont() + cell.textLabel?.theme_textColor = Color.title + cell.accessoryType = Themes.current == Themes(rawValue: indexPath.row) ? .checkmark : .none + cell.setBackgroundColor(Color.veryVeryLightGray) + cell.theme_backgroundColor = Color.veryVeryLightGray + cell.selectedBackgroundView = bgColorView + return cell + } } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { guard let theme = Themes(rawValue: indexPath.row) else { return } - Themes.switchTo(theme: theme) - changedThemeDelegate?.changedTheme() - tableView.reloadData() + if theme == .dark { + Preferences.set(.shouldSwitchToDarkerTheme, to: false) + } else if theme == .darker { + Preferences.set(.shouldSwitchToDarkerTheme, to: true) + } + reloadTheme(theme: theme) } override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - return "Available Themes".localized() + if #available(iOS 13.0, *), section > 0 { + return "" + } else { + return "Available Themes".localized() + } + } + + @objc func appearanceToggleValueChanged(sender: UISwitch) { + Preferences.set(.followSystemAppearance, to: sender.isOn) + + disableUserInteractionIfNeeded() + + debugLog("system appearance: \(Global.isDarkSystemAppearance ? "Dark" : "Light")") + + if Preferences.followSystemAppearance { + switch Themes.current { + case .dark, .darker: + if !Global.isDarkSystemAppearance { + reloadTheme(theme: .light) + } + default: + if Global.isDarkSystemAppearance { + reloadTheme(theme: Preferences.shouldSwitchToDarkerTheme ? .darker : .dark) + } + } + } + } + + func disableUserInteractionIfNeeded() { + if #available(iOS 13.0, *) { + (0..