Manos Chorianopoulos

add language, darkmode

...@@ -557,7 +557,7 @@ var timer2: DispatchSourceTimer? ...@@ -557,7 +557,7 @@ var timer2: DispatchSourceTimer?
557 // func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void { 557 // func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
558 // if (profileData != nil) { 558 // if (profileData != nil) {
559 // DispatchQueue.main.async { 559 // DispatchQueue.main.async {
560 - // swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 560 + // swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
561 561
562 // func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { 562 // func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
563 // if (campaignsData != nil) { 563 // if (campaignsData != nil) {
...@@ -589,7 +589,7 @@ var timer2: DispatchSourceTimer? ...@@ -589,7 +589,7 @@ var timer2: DispatchSourceTimer?
589 SwiftEventBus.post("coupon_retrieved", sender: couponEvent) 589 SwiftEventBus.post("coupon_retrieved", sender: couponEvent)
590 590
591 swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in }) 591 swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
592 - swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 592 + swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
593 593
594 func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void { 594 func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
595 if (couponsData != nil) { 595 if (couponsData != nil) {
...@@ -882,7 +882,7 @@ var timer2: DispatchSourceTimer? ...@@ -882,7 +882,7 @@ var timer2: DispatchSourceTimer?
882 } 882 }
883 } 883 }
884 884
885 - swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 885 + swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
886 886
887 func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { 887 func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
888 if (campaignsData != nil) { 888 if (campaignsData != nil) {
......
...@@ -57,12 +57,30 @@ public class swiftApi { ...@@ -57,12 +57,30 @@ public class swiftApi {
57 UserDefaults.standard.set(newValue, forKey: "merchantIdUD") 57 UserDefaults.standard.set(newValue, forKey: "merchantIdUD")
58 } 58 }
59 59
60 - public func getLanguage() -> String { 60 + public func getApplicationLocale() -> String {
61 - return UserDefaults.standard.string(forKey: "languageUD") ?? "" 61 + return UserDefaults.standard.string(forKey: "languageUD") ?? "el"
62 } 62 }
63 63
64 - public func setLanguage(_ newLang: String) -> Void { 64 + public func setApplicationLocale(_ newLang: String) -> Void {
65 - UserDefaults.standard.set(newLang, forKey: "languageUD") 65 + // newLang: "GR" / "EN"
66 + var tempLang: String = ""
67 + if (newLang == "EN" || newLang == "en") {
68 + tempLang = "en"
69 + } else {
70 + tempLang = "el"
71 + }
72 + UserDefaults.standard.set(tempLang, forKey: "languageUD")
73 +
74 + let instanceOfMyApi = MyApi()
75 + instanceOfMyApi.setLang(tempLang)
76 + }
77 +
78 + public func getIsDarkModeEnabled() -> Bool {
79 + return UserDefaults.standard.bool(forKey: "isDarkModeEnabledUD")
80 + }
81 +
82 + public func setIsDarkModeEnabled(_ newValue: Bool) -> Void {
83 + UserDefaults.standard.set(newValue, forKey: "isDarkModeEnabledUD")
66 } 84 }
67 85
68 86
...@@ -662,7 +680,7 @@ public class swiftApi { ...@@ -662,7 +680,7 @@ public class swiftApi {
662 } 680 }
663 } 681 }
664 682
665 - swiftApi().getCouponsUniversalAsync(language: "el", getCouponsCallback, failureCallback: failureCallback) 683 + swiftApi().getCouponsUniversalAsync(language: swiftApi().getApplicationLocale(), getCouponsCallback, failureCallback: failureCallback)
666 684
667 instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback) 685 instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
668 686
...@@ -2240,7 +2258,9 @@ public class swiftApi { ...@@ -2240,7 +2258,9 @@ public class swiftApi {
2240 "access_token": (campaignInfo?["access_token"] as! String), 2258 "access_token": (campaignInfo?["access_token"] as! String),
2241 "refresh_token": (campaignInfo?["refresh_token"] as! String), 2259 "refresh_token": (campaignInfo?["refresh_token"] as! String),
2242 "client_id": (campaignInfo?["client_id"] as! String), 2260 "client_id": (campaignInfo?["client_id"] as! String),
2243 - "client_secret": (campaignInfo?["client_secret"] as! String) 2261 + "client_secret": (campaignInfo?["client_secret"] as! String),
2262 + "lan": swiftApi().getApplicationLocale(),
2263 + "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false")
2244 ] 2264 ]
2245 2265
2246 let encoder = JSONEncoder() 2266 let encoder = JSONEncoder()
...@@ -2277,7 +2297,9 @@ public class swiftApi { ...@@ -2277,7 +2297,9 @@ public class swiftApi {
2277 "refresh_token": (campaignInfo?["refresh_token"] as! String), 2297 "refresh_token": (campaignInfo?["refresh_token"] as! String),
2278 "client_id": (campaignInfo?["client_id"] as! String), 2298 "client_id": (campaignInfo?["client_id"] as! String),
2279 "client_secret": (campaignInfo?["client_secret"] as! String), 2299 "client_secret": (campaignInfo?["client_secret"] as! String),
2280 - "map": (isMap ? "true" : "false") 2300 + "map": (isMap ? "true" : "false"),
2301 + "lan": swiftApi().getApplicationLocale(),
2302 + "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false")
2281 ] 2303 ]
2282 2304
2283 let encoder = JSONEncoder() 2305 let encoder = JSONEncoder()
...@@ -2314,7 +2336,9 @@ public class swiftApi { ...@@ -2314,7 +2336,9 @@ public class swiftApi {
2314 "refresh_token": (campaignInfo?["refresh_token"] as! String), 2336 "refresh_token": (campaignInfo?["refresh_token"] as! String),
2315 "client_id": (campaignInfo?["client_id"] as! String), 2337 "client_id": (campaignInfo?["client_id"] as! String),
2316 "client_secret": (campaignInfo?["client_secret"] as! String), 2338 "client_secret": (campaignInfo?["client_secret"] as! String),
2317 - "from_widget": (from_widget ? "true" : "false") 2339 + "from_widget": (from_widget ? "true" : "false"),
2340 + "lan": swiftApi().getApplicationLocale(),
2341 + "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false")
2318 ] 2342 ]
2319 2343
2320 let encoder = JSONEncoder() 2344 let encoder = JSONEncoder()
...@@ -3539,7 +3563,7 @@ public class swiftApi { ...@@ -3539,7 +3563,7 @@ public class swiftApi {
3539 } else { 3563 } else {
3540 let appUuid = swiftApi().getAppUuid() 3564 let appUuid = swiftApi().getAppUuid()
3541 let merchantId = swiftApi().getMerchantId() 3565 let merchantId = swiftApi().getMerchantId()
3542 - instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback) 3566 + instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: swiftApi().getApplicationLocale(), successBlock: initializeCallback, failureBlock: initializeFailureCallback)
3543 } 3567 }
3544 3568
3545 func initializeCallback(_ initializeData: [AnyHashable: Any]?) -> Void { 3569 func initializeCallback(_ initializeData: [AnyHashable: Any]?) -> Void {
...@@ -3642,7 +3666,7 @@ public class swiftApi { ...@@ -3642,7 +3666,7 @@ public class swiftApi {
3642 } else { 3666 } else {
3643 let appUuid = swiftApi().getAppUuid() 3667 let appUuid = swiftApi().getAppUuid()
3644 let merchantId = swiftApi().getMerchantId() 3668 let merchantId = swiftApi().getMerchantId()
3645 - instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback) 3669 + instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: swiftApi().getApplicationLocale(), successBlock: initializeCallback, failureBlock: initializeFailureCallback)
3646 } 3670 }
3647 3671
3648 3672
...@@ -3695,7 +3719,7 @@ public class swiftApi { ...@@ -3695,7 +3719,7 @@ public class swiftApi {
3695 3719
3696 func getSingleCampaignAsyncCallback(_ getSingleCampaignData: [AnyHashable: Any]?) -> Void { 3720 func getSingleCampaignAsyncCallback(_ getSingleCampaignData: [AnyHashable: Any]?) -> Void {
3697 3721
3698 - // swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 3722 + // swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
3699 3723
3700 // func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { 3724 // func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
3701 // if (campaignsData != nil) { 3725 // if (campaignsData != nil) {
...@@ -3735,7 +3759,7 @@ public class swiftApi { ...@@ -3735,7 +3759,7 @@ public class swiftApi {
3735 3759
3736 func getSingleCampaignFailureCallback(_ error: Error?) -> Void { 3760 func getSingleCampaignFailureCallback(_ error: Error?) -> Void {
3737 3761
3738 - // swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in }) 3762 + // swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
3739 3763
3740 // func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { 3764 // func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
3741 // if (campaignsData != nil) { 3765 // if (campaignsData != nil) {
......