Untitled
unknown
swift
2 years ago
16 kB
5
Indexable
// // MyVehiclesView.swift // Garageworks-iOS-Revamp // // Created by DigitalFlake Kapil Dongre on 15/01/23. // import SwiftUI import Combine struct MyVehiclesView: View { @Environment(\.presentationMode) var presentationMode @Environment(\.dismiss) private var dismiss @StateObject var deleteVehicle = DeleteVehicleObserver() @StateObject var getVehicleDetail = GetVehicleDetailSingleObserver() @State var callmakeview:Int? = nil @State var selectedVehicleDetails: Int? = nil @State var isShown = false @State private var registrationNo: String = "" @State var editImg = false @State var isDeleteVehicleAlertShown = false // @StateObject private var getCustDetails: CustomerDetailsObserver = CustomerDetailsObserver() var body: some View { NavigationView{ GeometryReader { geometry in VStack(spacing:0){ NavigationLink(destination:SettingsView().navigationBarHidden(true)){ HStack(spacing:20){ Image("Vector 1") .resizable() .frame(width: 8, height: 15) .padding(.leading,15) .foregroundColor(Color.init(hex: Colors.color_gr2)) .onTapGesture { self.presentationMode.wrappedValue.dismiss() } Text("My Vehicles") .bold() .font(Font.custom(Fonts.product_regular, size: 16)) .foregroundColor(Color.init(hex: Colors.color_gr2)) Spacer() } .frame(width:geometry.size.width,height:geometry.size.height * 0.10,alignment: .center) .background(.white) // .onTapGesture { // dismiss() // } } VStack(alignment: .leading) { ScrollView{ if !UserDefaultsManager.fetchCustomerVehicleList().isEmpty{ LazyVStack(spacing:20){ ForEach(UserDefaultsManager.fetchCustomerVehicleList() ?? [], id:\.self){ value in NavigationLink(destination: MainHomeView().navigationBarHidden(true), tag: 1, selection: $selectedVehicleDetails){ VStack(alignment: .leading,spacing:10){ HStack{ AsyncImage(url: URL(string: value.vehicle_category_icon ?? ""), content: { image in image .resizable() .aspectRatio(contentMode: .fit) }, placeholder: { ProgressView() }) .frame(width: geometry.size.width * 0.16, height: 50,alignment: .topLeading) // .padding(.top,5) HStack(alignment:.top){ Text("\(value.make_name ?? "") \(value.model_name ?? "")") .font(Font.custom(Fonts.product_regular, size: 16)) .foregroundColor(Color.init(hex: Colors.color_gr2)) .padding(.top,5) .multilineTextAlignment(.leading) } .frame(width:geometry.size.width*0.45,height:50, alignment:.topLeading) HStack(alignment:.top,spacing:15){ if value.is_vehicle_incomplete == 1 { Image("editImage") .renderingMode(.original) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 20, height: 23) .onTapGesture { // if value.is_vehicle_incomplete == 0 { isShown = true // } self.getVehicleDetail.getVehicleDetailSingle(customer_id: "\(UserDefaultsManager.fetchCustomer()?.customer_id! ?? "")", vehicle_id: "\(value.vehicle_id ?? "")") //To pass the year data on button click } } Image("trash") .renderingMode(.original) .resizable() .aspectRatio(contentMode: .fit) .frame(width: 20, height: 23) .onTapGesture { // if value.is_vehicle_incomplete == 0 { isDeleteVehicleAlertShown = true // } self.getVehicleDetail.getVehicleDetailSingle(customer_id: "\(UserDefaultsManager.fetchCustomer()?.customer_id! ?? "")", vehicle_id: "\(value.vehicle_id ?? "")") UserDefaultsManager.storeSelectedCustomerVehicle(value: value) print("tapped vehicleId",UserDefaultsManager.fetchSelectedCustomerVehicle()?.vehicle_id ?? "") //To pass the year data on button click } } .frame(width:geometry.size.width*0.15, alignment:.trailing) .padding(.bottom,10) } HStack(spacing:50){ VStack(alignment: .leading, spacing: 7){ Text("Registration No") .font(.system(size: 12)) .foregroundColor(.gray) if value.is_vehicle_incomplete == 1{ Text("-") .font(.system(size: 14)) .foregroundColor(.black) } else{ Text(value.regno) .font(.system(size: 14)) .foregroundColor(.black) } } // Spacer() VStack(alignment: .leading, spacing: 7){ Text("Year of Making") .font(.system(size: 12)) .foregroundColor(.gray) if value.is_vehicle_incomplete == 1{ Text("-") .font(.system(size: 14)) .foregroundColor(.black) }else{ Text(value.yom) .font(.system(size: 14)) .foregroundColor(.black) } } } .frame(width:geometry.size.width*0.8, alignment: .leading) } } .frame(width:geometry.size.width*0.8, height: geometry.size.height * 0.13, alignment: .leading) .padding() .background(.white) .cornerRadius(10) .onTapGesture { UserDefaultsManager.storeSelectedCustomerVehicle(value: value) print("tapped vehicleId",UserDefaultsManager.fetchSelectedCustomerVehicle()?.vehicle_id ?? "") self.selectedVehicleDetails = 1 } } // .frame(width:geometry.size.width, height: geometry.size.height * 0.2) }.frame(width:geometry.size.width) .background(Color.init(hex: Colors.color_gr)) .cornerRadius(30, corners: [.topLeft, .topRight]) } else{ Text("No vehicles registered with us") .frame(width:geometry.size.width * 0.9, height:geometry.size.height * 0.8, alignment:.center) .foregroundColor(.black) // .foregroundColor(Color.init(hex: Colors.color_bk)) .font(Font.custom(Fonts.product_medium, size: 16)) } } .frame(width: geometry.size.width, height: geometry.size.height * 0.75,alignment: .top) .padding() VStack{ NavigationLink(destination: MakeView().navigationBarHidden(true), tag:1 ,selection: $callmakeview){ Text(Strings.input_add_new_vehicle) .frame(width:geometry.size.width * 0.9, height: 50) .foregroundColor(Color.init(hex: Colors.color_wh)) .background(Color.init(hex: Colors.color_or)) .font(Font.custom(Fonts.product_medium, size: 15)) .cornerRadius(10) .padding(.leading, 15) .onTapGesture { self.callmakeview = 1 } } } .frame(width:geometry.size.width, height: geometry.size.height * 0.1, alignment: .bottom) .background(Color.init(hex: Colors.color_gr)) .padding(.leading,9) }.frame(width:geometry.size.width, height:geometry.size.height * 0.95,alignment: .top) .background(Color.init(hex: Colors.color_gr)) .cornerRadius(30, corners: [.topLeft, .topRight]) } .background(Color.init(hex: Colors.color_wh)) if(isShown){ VStack{ } .frame(width:UIScreen.main.bounds.width ,height:UIScreen.main.bounds.height,alignment: .top) .background(Color.black.opacity(0.5)) .disabled(true) EditVehicleAlertView(isShown: $isShown, registrationNo: $registrationNo).environmentObject(getVehicleDetail) } if(isDeleteVehicleAlertShown){ VStack{ } .frame(width:UIScreen.main.bounds.width ,height:UIScreen.main.bounds.height,alignment: .top) .background(Color.black.opacity(0.5)) .disabled(true) DeleteVehicleAlertView(isDeleteAlertShown: $isDeleteVehicleAlertShown) } } } } } struct MyVehiclesView_Previews: PreviewProvider { static var previews: some View { MyVehiclesView() } }
Editor is loading...