From 7a41b411c8884fb900ce76626801fe8d2ec30128 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Tue, 20 Dec 2022 09:03:42 +0800 Subject: [PATCH] WIP on Timeline Customiser --- NetNewsWire.xcodeproj/project.pbxproj | 4 + iOS/AppDefaults.swift | 2 + iOS/Settings/Settings.strings | 2 + .../TimelinePreviewTableViewController.swift | 17 +++ .../Appearance/TimelineCustomizerView.swift | 113 ++++++++++++++++++ iOS/Settings/Views/General/SettingsRows.swift | 4 +- 6 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 iOS/Settings/Views/Appearance/TimelineCustomizerView.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 619b6f144..508e6a3d3 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -855,6 +855,7 @@ DF5AD10128D6922200CA3BF7 /* SmartFeedSummaryWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1768144D2564BCE000D98635 /* SmartFeedSummaryWidget.swift */; }; DF766FED29377FD9006FBBE2 /* ExtensionsManagementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF766FEC29377FD9006FBBE2 /* ExtensionsManagementView.swift */; }; DF790D6228E990A900455FC7 /* AboutData.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF790D6128E990A900455FC7 /* AboutData.swift */; }; + DF84E563295122BA0045C334 /* TimelineCustomizerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF84E562295122BA0045C334 /* TimelineCustomizerView.swift */; }; DFB3497A294A962D00BC81AD /* AddAccountListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB34979294A962D00BC81AD /* AddAccountListView.swift */; }; DFB34980294B085100BC81AD /* AccountInspectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFB3497F294B085100BC81AD /* AccountInspectorView.swift */; }; DFB34982294B0B9B00BC81AD /* Inspector.strings in Resources */ = {isa = PBXBuildFile; fileRef = DFB34981294B0B9B00BC81AD /* Inspector.strings */; }; @@ -1620,6 +1621,7 @@ DF59F0732920DB5100ACD33D /* AccountsManagementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsManagementView.swift; sourceTree = ""; }; DF766FEC29377FD9006FBBE2 /* ExtensionsManagementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionsManagementView.swift; sourceTree = ""; }; DF790D6128E990A900455FC7 /* AboutData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutData.swift; sourceTree = ""; }; + DF84E562295122BA0045C334 /* TimelineCustomizerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineCustomizerView.swift; sourceTree = ""; }; DFB34979294A962D00BC81AD /* AddAccountListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAccountListView.swift; sourceTree = ""; }; DFB3497F294B085100BC81AD /* AccountInspectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountInspectorView.swift; sourceTree = ""; }; DFB34981294B0B9B00BC81AD /* Inspector.strings */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; path = Inspector.strings; sourceTree = ""; }; @@ -3042,6 +3044,7 @@ children = ( DFD406FE291FDC0C00C02962 /* DisplayAndBehaviorsView.swift */, DF59F071292085B800ACD33D /* ColorPaletteSelectorView.swift */, + DF84E562295122BA0045C334 /* TimelineCustomizerView.swift */, ); path = Appearance; sourceTree = ""; @@ -4368,6 +4371,7 @@ 51C4529B22650A1000C03939 /* FaviconDownloader.swift in Sources */, 84DEE56622C32CA4005FC42C /* SmartFeedDelegate.swift in Sources */, DF28B44F294ED92F00C4D8CA /* NewsBlurAddAccountView.swift in Sources */, + DF84E563295122BA0045C334 /* TimelineCustomizerView.swift in Sources */, 512E09012268907400BDCFDD /* MasterFeedTableViewSectionHeader.swift in Sources */, 512392BF24E33A3C00F11704 /* RedditSelectSortTableViewController.swift in Sources */, 516AE9E02372269A007DEEAA /* IconImage.swift in Sources */, diff --git a/iOS/AppDefaults.swift b/iOS/AppDefaults.swift index 2bcb5eb17..4d68d6b4a 100644 --- a/iOS/AppDefaults.swift +++ b/iOS/AppDefaults.swift @@ -231,6 +231,7 @@ final class AppDefaults: ObservableObject { } set { AppDefaults.setInt(for: Key.timelineNumberOfLines, newValue) + objectWillChange.send() } } @@ -241,6 +242,7 @@ final class AppDefaults: ObservableObject { } set { AppDefaults.store.set(newValue.rawValue, forKey: Key.timelineIconDimension) + objectWillChange.send() } } diff --git a/iOS/Settings/Settings.strings b/iOS/Settings/Settings.strings index 5462e5feb..ba1cc744e 100644 --- a/iOS/Settings/Settings.strings +++ b/iOS/Settings/Settings.strings @@ -41,6 +41,8 @@ "GROUP_BY_FEED" = "Group by Feed"; "REFRESH_TO_CLEAR_READ_ARTICLES" = "Refresh to Clear Articles"; "TIMELINE_LAYOUT" = "Timeline Layout"; +"ICON_SIZE" = "Icon Size"; +"NUMBER_OF_LINES" = "Number of Lines"; "ARTICLE_THEME" = "Article Theme"; "CONFIRM_MARK_ALL_AS_READ" = "Confirm Mark All as Read"; "OPEN_LINKS_IN_APP" = "Open Links in NetNewsWire"; diff --git a/iOS/Settings/TimelinePreviewTableViewController.swift b/iOS/Settings/TimelinePreviewTableViewController.swift index ad65dd052..919c4b0e6 100644 --- a/iOS/Settings/TimelinePreviewTableViewController.swift +++ b/iOS/Settings/TimelinePreviewTableViewController.swift @@ -8,6 +8,23 @@ import UIKit import Articles +import SwiftUI + +struct TimelinePreviewWrapper: UIViewControllerRepresentable { + + func makeUIViewController(context: Context) -> TimelinePreviewTableViewController { + let controller = UIStoryboard.settings.instantiateViewController(withIdentifier: "TimelinePreviewTableViewController") as! TimelinePreviewTableViewController + return controller + } + + func updateUIViewController(_ uiViewController: TimelinePreviewTableViewController, context: Context) { + // + } + + typealias UIViewControllerType = TimelinePreviewTableViewController + +} + class TimelinePreviewTableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { diff --git a/iOS/Settings/Views/Appearance/TimelineCustomizerView.swift b/iOS/Settings/Views/Appearance/TimelineCustomizerView.swift new file mode 100644 index 000000000..912d1bc88 --- /dev/null +++ b/iOS/Settings/Views/Appearance/TimelineCustomizerView.swift @@ -0,0 +1,113 @@ +// +// TimelineCustomizerView.swift +// NetNewsWire-iOS +// +// Created by Stuart Breckenridge on 20/12/2022. +// Copyright © 2022 Ranchero Software. All rights reserved. +// + +import SwiftUI + + +struct TimelineCustomizerView: View { + + @StateObject private var appDefaults = AppDefaults.shared + + var body: some View { + List { + Section(header: Text("ICON_SIZE", tableName: "Settings")) { + Slider(value: Binding(get: { Float(appDefaults.timelineIconSize.rawValue) }, + set: { appDefaults.timelineIconSize = IconSize(rawValue: Int($0))! }), + in: Float(IconSize.small.rawValue)...Float(IconSize.large.rawValue), + step: 1, + label: { Text("ICON_SIZE", tableName: "Settings") }, + onEditingChanged: { _ in + }) + .tint(Color(uiColor: AppAssets.primaryAccentColor)) + .padding(.horizontal, 16) + .padding(.vertical, 8) + .listRowInsets(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15)) + .background( + RoundedRectangle(cornerRadius: 8) + .foregroundColor(Color(uiColor: UIColor.systemBackground)) + ) + + } + .listRowInsets(EdgeInsets(top: 0, leading: 30, bottom: 0, trailing: 30)) + .listRowBackground(Color.clear) + .listRowSeparator(.hidden) + + Section(header: Text("NUMBER_OF_LINES", tableName: "Settings")) { + Slider(value: Binding(get: { Float(appDefaults.timelineNumberOfLines) }, + set: { appDefaults.timelineNumberOfLines = Int($0) }), + in: 1...5, + step: 1, + label: { Text("NUMBER_OF_LINES", tableName: "Settings") }, + onEditingChanged: { _ in + }) + .tint(Color(uiColor: AppAssets.primaryAccentColor)) + .padding(.horizontal, 16) + .padding(.vertical, 8) + .listRowInsets(EdgeInsets(top: 0, leading: 15, bottom: 0, trailing: 15)) + .background( + RoundedRectangle(cornerRadius: 8) + .foregroundColor(Color(uiColor: UIColor.systemBackground)) + ) + } + .listRowInsets(EdgeInsets(top: 0, leading: 30, bottom: 0, trailing: 30)) + .listRowBackground(Color.clear) + .listRowSeparator(.hidden) + + Section { + timeLinePreviewRow + .listRowInsets(EdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 28)) + } + } + .listStyle(.grouped) + .navigationTitle(Text("TIMELINE_LAYOUT", tableName: "Settings")) + } + + var timeLinePreviewRow: some View { + HStack(spacing: 6) { + VStack { + Circle() + .foregroundColor(Color(uiColor: AppAssets.primaryAccentColor)) + .frame(width: 12, height: 12) + Spacer() + }.frame(width: 12) + VStack { + Image(systemName: "globe.europe.africa.fill") + .resizable() + .frame(width: appDefaults.timelineIconSize.size.width, height: appDefaults.timelineIconSize.size.height) + .foregroundColor(Color(uiColor: AppAssets.primaryAccentColor)) + Spacer() + }.frame(width: appDefaults.timelineIconSize.size.width) + VStack(spacing: 4) { + Text("Enim ut tellus elementum sagittis vitae et. Nibh praesent tristique magna sit amet purus gravida quis blandit. Neque volutpat ac tincidunt vitae semper quis lectus nulla. Massa id neque aliquam vestibulum morbi blandit. Ultrices vitae auctor eu augue. Enim eu turpis egestas pretium aenean pharetra magna. Eget gravida cum sociis natoque. Sit amet consectetur adipiscing elit. Auctor eu augue ut lectus arcu bibendum. Maecenas volutpat blandit aliquam etiam erat velit. Ut pharetra sit amet aliquam id diam maecenas ultricies. In hac habitasse platea dictumst quisque sagittis purus sit amet.") + .bold() + .lineLimit(appDefaults.timelineNumberOfLines) + HStack { + Text("Feed name") + .foregroundColor(.secondary) + .font(.caption) + Spacer() + Text("08:51") + .foregroundColor(.secondary) + .font(.caption) + }.padding(0) + } + } + .edgesIgnoringSafeArea(.all) + .padding(.vertical, 4) + .padding(.leading, 4) + + } + + +} + +struct TimelineCustomizerView_Previews: PreviewProvider { + static var previews: some View { + TimelineCustomizerView() + } +} diff --git a/iOS/Settings/Views/General/SettingsRows.swift b/iOS/Settings/Views/General/SettingsRows.swift index a6e0d2685..ef2c306f3 100644 --- a/iOS/Settings/Views/General/SettingsRows.swift +++ b/iOS/Settings/Views/General/SettingsRows.swift @@ -144,7 +144,9 @@ struct SettingsViewRows { /// This row, when tapped, will push the the Timeline Layout screen /// in to view. static var timelineLayout: some View { - NavigationLink(destination: TimelineCustomizerWrapper().edgesIgnoringSafeArea(.all).navigationTitle(Text("TIMELINE_LAYOUT", tableName: "Settings"))) { + NavigationLink { + TimelineCustomizerView() + } label: { Text("TIMELINE_LAYOUT", tableName: "Settings") } }