Replaces light theme with “opaque” dark theme

Previous dark theme has been renamed “translucent”
This commit is contained in:
Riley Testut 2016-11-22 19:57:39 -08:00
parent 6b0ad3cf8f
commit d3b4f25f20
7 changed files with 85 additions and 47 deletions

View File

@ -220,7 +220,7 @@ extension GameViewController
{ {
case "showGamesViewController": case "showGamesViewController":
let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController let gamesViewController = (segue.destination as! UINavigationController).topViewController as! GamesViewController
gamesViewController.theme = .dark gamesViewController.theme = .translucent
gamesViewController.activeEmulatorCore = self.emulatorCore gamesViewController.activeEmulatorCore = self.emulatorCore
self.updateAutoSaveState() self.updateAutoSaveState()

View File

@ -19,4 +19,9 @@ extension UIColor
{ {
return UIColor(red: 184.0/255.0, green: 97.0/255.0, blue: 253.0/255.0, alpha: 1.0) return UIColor(red: 184.0/255.0, green: 97.0/255.0, blue: 253.0/255.0, alpha: 1.0)
} }
}
class var deltaDarkGray: UIColor
{
return UIColor(white: 0.15, alpha: 1.0)
}
} }

View File

@ -23,9 +23,20 @@ class GameCollectionViewController: UICollectionViewController
} }
} }
var theme: Theme = .light { var theme: Theme = .opaque {
didSet { didSet {
self.collectionView?.reloadData() // self.collectionView?.reloadData()
// Calling reloadData sometimes will not update the cells correctly if an insertion/deletion animation is in progress
// As a workaround, we manually iterate over and configure each cell ourselves
for cell in self.collectionView?.visibleCells ?? []
{
if let indexPath = self.collectionView?.indexPath(for: cell)
{
self.configure(cell as! GridCollectionViewCell, for: indexPath)
}
}
} }
} }
@ -180,19 +191,18 @@ private extension GameCollectionViewController
switch self.theme switch self.theme
{ {
case .light: case .opaque:
cell.textLabel.textColor = UIColor.darkText
cell.isTextLabelVibrancyEnabled = false cell.isTextLabelVibrancyEnabled = false
cell.isImageViewVibrancyEnabled = false cell.isImageViewVibrancyEnabled = false
case .dark: case .translucent:
cell.textLabel.textColor = UIColor.white
cell.isTextLabelVibrancyEnabled = true cell.isTextLabelVibrancyEnabled = true
cell.isImageViewVibrancyEnabled = true cell.isImageViewVibrancyEnabled = true
} }
cell.maximumImageSize = CGSize(width: 90, height: 90) cell.maximumImageSize = CGSize(width: 90, height: 90)
cell.textLabel.text = game.name cell.textLabel.text = game.name
cell.textLabel.textColor = UIColor.gray
if let artworkURL = game.artworkURL, !ignoreImageOperations if let artworkURL = game.artworkURL, !ignoreImageOperations
{ {

View File

@ -15,13 +15,24 @@ import Roxas
class GamesViewController: UIViewController class GamesViewController: UIViewController
{ {
var theme: Theme = .light { var theme: Theme = .opaque {
didSet { didSet {
self.updateTheme() self.updateTheme()
} }
} }
weak var activeEmulatorCore: EmulatorCore? weak var activeEmulatorCore: EmulatorCore? {
didSet
{
let game = oldValue?.game as? Game
NotificationCenter.default.removeObserver(self, name: .NSManagedObjectContextObjectsDidChange, object: game?.managedObjectContext)
if let game = self.activeEmulatorCore?.game as? Game
{
NotificationCenter.default.addObserver(self, selector: #selector(GamesViewController.managedObjectContextDidChange(with:)), name: .NSManagedObjectContextObjectsDidChange, object: game.managedObjectContext)
}
}
}
fileprivate var pageViewController: UIPageViewController! fileprivate var pageViewController: UIPageViewController!
fileprivate var backgroundView: RSTBackgroundView! fileprivate var backgroundView: RSTBackgroundView!
@ -72,6 +83,11 @@ extension GamesViewController
self.pageControl.centerXAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerXAnchor)!, constant: 0).isActive = true self.pageControl.centerXAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerXAnchor)!, constant: 0).isActive = true
self.pageControl.centerYAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerYAnchor)!, constant: 0).isActive = true self.pageControl.centerYAnchor.constraint(equalTo: (self.navigationController?.toolbar.centerYAnchor)!, constant: 0).isActive = true
self.navigationController?.navigationBar.barStyle = .blackTranslucent
self.navigationController?.toolbar.barStyle = .blackTranslucent
self.updateTheme()
} }
override func viewWillAppear(_ animated: Bool) override func viewWillAppear(_ animated: Bool)
@ -140,15 +156,8 @@ private extension GamesViewController
{ {
switch self.theme switch self.theme
{ {
case .light: case .opaque: self.view.backgroundColor = UIColor.deltaDarkGray
self.view.backgroundColor = UIColor.white case .translucent: self.view.backgroundColor = nil
self.navigationController?.navigationBar.barStyle = .default
self.navigationController?.toolbar.barStyle = .default
case .dark:
self.view.backgroundColor = nil
self.navigationController?.navigationBar.barStyle = .blackTranslucent
self.navigationController?.toolbar.barStyle = .blackTranslucent
} }
if let viewControllers = self.pageViewController.viewControllers as? [GameCollectionViewController] if let viewControllers = self.pageViewController.viewControllers as? [GameCollectionViewController]
@ -267,6 +276,30 @@ extension GamesViewController: ImportControllerDelegate
} }
} }
private extension GamesViewController
{
@objc func managedObjectContextDidChange(with notification: Notification)
{
guard let deletedObjects = notification.userInfo?[NSDeletedObjectsKey] as? Set<NSManagedObject> else { return }
if let game = self.activeEmulatorCore?.game as? Game
{
if deletedObjects.contains(game)
{
DispatchQueue.main.async {
self.theme = .opaque
}
}
}
else
{
DispatchQueue.main.async {
self.theme = .opaque
}
}
}
}
//MARK: - UIPageViewController - //MARK: - UIPageViewController -
/// UIPageViewController /// UIPageViewController
extension GamesViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate extension GamesViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate

View File

@ -26,7 +26,7 @@ class SaveStatesStoryboardSegue: UIStoryboardSegue
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(SaveStatesStoryboardSegue.handleDoneButton)) let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(SaveStatesStoryboardSegue.handleDoneButton))
saveStatesViewController.navigationItem.rightBarButtonItem = doneButton saveStatesViewController.navigationItem.rightBarButtonItem = doneButton
guard saveStatesViewController.theme == .dark else { return } guard saveStatesViewController.theme == .translucent else { return }
let sourceView = self.source.navigationController!.view! let sourceView = self.source.navigationController!.view!
@ -53,7 +53,7 @@ class SaveStatesStoryboardUnwindSegue: UIStoryboardSegue
{ {
super.perform() super.perform()
guard let saveStatesViewController = (self.source as? UINavigationController)?.topViewController as? SaveStatesViewController, saveStatesViewController.theme == .dark else { return } guard let saveStatesViewController = (self.source as? UINavigationController)?.topViewController as? SaveStatesViewController, saveStatesViewController.theme == .translucent else { return }
let destinationView = self.destination.navigationController!.view! let destinationView = self.destination.navigationController!.view!

View File

@ -49,7 +49,7 @@ class SaveStatesViewController: UICollectionViewController
var mode = Mode.loading var mode = Mode.loading
var theme = Theme.dark { var theme = Theme.translucent {
didSet { didSet {
if self.isViewLoaded if self.isViewLoaded
{ {
@ -135,6 +135,9 @@ extension SaveStatesViewController
self.registerForPreviewing(with: self, sourceView: self.collectionView!) self.registerForPreviewing(with: self, sourceView: self.collectionView!)
self.navigationController?.navigationBar.barStyle = .blackTranslucent
self.navigationController?.toolbar.barStyle = .blackTranslucent
self.updateBackgroundView() self.updateBackgroundView()
self.updateTheme() self.updateTheme()
} }
@ -192,23 +195,17 @@ private extension SaveStatesViewController
{ {
switch self.theme switch self.theme
{ {
case .light: case .opaque:
self.view.backgroundColor = UIColor.white self.view.backgroundColor = UIColor.deltaDarkGray
self.navigationController?.navigationBar.barStyle = .default
self.navigationController?.toolbar.barStyle = .default
self.vibrancyView.effect = nil self.vibrancyView.effect = nil
self.backgroundView.textLabel.textColor = UIColor.gray self.backgroundView.textLabel.textColor = UIColor.gray
self.backgroundView.detailTextLabel.textColor = UIColor.gray self.backgroundView.detailTextLabel.textColor = UIColor.gray
case .dark: case .translucent:
self.view.backgroundColor = nil self.view.backgroundColor = nil
self.navigationController?.navigationBar.barStyle = .blackTranslucent
self.navigationController?.toolbar.barStyle = .blackTranslucent
self.vibrancyView.effect = UIVibrancyEffect(blurEffect: UIBlurEffect(style: .dark)) self.vibrancyView.effect = UIVibrancyEffect(blurEffect: UIBlurEffect(style: .dark))
self.backgroundView.textLabel.textColor = UIColor.white self.backgroundView.textLabel.textColor = UIColor.white
@ -224,20 +221,17 @@ private extension SaveStatesViewController
cell.imageView.backgroundColor = UIColor.white cell.imageView.backgroundColor = UIColor.white
cell.imageView.image = UIImage(named: "DeltaPlaceholder") cell.imageView.image = UIImage(named: "DeltaPlaceholder")
cell.textLabel.textColor = UIColor.gray
switch self.theme switch self.theme
{ {
case .light: case .opaque:
cell.isTextLabelVibrancyEnabled = false cell.isTextLabelVibrancyEnabled = false
cell.isImageViewVibrancyEnabled = false cell.isImageViewVibrancyEnabled = false
cell.textLabel.textColor = UIColor.gray case .translucent:
case .dark:
cell.isTextLabelVibrancyEnabled = true cell.isTextLabelVibrancyEnabled = true
cell.isImageViewVibrancyEnabled = true cell.isImageViewVibrancyEnabled = true
cell.textLabel.textColor = UIColor.white
} }
if !ignoreOperations if !ignoreOperations
@ -289,16 +283,12 @@ private extension SaveStatesViewController
} }
headerView.textLabel.text = title headerView.textLabel.text = title
headerView.textLabel.textColor = UIColor.white
switch self.theme switch self.theme
{ {
case .light: case .opaque: headerView.isTextLabelVibrancyEnabled = false
headerView.textLabel.textColor = UIColor.gray case .translucent: headerView.isTextLabelVibrancyEnabled = true
headerView.isTextLabelVibrancyEnabled = false
case .dark:
headerView.textLabel.textColor = UIColor.white
headerView.isTextLabelVibrancyEnabled = true
} }
} }

View File

@ -10,6 +10,6 @@ import Foundation
enum Theme enum Theme
{ {
case light case opaque
case dark case translucent
} }