SyncController.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (C) 2016 Inigo Valentin
  2. //
  3. // This file is part of the Gasteizko Margolariak IOS app.
  4. //
  5. // The Gasteizko Margolariak IOS app is free software: you can
  6. // redistribute it and/or modify it under the terms of the
  7. // GNU General Public License as published by the Free Software
  8. // Foundation, either version 3 of the License, or (at your
  9. // option) any later version.
  10. //
  11. // The Gasteizko Margolariak IOS app is distributed in the
  12. // hope that it will be useful, but WITHOUT ANY WARRANTY;
  13. // without even the implied warranty of MERCHANTABILITY or
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  15. // Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public
  18. // License along with the Gasteizko Margolariak IOS app.
  19. // If not, see <http://www.gnu.org/licenses/>.
  20. import UIKit
  21. import CoreData
  22. /**
  23. The view controller of the app.
  24. */
  25. class SyncController: UIViewController{
  26. @IBOutlet weak var pb: UIProgressView!
  27. @IBOutlet weak var lb: UILabel!
  28. var completion: Float = 0.0
  29. let messages: [String] = ["Contactando con Don Margolo...", "Arrancando la furgo...", "Preparando kalimotxos...",
  30. "Tú eres el piloto", "Afinando la tuba...", "Margolari camina pa'lante, margolari camina pa'trás.", "Ari ari ari!", "Llegando tarde", "¿Cabe más gente en el Foro Margolari?"]
  31. /**
  32. Run when the app loads.
  33. */
  34. override func viewDidLoad() {
  35. NSLog(":SYNC:LOG: SyncController shown.")
  36. super.viewDidLoad()
  37. // Initial setup
  38. pb.progress = 0
  39. // Start the timer
  40. Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(progress), userInfo: nil, repeats: true)
  41. }
  42. /**
  43. Signal to update the progressbar and, maybe, the tag.
  44. */
  45. func progress(){
  46. if (Int(completion * 100) % 20) == 0 {
  47. let rnd = Int(arc4random_uniform(UInt32(messages.count)));
  48. lb.text = messages[rnd]
  49. }
  50. completion = completion + 0.02
  51. if completion >= 1.0{
  52. completion = 0.0
  53. }
  54. pb.progress = completion
  55. }
  56. }