Manos Chorianopoulos

coupons changes

...@@ -124,8 +124,8 @@ extension CouponBarcodeView { ...@@ -124,8 +124,8 @@ extension CouponBarcodeView {
124 124
125 func constructBarcode() -> String? { 125 func constructBarcode() -> String? {
126 // EAN 13 barcode construction 126 // EAN 13 barcode construction
127 - // let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""] 127 + let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
128 - let couponString = coupon["coupon"] as? String ?? "" 128 + let couponString = couponData["coupon"] as? String ?? ""
129 129
130 if (!couponString.isEmpty) { 130 if (!couponString.isEmpty) {
131 var checkDigit = 0; 131 var checkDigit = 0;
...@@ -158,6 +158,7 @@ extension CouponBarcodeView { ...@@ -158,6 +158,7 @@ extension CouponBarcodeView {
158 158
159 159
160 var body: some View { 160 var body: some View {
161 + let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
161 let barcodeString = constructBarcode() ?? "" 162 let barcodeString = constructBarcode() ?? ""
162 163
163 GeometryReader { geometry in 164 GeometryReader { geometry in
...@@ -194,7 +195,7 @@ extension CouponBarcodeView { ...@@ -194,7 +195,7 @@ extension CouponBarcodeView {
194 195
195 VStack(alignment: .center) { 196 VStack(alignment: .center) {
196 VStack { 197 VStack {
197 - Text(coupon["coupon"] as? String ?? "") 198 + Text(couponData["coupon"] as? String ?? "")
198 .fontWeight(.bold) 199 .fontWeight(.bold)
199 .font(.system(size: 27)) 200 .font(.system(size: 27))
200 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) 201 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
...@@ -209,7 +210,7 @@ extension CouponBarcodeView { ...@@ -209,7 +210,7 @@ extension CouponBarcodeView {
209 } 210 }
210 .frame(maxWidth: .infinity) 211 .frame(maxWidth: .infinity)
211 212
212 - if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: coupon["coupon"] as? String ?? ""))) { 213 + if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: couponData["coupon"] as? String ?? ""))) {
213 VStack(alignment: .center) { 214 VStack(alignment: .center) {
214 VStack {} 215 VStack {}
215 .frame(height: 1) 216 .frame(height: 1)
...@@ -284,7 +285,7 @@ extension CouponBarcodeView { ...@@ -284,7 +285,7 @@ extension CouponBarcodeView {
284 285
285 286
286 287
287 - Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["expiration"] as? String ?? "")) 288 + Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: couponData["expiration"] as? String ?? ""))
288 .fontWeight(.medium) 289 .fontWeight(.medium)
289 .font(.system(size: 14)) 290 .font(.system(size: 14))
290 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) 291 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
...@@ -378,7 +379,7 @@ extension CouponBarcodeView { ...@@ -378,7 +379,7 @@ extension CouponBarcodeView {
378 // couponset = CouponSetItemModel(dictionary: coupon) 379 // couponset = CouponSetItemModel(dictionary: coupon)
379 380
380 print("==================") 381 print("==================")
381 - print(coupon["coupon"] as? String ?? "") 382 + print(couponData["coupon"] as? String ?? "")
382 print("==================") 383 print("==================")
383 384
384 print("========constructBarcode()==========") 385 print("========constructBarcode()==========")
......
...@@ -4,16 +4,13 @@ ...@@ -4,16 +4,13 @@
4 // 4 //
5 // Created by Βασιλης Σκουρας on 13/1/22. 5 // Created by Βασιλης Σκουρας on 13/1/22.
6 // 6 //
7 -
8 #if canImport(SwiftUI) 7 #if canImport(SwiftUI)
9 import SwiftUI 8 import SwiftUI
10 import Combine 9 import Combine
11 import Foundation 10 import Foundation
12 import UIKit 11 import UIKit
13 -
14 class DataModel { 12 class DataModel {
15 var data: Array<NSDictionary> = [] 13 var data: Array<NSDictionary> = []
16 -
17 init() { //initializer method 14 init() { //initializer method
18 let instanceOfMyApi = MyApi() 15 let instanceOfMyApi = MyApi()
19 let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) 16 let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
...@@ -32,7 +29,9 @@ class DataModel { ...@@ -32,7 +29,9 @@ class DataModel {
32 // var temp = NSMutableDictionary(dictionary: s); 29 // var temp = NSMutableDictionary(dictionary: s);
33 if c["couponset_uuid"] as! String == s["uuid"] as! String { 30 if c["couponset_uuid"] as! String == s["uuid"] as! String {
34 var temp = NSMutableDictionary(dictionary: s); 31 var temp = NSMutableDictionary(dictionary: s);
35 - temp.addEntries(from: c as! [AnyHashable : Any]) 32 +// temp.addEntries(from: c as! [AnyHashable : Any])
33 +
34 + temp.setValue(c as! [AnyHashable : Any],forKey: "coupon_data")
36 35
37 self.data.append(temp as NSDictionary) 36 self.data.append(temp as NSDictionary)
38 } 37 }
...@@ -45,14 +44,15 @@ class DataModel { ...@@ -45,14 +44,15 @@ class DataModel {
45 } 44 }
46 } 45 }
47 } 46 }
48 -
49 var getData: Array<NSDictionary> { 47 var getData: Array<NSDictionary> {
50 get { // getter 48 get { // getter
51 - return data 49 + return data.filter({
50 + let couponData = $0["coupon_data"] as? [String: Any] ?? ["":""]
51 + return couponData["status"] as? Int == 1
52 + })
52 } 53 }
53 } 54 }
54 } 55 }
55 -
56 class ImageLoader: ObservableObject { 56 class ImageLoader: ObservableObject {
57 var didChange = PassthroughSubject<Data, Never>() 57 var didChange = PassthroughSubject<Data, Never>()
58 var data = Data() { 58 var data = Data() {
...@@ -60,7 +60,6 @@ class ImageLoader: ObservableObject { ...@@ -60,7 +60,6 @@ class ImageLoader: ObservableObject {
60 didChange.send(data) 60 didChange.send(data)
61 } 61 }
62 } 62 }
63 -
64 init(urlString:String) { 63 init(urlString:String) {
65 guard let url = URL(string: urlString) else { return } 64 guard let url = URL(string: urlString) else { return }
66 let task = URLSession.shared.dataTask(with: url) { data, response, error in 65 let task = URLSession.shared.dataTask(with: url) { data, response, error in
...@@ -72,15 +71,12 @@ class ImageLoader: ObservableObject { ...@@ -72,15 +71,12 @@ class ImageLoader: ObservableObject {
72 task.resume() 71 task.resume()
73 } 72 }
74 } 73 }
75 -
76 struct ImageView: View { 74 struct ImageView: View {
77 @ObservedObject var imageLoader:ImageLoader 75 @ObservedObject var imageLoader:ImageLoader
78 @State var image:UIImage = UIImage() 76 @State var image:UIImage = UIImage()
79 -
80 init(withURL url:String) { 77 init(withURL url:String) {
81 imageLoader = ImageLoader(urlString:url) 78 imageLoader = ImageLoader(urlString:url)
82 } 79 }
83 -
84 var body: some View { 80 var body: some View {
85 81
86 Image(uiImage: image) 82 Image(uiImage: image)
...@@ -91,7 +87,6 @@ struct ImageView: View { ...@@ -91,7 +87,6 @@ struct ImageView: View {
91 } 87 }
92 } 88 }
93 } 89 }
94 -
95 struct VLine: Shape { 90 struct VLine: Shape {
96 func path(in rect: CGRect) -> Path { 91 func path(in rect: CGRect) -> Path {
97 Path { path in 92 Path { path in
...@@ -100,7 +95,6 @@ struct VLine: Shape { ...@@ -100,7 +95,6 @@ struct VLine: Shape {
100 } 95 }
101 } 96 }
102 } 97 }
103 -
104 extension CouponsView { 98 extension CouponsView {
105 struct headerView: View { 99 struct headerView: View {
106 var goBack: () -> () 100 var goBack: () -> ()
...@@ -118,6 +112,8 @@ extension CouponsView { ...@@ -118,6 +112,8 @@ extension CouponsView {
118 } 112 }
119 } 113 }
120 Text("Όλα τα κουπόνια μου") 114 Text("Όλα τα κουπόνια μου")
115 + .fontWeight(.medium)
116 + .foregroundColor(Color(red: 0.20784313725490197, green: 0.3176470588235294, blue: 0.40784313725490196))
121 .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center) 117 .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center)
122 .offset( y: self.uiscreen.height * 0.02) 118 .offset( y: self.uiscreen.height * 0.02)
123 .font(.system(size: 15)) 119 .font(.system(size: 15))
...@@ -129,9 +125,9 @@ extension CouponsView { ...@@ -129,9 +125,9 @@ extension CouponsView {
129 struct couponView: View { 125 struct couponView: View {
130 var result: NSDictionary 126 var result: NSDictionary
131 var index: Int 127 var index: Int
128 + var parentView: UIView
132 129
133 var uiscreen = UIScreen.main.bounds 130 var uiscreen = UIScreen.main.bounds
134 -
135 static func localizedWithParameter(parameter: String) -> LocalizedStringKey { 131 static func localizedWithParameter(parameter: String) -> LocalizedStringKey {
136 return "\(parameter)" 132 return "\(parameter)"
137 } 133 }
...@@ -139,52 +135,69 @@ extension CouponsView { ...@@ -139,52 +135,69 @@ extension CouponsView {
139 static func convertDateFormat(inputDate: String) -> String { 135 static func convertDateFormat(inputDate: String) -> String {
140 let olDateFormatter = DateFormatter() 136 let olDateFormatter = DateFormatter()
141 olDateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" 137 olDateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
142 -
143 let oldDate = olDateFormatter.date(from: inputDate) 138 let oldDate = olDateFormatter.date(from: inputDate)
144 -
145 let convertDateFormatter = DateFormatter() 139 let convertDateFormatter = DateFormatter()
146 convertDateFormatter.dateFormat = "dd/MM/yyyy" 140 convertDateFormatter.dateFormat = "dd/MM/yyyy"
147 -
148 return convertDateFormatter.string(from: oldDate!) 141 return convertDateFormatter.string(from: oldDate!)
149 } 142 }
150 143
151 var body: some View { 144 var body: some View {
145 + let couponData = result["coupon_data"] as? [String: Any] ?? ["":""]
152 146
153 147
154 VStack(alignment: .leading) { 148 VStack(alignment: .leading) {
155 - HStack(alignment: .center) { 149 + Button {
156 - ImageView(withURL: result["img_preview"] as! String) 150 + // GiftItem Action
157 - .frame(maxWidth: self.uiscreen.width * 0.15) 151 + let instanceOfMyApi = MyApi()
158 - .padding(.leading , self.uiscreen.width * 0.055) 152 + let couponBarcodeViewController = instanceOfMyApi.openCouponBarcode(parentView, coupon: result as! [String : Any])!
159 - VLine() 153 + couponBarcodeViewController.view.tag = 7
160 - .stroke(style: StrokeStyle(lineWidth: 1, dash: [5])) 154 + // addChild(couponsViewController)
161 - .foregroundColor(Color(red: 0.4392156862745098, green: 0.4392156862745098, blue: 0.4392156862745098)) 155 + couponBarcodeViewController.view.frame = parentView.frame
162 - .frame(width: 1) 156 + parentView.addSubview(couponBarcodeViewController.view)
163 - .padding(.leading, self.uiscreen.width * 0.01) 157 + couponBarcodeViewController.didMove(toParent: UIHostingController(rootView: self))
164 - .padding(.top, self.uiscreen.height * 0.01) 158 + } label: {
165 - .padding(.bottom, self.uiscreen.height * 0.0075) 159 + HStack(alignment: .center) {
166 - Spacer() 160 + ImageView(withURL: result["img_preview"] as! String)
167 - VStack { 161 + .frame(maxWidth: self.uiscreen.width * 0.15)
168 - Text(CouponsView.couponView.localizedWithParameter(parameter: result["admin_name"] as? String ?? "")) 162 + .padding(.leading , self.uiscreen.width * 0.055)
169 - .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading) 163 + VLine()
170 - .font(.system(size: 15)) 164 + .stroke(style: StrokeStyle(lineWidth: 1, dash: [5]))
171 - Text(CouponsView.couponView.localizedWithParameter(parameter: result["discount"] as? String ?? "")) 165 + .foregroundColor(Color(red: 0.4392156862745098, green: 0.4392156862745098, blue: 0.4392156862745098))
172 - .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: self.uiscreen.height * 0.05, alignment: .leading) 166 + .frame(width: 1)
173 - .font(.system(size: 47)) 167 + .padding(.leading, self.uiscreen.width * 0.01)
174 - Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + CouponsView.couponView.convertDateFormat(inputDate: result["expiration"] as? String ?? ""))) 168 + .padding(.top, self.uiscreen.height * 0.01)
175 - .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading) 169 + .padding(.bottom, self.uiscreen.height * 0.0075)
176 - .font(.system(size: 10)) 170 + Spacer()
177 - } 171 + VStack {
178 - .frame(maxHeight: .infinity) 172 + Text(CouponsView.couponView.localizedWithParameter(parameter: result["name"] as? String ?? ""))
179 - .padding(.top, self.uiscreen.height * 0.03) 173 + .fontWeight(.medium)
180 - .padding(.bottom, self.uiscreen.height * 0.03) 174 + .foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4))
181 - VStack { 175 + .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading)
182 - Text(CouponsView.couponView.localizedWithParameter(parameter: result["short_description"] as! String)) 176 + .font(.system(size: 15))
183 - .frame(maxWidth: self.uiscreen.width * 0.22, maxHeight: self.uiscreen.height * 0.10) 177 + Text(CouponsView.couponView.localizedWithParameter(parameter: couponData["discount"] as? String ?? ""))
184 - .font(.system(size: 10)) 178 + .fontWeight(.bold)
179 + .foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4))
180 + .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: self.uiscreen.height * 0.05, alignment: .leading)
181 + .font(.system(size: 47))
182 + Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + CouponsView.couponView.convertDateFormat(inputDate: couponData["expiration"] as? String ?? "")))
183 + .fontWeight(.medium)
184 + .foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764))
185 + .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading)
186 + .font(.system(size: 10))
187 + }
188 + .frame(maxHeight: .infinity)
189 + .padding(.top, self.uiscreen.height * 0.03)
190 + .padding(.bottom, self.uiscreen.height * 0.03)
191 + VStack {
192 + Text(CouponsView.couponView.localizedWithParameter(parameter: result["short_description"] as! String))
193 + .fontWeight(.medium)
194 + .foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764))
195 + .frame(maxWidth: self.uiscreen.width * 0.22, maxHeight: self.uiscreen.height * 0.10)
196 + .font(.system(size: 10))
197 + }
198 + .frame(maxWidth: self.uiscreen.width * 0.25, maxHeight: .infinity)
199 + Spacer()
185 } 200 }
186 - .frame(maxWidth: self.uiscreen.width * 0.25, maxHeight: .infinity)
187 - Spacer()
188 } 201 }
189 } 202 }
190 .frame(width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.13) 203 .frame(width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.13)
...@@ -198,10 +211,8 @@ extension CouponsView { ...@@ -198,10 +211,8 @@ extension CouponsView {
198 } 211 }
199 212
200 } 213 }
201 -
202 @available(iOS 13.0.0, *) 214 @available(iOS 13.0.0, *)
203 struct CouponsView: View { 215 struct CouponsView: View {
204 -
205 var data:Array<NSDictionary> = DataModel().getData 216 var data:Array<NSDictionary> = DataModel().getData
206 217
207 var parentView: UIView 218 var parentView: UIView
...@@ -219,11 +230,12 @@ struct CouponsView: View { ...@@ -219,11 +230,12 @@ struct CouponsView: View {
219 var body: some View { 230 var body: some View {
220 VStack { 231 VStack {
221 headerView(goBack: goBack) 232 headerView(goBack: goBack)
222 - ScrollView { 233 + ScrollView(showsIndicators: false) {
223 VStack { 234 VStack {
224 if (data.count) > 0 { 235 if (data.count) > 0 {
225 ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in 236 ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in
226 - couponView(result: result, index: index) } 237 + couponView(result: result, index: index, parentView: parentView)
238 + }
227 } 239 }
228 } 240 }
229 .padding(.top, self.uiscreen.height * 0.05) 241 .padding(.top, self.uiscreen.height * 0.05)
...@@ -239,7 +251,6 @@ struct CouponsView: View { ...@@ -239,7 +251,6 @@ struct CouponsView: View {
239 } 251 }
240 } 252 }
241 #endif 253 #endif
242 -
243 @available(iOS 13.0.0, *) 254 @available(iOS 13.0.0, *)
244 struct Previews_CouponsView_Previews: PreviewProvider { 255 struct Previews_CouponsView_Previews: PreviewProvider {
245 static var uiscreen = UIScreen.main.bounds 256 static var uiscreen = UIScreen.main.bounds
...@@ -253,6 +264,5 @@ struct Previews_CouponsView_Previews: PreviewProvider { ...@@ -253,6 +264,5 @@ struct Previews_CouponsView_Previews: PreviewProvider {
253 .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center) 264 .frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center)
254 .offset( y: self.uiscreen.height * 0.07) 265 .offset( y: self.uiscreen.height * 0.07)
255 } 266 }
256 -
257 } 267 }
258 -} 268 +}
...\ No newline at end of file ...\ No newline at end of file
......