Vasilis
......@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
1E7086652811A93F00704CA8 /* CouponBarcodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7086642811A93F00704CA8 /* CouponBarcodeView.swift */; };
1E7086672811A96E00704CA8 /* CouponBarcodeViewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E7086662811A96E00704CA8 /* CouponBarcodeViewInterface.swift */; };
1E735FF2281067320050A298 /* CampaignWebview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E735FF1281067320050A298 /* CampaignWebview.swift */; };
1E735FF42810681E0050A298 /* CampaignWebviewInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E735FF32810681E0050A298 /* CampaignWebviewInterface.swift */; };
1EBEB02D280D69D800BF802C /* GiftsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBEB02C280D69D800BF802C /* GiftsView.swift */; };
......@@ -141,6 +143,8 @@
/* Begin PBXFileReference section */
1353B8C484CC0649CAC2EB74 /* Pods_WarplySDKFrameworkIOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WarplySDKFrameworkIOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1E7086642811A93F00704CA8 /* CouponBarcodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeView.swift; sourceTree = "<group>"; };
1E7086662811A96E00704CA8 /* CouponBarcodeViewInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponBarcodeViewInterface.swift; sourceTree = "<group>"; };
1E735FF1281067320050A298 /* CampaignWebview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignWebview.swift; sourceTree = "<group>"; };
1E735FF32810681E0050A298 /* CampaignWebviewInterface.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CampaignWebviewInterface.swift; sourceTree = "<group>"; };
1EBEB02C280D69D800BF802C /* GiftsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiftsView.swift; sourceTree = "<group>"; };
......@@ -345,6 +349,8 @@
E67D1EB9281055F800940F01 /* MoreForYouViewInterface.swift */,
E67D1EBF2810579F00940F01 /* MoreForYouView.swift */,
E67D1EC128113EED00940F01 /* CouponView.swift */,
1E7086642811A93F00704CA8 /* CouponBarcodeView.swift */,
1E7086662811A96E00704CA8 /* CouponBarcodeViewInterface.swift */,
E67D1EC328113EFD00940F01 /* CouponViewInterface.swift */,
E6D8DF5E27A9429E0006A3A9 /* MyApi.h */,
E6D8DF5C27A9429E0006A3A9 /* MyApi.m */,
......@@ -746,6 +752,7 @@
E6D8DF2E27A942920006A3A9 /* UIRefreshControl+AFNetworking.m in Sources */,
E6D8DF4827A942920006A3A9 /* AFURLRequestSerialization.m in Sources */,
E67D1EC228113EED00940F01 /* CouponView.swift in Sources */,
1E7086672811A96E00704CA8 /* CouponBarcodeViewInterface.swift in Sources */,
E6D8DEF327A942920006A3A9 /* WLNativeVideoTableViewCell.m in Sources */,
E6D8DF2527A942920006A3A9 /* WLSMSActionHanlder.m in Sources */,
E67D1EBE2810573900940F01 /* WalletView.swift in Sources */,
......@@ -790,6 +797,7 @@
E67D1EC828119ED300940F01 /* swiftApi.swift in Sources */,
E6D8DF5227A942920006A3A9 /* FMDatabase.m in Sources */,
E6D8DF1227A942920006A3A9 /* WLPushManager.m in Sources */,
1E7086652811A93F00704CA8 /* CouponBarcodeView.swift in Sources */,
E6D8DEF827A942920006A3A9 /* WLNativeAdTableViewCell.m in Sources */,
E6D8DE6D27A942010006A3A9 /* WarplySDKFrameworkIOS.docc in Sources */,
E6D8DF4427A942920006A3A9 /* AFURLResponseSerialization.m in Sources */,
......
//
// CouponBarcodeView.swift
// WarplySDKFrameworkIOS
//
// Created by Manos Chorianopoulos on 21/4/22.
//
#if canImport(SwiftUI)
import SwiftUI
import Combine
import Foundation
import UIKit
//import RSBarcodes_Swift
//import AVFoundation
extension CouponBarcodeView {
struct headerView: View {
var goBack: () -> ()
var uiscreen = UIScreen.main.bounds
var body: some View {
HStack(alignment: .center) {
Button {
// Button Action
goBack()
} label: {
Image("ic_back", bundle: Bundle(for: MyEmptyClass.self))
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: self.uiscreen.height * 0.025, height: self.uiscreen.height * 0.02)
}
Text("Εκπτωτικό κουπόνι")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.20784313725490197, green: 0.3176470588235294, blue: 0.40784313725490196))
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)
.padding(.horizontal)
}
.frame(maxWidth: .infinity)
.padding(.horizontal)
.padding(.vertical, 10)
}
}
struct couponContainer: View {
@State var coupon: Dictionary<String, Any>
// @State var couponset:CouponSetItemModel
var uiscreen = UIScreen.main.bounds
static func convertDateFormat(inputDate: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
if let date = dateFormatter.date(from: inputDate) {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
return resultString
} else {
return ""
}
}
func generateBarcode(from string: String) -> Image? {
let data = string.data(using: String.Encoding.ascii)
if let filter = CIFilter(name: "CICode128BarcodeGenerator") {
filter.setValue(data, forKey: "inputMessage")
// let transform = CGAffineTransform(scaleX: 3, y: 3)
// if let output = filter.outputImage?.transformed(by: transform) {
if let output = filter.outputImage {
// // Change the color using CIFilter
// let colorParameters = [
// "inputColor0": CIColor(color: UIColor.black), // Foreground
// "inputColor1": CIColor(color: UIColor.clear) // Background
// ]
// let colored = output.applyingFilter("CIFalseColor", parameters: colorParameters)
let image = Image(uiImage: UIImage(ciImage: output))
// return UIImage(ciImage: output)
return image
}
}
return nil
}
var body: some View {
GeometryReader { geometry in
ScrollView(showsIndicators: false) {
VStack(alignment: .leading) {
ImageView(withURL: coupon["img_preview"] as? String ?? "")
VStack(alignment: .leading) {
Text(coupon["name"] as? String ?? "")
.fontWeight(.bold)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.top, self.uiscreen.height * 0.04)
Text(coupon["short_description"] as? String ?? "")
.fontWeight(.regular)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.leading)
.padding(.horizontal)
.padding(.top, self.uiscreen.height * 0.02)
Text("Κωδικός Κουπονιού")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.center)
.padding(.top, self.uiscreen.height * 0.05)
.padding(.horizontal)
.frame(maxWidth: .infinity)
VStack(alignment: .center) {
VStack {
Text("1A2C378")
.fontWeight(.bold)
.font(.system(size: 27))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.center)
.padding(.horizontal)
.padding(.vertical, 10)
// .padding(.all)
}
.frame(width: self.uiscreen.width * 0.8)
.background(Color(red: 0.9333333333333333, green: 0.9686274509803922, blue: 1.0))
.cornerRadius(10)
}
.frame(maxWidth: .infinity)
if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: "123456789101112"))) {
VStack(alignment: .center) {
VStack {}
.frame(height: 1)
.frame(width: self.uiscreen.width * 0.9)
.background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
}
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.015)
// TODO: Add the barcode
// generateBarcode(from: "1234567891234")
// ?
// .resizable()
// .aspectRatio(contentMode: .fit)
// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
Text("123456789101112")
.fontWeight(.regular)
.font(.system(size: 22))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.center)
.padding(.vertical, self.uiscreen.height * 0.01)
.padding(.horizontal)
.frame(maxWidth: .infinity)
VStack(alignment: .center) {
VStack {}
.frame(height: 1)
.frame(width: self.uiscreen.width * 0.9)
.background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
}
.frame(maxWidth: .infinity)
}
Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["expiration"] as? String ?? ""))
.fontWeight(.medium)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.multilineTextAlignment(.center)
.padding(.top, self.uiscreen.height * 0.03)
.padding(.horizontal)
.frame(maxWidth: .infinity)
}
.frame(width:self.uiscreen.width)
Spacer()
VStack(alignment: .center) {
Button {
// Button Action
print("Send Gift Button tapped!")
} label: {
HStack {
Text("Κάντο δώρο!")
.fontWeight(.medium)
.font(.system(size: 16))
.foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961))
.multilineTextAlignment(.center)
.padding(.all)
// TODO: Add gift icon
}
.frame(maxWidth: .infinity)
}
.frame(width: self.uiscreen.width * 0.8)
.background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
.cornerRadius(7)
}
.frame(maxWidth: .infinity)
.padding(.top, self.uiscreen.height * 0.05)
// VStack(alignment: .center) {
// Button {
// // Button Action
// print("Shops Map Button tapped!")
// } label: {
// HStack {
// Text("Χάρτης Καταστημάτων")
// .fontWeight(.medium)
// .font(.system(size: 16))
// .foregroundColor(Color.white)
// .multilineTextAlignment(.center)
// .padding(.all)
// }
// .frame(maxWidth: .infinity)
// }
// .frame(width: self.uiscreen.width * 0.8)
// .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196))
// .cornerRadius(7)
// }
// .frame(maxWidth: .infinity)
// .padding(.top, self.uiscreen.height * 0.015)
Button {
// Button Action
print("Terms Button tapped!")
} label: {
Text("Όροι χρήσης")
.fontWeight(.medium)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
.underline()
.multilineTextAlignment(.center)
.padding(.top, self.uiscreen.height * 0.025)
.padding(.bottom, self.uiscreen.height * 0.03)
.padding(.horizontal)
.frame(maxWidth: .infinity)
}
.frame(maxWidth: .infinity)
}
.frame(width:self.uiscreen.width)
.frame(minHeight: geometry.size.height)
.padding(.bottom, self.uiscreen.height * 0.03)
}
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
}
struct ImageView: View {
@ObservedObject var imageLoader:UrlImageModel
var uiscreen = UIScreen.main.bounds
init(withURL url:String) {
imageLoader = UrlImageModel(urlString:url)
}
var body: some View {
Image(uiImage: imageLoader.image ?? UIImage())
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
}
}
}
@available(iOS 13.0.0, *)
struct CouponBarcodeView: View {
var parentView: UIView
var coupon: Dictionary<String, Any>
@State var couponset: CouponSetItemModel?
var uiscreen = UIScreen.main.bounds
func goBack() {
for subview in parentView.subviews {
if(subview.tag == 7) {
subview.removeFromSuperview()
}
}
}
var body: some View {
VStack {
headerView(goBack: goBack)
VStack {
couponContainer(coupon: coupon)
}
.background(Color.white)
.cornerRadius(30, corners: [.topLeft])
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
}
.edgesIgnoringSafeArea([.bottom])
.frame(width:self.uiscreen.width)
.frame(maxHeight: .infinity)
// .onAppear {
// // If you want to setup data with model
// couponset = CouponSetItemModel(dictionary: coupon)
//
// }
}
}
#endif
//struct CouponBarcodeView_Previews: PreviewProvider {
// static var previews: some View {
// CouponBarcodeView()
// }
//}
//
// CouponBarcodeViewInterface.swift
// WarplySDKFrameworkIOS
//
// Created by Manos Chorianopoulos on 21/4/22.
//
import Foundation
import SwiftUI
@available(iOS 13.0.0, *)
@objc public class CouponBarcodeViewInterface : NSObject {
@objc(couponBarcodeViewController::) static public func couponBarcodeViewController(parentView: UIView?, coupon: Dictionary<String, Any>) -> UIViewController {
return UIHostingController(rootView: CouponBarcodeView(parentView: parentView!, coupon: coupon))
}
}
......@@ -130,24 +130,20 @@ extension CouponView {
}
struct ImageView: View {
@ObservedObject var imageLoader:ImageLoaderGifts
@State var image:UIImage = UIImage()
@ObservedObject var imageLoader:UrlImageModel
var uiscreen = UIScreen.main.bounds
init(withURL url:String) {
imageLoader = ImageLoaderGifts(urlString:url)
imageLoader = UrlImageModel(urlString:url)
}
var body: some View {
Image(uiImage: image)
Image(uiImage: imageLoader.image ?? UIImage())
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.25)
.onReceive(imageLoader.didChange) { data in
self.image = UIImage(data: data) ?? UIImage()
}
}
}
......
......@@ -179,24 +179,88 @@ struct RoundedCorner: Shape {
}
}
class ImageLoaderGifts: ObservableObject {
var didChange = PassthroughSubject<Data, Never>()
var data = Data() {
didSet {
didChange.send(data)
class UrlImageModel: ObservableObject {
@Published var image: UIImage?
var urlString: String?
var imageCache = ImageCache.getImageCache()
func loadImage() {
if loadImageFromCache() {
print("Cache hit")
return
}
print("Cache miss, loading from url")
loadImageFromUrl()
}
init(urlString:String) {
guard let url = URL(string: urlString) else { return }
let task = URLSession.shared.dataTask(with: url) { data, response, error in
guard let data = data else { return }
DispatchQueue.main.async {
self.data = data
}
func loadImageFromCache() -> Bool {
guard let urlString = urlString else {
return false
}
guard let cacheImage = imageCache.get(forKey: urlString) else {
return false
}
image = cacheImage
return true
}
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.imageCache.set(forKey: self.urlString!, image: loadedImage)
self.image = loadedImage
}
}
init(urlString:String) {
self.urlString = urlString
loadImage()
}
}
class ImageCache {
var cache = NSCache<NSString, UIImage>()
func get(forKey: String) -> UIImage? {
return cache.object(forKey: NSString(string: forKey))
}
func set(forKey: String, image: UIImage) {
cache.setObject(image, forKey: NSString(string: forKey))
}
}
extension ImageCache {
private static var imageCache = ImageCache()
static func getImageCache() -> ImageCache {
return imageCache
}
}
......@@ -286,29 +350,25 @@ extension GiftsView {
}
struct ImageView: View {
@ObservedObject var imageLoader:ImageLoaderGifts
@State var image:UIImage = UIImage()
@ObservedObject var imageLoader:UrlImageModel
@State var width:CGFloat
@State var isFill:Bool
var uiscreen = UIScreen.main.bounds
init(withURL url:String , width:CGFloat, isFill:Bool) {
imageLoader = ImageLoaderGifts(urlString:url)
imageLoader = UrlImageModel(urlString:url)
self.width = width
self.isFill = isFill
}
var body: some View {
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: isFill ? .fill : .fit)
.frame(width: self.width)
.frame(maxHeight: .infinity)
.onReceive(imageLoader.didChange) { data in
self.image = UIImage(data: data) ?? UIImage()
}
Image(uiImage: imageLoader.image ?? UIImage())
.resizable()
.aspectRatio(contentMode: isFill ? .fill : .fit)
.frame(width: self.width)
.frame(maxHeight: .infinity)
}
}
......
......@@ -19,6 +19,7 @@
- (void) setLang:(NSString*) lang;
- (UIViewController *) openCoupons:(UIView*) parentView;
- (UIViewController *) openCoupon:(UIView*) parentView coupon:(NSDictionary*) coupon;
- (UIViewController *) openCouponBarcode:(UIView*) parentView coupon:(NSDictionary*) coupon;
- (UIViewController *) openGifts:(UIView*) parentView;
- (UIViewController *) openWallet:(UIView*) parentView;
- (UIViewController *) openMoreForYou:(UIView*) parentView;
......
......@@ -59,6 +59,12 @@ NSString *LANG;
return couponViewController;
}
- (UIViewController *) openCouponBarcode:(UIView*) parentView coupon:(NSDictionary*) coupon {
UIViewController *couponBarcodeViewController = [CouponBarcodeViewInterface couponBarcodeViewController:parentView :coupon];
return couponBarcodeViewController;
}
- (UIViewController *) openGifts:(UIView*) parentView{
UIViewController *giftsViewController = [GiftsViewInterface giftsViewController:parentView];
......