You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.0 KiB

3 years ago
3 years ago
  1. //
  2. // DebugManager.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 07/10/2019.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. //#if DEBUG
  10. class DebugManager {
  11. static let shared = DebugManager()
  12. var testAccountID: String {
  13. switch server {
  14. case .live:
  15. return "bikash@yopmail.com"
  16. default:
  17. return "bikash@yopmail.com"
  18. }
  19. }
  20. var testAccountPW: String {
  21. switch server {
  22. case .live:
  23. return "Test@12345"
  24. default:
  25. return "Test@12345"
  26. }
  27. }
  28. func setTestAccount(target: UIViewController, completion: ((String, String) -> Void)? = nil) {
  29. let alertcontroller = UIAlertController(title: "Test Account", message: nil, preferredStyle: .actionSheet)
  30. alertcontroller.view.tintColor = .themeText
  31. let testAction = UIAlertAction(title: testAccountID, style: .destructive, handler: { _ in
  32. completion?(self.testAccountID, self.testAccountPW)
  33. })
  34. let otherAction = UIAlertAction(title: "Other", style: .default, handler: nil)
  35. alertcontroller.addAction(testAction)
  36. alertcontroller.addAction(otherAction)
  37. if UIDevice.current.userInterfaceIdiom == .pad {
  38. if let popoverController = alertcontroller.popoverPresentationController {
  39. popoverController.sourceView = target.view
  40. popoverController.sourceRect = CGRect(
  41. x: target.view.bounds.midX,
  42. y: target.view.bounds.midY,
  43. width: 0,
  44. height: 0
  45. )
  46. popoverController.permittedArrowDirections = []
  47. target.present(alertcontroller, animated: true, completion: nil)
  48. }
  49. } else {
  50. target.present(alertcontroller, animated: true, completion: nil)
  51. }
  52. }
  53. func selectServerAlert(target: UIViewController, completion: (() -> Void)? = nil ) {
  54. let alertcontroller = UIAlertController(
  55. title: "Select Test Server",
  56. message: nil,
  57. preferredStyle: .actionSheet
  58. )
  59. alertcontroller.view.tintColor = .themeText
  60. var actions = [UIAlertAction]()
  61. Server.allCases.forEach { value in
  62. let action = UIAlertAction(title: value.rawValue, style: .default, handler: { _ in
  63. server = value
  64. UrlManager.sharedInstance.refreshBaseURL()
  65. switch server {
  66. default:
  67. completion?()
  68. }
  69. })
  70. actions.append(action)
  71. }
  72. actions.forEach {
  73. alertcontroller.addAction($0)
  74. }
  75. if UIDevice.current.userInterfaceIdiom == .pad {
  76. if let popoverController = alertcontroller.popoverPresentationController {
  77. popoverController.sourceView = target.view
  78. popoverController.sourceRect = CGRect(
  79. x: target.view.bounds.midX,
  80. y: target.view.bounds.midY,
  81. width: 0,
  82. height: 0
  83. )
  84. popoverController.permittedArrowDirections = []
  85. target.present(alertcontroller, animated: true, completion: nil)
  86. }
  87. } else {
  88. target.present(alertcontroller, animated: true, completion: nil)
  89. }
  90. }
  91. }
  92. //#endif