Manos Chorianopoulos

add language, darkmode

......@@ -557,7 +557,7 @@ var timer2: DispatchSourceTimer?
// func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
// if (profileData != nil) {
// DispatchQueue.main.async {
// swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
// swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
// func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
// if (campaignsData != nil) {
......@@ -589,7 +589,7 @@ var timer2: DispatchSourceTimer?
SwiftEventBus.post("coupon_retrieved", sender: couponEvent)
swiftApi().getCouponsAsync(getCouponsCallback, failureCallback: {errorCode in })
swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
if (couponsData != nil) {
......@@ -882,7 +882,7 @@ var timer2: DispatchSourceTimer?
}
}
swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
if (campaignsData != nil) {
......
......@@ -57,12 +57,30 @@ public class swiftApi {
UserDefaults.standard.set(newValue, forKey: "merchantIdUD")
}
public func getLanguage() -> String {
return UserDefaults.standard.string(forKey: "languageUD") ?? ""
public func getApplicationLocale() -> String {
return UserDefaults.standard.string(forKey: "languageUD") ?? "el"
}
public func setLanguage(_ newLang: String) -> Void {
UserDefaults.standard.set(newLang, forKey: "languageUD")
public func setApplicationLocale(_ newLang: String) -> Void {
// newLang: "GR" / "EN"
var tempLang: String = ""
if (newLang == "EN" || newLang == "en") {
tempLang = "en"
} else {
tempLang = "el"
}
UserDefaults.standard.set(tempLang, forKey: "languageUD")
let instanceOfMyApi = MyApi()
instanceOfMyApi.setLang(tempLang)
}
public func getIsDarkModeEnabled() -> Bool {
return UserDefaults.standard.bool(forKey: "isDarkModeEnabledUD")
}
public func setIsDarkModeEnabled(_ newValue: Bool) -> Void {
UserDefaults.standard.set(newValue, forKey: "isDarkModeEnabledUD")
}
......@@ -662,7 +680,7 @@ public class swiftApi {
}
}
swiftApi().getCouponsUniversalAsync(language: "el", getCouponsCallback, failureCallback: failureCallback)
swiftApi().getCouponsUniversalAsync(language: swiftApi().getApplicationLocale(), getCouponsCallback, failureCallback: failureCallback)
instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
......@@ -2240,7 +2258,9 @@ public class swiftApi {
"access_token": (campaignInfo?["access_token"] as! String),
"refresh_token": (campaignInfo?["refresh_token"] as! String),
"client_id": (campaignInfo?["client_id"] as! String),
"client_secret": (campaignInfo?["client_secret"] as! String)
"client_secret": (campaignInfo?["client_secret"] as! String),
"lan": swiftApi().getApplicationLocale(),
"dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false")
]
let encoder = JSONEncoder()
......@@ -2277,7 +2297,9 @@ public class swiftApi {
"refresh_token": (campaignInfo?["refresh_token"] as! String),
"client_id": (campaignInfo?["client_id"] as! String),
"client_secret": (campaignInfo?["client_secret"] as! String),
"map": (isMap ? "true" : "false")
"map": (isMap ? "true" : "false"),
"lan": swiftApi().getApplicationLocale(),
"dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false")
]
let encoder = JSONEncoder()
......@@ -2314,7 +2336,9 @@ public class swiftApi {
"refresh_token": (campaignInfo?["refresh_token"] as! String),
"client_id": (campaignInfo?["client_id"] as! String),
"client_secret": (campaignInfo?["client_secret"] as! String),
"from_widget": (from_widget ? "true" : "false")
"from_widget": (from_widget ? "true" : "false"),
"lan": swiftApi().getApplicationLocale(),
"dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false")
]
let encoder = JSONEncoder()
......@@ -3539,7 +3563,7 @@ public class swiftApi {
} else {
let appUuid = swiftApi().getAppUuid()
let merchantId = swiftApi().getMerchantId()
instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback)
instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: swiftApi().getApplicationLocale(), successBlock: initializeCallback, failureBlock: initializeFailureCallback)
}
func initializeCallback(_ initializeData: [AnyHashable: Any]?) -> Void {
......@@ -3642,7 +3666,7 @@ public class swiftApi {
} else {
let appUuid = swiftApi().getAppUuid()
let merchantId = swiftApi().getMerchantId()
instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: "el", successBlock: initializeCallback, failureBlock: initializeFailureCallback)
instanceOfMyApi.initialize(withCallback: nil, uuid: appUuid, merchantId: merchantId, lang: swiftApi().getApplicationLocale(), successBlock: initializeCallback, failureBlock: initializeFailureCallback)
}
......@@ -3695,7 +3719,7 @@ public class swiftApi {
func getSingleCampaignAsyncCallback(_ getSingleCampaignData: [AnyHashable: Any]?) -> Void {
// swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
// swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
// func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
// if (campaignsData != nil) {
......@@ -3735,7 +3759,7 @@ public class swiftApi {
func getSingleCampaignFailureCallback(_ error: Error?) -> Void {
// swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
// swiftApi().getCampaignsAsyncNew(language: swiftApi().getApplicationLocale(), filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in })
// func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
// if (campaignsData != nil) {
......