From 68fe9e2b6298e9db39d6d7b6d25013e31badf035 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 3 Nov 2019 04:01:58 -0600 Subject: [PATCH] Add the account icon to the account inspector. --- NetNewsWire.xcodeproj/project.pbxproj | 4 +++ .../AccountInspectorViewController.swift | 22 ++++++++++++ iOS/Inspector/InspectorHeaderView.swift | 36 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 iOS/Inspector/InspectorHeaderView.swift diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index f2349c26b..71a3c3d14 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -23,6 +23,7 @@ 5126EE97226CB48A00C22AFC /* SceneCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5126EE96226CB48A00C22AFC /* SceneCoordinator.swift */; }; 5127B238222B4849006D641D /* DetailKeyboardDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5127B236222B4849006D641D /* DetailKeyboardDelegate.swift */; }; 5127B23A222B4849006D641D /* DetailKeyboardShortcuts.plist in Resources */ = {isa = PBXBuildFile; fileRef = 5127B237222B4849006D641D /* DetailKeyboardShortcuts.plist */; }; + 512AF9C2236ED52C0066F8BE /* InspectorHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512AF9C1236ED52C0066F8BE /* InspectorHeaderView.swift */; }; 512E08E62268800D00BDCFDD /* FolderTreeControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97A11ED9F180007D329B /* FolderTreeControllerDelegate.swift */; }; 512E08E72268801200BDCFDD /* FeedTreeControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97611ED9EB96007D329B /* FeedTreeControllerDelegate.swift */; }; 512E09012268907400BDCFDD /* MasterFeedTableViewSectionHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512E08F722688F7C00BDCFDD /* MasterFeedTableViewSectionHeader.swift */; }; @@ -1206,6 +1207,7 @@ 5126EE96226CB48A00C22AFC /* SceneCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneCoordinator.swift; sourceTree = ""; }; 5127B236222B4849006D641D /* DetailKeyboardDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailKeyboardDelegate.swift; sourceTree = ""; }; 5127B237222B4849006D641D /* DetailKeyboardShortcuts.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = DetailKeyboardShortcuts.plist; sourceTree = ""; }; + 512AF9C1236ED52C0066F8BE /* InspectorHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorHeaderView.swift; sourceTree = ""; }; 512E08F722688F7C00BDCFDD /* MasterFeedTableViewSectionHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterFeedTableViewSectionHeader.swift; sourceTree = ""; }; 512E092B2268B25500BDCFDD /* UISplitViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UISplitViewController-Extensions.swift"; sourceTree = ""; }; 51314617235A797400387FDC /* NetNewsWire_iOSintentextension_target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = NetNewsWire_iOSintentextension_target.xcconfig; sourceTree = ""; }; @@ -1676,6 +1678,7 @@ 516A09412361248000EAE89B /* Inspector.storyboard */, 51A16991235E10D600EB091F /* AccountInspectorViewController.swift */, 5123DB9E233EC6FD00282CC9 /* FeedInspectorView.swift */, + 512AF9C1236ED52C0066F8BE /* InspectorHeaderView.swift */, ); path = Inspector; sourceTree = ""; @@ -3940,6 +3943,7 @@ 84CAFCA522BC8C08007694F0 /* FetchRequestQueue.swift in Sources */, 51C4529C22650A1000C03939 /* SingleFaviconDownloader.swift in Sources */, 51E595A6228CC36500FCC42B /* ArticleStatusSyncTimer.swift in Sources */, + 512AF9C2236ED52C0066F8BE /* InspectorHeaderView.swift in Sources */, 51A1699F235E10D700EB091F /* AboutViewController.swift in Sources */, 51C45290226509C100C03939 /* PseudoFeed.swift in Sources */, 51C452A922650DC600C03939 /* ArticleRenderer.swift in Sources */, diff --git a/iOS/Inspector/AccountInspectorViewController.swift b/iOS/Inspector/AccountInspectorViewController.swift index 853670755..fb0f153dc 100644 --- a/iOS/Inspector/AccountInspectorViewController.swift +++ b/iOS/Inspector/AccountInspectorViewController.swift @@ -36,6 +36,8 @@ class AccountInspectorViewController: UITableViewController { navigationItem.leftBarButtonItem = doneBarButtonItem } + tableView.register(InspectorHeaderView.self, forHeaderFooterViewReuseIdentifier: "SectionHeader") + } override func viewWillDisappear(_ animated: Bool) { @@ -83,6 +85,8 @@ class AccountInspectorViewController: UITableViewController { } +// MARK: Table View + extension AccountInspectorViewController { override func numberOfSections(in tableView: UITableView) -> Int { @@ -97,6 +101,22 @@ extension AccountInspectorViewController { } } + override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + return section == 0 ? 56.0 : super.tableView(tableView, heightForHeaderInSection: section) + } + + override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + guard let account = account else { return nil } + + if section == 0 { + let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! InspectorHeaderView + headerView.imageView.image = AppAssets.image(for: account.type) + return headerView + } else { + return super.tableView(tableView, viewForHeaderInSection: section) + } + } + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell @@ -122,6 +142,8 @@ extension AccountInspectorViewController { } +// MARK: UITextFieldDelegate + extension AccountInspectorViewController: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { diff --git a/iOS/Inspector/InspectorHeaderView.swift b/iOS/Inspector/InspectorHeaderView.swift new file mode 100644 index 000000000..3e22f457f --- /dev/null +++ b/iOS/Inspector/InspectorHeaderView.swift @@ -0,0 +1,36 @@ +// +// InspectorHeaderView.swift +// NetNewsWire-iOS +// +// Created by Maurice Parker on 11/3/19. +// Copyright © 2019 Ranchero Software. All rights reserved. +// + +import UIKit + +class InspectorHeaderView: UITableViewHeaderFooterView { + + var imageView = UIImageView() + + override init(reuseIdentifier: String?) { + super.init(reuseIdentifier: reuseIdentifier) + commonInit() + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + commonInit() + } + + func commonInit() { + imageView.tintColor = UIColor.label + imageView.contentMode = .scaleAspectFit + addSubview(imageView) + } + + override func layoutSubviews() { + let x = (bounds.width - 48.0) / 2 + let y = (bounds.height - 48.0) / 2 + imageView.frame = CGRect(x: x, y: y, width: 48.0, height: 48.0) + } +}