Skip to content

Commit

Permalink
Merge pull request #38 from weiran/dark
Browse files Browse the repository at this point in the history
Dark mode
  • Loading branch information
weiran authored May 6, 2018
2 parents 029a3a6 + fdca810 commit 2b13dc6
Show file tree
Hide file tree
Showing 66 changed files with 851 additions and 149 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions Assets/Icons.xcassets/SettingsIcon.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"images" : [
{
"idiom" : "universal",
"filename" : "668-gear4.png",
"filename" : "740-gear.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "668-gear4@2x.png",
"filename" : "740-gear@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "668-gear4@3x.png",
"filename" : "740-gear@3x.png",
"scale" : "3x"
}
],
Expand Down
29 changes: 29 additions & 0 deletions Client/AppNavigationController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// AppNavigationController.swift
// Hackers
//
// Created by Weiran Zhang on 05/05/2018.
// Copyright © 2018 Glass Umbrella. All rights reserved.
//

import UIKit

class AppNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
setupTheming()
navigationBar.setValue(true, forKey: "hidesShadow")
}
}

extension AppNavigationController: Themed {
func applyTheme(_ theme: AppTheme) {
navigationBar.barTintColor = theme.barBackgroundColor
navigationBar.tintColor = theme.barForegroundColor
let titleTextAttributes = [
NSAttributedStringKey.foregroundColor: theme.titleTextColor
]
navigationBar.titleTextAttributes = titleTextAttributes
navigationBar.largeTitleTextAttributes = titleTextAttributes
}
}
44 changes: 42 additions & 2 deletions Client/Comments/CommentTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import UIKit


class CommentTableViewCell : UITableViewCell {

var delegate: CommentDelegate?

var level: Int = 0 {
Expand All @@ -29,8 +28,11 @@ class CommentTableViewCell : UITableViewCell {
@IBOutlet var authorLabel : UILabel!
@IBOutlet var datePostedLabel : UILabel!
@IBOutlet var leftPaddingConstraint : NSLayoutConstraint!
@IBOutlet weak var separatorView: UIView!

override func awakeFromNib() {
super.awakeFromNib()
setupTheming()
contentView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(CommentTableViewCell.cellTapped)))
}

Expand All @@ -53,7 +55,7 @@ class CommentTableViewCell : UITableViewCell {
if let commentTextView = commentTextView {
// only for expanded comments
let commentFont = UIFont.systemFont(ofSize: 15)
let commentTextColor = UIColor.darkGray
let commentTextColor = AppThemeProvider.shared.currentTheme.textColor
let lineSpacing = 4 as CGFloat

let commentAttributedString = NSMutableAttributedString(string: comment.text)
Expand All @@ -80,3 +82,41 @@ extension CommentTableViewCell: UITextViewDelegate {
return true
}
}

extension CommentTableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
selected ? setSelectedBackground() : setUnselectedBackground()
}

override func setHighlighted(_ highlighted: Bool, animated: Bool) {
super.setHighlighted(highlighted, animated: animated)
highlighted ? setSelectedBackground() : setUnselectedBackground()
}

func setSelectedBackground() {
backgroundColor = AppThemeProvider.shared.currentTheme.cellHighlightColor
}

func setUnselectedBackground() {
backgroundColor = AppThemeProvider.shared.currentTheme.backgroundColor
}
}

extension CommentTableViewCell: Themed {
func applyTheme(_ theme: AppTheme) {
backgroundColor = theme.backgroundColor
if commentTextView != nil {
commentTextView.tintColor = theme.appTintColor
}
if authorLabel != nil {
authorLabel.textColor = theme.textColor
}
if datePostedLabel != nil {
datePostedLabel.textColor = theme.lightTextColor
}
if separatorView != nil {
separatorView.backgroundColor = theme.separatorColor
}
}
}
10 changes: 7 additions & 3 deletions Client/Comments/CommentsHeader.xib
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="CommentsHeaderView" customModule="Hackers" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="60"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -40,6 +40,10 @@
</constraints>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
<connections>
<outlet property="separatorView" destination="ggn-R0-s8v" id="m91-Tx-u1M"/>
<outlet property="titleLabel" destination="WWj-L3-Z9U" id="89b-MT-FGm"/>
</connections>
<point key="canvasLocation" x="18.5" y="12"/>
</view>
</objects>
Expand Down
27 changes: 27 additions & 0 deletions Client/Comments/CommentsHeaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// CommentsHeaderView.swift
// Hackers
//
// Created by Weiran Zhang on 05/05/2018.
// Copyright © 2018 Glass Umbrella. All rights reserved.
//

import UIKit

class CommentsHeaderView: UIView {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var separatorView: UIView!

override func awakeFromNib() {
super.awakeFromNib()
setupTheming()
}
}

extension CommentsHeaderView: Themed {
func applyTheme(_ theme: AppTheme) {
backgroundColor = theme.backgroundColor
titleLabel.textColor = theme.titleTextColor
separatorView.backgroundColor = theme.separatorColor
}
}
29 changes: 17 additions & 12 deletions Client/Comments/CommentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,20 @@ class CommentsViewController : UIViewController {

@IBOutlet var tableView: UITableView!

@IBOutlet weak var postTitleContainerView: UIView!
@IBOutlet weak var postTitleView: PostTitleView!
@IBOutlet weak var thumbnailImageView: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()

setupTheming()
setupPostTitleView()

tableView.backgroundView = nil
tableView.backgroundColor = .white

Theme.setupNavigationBar(navigationController?.navigationBar)

view.showAnimatedSkeleton()
view.showAnimatedSkeleton(usingColor: AppThemeProvider.shared.currentTheme.skeletonColor)
loadComments()
}

override func awakeFromNib() {
super.awakeFromNib()
navigationItem.largeTitleDisplayMode = .never
}

Expand Down Expand Up @@ -104,13 +100,13 @@ extension CommentsViewController: PostTitleViewDelegate {
func didPressLinkButton(_ post: HNPost) {
if verifyLink(post.urlString), let url = URL(string: post.urlString) {
// animate background colour for tap
self.tableView.tableHeaderView?.backgroundColor = Theme.backgroundPurpleColour
self.tableView.tableHeaderView?.backgroundColor = AppThemeProvider.shared.currentTheme.cellHighlightColor
UIView.animate(withDuration: 0.3, animations: {
self.tableView.tableHeaderView?.backgroundColor = .white
self.tableView.tableHeaderView?.backgroundColor = AppThemeProvider.shared.currentTheme.backgroundColor
})

// show link
let safariViewController = SFSafariViewController(url: url)
let safariViewController = ThemedSafariViewController(url: url)
self.present(safariViewController, animated: true, completion: nil)
}
}
Expand Down Expand Up @@ -149,6 +145,15 @@ extension CommentsViewController: UITableViewDelegate {
}
}

extension CommentsViewController: Themed {
func applyTheme(_ theme: AppTheme) {
view.backgroundColor = theme.backgroundColor
tableView.backgroundColor = theme.backgroundColor
tableView.separatorColor = theme.separatorColor
postTitleContainerView.backgroundColor = theme.backgroundColor
}
}

extension CommentsViewController: CommentDelegate {
func commentTapped(_ sender: UITableViewCell) {
if let indexPath = tableView.indexPath(for: sender) {
Expand All @@ -157,7 +162,7 @@ extension CommentsViewController: CommentDelegate {
}

func linkTapped(_ URL: Foundation.URL, sender: UITextView) {
let safariViewController = SFSafariViewController(url: URL)
let safariViewController = ThemedSafariViewController(url: URL)
self.present(safariViewController, animated: true, completion: nil)
}

Expand Down
11 changes: 11 additions & 0 deletions Client/Comments/EmptyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,16 @@
import UIKit

class EmptyViewController: UIViewController {
@IBOutlet weak var descriptionLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
setupTheming()
}
}

extension EmptyViewController: Themed {
func applyTheme(_ theme: AppTheme) {
view.backgroundColor = theme.backgroundColor
descriptionLabel.textColor = theme.titleTextColor
}
}
21 changes: 21 additions & 0 deletions Client/Helpers/ArrayExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ArrayExtensions.swift
// Night Mode
//
// Created by Michael on 01/04/2018.
// Copyright © 2018 Late Night Swift. All rights reserved.
//

import Foundation

extension Array {
/// Move the last element of the array to the beginning
/// - Returns: The element that was moved
mutating func rotate() -> Element? {
guard let lastElement = popLast() else {
return nil
}
insert(lastElement, at: 0)
return lastElement
}
}
File renamed without changes.
42 changes: 42 additions & 0 deletions Client/Helpers/SubscribableValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// SubscribableValue.swift
// Night Mode
//
// Created by Michael on 01/04/2018.
// Copyright © 2018 Late Night Swift. All rights reserved.
//

import Foundation

/// Stores a value of type T, and allows objects to subscribe to
/// be notified with this value is changed.
struct SubscribableValue<T> {
private typealias Subscription = (object: Weak<AnyObject>, handler: (T) -> Void)

private var subscriptions: [Subscription] = []

var value: T {
didSet {
for (object, handler) in subscriptions where object.value != nil {
handler(value)
}
}
}

init(value: T) {
self.value = value
}

mutating func subscribe(_ object: AnyObject, using handler: @escaping (T) -> Void) {
subscriptions.append((Weak(value: object), handler))
cleanupSubscriptions()
}

/// Removes any subscriptions where the object has been deallocated
/// and no longer exists
private mutating func cleanupSubscriptions() {
subscriptions = subscriptions.filter({ entry in
return entry.object.value != nil
})
}
}
24 changes: 24 additions & 0 deletions Client/Helpers/ThemedSafariViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ThemedSafariViewController.swift
// Hackers
//
// Created by Weiran Zhang on 05/05/2018.
// Copyright © 2018 Glass Umbrella. All rights reserved.
//

import SafariServices

class ThemedSafariViewController: SFSafariViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupTheming()
}
}

extension ThemedSafariViewController: Themed {
func applyTheme(_ theme: AppTheme) {
preferredBarTintColor = theme.barBackgroundColor
preferredControlTintColor = theme.appTintColor
view.backgroundColor = theme.backgroundColor
}
}
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions Client/Helpers/UIColor+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UIColor+Extensions.swift
// Hackers
//
// Created by Weiran Zhang on 05/05/2018.
// Copyright © 2018 Glass Umbrella. All rights reserved.
//

import UIKit

extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")

self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}

convenience init(rgb: Int) {
self.init(
red: (rgb >> 16) & 0xFF,
green: (rgb >> 8) & 0xFF,
blue: rgb & 0xFF
)
}
}
File renamed without changes.
Loading

0 comments on commit 2b13dc6

Please sign in to comment.