Vasilis

addition of getinbox2 in sdk

......@@ -285,6 +285,9 @@ WL_VERSION_INTERFACE()
- (BOOL)getInboxWithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure;
- (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)
return [self isRegistrationValid];
}
- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure
{
if (self.allOffers.count > 0) {
success(self.allOffers);
} else {
NSDictionary *postDictionary = @{@"offers": @{@"action": @"get_inbox"}};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success([contextResponse valueForKey:@"MAPP_OFFER"]);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
return [self isRegistrationValid];
}
- (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure
{
if (filter == nil) {
......
......@@ -50,6 +50,67 @@ class DataModel {
}
}
struct UrlImageView: View {
@ObservedObject var urlImageModel: UrlImageModel
init(urlString: String?) {
urlImageModel = UrlImageModel(urlString: urlString)
}
var body: some View {
Image(uiImage: urlImageModel.image ?? UrlImageView.defaultImage!)
.resizable()
.scaledToFill()
}
static var defaultImage = UIImage(systemName: "photo")
}
class UrlImageModel: ObservableObject {
@Published var image: UIImage?
var urlString: String?
init(urlString: String?) {
self.urlString = urlString
loadImage()
}
func loadImage() {
loadImageFromUrl()
}
func loadImageFromUrl() {
guard let urlString = urlString else {
return
}
let url = URL(string: urlString)!
let task = URLSession.shared.dataTask(with: url, completionHandler:
getImageFromResponse(data:response:error:))
task.resume()
}
func getImageFromResponse(data: Data?, response: URLResponse?, error: Error?)
{
guard error == nil else {
print("Error: \(error!)")
return
}
guard let data = data else {
print("No data found")
return
}
DispatchQueue.main.async {
guard let loadedImage = UIImage(data: data) else {
return
}
self.image = loadedImage
}
}
}
extension CouponsView {
struct headerView: View {
......@@ -69,26 +130,28 @@ extension CouponsView {
}
}
struct couponView: View {
@Binding var result: NSDictionary
var result: NSDictionary
var index: Int
var uiscreen = UIScreen.main.bounds
var body: some View {
ZStack {
URLImage(url: URL(string: result["img_preview"] as! String? ?? ""))
// .resizable()
.frame(width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04)
.cornerRadius(CGFloat(self.uiscreen.height * 0.02))
// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.14, y: -self.uiscreen.height * 0.07)
UrlImageView(urlString: result["img_preview"] as? String)
.frame(width: self.uiscreen.height * 0.25, height: self.uiscreen.height * 0.05, alignment: .leading)
.offset(x: self.uiscreen.width * 0.05, y: self.uiscreen.height * 0.06)
}
// .background(
// Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self))
// .resizable()
//// .edgesIgnoringSafeArea(.all)
// .frame(width: UIScreen.main.bounds.width * 0.8, height: UIScreen.main.bounds.height * 0.17)
// )
.background(
Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
.offset(x: self.uiscreen.width * 0.05, y: (CGFloat(index + 1) * self.uiscreen.height * 0.06) + CGFloat(index) * self.uiscreen.height * 0.17)
.padding()
.frame(width: UIScreen.main.bounds.width * 0.9, height: UIScreen.main.bounds.height * 0.17, alignment: .topLeading)
)
}
}
......@@ -107,8 +170,8 @@ struct CouponsView: View {
ScrollView {
VStack {
if (data.count) > 0 {
ForEach(data, id: \.self) { result in
couponView(result: result)
ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in
couponView(result: result, index: index)
}
}
}
......
......@@ -117,7 +117,7 @@ NSString *LANG;
__block NSArray *in = [NSMutableArray alloc];
__block BOOL isRunLoopNested = NO;
__block BOOL isOperationCompleted = NO;
[[Warply sharedService] getInboxWithSuccessBlock :^(NSArray *inbox) {
[[Warply sharedService] getInbox2WithSuccessBlock :^(NSArray *inbox) {
in = inbox;
isOperationCompleted = YES;
if (isRunLoopNested) {
......