Merge branch 'ios-candidate' of https://github.com/Ranchero-Software/NetNewsWire into ios-candidate

This commit is contained in:
Brent Simmons 2021-05-08 12:42:52 -07:00
commit 5490e3ab49
4 changed files with 60 additions and 21 deletions

View File

@ -16,8 +16,9 @@ import Articles
class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
private typealias UnclaimedWebFeed = (url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String)
private var unclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
private var newUnclaimedWebFeeds = [String: [UnclaimedWebFeed]]()
private var existingUnclaimedWebFeeds = [String: [WebFeed]]()
private var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "CloudKit")
weak var account: Account?
@ -75,7 +76,7 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
if let container = account.existingContainer(withExternalID: containerExternalID) {
createWebFeedIfNecessary(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, container: container)
} else {
addUnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, containerExternalID: containerExternalID)
addNewUnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: record.externalID, containerExternalID: containerExternalID)
}
}
}
@ -106,19 +107,27 @@ class CloudKitAcountZoneDelegate: CloudKitZoneDelegate {
folder?.externalID = record.externalID
}
if let folder = folder, let containerExternalID = folder.externalID, let unclaimedWebFeeds = unclaimedWebFeeds[containerExternalID] {
for unclaimedWebFeed in unclaimedWebFeeds {
createWebFeedIfNecessary(url: unclaimedWebFeed.url,
name: unclaimedWebFeed.name,
editedName: unclaimedWebFeed.editedName,
homePageURL: unclaimedWebFeed.homePageURL,
webFeedExternalID: unclaimedWebFeed.webFeedExternalID,
guard let folder = folder, let containerExternalID = folder.externalID else { return }
if let newUnclaimedWebFeeds = newUnclaimedWebFeeds[containerExternalID] {
for newUnclaimedWebFeed in newUnclaimedWebFeeds {
createWebFeedIfNecessary(url: newUnclaimedWebFeed.url,
name: newUnclaimedWebFeed.name,
editedName: newUnclaimedWebFeed.editedName,
homePageURL: newUnclaimedWebFeed.homePageURL,
webFeedExternalID: newUnclaimedWebFeed.webFeedExternalID,
container: folder)
}
self.unclaimedWebFeeds.removeValue(forKey: containerExternalID)
self.newUnclaimedWebFeeds.removeValue(forKey: containerExternalID)
}
if let existingUnclaimedWebFeeds = existingUnclaimedWebFeeds[containerExternalID] {
for existingUnclaimedWebFeed in existingUnclaimedWebFeeds {
folder.addWebFeed(existingUnclaimedWebFeed)
}
self.existingUnclaimedWebFeeds.removeValue(forKey: containerExternalID)
}
}
func removeContainer(_ externalID: String) {
@ -152,6 +161,8 @@ private extension CloudKitAcountZoneDelegate {
case .insert(_, let externalID, _):
if let container = account.existingContainer(withExternalID: externalID) {
container.addWebFeed(webFeed)
} else {
addExistingUnclaimedWebFeed(webFeed, containerExternalID: externalID)
}
}
}
@ -170,14 +181,25 @@ private extension CloudKitAcountZoneDelegate {
container.addWebFeed(webFeed)
}
func addUnclaimedWebFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, containerExternalID: String) {
if var unclaimedWebFeeds = self.unclaimedWebFeeds[containerExternalID] {
func addNewUnclaimedWebFeed(url: URL, name: String?, editedName: String?, homePageURL: String?, webFeedExternalID: String, containerExternalID: String) {
if var unclaimedWebFeeds = self.newUnclaimedWebFeeds[containerExternalID] {
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
self.newUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
} else {
var unclaimedWebFeeds = [UnclaimedWebFeed]()
unclaimedWebFeeds.append(UnclaimedWebFeed(url: url, name: name, editedName: editedName, homePageURL: homePageURL, webFeedExternalID: webFeedExternalID))
self.unclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
self.newUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
}
}
func addExistingUnclaimedWebFeed(_ webFeed: WebFeed, containerExternalID: String) {
if var unclaimedWebFeeds = self.existingUnclaimedWebFeeds[containerExternalID] {
unclaimedWebFeeds.append(webFeed)
self.existingUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
} else {
var unclaimedWebFeeds = [WebFeed]()
unclaimedWebFeeds.append(webFeed)
self.existingUnclaimedWebFeeds[containerExternalID] = unclaimedWebFeeds
}
}

View File

@ -10,7 +10,7 @@ import Foundation
import RSParser
import RSCore
final class FeedbinEntry: Codable {
final class FeedbinEntry: Decodable {
let articleID: Int
let feedID: Int
@ -50,14 +50,25 @@ final class FeedbinEntry: Codable {
}
}
struct FeedbinEntryJSONFeed: Codable {
struct FeedbinEntryJSONFeed: Decodable {
let jsonFeedAuthor: FeedbinEntryJSONFeedAuthor?
enum CodingKeys: String, CodingKey {
case jsonFeedAuthor = "author"
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
do {
jsonFeedAuthor = try container.decode(FeedbinEntryJSONFeedAuthor.self, forKey: .jsonFeedAuthor)
} catch {
jsonFeedAuthor = nil
}
}
}
struct FeedbinEntryJSONFeedAuthor: Codable {
struct FeedbinEntryJSONFeedAuthor: Decodable {
let url: String?
let avatarURL: String?
enum CodingKeys: String, CodingKey {

View File

@ -79,6 +79,13 @@ class WebViewController: UIViewController {
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
// We need to reload the webview on the iPhone when rotation happens to clear out any old bad viewport sizes
if traitCollection.userInterfaceIdiom == .phone {
loadWebView()
}
}
// MARK: Notifications
@objc func webFeedIconDidBecomeAvailable(_ note: Notification) {

View File

@ -1340,13 +1340,12 @@ private extension MasterFeedViewController {
ActivityManager.cleanUp(feed)
}
pushUndoableCommand(deleteCommand)
deleteCommand.perform()
if indexPath == coordinator.currentFeedIndexPath {
coordinator.selectFeed(indexPath: nil)
}
pushUndoableCommand(deleteCommand)
deleteCommand.perform()
}
}