Showing
2 changed files
with
48 additions
and
23 deletions
No preview for this file type
... | @@ -13,12 +13,20 @@ import UIKit | ... | @@ -13,12 +13,20 @@ import UIKit |
13 | 13 | ||
14 | class DataModel { | 14 | class DataModel { |
15 | var data: Array<NSDictionary> = [] | 15 | var data: Array<NSDictionary> = [] |
16 | + var data2: Array<swiftApi.CouponItemModel> = [] | ||
16 | 17 | ||
17 | init() { //initializer method | 18 | init() { //initializer method |
19 | + | ||
20 | + let instanceOfMySwiftApi = swiftApi() | ||
21 | + let couponsData = instanceOfMySwiftApi.getCoupons() | ||
22 | + | ||
23 | + self.data2 = couponsData | ||
24 | + | ||
25 | + | ||
18 | let instanceOfMyApi = MyApi() | 26 | let instanceOfMyApi = MyApi() |
19 | let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) | 27 | let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) |
20 | let coupons = instanceOfMyApi.getCoupons() as AnyObject? | 28 | let coupons = instanceOfMyApi.getCoupons() as AnyObject? |
21 | - | 29 | + |
22 | if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | 30 | if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { |
23 | let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) | 31 | let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) |
24 | if let myCouponsDictionary = coupons as? [String : AnyObject] { | 32 | if let myCouponsDictionary = coupons as? [String : AnyObject] { |
... | @@ -33,20 +41,26 @@ class DataModel { | ... | @@ -33,20 +41,26 @@ class DataModel { |
33 | if c["couponset_uuid"] as! String == s["uuid"] as! String { | 41 | if c["couponset_uuid"] as! String == s["uuid"] as! String { |
34 | var temp = NSMutableDictionary(dictionary: s); | 42 | var temp = NSMutableDictionary(dictionary: s); |
35 | // temp.addEntries(from: c as! [AnyHashable : Any]) | 43 | // temp.addEntries(from: c as! [AnyHashable : Any]) |
36 | - | 44 | + |
37 | temp.setValue(c as! [AnyHashable : Any],forKey: "coupon_data") | 45 | temp.setValue(c as! [AnyHashable : Any],forKey: "coupon_data") |
38 | - | 46 | + |
39 | self.data.append(temp as NSDictionary) | 47 | self.data.append(temp as NSDictionary) |
40 | } | 48 | } |
41 | - | 49 | + |
42 | } | 50 | } |
43 | } | 51 | } |
44 | - | 52 | + |
45 | } | 53 | } |
46 | } | 54 | } |
47 | } | 55 | } |
48 | } | 56 | } |
49 | } | 57 | } |
58 | + | ||
59 | + var getData2: Array<swiftApi.CouponItemModel> { | ||
60 | + get { // getter | ||
61 | + return data2 | ||
62 | + } | ||
63 | + } | ||
50 | 64 | ||
51 | var getData: Array<NSDictionary> { | 65 | var getData: Array<NSDictionary> { |
52 | get { // getter | 66 | get { // getter |
... | @@ -143,7 +157,7 @@ extension CouponsView { | ... | @@ -143,7 +157,7 @@ extension CouponsView { |
143 | } | 157 | } |
144 | 158 | ||
145 | struct couponView: View { | 159 | struct couponView: View { |
146 | - var result: NSDictionary | 160 | + var result: swiftApi.CouponItemModel |
147 | var index: Int | 161 | var index: Int |
148 | var parentView: UIView | 162 | var parentView: UIView |
149 | 163 | ||
... | @@ -154,19 +168,20 @@ extension CouponsView { | ... | @@ -154,19 +168,20 @@ extension CouponsView { |
154 | } | 168 | } |
155 | 169 | ||
156 | static func convertDateFormat(inputDate: String) -> String { | 170 | static func convertDateFormat(inputDate: String) -> String { |
157 | - let olDateFormatter = DateFormatter() | 171 | + let dateFormatter = DateFormatter() |
158 | - olDateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" | 172 | + dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" |
159 | - | 173 | + if let date = dateFormatter.date(from: inputDate) { |
160 | - let oldDate = olDateFormatter.date(from: inputDate) | 174 | + dateFormatter.dateFormat = "dd/MM/yyyy" |
161 | - | 175 | + let resultString = dateFormatter.string(from: date) |
162 | - let convertDateFormatter = DateFormatter() | 176 | + return resultString |
163 | - convertDateFormatter.dateFormat = "dd/MM/yyyy" | 177 | + } else { |
164 | - | 178 | + return "" |
165 | - return convertDateFormatter.string(from: oldDate!) | 179 | + } |
166 | } | 180 | } |
167 | 181 | ||
168 | var body: some View { | 182 | var body: some View { |
169 | - let couponData = result["coupon_data"] as? [String: Any] ?? ["":""] | 183 | +// let couponData = result["coupon_data"] as? [String: Any] ?? ["":""] |
184 | + let couponSetData = result.couponset_data | ||
170 | 185 | ||
171 | 186 | ||
172 | VStack(alignment: .leading) { | 187 | VStack(alignment: .leading) { |
... | @@ -181,7 +196,7 @@ extension CouponsView { | ... | @@ -181,7 +196,7 @@ extension CouponsView { |
181 | couponBarcodeViewController.didMove(toParent: UIHostingController(rootView: self)) | 196 | couponBarcodeViewController.didMove(toParent: UIHostingController(rootView: self)) |
182 | } label: { | 197 | } label: { |
183 | HStack(alignment: .center) { | 198 | HStack(alignment: .center) { |
184 | - ImageView(withURL: result["img_preview"] as! String) | 199 | + ImageView(withURL: couponSetData?.img_preview ?? "") |
185 | .frame(maxWidth: self.uiscreen.width * 0.15) | 200 | .frame(maxWidth: self.uiscreen.width * 0.15) |
186 | .padding(.leading , self.uiscreen.width * 0.055) | 201 | .padding(.leading , self.uiscreen.width * 0.055) |
187 | VLine() | 202 | VLine() |
... | @@ -193,17 +208,17 @@ extension CouponsView { | ... | @@ -193,17 +208,17 @@ extension CouponsView { |
193 | .padding(.bottom, self.uiscreen.height * 0.0075) | 208 | .padding(.bottom, self.uiscreen.height * 0.0075) |
194 | Spacer() | 209 | Spacer() |
195 | VStack { | 210 | VStack { |
196 | - Text(CouponsView.couponView.localizedWithParameter(parameter: result["name"] as? String ?? "")) | 211 | + Text(CouponsView.couponView.localizedWithParameter(parameter: couponSetData?.name ?? "")) |
197 | .fontWeight(.medium) | 212 | .fontWeight(.medium) |
198 | .foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4)) | 213 | .foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4)) |
199 | .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading) | 214 | .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading) |
200 | .font(.system(size: 15)) | 215 | .font(.system(size: 15)) |
201 | - Text(CouponsView.couponView.localizedWithParameter(parameter: couponData["discount"] as? String ?? "")) | 216 | + Text(CouponsView.couponView.localizedWithParameter(parameter: result.discount ?? "")) |
202 | .fontWeight(.bold) | 217 | .fontWeight(.bold) |
203 | .foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4)) | 218 | .foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4)) |
204 | .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: self.uiscreen.height * 0.05, alignment: .leading) | 219 | .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: self.uiscreen.height * 0.05, alignment: .leading) |
205 | .font(.system(size: 47)) | 220 | .font(.system(size: 47)) |
206 | - Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + CouponsView.couponView.convertDateFormat(inputDate: couponData["expiration"] as? String ?? ""))) | 221 | + Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + (result.expiration ?? ""))) |
207 | .fontWeight(.medium) | 222 | .fontWeight(.medium) |
208 | .foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764)) | 223 | .foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764)) |
209 | .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading) | 224 | .frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading) |
... | @@ -213,7 +228,7 @@ extension CouponsView { | ... | @@ -213,7 +228,7 @@ extension CouponsView { |
213 | .padding(.top, self.uiscreen.height * 0.03) | 228 | .padding(.top, self.uiscreen.height * 0.03) |
214 | .padding(.bottom, self.uiscreen.height * 0.03) | 229 | .padding(.bottom, self.uiscreen.height * 0.03) |
215 | VStack { | 230 | VStack { |
216 | - Text(CouponsView.couponView.localizedWithParameter(parameter: result["short_description"] as! String)) | 231 | + Text(CouponsView.couponView.localizedWithParameter(parameter: couponSetData?.short_description ?? "")) |
217 | .fontWeight(.medium) | 232 | .fontWeight(.medium) |
218 | .foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764)) | 233 | .foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764)) |
219 | .frame(maxWidth: self.uiscreen.width * 0.22, maxHeight: self.uiscreen.height * 0.10) | 234 | .frame(maxWidth: self.uiscreen.width * 0.22, maxHeight: self.uiscreen.height * 0.10) |
... | @@ -238,13 +253,23 @@ extension CouponsView { | ... | @@ -238,13 +253,23 @@ extension CouponsView { |
238 | 253 | ||
239 | @available(iOS 13.0.0, *) | 254 | @available(iOS 13.0.0, *) |
240 | struct CouponsView: View { | 255 | struct CouponsView: View { |
241 | - | 256 | + |
242 | - var data:Array<NSDictionary> = DataModel().getData | 257 | +// var data:Array<swiftApi.CouponItemModel> = [] |
258 | + | ||
259 | + var data:Array<swiftApi.CouponItemModel> = DataModel().getData2 | ||
243 | 260 | ||
244 | var parentView: UIView | 261 | var parentView: UIView |
245 | 262 | ||
246 | var uiscreen = UIScreen.main.bounds | 263 | var uiscreen = UIScreen.main.bounds |
247 | 264 | ||
265 | +// init() { //initializer method | ||
266 | +// | ||
267 | +// let instanceOfMySwiftApi = swiftApi() | ||
268 | +// let couponsData = instanceOfMySwiftApi.getCoupons() | ||
269 | +// | ||
270 | +// self.data = couponsData | ||
271 | +// } | ||
272 | + | ||
248 | func goBack(){ | 273 | func goBack(){ |
249 | for subview in parentView.subviews { | 274 | for subview in parentView.subviews { |
250 | if(subview.tag == 1) { | 275 | if(subview.tag == 1) { | ... | ... |
-
Please register or login to post a comment