Untitled

 avatar
unknown
plain_text
2 years ago
12 kB
7
Indexable
//
//  AddressSelectionView.swift
//  Garageworks-iOS-Revamp
//
//  Created by mac on 16/11/22.
//

import SwiftUI

struct AddressSelectionView: View {
    @State var zoom : Float = 15.0
    @ObservedObject private var viewModel = AddressSelectionObserver()
    //    @StateObject private var areaListObserver: AreaListObserver = AreaListObserver()
    @State var currentLocation : Bool = false
    @State var address : (text : String,location : String) = ("","")
    @State var shouldShowAddressView = false
    @State private var sublocality = ""
    @State private var name = ""
    @State private var email = ""
    @State private var alternateMobile = ""
    @State var isServiceableArea: Bool = false
    @Environment(\.dismiss) var dismiss
    
    var body: some View {
        //        NavigationView{
        GeometryReader{ geometry in
            VStack{
                HStack(spacing:20){
                    Image("Vector 1")
                        .resizable()
                        .frame(width: 8, height: 15)
                        .padding(.leading,15)
                        .foregroundColor(Color.init(hex: Colors.color_gr2))
                    Text(Strings.label_Please_select_your_address)
                        .font(Font.custom(Fonts.product_regular, size: 16))
                        .foregroundColor(Color.init(hex: Colors.color_gr2))
                    Spacer()
                }
                .frame(width:geometry.size.width,alignment: .topLeading)
                .background(.white)
                .padding(.leading,25)
                .padding(.bottom,20)
                
                ZStack{
                    ZStack(alignment: .top){
                        GoogleMapsView(zoom : $zoom,location: $viewModel.location, showCurrentLocation: $currentLocation, placeAddress: $viewModel.placeAddress, placePincode: $viewModel.placePincode, placeCity: $viewModel.placeCity, placeArea: $viewModel.placeArea, currentLocation: $viewModel.location)
                        //                                                        .frame(width: geometry.size.width, height: geometry.size.height*0.7)
                            .onAppear{
                                viewModel.fetchAddress()
                            }
                            .background()
                            .onChange(of: viewModel.placePincode, perform: { _ in
                                print("Value Changed!")
                                viewModel.searchArea(pincode: viewModel.placePincode)
                            })
                        
                        VStack(alignment: .trailing){
                            NavigationLink(destination: PlaceView(location: $viewModel.location)) {
                                HStack{
                                    Image("search")
                                        .foregroundColor(.black)
                                    Text("Search Places")
                                        .foregroundColor(Color.init(hex: Colors.color_3f))
                                        .font(Font.custom(Fonts.product_medium, size: 12))
                                }
                                .padding(13)
                                .background(.white)
                                .clipShape(RoundedRectangle(cornerRadius: 20))
                                .padding(.leading,230)
                            }
                            //                            .navigationBarTitle("")
                            //                             .navigationBarBackButtonHidden(true)
                            //                             .navigationBarHidden(true)
                            Spacer()
                            Button{
                                currentLocation.toggle()
                                currentLocation = true
                                //                                print("GPS")
                            }label: {
                                Image("gps")
                                    .padding(10)
                                    .background(.orange)
                                    .frame(alignment: .trailing)
                            }.clipShape(Circle())
                            
                            VStack(spacing:1){
                                Button{
                                    if(zoom<10){
                                        zoom = 13
                                    }
                                    zoom = zoom + 1
                                    //                                    print("add ",zoom)
                                }label: {
                                    Image("add")
                                } .padding(10)
                                    .background(.white)
                                    .cornerRadius(20, corners: [.topLeft, .topRight])
                                
                                Button{
                                    //                                    print("minus",zoom)
                                    if(zoom>22){
                                        zoom = 21
                                    }
                                    if(zoom >= 10) {
                                        zoom = zoom - 1
                                    }
                                }label: {
                                    Image("minus")
                                } .padding(10)
                                    .background(.white)
                                    .cornerRadius(20, corners: [.bottomLeft, .bottomRight])
                            }
                            
                            .padding(.bottom,70)
                        }
                        .frame(width: geometry.size.width, height: geometry.size.height*0.7)
                        .padding(15)
                        
                    }
                    .frame(width: geometry.size.width, height: geometry.size.height*0.96,alignment: .top)
                    .cornerRadius(27, corners: [.topLeft, .topRight])
                    .background(.white)
                    //MARK : Address show
                    ZStack{
                        Spacer()
                        //                                .frame(width: geometry.size.width, height: geometry.size.height)
                        VStack(spacing:15){
                            Text("Your Address")
                            //                                .padding()
                                .font(Font.custom(Fonts.product_medium, size: 15))
                                .foregroundColor(Color.init(hex: Colors.color_gr2))
                                .frame(width: geometry.size.width, alignment: .topLeading)
                                .padding(.top,20)
                                .padding(.leading,27)
                            Text(viewModel.placeAddress)
                                .padding()
                                .foregroundColor(Color.init(hex: Colors.color_gr2))
                                .frame(width: geometry.size.width * 0.9, alignment: .topLeading)
                                .background(Color.init(hex: Colors.color_wh))
                                .cornerRadius(10)
                            //                                .padding(.bottom,10)
                            
                            NavigationLink(destination: GoToDashboard().navigationBarHidden(true)){
                                HStack{
                                    Text(Strings.label_next)
                                        .frame(width: geometry.size.width * 0.9, height: 50)
                                        .font(Font.custom(Fonts.product_medium, size: 15))
                                        .foregroundColor(Color.init(hex: Colors.color_wh))
                                }
                                .background(Color.init(hex: Colors.color_or))
                                .cornerRadius(10)
                                .disabled(!viewModel.isServicableArea)
                                .opacity(viewModel.isServicableArea ? 1 : 0.5)
                                //                                .padding(.bottom,5)
                            }
                            .onTapGesture {
                                print(UserDefaultsManager.fetchSelectedArea()?.city)
                                // save area and placearea in userDefaults
                                UserDefaultsManager.storeSelectedArea(value: viewModel.areas!)     //get_area api
                                UserDefaultsManager.storeGoogleMapArea(value: viewModel.placeArea)  // goglemap Area
                                UserDefaultsManager.storeGoogleMapEnterdName(value: name)
                                UserDefaultsManager.storeGoogleMapEnterdEmail(value: email)
                                UserDefaultsManager.storeGoogleMapEnterdAlterNo(value: alternateMobile)
                                UserDefaultsManager.storeGoogleMapEnterdStreet(value: sublocality)
                                UserDefaultsManager.storeIsAddressChanged(value: true)
                                print("******",UserDefaultsManager.fetchIsAddressChanged())
                                //                                            dismiss()
                            }
                            Text("")
                                .frame(width: geometry.size.width,height: 20)
                                .background(Color.init(hex: Colors.color_gr))
                                .padding(.bottom,6)
                        }
                        //                            .frame(width: geometry.size.width, height: geometry.size.height*0.8,alignment: .bottom)
                        .background(Color.init(hex: Colors.color_gr), ignoresSafeAreaEdges: .bottom)
                        .cornerRadius(27, corners: [.topLeft, .topRight])
                    }
                    .frame(width: geometry.size.width, height: geometry.size.height*0.99,alignment: .bottom)
                }
                .frame(width: geometry.size.width,height: geometry.size.height*0.99,alignment: .top)
            }
            .frame(width: geometry.size.width,height: geometry.size.height)
            .background(.white)
            
            .onAppear{
                if viewModel.isServicableArea{
                    isServiceableArea = false
                }
            }
            if(isServiceableArea){
                VStack{
                    
                }
                .frame(width:UIScreen.main.bounds.width ,height:UIScreen.main.bounds.height,alignment: .top)
                .background(Color.black.opacity(0.5))
                .disabled(true)
                NonServiceableAreaAlertView(isServiceableArea: $isServiceableArea)
            }
        }
        .ignoresSafeArea(edges: .bottom)
        .navigationBarTitle("")
        .navigationBarBackButtonHidden(true)
        .navigationBarHidden(true)
        //        }
    }
}

struct AddressSelectionView_Previews: PreviewProvider {
    static var previews: some View {
        AddressSelectionView()
    }
}

struct GoToDashboard: View {
    var body: some View {
        //        MARK:  new user and Resigtered user dashboard values(area,city) update condition.
        if UserDefaultsManager.fetchIsFrom() == true && UserDefaultsManager.fetchSelectedMake()?.make_name !=  "" {
            MainHomeView()
        }
        else{
            MakeView()
        }
    }
}
Editor is loading...