Manos Chorianopoulos

add CouponBarcodeView v3

...@@ -10,7 +10,8 @@ import SwiftUI ...@@ -10,7 +10,8 @@ import SwiftUI
10 import Combine 10 import Combine
11 import Foundation 11 import Foundation
12 import UIKit 12 import UIKit
13 - 13 +//import RSBarcodes_Swift
14 +//import AVFoundation
14 15
15 16
16 extension CouponBarcodeView { 17 extension CouponBarcodeView {
...@@ -65,6 +66,36 @@ extension CouponBarcodeView { ...@@ -65,6 +66,36 @@ extension CouponBarcodeView {
65 } 66 }
66 } 67 }
67 68
69 +
70 + func generateBarcode(from string: String) -> Image? {
71 +
72 + let data = string.data(using: String.Encoding.ascii)
73 +
74 + if let filter = CIFilter(name: "CICode128BarcodeGenerator") {
75 + filter.setValue(data, forKey: "inputMessage")
76 +// let transform = CGAffineTransform(scaleX: 3, y: 3)
77 +
78 +
79 +// if let output = filter.outputImage?.transformed(by: transform) {
80 + if let output = filter.outputImage {
81 +
82 +// // Change the color using CIFilter
83 +// let colorParameters = [
84 +// "inputColor0": CIColor(color: UIColor.black), // Foreground
85 +// "inputColor1": CIColor(color: UIColor.clear) // Background
86 +// ]
87 +// let colored = output.applyingFilter("CIFalseColor", parameters: colorParameters)
88 + let image = Image(uiImage: UIImage(ciImage: output))
89 +
90 +// return UIImage(ciImage: output)
91 + return image
92 + }
93 + }
94 +
95 + return nil
96 + }
97 +
98 +
68 var body: some View { 99 var body: some View {
69 GeometryReader { geometry in 100 GeometryReader { geometry in
70 ScrollView(showsIndicators: false) { 101 ScrollView(showsIndicators: false) {
...@@ -72,6 +103,7 @@ extension CouponBarcodeView { ...@@ -72,6 +103,7 @@ extension CouponBarcodeView {
72 103
73 ImageView(withURL: coupon["img_preview"] as? String ?? "") 104 ImageView(withURL: coupon["img_preview"] as? String ?? "")
74 105
106 + VStack(alignment: .leading) {
75 Text(coupon["name"] as? String ?? "") 107 Text(coupon["name"] as? String ?? "")
76 .fontWeight(.bold) 108 .fontWeight(.bold)
77 .font(.system(size: 16)) 109 .font(.system(size: 16))
...@@ -88,6 +120,33 @@ extension CouponBarcodeView { ...@@ -88,6 +120,33 @@ extension CouponBarcodeView {
88 .padding(.horizontal) 120 .padding(.horizontal)
89 .padding(.top, self.uiscreen.height * 0.02) 121 .padding(.top, self.uiscreen.height * 0.02)
90 122
123 + Text("Κωδικός Κουπονιού")
124 + .fontWeight(.medium)
125 + .font(.system(size: 16))
126 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
127 + .multilineTextAlignment(.center)
128 + .padding(.top, self.uiscreen.height * 0.05)
129 + .padding(.horizontal)
130 + .frame(maxWidth: .infinity)
131 +
132 + VStack(alignment: .center) {
133 + VStack {
134 + Text("1A2C378")
135 + .fontWeight(.bold)
136 + .font(.system(size: 27))
137 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
138 + .multilineTextAlignment(.center)
139 + .padding(.horizontal)
140 + .padding(.vertical, 10)
141 +// .padding(.all)
142 + }
143 + .frame(width: self.uiscreen.width * 0.8)
144 + .background(Color(red: 0.9333333333333333, green: 0.9686274509803922, blue: 1.0))
145 + .cornerRadius(10)
146 + }
147 + .frame(maxWidth: .infinity)
148 +
149 + if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: "123456789101112"))) {
91 VStack(alignment: .center) { 150 VStack(alignment: .center) {
92 VStack {} 151 VStack {}
93 .frame(height: 1) 152 .frame(height: 1)
...@@ -95,7 +154,23 @@ extension CouponBarcodeView { ...@@ -95,7 +154,23 @@ extension CouponBarcodeView {
95 .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) 154 .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
96 } 155 }
97 .frame(maxWidth: .infinity) 156 .frame(maxWidth: .infinity)
157 + .padding(.top, self.uiscreen.height * 0.015)
98 158
159 + // TODO: Add the barcode
160 +// generateBarcode(from: "1234567891234")
161 +// ?
162 +// .resizable()
163 +// .aspectRatio(contentMode: .fit)
164 +// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
165 +
166 + Text("123456789101112")
167 + .fontWeight(.regular)
168 + .font(.system(size: 22))
169 + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
170 + .multilineTextAlignment(.center)
171 + .padding(.vertical, self.uiscreen.height * 0.01)
172 + .padding(.horizontal)
173 + .frame(maxWidth: .infinity)
99 174
100 175
101 VStack(alignment: .center) { 176 VStack(alignment: .center) {
...@@ -105,9 +180,11 @@ extension CouponBarcodeView { ...@@ -105,9 +180,11 @@ extension CouponBarcodeView {
105 .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) 180 .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
106 } 181 }
107 .frame(maxWidth: .infinity) 182 .frame(maxWidth: .infinity)
183 + }
184 +
108 185
109 186
110 - Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["img_preview"] as? String ?? "")) 187 + Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["expiration"] as? String ?? ""))
111 .fontWeight(.medium) 188 .fontWeight(.medium)
112 .font(.system(size: 14)) 189 .font(.system(size: 14))
113 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) 190 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
...@@ -115,6 +192,10 @@ extension CouponBarcodeView { ...@@ -115,6 +192,10 @@ extension CouponBarcodeView {
115 .padding(.top, self.uiscreen.height * 0.03) 192 .padding(.top, self.uiscreen.height * 0.03)
116 .padding(.horizontal) 193 .padding(.horizontal)
117 .frame(maxWidth: .infinity) 194 .frame(maxWidth: .infinity)
195 + }
196 + .frame(width:self.uiscreen.width)
197 +
198 +
118 199
119 Spacer() 200 Spacer()
120 201
...@@ -130,35 +211,39 @@ extension CouponBarcodeView { ...@@ -130,35 +211,39 @@ extension CouponBarcodeView {
130 .foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961)) 211 .foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961))
131 .multilineTextAlignment(.center) 212 .multilineTextAlignment(.center)
132 .padding(.all) 213 .padding(.all)
133 - }
134 - }
135 - .frame(width: self.uiscreen.width * 0.8)
136 - .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
137 - .cornerRadius(7)
138 - }
139 - .frame(maxWidth: .infinity)
140 - .padding(.top, self.uiscreen.height * 0.1)
141 214
142 - VStack(alignment: .center) { 215 + // TODO: Add gift icon
143 - Button {
144 - // Button Action
145 - print("Shops Map Button tapped!")
146 - } label: {
147 - HStack {
148 - Text("Χάρτης Καταστημάτων")
149 - .fontWeight(.medium)
150 - .font(.system(size: 16))
151 - .foregroundColor(Color.white)
152 - .multilineTextAlignment(.center)
153 - .padding(.all)
154 } 216 }
217 + .frame(maxWidth: .infinity)
155 } 218 }
156 .frame(width: self.uiscreen.width * 0.8) 219 .frame(width: self.uiscreen.width * 0.8)
157 - .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196)) 220 + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255))
158 .cornerRadius(7) 221 .cornerRadius(7)
159 } 222 }
160 .frame(maxWidth: .infinity) 223 .frame(maxWidth: .infinity)
161 - .padding(.top, self.uiscreen.height * 0.02) 224 + .padding(.top, self.uiscreen.height * 0.05)
225 +
226 +// VStack(alignment: .center) {
227 +// Button {
228 +// // Button Action
229 +// print("Shops Map Button tapped!")
230 +// } label: {
231 +// HStack {
232 +// Text("Χάρτης Καταστημάτων")
233 +// .fontWeight(.medium)
234 +// .font(.system(size: 16))
235 +// .foregroundColor(Color.white)
236 +// .multilineTextAlignment(.center)
237 +// .padding(.all)
238 +// }
239 +// .frame(maxWidth: .infinity)
240 +// }
241 +// .frame(width: self.uiscreen.width * 0.8)
242 +// .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196))
243 +// .cornerRadius(7)
244 +// }
245 +// .frame(maxWidth: .infinity)
246 +// .padding(.top, self.uiscreen.height * 0.015)
162 247
163 Button { 248 Button {
164 // Button Action 249 // Button Action
...@@ -170,7 +255,8 @@ extension CouponBarcodeView { ...@@ -170,7 +255,8 @@ extension CouponBarcodeView {
170 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) 255 .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
171 .underline() 256 .underline()
172 .multilineTextAlignment(.center) 257 .multilineTextAlignment(.center)
173 - .padding(.vertical, self.uiscreen.height * 0.03) 258 + .padding(.top, self.uiscreen.height * 0.025)
259 + .padding(.bottom, self.uiscreen.height * 0.03)
174 .padding(.horizontal) 260 .padding(.horizontal)
175 .frame(maxWidth: .infinity) 261 .frame(maxWidth: .infinity)
176 } 262 }
......