Manos Chorianopoulos

navigate back to wallet after share coupon

......@@ -44,6 +44,7 @@ import AVFoundation
var barcodeVisible: Bool = false;
public var coupon: swiftApi.CouponItemModel?
public var isFromWallet: Bool? = false
public override func viewDidLoad() {
super.viewDidLoad()
......@@ -235,6 +236,7 @@ import AVFoundation
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "ShareViewController") as! SwiftWarplyFramework.ShareViewController
vc.coupon = self.coupon
vc.isFromWallet = self.isFromWallet
self.navigationController?.pushViewController(vc, animated: true)
}
......
......@@ -26,6 +26,7 @@ import UIKit
let uiscreen: CGRect = UIScreen.main.bounds
public var coupon: swiftApi.CouponItemModel?
public var isFromWallet: Bool? = false
var selectedNumber: String = ""
var numbersList: Array<String> = []
......@@ -163,6 +164,29 @@ import UIKit
}))
self.present(alert, animated: true, completion: nil)
}
func showSuccessDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
if (self.isFromWallet == true) {
self.popBack(3)
} else {
print("default")
}
case .cancel:
print("cancel")
case .destructive:
print("destructive")
}
}))
self.present(alert, animated: true, completion: nil)
}
// MARK: - API Calls
func getProfileRequest() {
......@@ -189,7 +213,6 @@ import UIKit
if (response != nil) {
DispatchQueue.main.async {
if (response?.getStatus == 1) {
self.showDialog("Συγχαρητήρια!","Μόλις έκανες δώρο ένα κουπόνι!")
swiftApi().getCouponsAsync(getCouponsCallback)
......@@ -197,6 +220,7 @@ import UIKit
if (couponsData != nil) {
DispatchQueue.main.async {
self.showSuccessDialog("Συγχαρητήρια!","Μόλις έκανες δώρο ένα κουπόνι!")
}
} else {
}
......
......@@ -63,6 +63,16 @@ extension UIViewController {
self.navigationItem.titleView = titleLabel
}
// pop back n viewcontroller
func popBack(_ nb: Int) {
if let viewControllers: [UIViewController] = self.navigationController?.viewControllers {
guard viewControllers.count < nb else {
self.navigationController?.popToViewController(viewControllers[viewControllers.count - nb], animated: true)
return
}
}
}
}
extension String {
......
......@@ -412,6 +412,7 @@ extension WalletViewController: UITableViewDelegate, UITableViewDataSource{
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as! SwiftWarplyFramework.CouponBarcodeViewController
vc.coupon = coupons[indexPath.row]
vc.isFromWallet = true
self.navigationController?.pushViewController(vc, animated: true)
}
......