This commit is contained in:
Fin 2020-05-26 16:03:50 +08:00
parent 636d34bbb0
commit b202e1e240
14 changed files with 127 additions and 64 deletions

View File

@ -33,6 +33,7 @@
0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; }; 0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; };
0661A54D204FDA4100965E4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */; }; 0661A54D204FDA4100965E4E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */; };
06802E5320ECC40C00767047 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; }; 06802E5320ECC40C00767047 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; };
068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068F66B2247BD84C00DAD25A /* MessageListViewController.swift */; };
06B1158D247BA6D5006D91FB /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06B1158C247BA6D5006D91FB /* CloudKit.framework */; }; 06B1158D247BA6D5006D91FB /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06B1158C247BA6D5006D91FB /* CloudKit.framework */; };
06B1158F247BB1FB006D91FB /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B1158E247BB1FB006D91FB /* Message.swift */; }; 06B1158F247BB1FB006D91FB /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B1158E247BB1FB006D91FB /* Message.swift */; };
06B11591247BC132006D91FB /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B1158E247BB1FB006D91FB /* Message.swift */; }; 06B11591247BC132006D91FB /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06B1158E247BB1FB006D91FB /* Message.swift */; };
@ -104,6 +105,7 @@
0683486A2050F1310024B6DA /* Bark.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Bark.entitlements; sourceTree = "<group>"; }; 0683486A2050F1310024B6DA /* Bark.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Bark.entitlements; sourceTree = "<group>"; };
0683487020510FB20024B6DA /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; }; 0683487020510FB20024B6DA /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
0683487220510FB20024B6DA /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; }; 0683487220510FB20024B6DA /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; };
068F66B2247BD84C00DAD25A /* MessageListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageListViewController.swift; sourceTree = "<group>"; };
06B1158C247BA6D5006D91FB /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; 06B1158C247BA6D5006D91FB /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
06B1158E247BB1FB006D91FB /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; }; 06B1158E247BB1FB006D91FB /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
06B11590247BBC15006D91FB /* NotificationServiceExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationServiceExtension.entitlements; sourceTree = "<group>"; }; 06B11590247BBC15006D91FB /* NotificationServiceExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NotificationServiceExtension.entitlements; sourceTree = "<group>"; };
@ -157,6 +159,7 @@
0661A544204FDA4100965E4E /* HomeViewController.swift */, 0661A544204FDA4100965E4E /* HomeViewController.swift */,
0637FA8920E0D58800E80174 /* NewServerViewController.swift */, 0637FA8920E0D58800E80174 /* NewServerViewController.swift */,
0603706C20E23EC000F4CA05 /* BarkSFSafariViewController.swift */, 0603706C20E23EC000F4CA05 /* BarkSFSafariViewController.swift */,
068F66B2247BD84C00DAD25A /* MessageListViewController.swift */,
); );
path = Controller; path = Controller;
sourceTree = "<group>"; sourceTree = "<group>";
@ -502,6 +505,7 @@
0637FA7C20E0930E00E80174 /* BarkApi.swift in Sources */, 0637FA7C20E0930E00E80174 /* BarkApi.swift in Sources */,
0637FA8020E0981E00E80174 /* BarkSettings.swift in Sources */, 0637FA8020E0981E00E80174 /* BarkSettings.swift in Sources */,
0603706B20E20A7C00F4CA05 /* String+Extension.swift in Sources */, 0603706B20E20A7C00F4CA05 /* String+Extension.swift in Sources */,
068F66B3247BD84C00DAD25A /* MessageListViewController.swift in Sources */,
0661A543204FDA4100965E4E /* AppDelegate.swift in Sources */, 0661A543204FDA4100965E4E /* AppDelegate.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@ -39,6 +39,17 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
} }
} }
} }
//
let bar = UINavigationBar.appearance(whenContainedInInstancesOf: [BarkNavigationController.self])
bar.backIndicatorImage = UIImage(named: "back")
bar.backIndicatorTransitionMaskImage = UIImage(named: "back")
bar.tintColor = Color.darkText.primary
let buttonItem = UIBarButtonItem.appearance(whenContainedInInstancesOf: [BarkNavigationController.self])
buttonItem.setTitleTextAttributes([NSAttributedString.Key.font: RobotoFont.regular(with: 0)], for: .normal)
buttonItem.setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -1000, vertical: 0), for: .default)
let groupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.bark") let groupUrl = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.bark")
let fileUrl = groupUrl?.appendingPathComponent("bark.realm") let fileUrl = groupUrl?.appendingPathComponent("bark.realm")
let config = Realm.Configuration( let config = Realm.Configuration(

View File

@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "back@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "back@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -27,11 +27,6 @@
<key>NSAllowsArbitraryLoads</key> <key>NSAllowsArbitraryLoads</key>
<true/> <true/>
</dict> </dict>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key> <key>UIRequiredDeviceCapabilities</key>

View File

@ -8,30 +8,12 @@
import UIKit import UIKit
import Material import Material
import UINavigationItem_Margin
class BarkNavigationController: NavigationController{ class BarkNavigationController: UINavigationController{
override func prepare() { override func viewDidLoad() {
super.prepare() super.viewDidLoad()
isMotionEnabled = true self.navigationItem.leftMargin = 8
motionNavigationTransitionType = .autoReverse(presenting: .fade) self.navigationItem.rightMargin = 8
guard let v = navigationBar as? NavigationBar else {
return
}
v.depthPreset = .none
v.dividerColor = Color.grey.lighten2
navigationBar.backgroundColor = Color.blue.darken2
statusBarStyle = .lightContent
}
override var childForStatusBarStyle: UIViewController?{
get {
return self.topViewController
}
} }
} }

View File

@ -12,10 +12,9 @@ class BaseViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
self.navigationItem.backButton.tintColor = UIColor.white
self.view.backgroundColor = Color.grey.lighten5 self.view.backgroundColor = Color.grey.lighten5
navigationItem.titleLabel.textColor = .white self.navigationItem.leftMargin = 8
navigationItem.titleLabel.font = UIFont.systemFont(ofSize: 16) self.navigationItem.rightMargin = 8
} }
override var preferredStatusBarStyle: UIStatusBarStyle{ override var preferredStatusBarStyle: UIStatusBarStyle{

View File

@ -12,14 +12,13 @@ import Material
class HomeViewController: BaseViewController { class HomeViewController: BaseViewController {
let newButton: IconButton = { let newButton: IconButton = {
let btn = IconButton(image: Icon.add, tintColor: .white) let btn = IconButton(image: Icon.add, tintColor: .black)
btn.pulseColor = .white btn.pulseColor = .black
btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
return btn return btn
}() }()
let startButton = FABButton(title: NSLocalizedString("RegisterDevice")) lazy var startButton = FABButton(title: NSLocalizedString("RegisterDevice"))
let statusButton = IconButton(image: UIImage(named: "baseline_https_black_24pt"), tintColor: .white)
let tableView :UITableView = { let tableView :UITableView = {
let tableView = UITableView() let tableView = UITableView()
@ -74,14 +73,12 @@ class HomeViewController: BaseViewController {
super.viewDidLoad() super.viewDidLoad()
self.view.backgroundColor = Color.grey.lighten3 self.view.backgroundColor = Color.grey.lighten3
navigationItem.titleLabel.textColor = .white
navigationItem.titleLabel.textAlignment = .left
navigationItem.detailLabel.textAlignment = .left
navigationItem.detailLabel.textColor = .white
newButton.addTarget(self, action: #selector(new), for: .touchUpInside) newButton.addTarget(self, action: #selector(new), for: .touchUpInside)
navigationItem.rightViews = [newButton] navigationItem.rightBarButtonItem = UIBarButtonItem(customView: newButton)
navigationItem.leftViews = [statusButton]
let messageBtn = IconButton(image: Icon.history, tintColor: .black)
messageBtn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: messageBtn)
self.view.addSubview(self.tableView) self.view.addSubview(self.tableView)
self.tableView.snp.makeConstraints { (make ) in self.tableView.snp.makeConstraints { (make ) in
@ -93,6 +90,7 @@ class HomeViewController: BaseViewController {
UNUserNotificationCenter.current().getNotificationSettings { (settings) in UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus != .authorized { if settings.authorizationStatus != .authorized {
dispatch_sync_safely_main_queue { dispatch_sync_safely_main_queue {
self.startButton.backgroundColor = Color.white
self.startButton.transition([ .scale(0.75) , .opacity(0)] ) self.startButton.transition([ .scale(0.75) , .opacity(0)] )
self.startButton.addTarget(self, action: #selector(self.start), for: .touchUpInside) self.startButton.addTarget(self, action: #selector(self.start), for: .touchUpInside)
self.view.addSubview(self.startButton) self.view.addSubview(self.startButton)
@ -110,7 +108,8 @@ class HomeViewController: BaseViewController {
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
if let url = URL(string: ServerManager.shared.currentAddress) { if let url = URL(string: ServerManager.shared.currentAddress) {
navigationItem.titleLabel.text = url.host // navigationItem.titleLabel.text = url.host
navigationItem.title = url.host
refreshState() refreshState()
} }
} }
@ -187,20 +186,14 @@ extension HomeViewController {
switch Client.shared.state { switch Client.shared.state {
case .ok: case .ok:
if let url = URL(string: ServerManager.shared.currentAddress) { if let url = URL(string: ServerManager.shared.currentAddress) {
if url.scheme?.lowercased() == "https" { if url.scheme?.lowercased() != "https" {
navigationItem.detailLabel.text = NSLocalizedString("SecureConnection") self.showSnackbar(text: NSLocalizedString("InsecureConnection"))
statusButton.image = UIImage(named: "baseline_https_black_24pt")
}
else {
navigationItem.detailLabel.text = NSLocalizedString("InsecureConnection")
statusButton.image = UIImage(named: "baseline_http_black_24pt")
} }
self.tableView.reloadData() self.tableView.reloadData()
} }
case .unRegister:
navigationItem.detailLabel.text = NSLocalizedString("UnregisteredDevice")
case .serverError: case .serverError:
navigationItem.detailLabel.text = NSLocalizedString("ServerError") self.showSnackbar(text: NSLocalizedString("ServerError"))
default: break;
} }
} }
} }

View File

@ -0,0 +1,30 @@
//
// MessageListViewController.swift
// Bark
//
// Created by huangfeng on 2020/5/25.
// Copyright © 2020 Fin. All rights reserved.
//
import UIKit
class MessageListViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}

View File

@ -31,16 +31,18 @@ class NewServerViewController: BaseViewController {
return label return label
}() }()
let doneButton = IconButton(image: Icon.check, tintColor: .white) let doneButton = IconButton(image: Icon.check, tintColor: .black)
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
navigationItem.titleLabel.text = NSLocalizedString("AddServer")
navigationItem.title = NSLocalizedString("AddServer")
doneButton.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
doneButton.addTarget(self, action: #selector(done), for: .touchUpInside) doneButton.addTarget(self, action: #selector(done), for: .touchUpInside)
navigationItem.rightViews = [doneButton] navigationItem.rightBarButtonItem = UIBarButtonItem(customView: doneButton)
self.view.layout(addressTextField).top(40).left(10).right(10) self.view.layout(addressTextField).top(kNavigationHeight + 40).left(10).right(10)
self.view.addSubview(noticeLabel) self.view.addSubview(noticeLabel)
noticeLabel.snp.makeConstraints { (make) in noticeLabel.snp.makeConstraints { (make) in
@ -52,9 +54,11 @@ class NewServerViewController: BaseViewController {
} }
override func viewDidAppear(_ animated: Bool) { override func viewDidAppear(_ animated: Bool) {
if (addressTextField.text?.count ?? 0) <= 0 {
_ = self.addressTextField.becomeFirstResponder() _ = self.addressTextField.becomeFirstResponder()
addressTextField.text = "https://" addressTextField.text = "https://"
} }
}
@objc func done(){ @objc func done(){
self.addressTextField.resignFirstResponder() self.addressTextField.resignFirstResponder()

View File

@ -1,4 +1,4 @@
// //
// Defines.swift // Defines.swift
// Bark // Bark
// //
@ -30,3 +30,19 @@ extension UIViewController {
func NSLocalizedString( _ key:String ) -> String { func NSLocalizedString( _ key:String ) -> String {
return NSLocalizedString(key, comment: "") return NSLocalizedString(key, comment: "")
} }
let kNavigationHeight: CGFloat = {
return kSafeAreaInsets.top + 44
}()
let kSafeAreaInsets:UIEdgeInsets = {
if #available(iOS 12.0, *){
return UIWindow().safeAreaInsets
}
else if #available(iOS 11.0, *){
let inset = UIWindow().safeAreaInsets
if inset.top > 0 { return inset}
//iOS 11 safeAreaInsets.top 0iOS12 便
}
return UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
}()

View File

@ -1,6 +1,7 @@
platform:ios,'10.0' platform:ios,'10.0'
inhibit_all_warnings! inhibit_all_warnings!
use_modular_headers! use_modular_headers!
source 'https://github.com/CocoaPods/Specs.git'
def pods def pods
pod 'SnapKit' pod 'SnapKit'
@ -14,6 +15,7 @@ def pods
pod 'DeviceKit' pod 'DeviceKit'
pod 'DefaultsKit', :git => 'https://github.com/nmdias/DefaultsKit' pod 'DefaultsKit', :git => 'https://github.com/nmdias/DefaultsKit'
pod 'IceCream' pod 'IceCream'
pod 'UINavigationItem+Margin'
end end
target 'Bark' do target 'Bark' do

View File

@ -28,6 +28,7 @@ PODS:
- SnapKit (5.0.1) - SnapKit (5.0.1)
- SVProgressHUD (2.2.5) - SVProgressHUD (2.2.5)
- SwiftyJSON (5.0.0) - SwiftyJSON (5.0.0)
- "UINavigationItem+Margin (2.1.1)"
DEPENDENCIES: DEPENDENCIES:
- DefaultsKit (from `https://github.com/nmdias/DefaultsKit`) - DefaultsKit (from `https://github.com/nmdias/DefaultsKit`)
@ -41,8 +42,11 @@ DEPENDENCIES:
- SnapKit - SnapKit
- SVProgressHUD - SVProgressHUD
- SwiftyJSON - SwiftyJSON
- "UINavigationItem+Margin"
SPEC REPOS: SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- "UINavigationItem+Margin"
trunk: trunk:
- Alamofire - Alamofire
- DeviceKit - DeviceKit
@ -86,7 +90,8 @@ SPEC CHECKSUMS:
SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb SnapKit: 97b92857e3df3a0c71833cce143274bf6ef8e5eb
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6 SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7 SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7
"UINavigationItem+Margin": 7368d506fb2f7daa0c0489846cc8c2384ab1ab6d
PODFILE CHECKSUM: 993d19d838d6d55da4b65c5a2e5e68bce37c8097 PODFILE CHECKSUM: 179f10f903da643b7f8bb2079d8f88b0f8e32323
COCOAPODS: 1.8.4 COCOAPODS: 1.8.4