Skip to content

Commit

Permalink
abstacted diffent views to make code readable
Browse files Browse the repository at this point in the history
  • Loading branch information
amanbind007 committed Feb 23, 2024
1 parent 77130bb commit e8c5590
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 271 deletions.
24 changes: 24 additions & 0 deletions Weather Varta.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

/* Begin PBXBuildFile section */
5C0536CF2B8269FA000E05B5 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C0536CE2B8269FA000E05B5 /* NetworkManager.swift */; };
5C6CFFDD2B890E5400425824 /* WeatherCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6CFFDC2B890E5400425824 /* WeatherCard.swift */; };
5C6CFFDF2B890EE800425824 /* SunriseSunsetCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6CFFDE2B890EE800425824 /* SunriseSunsetCard.swift */; };
5C6CFFE12B890F2A00425824 /* CloudinessVisibilityCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6CFFE02B890F2A00425824 /* CloudinessVisibilityCard.swift */; };
5C6CFFE32B890F7D00425824 /* HumidityPressureCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6CFFE22B890F7D00425824 /* HumidityPressureCard.swift */; };
5C6CFFE52B890FC700425824 /* WindSpeedAndDirectionCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6CFFE42B890FC700425824 /* WindSpeedAndDirectionCard.swift */; };
5C6CFFE72B89101F00425824 /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C6CFFE62B89101F00425824 /* SearchBarView.swift */; };
5C9FFE752B84FEF5000B5B4D /* WeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C9FFE742B84FEF5000B5B4D /* WeatherModel.swift */; };
5CA592782B83C247003431E4 /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CA592772B83C247003431E4 /* LocationManager.swift */; };
5CC47D512B77D82000D9BD3D /* Weather_VartaApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CC47D502B77D82000D9BD3D /* Weather_VartaApp.swift */; };
Expand All @@ -19,6 +25,12 @@

/* Begin PBXFileReference section */
5C0536CE2B8269FA000E05B5 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
5C6CFFDC2B890E5400425824 /* WeatherCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherCard.swift; sourceTree = "<group>"; };
5C6CFFDE2B890EE800425824 /* SunriseSunsetCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SunriseSunsetCard.swift; sourceTree = "<group>"; };
5C6CFFE02B890F2A00425824 /* CloudinessVisibilityCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloudinessVisibilityCard.swift; sourceTree = "<group>"; };
5C6CFFE22B890F7D00425824 /* HumidityPressureCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HumidityPressureCard.swift; sourceTree = "<group>"; };
5C6CFFE42B890FC700425824 /* WindSpeedAndDirectionCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindSpeedAndDirectionCard.swift; sourceTree = "<group>"; };
5C6CFFE62B89101F00425824 /* SearchBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBarView.swift; sourceTree = "<group>"; };
5C9FFE742B84FEF5000B5B4D /* WeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherModel.swift; sourceTree = "<group>"; };
5CA592772B83C247003431E4 /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; };
5CC47D4D2B77D82000D9BD3D /* Weather Varta.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Weather Varta.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -99,6 +111,12 @@
isa = PBXGroup;
children = (
5CC47D522B77D82000D9BD3D /* WeatherView.swift */,
5C6CFFE62B89101F00425824 /* SearchBarView.swift */,
5C6CFFE42B890FC700425824 /* WindSpeedAndDirectionCard.swift */,
5C6CFFE22B890F7D00425824 /* HumidityPressureCard.swift */,
5C6CFFE02B890F2A00425824 /* CloudinessVisibilityCard.swift */,
5C6CFFDE2B890EE800425824 /* SunriseSunsetCard.swift */,
5C6CFFDC2B890E5400425824 /* WeatherCard.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -189,12 +207,18 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5C6CFFDD2B890E5400425824 /* WeatherCard.swift in Sources */,
5C0536CF2B8269FA000E05B5 /* NetworkManager.swift in Sources */,
5CC47D532B77D82000D9BD3D /* WeatherView.swift in Sources */,
5CA592782B83C247003431E4 /* LocationManager.swift in Sources */,
5C6CFFE72B89101F00425824 /* SearchBarView.swift in Sources */,
5CC47D622B77DF8600D9BD3D /* WeatherResult.swift in Sources */,
5C9FFE752B84FEF5000B5B4D /* WeatherModel.swift in Sources */,
5CC47D512B77D82000D9BD3D /* Weather_VartaApp.swift in Sources */,
5C6CFFE52B890FC700425824 /* WindSpeedAndDirectionCard.swift in Sources */,
5C6CFFE32B890F7D00425824 /* HumidityPressureCard.swift in Sources */,
5C6CFFE12B890F2A00425824 /* CloudinessVisibilityCard.swift in Sources */,
5C6CFFDF2B890EE800425824 /* SunriseSunsetCard.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
61 changes: 61 additions & 0 deletions Weather Varta/Views/CloudinessVisibilityCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// CloudinessVisibilityCard.swift
// Weather Varta
//
// Created by Aman Bind on 23/02/24.
//

import SwiftUI

struct CloudinessVisibilityCard: View {
var body: some View {
VStack(alignment: .leading) {
HStack {
Image(systemName: "eye")
.resizable()
.scaledToFit()
.frame(width: 20)

VStack(alignment: .leading) {
HStack {
Text("6.0")
.font(.title2)
Text("km")
.font(.footnote)
.offset(x: -5, y: 2)
}

Text("VISIBILITY")
.font(.caption2)
}
}.offset(x: 25)

Divider()
HStack {
Image(systemName: "cloud")
.resizable()
.scaledToFit()
.frame(width: 20)
VStack(alignment: .leading) {
HStack {
Text("50")
.font(.title2)
Text("%")
.font(.footnote)
.offset(x: -5, y: 2)
}
Text("CLOUDINESS")
.font(.caption2)
}
}
.offset(x: 25)
}
.frame(width: 173, height: 140)
.background(Color("background_card"))
.clipShape(RoundedRectangle(cornerRadius: 20))
}
}

#Preview {
CloudinessVisibilityCard()
}
61 changes: 61 additions & 0 deletions Weather Varta/Views/HumidityPressureCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// HumidityPressureCard.swift
// Weather Varta
//
// Created by Aman Bind on 23/02/24.
//

import SwiftUI

struct HumidityPressureCard: View {
var body: some View {
VStack(alignment: .leading) {
HStack {
Image(systemName: "humidity")
.resizable()
.scaledToFit()
.frame(width: 20)

VStack(alignment: .leading) {
HStack {
Text("50")
.font(.title2)
Text("%")
.font(.footnote)
.offset(x: -5, y: 2)
}

Text("HUMIDITY")
.font(.caption2)
}
}.offset(x: 25)

Divider()
HStack {
Image(systemName: "gauge")
.resizable()
.scaledToFit()
.frame(width: 20)
VStack(alignment: .leading) {
HStack {
Text("1,019")
.font(.title2)
Text("hPa")
.font(.footnote)
.offset(x: -5, y: 2)
}
Text("PRESSURE")
.font(.caption2)
}
}
.offset(x: 25)
}
.frame(width: 173, height: 140)
.background(Color("background_card"))
.clipShape(RoundedRectangle(cornerRadius: 20))
}
}

#Preview {
HumidityPressureCard()
}
54 changes: 54 additions & 0 deletions Weather Varta/Views/SearchBarView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// SearchBarView.swift
// Weather Varta
//
// Created by Aman Bind on 23/02/24.
//

import SwiftUI

struct SearchBarView: View {

@Binding var searchCity: String
@Binding var networkManager: NetworkManager
@Binding var locationManager: LocationDataManager

var body: some View {
HStack {
RoundedRectangle(cornerRadius: 25)
.frame(width: 320, height: 40)
.foregroundColor(Color.backgroundCard)
.overlay {
HStack {
Image(systemName: "map.fill")
.padding()
TextField("Enter your City", text: $searchCity)
.textFieldStyle(.plain)
.font(.title3)
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
.submitLabel(.search)
.onSubmit {
networkManager.fetchWeatherByName(city: searchCity)
}
}
}
.padding(1)

Button(action: {
locationManager.requestLocation()
networkManager.fetchWeatherByLocation(coordinate: locationManager.location!)
}, label: {
Image(systemName: "location.circle.fill")
.resizable()
.scaledToFit()
.foregroundStyle(.blue)

})
}
}
}

#Preview {
SearchBarView(searchCity: .constant(""), networkManager: .constant(NetworkManager()), locationManager: .constant(LocationDataManager()))
}
60 changes: 60 additions & 0 deletions Weather Varta/Views/SunriseSunsetCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// SunriseSunsetCard.swift
// Weather Varta
//
// Created by Aman Bind on 23/02/24.
//

import SwiftUI

struct SunriseSunsetCard: View {
var body: some View {
HStack {
VStack {
Image(systemName: "sunrise.fill")
.resizable()
.scaledToFit()
.frame(width: 25)

HStack {
Text("5:30")
.font(.title3)
.offset(y: -5)
Text("PM")
.font(.caption2)
.offset(x: -5, y: -5)
}

Text("SUNRISE")
.font(.caption2)
}

Divider()

VStack {
Image(systemName: "sunset.fill")
.resizable()
.scaledToFit()
.frame(width: 25)

HStack {
Text("5:30")
.font(.title3)
.offset(y: -5)
Text("PM")
.font(.caption2)
.offset(x: -5, y: -5)
}
Text("SUNSET")
.font(.caption2)
}
}
.frame(width: 173, height: 140)
.background(Color("background_card"))
.clipShape(RoundedRectangle(cornerRadius: 20))
}
}

#Preview {
SunriseSunsetCard()
}
75 changes: 75 additions & 0 deletions Weather Varta/Views/WeatherCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// WeatherCard.swift
// Weather Varta
//
// Created by Aman Bind on 23/02/24.
//

import SwiftUI

struct WeatherCard: View {
var body: some View {
VStack {
HStack(alignment: .top, spacing: 20, content: {
Image(systemName: "sun.max.trianglebadge.exclamationmark")
.symbolRenderingMode(.monochrome)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 80, height: 80)
.offset(y: 10)

Text("25")
.font(.system(size: 80))
.offset(x: 15)

Text("")
.offset(y: 15)

})
.offset(y: 20)

Text("Clear")
.offset(y: 10)

HStack {
Spacer()
VStack {
HStack {
Text("MAX:")
Text("25℃")
}

HStack {
Text("MIN:")
Text("25℃")
}
}
.offset(y: 5)

Spacer()
HStack {
Image(systemName: "thermometer.medium")
.resizable()
.scaledToFit()
.frame(width: 25)

VStack {
Text("25℃")
.font(.largeTitle)
.offset(y: 5)
Text("FEELS LIKE")
.font(.caption2)
}
}
Spacer()
}
}
.frame(width: 356, height: 250)
.background(Color("background_card_big"))
.clipShape(RoundedRectangle(cornerRadius: 20))
}
}

#Preview {
WeatherCard()
}
Loading

0 comments on commit e8c5590

Please sign in to comment.