Skip to content

Commit

Permalink
Merge pull request weiran#221 from weiran/ios15
Browse files Browse the repository at this point in the history
iOS 15 update
  • Loading branch information
weiran authored Dec 4, 2021
2 parents 96f24e2 + 41065d5 commit 9654c16
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 81 deletions.
11 changes: 7 additions & 4 deletions App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import SwinjectStoryboard
import Nuke

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -22,6 +23,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if ProcessInfo.processInfo.arguments.contains("skipAnimations") {
UIView.setAnimationsEnabled(false)
}
if ProcessInfo.processInfo.arguments.contains("darkMode") {
window?.overrideUserInterfaceStyle = .dark
}

// setup window and entry point
window = UIWindow()
Expand All @@ -33,10 +37,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window?.tintColor = AppTheme.default.appTintColor
window?.makeKeyAndVisible()

if ProcessInfo.processInfo.arguments.contains("darkMode") {
window?.overrideUserInterfaceStyle = .dark
}

// setup NavigationService
navigationService = SwinjectStoryboard.getService()
navigationService?.mainSplitViewController = mainSplitViewController
Expand All @@ -47,6 +47,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

// init default settings
UserDefaults.standard.registerDefaults()

// setup Nuke
DataLoader.sharedUrlCache.diskCapacity = 1024 * 1024 * 100 // 100MB
}

func application(
Expand Down
69 changes: 33 additions & 36 deletions App/Comments/CommentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,24 @@ class CommentsViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
setupCollectionView()
setupRefreshControl()
load()
}

deinit {
tearDownHandoff()
}

private func setupRefreshControl() {
let refreshControl = UIRefreshControl()
refreshControl.addTarget(
self,
action: #selector(load),
for: .valueChanged
)
self.refreshControl = refreshControl
}

@objc private func load(showSpinner: Bool = true) {
if showSpinner {
tableView.backgroundView = TableViewBackgroundView.loadingBackgroundView()
Expand Down Expand Up @@ -250,8 +260,18 @@ extension CommentsViewController {
voteAction()
}

let share = UIAction(
title: "Share",
image: UIImage(systemName: "square.and.arrow.up"),
identifier: UIAction.Identifier(rawValue: "share.comment")
) { [weak self] _ in
self?.shareComment(at: indexPath)
}

let voteMenu = upvoted ? unvote : upvote
return UIMenu(title: "", image: nil, identifier: nil, children: [voteMenu])
let shareMenu = UIMenu(title: "", options: .displayInline, children: [share])

return UIMenu(title: "", image: nil, identifier: nil, children: [voteMenu, shareMenu])
}
}

Expand Down Expand Up @@ -350,7 +370,7 @@ extension CommentsViewController: SwipeTableViewCellDelegate {
)

case (.right, 1):
return [collapseAction(), shareAction()]
return [collapseAction()]

case (.left, 1):
let comment = commentsController.visibleComments[indexPath.row]
Expand All @@ -366,28 +386,16 @@ extension CommentsViewController: SwipeTableViewCellDelegate {
}
}

private func shareAction() -> SwipeAction {
let shareAction = SwipeAction(style: .default, title: "Share") { [weak self] _, indexPath in
guard let strongSelf = self else {
return
}
let comment = strongSelf.commentsController.visibleComments[indexPath.row]
let url = comment.hackerNewsURL
let activityViewController = UIActivityViewController(
activityItems: [url],
applicationActivities: nil
)
let cell = strongSelf.tableView.cellForRow(at: indexPath)
activityViewController.popoverPresentationController?.sourceView = cell
strongSelf.present(activityViewController, animated: true, completion: nil)
}
shareAction.backgroundColor = .systemGreen
shareAction.textColor = .white

let iconImage = UIImage(systemName: "square.and.arrow.up")!.withTintColor(.white)
shareAction.image = iconImage

return shareAction
private func shareComment(at indexPath: IndexPath) {
let comment = self.commentsController.visibleComments[indexPath.row]
let url = comment.hackerNewsURL
let activityViewController = UIActivityViewController(
activityItems: [url],
applicationActivities: nil
)
let cell = self.tableView.cellForRow(at: indexPath)
activityViewController.popoverPresentationController?.sourceView = cell
self.present(activityViewController, animated: true, completion: nil)
}

private func collapseAction() -> SwipeAction {
Expand Down Expand Up @@ -483,17 +491,6 @@ extension CommentsViewController: CommentDelegate {

// MARK: - Handoff
extension CommentsViewController {

private func setupCollectionView() {
let refreshControl = UIRefreshControl()
refreshControl.addTarget(
self,
action: #selector(load),
for: .valueChanged
)
self.refreshControl = refreshControl
}

private func setupHandoff(with post: Post?, activityType: ActivityType) {
guard let post = post else {
return
Expand Down
20 changes: 15 additions & 5 deletions App/Services/OnboardingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ enum OnboardingService {
}

private static func items() -> [WhatsNew.Item] {
let defaultBrowserItem = WhatsNew.Item(
title: "Disable swipe gestures",
subtitle: "Added a setting to disable all swipe gestures, you can long tap for a menu instead. Thanks to @ballwood for the contribution.",
image: UIImage(systemName: "hand.draw.fill")
let pullToRefreshItem = WhatsNew.Item(
title: "Pull to refresh comments",
subtitle: "Thanks @ballwood.",
image: UIImage(systemName: "arrow.clockwise")
)
return [defaultBrowserItem]
let shareCommentItem = WhatsNew.Item(
title: "Share comments",
subtitle: "Long press on a comment to share a direct link.",
image: UIImage(systemName: "bubble.left")
)
let bugfixesItem = WhatsNew.Item(
title: "Fixes and improvements",
subtitle: "Feedback emails work with third party email apps.\n\nThumbnail cache size limited to 100MB.",
image: UIImage(systemName: "checkmark.seal")
)
return [pullToRefreshItem, shareCommentItem, bugfixesItem]
}
}

Expand Down
16 changes: 13 additions & 3 deletions App/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,24 @@ extension SettingsViewController {
}

private func sendFeedbackEmail() {
let appVersion = self.appVersion() ?? ""
let emailAddress = "weiran@zhang.me.uk"
let subject = "Feedback for Hackers \(appVersion)"

if MFMailComposeViewController.canSendMail() {
let appVersion = self.appVersion() ?? ""
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["weiran@zhang.me.uk"])
mail.setSubject("Feedback for Hackers \(appVersion)")
mail.setToRecipients([emailAddress])
mail.setSubject(subject)
mail.setMessageBody("", isHTML: true)
present(mail, animated: true)
} else {
let mailtoString = "mailto:\(emailAddress)?subject=\(subject)"
.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
let mailtoURL = URL(string: mailtoString)!
if UIApplication.shared.canOpenURL(mailtoURL) {
UIApplication.shared.open(mailtoURL, options: [:])
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Extensions/HackersActionExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>4.6.3</string>
<string>4.6.4</string>
<key>CFBundleVersion</key>
<string>105</string>
<string>106</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
4 changes: 2 additions & 2 deletions Extensions/HackersShareExtension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>4.6.3</string>
<string>4.6.4</string>
<key>CFBundleVersion</key>
<string>105</string>
<string>106</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
24 changes: 14 additions & 10 deletions Hackers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1026,13 +1026,15 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 106;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = 2KB59GPA9B;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
INFOPLIST_FILE = Extensions/HackersActionExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 4.6.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.weiranzhang.Hackers.HackersActionExtension;
Expand All @@ -1059,13 +1061,15 @@
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 106;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = 2KB59GPA9B;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
INFOPLIST_FILE = Extensions/HackersActionExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MARKETING_VERSION = 4.6.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.weiranzhang.Hackers.HackersActionExtension;
Expand Down Expand Up @@ -1161,7 +1165,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
INFOPLIST_FILE = Extensions/HackersShareExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -1194,7 +1198,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
INFOPLIST_FILE = Extensions/HackersShareExtension/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -1316,15 +1320,15 @@
CODE_SIGN_ENTITLEMENTS = "App/Supporting Files/Hackers.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 105;
CURRENT_PROJECT_VERSION = 106;
DEVELOPMENT_TEAM = 2KB59GPA9B;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "App/Supporting Files/Hackers2-Prefix.pch";
INFOPLIST_FILE = "App/Supporting Files/Hackers-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 4.6.3;
MARKETING_VERSION = 4.6.4;
PRODUCT_BUNDLE_IDENTIFIER = "com.weiranzhang.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Hackers;
PROVISIONING_PROFILE_SPECIFIER = "Hackers Dev Profile";
Expand All @@ -1346,15 +1350,15 @@
CODE_SIGN_ENTITLEMENTS = "App/Supporting Files/Hackers.entitlements";
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 105;
CURRENT_PROJECT_VERSION = 106;
DEVELOPMENT_TEAM = 2KB59GPA9B;
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "App/Supporting Files/Hackers2-Prefix.pch";
INFOPLIST_FILE = "App/Supporting Files/Hackers-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 4.6.3;
MARKETING_VERSION = 4.6.4;
PRODUCT_BUNDLE_IDENTIFIER = "com.weiranzhang.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = Hackers;
PROVISIONING_PROFILE_SPECIFIER = "Hackers Prod Profile";
Expand Down
2 changes: 1 addition & 1 deletion Hackers.xcodeproj/xcshareddata/xcschemes/Hackers.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
LastUpgradeVersion = "1310"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target 'Hackers' do
pod 'PromiseKit/CorePromise'
pod 'Loaf'
pod 'SwipeCellKit'
pod 'Swinject', '~> 2.6.2' # SwinjectStoryboard needs updating
pod 'Swinject'
pod 'SwinjectStoryboard'
pod 'BulletinBoard'
pod 'WhatsNewKit'
Expand Down
Loading

0 comments on commit 9654c16

Please sign in to comment.