From 91ab3c65ac7bc1aadbd42c0080d2c8f489e316b4 Mon Sep 17 00:00:00 2001 From: Chris Li Date: Fri, 10 Feb 2017 13:54:33 -0500 Subject: [PATCH] Commit --- .../Controller/Others/WelcomeController.swift | 135 +++++++++++++---- Kiwix-iOS/Info.plist | 2 +- Kiwix-iOS/Storyboard/Welcome.storyboard | 141 ++++++++++-------- Kiwix/Operations/ScanProcedure.swift | 5 + 4 files changed, 184 insertions(+), 99 deletions(-) diff --git a/Kiwix-iOS/Controller/Others/WelcomeController.swift b/Kiwix-iOS/Controller/Others/WelcomeController.swift index cb13e03d..232b228c 100644 --- a/Kiwix-iOS/Controller/Others/WelcomeController.swift +++ b/Kiwix-iOS/Controller/Others/WelcomeController.swift @@ -10,49 +10,118 @@ import UIKit class WelcomeController: UIViewController { @IBOutlet weak var stackView: UIStackView! + let button = ProminentButton(theme: .blue) + enum WelcomePageStatus { + case openLibrary, openMainPage, readLast + } + + override func viewDidLoad() { + super.viewDidLoad() + + stackView.arrangedSubviews.forEach { (subView) in + stackView.removeArrangedSubview(subView) + subView.removeFromSuperview() + } + stackView.addArrangedSubview(button) + + NotificationCenter.default.addObserver(forName: Notification.Name(rawValue: "LibraryScanFinished"), object: nil, queue: nil) { (notification) in + OperationQueue.main.addOperation({ + self.configureButtons() + }) + } + } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - - let button = OpenLibraryButton() - stackView.addArrangedSubview(button) - } - -} - -class OpenLibraryButton: UIButton { - init() { - super.init(frame: CGRect.zero) - let style = NSMutableParagraphStyle() - style.alignment = .center - let attributedTitle = NSMutableAttributedString(string: "Open Library\n", attributes: [ - NSForegroundColorAttributeName: UIColor.white, - NSFontAttributeName: UIFont.systemFont(ofSize: 17, weight: UIFontWeightMedium), - NSParagraphStyleAttributeName: style - ] - ) - let attributedSubtitle = NSMutableAttributedString(string: "Download or import a book", attributes: [ - NSForegroundColorAttributeName: UIColor.white, - NSFontAttributeName: UIFont.systemFont(ofSize: 13, weight: UIFontWeightRegular), - NSParagraphStyleAttributeName: style - ]) - attributedTitle.append(attributedSubtitle) - - titleLabel?.numberOfLines = 0 - setAttributedTitle(attributedTitle, for: UIControlState.normal) - setTitleColor(UIColor.white, for: UIControlState.normal) - layer.cornerRadius = 10.0 - backgroundColor = UIColor.blue } - override var isHighlighted: Bool { - didSet { - backgroundColor = isHighlighted ? UIColor.lightGray : UIColor.orange + func configureButtons() { + UIView.animate(withDuration: 0.2) { + if ZimMultiReader.shared.readers.count == 0 { + self.button.theme = .blue + self.button.configureText(title: "Open Library", subtitle: "Download or import a book") + self.button.addTarget(Controllers.main, action: #selector(MainController.didTapLibraryButton), for: .touchUpInside) + } else { + self.button.theme = .green + self.button.configureText(title: "Start Reading", subtitle: "Open main page of placeholder") + self.button.addTarget(Controllers.main, action: #selector(MainController.didTapLibraryButton), for: .touchUpInside) + } } } +} + +class ProminentButton: UIButton { + var theme: Theme { + didSet { + configureColor() + } + } + + init(theme: Theme) { + self.theme = theme + super.init(frame: CGRect.zero) + + layer.cornerRadius = 10.0 + layer.masksToBounds = true + configureColor() + } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + override var isHighlighted: Bool { + didSet { + configureColor() + } + } + + private func configureColor() { + switch theme { + case .blue: + backgroundColor = isHighlighted ? Color.Blue.highlighted : Color.Blue.normal + case .green: + backgroundColor = isHighlighted ? Color.Green.highlighted : Color.Green.normal + case .orange: + backgroundColor = isHighlighted ? Color.Orange.highlighted : Color.Orange.normal + } + } + + func configureText(title: String, subtitle: String?) { + let style = NSMutableParagraphStyle() + style.alignment = .center + let title = NSMutableAttributedString(string: subtitle == nil ? title : (title + "\n"), attributes: [ + NSForegroundColorAttributeName: UIColor.white, + NSFontAttributeName: UIFont.systemFont(ofSize: 17, weight: UIFontWeightMedium), + NSParagraphStyleAttributeName: style]) + if let subtitle = subtitle { + let attributedSubtitle = NSMutableAttributedString(string: subtitle, attributes: [ + NSForegroundColorAttributeName: UIColor.white, + NSFontAttributeName: UIFont.systemFont(ofSize: 13, weight: UIFontWeightRegular), + NSParagraphStyleAttributeName: style]) + title.append(attributedSubtitle) + } + titleLabel?.numberOfLines = 0 + setAttributedTitle(title, for: .normal) + } + + enum Theme { + case blue, green, orange + } + + fileprivate class Color { + fileprivate class Blue { + fileprivate static let normal = UIColor(colorLiteralRed: 1/255, green: 121/255, blue: 1, alpha: 1) + fileprivate static let highlighted = UIColor(colorLiteralRed: 125/255, green: 185/255, blue: 248/255, alpha: 1) + } + fileprivate class Green { + fileprivate static let normal = UIColor(colorLiteralRed: 72/255, green: 218/255, blue: 104/255, alpha: 1) + fileprivate static let highlighted = UIColor(colorLiteralRed: 54/255, green: 197/255, blue: 91/255, alpha: 1) + } + fileprivate class Orange { + fileprivate static let normal = UIColor(colorLiteralRed: 1/255, green: 121/255, blue: 1, alpha: 1) + fileprivate static let highlighted = UIColor(colorLiteralRed: 125/255, green: 185/255, blue: 248/255, alpha: 1) + } + } } diff --git a/Kiwix-iOS/Info.plist b/Kiwix-iOS/Info.plist index e5b46407..9204336d 100644 --- a/Kiwix-iOS/Info.plist +++ b/Kiwix-iOS/Info.plist @@ -57,7 +57,7 @@ NSAppTransportSecurity NSAllowsArbitraryLoads - + NSExceptionDomains kiwix.org diff --git a/Kiwix-iOS/Storyboard/Welcome.storyboard b/Kiwix-iOS/Storyboard/Welcome.storyboard index 85acc721..acfa5457 100644 --- a/Kiwix-iOS/Storyboard/Welcome.storyboard +++ b/Kiwix-iOS/Storyboard/Welcome.storyboard @@ -6,8 +6,6 @@ - - @@ -23,74 +21,87 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - + + + + @@ -102,7 +113,7 @@ - + diff --git a/Kiwix/Operations/ScanProcedure.swift b/Kiwix/Operations/ScanProcedure.swift index c26367a0..f83c65bd 100644 --- a/Kiwix/Operations/ScanProcedure.swift +++ b/Kiwix/Operations/ScanProcedure.swift @@ -28,6 +28,11 @@ class ScanLocalBookOperation: Procedure { super.init() add(condition: MutuallyExclusive()) name = String(describing: self) + + addDidFinishBlockObserver { (procedure, errors) in + let notification = Notification(name: Notification.Name(rawValue: "LibraryScanFinished")) + NotificationCenter.default.post(notification) + } } override func execute() {