diff --git a/ios-app/app.xcodeproj/project.pbxproj b/ios-app/app.xcodeproj/project.pbxproj index 7a9e5aff..bce4d548 100644 --- a/ios-app/app.xcodeproj/project.pbxproj +++ b/ios-app/app.xcodeproj/project.pbxproj @@ -53,6 +53,15 @@ 9EEAF94E23C1F3DC000AAB49 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEAF94C23C1F3DC000AAB49 /* SearchBar.swift */; }; 9EEAF95023C1F474000AAB49 /* AccountTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEAF94F23C1F474000AAB49 /* AccountTab.swift */; }; 9EFDEF9A23C215A9006EB4B4 /* AlertFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EFDEF9923C215A9006EB4B4 /* AlertFactory.swift */; }; + BC04DC0B23CB3BE7006D0767 /* FavoriteSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC04DC0A23CB3BE7006D0767 /* FavoriteSearch.swift */; }; + BC04DC0D23CB4104006D0767 /* FavoriteSearchResultRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC04DC0C23CB4104006D0767 /* FavoriteSearchResultRow.swift */; }; + BC1A86B723CBB755005DE4F5 /* LocationHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC1A86B623CBB755005DE4F5 /* LocationHeaderView.swift */; }; + BC241EC323CB8B0600F4C0CC /* FavoriteCity.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC241EC223CB8B0600F4C0CC /* FavoriteCity.swift */; }; + BC26444123CB835300330645 /* WeatherConditionExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC26444023CB835300330645 /* WeatherConditionExtension.swift */; }; + BC9795FE23CCC4AD00546A6E /* Mowesta.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = BC9795FC23CCC4AD00546A6E /* Mowesta.xcdatamodeld */; }; + BCEE929023CCEDD80029CC73 /* LocationDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCEE928F23CCEDD80029CC73 /* LocationDetailView.swift */; }; + BCEE929223CCF7B60029CC73 /* LocationForecastView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCEE929123CCF7B60029CC73 /* LocationForecastView.swift */; }; + BCFAD1F923CB4BEC0032455B /* FavoriteSearchResults.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFAD1F823CB4BEC0032455B /* FavoriteSearchResults.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -125,6 +134,15 @@ 9EEAF94C23C1F3DC000AAB49 /* SearchBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; 9EEAF94F23C1F474000AAB49 /* AccountTab.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountTab.swift; sourceTree = ""; }; 9EFDEF9923C215A9006EB4B4 /* AlertFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertFactory.swift; sourceTree = ""; }; + BC04DC0A23CB3BE7006D0767 /* FavoriteSearch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteSearch.swift; sourceTree = ""; }; + BC04DC0C23CB4104006D0767 /* FavoriteSearchResultRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteSearchResultRow.swift; sourceTree = ""; }; + BC1A86B623CBB755005DE4F5 /* LocationHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationHeaderView.swift; sourceTree = ""; }; + BC241EC223CB8B0600F4C0CC /* FavoriteCity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteCity.swift; sourceTree = ""; }; + BC26444023CB835300330645 /* WeatherConditionExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherConditionExtension.swift; sourceTree = ""; }; + BC9795FD23CCC4AD00546A6E /* Mowesta.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Mowesta.xcdatamodel; sourceTree = ""; }; + BCEE928F23CCEDD80029CC73 /* LocationDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationDetailView.swift; sourceTree = ""; }; + BCEE929123CCF7B60029CC73 /* LocationForecastView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationForecastView.swift; sourceTree = ""; }; + BCFAD1F823CB4BEC0032455B /* FavoriteSearchResults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteSearchResults.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -246,6 +264,7 @@ children = ( 9E0C988723A78341001EA11E /* CurrentWeatherData.swift */, 9E8C8C4D23C1FB0500FF8E6D /* LocationExtensions.swift */, + BC26444023CB835300330645 /* WeatherConditionExtension.swift */, 9EE4771923C3C77F003BA29C /* FavoriteLocations.swift */, 9E81DC9123A7DECE00568CF4 /* UserData.swift */, ); @@ -257,6 +276,9 @@ children = ( 9E3CA3F023A5278E003873E8 /* FavoriteRow.swift */, 9E3CA3F323A52ABF003873E8 /* FavoriteList.swift */, + BC04DC0A23CB3BE7006D0767 /* FavoriteSearch.swift */, + BC04DC0C23CB4104006D0767 /* FavoriteSearchResultRow.swift */, + BCFAD1F823CB4BEC0032455B /* FavoriteSearchResults.swift */, ); path = FavoriteView; sourceTree = ""; @@ -264,6 +286,7 @@ 9E3CA40223A53A2E003873E8 /* Resources */ = { isa = PBXGroup; children = ( + BC9795FC23CCC4AD00546A6E /* Mowesta.xcdatamodeld */, ); path = Resources; sourceTree = ""; @@ -281,11 +304,15 @@ 9E78A74423C916B000D8A27D /* LocationView */ = { isa = PBXGroup; children = ( + BC241EC223CB8B0600F4C0CC /* FavoriteCity.swift */, 9E78A74523C916CF00D8A27D /* LocationDetail.swift */, 9E78A74723C918C600D8A27D /* CityDetail.swift */, 9E78A74923C91B3D00D8A27D /* StateDetail.swift */, 9E78A74B23C91B4A00D8A27D /* CountryDetail.swift */, 9E3CA3EE23A51DFC003873E8 /* DegreeNumberCircle.swift */, + BC1A86B623CBB755005DE4F5 /* LocationHeaderView.swift */, + BCEE928F23CCEDD80029CC73 /* LocationDetailView.swift */, + BCEE929123CCF7B60029CC73 /* LocationForecastView.swift */, ); path = LocationView; sourceTree = ""; @@ -478,7 +505,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + BC1A86B723CBB755005DE4F5 /* LocationHeaderView.swift in Sources */, 9EA0D16323C9118C0068F739 /* LocationMock.swift in Sources */, + BC9795FE23CCC4AD00546A6E /* Mowesta.xcdatamodeld in Sources */, + BCEE929023CCEDD80029CC73 /* LocationDetailView.swift in Sources */, 9E6D640D23CC798F0002CBCF /* WeatherStationRow.swift in Sources */, 9EE4770C23C36363003BA29C /* SearchResults.swift in Sources */, 2C7846D52372F44300766694 /* AppDelegate.swift in Sources */, @@ -486,10 +516,13 @@ 9E3CA3EF23A51DFC003873E8 /* DegreeNumberCircle.swift in Sources */, 9E6D640B23CC77800002CBCF /* AboutMe.swift in Sources */, 9E81DC9223A7DECE00568CF4 /* UserData.swift in Sources */, + BC04DC0B23CB3BE7006D0767 /* FavoriteSearch.swift in Sources */, 9EEAF94D23C1F3DC000AAB49 /* SearchTab.swift in Sources */, + BC241EC323CB8B0600F4C0CC /* FavoriteCity.swift in Sources */, 2C7846D72372F44300766694 /* SceneDelegate.swift in Sources */, 9EE4771423C37158003BA29C /* SearchResultRow.swift in Sources */, 9E8C8C4E23C1FB0500FF8E6D /* LocationExtensions.swift in Sources */, + BCFAD1F923CB4BEC0032455B /* FavoriteSearchResults.swift in Sources */, 9EE4771223C36E9E003BA29C /* AlamofireUtils.swift in Sources */, 9EEAF95023C1F474000AAB49 /* AccountTab.swift in Sources */, 9E78A74C23C91B4A00D8A27D /* CountryDetail.swift in Sources */, @@ -500,6 +533,7 @@ 9EE4770E23C363F6003BA29C /* ViewExtensions.swift in Sources */, 9E78A74A23C91B3D00D8A27D /* StateDetail.swift in Sources */, 9E8334A423AD003E00B191A3 /* Login.swift in Sources */, + BCEE929223CCF7B60029CC73 /* LocationForecastView.swift in Sources */, 9EE4771A23C3C77F003BA29C /* FavoriteLocations.swift in Sources */, 2C7846D92372F44300766694 /* ContentView.swift in Sources */, 9E3CA3F423A52ABF003873E8 /* FavoriteList.swift in Sources */, @@ -508,10 +542,12 @@ 9E3CA3F123A5278E003873E8 /* FavoriteRow.swift in Sources */, 9E78A74823C918C600D8A27D /* CityDetail.swift in Sources */, 9EA0D16523C9133F0068F739 /* UserMock.swift in Sources */, + BC04DC0D23CB4104006D0767 /* FavoriteSearchResultRow.swift in Sources */, 9E78A74623C916CF00D8A27D /* LocationDetail.swift in Sources */, 9E0C988823A78341001EA11E /* CurrentWeatherData.swift in Sources */, 9EBA34EB23CD1A260013E2AB /* Card.swift in Sources */, 9E8334A123ACFCD300B191A3 /* LoadingView.swift in Sources */, + BC26444123CB835300330645 /* WeatherConditionExtension.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -783,6 +819,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 2KS4Z77UGE; INFOPLIST_FILE = appUITests/Info.plist; @@ -804,6 +841,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 2KS4Z77UGE; INFOPLIST_FILE = appUITests/Info.plist; @@ -901,6 +939,19 @@ productName = Socket; }; /* End XCSwiftPackageProductDependency section */ + +/* Begin XCVersionGroup section */ + BC9795FC23CCC4AD00546A6E /* Mowesta.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + BC9795FD23CCC4AD00546A6E /* Mowesta.xcdatamodel */, + ); + currentVersion = BC9795FD23CCC4AD00546A6E /* Mowesta.xcdatamodel */; + path = Mowesta.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ }; rootObject = 2C7846C92372F44300766694 /* Project object */; } diff --git a/ios-app/app/Data/FavoriteLocations.swift b/ios-app/app/Data/FavoriteLocations.swift index 9b60ad6a..9e453e33 100644 --- a/ios-app/app/Data/FavoriteLocations.swift +++ b/ios-app/app/Data/FavoriteLocations.swift @@ -8,36 +8,47 @@ import Foundation import MowestaApi +import SwiftUI class FavoriteLocations : ObservableObject { + //The PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model. + // var objectWillChange = PassthroughSubject() - @Published var locations = [LocationHierarchy] () - @Published var currentWeathers = [LocationHierarchy : CurrentWeatherData]() + @Published var locations = [LocationHierarchy]() { + willSet { + objectWillChange.send() + } + } + @Published var currentWeathers = [Int64 : CurrentWeatherData]() + @Published var weatherForecasts = [Int64 : WeatherForecast]() init(locations: [LocationHierarchy]) { self.locations = locations - for location in locations { - currentWeathers[location] = CurrentWeatherData(temperature: 10, icon: "sun.max") - } +// for location in locations { +// currentWeathers[location._id!] = CurrentWeatherData(temperature: 10, icon: "sun.max") +// weatherForecasts[location._id!] = forecast +// } } + public func toggleLocation(_ location: LocationHierarchy) { - guard let pos = locations.firstIndex(where: {l in - location == l - }) else { + guard let pos = locations.firstIndex(where: {$0._id == location._id}) else { locations.append(location) + WeatherAPI.getForecast(_id: location._id!, completion: self.addWeatherForecast) return } locations.remove(at: pos) } - func pull() { - + func addWeatherForecast(weatherforecast: WeatherForecast?, error: Error?) { + if (error != nil) { + //maybe handle + } + if (weatherforecast != nil) { + NSLog("Forecast with id: \(String(describing: weatherforecast?._id)) loaded") + weatherForecasts[(weatherforecast?._id)!] = weatherforecast + } } - - func push() { - - } - + } diff --git a/ios-app/app/Data/LocationExtensions.swift b/ios-app/app/Data/LocationExtensions.swift index fd06cddf..f6dd8ee8 100644 --- a/ios-app/app/Data/LocationExtensions.swift +++ b/ios-app/app/Data/LocationExtensions.swift @@ -32,6 +32,16 @@ extension City : Hashable, LocationName { hasher.combine(coordinate.longitude) hasher.combine(coordinate.latitude) } + + public func getMillisecondsFromGMT() -> Int { + NSLog("The timezone: \(self.timezone)") + switch self.timezone { + case "+1": + return 3600 * 1000 + default: + return 0 + } + } } extension State : Hashable, LocationName { @@ -60,11 +70,22 @@ extension Country : Hashable, LocationName { } } -extension LocationHierarchy : Hashable, LocationName { +extension LocationHierarchy : Hashable, LocationName, Equatable{ public static func == (lhs: LocationHierarchy, rhs: LocationHierarchy) -> Bool { return lhs._id == rhs._id } + public static func == (lhs: LocationHierarchy, rhs: Int64) -> Bool { + return lhs._id == rhs + } + + func isEqual(object: AnyObject?) -> Bool { + if let rhs = object as? LocationHierarchy { + return self == rhs + } + return false + } + public func hash(into hasher: inout Hasher) { hasher.combine(names) hasher.combine(coordinate.longitude) diff --git a/ios-app/app/Data/WeatherConditionExtension.swift b/ios-app/app/Data/WeatherConditionExtension.swift new file mode 100644 index 00000000..0a27db47 --- /dev/null +++ b/ios-app/app/Data/WeatherConditionExtension.swift @@ -0,0 +1,48 @@ +// +// PredictionExtensuins.swift +// app +// +// Created by Tobias Stottrop on 12.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import Foundation +import MowestaApi +import SwiftUI + + +extension WeatherCondition { + + public func getWeatherTypeImageName() -> String { + switch self.type { + case .unknown: return "questionmark" + case .clearSky: return "sun.max" + case .mainlyClear: return "cloud.sun" + case .partlyCloudy: return "cloud" + case .cloudy: return "cloud.fill" + case .fog: return "cloud.fog" + case .fogDepositingRime : return "cloud.fog" + case .slightDrizzle : return "cloud.drizzle" + case .moderateDrizzle : return "cloud.rain" + case .heavyDrizzle : return "cloud.rheavyrain" + case .drizzleFreezingSlight : return "cloud.snow" + case .drizzleFreezingModerateHeavy : return "cloud.snow" + case .slightRainNotFreezing : return "cloud.drizzle" + case .moderateRainNotFreezing : return "cloud.rain" + case .heavyRainNotFreezing : return "cloud.heavyrain" + case .rainFreezingSlight : return "cloud.snow" + case .rainFreezingModerateHeavy : return "cloud.snow" + case .slightFallOfSnowflakes : return "cloud.snow" + case .moderateFallOfSnowflakes : return "cloud.snow" + case .heavyFallOfSnowflakes : return "cloud.snow" + case .snowGrains : return "snow" + case .rainShowerSlight : return "cloud.rain" + case .rainShowerModerateHeavy : return "cloud.heavyrain" + case .rainShowerViolent : return "cloud.heavyrain" + case .snowShowerSlight : return "cloud.snow" + case .snowShowerModerateHeavy : return "cloud.snow" + case .thunderstormSlightModerate : return "cloud.bolt" + case .thunderstormHailHeavy : return "cloud.bolt" + } + } +} diff --git a/ios-app/app/FavoriteView/FavoriteList.swift b/ios-app/app/FavoriteView/FavoriteList.swift index 63855e3e..adf26e05 100644 --- a/ios-app/app/FavoriteView/FavoriteList.swift +++ b/ios-app/app/FavoriteView/FavoriteList.swift @@ -10,16 +10,37 @@ import SwiftUI import MowestaApi struct FavoriteList: View { - @EnvironmentObject var data: FavoriteLocations + @EnvironmentObject var favorites: FavoriteLocations + @UIState private var searchFavorites = false; + + private func deleteItem(at indexSet: IndexSet) { + self.favorites.locations.remove(atOffsets: indexSet) + } var body: some View { NavigationView { - List(data.locations, id: \._id) { location in - NavigationLink(destination: LocationDetail(location: location)) { - FavoriteRow(location: location) + List{ + ForEach(favorites.locations, id: \._id) { location in + NavigationLink(destination: LocationDetail(location: location)) { + FavoriteRow(location: location) + } + } + .onDelete(perform: self.deleteItem) + .onMove { (indexSet, index) in + self.favorites.locations.move(fromOffsets: indexSet, toOffset: index) } } - .navigationBarTitle(Text("Favorites")) + .listStyle(GroupedListStyle()) + .navigationBarTitle("Favorites", displayMode: .automatic) + .navigationBarItems(leading: EditButton(), trailing: + Button(action: { + self.searchFavorites = true + }){ + Text("Add") + }) + }.sheet(isPresented: $searchFavorites) { + FavoriteSearch(isPresented: self.$searchFavorites) + .environmentObject(self.favorites) } } } diff --git a/ios-app/app/FavoriteView/FavoriteRow.swift b/ios-app/app/FavoriteView/FavoriteRow.swift index 726defc5..61912ca7 100644 --- a/ios-app/app/FavoriteView/FavoriteRow.swift +++ b/ios-app/app/FavoriteView/FavoriteRow.swift @@ -11,24 +11,46 @@ import MowestaApi struct FavoriteRow: View { var location: LocationHierarchy - @EnvironmentObject var data: FavoriteLocations + + var body2: some View { + HStack { + builder() + } + .frame(minWidth: 0 , maxWidth: .infinity) + .background(Color.blue) + .cornerRadius(CGFloat(20)) + .padding() + .shadow(color: Color.blue, radius: CGFloat(4), x: CGFloat(2), y: CGFloat(2)) + } var body: some View { HStack{ Text(location.getName()) + .font(.subheadline) Spacer() - Image(systemName: data.currentWeathers[location]?.icon ?? "sun.min") - Text("\(data.currentWeathers[location]?.temperature ?? 0)°") + Image(systemName: "sun.min") + Text("220°") }.padding() } -} - -struct FavoriteRow_Previews: PreviewProvider { - static var previews: some View { - Group { - FavoriteRow(location: locationEssen) - .environmentObject(FavoriteLocations(locations: [locationEssen])) + + + + @ViewBuilder + func builder() -> some View { + if (self.location.type == .city) { + FavoriteCity(location: location) + } else if (self.location.type == .state) { + FavoriteCity(location: location) + } else { + FavoriteCity(location: location) + } + } + + struct FavoriteRow_Previews: PreviewProvider { + static var previews: some View { + Group { + FavoriteRow(location: locationEssen) + } } - .previewLayout(.fixed(width: 300, height:70)) } } diff --git a/ios-app/app/FavoriteView/FavoriteSearch.swift b/ios-app/app/FavoriteView/FavoriteSearch.swift new file mode 100644 index 00000000..8434a4f9 --- /dev/null +++ b/ios-app/app/FavoriteView/FavoriteSearch.swift @@ -0,0 +1,74 @@ +// +// FavoriteSearch.swift +// app +// +// Created by Tobias Stottrop on 12.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import SwiftUI +import MowestaApi + +struct FavoriteSearch: View { + @Binding var isPresented: Bool + + @UIState private var searchText: String = "" + @UIState private var searchProgress = false + @UIState private var locations: [LocationHierarchy] = [] + + + var body: some View { + NavigationView { + VStack { + SearchBar(text: self.$searchText, onChanged: self.searchTextChanged, onCanceled: self.canceled, onSearch: self.search) + FavoriteSearchResults(searchProgress: self.$searchProgress, locations: self.$locations, isPresented: self.$isPresented) + .navigationBarTitle(Text("Add Favorites"), displayMode: .inline) + .navigationBarItems(trailing: Button(action: { + self.isPresented = false + }){ + Text("Done") + }) + .resignKeyboardOnDragGesture() + } + } + } + + func canceled() { + self.searchText = "" + self.searchProgress = false + self.locations = [] + } + + func search() { + self.searchProgress = true + LocationAPI.searchLocations(language: .de, term: searchText, completion: receivedLocations) + + } + + func searchTextChanged() { + self.searchProgress = true + LocationAPI.searchLocations(language: .de, term: searchText, completion: receivedLocations) + } + + func receivedLocations(locationHierarchyPage: LocationHierarchyPage?, error: Error?) { + self.searchProgress = false + if let locationPage = locationHierarchyPage { + self.locations = [] + for location in locationPage.elements { + self.locations.append(location) + } + return + } + if let err = error { + print(err) + // evtl logging ?! + } + + } + + struct FavoriteSearch_Previews: PreviewProvider { + static var previews: some View { + FavoriteSearch(isPresented: .constant(true)) + } + } +} diff --git a/ios-app/app/FavoriteView/FavoriteSearchResultRow.swift b/ios-app/app/FavoriteView/FavoriteSearchResultRow.swift new file mode 100644 index 00000000..ab110f92 --- /dev/null +++ b/ios-app/app/FavoriteView/FavoriteSearchResultRow.swift @@ -0,0 +1,118 @@ +// +// SearchResultRow.swift +// app +// +// Created by Tobias Stottrop on 06.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import SwiftUI +import MowestaApi + +struct FavoriteSearchResultRow: View { + var location: LocationHierarchy + + @EnvironmentObject var favorites: FavoriteLocations + @UIState private var reload = false + + var delimeter: String { + get { + location.parent != nil && location.parent!.parent != nil ? " · " : "" + } + } + + var stateName: String { + get { + if (location.parent?.type == .state) { + return location.parent!.getName() + } else { + return "" + } + } + } + + var countryName: String { + get { + if (location.parent?.type == .country) { + return location.parent!.getName() + } else if (location.parent?.parent?.type == .country) { + return location.parent!.parent!.getName() + } else { + return "" + } + } + } + + var body: some View { + HStack { + ZStack { + Image(systemName: "circle.fill") + .font(Font.system(size: 30)) + .foregroundColor(.red) + Image(systemName: "mappin") + .font(Font.system(size: 20)) + .foregroundColor(.white) + } + VStack { + if (location.type == .city) { + HStack { + Text(location.getName()) + .font(.subtitle) + + Spacer() + } + HStack { + Text(stateName + delimeter + countryName) + .font(.caption) + .foregroundColor(.gray) + Spacer() + } + } else if (location.type == .state) { + HStack { + Text(location.getName()) + .font(.subtitle) + Spacer() + } + HStack { + Text(countryName) + .font(.caption) + .foregroundColor(.gray) + Spacer() + } + } else if (location.type == .country) { + HStack { + Text(location.getName()) + .font(.subtitle) + Spacer() + } + } + } + + Button(action: { + self.favorites.toggleLocation(self.location) + self.reload = !self.reload + }) { + Image(systemName: favorites.locations.contains{ element in + return element == location + } ? "heart.fill" : "heart").foregroundColor(Color.red) + .font(Font.system(size: 25)) + } + + } + .padding(.top, 10) + .padding(.bottom, 10) + } +} + +struct FavoriteSearchResultRow_Previews: PreviewProvider { + static var previews: some View { + Group { + FavoriteSearchResultRow(location: locationEssen) + FavoriteSearchResultRow(location: locationNrw) + //FavoriteSearchResultRow(isPresented: .constant(true), location: locationNrw) + //FavoriteSearchResultRow(isPresented: .constant(true), location: locationDeutschland) + } + .environmentObject(FavoriteLocations(locations: [locationEssen])) + .previewLayout(.fixed(width: 300, height:70)) + } +} diff --git a/ios-app/app/FavoriteView/FavoriteSearchResults.swift b/ios-app/app/FavoriteView/FavoriteSearchResults.swift new file mode 100644 index 00000000..f7ca7dfb --- /dev/null +++ b/ios-app/app/FavoriteView/FavoriteSearchResults.swift @@ -0,0 +1,35 @@ +// +// FavoriteSearchResults.swift +// app +// +// Created by Tobias Stottrop on 12.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import SwiftUI +import MowestaApi + +struct FavoriteSearchResults: View { + @Binding var searchProgress: Bool + @Binding var locations: [LocationHierarchy] + @Binding var isPresented: Bool + + @ViewBuilder + var body: some View { + if (self.searchProgress) { + Spacer() + ActivityIndicator(style: .large) + Spacer() + } else { + List(self.locations, id: \._id) { location in + FavoriteSearchResultRow(location: location) + } + } + } +} + +struct FavoriteSearchResults_Previews: PreviewProvider { + static var previews: some View { + FavoriteSearchResults(searchProgress: .constant(false), locations: .constant([locationEssen, locationNrw]), isPresented: .constant(true)) + } +} diff --git a/ios-app/app/LocationView/CityDetail.swift b/ios-app/app/LocationView/CityDetail.swift index ca6ba43c..fd1d3de5 100644 --- a/ios-app/app/LocationView/CityDetail.swift +++ b/ios-app/app/LocationView/CityDetail.swift @@ -11,47 +11,75 @@ import MowestaApi struct CityDetail: View { - @EnvironmentObject var favoriteLocations : FavoriteLocations + @EnvironmentObject var favorites : FavoriteLocations @UIState private var location: LocationHierarchy = locationEssen - @UIState private var city: City? = essen + @UIState private var city: City = essen + @UIState private var forecast: WeatherForecast = weatherforecast + @UIState private var current: WeatherCondition = condition + @UIState private var currentType: String = "sun.min" + private var currentTime : Int = Int(Date().timeIntervalSince1970) + func setLocation(_ location: LocationHierarchy) -> some View { self.location = location + NSLog("\(self.city.getMillisecondsFromGMT())") + LocationAPI.getCity(_id: location._id!, completion: { c, err in if let city = c { self.city = city + //NSLog("\(city)") + } + }) + WeatherAPI.getForecast(_id: location._id!, completion: {f, err in + if let fore = f { + self.forecast = fore + let epochInMS = self.currentTime * 1000; + let withGMT = epochInMS + self.city.getMillisecondsFromGMT() + + for item in fore.conditions { + //NSLog("Current stamp: \(Int(epochInMS) + self.city.getMillisecondsFromGMT())") + //NSLog("First stamp: \(item.time)") + //NSLog("withGMT : \(withGMT)") + //NSLog("First stamp: \(item.time)") + //NSLog("Last stamp: \((item.time + Int64(item.duration * 3600 * 1000)))") + if (withGMT > item.time && withGMT <= ((item.time + Int64(item.duration * 3600 * 1000)))) { + //NSLog("CALLLLLLLLED") + //NSLog("\(item.type)") + self.currentType = item.getWeatherTypeImageName() + self.current = item as WeatherCondition + NSLog("after setting: \(self.$current)") + NSLog("after setting: \(item)") + } + } } }) return self } + var body: some View { - NavigationView{ - VStack{ - VStack(alignment: .center){ - Text(location.getName()) - .font(.title) - }.padding() - .offset(y: -30) - .padding(.bottom, -30) - DegreeNumberCircle(temperature: favoriteLocations.currentWeathers[location]?.temperature ?? 0, size: 100) - Button(action: updateWeather) { - Text("Update Wetter") - } + List { + Section(header: Text("Now")) { + LocationHeaderView(city: $city, weatherType: $current) + } + Section(header: Text("Today")) { + LocationDetailView(conditions: forecast.conditions) + } + Section(header: Text("Next days")) { + LocationForecastView() } } - .navigationBarTitle(Text(city?.getName() ?? "NIL")) } func updateWeather() { - favoriteLocations.currentWeathers[locationEssen]?.temperature = 40 + favorites.currentWeathers[city._id!]?.temperature = 40 } } struct CityDetail_Previews: PreviewProvider { static var previews: some View { CityDetail() - .setLocation(locationEssen) + //.environment(\.locale, .init(identifier: "de")) .environmentObject(FavoriteLocations(locations: [locationEssen])) } } diff --git a/ios-app/app/LocationView/CountryDetail.swift b/ios-app/app/LocationView/CountryDetail.swift index aef9ec0e..c8006beb 100644 --- a/ios-app/app/LocationView/CountryDetail.swift +++ b/ios-app/app/LocationView/CountryDetail.swift @@ -11,7 +11,6 @@ import MowestaApi struct CountryDetail: View { - @EnvironmentObject var favoriteLocations : FavoriteLocations @UIState private var location: LocationHierarchy = locationDeutschland @UIState private var country: Country? @@ -34,6 +33,5 @@ struct CountryDetail_Previews: PreviewProvider { static var previews: some View { CountryDetail() .setLocation(locationDeutschland) - .environmentObject(FavoriteLocations(locations: [locationEssen])) } } diff --git a/ios-app/app/LocationView/FavoriteCity.swift b/ios-app/app/LocationView/FavoriteCity.swift new file mode 100644 index 00000000..407ced1f --- /dev/null +++ b/ios-app/app/LocationView/FavoriteCity.swift @@ -0,0 +1,56 @@ +// +// FavoriteCity.swift +// app +// +// Created by Tobias Stottrop on 12.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import SwiftUI +import MowestaApi + +struct FavoriteCity: View { + var location: LocationHierarchy + @EnvironmentObject var favorites: FavoriteLocations + + var body: some View { + VStack(spacing: 10){ + Text(location.getName()) + .foregroundColor(Color.white) + .fontWeight(Font.Weight.heavy) + .font(Font.system(size: 30)) + + Image(systemName: favorites.currentWeathers[location._id!]?.icon ?? "sun.min") + .resizable() + .foregroundColor(Color.white) + .frame(width: 100, height: 100) + .aspectRatio(contentMode: .fit) + + VStack{ Text("\(favorites.currentWeathers[location._id!]?.temperature ?? 0)°") + .foregroundColor(Color.white) + .font(.title) + HStack { + Text("22°C") + .foregroundColor(Color.white) + .font( Font.system(size: 14)) + .opacity(0.5) + Text("33°C") + .foregroundColor(Color.white) + .font( Font.system(size: 14)) + .opacity(1) + } + } + } + } +} + +struct FavoriteCity_Previews: PreviewProvider { + static var previews: some View { + FavoriteCity(location: locationEssen) + .frame(minWidth: 0 , maxWidth: .infinity) + .background(Color.blue) + .cornerRadius(CGFloat(20)) + .padding() + .shadow(color: Color.blue, radius: CGFloat(20), x: CGFloat(10), y: CGFloat(10)) + } +} diff --git a/ios-app/app/LocationView/LocationDetail.swift b/ios-app/app/LocationView/LocationDetail.swift index 20204a11..3d45a153 100644 --- a/ios-app/app/LocationView/LocationDetail.swift +++ b/ios-app/app/LocationView/LocationDetail.swift @@ -10,22 +10,23 @@ import SwiftUI import MowestaApi struct LocationDetail: View { - @EnvironmentObject var favoriteLocations : FavoriteLocations + @EnvironmentObject var favorites : FavoriteLocations var location: LocationHierarchy var body: some View { VStack { builder() } + .navigationBarTitle(location.getName()) .navigationBarItems(trailing: VStack { Button(action: { - self.favoriteLocations.toggleLocation(self.location) + self.favorites.toggleLocation(self.location) }) { - Image(systemName: favoriteLocations.locations.contains{ element in - return element == location - } ? "heart.fill" : "heart") - .font(Font.system(size: 25)) + Image(systemName: favorites.locations.contains{ element in + return element == location + } ? "heart.fill" : "heart") + .font(Font.system(size: 25)) } }) } @@ -45,6 +46,6 @@ struct LocationDetail: View { struct LocationDetail_Previews: PreviewProvider { static var previews: some View { LocationDetail(location: locationEssen) - .environmentObject(FavoriteLocations(locations: [])) + .environmentObject(FavoriteLocations(locations: [locationEssen])) } } diff --git a/ios-app/app/LocationView/LocationDetailView.swift b/ios-app/app/LocationView/LocationDetailView.swift new file mode 100644 index 00000000..077a133e --- /dev/null +++ b/ios-app/app/LocationView/LocationDetailView.swift @@ -0,0 +1,43 @@ +// +// LocationDetailView.swift +// app +// +// Created by Tobias Stottrop on 13.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import SwiftUI +import MowestaApi + +struct LocationDetailView: View { + @UIState var conditions : [WeatherCondition] + + + var body: some View { + ScrollView(.horizontal) { + HStack(spacing: 8) { + ForEach(conditions, id: \.hour) { cond in + VStack(spacing: 8) { + Text(String(cond.hour)) + .font(.footnote) + Image(systemName: cond.getWeatherTypeImageName()) + .font(.body) + Text("22C") + .font(.headline) + } + } + } + .frame(height: 100) + .padding(.trailing) + } + .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) + .frame(height: 100) + } +} + +struct LocationDetailView_Previews: PreviewProvider { + static var previews: some View { + LocationDetailView(conditions: [condition, condition, condition, condition, condition, condition,condition, condition, condition]) + .previewLayout(.fixed(width: 350, height:100)) + } +} diff --git a/ios-app/app/LocationView/LocationForecastView.swift b/ios-app/app/LocationView/LocationForecastView.swift new file mode 100644 index 00000000..1e02d056 --- /dev/null +++ b/ios-app/app/LocationView/LocationForecastView.swift @@ -0,0 +1,21 @@ +// +// LocationForecastView.swift +// app +// +// Created by Tobias Stottrop on 13.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// + +import SwiftUI + +struct LocationForecastView: View { + var body: some View { + Text("Next days....") + } +} + +struct LocationForecastView_Previews: PreviewProvider { + static var previews: some View { + LocationForecastView() + } +} diff --git a/ios-app/app/LocationView/LocationHeaderView.swift b/ios-app/app/LocationView/LocationHeaderView.swift new file mode 100644 index 00000000..700ab5c8 --- /dev/null +++ b/ios-app/app/LocationView/LocationHeaderView.swift @@ -0,0 +1,51 @@ +// +// LocationHeaderView.swift +// app +// +// Created by Tobias Stottrop on 12.01.20. +// Copyright © 2020 Marcus Handte. All rights reserved. +// +import SwiftUI +import MowestaApi + +struct LocationHeaderView: View { + @Binding var city: City; + @Binding var weatherType: WeatherCondition + + func test() -> some View{ + NSLog("\(String(describing: weatherType))") + return Spacer() + } + + func getDateAsString() -> String { + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "de_DE") + formatter.dateStyle = .medium + formatter.timeStyle = .short + let dateString = formatter.string(from: Date()) + return dateString + } + + var body: some View { + VStack(alignment: .leading) { + Text(getDateAsString()) + HStack { + Spacer() + HStack(alignment: .center, spacing: 16) { + Image(systemName: weatherType.getWeatherTypeImageName()) + .font(.largeTitle) + Text(String(weatherType.temperature)) + .font(.largeTitle) + } + Spacer() + } + } + } +} + +struct LocationHeaderView_Previews: PreviewProvider { + static var previews: some View { + LocationHeaderView(city: .constant(essen), weatherType: .constant(condition)) + .previewLayout(.fixed(width: 350, height:150)) + } +} diff --git a/ios-app/app/LocationView/StateDetail.swift b/ios-app/app/LocationView/StateDetail.swift index 576898d8..06051f33 100644 --- a/ios-app/app/LocationView/StateDetail.swift +++ b/ios-app/app/LocationView/StateDetail.swift @@ -10,7 +10,6 @@ import SwiftUI import MowestaApi struct StateDetail: View { - @EnvironmentObject var favoriteLocations : FavoriteLocations @UIState private var location: LocationHierarchy = locationNrw @UIState private var state: MowestaApi.State? @@ -33,6 +32,6 @@ struct StateDetail_Previews: PreviewProvider { static var previews: some View { StateDetail() .setLocation(locationNrw) - .environmentObject(FavoriteLocations(locations: [locationEssen])) + } } diff --git a/ios-app/app/MockData/LocationMock.swift b/ios-app/app/MockData/LocationMock.swift index 8137ff8f..20d70919 100644 --- a/ios-app/app/MockData/LocationMock.swift +++ b/ios-app/app/MockData/LocationMock.swift @@ -10,7 +10,7 @@ import MowestaApi let locationDeutschland = LocationHierarchy(_id: 6, creationTime: 0, modificationTime: 0, deleted: false, coordinate: Coordinate(latitude: 2.3, longitude: 2.4), type: .country, parent: nil, names: ["de" : "Deutschland", "local" : "Deutschland", "en" : "Germany"]) -let locationNrw = LocationHierarchy(_id: 6, creationTime: 0, modificationTime: 0, deleted: false, coordinate: Coordinate(latitude: 2.3, longitude: 2.4), type: .state, parent: locationDeutschland , names: ["de" : "Nordrhein-Westfalen", "local" : "Nordrhein-Westfalen", "en" : "North Rhine-Westphalia"]) +let locationNrw = LocationHierarchy(_id: 7, creationTime: 0, modificationTime: 0, deleted: false, coordinate: Coordinate(latitude: 2.3, longitude: 2.4), type: .state, parent: locationDeutschland , names: ["de" : "Nordrhein-Westfalen", "local" : "Nordrhein-Westfalen", "en" : "North Rhine-Westphalia"]) let locationEssen = LocationHierarchy(_id: 6, creationTime: 0, modificationTime: 0, deleted: false, coordinate: Coordinate(latitude: 2.3, longitude: 2.4), type: .city, parent: locationNrw, names: ["de" : "Essen", "local" : "Essen", "en" : "Essen"]) @@ -28,6 +28,11 @@ let berlin = City(_id: 5, creationTime: 0, modificationTime: 0, deleted: false, let rain4 = CurrentWeatherData(temperature: 4, icon: "sun") +let condition = WeatherCondition(source: WeatherCondition.Source.cosmoEurope, time: 1578787200000, hour: 0, duration: 1, type: WeatherCondition.ModelType.clearSky, temperature: 23, windDirection: WeatherCondition.WindDirection.east, windSpeed: 6, cloudCoverage: 12, cloudDepth: 22, pressure: 22, precipitation: 32, snowDepth: 0, humidity: 32) + +let weatherforecast = WeatherForecast(_id: 8022, creationTime: 1578852215818, modificationTime: 1578852215818, deleted: false, coordinate: Coordinate(latitude: 7.0243988037109375, longitude: 50.9375), source: WeatherForecast.Source.iconEurope, surfaceHeight: -0.02880859375, plantCoverage: 0, soilType: WeatherForecast.SoilType.clay, conditions: [condition]) + + func loadTestData() -> [City] { return [essen, berlin]; } diff --git a/ios-app/app/Resources/Mowesta.xcdatamodeld/Mowesta.xcdatamodel/contents b/ios-app/app/Resources/Mowesta.xcdatamodeld/Mowesta.xcdatamodel/contents new file mode 100644 index 00000000..1cd38239 --- /dev/null +++ b/ios-app/app/Resources/Mowesta.xcdatamodeld/Mowesta.xcdatamodel/contents @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/ios-app/app/de.lproj/Localizable.strings b/ios-app/app/de.lproj/Localizable.strings index f242531d..e904ebde 100644 --- a/ios-app/app/de.lproj/Localizable.strings +++ b/ios-app/app/de.lproj/Localizable.strings @@ -31,3 +31,7 @@ /* Search View */ "SVSearchLocations" = "Suche Orte"; + +/* Favorites View */ +"Favorite_NavigationBarTitle" = "Favoriten"; +"Now" = "Jetzt"; diff --git a/ios-app/app/en.lproj/Localizable.strings b/ios-app/app/en.lproj/Localizable.strings index 6c5bddd2..c4e43a9c 100644 --- a/ios-app/app/en.lproj/Localizable.strings +++ b/ios-app/app/en.lproj/Localizable.strings @@ -31,3 +31,7 @@ /* Search View */ "SVSearchLocations" = "Search Locations"; + +/* Favorites View */ +"Favorite_NavigationBarTitle" = "Favorites"; +"Now" = "Now";