Mercurial > public > lazybear
changeset 258:471906e56feb
Changing NewsView on iPad
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Fri, 12 Mar 2021 20:48:42 +0100 |
parents | b666b999824f |
children | 23e48c2d153d |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate LazyBear/ContentView.swift LazyBear/UI/NewsRow.swift LazyBear/UI/NewsView.swift |
diffstat | 6 files changed, 91 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Fri Mar 12 18:26:57 2021 +0100 +++ b/LazyBear.xcodeproj/project.pbxproj Fri Mar 12 20:48:42 2021 +0100 @@ -20,6 +20,7 @@ 9517626025EEB37E00733235 /* PriceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9517625F25EEB37E00733235 /* PriceModel.swift */; }; 9517626325EEBD3800733235 /* IexAttribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9517626225EEBD3800733235 /* IexAttribution.swift */; }; 9520C26F25F4D43D0070DD71 /* TransactionDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9520C26E25F4D43D0070DD71 /* TransactionDetail.swift */; }; + 9525C89725FBF7310080A0E8 /* WaterfallGrid in Frameworks */ = {isa = PBXBuildFile; productRef = 9525C89625FBF7310080A0E8 /* WaterfallGrid */; }; 9549D63325E1903F0085C3CD /* Charts in Frameworks */ = {isa = PBXBuildFile; productRef = 9549D63225E1903F0085C3CD /* Charts */; }; 9549D63625E191520085C3CD /* Normalize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9549D63525E191520085C3CD /* Normalize.swift */; }; 95672B8F25DDA54700DCBE4A /* LazyBearApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95672B8E25DDA54700DCBE4A /* LazyBearApp.swift */; }; @@ -149,6 +150,7 @@ 95D34C2725EFD5FE006F4A81 /* SDWebImageSwiftUI in Frameworks */, 958A735225E0170900FD7ECA /* CloudKit.framework in Frameworks */, 9549D63325E1903F0085C3CD /* Charts in Frameworks */, + 9525C89725FBF7310080A0E8 /* WaterfallGrid in Frameworks */, 95B3E0A625E1318D007EFDE3 /* SwiftlySearch in Frameworks */, 95DED9E425F2B4D6000DFCBA /* SwiftUICharts in Frameworks */, ); @@ -321,6 +323,7 @@ 9549D63225E1903F0085C3CD /* Charts */, 95D34C2625EFD5FE006F4A81 /* SDWebImageSwiftUI */, 95DED9E325F2B4D6000DFCBA /* SwiftUICharts */, + 9525C89625FBF7310080A0E8 /* WaterfallGrid */, ); productName = LazyBear; productReference = 95672B8B25DDA54700DCBE4A /* LazyBear.app */; @@ -354,6 +357,7 @@ 9549D63125E1903F0085C3CD /* XCRemoteSwiftPackageReference "swiftui-charts" */, 95D34C2525EFD5FE006F4A81 /* XCRemoteSwiftPackageReference "SDWebImageSwiftUI" */, 95DED9E225F2B4D6000DFCBA /* XCRemoteSwiftPackageReference "SwiftUICharts" */, + 9525C89525FBF7310080A0E8 /* XCRemoteSwiftPackageReference "WaterfallGrid" */, ); productRefGroup = 95672B8C25DDA54700DCBE4A /* Products */; projectDirPath = ""; @@ -636,6 +640,14 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ + 9525C89525FBF7310080A0E8 /* XCRemoteSwiftPackageReference "WaterfallGrid" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/paololeonardi/WaterfallGrid.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.0.1; + }; + }; 9549D63125E1903F0085C3CD /* XCRemoteSwiftPackageReference "swiftui-charts" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/spacenation/swiftui-charts.git"; @@ -671,6 +683,11 @@ /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ + 9525C89625FBF7310080A0E8 /* WaterfallGrid */ = { + isa = XCSwiftPackageProductDependency; + package = 9525C89525FBF7310080A0E8 /* XCRemoteSwiftPackageReference "WaterfallGrid" */; + productName = WaterfallGrid; + }; 9549D63225E1903F0085C3CD /* Charts */ = { isa = XCSwiftPackageProductDependency; package = 9549D63125E1903F0085C3CD /* XCRemoteSwiftPackageReference "swiftui-charts" */;
--- a/LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Fri Mar 12 18:26:57 2021 +0100 +++ b/LazyBear.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved Fri Mar 12 20:48:42 2021 +0100 @@ -54,6 +54,15 @@ "revision": "6cacb77e8d3e0a9ed1d09ce9a19ba057c95ce529", "version": "0.5.2" } + }, + { + "package": "WaterfallGrid", + "repositoryURL": "https://github.com/paololeonardi/WaterfallGrid.git", + "state": { + "branch": null, + "revision": "944aa82832ed5a9eaaf50862cdd53e3c10ab55eb", + "version": "1.0.1" + } } ] },
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/LazyBear/ContentView.swift Fri Mar 12 18:26:57 2021 +0100 +++ b/LazyBear/ContentView.swift Fri Mar 12 20:48:42 2021 +0100 @@ -53,7 +53,7 @@ ActionView() .offset(y: hudManager.showAction ? 0 : 250) .animation(.easeInOut) - .padding(.horizontal) + .padding() } } .accentColor(Color("\(userSettings.first?.theme?.lowercased() ?? "default")Accent")) @@ -65,5 +65,6 @@ struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() + .environmentObject(HudManager()) } }
--- a/LazyBear/UI/NewsRow.swift Fri Mar 12 18:26:57 2021 +0100 +++ b/LazyBear/UI/NewsRow.swift Fri Mar 12 20:48:42 2021 +0100 @@ -6,6 +6,7 @@ // import SwiftUI +import SDWebImageSwiftUI struct NewsRow: View { var new: NewsModel @@ -13,50 +14,54 @@ @Environment(\.colorScheme) var colorScheme // Detect dark mode var body: some View { - Button(action: { self.showingDetail = true }) { - HStack { - VStack(alignment: .leading) { - if let source = new.source { - Text(source.uppercased()) - .font(.caption) - .opacity(0.5) - - } - - if let headline = new.headline { - Text(headline) - .font(.headline) - .lineLimit(4) - } + VStack(alignment: .leading) { + // If iPad show Image + if UIDevice.current.userInterfaceIdiom == .pad { + WebImage(url: URL(string: new.image ?? "")) + .resizable() + .placeholder { } + .indicator(.activity) + .aspectRatio(contentMode: .fit) + .cornerRadius(UIDevice.current.userInterfaceIdiom == .pad ? 10: 0) + } + + if let source = new.source { + Text(source.uppercased()) + .font(.caption) + .opacity(0.5) - if let summary = new.summary { - Text(summary) - .opacity(0.5) - .font(.subheadline) - .lineLimit(1) - .padding(.bottom, 5) - } - - if (new.datetime != nil) { - let humanDate = convertDate() - Text("\(humanDate) ago") - .font(.caption2) - .opacity(0.5) - } + } + + if let headline = new.headline { + Text(headline) + .font(.headline) + .lineLimit(UIDevice.current.userInterfaceIdiom == .pad ? nil: 4) } - Spacer() + if let summary = new.summary { + Text(summary) + .opacity(0.5) + .font(.subheadline) + .lineLimit(UIDevice.current.userInterfaceIdiom == .pad ? 10: 1) + .padding(.bottom, 5) + } + + if (new.datetime != nil) { + let humanDate = convertDate() + Text("\(humanDate) ago") + .font(.caption2) + .opacity(0.5) + } } } .foregroundColor(colorScheme == .dark ? .white: .black) - .padding(.horizontal) .sheet(isPresented: $showingDetail) { DetailNew(new: new) } } - // Cover Epoch time to human date + // Convert Epoch time to human date private func convertDate() -> String { let now = Date() // Current date // Time when the article was published. Divide new.datetime by 1,000 because
--- a/LazyBear/UI/NewsView.swift Fri Mar 12 18:26:57 2021 +0100 +++ b/LazyBear/UI/NewsView.swift Fri Mar 12 20:48:42 2021 +0100 @@ -6,10 +6,12 @@ // import SwiftUI +import WaterfallGrid struct NewsView: View { var symbol: String - @FetchRequest(entity: UserSettings.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \UserSettings.changedAt, ascending: false)]) var userSettings: FetchedResults<UserSettings> + @FetchRequest(entity: UserSettings.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \UserSettings.changedAt, ascending: false)]) + var userSettings: FetchedResults<UserSettings> @State private var news = [NewsModel]() var body: some View { @@ -30,11 +32,31 @@ } let language = userSettings.first?.newsLanguage ?? "en" - ForEach(news, id: \.self) { new in - if language == new.lang { + + // If iPhone + if UIDevice.current.userInterfaceIdiom == .phone { + ForEach(news, id: \.self) { new in + if language == new.lang { + NewsRow(new: new) + .padding(.horizontal) + + Divider() + } + } + } + + // If iPad + if UIDevice.current.userInterfaceIdiom == .pad { + WaterfallGrid(news, id: \.self) { new in NewsRow(new: new) - Divider() } + .gridStyle( + columnsInPortrait: 2, + columnsInLandscape: 3, + spacing: 8, + animation: .easeInOut(duration: 0.5) + ) + .padding(EdgeInsets(top: 16, leading: 8, bottom: 16, trailing: 8)) } } .onAppear {