Vasilis
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
7 objects = { 7 objects = {
8 8
9 /* Begin PBXBuildFile section */ 9 /* Begin PBXBuildFile section */
10 + 1E7086652811A93F00704CA8 /* CouponBarcodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7086642811A93F00704CA8 /* CouponBarcodeView.swift */; };
11 + 1E7086672811A96E00704CA8 /* CouponBarcodeViewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7086662811A96E00704CA8 /* CouponBarcodeViewInterface.swift */; };
10 1E735FF2281067320050A298 /* CampaignWebview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E735FF1281067320050A298 /* CampaignWebview.swift */; }; 12 1E735FF2281067320050A298 /* CampaignWebview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E735FF1281067320050A298 /* CampaignWebview.swift */; };
11 1E735FF42810681E0050A298 /* CampaignWebviewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E735FF32810681E0050A298 /* CampaignWebviewInterface.swift */; }; 13 1E735FF42810681E0050A298 /* CampaignWebviewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E735FF32810681E0050A298 /* CampaignWebviewInterface.swift */; };
12 1EBEB02D280D69D800BF802C /* GiftsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBEB02C280D69D800BF802C /* GiftsView.swift */; }; 14 1EBEB02D280D69D800BF802C /* GiftsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBEB02C280D69D800BF802C /* GiftsView.swift */; };
...@@ -141,6 +143,8 @@ ...@@ -141,6 +143,8 @@
141 143
142 /* Begin PBXFileReference section */ 144 /* Begin PBXFileReference section */
143 1353B8C484CC0649CAC2EB74 /* Pods_WarplySDKFrameworkIOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WarplySDKFrameworkIOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 145 1353B8C484CC0649CAC2EB74 /* Pods_WarplySDKFrameworkIOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WarplySDKFrameworkIOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
146 + 1E7086642811A93F00704CA8 /* CouponBarcodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeView.swift; sourceTree = "<group>"; };
147 + 1E7086662811A96E00704CA8 /* CouponBarcodeViewInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeViewInterface.swift; sourceTree = "<group>"; };
144 1E735FF1281067320050A298 /* CampaignWebview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignWebview.swift; sourceTree = "<group>"; }; 148 1E735FF1281067320050A298 /* CampaignWebview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignWebview.swift; sourceTree = "<group>"; };
145 1E735FF32810681E0050A298 /* CampaignWebviewInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignWebviewInterface.swift; sourceTree = "<group>"; }; 149 1E735FF32810681E0050A298 /* CampaignWebviewInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignWebviewInterface.swift; sourceTree = "<group>"; };
146 1EBEB02C280D69D800BF802C /* GiftsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiftsView.swift; sourceTree = "<group>"; }; 150 1EBEB02C280D69D800BF802C /* GiftsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiftsView.swift; sourceTree = "<group>"; };
...@@ -345,6 +349,8 @@ ...@@ -345,6 +349,8 @@
345 E67D1EB9281055F800940F01 /* MoreForYouViewInterface.swift */, 349 E67D1EB9281055F800940F01 /* MoreForYouViewInterface.swift */,
346 E67D1EBF2810579F00940F01 /* MoreForYouView.swift */, 350 E67D1EBF2810579F00940F01 /* MoreForYouView.swift */,
347 E67D1EC128113EED00940F01 /* CouponView.swift */, 351 E67D1EC128113EED00940F01 /* CouponView.swift */,
352 + 1E7086642811A93F00704CA8 /* CouponBarcodeView.swift */,
353 + 1E7086662811A96E00704CA8 /* CouponBarcodeViewInterface.swift */,
348 E67D1EC328113EFD00940F01 /* CouponViewInterface.swift */, 354 E67D1EC328113EFD00940F01 /* CouponViewInterface.swift */,
349 E6D8DF5E27A9429E0006A3A9 /* MyApi.h */, 355 E6D8DF5E27A9429E0006A3A9 /* MyApi.h */,
350 E6D8DF5C27A9429E0006A3A9 /* MyApi.m */, 356 E6D8DF5C27A9429E0006A3A9 /* MyApi.m */,
...@@ -746,6 +752,7 @@ ...@@ -746,6 +752,7 @@
746 E6D8DF2E27A942920006A3A9 /* UIRefreshControl+AFNetworking.m in Sources */, 752 E6D8DF2E27A942920006A3A9 /* UIRefreshControl+AFNetworking.m in Sources */,
747 E6D8DF4827A942920006A3A9 /* AFURLRequestSerialization.m in Sources */, 753 E6D8DF4827A942920006A3A9 /* AFURLRequestSerialization.m in Sources */,
748 E67D1EC228113EED00940F01 /* CouponView.swift in Sources */, 754 E67D1EC228113EED00940F01 /* CouponView.swift in Sources */,
755 + 1E7086672811A96E00704CA8 /* CouponBarcodeViewInterface.swift in Sources */,
749 E6D8DEF327A942920006A3A9 /* WLNativeVideoTableViewCell.m in Sources */, 756 E6D8DEF327A942920006A3A9 /* WLNativeVideoTableViewCell.m in Sources */,
750 E6D8DF2527A942920006A3A9 /* WLSMSActionHanlder.m in Sources */, 757 E6D8DF2527A942920006A3A9 /* WLSMSActionHanlder.m in Sources */,
751 E67D1EBE2810573900940F01 /* WalletView.swift in Sources */, 758 E67D1EBE2810573900940F01 /* WalletView.swift in Sources */,
...@@ -790,6 +797,7 @@ ...@@ -790,6 +797,7 @@
790 E67D1EC828119ED300940F01 /* swiftApi.swift in Sources */, 797 E67D1EC828119ED300940F01 /* swiftApi.swift in Sources */,
791 E6D8DF5227A942920006A3A9 /* FMDatabase.m in Sources */, 798 E6D8DF5227A942920006A3A9 /* FMDatabase.m in Sources */,
792 E6D8DF1227A942920006A3A9 /* WLPushManager.m in Sources */, 799 E6D8DF1227A942920006A3A9 /* WLPushManager.m in Sources */,
800 + 1E7086652811A93F00704CA8 /* CouponBarcodeView.swift in Sources */,
793 E6D8DEF827A942920006A3A9 /* WLNativeAdTableViewCell.m in Sources */, 801 E6D8DEF827A942920006A3A9 /* WLNativeAdTableViewCell.m in Sources */,
794 E6D8DE6D27A942010006A3A9 /* WarplySDKFrameworkIOS.docc in Sources */, 802 E6D8DE6D27A942010006A3A9 /* WarplySDKFrameworkIOS.docc in Sources */,
795 E6D8DF4427A942920006A3A9 /* AFURLResponseSerialization.m in Sources */, 803 E6D8DF4427A942920006A3A9 /* AFURLResponseSerialization.m in Sources */,
......
1 +//
2 +// CouponBarcodeView.swift
3 +// WarplySDKFrameworkIOS
4 +//
5 +// Created by Manos Chorianopoulos on 21/4/22.
6 +//
7 +
8 +#if canImport(SwiftUI)
9 +import SwiftUI
10 +import Combine
11 +import Foundation
12 +import UIKit
13 +//import RSBarcodes_Swift
14 +//import AVFoundation
15 +
16 +
17 +extension CouponBarcodeView {
18 + struct headerView: View {
19 + var goBack: () -> ()
20 +
21 + var uiscreen = UIScreen.main.bounds
22 +
23 + var body: some View {
24 + HStack(alignment: .center) {
25 + Button {
26 + // Button Action
27 + goBack()
28 + } label: {
29 + Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
30 + .resizable()
31 + .aspectRatio(contentMode: .fit)
32 + .frame(width: self.uiscreen.height * 0.025, height: self.uiscreen.height * 0.02)
33 + }
34 +
35 + Text("Εκπτωτικό κουπόνι")
36 + .fontWeight(.medium)
37 + .font(.system(size: 16))
38 + .foregroundColor(Color(red: 0.20784313725490197, green: 0.3176470588235294, blue: 0.40784313725490196))
39 + .multilineTextAlignment(.center)
40 + .frame(maxWidth: .infinity)
41 + .padding(.horizontal)
42 +
43 + }
44 + .frame(maxWidth: .infinity)
45 + .padding(.horizontal)
46 + .padding(.vertical, 10)
47 + }
48 + }
49 +
50 + struct couponContainer: View {
51 + @State var coupon: Dictionary<String, Any>
52 +// @State var couponset:CouponSetItemModel
53 +
54 + var uiscreen = UIScreen.main.bounds
55 +
56 +
57 + static func convertDateFormat(inputDate: String) -> String {
58 + let dateFormatter = DateFormatter()
59 + dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
60 + if let date = dateFormatter.date(from: inputDate) {
61 + dateFormatter.dateFormat = "dd/MM/yyyy"
62 + let resultString = dateFormatter.string(from: date)
63 + return resultString
64 + } else {
65 + return ""
66 + }
67 + }
68 +
69 +
70 + func generateBarcode(from string: String) -> Image? {
71 +
72 + let data = string.data(using: String.Encoding.ascii)
73 +
74 + if let filter = CIFilter(name: "CICode128BarcodeGenerator") {
75 + filter.setValue(data, forKey: "inputMessage")
76 +// let transform = CGAffineTransform(scaleX: 3, y: 3)
77 +
78 +
79 +// if let output = filter.outputImage?.transformed(by: transform) {
80 + if let output = filter.outputImage {
81 +
82 +// // Change the color using CIFilter
83 +// let colorParameters = [
84 +// "inputColor0": CIColor(color: UIColor.black), // Foreground
85 +// "inputColor1": CIColor(color: UIColor.clear) // Background
86 +// ]
87 +// let colored = output.applyingFilter("CIFalseColor", parameters: colorParameters)
88 + let image = Image(uiImage: UIImage(ciImage: output))
89 +
90 +// return UIImage(ciImage: output)
91 + return image
92 + }
93 + }
94 +
95 + return nil
96 + }
97 +
98 +
99 + var body: some View {
100 + GeometryReader { geometry in
101 + ScrollView(showsIndicators: false) {
102 + VStack(alignment: .leading) {
103 +
104 + ImageView(withURL: coupon["img_preview"] as? String ?? "")
105 +
106 + VStack(alignment: .leading) {
107 + Text(coupon["name"] as? String ?? "")
108 + .fontWeight(.bold)
109 + .font(.system(size: 16))
110 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
111 + .multilineTextAlignment(.leading)
112 + .padding(.horizontal)
113 + .padding(.top, self.uiscreen.height * 0.04)
114 +
115 + Text(coupon["short_description"] as? String ?? "")
116 + .fontWeight(.regular)
117 + .font(.system(size: 14))
118 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
119 + .multilineTextAlignment(.leading)
120 + .padding(.horizontal)
121 + .padding(.top, self.uiscreen.height * 0.02)
122 +
123 + Text("Κωδικός Κουπονιού")
124 + .fontWeight(.medium)
125 + .font(.system(size: 16))
126 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
127 + .multilineTextAlignment(.center)
128 + .padding(.top, self.uiscreen.height * 0.05)
129 + .padding(.horizontal)
130 + .frame(maxWidth: .infinity)
131 +
132 + VStack(alignment: .center) {
133 + VStack {
134 + Text("1A2C378")
135 + .fontWeight(.bold)
136 + .font(.system(size: 27))
137 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
138 + .multilineTextAlignment(.center)
139 + .padding(.horizontal)
140 + .padding(.vertical, 10)
141 +// .padding(.all)
142 + }
143 + .frame(width: self.uiscreen.width * 0.8)
144 + .background(Color(red: 0.9333333333333333, green: 0.9686274509803922, blue: 1.0))
145 + .cornerRadius(10)
146 + }
147 + .frame(maxWidth: .infinity)
148 +
149 + if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: "123456789101112"))) {
150 + VStack(alignment: .center) {
151 + VStack {}
152 + .frame(height: 1)
153 + .frame(width: self.uiscreen.width * 0.9)
154 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
155 + }
156 + .frame(maxWidth: .infinity)
157 + .padding(.top, self.uiscreen.height * 0.015)
158 +
159 + // TODO: Add the barcode
160 +// generateBarcode(from: "1234567891234")
161 +// ?
162 +// .resizable()
163 +// .aspectRatio(contentMode: .fit)
164 +// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
165 +
166 + Text("123456789101112")
167 + .fontWeight(.regular)
168 + .font(.system(size: 22))
169 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
170 + .multilineTextAlignment(.center)
171 + .padding(.vertical, self.uiscreen.height * 0.01)
172 + .padding(.horizontal)
173 + .frame(maxWidth: .infinity)
174 +
175 +
176 + VStack(alignment: .center) {
177 + VStack {}
178 + .frame(height: 1)
179 + .frame(width: self.uiscreen.width * 0.9)
180 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
181 + }
182 + .frame(maxWidth: .infinity)
183 + }
184 +
185 +
186 +
187 + Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["expiration"] as? String ?? ""))
188 + .fontWeight(.medium)
189 + .font(.system(size: 14))
190 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
191 + .multilineTextAlignment(.center)
192 + .padding(.top, self.uiscreen.height * 0.03)
193 + .padding(.horizontal)
194 + .frame(maxWidth: .infinity)
195 + }
196 + .frame(width:self.uiscreen.width)
197 +
198 +
199 +
200 + Spacer()
201 +
202 + VStack(alignment: .center) {
203 + Button {
204 + // Button Action
205 + print("Send Gift Button tapped!")
206 + } label: {
207 + HStack {
208 + Text("Κάντο δώρο!")
209 + .fontWeight(.medium)
210 + .font(.system(size: 16))
211 + .foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961))
212 + .multilineTextAlignment(.center)
213 + .padding(.all)
214 +
215 + // TODO: Add gift icon
216 + }
217 + .frame(maxWidth: .infinity)
218 + }
219 + .frame(width: self.uiscreen.width * 0.8)
220 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
221 + .cornerRadius(7)
222 + }
223 + .frame(maxWidth: .infinity)
224 + .padding(.top, self.uiscreen.height * 0.05)
225 +
226 +// VStack(alignment: .center) {
227 +// Button {
228 +// // Button Action
229 +// print("Shops Map Button tapped!")
230 +// } label: {
231 +// HStack {
232 +// Text("Χάρτης Καταστημάτων")
233 +// .fontWeight(.medium)
234 +// .font(.system(size: 16))
235 +// .foregroundColor(Color.white)
236 +// .multilineTextAlignment(.center)
237 +// .padding(.all)
238 +// }
239 +// .frame(maxWidth: .infinity)
240 +// }
241 +// .frame(width: self.uiscreen.width * 0.8)
242 +// .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196))
243 +// .cornerRadius(7)
244 +// }
245 +// .frame(maxWidth: .infinity)
246 +// .padding(.top, self.uiscreen.height * 0.015)
247 +
248 + Button {
249 + // Button Action
250 + print("Terms Button tapped!")
251 + } label: {
252 + Text("Όροι χρήσης")
253 + .fontWeight(.medium)
254 + .font(.system(size: 14))
255 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
256 + .underline()
257 + .multilineTextAlignment(.center)
258 + .padding(.top, self.uiscreen.height * 0.025)
259 + .padding(.bottom, self.uiscreen.height * 0.03)
260 + .padding(.horizontal)
261 + .frame(maxWidth: .infinity)
262 + }
263 + .frame(maxWidth: .infinity)
264 +
265 +
266 + }
267 + .frame(width:self.uiscreen.width)
268 + .frame(minHeight: geometry.size.height)
269 + .padding(.bottom, self.uiscreen.height * 0.03)
270 + }
271 + .frame(width:self.uiscreen.width)
272 + .frame(maxHeight: .infinity)
273 + }
274 + .frame(width:self.uiscreen.width)
275 + .frame(maxHeight: .infinity)
276 + }
277 + }
278 +
279 + struct ImageView: View {
280 + @ObservedObject var imageLoader:UrlImageModel
281 +
282 + var uiscreen = UIScreen.main.bounds
283 +
284 + init(withURL url:String) {
285 + imageLoader = UrlImageModel(urlString:url)
286 + }
287 +
288 + var body: some View {
289 +
290 + Image(uiImage: imageLoader.image ?? UIImage())
291 + .resizable()
292 + .aspectRatio(contentMode: .fill)
293 + .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
294 + }
295 + }
296 +
297 +}
298 +
299 +@available(iOS 13.0.0, *)
300 +struct CouponBarcodeView: View {
301 + var parentView: UIView
302 + var coupon: Dictionary<String, Any>
303 + @State var couponset: CouponSetItemModel?
304 +
305 + var uiscreen = UIScreen.main.bounds
306 +
307 + func goBack() {
308 + for subview in parentView.subviews {
309 + if(subview.tag == 7) {
310 + subview.removeFromSuperview()
311 + }
312 + }
313 + }
314 +
315 +
316 + var body: some View {
317 + VStack {
318 + headerView(goBack: goBack)
319 +
320 + VStack {
321 + couponContainer(coupon: coupon)
322 + }
323 + .background(Color.white)
324 + .cornerRadius(30, corners: [.topLeft])
325 + .frame(width:self.uiscreen.width)
326 + .frame(maxHeight: .infinity)
327 + }
328 + .edgesIgnoringSafeArea([.bottom])
329 + .frame(width:self.uiscreen.width)
330 + .frame(maxHeight: .infinity)
331 +// .onAppear {
332 +// // If you want to setup data with model
333 +// couponset = CouponSetItemModel(dictionary: coupon)
334 +//
335 +// }
336 + }
337 +}
338 +#endif
339 +
340 +//struct CouponBarcodeView_Previews: PreviewProvider {
341 +// static var previews: some View {
342 +// CouponBarcodeView()
343 +// }
344 +//}
1 +//
2 +// CouponBarcodeViewInterface.swift
3 +// WarplySDKFrameworkIOS
4 +//
5 +// Created by Manos Chorianopoulos on 21/4/22.
6 +//
7 +
8 +import Foundation
9 +import SwiftUI
10 +
11 +@available(iOS 13.0.0, *)
12 +@objc public class CouponBarcodeViewInterface : NSObject {
13 +
14 + @objc(couponBarcodeViewController::) static public func couponBarcodeViewController(parentView: UIView?, coupon: Dictionary<String, Any>) -> UIViewController {
15 + return UIHostingController(rootView: CouponBarcodeView(parentView: parentView!, coupon: coupon))
16 + }
17 +
18 +}
19 +
...@@ -130,24 +130,20 @@ extension CouponView { ...@@ -130,24 +130,20 @@ extension CouponView {
130 } 130 }
131 131
132 struct ImageView: View { 132 struct ImageView: View {
133 - @ObservedObject var imageLoader:ImageLoaderGifts 133 + @ObservedObject var imageLoader:UrlImageModel
134 - @State var image:UIImage = UIImage()
135 134
136 var uiscreen = UIScreen.main.bounds 135 var uiscreen = UIScreen.main.bounds
137 136
138 init(withURL url:String) { 137 init(withURL url:String) {
139 - imageLoader = ImageLoaderGifts(urlString:url) 138 + imageLoader = UrlImageModel(urlString:url)
140 } 139 }
141 140
142 var body: some View { 141 var body: some View {
143 142
144 - Image(uiImage: image) 143 + Image(uiImage: imageLoader.image ?? UIImage())
145 .resizable() 144 .resizable()
146 .aspectRatio(contentMode: .fill) 145 .aspectRatio(contentMode: .fill)
147 .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25) 146 .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
148 - .onReceive(imageLoader.didChange) { data in
149 - self.image = UIImage(data: data) ?? UIImage()
150 - }
151 } 147 }
152 } 148 }
153 149
......
...@@ -179,24 +179,88 @@ struct RoundedCorner: Shape { ...@@ -179,24 +179,88 @@ struct RoundedCorner: Shape {
179 } 179 }
180 } 180 }
181 181
182 -class ImageLoaderGifts: ObservableObject { 182 +class UrlImageModel: ObservableObject {
183 - var didChange = PassthroughSubject<Data, Never>() 183 + @Published var image: UIImage?
184 - var data = Data() { 184 + var urlString: String?
185 - didSet { 185 + var imageCache = ImageCache.getImageCache()
186 - didChange.send(data) 186 +
187 +
188 + func loadImage() {
189 + if loadImageFromCache() {
190 + print("Cache hit")
191 + return
187 } 192 }
193 +
194 + print("Cache miss, loading from url")
195 + loadImageFromUrl()
188 } 196 }
189 197
190 - init(urlString:String) { 198 + func loadImageFromCache() -> Bool {
191 - guard let url = URL(string: urlString) else { return } 199 + guard let urlString = urlString else {
192 - let task = URLSession.shared.dataTask(with: url) { data, response, error in 200 + return false
193 - guard let data = data else { return }
194 - DispatchQueue.main.async {
195 - self.data = data
196 } 201 }
202 +
203 + guard let cacheImage = imageCache.get(forKey: urlString) else {
204 + return false
205 + }
206 +
207 + image = cacheImage
208 + return true
197 } 209 }
210 +
211 + func loadImageFromUrl() {
212 + guard let urlString = urlString else {
213 + return
214 + }
215 +
216 + let url = URL(string: urlString)!
217 + let task = URLSession.shared.dataTask(with: url, completionHandler: getImageFromResponse(data:response:error:))
198 task.resume() 218 task.resume()
199 } 219 }
220 +
221 + func getImageFromResponse(data: Data?, response: URLResponse?, error: Error?) {
222 + guard error == nil else {
223 + print("Error: \(error!)")
224 + return
225 + }
226 + guard let data = data else {
227 + print("No data found")
228 + return
229 + }
230 +
231 + DispatchQueue.main.async {
232 + guard let loadedImage = UIImage(data: data) else {
233 + return
234 + }
235 +
236 + self.imageCache.set(forKey: self.urlString!, image: loadedImage)
237 + self.image = loadedImage
238 + }
239 + }
240 +
241 + init(urlString:String) {
242 + self.urlString = urlString
243 + loadImage()
244 + }
245 +}
246 +
247 +class ImageCache {
248 + var cache = NSCache<NSString, UIImage>()
249 +
250 + func get(forKey: String) -> UIImage? {
251 + return cache.object(forKey: NSString(string: forKey))
252 + }
253 +
254 + func set(forKey: String, image: UIImage) {
255 + cache.setObject(image, forKey: NSString(string: forKey))
256 + }
257 +}
258 +
259 +extension ImageCache {
260 + private static var imageCache = ImageCache()
261 + static func getImageCache() -> ImageCache {
262 + return imageCache
263 + }
200 } 264 }
201 265
202 266
...@@ -286,29 +350,25 @@ extension GiftsView { ...@@ -286,29 +350,25 @@ extension GiftsView {
286 } 350 }
287 351
288 struct ImageView: View { 352 struct ImageView: View {
289 - @ObservedObject var imageLoader:ImageLoaderGifts 353 + @ObservedObject var imageLoader:UrlImageModel
290 - @State var image:UIImage = UIImage()
291 @State var width:CGFloat 354 @State var width:CGFloat
292 @State var isFill:Bool 355 @State var isFill:Bool
293 356
294 var uiscreen = UIScreen.main.bounds 357 var uiscreen = UIScreen.main.bounds
295 358
296 init(withURL url:String , width:CGFloat, isFill:Bool) { 359 init(withURL url:String , width:CGFloat, isFill:Bool) {
297 - imageLoader = ImageLoaderGifts(urlString:url) 360 + imageLoader = UrlImageModel(urlString:url)
298 self.width = width 361 self.width = width
299 self.isFill = isFill 362 self.isFill = isFill
300 } 363 }
301 364
302 var body: some View { 365 var body: some View {
303 366
304 - Image(uiImage: image) 367 + Image(uiImage: imageLoader.image ?? UIImage())
305 .resizable() 368 .resizable()
306 .aspectRatio(contentMode: isFill ? .fill : .fit) 369 .aspectRatio(contentMode: isFill ? .fill : .fit)
307 .frame(width: self.width) 370 .frame(width: self.width)
308 .frame(maxHeight: .infinity) 371 .frame(maxHeight: .infinity)
309 - .onReceive(imageLoader.didChange) { data in
310 - self.image = UIImage(data: data) ?? UIImage()
311 - }
312 } 372 }
313 } 373 }
314 374
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 - (void) setLang:(NSString*) lang; 19 - (void) setLang:(NSString*) lang;
20 - (UIViewController *) openCoupons:(UIView*) parentView; 20 - (UIViewController *) openCoupons:(UIView*) parentView;
21 - (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon; 21 - (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon;
22 +- (UIViewController *) openCouponBarcode:(UIView*) parentView coupon:(NSDictionary*) coupon;
22 - (UIViewController *) openGifts:(UIView*) parentView; 23 - (UIViewController *) openGifts:(UIView*) parentView;
23 - (UIViewController *) openWallet:(UIView*) parentView; 24 - (UIViewController *) openWallet:(UIView*) parentView;
24 - (UIViewController *) openMoreForYou:(UIView*) parentView; 25 - (UIViewController *) openMoreForYou:(UIView*) parentView;
......
...@@ -59,6 +59,12 @@ NSString *LANG; ...@@ -59,6 +59,12 @@ NSString *LANG;
59 return couponViewController; 59 return couponViewController;
60 } 60 }
61 61
62 +- (UIViewController *) openCouponBarcode:(UIView*) parentView coupon:(NSDictionary*) coupon {
63 +
64 + UIViewController *couponBarcodeViewController = [CouponBarcodeViewInterface couponBarcodeViewController:parentView :coupon];
65 + return couponBarcodeViewController;
66 +}
67 +
62 - (UIViewController *) openGifts:(UIView*) parentView{ 68 - (UIViewController *) openGifts:(UIView*) parentView{
63 69
64 UIViewController *giftsViewController = [GiftsViewInterface giftsViewController:parentView]; 70 UIViewController *giftsViewController = [GiftsViewInterface giftsViewController:parentView];
......