Manos Chorianopoulos
......@@ -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) {
......
......@@ -3,22 +3,4 @@
uuid = "91478161-56E8-4654-93F2-7756A39480EE"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "28AEA58D-19E0-4D42-BABE-9F1C341D6182"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "WarplySDKFrameworkIOS/CouponsView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "100"
endingLineNumber = "100"
landmarkName = "previews"
landmarkType = "24">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
......
......@@ -9,36 +9,114 @@
import SwiftUI
class DataModel {
var data: Array<NSDictionary>?
var data: Array<NSDictionary> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
let coupons = instanceOfMyApi.getCoupons() as AnyObject?
let coupons = instanceOfMyApi.getCoupons() as AnyObject?
if let myDictionary = coupons as? [String : AnyObject] {
self.data = (myDictionary["result"] as! Array<NSDictionary>)
if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] {
let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>)
if let myCouponsDictionary = coupons as? [String : AnyObject] {
let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>)
if let sets = couponSetsData as? NSArray {
for set in sets {
let s = set as! NSDictionary
if let cpns = couponsData as? NSArray {
for coupon in cpns {
var c = coupon as! NSDictionary
// var temp = NSMutableDictionary(dictionary: s);
if c["couponset_uuid"] as! String == s["uuid"] as! String {
var temp = NSMutableDictionary(dictionary: s);
temp.addEntries(from: c as! [AnyHashable : Any])
self.data.append(temp as NSDictionary)
}
}
}
}
}
}
}
}
var getData: Array<NSDictionary> {
get { // getter
return data ?? []
return data
}
}
}
struct UrlImageView: View {
@ObservedObject var urlImageModel: UrlImageModel
init(urlString: String?) {
urlImageModel = UrlImageModel(urlString: urlString)
}
@available(iOS 13.0.0, *)
struct CouponsView: View {
var data:Array<NSDictionary> = DataModel().getData
var uiscreen = UIScreen.main.bounds
// @State private var bottomRect: CGRect = .zero
var body: some View {
VStack {
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 {
var uiscreen = UIScreen.main.bounds
var body: some View {
ZStack {
Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
......@@ -49,41 +127,57 @@ struct CouponsView: View {
.offset( y: self.uiscreen.height * 0.07)
.frame(width: self.uiscreen.width)
}
}
}
struct couponView: View {
var result: NSDictionary
var index: Int
var uiscreen = UIScreen.main.bounds
var body: some View {
ZStack {
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()
.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)
)
}
}
}
@available(iOS 13.0.0, *)
struct CouponsView: View {
var data:Array<NSDictionary> = DataModel().getData
var uiscreen = UIScreen.main.bounds
var body: some View {
VStack {
headerView()
ScrollView {
VStack {
// let dataArray:[NSDictionary] = (data as! NSArray).compactMap({ $0 as? NSDictionary })
// if (data?.count())! > 0 {
// data?.forEach { (language) in
// ForEach(data, id: \.self) { result in
//
//
//
// ZStack {
// Image("logo", bundle: Bundle(for: MyEmptyClass.self))
// .resizable()
// .frame(width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04, alignment: .topLeading)
// .cornerRadius(CGFloat(self.uiscreen.height * 0.02))
// .offset(x: -self.uiscreen.width / 2 + self.uiscreen.width * 0.14, y: -self.uiscreen.height * 0.07)
//
// }.background(
// Image("coupons_container", bundle: Bundle(identifier:"framework.warp.ly.warplySDKFrameworkIOS"))
// .resizable()
// .edgesIgnoringSafeArea(.all)
// .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
// )
//
if (data.count) > 0 {
ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in
couponView(result: result, index: index)
}
}
//
}
.frame(width:self.uiscreen.width, height:self.uiscreen.height )
}
}
}
}
#endif
......
......@@ -126,7 +126,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) {
......