Implemented group by feed for iOS
This commit is contained in:
parent
045bc61684
commit
01c48e788b
|
@ -12,10 +12,11 @@ struct AppDefaults {
|
|||
|
||||
struct Key {
|
||||
static let firstRunDate = "firstRunDate"
|
||||
static let timelineGroupByFeed = "timelineGroupByFeed"
|
||||
static let timelineNumberOfLines = "timelineNumberOfLines"
|
||||
static let timelineSortDirection = "timelineSortDirection"
|
||||
static let refreshInterval = "refreshInterval"
|
||||
static let lastRefresh = "lastRefresh"
|
||||
static let timelineNumberOfLines = "timelineNumberOfLines"
|
||||
}
|
||||
|
||||
static let isFirstRun: Bool = {
|
||||
|
@ -35,6 +36,15 @@ struct AppDefaults {
|
|||
UserDefaults.standard.set(newValue.rawValue, forKey: Key.refreshInterval)
|
||||
}
|
||||
}
|
||||
|
||||
static var timelineGroupByFeed: Bool {
|
||||
get {
|
||||
return bool(for: Key.timelineGroupByFeed)
|
||||
}
|
||||
set {
|
||||
setBool(for: Key.timelineGroupByFeed, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
static var timelineSortDirection: ComparisonResult {
|
||||
get {
|
||||
|
@ -64,7 +74,10 @@ struct AppDefaults {
|
|||
}
|
||||
|
||||
static func registerDefaults() {
|
||||
let defaults: [String : Any] = [Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue, Key.refreshInterval: RefreshInterval.everyHour.rawValue, Key.timelineNumberOfLines: 3]
|
||||
let defaults: [String : Any] = [Key.refreshInterval: RefreshInterval.everyHour.rawValue,
|
||||
Key.timelineGroupByFeed: false,
|
||||
Key.timelineNumberOfLines: 3,
|
||||
Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue]
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,13 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||
}
|
||||
}
|
||||
}
|
||||
private(set) var groupByFeed = AppDefaults.timelineGroupByFeed {
|
||||
didSet {
|
||||
if groupByFeed != oldValue {
|
||||
groupByFeedDidChange()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let treeControllerDelegate = FeedTreeControllerDelegate()
|
||||
private lazy var treeController: TreeController = {
|
||||
|
@ -412,6 +419,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
|||
|
||||
@objc func userDefaultsDidChange(_ note: Notification) {
|
||||
self.sortDirection = AppDefaults.timelineSortDirection
|
||||
self.groupByFeed = AppDefaults.timelineGroupByFeed
|
||||
}
|
||||
|
||||
@objc func accountDidDownloadArticles(_ note: Notification) {
|
||||
|
@ -1344,8 +1352,12 @@ private extension SceneCoordinator {
|
|||
replaceArticles(with: Set(articles), animate: true)
|
||||
}
|
||||
|
||||
func groupByFeedDidChange() {
|
||||
replaceArticles(with: Set(articles), animate: true)
|
||||
}
|
||||
|
||||
func replaceArticles(with unsortedArticles: Set<Article>, animate: Bool) {
|
||||
let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection)
|
||||
let sortedArticles = Array(unsortedArticles).sortedByDate(sortDirection, groupByFeed: groupByFeed)
|
||||
|
||||
if articles != sortedArticles {
|
||||
|
||||
|
|
|
@ -56,6 +56,9 @@ struct SettingsView : View {
|
|||
Toggle(isOn: $viewModel.sortOldestToNewest) {
|
||||
Text("Sort Oldest to Newest")
|
||||
}
|
||||
Toggle(isOn: $viewModel.groupByFeed) {
|
||||
Text("Group By Feed")
|
||||
}
|
||||
Stepper(value: $viewModel.timelineNumberOfLines, in: 2...6) {
|
||||
Text("Number of Text Lines: \(viewModel.timelineNumberOfLines)")
|
||||
}
|
||||
|
@ -221,6 +224,16 @@ struct SettingsView : View {
|
|||
}
|
||||
}
|
||||
|
||||
var groupByFeed: Bool {
|
||||
get {
|
||||
return AppDefaults.timelineGroupByFeed
|
||||
}
|
||||
set {
|
||||
objectWillChange.send()
|
||||
AppDefaults.timelineGroupByFeed = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var timelineNumberOfLines: Int {
|
||||
get {
|
||||
return AppDefaults.timelineNumberOfLines
|
||||
|
|
Loading…
Reference in New Issue