From 9345b915734377a2479a92579ed6d1849b708f72 Mon Sep 17 00:00:00 2001 From: Louis Hollingworth Date: Sun, 28 May 2023 19:43:37 +0100 Subject: [PATCH] Added Esperanto translations Added beginnings of feed parsing, may need to switch parser. Signed-off-by: Louis Hollingworth --- Leganto.xcodeproj/project.pbxproj | 44 +++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 14 ++++++ Leganto/AddFeedView.swift | 9 ++++ Leganto/ContentView.swift | 4 +- Leganto/DataController.swift | 13 ++++- Leganto/FeedParser.swift | 48 +++++++++++++++++++ Leganto/FeedView.swift | 13 +++-- Leganto/FeedViewCell.swift | 26 ++++++++-- Leganto/Info.plist | 14 ++++++ Leganto/Leganto.entitlements | 20 ++++++-- Leganto/en-GB.lproj/Localizable.strings | 1 + Leganto/eo.lproj/Localizable.strings | 22 +++++++++ README.md | 1 + 13 files changed, 213 insertions(+), 16 deletions(-) create mode 100644 Leganto.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 Leganto/FeedParser.swift create mode 100644 Leganto/Info.plist create mode 100644 Leganto/eo.lproj/Localizable.strings diff --git a/Leganto.xcodeproj/project.pbxproj b/Leganto.xcodeproj/project.pbxproj index 6821cdb..91eae28 100644 --- a/Leganto.xcodeproj/project.pbxproj +++ b/Leganto.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 860920F32A1E917600CED32F /* FeedParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 860920F22A1E917600CED32F /* FeedParser.swift */; }; 86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */; }; 86B463412A1A382800CBBE76 /* Leganto.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */; }; 86B463432A1A382800CBBE76 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463422A1A382800CBBE76 /* ContentView.swift */; }; @@ -17,9 +18,11 @@ 86B4635A2A1A499300CBBE76 /* AddFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463592A1A499300CBBE76 /* AddFeedView.swift */; }; 86B4635C2A1D1C6C00CBBE76 /* FeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B4635B2A1D1C6C00CBBE76 /* FeedView.swift */; }; 86B4635E2A1D217B00CBBE76 /* FeedViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B4635D2A1D217B00CBBE76 /* FeedViewCell.swift */; }; + 86B463612A1D346700CBBE76 /* FeedKit in Frameworks */ = {isa = PBXBuildFile; productRef = 86B463602A1D346700CBBE76 /* FeedKit */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 860920F22A1E917600CED32F /* FeedParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedParser.swift; sourceTree = ""; }; 86B463382A1A382800CBBE76 /* Leganto.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Leganto.app; sourceTree = BUILT_PRODUCTS_DIR; }; 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegantoApp.swift; sourceTree = ""; }; 86B463402A1A382800CBBE76 /* Leganto.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Leganto.xcdatamodel; sourceTree = ""; }; @@ -32,6 +35,8 @@ 86B463592A1A499300CBBE76 /* AddFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeedView.swift; sourceTree = ""; }; 86B4635B2A1D1C6C00CBBE76 /* FeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedView.swift; sourceTree = ""; }; 86B4635D2A1D217B00CBBE76 /* FeedViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedViewCell.swift; sourceTree = ""; }; + 86B463622A1D37C400CBBE76 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 86B463632A1D387100CBBE76 /* eo */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = eo; path = eo.lproj/Localizable.strings; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -39,6 +44,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 86B463612A1D346700CBBE76 /* FeedKit in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -64,6 +70,7 @@ 86B4633A2A1A382800CBBE76 /* Leganto */ = { isa = PBXGroup; children = ( + 86B463622A1D37C400CBBE76 /* Info.plist */, 86B4635D2A1D217B00CBBE76 /* FeedViewCell.swift */, 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */, 86B463422A1A382800CBBE76 /* ContentView.swift */, @@ -75,6 +82,7 @@ 86B463472A1A382B00CBBE76 /* Preview Content */, 86B463592A1A499300CBBE76 /* AddFeedView.swift */, 86B4635B2A1D1C6C00CBBE76 /* FeedView.swift */, + 860920F22A1E917600CED32F /* FeedParser.swift */, ); path = Leganto; sourceTree = ""; @@ -103,6 +111,9 @@ dependencies = ( ); name = Leganto; + packageProductDependencies = ( + 86B463602A1D346700CBBE76 /* FeedKit */, + ); productName = Leganto; productReference = 86B463382A1A382800CBBE76 /* Leganto.app */; productType = "com.apple.product-type.application"; @@ -129,8 +140,12 @@ knownRegions = ( Base, "en-GB", + eo, ); mainGroup = 86B4632F2A1A382800CBBE76; + packageReferences = ( + 86B4635F2A1D346700CBBE76 /* XCRemoteSwiftPackageReference "FeedKit" */, + ); productRefGroup = 86B463392A1A382800CBBE76 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -162,6 +177,7 @@ 86B463582A1A42D100CBBE76 /* DataController.swift in Sources */, 86B4635A2A1A499300CBBE76 /* AddFeedView.swift in Sources */, 86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */, + 860920F32A1E917600CED32F /* FeedParser.swift in Sources */, 86B4635C2A1D1C6C00CBBE76 /* FeedView.swift in Sources */, 86B4635E2A1D217B00CBBE76 /* FeedViewCell.swift in Sources */, 86B463432A1A382800CBBE76 /* ContentView.swift in Sources */, @@ -175,6 +191,7 @@ isa = PBXVariantGroup; children = ( 86B463562A1A3ECE00CBBE76 /* en-GB */, + 86B463632A1D387100CBBE76 /* eo */, ); name = Localizable.strings; sourceTree = ""; @@ -306,7 +323,9 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = Leganto/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Leganto; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.reference"; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; @@ -326,6 +345,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -345,7 +366,9 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = Leganto/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Leganto; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.reference"; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; @@ -365,6 +388,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = auto; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -394,6 +419,25 @@ }; /* End XCConfigurationList section */ +/* Begin XCRemoteSwiftPackageReference section */ + 86B4635F2A1D346700CBBE76 /* XCRemoteSwiftPackageReference "FeedKit" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/nmdias/FeedKit.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 9.0.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 86B463602A1D346700CBBE76 /* FeedKit */ = { + isa = XCSwiftPackageProductDependency; + package = 86B4635F2A1D346700CBBE76 /* XCRemoteSwiftPackageReference "FeedKit" */; + productName = FeedKit; + }; +/* End XCSwiftPackageProductDependency section */ + /* Begin XCVersionGroup section */ 86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */ = { isa = XCVersionGroup; diff --git a/Leganto.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Leganto.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..9ea620b --- /dev/null +++ b/Leganto.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,14 @@ +{ + "pins" : [ + { + "identity" : "feedkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/nmdias/FeedKit.git", + "state" : { + "revision" : "68493a33d862c33c9a9f67ec729b3b7df1b20ade", + "version" : "9.1.2" + } + } + ], + "version" : 2 +} diff --git a/Leganto/AddFeedView.swift b/Leganto/AddFeedView.swift index e0b5e21..ecf381b 100644 --- a/Leganto/AddFeedView.swift +++ b/Leganto/AddFeedView.swift @@ -25,6 +25,7 @@ struct AddFeed: View { } #else AddFeedContent() + .padding(.all) #endif } } @@ -52,6 +53,14 @@ struct AddFeedContent: View { } } .toolbar { + ToolbarItem { + Button { + dismiss() + } label: { + Text("cancel") + } + + } ToolbarItem { Button(action: addItem) { Text("save") diff --git a/Leganto/ContentView.swift b/Leganto/ContentView.swift index 04c03be..6ebe300 100644 --- a/Leganto/ContentView.swift +++ b/Leganto/ContentView.swift @@ -10,7 +10,7 @@ import CoreData struct ContentView: View { @Environment(\.managedObjectContext) var moc - @FetchRequest(sortDescriptors: [], animation: .default) var feeds: FetchedResults + @FetchRequest(sortDescriptors: [SortDescriptor(\.name)], animation: .default) var feeds: FetchedResults @State private var showAddScreen = false @@ -19,7 +19,7 @@ struct ContentView: View { List { ForEach(feeds) { item in NavigationLink { - FeedView(source: item) + FeedView(feedURL: URL(string: item.url!)!, feedName: item.name!) } label: { HStack { if Genre(rawValue: item.genre) == .news { diff --git a/Leganto/DataController.swift b/Leganto/DataController.swift index 9dcbfc9..e72650d 100644 --- a/Leganto/DataController.swift +++ b/Leganto/DataController.swift @@ -52,6 +52,7 @@ class DataController: ObservableObject { init(inMemory: Bool = false) { container = NSPersistentCloudKitContainer(name: "Leganto") + if inMemory { container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") } @@ -72,7 +73,17 @@ class DataController: ObservableObject { fatalError("Unresolved error \(error), \(error.userInfo)") } }) - + + /* +#if DEBUG +do { + try container.initializeCloudKitSchema() +} catch { + let err = error as NSError + fatalError("Unresolved error \(err), \(err.userInfo)") +} +#endif + */ container.viewContext.automaticallyMergesChangesFromParent = true } } diff --git a/Leganto/FeedParser.swift b/Leganto/FeedParser.swift new file mode 100644 index 0000000..4ed25e0 --- /dev/null +++ b/Leganto/FeedParser.swift @@ -0,0 +1,48 @@ +// +// FeedParser.swift +// Leganto +// +// Created by Louis Hollingworth on 2023-05-24. +// + +import Foundation +import FeedKit + +class LFeedParser: ObservableObject { + var urlStr: String + @Published var rssFeed: RSSFeed? + @Published var atomFeed: AtomFeed? + @Published var jsonFeed: JSONFeed? + + init(urlStr: String) { + self.urlStr = urlStr + } + + func loadData() { + if let url = URL(string: urlStr) { + let parser = FeedParser(URL: url) + + parser.parseAsync { (result) in + + switch result { + case .success(let feed): + switch feed { + case let .atom(feed): + self.atomFeed = feed + case let .json(feed): + self.jsonFeed = feed + case let .rss(feed): + self.rssFeed = feed + } + case .failure(let err): + print(err) + } + + DispatchQueue.main.async { + self.objectWillChange.send() + } + } + } + + } +} diff --git a/Leganto/FeedView.swift b/Leganto/FeedView.swift index 89cac57..5fa90bd 100644 --- a/Leganto/FeedView.swift +++ b/Leganto/FeedView.swift @@ -6,16 +6,21 @@ // import SwiftUI +import FeedKit struct FeedView: View { - var source: Feed + var feed: Feed + @ObservedObject var parsed: LFeedParser = LFeedParser(urlStr: "https://git.ludoviko.ch/lucxjo/leganto-apple.rss") var body: some View { List { - ForEach(1..<20) { item in - FeedViewCell() + if let feed = parsed.jsonFeed { + ForEach(feed.items!, id: \.id!) { item in + FeedViewCell(title: item.title!, author: item.author!, date: Date(), + content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") + } } } - .navigationTitle(source.name!) + .navigationTitle(feed.name!) } } diff --git a/Leganto/FeedViewCell.swift b/Leganto/FeedViewCell.swift index 5f7299f..7c40b60 100644 --- a/Leganto/FeedViewCell.swift +++ b/Leganto/FeedViewCell.swift @@ -8,25 +8,41 @@ import SwiftUI struct FeedViewCell: View { + let title: String + let author: String + let date: Date + let content: String + var body: some View { VStack(alignment: .leading) { - Text("Title") + Text(title) .font(.title) HStack { - Text("Author") + Text(author) Spacer() - Text("Date") + Text(date, formatter: dateFormatter) } .font(.footnote) - Text("Content") + Text(content) .font(.body) } .multilineTextAlignment(.leading) } } +private let dateFormatter: DateFormatter = { + let formatter = DateFormatter() + formatter.dateStyle = .short + formatter.timeStyle = .short + return formatter +}() + + struct FeedViewCell_Previews: PreviewProvider { static var previews: some View { - FeedViewCell() + FeedViewCell( + title: "Test", author: "Test Author", date: Date(), + content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + ) } } diff --git a/Leganto/Info.plist b/Leganto/Info.plist new file mode 100644 index 0000000..062d626 --- /dev/null +++ b/Leganto/Info.plist @@ -0,0 +1,14 @@ + + + + + CFBundleURLTypes + + + + UIBackgroundModes + + remote-notification + + + diff --git a/Leganto/Leganto.entitlements b/Leganto/Leganto.entitlements index f2ef3ae..3e1a2cc 100644 --- a/Leganto/Leganto.entitlements +++ b/Leganto/Leganto.entitlements @@ -2,9 +2,21 @@ - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - + aps-environment + development + com.apple.developer.aps-environment + development + com.apple.developer.icloud-container-identifiers + + iCloud.ch.ludoviko.Leganto + + com.apple.developer.icloud-services + + CloudKit + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + diff --git a/Leganto/en-GB.lproj/Localizable.strings b/Leganto/en-GB.lproj/Localizable.strings index eb8bf1b..86873dd 100644 --- a/Leganto/en-GB.lproj/Localizable.strings +++ b/Leganto/en-GB.lproj/Localizable.strings @@ -9,6 +9,7 @@ // General "feeds" = "Feeds"; "save" = "Save"; +"cancel" = "Cancel"; "name" = "Name"; "desc" = "Description"; "url" = "URL"; diff --git a/Leganto/eo.lproj/Localizable.strings b/Leganto/eo.lproj/Localizable.strings new file mode 100644 index 0000000..e78145f --- /dev/null +++ b/Leganto/eo.lproj/Localizable.strings @@ -0,0 +1,22 @@ +/* + Localizable.strings + Leganto + + Created by Louis Hollingworth on 2023-05-21. + +*/ + +// General +"feeds" = "Fluoj"; +"save" = "Konservi"; +"cancel" = "Nuligi"; +"name" = "Nomo"; +"desc" = "Priskribo"; +"url" = "URL"; +"genre" = "Ĝenro"; +"fadd" = "Aldoni Fluon"; + +// Genre categories +"uncategorised" = "Nekategoriigita"; +"technology" = "Teĥnologio"; +"news" = "Novaĵoj"; diff --git a/README.md b/README.md index 25437aa..7219f6b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Leganto +[![Weblate project translated](https://img.shields.io/weblate/progress/leganto?color=ef9f76&logo=weblate&logoColor=ef9f76&server=https%3A%2F%2Fi18n.ludoviko.ch&style=for-the-badge&labelColor=414559)](https://i18n.ludoviko.ch/projects/leganto/leganto-apple/) An RSS reader.