Manos Chorianopoulos

coupons changes

......@@ -124,8 +124,8 @@ extension CouponBarcodeView {
func constructBarcode() -> String? {
// EAN 13 barcode construction
// let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
let couponString = coupon["coupon"] as? String ?? ""
let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
let couponString = couponData["coupon"] as? String ?? ""
if (!couponString.isEmpty) {
var checkDigit = 0;
......@@ -158,6 +158,7 @@ extension CouponBarcodeView {
var body: some View {
let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
let barcodeString = constructBarcode() ?? ""
GeometryReader { geometry in
......@@ -194,7 +195,7 @@ extension CouponBarcodeView {
VStack(alignment: .center) {
VStack {
Text(coupon["coupon"] as? String ?? "")
Text(couponData["coupon"] as? String ?? "")
.fontWeight(.bold)
.font(.system(size: 27))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
......@@ -209,7 +210,7 @@ extension CouponBarcodeView {
}
.frame(maxWidth: .infinity)
if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: coupon["coupon"] as? String ?? ""))) {
if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: couponData["coupon"] as? String ?? ""))) {
VStack(alignment: .center) {
VStack {}
.frame(height: 1)
......@@ -284,7 +285,7 @@ extension CouponBarcodeView {
Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["expiration"] as? String ?? ""))
Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: couponData["expiration"] as? String ?? ""))
.fontWeight(.medium)
.font(.system(size: 14))
.foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803))
......@@ -378,7 +379,7 @@ extension CouponBarcodeView {
// couponset = CouponSetItemModel(dictionary: coupon)
print("==================")
print(coupon["coupon"] as? String ?? "")
print(couponData["coupon"] as? String ?? "")
print("==================")
print("========constructBarcode()==========")
......
......@@ -4,16 +4,13 @@
//
// Created by Βασιλης Σκουρας on 13/1/22.
//
#if canImport(SwiftUI)
import SwiftUI
import Combine
import Foundation
import UIKit
class DataModel {
var data: Array<NSDictionary> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
......@@ -32,7 +29,9 @@ class DataModel {
// 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])
// temp.addEntries(from: c as! [AnyHashable : Any])
temp.setValue(c as! [AnyHashable : Any],forKey: "coupon_data")
self.data.append(temp as NSDictionary)
}
......@@ -45,14 +44,15 @@ class DataModel {
}
}
}
var getData: Array<NSDictionary> {
get { // getter
return data
return data.filter({
let couponData = $0["coupon_data"] as? [String: Any] ?? ["":""]
return couponData["status"] as? Int == 1
})
}
}
}
class ImageLoader: ObservableObject {
var didChange = PassthroughSubject<Data, Never>()
var data = Data() {
......@@ -60,7 +60,6 @@ class ImageLoader: ObservableObject {
didChange.send(data)
}
}
init(urlString:String) {
guard let url = URL(string: urlString) else { return }
let task = URLSession.shared.dataTask(with: url) { data, response, error in
......@@ -72,15 +71,12 @@ class ImageLoader: ObservableObject {
task.resume()
}
}
struct ImageView: View {
@ObservedObject var imageLoader:ImageLoader
@State var image:UIImage = UIImage()
init(withURL url:String) {
imageLoader = ImageLoader(urlString:url)
}
var body: some View {
Image(uiImage: image)
......@@ -91,7 +87,6 @@ struct ImageView: View {
}
}
}
struct VLine: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
......@@ -100,7 +95,6 @@ struct VLine: Shape {
}
}
}
extension CouponsView {
struct headerView: View {
var goBack: () -> ()
......@@ -118,6 +112,8 @@ extension CouponsView {
}
}
Text("Όλα τα κουπόνια μου")
.fontWeight(.medium)
.foregroundColor(Color(red: 0.20784313725490197, green: 0.3176470588235294, blue: 0.40784313725490196))
.frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center)
.offset( y: self.uiscreen.height * 0.02)
.font(.system(size: 15))
......@@ -129,9 +125,9 @@ extension CouponsView {
struct couponView: View {
var result: NSDictionary
var index: Int
var parentView: UIView
var uiscreen = UIScreen.main.bounds
static func localizedWithParameter(parameter: String) -> LocalizedStringKey {
return "\(parameter)"
}
......@@ -139,19 +135,27 @@ extension CouponsView {
static func convertDateFormat(inputDate: String) -> String {
let olDateFormatter = DateFormatter()
olDateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
let oldDate = olDateFormatter.date(from: inputDate)
let convertDateFormatter = DateFormatter()
convertDateFormatter.dateFormat = "dd/MM/yyyy"
return convertDateFormatter.string(from: oldDate!)
}
var body: some View {
let couponData = result["coupon_data"] as? [String: Any] ?? ["":""]
VStack(alignment: .leading) {
Button {
// GiftItem Action
let instanceOfMyApi = MyApi()
let couponBarcodeViewController = instanceOfMyApi.openCouponBarcode(parentView, coupon: result as! [String : Any])!
couponBarcodeViewController.view.tag = 7
// addChild(couponsViewController)
couponBarcodeViewController.view.frame = parentView.frame
parentView.addSubview(couponBarcodeViewController.view)
couponBarcodeViewController.didMove(toParent: UIHostingController(rootView: self))
} label: {
HStack(alignment: .center) {
ImageView(withURL: result["img_preview"] as! String)
.frame(maxWidth: self.uiscreen.width * 0.15)
......@@ -165,13 +169,19 @@ extension CouponsView {
.padding(.bottom, self.uiscreen.height * 0.0075)
Spacer()
VStack {
Text(CouponsView.couponView.localizedWithParameter(parameter: result["admin_name"] as? String ?? ""))
Text(CouponsView.couponView.localizedWithParameter(parameter: result["name"] as? String ?? ""))
.fontWeight(.medium)
.foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4))
.frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading)
.font(.system(size: 15))
Text(CouponsView.couponView.localizedWithParameter(parameter: result["discount"] as? String ?? ""))
Text(CouponsView.couponView.localizedWithParameter(parameter: couponData["discount"] as? String ?? ""))
.fontWeight(.bold)
.foregroundColor(Color(red: 0.22745098039215686, green: 0.3215686274509804, blue: 0.4))
.frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: self.uiscreen.height * 0.05, alignment: .leading)
.font(.system(size: 47))
Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + CouponsView.couponView.convertDateFormat(inputDate: result["expiration"] as? String ?? "")))
Text(CouponsView.couponView.localizedWithParameter(parameter: "Ισχύει εώς " + CouponsView.couponView.convertDateFormat(inputDate: couponData["expiration"] as? String ?? "")))
.fontWeight(.medium)
.foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764))
.frame(maxWidth: self.uiscreen.width * 0.35, maxHeight: .infinity, alignment: .leading)
.font(.system(size: 10))
}
......@@ -180,6 +190,8 @@ extension CouponsView {
.padding(.bottom, self.uiscreen.height * 0.03)
VStack {
Text(CouponsView.couponView.localizedWithParameter(parameter: result["short_description"] as! String))
.fontWeight(.medium)
.foregroundColor(Color(red: 0.3803921568627451, green: 0.44313725490196076, blue: 0.5058823529411764))
.frame(maxWidth: self.uiscreen.width * 0.22, maxHeight: self.uiscreen.height * 0.10)
.font(.system(size: 10))
}
......@@ -187,6 +199,7 @@ extension CouponsView {
Spacer()
}
}
}
.frame(width: self.uiscreen.width * 0.95, height: self.uiscreen.height * 0.13)
.background(
Image("coupons_container", bundle: Bundle(for: MyEmptyClass.self))
......@@ -198,10 +211,8 @@ extension CouponsView {
}
}
@available(iOS 13.0.0, *)
struct CouponsView: View {
var data:Array<NSDictionary> = DataModel().getData
var parentView: UIView
......@@ -219,11 +230,12 @@ struct CouponsView: View {
var body: some View {
VStack {
headerView(goBack: goBack)
ScrollView {
ScrollView(showsIndicators: false) {
VStack {
if (data.count) > 0 {
ForEach(Array(zip(data.indices, data)), id: \.0) { index, result in
couponView(result: result, index: index) }
couponView(result: result, index: index, parentView: parentView)
}
}
}
.padding(.top, self.uiscreen.height * 0.05)
......@@ -239,7 +251,6 @@ struct CouponsView: View {
}
}
#endif
@available(iOS 13.0.0, *)
struct Previews_CouponsView_Previews: PreviewProvider {
static var uiscreen = UIScreen.main.bounds
......@@ -253,6 +264,5 @@ struct Previews_CouponsView_Previews: PreviewProvider {
.frame(width: self.uiscreen.width * 0.8, height: self.uiscreen.height * 0.025, alignment: .center)
.offset( y: self.uiscreen.height * 0.07)
}
}
}
\ No newline at end of file
......