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

Small refactoring #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions RxMarbles/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,28 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var introWindow: UIWindow?
private var _disposeBag = DisposeBag()

private var disposeBag = DisposeBag()

private let _operatorsTableViewController = OperatorsTableViewController()
private let _splitViewController = UISplitViewController()
private let operatorsTableViewController = OperatorsTableViewController()
private let splitViewController = UISplitViewController()


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Fabric.with([Crashlytics.self])

window = UIWindow()

_splitViewController.delegate = self
splitViewController.delegate = self

let masterNav = UINavigationController(rootViewController: _operatorsTableViewController)
let detailNav = UINavigationController(rootViewController: OperatorViewController(rxOperator: _operatorsTableViewController.selectedOperator))

if #available(iOS 11, *) {
masterNav.navigationBar.prefersLargeTitles = true

}
let masterNav = UINavigationController(rootViewController: operatorsTableViewController)
let detailNav = UINavigationController(rootViewController: OperatorViewController(rxOperator: operatorsTableViewController.selectedOperator))

masterNav.navigationBar.prefersLargeTitles = true

_splitViewController.viewControllers = [masterNav, detailNav]
splitViewController.viewControllers = [masterNav, detailNav]

window?.rootViewController = _splitViewController
window?.rootViewController = splitViewController

let showIntroKey = "show_intro"
let defaults = UserDefaults.standard
Expand All @@ -53,7 +51,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.window?.makeKeyAndVisible()

if (defaults.object(forKey: showIntroKey)! as AnyObject).boolValue == true {
_showHelpWindow()
showHelpWindow()
} else {
showMainWindow()
}
Expand All @@ -65,12 +63,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

Notifications.hideHelpWindow.rx()
.subscribe { _ in self.showMainWindow() }
.disposed(by: _disposeBag)
.disposed(by: disposeBag)

return true
}

private func _showHelpWindow() {
private func showHelpWindow() {
introWindow = UIWindow()
let helpViewController = HelpViewController()
helpViewController.helpMode = false
Expand All @@ -91,11 +89,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

@objc func focusSearch() {
if let nav = _splitViewController.viewControllers.first as? UINavigationController {
if let nav = splitViewController.viewControllers.first as? UINavigationController {
nav.popToRootViewController(animated: false)


_operatorsTableViewController.focusSearch()
operatorsTableViewController.focusSearch()
}
}

Expand All @@ -114,10 +112,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
operatorRawValue = opRawValue
}
if let op = Operator(rawValue: operatorRawValue),
let nav = _splitViewController.viewControllers.first as? UINavigationController {
let nav = splitViewController.viewControllers.first as? UINavigationController {
nav.popToRootViewController(animated: false)
_operatorsTableViewController.presentingViewController?.dismiss(animated: false, completion: nil)
_operatorsTableViewController.openOperator(op)
operatorsTableViewController.presentingViewController?.dismiss(animated: false, completion: nil)
operatorsTableViewController.openOperator(op)
}

return false
Expand Down Expand Up @@ -157,12 +155,10 @@ extension AppDelegate: UISplitViewControllerDelegate {
if let detail = primaryViewController.separateSecondaryViewController(for: splitViewController) {
navController = UINavigationController(rootViewController: detail)
} else {
let op = _operatorsTableViewController.selectedOperator
let op = operatorsTableViewController.selectedOperator
navController = UINavigationController(rootViewController: OperatorViewController(rxOperator: op))
}
if #available(iOS 11.0, *) {
navController.navigationBar.prefersLargeTitles = true
}
navController.navigationBar.prefersLargeTitles = true
return navController
}
}
6 changes: 3 additions & 3 deletions RxMarbles/EventShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

private var __coloredImages = [String: UIImage]()
private var coloredImages = [String: UIImage]()

enum EventShape: String {
case circle
Expand All @@ -30,7 +30,7 @@ enum EventShape: String {
func image(_ color: UIColor) -> UIImage {
let key = "\(color.description)-\(self)"

if let res = __coloredImages[key] {
if let res = coloredImages[key] {
return res
}

Expand All @@ -56,7 +56,7 @@ enum EventShape: String {
let res = UIGraphicsGetImageFromCurrentImageContext()!


__coloredImages[key] = res
coloredImages[key] = res
return res
}
}
Expand Down
49 changes: 25 additions & 24 deletions RxMarbles/EventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
import RxSwift

class EventView: UIView {

weak var animator: UIDynamicAnimator? = nil
weak var sequenceView: SourceSequenceView?

Expand All @@ -19,20 +20,20 @@ class EventView: UIView {
var gravity: UIGravityBehavior? = nil
var removeBehavior: UIDynamicItemBehavior? = nil

private let _tapGestureRecognizer = UITapGestureRecognizer()
private let _imageView = UIImageView()
private let tapGestureRecognizer = UITapGestureRecognizer()
private let imageView = UIImageView()

var label = UILabel()

init(recorded: RecordedType) {
super.init(frame: CGRect(x: 0, y: 0, width: 42, height: 50))

_imageView.contentMode = .center
imageView.contentMode = .center
if #available(iOS 13.0, *) {
label.textColor = .systemGray
}
label.font = Font.ultraLightText(11)
addSubview(_imageView)
addSubview(imageView)
addSubview(label)

layer.shouldRasterize = true
Expand All @@ -45,22 +46,22 @@ class EventView: UIView {
label.sizeToFit()
}

_imageView.image = v.shape.image(v.color)
_imageView.frame = CGRect(x: 0, y: 0, width: 16, height: 16)
imageView.image = v.shape.image(v.color)
imageView.frame = CGRect(x: 0, y: 0, width: 16, height: 16)
case .completed:
_imageView.image = RxMarbles.Image.complete
imageView.image = RxMarbles.Image.complete
if #available(iOS 13.0, *) {
_imageView.tintColor = .label
imageView.tintColor = .label
} else {
_imageView.tintColor = .black
imageView.tintColor = .black
}
layer.zPosition = -1
case .error:
_imageView.image = RxMarbles.Image.error
imageView.image = RxMarbles.Image.error
if #available(iOS 13.0, *) {
_imageView.tintColor = .label
imageView.tintColor = .label
} else {
_imageView.tintColor = .black
imageView.tintColor = .black
}
layer.zPosition = -1
}
Expand All @@ -81,14 +82,14 @@ class EventView: UIView {
}
}
self.recorded = recorded
_tapGestureRecognizer.addTarget(self, action: #selector(EventView.setEventView))
_tapGestureRecognizer.isEnabled = false
addGestureRecognizer(_tapGestureRecognizer)
tapGestureRecognizer.addTarget(self, action: #selector(EventView.setEventView))
tapGestureRecognizer.isEnabled = false
addGestureRecognizer(tapGestureRecognizer)
}

override func layoutSubviews() {
super.layoutSubviews()
_imageView.center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
imageView.center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
label.center = CGPoint(x: bounds.width / 2.0, y: bounds.height * 0.15)
}

Expand Down Expand Up @@ -133,11 +134,11 @@ class EventView: UIView {
}

func addTapRecognizer() {
_tapGestureRecognizer.isEnabled = true
tapGestureRecognizer.isEnabled = true
}

func removeTapRecognizer() {
_tapGestureRecognizer.isEnabled = false
tapGestureRecognizer.isEnabled = false
}

@objc func setEventView() {
Expand All @@ -149,23 +150,23 @@ class EventView: UIView {
let alpha: CGFloat = onDeleteZone ? 1.0 : 0.2
switch recorded.value {
case .next:
_imageView.image = recorded.value.element?.shape.image.withRenderingMode(.alwaysTemplate)
imageView.image = recorded.value.element?.shape.image.withRenderingMode(.alwaysTemplate)
case .completed:
_imageView.image = RxMarbles.Image.complete.withRenderingMode(.alwaysTemplate)
imageView.image = RxMarbles.Image.complete.withRenderingMode(.alwaysTemplate)
case .error:
_imageView.image = RxMarbles.Image.error.withRenderingMode(.alwaysTemplate)
imageView.image = RxMarbles.Image.error.withRenderingMode(.alwaysTemplate)
}
_imageView.tintColor = color
imageView.tintColor = color
self.alpha = alpha
}

func setColorOnPreview(color: UIColor) {
_imageView.image = recorded.value.element?.shape.image(color)
imageView.image = recorded.value.element?.shape.image(color)
}

func refreshColorAndValue() {
if let color = recorded.value.element?.color {
_imageView.image = recorded.value.element?.shape.image(color)
imageView.image = recorded.value.element?.shape.image(color)
}
if let value = recorded.value.element?.value {
label.text = value
Expand Down
Loading