Untitled
unknown
swift
3 years ago
8.9 kB
12
Indexable
//
// MyVehiclesView.swift
// Garageworks-iOS-Revamp
//
// Created by DigitalFlake Kapil Dongre on 15/01/23.
//
import SwiftUI
struct MyVehiclesView: View {
@Environment(\.presentationMode) var presentationMode
@StateObject var deleteVehicle = DeleteVehicleObserver()
@StateObject var getVehicleDetail = GetVehicleDetailSingleObserver()
@State var callmakeview:Int? = nil
@State var isShown = false
@StateObject private var customerObserver: CustomerDetailsObserver = CustomerDetailsObserver()
@StateObject var updateCustomerVehicleObserver: UpdateCustVehicleObserver = UpdateCustVehicleObserver(customer_id: "26", vehicle_id: UserDefaultsManager.fetchCustomerVehicle()?.vehicle_id ?? "", model: UserDefaultsManager.fetchSelectedModel()?.model_name ?? "", make: UserDefaultsManager.fetchSelectedMake()?.make_id ?? "", vehicle_category: UserDefaultsManager.fetchCustomerVehicle()?.vehicle_category ?? "", reg_no: UserDefaultsManager.fetchCustomerVehicle()?.regno ?? "", yom: UserDefaultsManager.fetchCustomerVehicle()?.yom ?? "", km_reading: UserDefaultsManager.fetchCustomerVehicle()?.km_reading ?? "")
var body: some View {
GeometryReader { geometry in
VStack(spacing:0){
// NavigationLink(destination:SettingsView().navigationBarHidden(true)){
HStack(spacing:20){
Image("Vector 1")
.padding(.leading,10)
.onTapGesture {
self.presentationMode.wrappedValue.dismiss()
}
Text("My Vehicles")
.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)
// }
VStack(alignment: .leading) {
ScrollView{
LazyVStack{
ForEach(customerObserver.customer_vehicle ?? [], id:\.self){ value in
VStack(spacing:20){
HStack(alignment:.top){
AsyncImage(url: URL(string: value.vehicle_category_icon ?? ""),
content: { image in
image
.resizable()
.aspectRatio(contentMode: .fit)
// .frame(width:geometry.size.width * 0.3, height: geometry.size.height * 0.5,alignment: .topLeading)
// .cornerRadius(10)
},
placeholder: {
ProgressView()
// .padding(.leading,20)
})
.frame(width: geometry.size.width * 0.16, height: 50)
Text(value.make_name ?? "")
.font(Font.custom(Fonts.product_regular, size: 16))
.foregroundColor(Color.init(hex: Colors.color_gr2))
Text(value.model_name ?? "")
.font(Font.custom(Fonts.product_regular, size: 16))
.foregroundColor(Color.init(hex: Colors.color_gr2))
// .tag(value.id)
Spacer()
Image("editImage")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 20, height: 23)
.onTapGesture {
isShown = true
self.getVehicleDetail.getVehicleDetailSingle(customer_id: "\(UserDefaultsManager.fetchCustomer()?.customer_id! ?? "")", vehicle_id: "\(value.vehicle_id ?? "")")
}
Image("trash")
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 20, height: 23)
.onTapGesture {
print("delete vehicle of ID: \(value.vehicle_id ?? "") of customerID: \(UserDefaultsManager.fetchCustomer()?.customer_id! ?? "")")
DispatchQueue.main.async {
deleteVehicle.deleteVehicle(customer_id: "\(UserDefaultsManager.fetchCustomer()?.customer_id! ?? "")", vehicle_id: "\(value.vehicle_id ?? "")")
}
}
// .onAppear{
// customerObserver.CustomerDetailsObserver(cust_id: UserDefaultsManager.fetchCustomer()?.customer_id ?? "")
// }
}
.padding(.bottom,5)
.padding(.top,5)
}
.frame(width:geometry.size.width*0.8,height: geometry.size.height * 0.13,alignment: .leading)
.padding()
.background(.white)
.cornerRadius(10)
}
// .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])
}
.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)
.onTapGesture {
self.callmakeview = 1
}
}
}
.frame(width:geometry.size.width, height:geometry.size.height * 0.1, alignment: .bottom)
.background(Color.init(hex: Colors.color_gr))
}.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)
}
}
}
}
struct MyVehiclesView_Previews: PreviewProvider {
static var previews: some View {
MyVehiclesView()
}
}
Editor is loading...