# HG changeset patch # User Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> # Date 1612520045 -3600 # Node ID 82ac1ea6526931f6a567e22a752829802938ab1e # Parent 4e920489a57e5d58ebc9cdef65549c5d18677052 Add NewsDetail diff -r 4e920489a57e -r 82ac1ea65269 LazyBear.xcodeproj/project.pbxproj --- a/LazyBear.xcodeproj/project.pbxproj Thu Feb 04 23:29:00 2021 +0100 +++ b/LazyBear.xcodeproj/project.pbxproj Fri Feb 05 11:14:05 2021 +0100 @@ -34,6 +34,7 @@ 95B04EB325212369000AD27F /* LazyBearApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B04EB225212369000AD27F /* LazyBearApp.swift */; }; 95B04EB525212369000AD27F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B04EB425212369000AD27F /* ContentView.swift */; }; 95B04EB72521236A000AD27F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95B04EB62521236A000AD27F /* Assets.xcassets */; }; + 95B3552825CD4A5600BCDE8E /* NewsDetail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B3552725CD4A5600BCDE8E /* NewsDetail.swift */; }; 95B395A525BDF42E009A7EB0 /* companies.json in Resources */ = {isa = PBXBuildFile; fileRef = 95B395A425BDF42E009A7EB0 /* companies.json */; }; 95D1BF4925ADCF7700E5D063 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95D1BF4825ADCF7700E5D063 /* Persistence.swift */; }; 95E4118F25BEC35D00A9C23F /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 95E4118E25BEC35D00A9C23F /* SDWebImageSwiftUI */; }; @@ -85,6 +86,7 @@ 95B04EB425212369000AD27F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 95B04EB62521236A000AD27F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 95B04EBB2521236A000AD27F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 95B3552725CD4A5600BCDE8E /* NewsDetail.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NewsDetail.swift; path = lazybear/Views/NewsDetail.swift; sourceTree = SOURCE_ROOT; }; 95B395A425BDF42E009A7EB0 /* companies.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = companies.json; path = lazybear/Data/companies.json; sourceTree = SOURCE_ROOT; }; 95D1BF4825ADCF7700E5D063 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Persistence.swift; path = LazyBear/Persistence.swift; sourceTree = SOURCE_ROOT; }; 95E4119125BEC56F00A9C23F /* SuperTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuperTitle.swift; sourceTree = ""; }; @@ -171,6 +173,7 @@ 95363CE925C8858800B74131 /* TransactionRow.swift */, 959D28DE25CC9A1A0029F689 /* News.swift */, 959D28E125CC9B370029F689 /* NewsRow.swift */, + 95B3552725CD4A5600BCDE8E /* NewsDetail.swift */, ); path = Views; sourceTree = ""; @@ -320,6 +323,7 @@ 95AB4A7A259DCBAE0064C9C1 /* ReadJson.swift in Sources */, 95F6F45C25C20D8D002AC66A /* Price.swift in Sources */, 9597CE0125C1DC0A004DDFED /* LogoModifier.swift in Sources */, + 95B3552825CD4A5600BCDE8E /* NewsDetail.swift in Sources */, 954DDF0425C456E800848A4B /* QuoteModel.swift in Sources */, 959D28E225CC9B370029F689 /* NewsRow.swift in Sources */, 9520F0B525C7131300692610 /* LineChart.swift in Sources */, diff -r 4e920489a57e -r 82ac1ea65269 LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r 4e920489a57e -r 82ac1ea65269 lazybear/Network/Request.swift --- a/lazybear/Network/Request.swift Thu Feb 04 23:29:00 2021 +0100 +++ b/lazybear/Network/Request.swift Fri Feb 05 11:14:05 2021 +0100 @@ -21,7 +21,7 @@ // Decode response with the model passed let decodedResponse = try JSONDecoder().decode(model, from: data) DispatchQueue.main.async { - print(decodedResponse) + //print(decodedResponse) completion(decodedResponse) } return diff -r 4e920489a57e -r 82ac1ea65269 lazybear/Views/NewsDetail.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Views/NewsDetail.swift Fri Feb 05 11:14:05 2021 +0100 @@ -0,0 +1,55 @@ +// +// NewsDetail.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 5/2/21. +// + +import SwiftUI +import SDWebImageSwiftUI + +struct NewsDetail: View { + @State var new: NewsModel + @Environment(\.presentationMode) var detailPresentation + + var body: some View { + + VStack(alignment: .leading) { + HStack { + Spacer() + Button(action: { self.detailPresentation.wrappedValue.dismiss() }) { + Image(systemName: "multiply.circle.fill") + } + } + + Text(new.source ?? "-") + .font(.caption2) + + Text(new.headline ?? "-") + .font(.title) + .fontWeight(.semibold) + + ScrollView { + VStack(alignment: .leading) { + WebImage(url: URL(string: new.image ?? "")) + .resizable() + .indicator(.activity) + .scaledToFit() + + Divider() + Text(new.summary ?? "-") + Link("Read the full article", destination: URL(string: new.url ?? "")!) + .padding(.top) + } + + } + } + .padding() + } +} + +struct NewsDetail_Previews: PreviewProvider { + static var previews: some View { + NewsDetail(new: NewsModel(datetime: 248375623, headline: "Leak says Apple’s first mixed-reality headset will cost $3,000", source: "BGR", url: "", summary: "A new report lists the purported price and release date of Apple’s upcoming high-end mixed-reality (MR) glasses. The headset will supposedly retail for around $3,000 in 2022. The device will reportedly use cameras to track the wearer's hands, while internal sensors track eye movements. The headset is said to feature two 8K displays that will follow the eyes' movement, displaying the images that are in focus at high resolution, with objects in peripheral vision being shown at a lower resolution. Apple has been rumored more than once to be developing its own smart headgear that would work in tandem with other devices, like the iPhone or a Mac. The so-called Apple Glasses project has been the subject.", image: "")) + } +} diff -r 4e920489a57e -r 82ac1ea65269 lazybear/Views/NewsRow.swift --- a/lazybear/Views/NewsRow.swift Thu Feb 04 23:29:00 2021 +0100 +++ b/lazybear/Views/NewsRow.swift Fri Feb 05 11:14:05 2021 +0100 @@ -9,34 +9,41 @@ struct NewsRow: View { @State var new: NewsModel + @State private var showDetails = false var body: some View { - VStack(alignment: .leading) { - Text(new.source ?? "-") - .font(.caption2) - - Text(new.headline ?? "-") - .font(.headline) - .fontWeight(.semibold) - .lineLimit(4) - - Text(new.summary ?? "-") - .lineLimit(3) - .font(.caption) - .padding(.top, 3) - - let (hours, minutes) = convertEpoch() - Text("\(hours) hours and \(minutes) minutes ago") - .font(.caption) - .fontWeight(.semibold) - .padding(.top, 3) - - Divider() + Button(action: { self.showDetails.toggle() }) { + VStack(alignment: .leading) { + Text(new.source ?? "-") + .font(.caption2) + + Text(new.headline ?? "-") + .font(.headline) + .fontWeight(.semibold) + .lineLimit(4) + + Text(new.summary ?? "-") + .lineLimit(3) + .font(.caption) + .padding(.top, 3) + + let (hours, minutes) = epochToHours() + Text("\(hours) hours and \(minutes) minutes ago") + .font(.caption) + .fontWeight(.semibold) + .padding(.top, 3) + + Divider() + } + .padding([.leading, .trailing]) } - .padding([.leading, .trailing]) + .buttonStyle(PlainButtonStyle()) + .sheet(isPresented: $showDetails) { + NewsDetail(new: self.new) + } } - private func convertEpoch() -> (String, String) { + private func epochToHours() -> (String, String) { let now = Date() // Current date let articlePublished = Date(timeIntervalSince1970: TimeInterval(new.datetime ?? 0)/1000)