Showing
5 changed files
with
105 additions
and
15 deletions
... | @@ -285,6 +285,9 @@ WL_VERSION_INTERFACE() | ... | @@ -285,6 +285,9 @@ WL_VERSION_INTERFACE() |
285 | - (BOOL)getInboxWithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | 285 | - (BOOL)getInboxWithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; |
286 | 286 | ||
287 | 287 | ||
288 | +- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | ||
289 | + | ||
290 | + | ||
288 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure; | 291 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure; |
289 | 292 | ||
290 | - (void)sendContactWithSuccessBlock:(NSString *)name andEmail:(NSString *)email andMsisdn:msisdn andMessage:message :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure; | 293 | - (void)sendContactWithSuccessBlock:(NSString *)name andEmail:(NSString *)email andMsisdn:msisdn andMessage:message :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
... | @@ -430,6 +430,30 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -430,6 +430,30 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
430 | return [self isRegistrationValid]; | 430 | return [self isRegistrationValid]; |
431 | } | 431 | } |
432 | 432 | ||
433 | +- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure | ||
434 | +{ | ||
435 | + if (self.allOffers.count > 0) { | ||
436 | + success(self.allOffers); | ||
437 | + } else { | ||
438 | + NSDictionary *postDictionary = @{@"offers": @{@"action": @"get_inbox"}}; | ||
439 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
440 | + | ||
441 | + [self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
442 | + if (success) { | ||
443 | + success([contextResponse valueForKey:@"MAPP_OFFER"]); | ||
444 | + } | ||
445 | + } failureBlock:^(NSError *error) { | ||
446 | + if (failure) { | ||
447 | + failure(error); | ||
448 | + } | ||
449 | + }]; | ||
450 | + } | ||
451 | + | ||
452 | + | ||
453 | + return [self isRegistrationValid]; | ||
454 | +} | ||
455 | + | ||
456 | + | ||
433 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure | 457 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure |
434 | { | 458 | { |
435 | if (filter == nil) { | 459 | if (filter == nil) { | ... | ... |
No preview for this file type
... | @@ -50,6 +50,67 @@ class DataModel { | ... | @@ -50,6 +50,67 @@ class DataModel { |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | +struct UrlImageView: View { | ||
54 | + @ObservedObject var urlImageModel: UrlImageModel | ||
55 | + | ||
56 | + init(urlString: String?) { | ||
57 | + urlImageModel = UrlImageModel(urlString: urlString) | ||
58 | + } | ||
59 | + | ||
60 | + var body: some View { | ||
61 | + Image(uiImage: urlImageModel.image ?? UrlImageView.defaultImage!) | ||
62 | + .resizable() | ||
63 | + .scaledToFill() | ||
64 | + } | ||
65 | + | ||
66 | + static var defaultImage = UIImage(systemName: "photo") | ||
67 | +} | ||
68 | + | ||
69 | +class UrlImageModel: ObservableObject { | ||
70 | + @Published var image: UIImage? | ||
71 | + var urlString: String? | ||
72 | + | ||
73 | + init(urlString: String?) { | ||
74 | + self.urlString = urlString | ||
75 | + loadImage() | ||
76 | + } | ||
77 | + | ||
78 | + func loadImage() { | ||
79 | + loadImageFromUrl() | ||
80 | + } | ||
81 | + | ||
82 | + func loadImageFromUrl() { | ||
83 | + guard let urlString = urlString else { | ||
84 | + return | ||
85 | + } | ||
86 | + | ||
87 | + let url = URL(string: urlString)! | ||
88 | + let task = URLSession.shared.dataTask(with: url, completionHandler: | ||
89 | + getImageFromResponse(data:response:error:)) | ||
90 | + task.resume() | ||
91 | + } | ||
92 | + | ||
93 | + | ||
94 | + func getImageFromResponse(data: Data?, response: URLResponse?, error: Error?) | ||
95 | + { | ||
96 | + guard error == nil else { | ||
97 | + print("Error: \(error!)") | ||
98 | + return | ||
99 | + } | ||
100 | + guard let data = data else { | ||
101 | + print("No data found") | ||
102 | + return | ||
103 | + } | ||
104 | + | ||
105 | + DispatchQueue.main.async { | ||
106 | + guard let loadedImage = UIImage(data: data) else { | ||
107 | + return | ||
108 | + } | ||
109 | + self.image = loadedImage | ||
110 | + } | ||
111 | + } | ||
112 | +} | ||
113 | + | ||
53 | extension CouponsView { | 114 | extension CouponsView { |
54 | struct headerView: View { | 115 | struct headerView: View { |
55 | 116 | ||
... | @@ -69,26 +130,28 @@ extension CouponsView { | ... | @@ -69,26 +130,28 @@ extension CouponsView { |
69 | } | 130 | } |
70 | } | 131 | } |
71 | 132 | ||
133 | + | ||
134 | + | ||
72 | struct couponView: View { | 135 | struct couponView: View { |
73 | - @Binding var result: NSDictionary | 136 | + var result: NSDictionary |
137 | + var index: Int | ||
74 | 138 | ||
75 | var uiscreen = UIScreen.main.bounds | 139 | var uiscreen = UIScreen.main.bounds |
76 | 140 | ||
77 | var body: some View { | 141 | var body: some View { |
78 | ZStack { | 142 | ZStack { |
79 | - URLImage(url: URL(string: result["img_preview"] as! String? ?? "")) | 143 | + UrlImageView(urlString: result["img_preview"] as? String) |
80 | -// .resizable() | 144 | + .frame(width: self.uiscreen.height * 0.25, height: self.uiscreen.height * 0.05, alignment: .leading) |
81 | - .frame(width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04) | 145 | + .offset(x: self.uiscreen.width * 0.05, y: self.uiscreen.height * 0.06) |
82 | - .cornerRadius(CGFloat(self.uiscreen.height * 0.02)) | ||
83 | -// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.14, y: -self.uiscreen.height * 0.07) | ||
84 | 146 | ||
85 | } | 147 | } |
86 | -// .background( | 148 | + .background( |
87 | -// Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self)) | 149 | + Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self)) |
88 | -// .resizable() | 150 | + .resizable() |
89 | -//// .edgesIgnoringSafeArea(.all) | 151 | + .offset(x: self.uiscreen.width * 0.05, y: (CGFloat(index + 1) * self.uiscreen.height * 0.06) + CGFloat(index) * self.uiscreen.height * 0.17) |
90 | -// .frame(width: UIScreen.main.bounds.width * 0.8, height: UIScreen.main.bounds.height * 0.17) | 152 | + .padding() |
91 | -// ) | 153 | + .frame(width: UIScreen.main.bounds.width * 0.9, height: UIScreen.main.bounds.height * 0.17, alignment: .topLeading) |
154 | + ) | ||
92 | } | 155 | } |
93 | } | 156 | } |
94 | 157 | ||
... | @@ -107,8 +170,8 @@ struct CouponsView: View { | ... | @@ -107,8 +170,8 @@ struct CouponsView: View { |
107 | ScrollView { | 170 | ScrollView { |
108 | VStack { | 171 | VStack { |
109 | if (data.count) > 0 { | 172 | if (data.count) > 0 { |
110 | - ForEach(data, id: \.self) { result in | 173 | + ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in |
111 | - couponView(result: result) | 174 | + couponView(result: result, index: index) |
112 | } | 175 | } |
113 | } | 176 | } |
114 | } | 177 | } | ... | ... |
... | @@ -117,7 +117,7 @@ NSString *LANG; | ... | @@ -117,7 +117,7 @@ NSString *LANG; |
117 | __block NSArray *in = [NSMutableArray alloc]; | 117 | __block NSArray *in = [NSMutableArray alloc]; |
118 | __block BOOL isRunLoopNested = NO; | 118 | __block BOOL isRunLoopNested = NO; |
119 | __block BOOL isOperationCompleted = NO; | 119 | __block BOOL isOperationCompleted = NO; |
120 | - [[Warply sharedService] getInboxWithSuccessBlock :^(NSArray *inbox) { | 120 | + [[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) { |
121 | in = inbox; | 121 | in = inbox; |
122 | isOperationCompleted = YES; | 122 | isOperationCompleted = YES; |
123 | if (isRunLoopNested) { | 123 | if (isRunLoopNested) { | ... | ... |
-
Please register or login to post a comment