Skip to content

Commit

Permalink
Added themes.
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
gdombiak committed Jul 26, 2018
1 parent af09bef commit be644d0
Show file tree
Hide file tree
Showing 30 changed files with 739 additions and 39 deletions.
54 changes: 49 additions & 5 deletions OctoPod.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "emblem-art.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions OctoPod/Assets.xcassets/Settings UI/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "3d-printer (1).png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
217 changes: 194 additions & 23 deletions OctoPod/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion OctoPod/File UI/FileDetailsViewController.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import UIKit

class FileDetailsViewController: UITableViewController {
class FileDetailsViewController: ThemedStaticUITableViewController {

var printFile: PrintFile?

@IBOutlet weak var fileTextLabel: UILabel!
@IBOutlet weak var sizeTextLabel: UILabel!
@IBOutlet weak var originTextLabel: UILabel!
@IBOutlet weak var printTimeTextLabel: UILabel!
@IBOutlet weak var uploadedTextLabel: UILabel!

@IBOutlet weak var fileNameLabel: UILabel!
@IBOutlet weak var sizeLabel: UILabel!
@IBOutlet weak var originLabel: UILabel!
Expand All @@ -21,6 +27,7 @@ class FileDetailsViewController: UITableViewController {
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
fileNameLabel.text = printFile?.display
sizeLabel.text = printFile?.displaySize()
originLabel.text = printFile?.displayOrigin()
Expand All @@ -29,6 +36,8 @@ class FileDetailsViewController: UITableViewController {

printButton.isEnabled = printFile != nil && printFile!.canBePrinted()
deleteButton.isEnabled = printFile != nil && printFile!.canBeDeleted()

themeLabels()
}

@IBAction func printClicked(_ sender: Any) {
Expand Down Expand Up @@ -75,4 +84,22 @@ class FileDetailsViewController: UITableViewController {
}
return ""
}

fileprivate func themeLabels() {
let theme = Theme.currentTheme()
let textLabelColor = theme.labelColor()
let textColor = theme.textColor()

fileTextLabel.textColor = textLabelColor
sizeTextLabel.textColor = textLabelColor
originTextLabel.textColor = textLabelColor
printTimeTextLabel.textColor = textLabelColor
uploadedTextLabel.textColor = textLabelColor

fileNameLabel.textColor = textColor
sizeLabel.textColor = textColor
originLabel.textColor = textColor
estimatedPrintTimeLabel.textColor = textColor
uploadedDateLabel.textColor = textColor
}
}
39 changes: 38 additions & 1 deletion OctoPod/File UI/FilesTreeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ import UIKit

class FilesTreeViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

private var currentTheme: Theme.ThemeChoice!

let printerManager: PrinterManager = { return (UIApplication.shared.delegate as! AppDelegate).printerManager! }()
let octoprintClient: OctoPrintClient = { return (UIApplication.shared.delegate as! AppDelegate).octoprintClient }()

@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var sortByTextLabel: UILabel!
@IBOutlet weak var sortByControl: UISegmentedControl!
@IBOutlet weak var refreshSDButton: UIButton!
var refreshControl: UIRefreshControl?

var files: Array<PrintFile> = Array()

override func viewDidLoad() {
super.viewDidLoad()

// Remember current theme so we know when to repaint
currentTheme = Theme.currentTheme()

// Create, configure and add UIRefreshControl to table view
refreshControl = UIRefreshControl()
Expand All @@ -26,12 +33,23 @@ class FilesTreeViewController: UIViewController, UITableViewDataSource, UITableV
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

if currentTheme != Theme.currentTheme() {
// Theme changed so repaint table now (to prevent quick flash in the UI with the old theme)
tableView.reloadData()
currentTheme = Theme.currentTheme()
}

if let printer = printerManager.getDefaultPrinter() {
// Update window title to Camera name
navigationItem.title = printer.name

loadFiles(done: nil)
}

ThemeUIUtils.applyTheme(table: tableView, staticCells: false)
applyTheme()
}

override func didReceiveMemoryWarning() {
Expand Down Expand Up @@ -80,6 +98,10 @@ class FilesTreeViewController: UIViewController, UITableViewDataSource, UITableV
}
}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
ThemeUIUtils.themeCell(cell: cell)
}

// MARK: - Unwind operations

@IBAction func backFromDelete(_ sender: UIStoryboardSegue) {
Expand Down Expand Up @@ -165,8 +187,23 @@ class FilesTreeViewController: UIViewController, UITableViewDataSource, UITableV
})
}

// MARK: - Private functions
// MARK: - Theme functions

fileprivate func applyTheme() {
let theme = Theme.currentTheme()
let tintColor = theme.tintColor()

// Set background color to the view
view.backgroundColor = theme.backgroundColor()
// Set background color to the refresh SD button
refreshSDButton.tintColor = tintColor
// Set background color to the sort control
sortByTextLabel.textColor = theme.labelColor()
sortByControl.tintColor = tintColor
}

// MARK: - Private functions

fileprivate func loadFiles(delay seconds: Double) {
// Wait requested seconds before loading files (so SD card has time to be read)
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
Expand Down
12 changes: 9 additions & 3 deletions OctoPod/File UI/FolderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit

// VC that renders content of a folder
// Files were already fetched by FilesTreeViewController
class FolderViewController: UITableViewController {
class FolderViewController: ThemedDynamicUITableViewController {

let octoprintClient: OctoPrintClient = { return (UIApplication.shared.delegate as! AppDelegate).octoprintClient }()

Expand All @@ -11,19 +11,25 @@ class FolderViewController: UITableViewController {
var files: Array<PrintFile> = Array() // Track files of the folder

override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Update window title to folder we are browsing
navigationItem.title = folder.display

files = folder.children!

// Clear selected row when going back to this VC
if let selectionIndexPath = self.tableView.indexPathForSelectedRow {
tableView.deselectRow(at: selectionIndexPath, animated: animated)
}
}

// MARK: - Table view data source
Expand Down
2 changes: 1 addition & 1 deletion OctoPod/Model/PrintFile.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

class PrintFile {
static let SORT_BY_PREFERENCE = "filesSortBy"
private static let SORT_BY_PREFERENCE = "filesSortBy"

enum SortBy: Int {
case uploadDate = 0
Expand Down
21 changes: 20 additions & 1 deletion OctoPod/Move UI/MoveSubViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import UIKit
// OctoPrint does not report current fan speed or extruder flow rate so we
// initially assume 100% and then just leave last value set by user. Display
// value will go back to 100% if app is terminated
class MoveSubViewController: UITableViewController {
class MoveSubViewController: ThemedStaticUITableViewController {

let printerManager: PrinterManager = { return (UIApplication.shared.delegate as! AppDelegate).printerManager! }()
let octoprintClient: OctoPrintClient = { return (UIApplication.shared.delegate as! AppDelegate).octoprintClient }()

@IBOutlet weak var flowRateTextLabel: UILabel!
@IBOutlet weak var fanTextLabel: UILabel!
@IBOutlet weak var disableMotorLabel: UILabel!

@IBOutlet weak var xyStepSegmentedControl: UISegmentedControl!
@IBOutlet weak var zStepSegmentedControl: UISegmentedControl!
@IBOutlet weak var eStepSegmentedControl: UISegmentedControl!
Expand All @@ -31,11 +35,13 @@ class MoveSubViewController: UITableViewController {
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let _ = printerManager.getDefaultPrinter() {
enableButtons(enable: true)
} else {
enableButtons(enable: false)
}
themeLabels()
}

override func didReceiveMemoryWarning() {
Expand Down Expand Up @@ -240,6 +246,19 @@ class MoveSubViewController: UITableViewController {
})
}

fileprivate func themeLabels() {
let theme = Theme.currentTheme()
let textLabelColor = theme.labelColor()
let textColor = theme.textColor()

flowRateTextLabel.textColor = textLabelColor
fanTextLabel.textColor = textLabelColor
disableMotorLabel.textColor = textLabelColor

flowRateLabel.textColor = textColor
fanSpeedLabel.textColor = textColor
}

fileprivate func showAlert(_ title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .default, handler: { (UIAlertAction) -> Void in
Expand Down
22 changes: 22 additions & 0 deletions OctoPod/NavigationController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import UIKit

class NavigationController: UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let theme = Theme.currentTheme()

navigationBar.barTintColor = theme.navigationTopColor()
}
}
45 changes: 43 additions & 2 deletions OctoPod/Panel UI/PrinterSubpanelViewController.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import UIKit

class PrinterSubpanelViewController: UITableViewController, UIPopoverPresentationControllerDelegate {
class PrinterSubpanelViewController: ThemedStaticUITableViewController, UIPopoverPresentationControllerDelegate {

enum buttonsScope {
case all
case all_except_connect
}

@IBOutlet weak var printedTextLabel: UILabel!
@IBOutlet weak var printTimeTextLabel: UILabel!
@IBOutlet weak var printTimeLeftTextLabel: UILabel!
@IBOutlet weak var printerStatusTextLabel: UILabel!
@IBOutlet weak var tool0TextLabel: UILabel!
@IBOutlet weak var bedTextLabel: UILabel!
@IBOutlet weak var tool1TextLabel: UILabel!

@IBOutlet weak var printerStatusLabel: UILabel!

@IBOutlet weak var progressView: UIProgressView!
Expand Down Expand Up @@ -43,6 +51,11 @@ class PrinterSubpanelViewController: UITableViewController, UIPopoverPresentatio
clearValues()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
themeLabels()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
Expand Down Expand Up @@ -94,7 +107,7 @@ class PrinterSubpanelViewController: UITableViewController, UIPopoverPresentatio
if let state = event.state {
self.printerStatusLabel.text = state
}

if let progress = event.progressCompletion {
let progressText = String(format: "%.1f", progress)
self.progressLabel.text = "\(progressText)%"
Expand Down Expand Up @@ -208,4 +221,32 @@ class PrinterSubpanelViewController: UITableViewController, UIPopoverPresentatio
self.tool1SetTempButton.isEnabled = false
}
}

fileprivate func themeLabels() {
let theme = Theme.currentTheme()
let textLabelColor = theme.labelColor()
let textColor = theme.textColor()

printedTextLabel.textColor = textLabelColor
printTimeTextLabel.textColor = textLabelColor
printTimeLeftTextLabel.textColor = textLabelColor
printerStatusTextLabel.textColor = textLabelColor
tool0TextLabel.textColor = textLabelColor
bedTextLabel.textColor = textLabelColor
tool1TextLabel.textColor = textLabelColor
tool0SplitLabel.textColor = textLabelColor
tool1SplitLabel.textColor = textLabelColor
bedSplitLabel.textColor = textLabelColor

printerStatusLabel.textColor = textColor
progressLabel.textColor = textColor
printTimeLabel.textColor = textColor
printTimeLeftLabel.textColor = textColor
tool0ActualLabel.textColor = textColor
tool0TargetLabel.textColor = textColor
tool1ActualLabel.textColor = textColor
tool1TargetLabel.textColor = textColor
bedActualLabel.textColor = textColor
bedTargetLabel.textColor = textColor
}
}
Loading

0 comments on commit be644d0

Please sign in to comment.