From 8ba7a5fa6ef7274339c3c709a2babb790e11e32b Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Fri, 10 May 2024 16:52:28 -0700 Subject: Further work on threaded news UI: better icons, tweaked indentation, post count, keyboard navigation. --- .../News Bundle.imageset/Contents.json | 6 +-- .../News Bundle.imageset/Frame 3.png | Bin 405 -> 0 bytes .../News Bundle.imageset/Frame 3@2x.png | Bin 988 -> 0 bytes .../News Bundle.imageset/Frame 3@3x.png | Bin 1783 -> 0 bytes .../News Bundle.imageset/News Bundle.png | Bin 0 -> 307 bytes .../News Bundle.imageset/News Bundle@2x.png | Bin 0 -> 471 bytes .../News Bundle.imageset/News Bundle@3x.png | Bin 0 -> 646 bytes .../News Category.imageset/Contents.json | 6 +-- .../News Category.imageset/Frame 1.png | Bin 402 -> 0 bytes .../News Category.imageset/Frame 1@2x.png | Bin 777 -> 0 bytes .../News Category.imageset/Frame 1@3x.png | Bin 1178 -> 0 bytes .../News Category.imageset/News Category.png | Bin 0 -> 355 bytes .../News Category.imageset/News Category@2x.png | Bin 0 -> 647 bytes .../News Category.imageset/News Category@3x.png | Bin 0 -> 993 bytes Hotline/Models/Hotline.swift | 1 + Hotline/Models/NewsInfo.swift | 4 ++ Hotline/macOS/NewsView.swift | 50 ++++++++++++--------- 17 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 Hotline/Assets.xcassets/News Bundle.imageset/Frame 3.png delete mode 100644 Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@2x.png delete mode 100644 Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@3x.png create mode 100644 Hotline/Assets.xcassets/News Bundle.imageset/News Bundle.png create mode 100644 Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@2x.png create mode 100644 Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@3x.png delete mode 100644 Hotline/Assets.xcassets/News Category.imageset/Frame 1.png delete mode 100644 Hotline/Assets.xcassets/News Category.imageset/Frame 1@2x.png delete mode 100644 Hotline/Assets.xcassets/News Category.imageset/Frame 1@3x.png create mode 100644 Hotline/Assets.xcassets/News Category.imageset/News Category.png create mode 100644 Hotline/Assets.xcassets/News Category.imageset/News Category@2x.png create mode 100644 Hotline/Assets.xcassets/News Category.imageset/News Category@3x.png diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/Contents.json b/Hotline/Assets.xcassets/News Bundle.imageset/Contents.json index bfb6d35..4c19d5a 100644 --- a/Hotline/Assets.xcassets/News Bundle.imageset/Contents.json +++ b/Hotline/Assets.xcassets/News Bundle.imageset/Contents.json @@ -1,17 +1,17 @@ { "images" : [ { - "filename" : "Frame 3.png", + "filename" : "News Bundle.png", "idiom" : "universal", "scale" : "1x" }, { - "filename" : "Frame 3@2x.png", + "filename" : "News Bundle@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "Frame 3@3x.png", + "filename" : "News Bundle@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3.png b/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3.png deleted file mode 100644 index 46d144d..0000000 Binary files a/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3.png and /dev/null differ diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@2x.png b/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@2x.png deleted file mode 100644 index 2dbb989..0000000 Binary files a/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@2x.png and /dev/null differ diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@3x.png b/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@3x.png deleted file mode 100644 index 649ab86..0000000 Binary files a/Hotline/Assets.xcassets/News Bundle.imageset/Frame 3@3x.png and /dev/null differ diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle.png b/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle.png new file mode 100644 index 0000000..83e97ed Binary files /dev/null and b/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle.png differ diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@2x.png b/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@2x.png new file mode 100644 index 0000000..114f547 Binary files /dev/null and b/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@2x.png differ diff --git a/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@3x.png b/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@3x.png new file mode 100644 index 0000000..db8bb27 Binary files /dev/null and b/Hotline/Assets.xcassets/News Bundle.imageset/News Bundle@3x.png differ diff --git a/Hotline/Assets.xcassets/News Category.imageset/Contents.json b/Hotline/Assets.xcassets/News Category.imageset/Contents.json index 7245ec5..ee9c6aa 100644 --- a/Hotline/Assets.xcassets/News Category.imageset/Contents.json +++ b/Hotline/Assets.xcassets/News Category.imageset/Contents.json @@ -1,17 +1,17 @@ { "images" : [ { - "filename" : "Frame 1.png", + "filename" : "News Category.png", "idiom" : "universal", "scale" : "1x" }, { - "filename" : "Frame 1@2x.png", + "filename" : "News Category@2x.png", "idiom" : "universal", "scale" : "2x" }, { - "filename" : "Frame 1@3x.png", + "filename" : "News Category@3x.png", "idiom" : "universal", "scale" : "3x" } diff --git a/Hotline/Assets.xcassets/News Category.imageset/Frame 1.png b/Hotline/Assets.xcassets/News Category.imageset/Frame 1.png deleted file mode 100644 index 1c3a080..0000000 Binary files a/Hotline/Assets.xcassets/News Category.imageset/Frame 1.png and /dev/null differ diff --git a/Hotline/Assets.xcassets/News Category.imageset/Frame 1@2x.png b/Hotline/Assets.xcassets/News Category.imageset/Frame 1@2x.png deleted file mode 100644 index e1bce20..0000000 Binary files a/Hotline/Assets.xcassets/News Category.imageset/Frame 1@2x.png and /dev/null differ diff --git a/Hotline/Assets.xcassets/News Category.imageset/Frame 1@3x.png b/Hotline/Assets.xcassets/News Category.imageset/Frame 1@3x.png deleted file mode 100644 index 6a16cef..0000000 Binary files a/Hotline/Assets.xcassets/News Category.imageset/Frame 1@3x.png and /dev/null differ diff --git a/Hotline/Assets.xcassets/News Category.imageset/News Category.png b/Hotline/Assets.xcassets/News Category.imageset/News Category.png new file mode 100644 index 0000000..2667489 Binary files /dev/null and b/Hotline/Assets.xcassets/News Category.imageset/News Category.png differ diff --git a/Hotline/Assets.xcassets/News Category.imageset/News Category@2x.png b/Hotline/Assets.xcassets/News Category.imageset/News Category@2x.png new file mode 100644 index 0000000..c92ca23 Binary files /dev/null and b/Hotline/Assets.xcassets/News Category.imageset/News Category@2x.png differ diff --git a/Hotline/Assets.xcassets/News Category.imageset/News Category@3x.png b/Hotline/Assets.xcassets/News Category.imageset/News Category@3x.png new file mode 100644 index 0000000..e64c7e6 Binary files /dev/null and b/Hotline/Assets.xcassets/News Category.imageset/News Category@3x.png differ diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift index 48266a9..5dc61ab 100644 --- a/Hotline/Models/Hotline.swift +++ b/Hotline/Models/Hotline.swift @@ -387,6 +387,7 @@ class Hotline: Equatable, HotlineClientDelegate, HotlineFileClientDelegate { if let parentID = article.parentID, parentID != 0, let parentArticle = articleMap[parentID] { + article.expanded = true parentArticle.children.append(article) } else { diff --git a/Hotline/Models/NewsInfo.swift b/Hotline/Models/NewsInfo.swift index b635138..eecd550 100644 --- a/Hotline/Models/NewsInfo.swift +++ b/Hotline/Models/NewsInfo.swift @@ -26,6 +26,10 @@ enum NewsInfoType { var articleDate: Date? var read: Bool = false + var expandable: Bool { + self.type == .bundle || self.type == .category || self.children.count > 0 + } + init(hotlineNewsCategory: HotlineNewsCategory) { self.categoryID = hotlineNewsCategory.id self.articleID = nil diff --git a/Hotline/macOS/NewsView.swift b/Hotline/macOS/NewsView.swift index e87a7f0..906a9a4 100644 --- a/Hotline/macOS/NewsView.swift +++ b/Hotline/macOS/NewsView.swift @@ -151,14 +151,14 @@ struct NewsView: View { } } .onKeyPress(.rightArrow) { - if let s = selection, s.type == .bundle || s.type == .category { + if let s = selection, s.expandable { s.expanded = true return .handled } return .ignored } .onKeyPress(.leftArrow) { - if let s = selection, s.type == .bundle || s.type == .category { + if let s = selection, s.expandable { s.expanded = false return .handled } @@ -248,7 +248,7 @@ struct NewsItemView: View { var body: some View { HStack(alignment: .center, spacing: 6) { - if news.type == .bundle || news.type == .category || news.children.count > 0 { + if news.expandable { Button { news.expanded.toggle() } label: { @@ -260,16 +260,16 @@ struct NewsItemView: View { } .buttonStyle(.plain) .frame(width: 10) - .padding(.leading, 4) + .padding(.leading, 2) } else { Spacer() - .frame(width: 14) + .frame(width: 12) } // Tree indent Spacer() - .frame(width: CGFloat(max(0, depth-1)) * 16) + .frame(width: (CGFloat(depth) * 22)) switch news.type { case .category: @@ -281,8 +281,7 @@ struct NewsItemView: View { .resizable() .frame(width: 16, height: 16) case .article: - Spacer() - .frame(width: 16) + EmptyView() } Text(news.name) @@ -294,12 +293,26 @@ struct NewsItemView: View { } Spacer() if news.type == .bundle || news.type == .category { - Text("^[\(news.count) \(news.type == .bundle ? "Category" : "Post")](inflect: true)") - .foregroundStyle(.secondary) - .lineLimit(1) - .padding([.leading, .trailing], 8) - .padding([.top, .bottom], 2) - .background(Capsule(style: .circular).stroke(.secondary.opacity(0.3), lineWidth: 1)) + ZStack { + + Text("^[\(news.count) \(news.type == .bundle ? "Category" : "Post")](inflect: true)") + .foregroundStyle(.clear) + .font(.caption) + .lineLimit(1) + .padding([.leading, .trailing], 8) + .padding([.top, .bottom], 2) + .background(.tertiary) + .clipShape(Capsule()) + + Text("^[\(news.count) \(news.type == .bundle ? "Category" : "Post")](inflect: true)") + .foregroundStyle(.white) + .font(.caption) + .lineLimit(1) + .padding([.leading, .trailing], 8) + .padding([.top, .bottom], 2) + .blendMode(.destinationOut) + } + .drawingGroup(opaque: false) } if news.type == .article && news.articleUsername != nil { if let d = news.articleDate { @@ -309,15 +322,12 @@ struct NewsItemView: View { } .frame(maxWidth: .infinity, maxHeight: .infinity) .onChange(of: news.expanded) { - guard news.expanded else { + guard news.expanded, news.type == .bundle || news.type == .category else { return } - news.read = true - if news.type == .bundle || news.type == .category { - Task { - await model.getNewsList(at: news.path) - } + Task { + await model.getNewsList(at: news.path) } } -- cgit