Change to not suggest root folder for Accounts that don't support it. Issue #1287

This commit is contained in:
Maurice Parker 2019-11-16 13:25:55 -06:00
parent 91a3e4fd73
commit 5ce5175bc0
6 changed files with 78 additions and 10 deletions

View File

@ -131,7 +131,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
public var sortedFolders: [Folder]? {
if let folders = folders {
return Array(folders).sorted(by: { $0.nameForDisplay > $1.nameForDisplay })
return Array(folders).sorted(by: { $0.nameForDisplay < $1.nameForDisplay })
}
return nil
}

View File

@ -128,6 +128,7 @@
51A1699D235E10D700EB091F /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A16993235E10D600EB091F /* SettingsViewController.swift */; };
51A1699F235E10D700EB091F /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A16995235E10D600EB091F /* AboutViewController.swift */; };
51A169A0235E10D700EB091F /* FeedbinAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A16996235E10D700EB091F /* FeedbinAccountViewController.swift */; };
51A66685238075AE00CB272D /* AddWebFeedDefaultContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51A66684238075AE00CB272D /* AddWebFeedDefaultContainer.swift */; };
51B62E68233186730085F949 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51B62E67233186730085F949 /* IconView.swift */; };
51BB7C272335A8E5008E8144 /* ArticleActivityItemSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51BB7C262335A8E5008E8144 /* ArticleActivityItemSource.swift */; };
51BB7C312335ACDE008E8144 /* page.html in Resources */ = {isa = PBXBuildFile; fileRef = 51BB7C302335ACDE008E8144 /* page.html */; };
@ -1290,6 +1291,7 @@
51A16993235E10D600EB091F /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
51A16995235E10D600EB091F /* AboutViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
51A16996235E10D700EB091F /* FeedbinAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbinAccountViewController.swift; sourceTree = "<group>"; };
51A66684238075AE00CB272D /* AddWebFeedDefaultContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedDefaultContainer.swift; sourceTree = "<group>"; };
51B62E67233186730085F949 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = "<group>"; };
51BB7C262335A8E5008E8144 /* ArticleActivityItemSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleActivityItemSource.swift; sourceTree = "<group>"; };
51BB7C302335ACDE008E8144 /* page.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = page.html; sourceTree = "<group>"; };
@ -1933,6 +1935,7 @@
51C452842265093600C03939 /* AddWebFeedViewController.swift */,
51E43961238037C400015C31 /* AddWebFeedFolderViewController.swift */,
51E4397F23805EBC00015C31 /* AddWebFeedFolderTableViewCell.swift */,
51A66684238075AE00CB272D /* AddWebFeedDefaultContainer.swift */,
);
path = Add;
sourceTree = "<group>";
@ -3929,6 +3932,7 @@
51FE10042345529D0056195D /* UserNotificationManager.swift in Sources */,
51C452A022650A1900C03939 /* WebFeedIconDownloader.swift in Sources */,
51C4529E22650A1900C03939 /* ImageDownloader.swift in Sources */,
51A66685238075AE00CB272D /* AddWebFeedDefaultContainer.swift in Sources */,
51C45292226509C800C03939 /* TodayFeedDelegate.swift in Sources */,
51C452A222650A1900C03939 /* RSHTMLMetadata+Extension.swift in Sources */,
514B7D1F23219F3C00BAC947 /* AddControllerType.swift in Sources */,

View File

@ -0,0 +1,51 @@
//
// AddWebFeedDefaultContainer.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 11/16/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
import Account
struct AddWebFeedDefaultContainer {
static var defaultContainer: Container? {
if let accountID = AppDefaults.addWebFeedAccountID, let account = AccountManager.shared.activeAccounts.first(where: { $0.accountID == accountID }) {
if let folderName = AppDefaults.addWebFeedFolderName, let folder = account.findFolder(withDisplayName: folderName) {
return folder
} else {
return substituteContainerIfNeeded(account: account)
}
} else if let account = AccountManager.shared.sortedActiveAccounts.first {
return substituteContainerIfNeeded(account: account)
} else {
return nil
}
}
static func storeDefaultContainer(_ container: Container) {
AppDefaults.addWebFeedAccountID = container.account?.accountID
if let folder = container as? Folder {
AppDefaults.addWebFeedFolderName = folder.nameForDisplay
} else {
AppDefaults.addWebFeedFolderName = nil
}
}
private static func substituteContainerIfNeeded(account: Account) -> Container? {
if !account.behaviors.contains(.disallowFeedInRootFolder) {
return account
} else {
if let folder = account.sortedFolders?.first {
return folder
} else {
return nil
}
}
}
}

View File

@ -68,11 +68,16 @@ class AddWebFeedFolderViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.accessoryType = .checkmark
let container = containers[indexPath.row]
delegate?.didSelect(container: containers[indexPath.row])
navigationController?.popViewController(animated: true)
if let account = container as? Account, account.behaviors.contains(.disallowFeedInRootFolder) {
tableView.selectRow(at: nil, animated: false, scrollPosition: .none)
} else {
let cell = tableView.cellForRow(at: indexPath)
cell?.accessoryType = .checkmark
delegate?.didSelect(container: container)
navigationController?.popViewController(animated: true)
}
}
}

View File

@ -48,10 +48,8 @@ class AddWebFeedViewController: UITableViewController, AddContainerViewControlle
nameTextField.text = initialFeedName
nameTextField.delegate = self
if let accountID = AppDefaults.addWebFeedAccountID, let account = AccountManager.shared.activeAccounts.first(where: { $0.accountID == accountID }) {
container = account
} else if let account = AccountManager.shared.sortedActiveAccounts.first {
container = account
if let defaultContainer = AddWebFeedDefaultContainer.defaultContainer {
container = defaultContainer
} else {
delegate?.readyToAdd(state: false)
}
@ -138,7 +136,7 @@ extension AddWebFeedViewController: AddWebFeedFolderViewControllerDelegate {
func didSelect(container: Container) {
self.container = container
updateFolderLabel()
AppDefaults.addWebFeedAccountID = container.account?.accountID
AddWebFeedDefaultContainer.storeDefaultContainer(container)
}
}

View File

@ -26,6 +26,7 @@ struct AppDefaults {
static let displayUndoAvailableTip = "displayUndoAvailableTip"
static let lastRefresh = "lastRefresh"
static let addWebFeedAccountID = "addWebFeedAccountID"
static let addWebFeedFolderName = "addWebFeedFolderName"
static let addFolderAccountID = "addFolderAccountID"
}
@ -46,6 +47,15 @@ struct AppDefaults {
}
}
static var addWebFeedFolderName: String? {
get {
return string(for: Key.addWebFeedFolderName)
}
set {
setString(for: Key.addWebFeedFolderName, newValue)
}
}
static var addFolderAccountID: String? {
get {
return string(for: Key.addFolderAccountID)