Merge pull request #2910 from stuartbreckenridge/widget-fetch-changes
Widget fetch changes
This commit is contained in:
commit
ed4896890d
|
@ -53,9 +53,9 @@ public enum AccountType: Int, Codable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum FetchType {
|
public enum FetchType {
|
||||||
case starred(Int?)
|
case starred(_: Int? = nil)
|
||||||
case unread(Int?)
|
case unread(_: Int? = nil)
|
||||||
case today(Int?)
|
case today(_: Int? = nil)
|
||||||
case folder(Folder, Bool)
|
case folder(Folder, Bool)
|
||||||
case webFeed(WebFeed)
|
case webFeed(WebFeed)
|
||||||
case articleIDs(Set<String>)
|
case articleIDs(Set<String>)
|
||||||
|
|
|
@ -12,11 +12,13 @@ import os.log
|
||||||
import UIKit
|
import UIKit
|
||||||
import RSCore
|
import RSCore
|
||||||
import Articles
|
import Articles
|
||||||
|
import Account
|
||||||
|
|
||||||
|
|
||||||
public final class WidgetDataEncoder {
|
public final class WidgetDataEncoder {
|
||||||
|
|
||||||
private let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
private let log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
|
||||||
|
private let fetchLimit = 7
|
||||||
|
|
||||||
private var backgroundTaskID: UIBackgroundTaskIdentifier!
|
private var backgroundTaskID: UIBackgroundTaskIdentifier!
|
||||||
private lazy var appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
private lazy var appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
|
||||||
|
@ -31,11 +33,9 @@ public final class WidgetDataEncoder {
|
||||||
os_log(.debug, log: log, "Starting encoding widget data.")
|
os_log(.debug, log: log, "Starting encoding widget data.")
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let unreadArticles = Array(try SmartFeedsController.shared.unreadFeed.fetchArticles()).sortedByDate(.orderedDescending)
|
let unreadArticles = Array(try AccountManager.shared.fetchArticles(.unread(fetchLimit))).sortedByDate(.orderedDescending)
|
||||||
|
let starredArticles = Array(try AccountManager.shared.fetchArticles(.starred(fetchLimit))).sortedByDate(.orderedDescending)
|
||||||
let starredArticles = Array(try SmartFeedsController.shared.starredFeed.fetchArticles()).sortedByDate(.orderedDescending)
|
let todayArticles = Array(try AccountManager.shared.fetchArticles(.today(fetchLimit))).sortedByDate(.orderedDescending)
|
||||||
|
|
||||||
let todayArticles = Array(try SmartFeedsController.shared.todayFeed.fetchUnreadArticles()).sortedByDate(.orderedDescending)
|
|
||||||
|
|
||||||
var unread = [LatestArticle]()
|
var unread = [LatestArticle]()
|
||||||
var today = [LatestArticle]()
|
var today = [LatestArticle]()
|
||||||
|
@ -74,9 +74,9 @@ public final class WidgetDataEncoder {
|
||||||
if today.count == 7 { break }
|
if today.count == 7 { break }
|
||||||
}
|
}
|
||||||
|
|
||||||
let latestData = WidgetData(currentUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount,
|
let latestData = WidgetData(currentUnreadCount: try! AccountManager.shared.fetchArticles(.unread()).count,
|
||||||
currentTodayCount: try! SmartFeedsController.shared.todayFeed.fetchUnreadArticles().count,
|
currentTodayCount: try! AccountManager.shared.fetchArticles(.today()).count,
|
||||||
currentStarredCount: try! SmartFeedsController.shared.starredFeed.fetchArticles().count,
|
currentStarredCount: try! AccountManager.shared.fetchArticles(.starred()).count,
|
||||||
unreadArticles: unread,
|
unreadArticles: unread,
|
||||||
starredArticles: starred,
|
starredArticles: starred,
|
||||||
todayArticles:today,
|
todayArticles:today,
|
||||||
|
|
|
@ -1235,7 +1235,7 @@ private extension MasterFeedViewController {
|
||||||
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, account.nameForDisplay) as String
|
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, account.nameForDisplay) as String
|
||||||
let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in
|
let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in
|
||||||
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
|
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
|
||||||
if let articles = try? account.fetchArticles(.unread) {
|
if let articles = try? account.fetchArticles(.unread()) {
|
||||||
self?.coordinator.markAllAsRead(Array(articles))
|
self?.coordinator.markAllAsRead(Array(articles))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue