Merge pull request #5 from Ranchero-Software/swiftui

Swiftui
This commit is contained in:
Stuart Breckenridge 2020-07-02 20:11:40 +08:00 committed by GitHub
commit 00e498e826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 7 deletions

View File

@ -14,7 +14,7 @@ enum FontSize: Int {
case veryLarge = 3
}
struct AppDefaults {
final class AppDefaults {
static var shared = AppDefaults()
private init() {}

View File

@ -27,6 +27,7 @@ struct MainApp: App {
SceneNavigationView()
.frame(minWidth: 600, idealWidth: 1000, maxWidth: .infinity, minHeight: 600, idealHeight: 700, maxHeight: .infinity)
.environmentObject(sceneModel)
.environmentObject(defaults)
.toolbar {
ToolbarItem {
@ -144,6 +145,7 @@ struct MainApp: App {
WindowGroup {
SceneNavigationView()
.environmentObject(sceneModel)
.environmentObject(defaults)
}.commands {
CommandGroup(after: .newItem, addition: {
Button("New Feed", action: {})

View File

@ -10,7 +10,9 @@ import SwiftUI
struct TimelineItemView: View {
@EnvironmentObject var defaults: AppDefaults
@StateObject var articleIconImageLoader = ArticleIconImageLoader()
var timelineItem: TimelineItem
var body: some View {
@ -19,12 +21,12 @@ struct TimelineItemView: View {
TimelineItemStatusView(status: timelineItem.status)
if let image = articleIconImageLoader.image {
IconImageView(iconImage: image)
.frame(width: AppDefaults.timelineIconSize.size.width, height: AppDefaults.timelineIconSize.size.height, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
.frame(width: CGFloat(defaults.timelineIconSize), height: CGFloat(defaults.timelineIconSize), alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
}
VStack {
Text(verbatim: timelineItem.article.title ?? "N/A")
.fontWeight(.semibold)
.lineLimit(AppDefaults.timelineNumberOfLines)
.lineLimit(defaults.timelineNumberOfLines)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.trailing, 4)
Spacer()

View File

@ -29,7 +29,7 @@ class TimelineModel: ObservableObject {
private var articles = [Article]()
private var sortDirection = AppDefaults.timelineSortDirection {
private var sortDirection = AppDefaults.shared.timelineSortDirection {
didSet {
if sortDirection != oldValue {
sortParametersDidChange()
@ -37,7 +37,7 @@ class TimelineModel: ObservableObject {
}
}
private var groupByFeed = AppDefaults.timelineGroupByFeed {
private var groupByFeed = AppDefaults.shared.timelineGroupByFeed {
didSet {
if groupByFeed != oldValue {
sortParametersDidChange()
@ -111,7 +111,7 @@ private extension TimelineModel {
}
func replaceArticles(with unsortedArticles: Set<Article>) {
articles = Array(unsortedArticles).sortedByDate(sortDirection, groupByFeed: groupByFeed)
articles = Array(unsortedArticles).sortedByDate(sortDirection ? .orderedDescending : .orderedAscending, groupByFeed: groupByFeed)
timelineItems = articles.map { TimelineItem(article: $0) }
// TODO: Update unread counts and other item done in didSet on AppKit

View File

@ -26,7 +26,7 @@ enum UserInterfaceColorPalette: Int, CustomStringConvertible, CaseIterable {
}
class AppDefaults {
final class AppDefaults {
static let shared = AppDefaults()
private init() {}