Skip to content

Commit

Permalink
ios 13 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
nedley committed Sep 29, 2019
1 parent 4708fa4 commit 2902374
Show file tree
Hide file tree
Showing 38 changed files with 290 additions and 62 deletions.
14 changes: 6 additions & 8 deletions appdb/Other/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="NoU-Zh-kTp">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="NoU-Zh-kTp">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
Expand All @@ -21,17 +18,17 @@
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.93725490196078431" green="0.93725490196078431" blue="0.95686274509803915" alpha="1" colorSpace="calibratedRGB"/>
<color key="backgroundColor" systemColor="systemGroupedBackgroundColor" red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" id="Ubq-c5-nI0"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="991.20000000000005" y="374.66266866566718"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="pqs-uG-NRo">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="yGx-uc-Ye9" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController automaticallyAdjustsScrollViewInsets="NO" toolbarHidden="NO" id="NoU-Zh-kTp" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="HbO-UD-TKt">
Expand All @@ -47,6 +44,7 @@
<segue destination="01J-lp-oVM" kind="relationship" relationship="rootViewController" id="oWI-Fs-2ut"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="yGx-uc-Ye9" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="52" y="374.66266866566718"/>
</scene>
Expand Down
2 changes: 1 addition & 1 deletion appdb/Other/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<true/>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions appdb/Startup/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegat
Global.deleteEventualKeychainData()
Global.restoreLanguage()
Themes.restoreLastTheme()
Global.refreshAppearanceForCurrentTheme()
Preferences.set(.adBannerHeight, to: 0)

// Set main tint color
self.window?.theme_backgroundColor = Color.tableViewBackgroundColor
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()
Expand All @@ -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()
Expand All @@ -71,6 +76,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UITabBarControllerDelegat
if let sdk = STAStartAppSDK.sharedInstance() {
sdk.appID = AdHelper.appID
sdk.devID = AdHelper.devID
sdk.disableReturnAd()
}
}

Expand Down
97 changes: 97 additions & 0 deletions appdb/Startup/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions appdb/Startup/Global.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion appdb/Startup/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

// Non sensitive data can be stored in UserDefaults
extension Defaults.Keys {
static let theme = Key<Int>("theme", default: 0)
static let theme = Key<Int>("theme", default: Global.isDarkSystemAppearance ? 1 : 0)
static let didSpecifyPreferredLanguage = Key<Bool>("didSpecifyPreferredLanguage", default: false)
static let appsync = Key<Bool>("appsync", default: false)
static let ignoreCompatibility = Key<Bool>("ignoreCompatibility", default: false)
Expand All @@ -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<Bool>("followSystemAppearance", default: true)
static let shouldSwitchToDarkerTheme = Key<Bool>("shouldSwitchToDarkerTheme", default: false)
}

// Sensitive data is stored in Keychain
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions appdb/Startup/TabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
12 changes: 10 additions & 2 deletions appdb/Startup/Themes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion appdb/Tabs/Featured/Categories/CategoryCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 2902374

Please sign in to comment.