2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// DefaultFeedsImporter.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 8/13/15.
|
|
|
|
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2017-09-17 21:22:15 +02:00
|
|
|
import Data
|
2017-09-17 21:34:10 +02:00
|
|
|
import Account
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
private func shouldImportDefaultFeeds(_ isFirstRun: Bool) -> Bool {
|
|
|
|
|
|
|
|
if !isFirstRun {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-09-24 21:24:44 +02:00
|
|
|
for oneAccount in AccountManager.shared.accounts {
|
2017-05-27 19:43:27 +02:00
|
|
|
if oneAccount.hasAtLeastOneFeed {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
private func defaultFeedsArray() -> NSArray {
|
|
|
|
|
|
|
|
let f = Bundle.main.path(forResource: "DefaultFeeds", ofType: "plist")!
|
|
|
|
return NSArray(contentsOfFile: f)!
|
|
|
|
}
|
|
|
|
|
|
|
|
private func importFeedsWithArray(_ defaultFeeds: NSArray, _ account: Account) {
|
|
|
|
|
|
|
|
for d in defaultFeeds {
|
|
|
|
|
|
|
|
guard let oneFeedDictionary = d as? NSDictionary else {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
let oneFeed = LocalFeed(account: account, diskDictionary: oneFeedDictionary)!
|
|
|
|
let _ = account.addItem(oneFeed)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func importDefaultFeedsIfNeeded(_ isFirstRun: Bool, account: Account) {
|
|
|
|
|
|
|
|
if !shouldImportDefaultFeeds(isFirstRun) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
importFeedsWithArray(defaultFeedsArray(), account)
|
|
|
|
}
|