Skip to content

Commit

Permalink
Add json demo
Browse files Browse the repository at this point in the history
  • Loading branch information
onekyle committed Dec 3, 2019
1 parent c725276 commit a66b4c6
Show file tree
Hide file tree
Showing 71 changed files with 2,167 additions and 467 deletions.
71 changes: 71 additions & 0 deletions JsonDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// AppDelegate.swift
// JsonDemo
//
// Created by Gesen on 16/3/1.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit
import SwiftTheme

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

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

// default: Red.json

ThemeManager.setTheme(jsonName: "Red", path: .mainBundle)

// status bar

UIApplication.shared.theme_setStatusBarStyle("UIStatusBarStyle", animated: true)

// navigation bar

let navigationBar = UINavigationBar.appearance()

navigationBar.theme_tintColor = "Global.barTextColor"
navigationBar.theme_barTintColor = "Global.barTintColor"
navigationBar.theme_titleTextAttributes = ThemeStringAttributesPicker(keyPath: "Global.barTextColor") { value -> [NSAttributedString.Key : AnyObject]? in
guard let rgba = value as? String else {
return nil
}

let color = UIColor(rgba: rgba)
let shadow = NSShadow(); shadow.shadowOffset = CGSize.zero
let titleTextAttributes = [
NSAttributedString.Key.foregroundColor: color,
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
NSAttributedString.Key.shadow: shadow
]

return titleTextAttributes
}

// tab bar

let tabBar = UITabBar.appearance()

tabBar.theme_tintColor = "Global.barTextColor"
tabBar.theme_barTintColor = "Global.barTintColor"

return true
}

func applicationWillResignActive(_ application: UIApplication) { }

func applicationDidEnterBackground(_ application: UIApplication) { }

func applicationWillEnterForeground(_ application: UIApplication) { }

func applicationDidBecomeActive(_ application: UIApplication) { }

func applicationWillTerminate(_ application: UIApplication) { }


}

292 changes: 292 additions & 0 deletions JsonDemo/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions JsonDemo/Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github "marmelroy/Zip"
github "jdg/MBProgressHUD" ~> 0.9.2
89 changes: 89 additions & 0 deletions JsonDemo/Detail/SelectThemeViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// SelectThemeViewController.swift
// JsonDemo
//
// Created by Gesen on 16/3/1.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit

class SelectThemeViewController: UIViewController, UIAlertViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

view.theme_backgroundColor = "Global.backgroundColor"
}

@IBAction func tapRed(_ sender: AnyObject) {
MyThemes.switchTo(.red)
}

@IBAction func tapYellow(_ sender: AnyObject) {
MyThemes.switchTo(.yello)
}

@IBAction func tapBlue(_ sender: AnyObject) {
guard MyThemes.isBlueThemeExist() else {

let title = "Not Downloaded"
let message = "Download the theme right now?"

if #available(iOS 8.0, *) {

let alert = UIAlertController(title: title,
message: message,
preferredStyle: .alert)

alert.addAction(UIAlertAction(
title: "Cancel",
style: .cancel,
handler: nil)
)
alert.addAction(UIAlertAction(
title: "Sure",
style: .default,
handler: { [unowned self] _ in
self.downloadStart()
})
)

present(alert, animated: true, completion: nil)

} else {

UIAlertView(title: title,
message: message,
delegate: self,
cancelButtonTitle: "Cancel",
otherButtonTitles: "Sure").show()

}
return
}

MyThemes.switchTo(.blue)
}

func alertView(_ alertView: UIAlertView, clickedButtonAt buttonIndex: Int) {
if buttonIndex == 1 {
downloadStart()
}
}

fileprivate func downloadStart() {
let HUD = navigationController!.showHUD("Download Theme...")

MyThemes.downloadBlueTask() { isSuccess in
HUD.label.text = isSuccess ? "Successful!" : "Failure!"
HUD.mode = .text
HUD.hide(animated: true, afterDelay: 1)

if isSuccess {
MyThemes.switchTo(.blue)
}
}
}

}
1 change: 1 addition & 0 deletions JsonDemo/Json/.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"SwitchNightCell":{"iconImage":"icon_night_dark"},"ListViewController":{"separatorColor":"#C6C5C5"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#AAA","buttonTitleColorNormal":"#000","buttonBackgroundColor":"#F4C600"},"SelectThemeCell":{"iconImage":"icon_theme_yellow"},"UIStatusBarStyle":"DarkContent","Global":{"textColor":"#000","backgroundColor":"#FFF","barTintColor":"#F4C600","barTextColor":"#000"}}
1 change: 1 addition & 0 deletions JsonDemo/Json/Night.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"SwitchNightCell":{"iconImage":"icon_night_light"},"ListViewController":{"separatorColor":"#ECF0F1"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#AAA","buttonTitleColorNormal":"#000","buttonBackgroundColor":"#ECF0F1"},"SelectThemeCell":{"iconImage":"icon_theme_light"},"UIStatusBarStyle":"LightContent","Global":{"textColor":"#ECF0F1","backgroundColor":"#292b38","barTintColor":"#01040D","barTextColor":"#FFF"}}
1 change: 1 addition & 0 deletions JsonDemo/Json/Red.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"SwitchNightCell":{"iconImage":"icon_night_dark"},"ListViewController":{"separatorColor":"#C6C5C5"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#555","buttonTitleColorNormal":"#FFF","buttonBackgroundColor":"#EB4F38"},"SelectThemeCell":{"iconImage":"icon_theme_red"},"UIStatusBarStyle":"LightContent","Global":{"textColor":"#000","backgroundColor":"#FFF","barTintColor":"#EB4F38","barTextColor":"#FFF"}}
1 change: 1 addition & 0 deletions JsonDemo/Json/Yellow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"SwitchNightCell":{"iconImage":"icon_night_dark"},"ListViewController":{"separatorColor":"#C6C5C5"},"ChangeThemeCell":{"buttonTitleColorHighlighted":"#AAA","buttonTitleColorNormal":"#000","buttonBackgroundColor":"#F4C600"},"SelectThemeCell":{"iconImage":"icon_theme_yellow"},"UIStatusBarStyle":"DarkContent","Global":{"textColor":"#000","backgroundColor":"#FFF","barTintColor":"#F4C600","barTextColor":"#000"}}
21 changes: 21 additions & 0 deletions JsonDemo/List/AboutCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AboutCell.swift
// JsonDemo
//
// Created by Gesen on 16/3/2.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit

class AboutCell: BaseCell {

@IBOutlet weak var content: UILabel!

override func awakeFromNib() {
super.awakeFromNib()

content.theme_textColor = "Global.textColor"
}

}
19 changes: 19 additions & 0 deletions JsonDemo/List/BaseCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// BaseCell.swift
// JsonDemo
//
// Created by Gesen on 16/3/14.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit

class BaseCell: UITableViewCell {

override func awakeFromNib() {
super.awakeFromNib()

theme_backgroundColor = "Global.backgroundColor"
}

}
28 changes: 28 additions & 0 deletions JsonDemo/List/ChangeThemeCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// ChangeThemeCell.swift
// JsonDemo
//
// Created by Gesen on 16/3/2.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit

class ChangeThemeCell: BaseCell {

@IBOutlet weak var changeTheme: UIButton!

override func awakeFromNib() {
super.awakeFromNib()

changeTheme.theme_setTitleColor("ChangeThemeCell.buttonTitleColorNormal", forState: .normal)
changeTheme.theme_setTitleColor("ChangeThemeCell.buttonTitleColorNormal", forState: .highlighted)
changeTheme.theme_backgroundColor = "ChangeThemeCell.buttonBackgroundColor"
changeTheme.layer.cornerRadius = changeTheme.bounds.size.width / 2
}

@IBAction func tapChange(_ sender: UIButton) {
MyThemes.switchToNext()
}

}
20 changes: 20 additions & 0 deletions JsonDemo/List/ListViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// ListViewController.swift
// JsonDemo
//
// Created by Gesen on 16/3/1.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit

class ListViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

tableView.theme_backgroundColor = "Global.backgroundColor"
tableView.theme_separatorColor = "ListViewController.separatorColor"
}

}
23 changes: 23 additions & 0 deletions JsonDemo/List/SelectThemeCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// SelectThemeCell.swift
// JsonDemo
//
// Created by Gesen on 16/3/2.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit

class SelectThemeCell: BaseCell {

@IBOutlet weak var title: UILabel!
@IBOutlet weak var themeIcon: UIImageView!

override func awakeFromNib() {
super.awakeFromNib()

title.theme_textColor = "Global.textColor"
themeIcon.theme_image = "SelectThemeCell.iconImage"
}

}
37 changes: 37 additions & 0 deletions JsonDemo/List/SwitchNightCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// SwitchNightCell.swift
// JsonDemo
//
// Created by Gesen on 16/3/2.
// Copyright © 2016年 Gesen. All rights reserved.
//

import UIKit
import SwiftTheme

class SwitchNightCell: BaseCell {

@IBOutlet weak var title: UILabel!
@IBOutlet weak var nightIcon: UIImageView!
@IBOutlet weak var nightSwitch: UISwitch!

override func awakeFromNib() {
super.awakeFromNib()

title.theme_textColor = "Global.textColor"
nightIcon.theme_image = "SwitchNightCell.iconImage"

updateNightSwitch()

NotificationCenter.default.addObserver(self, selector: #selector(updateNightSwitch), name: NSNotification.Name(rawValue: ThemeUpdateNotification), object: nil)
}

@IBAction func changeNight(_ sender: UISwitch) {
MyThemes.switchNight(sender.isOn)
}

@objc fileprivate func updateNightSwitch() {
nightSwitch.isOn = MyThemes.isNight()
}

}
Loading

0 comments on commit a66b4c6

Please sign in to comment.