Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Night mode #69

Merged
merged 118 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
5fed0ba
add yellow color
Apr 10, 2019
9269852
add darkMode switch to settings
Apr 10, 2019
4e7d28a
add light and dark theme defenitions
Apr 10, 2019
537ea42
add ThemeStore
Apr 10, 2019
76fdc9a
add Theme
Apr 10, 2019
3e4183e
add ThemeController
Apr 10, 2019
a096cf0
add localizable strings
Apr 10, 2019
0456b85
call theme update from AppDelegate
Apr 10, 2019
9e40a95
move extension to it own file
Apr 11, 2019
986427f
fix themeSelection storing
Apr 11, 2019
bc287a4
using a singleton for the ThemeController
Apr 11, 2019
f36c9af
generalize switchCell to be configured from the outside
Apr 11, 2019
6bbb613
update colors
Apr 11, 2019
1566880
add custom map TileOverlay
Apr 11, 2019
15a7869
* add custom tile overlay
Apr 11, 2019
2fe9109
change back to NON Singleton for better testability
Apr 11, 2019
20232bd
add tests
Apr 11, 2019
3ad8ece
add UIWindow and UIApplication extensions
Apr 15, 2019
65712ca
add night mode strings
Apr 20, 2019
a61db35
move section enum from settings to its own file because it deserves one
Apr 20, 2019
6147efc
custom view for rule detail textview to make it listen to UIAppearance
Apr 20, 2019
c104035
move settings section header in xib so it can listen to UIAppearance
Apr 20, 2019
68f0f9b
add custom UISwitch tint color
Apr 20, 2019
7bbce2d
observce themeDidChange notification
Apr 20, 2019
88199cf
add NibProviding protocol for convenience
Apr 20, 2019
37bfbaa
update setting segmentedControl tint
Apr 20, 2019
f409bff
set colors
Apr 20, 2019
b15e5d1
remove empty cells
Apr 20, 2019
247a836
add dynamic color properties
Apr 20, 2019
495f579
move property to be held by controller
Apr 20, 2019
0a86589
add files to project after rebase
Apr 21, 2019
6bee7c0
update mapView tileOverlays when theme changes
Apr 21, 2019
98de187
inject themeController into SettingsController
Apr 22, 2019
6a1daba
remove settings textColor in TweetCell
Apr 22, 2019
724d19b
move setting in instance creation
Apr 22, 2019
0a02304
add themeController to controller creation
Apr 22, 2019
5a3bc51
remove button tintColor setting
Apr 22, 2019
c04d959
remove setting the tintColor
Apr 22, 2019
8e890fc
* remove NavigationItem cases since it is easier to theme them when t…
Apr 22, 2019
cd06125
mask view of navigationOverlayController to bounds
Apr 22, 2019
3597ac2
change tintColor
Apr 22, 2019
d0051f5
set link tint color in tweetCell
Apr 22, 2019
1ac5695
set UIApplication tintColor
Apr 22, 2019
cd8481e
set keyboardStyle appearance
Apr 22, 2019
899644e
set UINavigationBar appearance
Apr 22, 2019
625f9f2
set UINavigationItem appearance
Apr 22, 2019
b6cb880
set TableViewCell, ScrollView background and SettingsFooterBackground
Apr 22, 2019
717f0f5
set custom view appearance
Apr 22, 2019
e1d2f96
set UIToolBar appearance
Apr 22, 2019
c150fec
set navigationOverlay appearance
Apr 22, 2019
955bc2f
set UILabek appearance
Apr 22, 2019
2992927
set UITextView appearance
Apr 22, 2019
2dd8c1b
set refreshControl appearance
Apr 22, 2019
625ca56
update static names for notifications
Apr 23, 2019
0618f1c
remove comma
Apr 23, 2019
63e98de
update CHANGELOG.md
Apr 23, 2019
f484935
set chatMessage appearance
Apr 23, 2019
05728e7
move display formatting to FormatDisplay
Apr 23, 2019
0455bde
add SeperatorView and update appearance
Apr 23, 2019
74c763c
add styles
Apr 23, 2019
1c9ce45
add colors
Apr 23, 2019
ced98cf
adopt to swiftFormat autocorrection
Apr 23, 2019
67b53f8
add secondary titleColor
Apr 23, 2019
11c6cdb
set chatInputView colors. Finally 🍾
Apr 24, 2019
27ddb82
update naming
Apr 24, 2019
e3d5ad9
set cellSelected backgroundColor
Apr 29, 2019
8ef9fae
set navigationBar isTranslucent style
Apr 29, 2019
8601f62
disable setting textColor for rules from rulesController
Apr 29, 2019
6b82c8b
create UILabel subclass to update color
Apr 29, 2019
4489c09
update label overlay colors
Apr 29, 2019
4e6592c
update overlay label on mapview
Apr 29, 2019
f229cf8
set unreadMessagesBackgroundColor
Apr 29, 2019
f4be3bf
update UIRefreshControl appearance
Apr 29, 2019
f19e630
update property observers
Apr 29, 2019
4ce35f8
update uiswitch color to match design
Apr 29, 2019
4b66c15
* add placeholder text again
Apr 29, 2019
5af55ba
add tests to project file
Apr 30, 2019
3eef33d
update settingsSwitchCells to work with closures
Apr 30, 2019
72a5b98
update test to updated property
Apr 30, 2019
e695df4
rename property
Apr 30, 2019
7590a8a
add unit tests for applying theme
Apr 30, 2019
705fc87
remove unused properties
Apr 30, 2019
dd26e81
update toolBarTintColor after review
Apr 30, 2019
603be51
fix not showing whole settings on smaller devices
Apr 30, 2019
2d2a9fd
fix color of disabled chat message send button
Apr 30, 2019
c41e02d
add highlighted color again
Apr 30, 2019
15c0bb2
* update to Notification
May 2, 2019
ec2c82d
remove unnecessary synchronize
May 2, 2019
30b912b
add cases from Section enum
May 2, 2019
2a334de
set label.adjustsFontForContentSizeCategory in IB
May 2, 2019
1166251
remove unused color extensions
May 2, 2019
cb7c078
remove unused properties
May 2, 2019
7ba56ea
remove some old cod3
May 2, 2019
54f2300
injecting themeController intp MapController via AppController
May 2, 2019
f8eb84f
update extension name
May 2, 2019
1e7dbe2
* update toolBar backgroundColor after code review 👌
May 2, 2019
6bfef72
style navigationOverlay view with alpha component
May 3, 2019
3234f18
divide and conquer applyTheme func
May 3, 2019
b3e761d
* update tweetTableViewCell appearancne
May 3, 2019
4d82488
remove maskToBounds to give OverlayView its shadow back
May 3, 2019
64affab
fix failing tests 🏃‍♂️
May 3, 2019
055394c
update to collect gps and nightMode switch in preferences
May 3, 2019
7adc46e
* remove unused colors
May 3, 2019
7e008eb
apply theme in the appController
May 4, 2019
2b661c1
fix statusBarStyle in MapViewController
May 4, 2019
4ebee0e
add comments
May 4, 2019
b91cff2
add italian translation
May 4, 2019
fc5520a
remove unused strings
May 4, 2019
495d2a0
add statusBarStyle
May 4, 2019
1b35d15
update NSNotification to Notification
May 6, 2019
af4c1ea
rework NavigaionOverlayController
May 7, 2019
fbc50cb
add dynamic property
May 7, 2019
33585a3
set custom button appearance
May 7, 2019
4b8333a
Merge master into darkMode
May 7, 2019
6ed538e
fix CustomButton appearance
May 7, 2019
cd7745a
fix mapViewController initial tile load
May 7, 2019
4818835
fix tests ✅
May 7, 2019
6769c31
* ChatNavigationButton appearance textColor is alwazs white now
May 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ Changelog for Critical Maps iOS
## [UNRELEASED]

### Added

- Message Notification Bubble
- Swiftformat to the build phases
- Network activity indicator support
- French localisation. Thanks Alban!
- Night mode feature

### Updated

- SDWebImage

### Fixed

- Users can not send empty chat messages anymore.
- A bug that prevented sending messages if another network request is active

## [3.0.0] - 2019-04-18


### Changed

- Complete Redesign
Expand Down
76 changes: 72 additions & 4 deletions CriticalMaps.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions CriticalMass/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import Foundation

class AppController {
init() {
onAppLaunch()
}

private func onAppLaunch() {
loadInitialData()
themeController.applyTheme()
}

private let networkOperator: NetworkOperator = {
Expand All @@ -21,6 +26,8 @@ class AppController {
return RequestManager(dataStore: MemoryDataStore(), locationProvider: LocationManager(), networkLayer: networkOperator, deviceId: deviceId.md5, url: Constants.apiEndpoint)
}()

private let themeController = ThemeController()

private lazy var chatManager: ChatManager = {
ChatManager(requestManager: requestManager)
}()
Expand Down Expand Up @@ -50,12 +57,11 @@ class AppController {
}

private func getSettingsViewController() -> SettingsViewController {
return SettingsViewController()
return SettingsViewController(themeController: themeController)
}

lazy var rootViewController: UIViewController = {
let rootViewController = MapViewController()

let rootViewController = MapViewController(themeController: self.themeController)
let navigationOverlay = NavigationOverlayViewController(navigationItems: [
.init(representation: .view(rootViewController.followMeButton), action: .none),
.init(representation: .button(chatNavigationButtonController.button), action: .navigation(viewController: getSocialViewController)),
Expand Down
30 changes: 21 additions & 9 deletions CriticalMass/ChatInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,50 @@ protocol ChatInputDelegate: AnyObject {
}

class ChatInputView: UIView, UITextFieldDelegate {
@objc
dynamic var sendMessageButtonColor: UIColor? {
willSet {
button.setTitleColor(newValue, for: .normal)
button.setTitleColor(newValue?.withAlphaComponent(0.4), for: .disabled)
button.setTitleColor(newValue?.withAlphaComponent(0.4), for: .highlighted)
}
}

@objc
dynamic var textViewTextColor: UIColor? {
willSet {
textField.textColor = newValue
}
}

weak var delegate: ChatInputDelegate?

private let textField: UITextField = {
let textField = TextFieldWithInsets()
textField.isOpaque = false
textField.translatesAutoresizingMaskIntoConstraints = false
textField.backgroundColor = .chatInputTextfieldBackground
textField.attributedPlaceholder = NSAttributedString(string: NSLocalizedString("chat.placeholder", comment: ""), attributes: [.foregroundColor: UIColor.chatInputPlaceholder])
textField.placeholder = NSLocalizedString("chat.placeholder", comment: "")
textField.insets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
textField.enablesReturnKeyAutomatically = true
textField.returnKeyType = .send
textField.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
textField.layer.masksToBounds = true
return textField
}()

private let button: UIButton = {
let button = UIButton()
button.titleLabel?.textAlignment = .center
button.setTitle(NSLocalizedString("chat.send", comment: ""), for: .normal)
button.setTitleColor(.chatInputSendButton, for: .normal)
button.setTitleColor(UIColor.chatInputSendButton.withAlphaComponent(0.4), for: .highlighted)
button.setTitleColor(UIColor.chatInputSendButton.withAlphaComponent(0.4), for: .disabled)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(didTapSendButton), for: .touchUpInside)
button.isEnabled = false
return button
}()

private let separator: UIView = {
let view = UIView()
private let separator: SeperatorView = {
let view = SeperatorView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .chatInputSeparator
return view
}()

Expand All @@ -57,7 +70,6 @@ class ChatInputView: UIView, UITextFieldDelegate {
}

private func commonInit() {
backgroundColor = .chatInputBackground
addSubview(textField)
addSubview(button)
addSubview(separator)
Expand Down
23 changes: 17 additions & 6 deletions CriticalMass/ChatMessageTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
import UIKit

class ChatMessageTableViewCell: UITableViewCell, MessagesTableViewCell {
@objc
dynamic var timeLabelTextColor: UIColor? {
willSet {
timeLabel.textColor = newValue
}
}

@objc
dynamic var chatTextColor: UIColor? {
willSet {
chatTextView.textColor = newValue
}
}

@IBOutlet private var timeLabel: UILabel!
@IBOutlet private var chatTextView: UITextView! {
didSet {
Expand All @@ -19,15 +33,12 @@ class ChatMessageTableViewCell: UITableViewCell, MessagesTableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
timeLabel?.textColor = .chatMessageDate
chatTextView?.textColor = .chatMessageText
timeLabel?.textColor = .gray200
chatTextView?.textColor = .gray300
}

func setup(for message: ChatMessage) {
let date = Date(timeIntervalSince1970: message.timestamp)
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
timeLabel?.text = formatter.string(from: date)
timeLabel?.text = FormatDisplay.hoursAndMinutesDateString(from: message)
chatTextView?.text = message.decodedMessage
}
}
18 changes: 14 additions & 4 deletions CriticalMass/ChatNavigationButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
import UIKit

class ChatNavigationButton: CustomButton {
@objc
dynamic var unreadMessagesBackgroundColor: UIColor? {
willSet {
unreadLabel.backgroundColor = newValue
}
}

@objc
dynamic var unreadMessagesTextColor: UIColor? {
willSet {
unreadLabel.textColor = newValue
}
}

private let unreadLabel = UILabel()

public var unreadCount: UInt = 0 {
Expand All @@ -24,9 +38,7 @@ class ChatNavigationButton: CustomButton {
init() {
super.init(frame: .zero)
setImage(UIImage(named: "Chat")!, for: .normal)
tintColor = .navigationOverlayForeground
adjustsImageWhenHighlighted = false
highlightedTintColor = UIColor.navigationOverlayForeground.withAlphaComponent(0.4)
mltbnz marked this conversation as resolved.
Show resolved Hide resolved
accessibilityLabel = NSLocalizedString("chat.title", comment: "")
configureUnreadBubble()
}
Expand All @@ -36,8 +48,6 @@ class ChatNavigationButton: CustomButton {
}

private func configureUnreadBubble() {
unreadLabel.backgroundColor = .red
unreadLabel.textColor = .white
unreadLabel.font = UIFont.systemFont(ofSize: 11, weight: .heavy)
unreadLabel.layer.cornerRadius = 8
unreadLabel.layer.masksToBounds = true
Expand Down
84 changes: 24 additions & 60 deletions CriticalMass/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,55 @@
import UIKit

extension UIColor {
static var rulesDetailText: UIColor {
return UIColor(red: 69 / 255.0, green: 71 / 255.0, blue: 77 / 255.0, alpha: 1)
}

static var rulesOverViewCell: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
}

static var chatInputBackground: UIColor {
return UIColor(red: 250 / 255.0, green: 250 / 255.0, blue: 250 / 255.0, alpha: 1)
}

static var chatInputTextfieldBackground: UIColor {
return UIColor(red: 218 / 255.0, green: 220 / 255.0, blue: 224 / 255.0, alpha: 1)
}

static var chatInputSendButton: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
}

static var chatInputSeparator: UIColor {
return UIColor(red: 218 / 255.0, green: 220 / 255.0, blue: 224 / 255.0, alpha: 1)
}

static var chatInputPlaceholder: UIColor {
return UIColor(red: 69 / 255.0, green: 71 / 255.0, blue: 77 / 255.0, alpha: 1)
}

static var chatMessageDate: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
}

static var chatMessageText: UIColor {
return UIColor(red: 69 / 255.0, green: 71 / 255.0, blue: 77 / 255.0, alpha: 1)
}

static var twitterProfileInnerBorder: UIColor {
return UIColor(red: 55 / 255.0, green: 64 / 255.0, blue: 82 / 255.0, alpha: 0.18)
}

static var twitterName: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
static var gray100: UIColor {
return UIColor(white: 26.0 / 255.0, alpha: 1.0)
}

static var twitterUsername: UIColor {
return UIColor(red: 144 / 255.0, green: 147 / 255.0, blue: 153 / 255.0, alpha: 1)
static var gray200: UIColor {
return UIColor(white: 38.0 / 255.0, alpha: 1)
}

static var gray400: UIColor {
return UIColor(red: 144 / 255.0, green: 147 / 255.0, blue: 153 / 255.0, alpha: 1)
static var gray300: UIColor {
return UIColor(red: 69.0 / 255.0, green: 71.0 / 255.0, blue: 77.0 / 255.0, alpha: 1.0)
}

static var twitterText: UIColor {
return UIColor(red: 69 / 255.0, green: 71 / 255.0, blue: 77 / 255.0, alpha: 1)
static var gray400: UIColor {
mltbnz marked this conversation as resolved.
Show resolved Hide resolved
return UIColor(red: 144 / 255.0, green: 147 / 255.0, blue: 153 / 255.0, alpha: 1)
}

static var twitterDate: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
static var gray500: UIColor {
return UIColor(red: 218.0 / 255.0, green: 220.0 / 255.0, blue: 224.0 / 255.0, alpha: 1.0)
}

static var gray200: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
static var settingsOpenSourceForeground: UIColor {
return UIColor(white: 26.0 / 255.0, alpha: 1)
}

static var settingsForeground: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
static var navigationOverlayBackground: UIColor {
return UIColor(white: 1.0, alpha: 0.8)
}

static var settingsOpenSourceForeground: UIColor {
return UIColor(red: 26 / 255.0, green: 26 / 255.0, blue: 26 / 255.0, alpha: 1)
static var yellow100: UIColor {
return UIColor(red: 255.0 / 255.0, green: 214.0 / 255.0, blue: 51.0 / 255.0, alpha: 1.0)
}

static var navigationOverlayBackground: UIColor {
return UIColor(red: 255 / 255.0, green: 255 / 255.0, blue: 255 / 255.0, alpha: 0.8)
static var gray600: UIColor {
return UIColor(white: 250.0 / 255.0, alpha: 1.0)
}

static var navigationOverlayForeground: UIColor {
return UIColor(red: 38 / 255.0, green: 38 / 255.0, blue: 38 / 255.0, alpha: 1)
static var lightThemeToolBarBackgroundColor: UIColor {
return gray600
}

static var navigationOverlaySeparator: UIColor {
return UIColor(white: 0.0, alpha: 0.1)
static var lightThemeNavigationOverlaySeperatorColor: UIColor {
return UIColor(red: 220.0 / 255.0, green: 224.0 / 255.0, blue: 216.0 / 255.0, alpha: 1.00)
}

static var socialTabControlTintColor: UIColor {
return .black
static var darkThemeNavigationOverlaySeperatorColor: UIColor {
return UIColor(white: 57.0 / 255.0, alpha: 1.00)
}
}
2 changes: 2 additions & 0 deletions CriticalMass/CriticalMaps-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
</plist>
20 changes: 9 additions & 11 deletions CriticalMass/CustomButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
import UIKit

class CustomButton: UIButton {
public var highlightedTintColor: UIColor?
private var defaultTintColor: UIColor?
@objc
public dynamic var highlightedTintColor: UIColor!
@objc
public dynamic var defaultTintColor: UIColor! {
willSet {
tintColor = newValue
}
}

override var isHighlighted: Bool {
didSet {
if let highlightedTintColor = highlightedTintColor, isHighlighted {
if defaultTintColor == nil {
defaultTintColor = tintColor
}
tintColor = highlightedTintColor
} else if let defaultTintColor = defaultTintColor {
tintColor = defaultTintColor
self.defaultTintColor = nil
}
tintColor = isHighlighted ? highlightedTintColor : defaultTintColor
}
}
}
21 changes: 21 additions & 0 deletions CriticalMass/DarkMapOverlay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// DarkMapOverlay.swift
// CriticalMaps
//
// Created by Malte Bünz on 11.04.19.
// Copyright © 2019 Pokus Labs. All rights reserved.
//

import MapKit

class DarkModeMapOverlay: MKTileOverlay {
init() {
super.init(urlTemplate: nil)
canReplaceMapContent = true
}

override func url(forTilePath path: MKTileOverlayPath) -> URL {
let tileUrl = "https://a.basemaps.cartocdn.com/dark_all/\(path.z)/\(path.x)/\(path.y).png"
return URL(string: tileUrl)!
}
}
7 changes: 7 additions & 0 deletions CriticalMass/FormatDisplay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ enum FormatDisplay {
formatter.maximumUnitCount = 1
return formatter.string(from: components)
}

static func hoursAndMinutesDateString(from message: ChatMessage) -> String {
let date = Date(timeIntervalSince1970: message.timestamp)
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
return formatter.string(from: date)
}
}