Skip to content

Commit 0de06ae

Browse files
committed
Stuff and in-app browser for Register
1 parent 055aa20 commit 0de06ae

File tree

9 files changed

+139
-4
lines changed

9 files changed

+139
-4
lines changed

VPN.HT.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
D91603571B18FAE700D1A33D /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D91603561B18FAE700D1A33D /* NetworkExtension.framework */; };
1111
D95E83821B2F0205006A9681 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = D95E83801B2F01B6006A9681 /* LaunchScreen.xib */; };
12+
D9662B3B1BA61C1F001D0F14 /* SMWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9662B3A1BA61C1F001D0F14 /* SMWebView.swift */; };
1213
D97C8AA61B6D7FB8001EF1C0 /* VpnViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D97C8AA51B6D7FB8001EF1C0 /* VpnViewController.swift */; };
1314
D97F11A31B08A40E003C6CB8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D97F11A21B08A40E003C6CB8 /* AppDelegate.swift */; };
1415
D97F11A51B08A40E003C6CB8 /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D97F11A41B08A40E003C6CB8 /* LoginViewController.swift */; };
@@ -42,6 +43,7 @@
4243
D916035C1B19103300D1A33D /* VPN.HT-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VPN.HT-Bridging-Header.h"; sourceTree = "<group>"; };
4344
D948A8F81B0A7F7F00EF3DC2 /* VPN.HT.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = VPN.HT.entitlements; sourceTree = "<group>"; };
4445
D95E83801B2F01B6006A9681 /* LaunchScreen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
46+
D9662B3A1BA61C1F001D0F14 /* SMWebView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SMWebView.swift; sourceTree = "<group>"; };
4547
D9775D4D1B4AF7690021BDCA /* DnsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DnsViewController.swift; sourceTree = "<group>"; };
4648
D97C8AA51B6D7FB8001EF1C0 /* VpnViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VpnViewController.swift; sourceTree = "<group>"; usesTabs = 1; };
4749
D97F119D1B08A40E003C6CB8 /* VPN.HT.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VPN.HT.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -118,6 +120,7 @@
118120
D9BEF4371B7BC48500FC91CB /* Images.xcassets */,
119121
D97F11C41B08BA3D003C6CB8 /* Classes.swift */,
120122
D9E609351B22261F00FB21F3 /* KeychainAccess.m */,
123+
D9662B3A1BA61C1F001D0F14 /* SMWebView.swift */,
121124
D9E609371B22262E00FB21F3 /* KeychainAccess.h */,
122125
D916035C1B19103300D1A33D /* VPN.HT-Bridging-Header.h */,
123126
D9D8BFAF1B2B707B00F47BF3 /* Main.storyboard */,
@@ -269,6 +272,7 @@
269272
isa = PBXSourcesBuildPhase;
270273
buildActionMask = 2147483647;
271274
files = (
275+
D9662B3B1BA61C1F001D0F14 /* SMWebView.swift in Sources */,
272276
D97F11A51B08A40E003C6CB8 /* LoginViewController.swift in Sources */,
273277
D97F11C51B08BA3D003C6CB8 /* Classes.swift in Sources */,
274278
D97F11A31B08A40E003C6CB8 /* AppDelegate.swift in Sources */,

VPN.HT/DnsViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class SmartDnsTutorialViewController: UIViewController, UIPageViewControllerData
199199
override func viewDidLoad() {
200200
self.automaticallyAdjustsScrollViewInsets = false
201201
self.navigationController?.navigationBar.barTintColor = StaticVar.darkBackgroundColor
202-
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Bordered, target: self, action: "hideTutorialView:")
202+
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: "hideTutorialView:")
203203
doneButton.tintColor = StaticVar.lightBackgroundColor
204204
self.navigationItem.setRightBarButtonItem(doneButton, animated: false)
205205
self.navigationController?.navigationBar.barTintColor = StaticVar.darkBackgroundColor
-4 Bytes
Loading
Loading
Loading

VPN.HT/LoginViewController.swift

+25-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class LoginViewController: UIViewController, UITextFieldDelegate {
4242

4343
let usernameLayer = username.layer
4444
let usernameBottomBorder = CALayer()
45-
usernameBottomBorder.borderColor = UIColor.darkGrayColor().CGColor
45+
usernameBottomBorder.borderColor = UIColor(red: 187/255, green: 187/255, blue: 187/255, alpha: 1).CGColor
4646
usernameBottomBorder.borderWidth = 1
4747
usernameBottomBorder.frame = CGRectMake(-1, usernameLayer.frame.size.height-1, usernameLayer.frame.size.width, 1)
4848
usernameLayer.addSublayer(usernameBottomBorder)
@@ -57,7 +57,7 @@ class LoginViewController: UIViewController, UITextFieldDelegate {
5757

5858
let passwordLayer = password.layer
5959
let passwordBottomBorder = CALayer()
60-
passwordBottomBorder.borderColor = UIColor.darkGrayColor().CGColor
60+
passwordBottomBorder.borderColor = UIColor(red: 187/255, green: 187/255, blue: 187/255, alpha: 1).CGColor
6161
passwordBottomBorder.borderWidth = 1
6262
passwordBottomBorder.frame = CGRectMake(-1, usernameLayer.frame.size.height-1, usernameLayer.frame.size.width, 1)
6363
passwordLayer.addSublayer(passwordBottomBorder)
@@ -125,7 +125,10 @@ class LoginViewController: UIViewController, UITextFieldDelegate {
125125
}
126126

127127
func register(sender: UIButton) {
128-
UIApplication.sharedApplication().openURL(NSURL(string:"https://vpn.ht/signup")!)
128+
let registerWebView = registerWebViewController()
129+
registerWebView.navigationController?.navigationBar.barTintColor = StaticVar.darkBackgroundColor
130+
let registerView = UINavigationController(rootViewController: registerWebView)
131+
self.presentViewController(registerView, animated: true, completion: nil)
129132
}
130133

131134
func checkLogin() {
@@ -297,3 +300,22 @@ class LoginViewController: UIViewController, UITextFieldDelegate {
297300
}
298301
}
299302

303+
class registerWebViewController: UIViewController {
304+
305+
override func viewDidLoad() {
306+
self.navigationController?.navigationBar.barTintColor = StaticVar.darkBackgroundColor
307+
let doneButton = UIBarButtonItem(title: "Close", style: UIBarButtonItemStyle.Plain, target: self, action: "hideRegisterWebView:")
308+
doneButton.tintColor = StaticVar.lightBackgroundColor
309+
self.navigationItem.setRightBarButtonItem(doneButton, animated: false)
310+
self.navigationController?.navigationBar.barTintColor = StaticVar.darkBackgroundColor
311+
self.view.backgroundColor = StaticVar.darkBackgroundColor
312+
313+
let webView = SMWebView.loadURL(NSURL(string: "https://vpn.ht/buy-vpn?_ref=ios")!)
314+
webView.frame = UIScreen.mainScreen().bounds
315+
self.view.addSubview(webView)
316+
}
317+
318+
func hideRegisterWebView(sender: UIBarButtonItem) {
319+
self.dismissViewControllerAnimated(true, completion: nil)
320+
}
321+
}

VPN.HT/SMWebView.swift

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//
2+
// SMWebView
3+
//
4+
// Created by Shai Mishali on 8/19/15.
5+
// Copyright (c) 2015 Shai Mishali. All rights reserved.
6+
//
7+
8+
import Foundation
9+
import UIKit
10+
11+
public class SMWebView : UIWebView, UIWebViewDelegate{
12+
//MARK: Typealiasing for Closure Types
13+
public typealias SMWebViewClosure = (webView:SMWebView) -> ()
14+
public typealias SMWebViewFailClosure = (webView:SMWebView, error: NSError) -> ()
15+
public typealias SMWebViewShouldLoadClosure = (webView:SMWebView, request: NSURLRequest, navigationType: UIWebViewNavigationType) -> (Bool)
16+
17+
//MARK: Internal storage for Closures
18+
internal var __didStartLoadingHandler:SMWebViewClosure? = nil
19+
internal var __didFinishLoadingHandler:SMWebViewClosure? = nil
20+
internal var __didCompleteLoadingHandler:SMWebViewClosure? = nil
21+
internal var __didFailLoadingHandler:SMWebViewFailClosure? = nil
22+
internal var __shouldStartLoadingHandler:SMWebViewShouldLoadClosure? = nil
23+
24+
//MARK: Initializers
25+
override public init(frame: CGRect) {
26+
super.init(frame: frame)
27+
self.delegate = self
28+
}
29+
30+
required public init?(coder aDecoder: NSCoder) {
31+
super.init(coder: aDecoder)
32+
self.delegate = self
33+
}
34+
35+
// URL/String loaders with Chaining-support
36+
public class func loadURL(URL: NSURL) -> SMWebView{
37+
let wv = SMWebView()
38+
wv.loadRequest(NSURLRequest(URL: URL))
39+
return wv
40+
}
41+
42+
public class func loadHTML(string: String!, baseURL: NSURL!) -> SMWebView{
43+
let wv = SMWebView()
44+
wv.loadHTMLString(string, baseURL: baseURL)
45+
return wv
46+
}
47+
48+
public func loadURL(URL: NSURL) -> SMWebView{
49+
self.loadRequest(NSURLRequest(URL: URL))
50+
return self
51+
}
52+
53+
public func loadHTML(string: String!, baseURL: NSURL!) -> SMWebView{
54+
self.loadHTMLString(string, baseURL: baseURL)
55+
return self
56+
}
57+
58+
//MARK: Closure methods
59+
public func didStartLoading(handler: SMWebViewClosure) -> SMWebView{
60+
self.__didStartLoadingHandler = handler
61+
62+
return self
63+
}
64+
65+
public func didFinishLoading(handler: SMWebViewClosure) -> SMWebView{
66+
self.__didFinishLoadingHandler = handler
67+
return self
68+
}
69+
70+
public func didFailLoading(handler: SMWebViewFailClosure) -> SMWebView{
71+
self.__didFailLoadingHandler = handler
72+
return self
73+
}
74+
75+
public func didCompleteLoading(handler: SMWebViewClosure) -> SMWebView{
76+
self.__didCompleteLoadingHandler = handler
77+
return self
78+
}
79+
80+
public func shouldStartLoading(handler: SMWebViewShouldLoadClosure) -> SMWebView{
81+
self.__shouldStartLoadingHandler = handler
82+
return self
83+
}
84+
85+
//MARK: UIWebView Delegate & Closure Handling
86+
public func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
87+
self.__didFailLoadingHandler?(webView: self, error: error!)
88+
}
89+
90+
public func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
91+
if self.__shouldStartLoadingHandler != nil {
92+
return self.__shouldStartLoadingHandler!(webView: self, request: request, navigationType: navigationType)
93+
}
94+
95+
return true
96+
}
97+
98+
public func webViewDidStartLoad(webView: UIWebView) {
99+
self.__didStartLoadingHandler?(webView: self)
100+
}
101+
102+
public func webViewDidFinishLoad(webView: UIWebView) {
103+
self.__didFinishLoadingHandler?(webView: self)
104+
105+
if !webView.loading {
106+
self.__didCompleteLoadingHandler?(webView: self)
107+
}
108+
}
109+
}

logo.sketch

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)