Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func consoleAlertPopup(title: String, message: String) {
- let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
- UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
- alertController.addAction(UIAlertAction(title: "Try Again", style: UIAlertActionStyle.default, handler: nil))
- }
- import UIKit
- import CoreLocation
- import MobileCoreServices
- class ConsoleViewController: UIViewController, CLLocationManagerDelegate {
- var alertView: UIAlertController?
- // IB Outlets \
- @IBOutlet var DisplayUserName: UILabel!
- @IBOutlet var LastCheckInLabel: UILabel!
- @IBOutlet var NextCourtDateLabel: UILabel!
- @IBOutlet weak var CourtDateButton: UIButton!
- @IBOutlet weak var courtDatePicker: UIDatePicker!
- //Global Variables & UI Elements
- var checkInImg: UIImage!
- var userNameString: String!
- var newDisplayDate: String?
- var updatedCourtLabel: String?
- let formatter = DateFormatter()
- let displayFormatter = DateFormatter()
- var locationManager: CLLocationManager!
- @IBAction func clickCheckIn(_ sender: UIButton) {
- sendPicture()
- //Camera Pop Up
- }
- @IBAction func clickCourtDate() {
- courtPickerAction(Any.self)
- }
- @IBAction func courtPickerAction(_ sender: Any) {
- DatePickerDialog().show("Select Next Court Date", doneButtonTitle: "Submit", cancelButtonTitle: "Cancel", datePickerMode: .dateAndTime) {
- (courtDateTime) -> Void in
- if courtDateTime == nil {
- //Do nothing
- } else {
- self.formatter.dateFormat = "yyyy-MM-dd HH:mm"
- self.newDisplayDate = self.formatter.string(from: (courtDateTime)!)
- //print("Date after format: (courtDateTime)")
- print("Date and time: (self.newDisplayDate) after sendDefendantData func")
- // Submit Button - Date Picker \
- if (DatePickerDialog().doneButton != nil) {
- self.sendDefendantData()
- print("Send Defendant Data from Submit")
- print("After sendDefData: (self.newDisplayDate)")
- self.displayFormatter.dateStyle = DateFormatter.Style.full
- self.displayFormatter.timeStyle = DateFormatter.Style.short
- self.NextCourtDateLabel.text = self.displayFormatter.string(from: courtDateTime!)
- }
- }
- }
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- print("Console View Did Load")
- self.hideKeyboardWhenTappedAround()
- DisplayUserName.text! = userNameString
- // For location allowance from user
- // I've placed this code here (instead of in a function) so the alert
- // pop up will show and allows accessing location. "not in hierarchy"
- // elsewise.
- self.locationManager = CLLocationManager()
- self.locationManager.delegate = self
- self.locationManager.requestWhenInUseAuthorization()
- // Format Display Date & Times
- self.displayFormatter.dateStyle = DateFormatter.Style.full
- self.displayFormatter.timeStyle = DateFormatter.Style.long
- // Retrieve Defendant Data From API Handler
- getDefendantData()
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func presentAlert(_ message: String) {
- self.alertView = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
- alertView?.addAction(UIAlertAction(title: "OK", style: .cancel) { _ in })
- ViewController().present(alertView!, animated: true, completion: nil)
- }
- func consoleAlertPopup(title: String, message: String) {
- let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
- UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true, completion: nil)
- alertController.addAction(UIAlertAction(title: "Try Again", style: UIAlertActionStyle.default, handler: nil))
- }
- func getDefendantData() {...}
- func sendDefendantData() {...}
- func sendPicture() {....}
- import UIKit
- // Hide Keyboard \
- extension UIViewController {
- func hideKeyboardWhenTappedAround() {
- let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
- view.addGestureRecognizer(tap)
- }
- func dismissKeyboard() {
- view.endEditing(true)
- }
- }
- class ViewController: UIViewController {
- // Send User Login to Console Screen \
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- if (segue.identifier == "toConsoleScreen") {
- let secondViewController = segue.destination as! ConsoleViewController
- secondViewController.userNameString = UserNameField.text!
- print("PrepareSegue")
- }
- }
- @IBAction func UserNameEditBegan() {
- UserNameField.text = nil
- }
- @IBAction func PasswordEditBegan() {
- PasswordField.text = nil
- }
- @IBOutlet weak var UserNameField: UITextField!
- @IBOutlet weak var PasswordField: UITextField!
- func successfulLogin(Username: String) {
- print("Inside Function")
- print(Username)
- print("Inside Successful Login")
- // Show next view - Add to Main Queue\
- OperationQueue.main.addOperation{
- //print("Before dismissal")
- // self.dismiss(animated: true, completion: nil)
- //print("After dismissal")
- self.performSegue(withIdentifier: "toConsoleScreen", sender: self)
- print("After segue")
- }
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- self.hideKeyboardWhenTappedAround()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func loginButton() {
- login(Username: UserNameField.text!, Password: PasswordField.text!) { username in
- self.successfulLogin(Username: username)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement