Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. func consoleAlertPopup(title: String, message: String) {
  2.  
  3. let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
  4. UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
  5. alertController.addAction(UIAlertAction(title: "Try Again", style: UIAlertActionStyle.default, handler: nil))
  6. }
  7.  
  8. import UIKit
  9. import CoreLocation
  10. import MobileCoreServices
  11.  
  12. class ConsoleViewController: UIViewController, CLLocationManagerDelegate {
  13.  
  14. var alertView: UIAlertController?
  15.  
  16. // IB Outlets \
  17. @IBOutlet var DisplayUserName: UILabel!
  18. @IBOutlet var LastCheckInLabel: UILabel!
  19. @IBOutlet var NextCourtDateLabel: UILabel!
  20. @IBOutlet weak var CourtDateButton: UIButton!
  21.  
  22. @IBOutlet weak var courtDatePicker: UIDatePicker!
  23.  
  24. //Global Variables & UI Elements
  25. var checkInImg: UIImage!
  26. var userNameString: String!
  27. var newDisplayDate: String?
  28. var updatedCourtLabel: String?
  29. let formatter = DateFormatter()
  30. let displayFormatter = DateFormatter()
  31. var locationManager: CLLocationManager!
  32.  
  33. @IBAction func clickCheckIn(_ sender: UIButton) {
  34.  
  35. sendPicture()
  36. //Camera Pop Up
  37.  
  38. }
  39.  
  40. @IBAction func clickCourtDate() {
  41.  
  42. courtPickerAction(Any.self)
  43.  
  44. }
  45.  
  46. @IBAction func courtPickerAction(_ sender: Any) {
  47.  
  48.  
  49. DatePickerDialog().show("Select Next Court Date", doneButtonTitle: "Submit", cancelButtonTitle: "Cancel", datePickerMode: .dateAndTime) {
  50. (courtDateTime) -> Void in
  51.  
  52. if courtDateTime == nil {
  53. //Do nothing
  54. } else {
  55. self.formatter.dateFormat = "yyyy-MM-dd HH:mm"
  56. self.newDisplayDate = self.formatter.string(from: (courtDateTime)!)
  57.  
  58.  
  59. //print("Date after format: (courtDateTime)")
  60. print("Date and time: (self.newDisplayDate) after sendDefendantData func")
  61.  
  62.  
  63. // Submit Button - Date Picker \
  64. if (DatePickerDialog().doneButton != nil) {
  65.  
  66. self.sendDefendantData()
  67.  
  68.  
  69. print("Send Defendant Data from Submit")
  70. print("After sendDefData: (self.newDisplayDate)")
  71.  
  72. self.displayFormatter.dateStyle = DateFormatter.Style.full
  73. self.displayFormatter.timeStyle = DateFormatter.Style.short
  74. self.NextCourtDateLabel.text = self.displayFormatter.string(from: courtDateTime!)
  75.  
  76. }
  77.  
  78. }
  79. }
  80. }
  81.  
  82.  
  83. override func viewDidLoad() {
  84. super.viewDidLoad()
  85.  
  86.  
  87. print("Console View Did Load")
  88. self.hideKeyboardWhenTappedAround()
  89.  
  90. DisplayUserName.text! = userNameString
  91. // For location allowance from user
  92. // I've placed this code here (instead of in a function) so the alert
  93. // pop up will show and allows accessing location. "not in hierarchy"
  94. // elsewise.
  95. self.locationManager = CLLocationManager()
  96. self.locationManager.delegate = self
  97. self.locationManager.requestWhenInUseAuthorization()
  98.  
  99. // Format Display Date & Times
  100. self.displayFormatter.dateStyle = DateFormatter.Style.full
  101. self.displayFormatter.timeStyle = DateFormatter.Style.long
  102.  
  103.  
  104. // Retrieve Defendant Data From API Handler
  105. getDefendantData()
  106.  
  107.  
  108.  
  109.  
  110.  
  111. // Do any additional setup after loading the view.
  112. }
  113.  
  114. override func didReceiveMemoryWarning() {
  115. super.didReceiveMemoryWarning()
  116. // Dispose of any resources that can be recreated.
  117. }
  118.  
  119.  
  120.  
  121.  
  122. func presentAlert(_ message: String) {
  123.  
  124. self.alertView = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
  125. alertView?.addAction(UIAlertAction(title: "OK", style: .cancel) { _ in })
  126.  
  127. ViewController().present(alertView!, animated: true, completion: nil)
  128.  
  129. }
  130.  
  131.  
  132. func consoleAlertPopup(title: String, message: String) {
  133.  
  134. let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
  135. UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
  136. alertController.addAction(UIAlertAction(title: "Try Again", style: UIAlertActionStyle.default, handler: nil))
  137. }
  138.  
  139. func getDefendantData() {...}
  140. func sendDefendantData() {...}
  141. func sendPicture() {....}
  142.  
  143. import UIKit
  144.  
  145.  
  146. // Hide Keyboard \
  147. extension UIViewController {
  148. func hideKeyboardWhenTappedAround() {
  149. let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
  150. view.addGestureRecognizer(tap)
  151. }
  152.  
  153. func dismissKeyboard() {
  154. view.endEditing(true)
  155. }
  156. }
  157.  
  158.  
  159.  
  160. class ViewController: UIViewController {
  161.  
  162. // Send User Login to Console Screen \
  163. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  164.  
  165. if (segue.identifier == "toConsoleScreen") {
  166.  
  167. let secondViewController = segue.destination as! ConsoleViewController
  168.  
  169. secondViewController.userNameString = UserNameField.text!
  170.  
  171. print("PrepareSegue")
  172. }
  173.  
  174. }
  175.  
  176. @IBAction func UserNameEditBegan() {
  177. UserNameField.text = nil
  178. }
  179. @IBAction func PasswordEditBegan() {
  180. PasswordField.text = nil
  181. }
  182.  
  183. @IBOutlet weak var UserNameField: UITextField!
  184. @IBOutlet weak var PasswordField: UITextField!
  185.  
  186. func successfulLogin(Username: String) {
  187.  
  188.  
  189. print("Inside Function")
  190.  
  191. print(Username)
  192. print("Inside Successful Login")
  193.  
  194. // Show next view - Add to Main Queue\
  195. OperationQueue.main.addOperation{
  196.  
  197. //print("Before dismissal")
  198. // self.dismiss(animated: true, completion: nil)
  199. //print("After dismissal")
  200. self.performSegue(withIdentifier: "toConsoleScreen", sender: self)
  201. print("After segue")
  202.  
  203. }
  204. }
  205.  
  206.  
  207.  
  208. override func viewDidLoad() {
  209. super.viewDidLoad()
  210.  
  211. self.hideKeyboardWhenTappedAround()
  212.  
  213.  
  214.  
  215. // Do any additional setup after loading the view, typically from a nib.
  216.  
  217.  
  218. }
  219.  
  220. override func didReceiveMemoryWarning() {
  221. super.didReceiveMemoryWarning()
  222. // Dispose of any resources that can be recreated.
  223. }
  224.  
  225. @IBAction func loginButton() {
  226.  
  227. login(Username: UserNameField.text!, Password: PasswordField.text!) { username in
  228. self.successfulLogin(Username: username)
  229. }
  230.  
  231.  
  232.  
  233. }
  234.  
  235.  
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement