Skip to content

Commit 54e80de

Browse files
committed
refactor: use *some* class inheritance
this will significantly reduce the amount of code used throughout the project, more to come soon
1 parent 90edb69 commit 54e80de

7 files changed

Lines changed: 165 additions & 309 deletions

File tree

feather.xcodeproj/project.pbxproj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
335F0C2E2C5E0FFF00A4F0AE /* CoreDataManager+Certificates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335F0C2D2C5E0FFF00A4F0AE /* CoreDataManager+Certificates.swift */; };
3737
335F0C302C5E175B00A4F0AE /* CertData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335F0C2F2C5E175B00A4F0AE /* CertData.swift */; };
3838
336EEE812C32367C0011188D /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = 336EEE802C32367C0011188D /* ZIPFoundation */; };
39+
338230E02D7A662900999AD3 /* FRSTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 338230DF2D7A660E00999AD3 /* FRSTableViewController.swift */; };
3940
3386515B2D52343500A85670 /* CardContextMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3386515A2D52343500A85670 /* CardContextMenuView.swift */; };
4041
3386515D2D52A51400A85670 /* NewsCardContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3386515C2D52A51400A85670 /* NewsCardContainerView.swift */; };
4142
3386515F2D52A5DF00A85670 /* View+NavTransition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3386515E2D52A5DF00A85670 /* View+NavTransition.swift */; };
@@ -121,7 +122,6 @@
121122
33E4D8382C659FE9006A1C26 /* CertificateViewTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E4D8372C659FE9006A1C26 /* CertificateViewTableViewCell.swift */; };
122123
33E4D8412C67E5C3006A1C26 /* DonationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E4D8402C67E5C3006A1C26 /* DonationTableViewCell.swift */; };
123124
33E4D8432C6802BB006A1C26 /* SettingsHeaderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E4D8422C6802BB006A1C26 /* SettingsHeaderTableViewCell.swift */; };
124-
33E5A5992CC8586E00532930 /* LanguageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E5A5982CC8586E00532930 /* LanguageViewController.swift */; };
125125
33E5A59B2CC858FE00532930 /* Language.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33E5A59A2CC858FE00532930 /* Language.swift */; };
126126
33E5A59D2CC859E400532930 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 33BF31642C7C05330087F3D2 /* Localizable.strings */; };
127127
33E5A5A02CC85C1B00532930 /* Antoine.md in Resources */ = {isa = PBXBuildFile; fileRef = 33E5A59F2CC85C1B00532930 /* Antoine.md */; };
@@ -182,6 +182,7 @@
182182
335F0C2B2C5DC3AE00A4F0AE /* CoreDataManager+SignedApps.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreDataManager+SignedApps.swift"; sourceTree = "<group>"; };
183183
335F0C2D2C5E0FFF00A4F0AE /* CoreDataManager+Certificates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CoreDataManager+Certificates.swift"; sourceTree = "<group>"; };
184184
335F0C2F2C5E175B00A4F0AE /* CertData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CertData.swift; sourceTree = "<group>"; };
185+
338230DF2D7A660E00999AD3 /* FRSTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FRSTableViewController.swift; sourceTree = "<group>"; };
185186
3386515A2D52343500A85670 /* CardContextMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardContextMenuView.swift; sourceTree = "<group>"; };
186187
3386515C2D52A51400A85670 /* NewsCardContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewsCardContainerView.swift; sourceTree = "<group>"; };
187188
3386515E2D52A5DF00A85670 /* View+NavTransition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+NavTransition.swift"; sourceTree = "<group>"; };
@@ -271,7 +272,6 @@
271272
33E4D83E2C66C692006A1C26 /* UISheetPresentationControllerDetent+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UISheetPresentationControllerDetent+Private.h"; sourceTree = "<group>"; };
272273
33E4D8402C67E5C3006A1C26 /* DonationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DonationTableViewCell.swift; sourceTree = "<group>"; };
273274
33E4D8422C6802BB006A1C26 /* SettingsHeaderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsHeaderTableViewCell.swift; sourceTree = "<group>"; };
274-
33E5A5982CC8586E00532930 /* LanguageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageViewController.swift; sourceTree = "<group>"; };
275275
33E5A59A2CC858FE00532930 /* Language.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Language.swift; sourceTree = "<group>"; };
276276
33E5A59F2CC85C1B00532930 /* Antoine.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = Antoine.md; sourceTree = "<group>"; };
277277
33E5A5A12CC85CAA00532930 /* ServerOptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerOptionsViewController.swift; sourceTree = "<group>"; };
@@ -406,14 +406,6 @@
406406
path = "View Logs";
407407
sourceTree = "<group>";
408408
};
409-
33275B6A2CD0A4E4007ED278 /* Language */ = {
410-
isa = PBXGroup;
411-
children = (
412-
33E5A5982CC8586E00532930 /* LanguageViewController.swift */,
413-
);
414-
path = Language;
415-
sourceTree = "<group>";
416-
};
417409
336EEE822C324C9B0011188D /* Apps */ = {
418410
isa = PBXGroup;
419411
children = (
@@ -425,6 +417,14 @@
425417
path = Apps;
426418
sourceTree = "<group>";
427419
};
420+
338230DE2D7A65F900999AD3 /* Common */ = {
421+
isa = PBXGroup;
422+
children = (
423+
338230DF2D7A660E00999AD3 /* FRSTableViewController.swift */,
424+
);
425+
path = Common;
426+
sourceTree = "<group>";
427+
};
428428
338FFCD72C682457006C3BE0 /* Extra */ = {
429429
isa = PBXGroup;
430430
children = (
@@ -638,12 +638,12 @@
638638
33AC87EF2C3B7C46003D1175 /* Settings */ = {
639639
isa = PBXGroup;
640640
children = (
641+
338230DE2D7A65F900999AD3 /* Common */,
641642
33AC87F02C3B7CBE003D1175 /* SettingsViewController.swift */,
642643
33E4D8402C67E5C3006A1C26 /* DonationTableViewCell.swift */,
643644
332476E72C3E9044008C8EF0 /* About */,
644645
332476E42C3E8778008C8EF0 /* Display */,
645646
338FFCE22C6950FC006C3BE0 /* AppIcon */,
646-
33275B6A2CD0A4E4007ED278 /* Language */,
647647
33AC87EE2C3B7C3D003D1175 /* Certificates */,
648648
33275B662CD0A4A6007ED278 /* Server Options */,
649649
33275B692CD0A4D8007ED278 /* View Logs */,
@@ -1088,6 +1088,7 @@
10881088
AF9B6B442C6346FF00735748 /* openssl_tools.mm in Sources */,
10891089
33C0E6DA2D3E417900AF36E3 /* ESignRepoParser.swift in Sources */,
10901090
33BA37A82BF8168900FF530A /* TabbarController.swift in Sources */,
1091+
338230E02D7A662900999AD3 /* FRSTableViewController.swift in Sources */,
10911092
AFAC50952C48DF9300EDEAB6 /* AppSigner.swift in Sources */,
10921093
339FE33E2CCE06A100C297BA /* AddIdentifierViewController.swift in Sources */,
10931094
3386515F2D52A5DF00A85670 /* View+NavTransition.swift in Sources */,
@@ -1104,7 +1105,6 @@
11041105
33E4D8382C659FE9006A1C26 /* CertificateViewTableViewCell.swift in Sources */,
11051106
33951CFE2C37AFCF00802F78 /* FloatingActionButton.swift in Sources */,
11061107
33E4D8412C67E5C3006A1C26 /* DonationTableViewCell.swift in Sources */,
1107-
33E5A5992CC8586E00532930 /* LanguageViewController.swift in Sources */,
11081108
33C0E6E52D3E4C9200AF36E3 /* ESignRepoKey.swift in Sources */,
11091109
33DA8AC52D3CA2D7009357AD /* SettingsAltIconView.swift in Sources */,
11101110
33EEDAA42C5D9358009089DC /* CoreDataManager+DownloadedApps.swift in Sources */,

iOS/Views/Settings/About/AboutViewController.swift

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,36 @@
99
import UIKit
1010
import MachO
1111

12-
class AboutViewController: UITableViewController {
13-
14-
12+
class AboutViewController: FRSTableViewController {
1513
var credits: [CreditsPerson] = []
1614
var creditsSponsors: [CreditsPerson] = []
1715
var fileNames: [String] = []
1816

1917
private let sourceGET = SourceGET()
2018

21-
var tableData = [
22-
["Header"],
23-
[],
24-
["", "Thanks"], // Don't translate this
25-
[]
26-
]
27-
28-
var sectionTitles = [
29-
"",
30-
String.localized("ABOUT_VIEW_CONTROLLER_SECTION_TITLE_CREDITS"),
31-
String.localized("ABOUT_VIEW_CONTROLLER_SECTION_TITLE_SPONSORS"),
32-
String.localized("ABOUT_VIEW_CONTROLLER_SECTION_TITLE_ACKNOWLEDGEMENTS")
33-
]
34-
35-
init() { super.init(style: .insetGrouped) }
36-
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
37-
38-
override func viewDidAppear(_ animated: Bool) {
39-
super.viewDidAppear(false)
40-
}
41-
4219
override func viewDidLoad() {
4320
super.viewDidLoad()
44-
setupViews()
21+
22+
tableData = [
23+
["Header"],
24+
[],
25+
["", "Thanks"], // Don't translate this
26+
[]
27+
]
28+
29+
sectionTitles = [
30+
"",
31+
String.localized("ABOUT_VIEW_CONTROLLER_SECTION_TITLE_CREDITS"),
32+
String.localized("ABOUT_VIEW_CONTROLLER_SECTION_TITLE_SPONSORS"),
33+
String.localized("ABOUT_VIEW_CONTROLLER_SECTION_TITLE_ACKNOWLEDGEMENTS")
34+
]
35+
4536
setupCreditsSection()
4637
setupNavigation()
4738
}
4839

49-
fileprivate func setupViews() {
50-
self.tableView.dataSource = self
51-
self.tableView.delegate = self
52-
}
53-
5440
fileprivate func setupNavigation() {
5541
self.title = "About"
56-
self.navigationItem.largeTitleDisplayMode = .never
5742
self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareButtonTapped))
5843
}
5944

@@ -126,16 +111,6 @@ class AboutViewController: UITableViewController {
126111
}
127112

128113
extension AboutViewController {
129-
override func numberOfSections(in tableView: UITableView) -> Int { return sectionTitles.count }
130-
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return sectionTitles[section].isEmpty ? 0 : 40 }
131-
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return tableData[section].count }
132-
133-
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
134-
let title = sectionTitles[section]
135-
let headerView = InsetGroupedSectionHeader(title: title)
136-
return headerView
137-
}
138-
139114
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
140115
let reuseIdentifier = "Cell"
141116
let cell = UITableViewCell(style: .value1, reuseIdentifier: reuseIdentifier)
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// FRSTableViewController.swift
3+
// feather
4+
//
5+
// Created by samara on 6.03.2025.
6+
//
7+
8+
class FRSTableViewController: UITableViewController {
9+
var tableData: [[String]] = [[]]
10+
var sectionTitles: [String] = []
11+
12+
init() {
13+
super.init(style: .insetGrouped)
14+
}
15+
16+
required init?(coder: NSCoder) {
17+
fatalError("init(coder:) has not been implemented")
18+
}
19+
20+
override func viewDidLoad() {
21+
super.viewDidLoad()
22+
23+
// Navigation
24+
configureTitleDisplayMode()
25+
26+
// Delegates
27+
self.tableView.dataSource = self
28+
self.tableView.delegate = self
29+
}
30+
31+
private func configureTitleDisplayMode() {
32+
if isRootViewController() {
33+
navigationItem.largeTitleDisplayMode = .always
34+
navigationController?.navigationBar.prefersLargeTitles = true
35+
} else {
36+
navigationItem.largeTitleDisplayMode = .never
37+
}
38+
}
39+
40+
private func isRootViewController() -> Bool {
41+
return navigationController?.viewControllers.first === self
42+
}
43+
44+
func ensureTableDataHasSections() {
45+
while tableData.count < sectionTitles.count {
46+
tableData.append([])
47+
}
48+
}
49+
}
50+
51+
// MARK: - Tableview overrides
52+
53+
extension FRSTableViewController {
54+
override func numberOfSections(in tableView: UITableView) -> Int {
55+
return sectionTitles.count
56+
}
57+
58+
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
59+
return sectionTitles[section].isEmpty ? 0 : 40
60+
}
61+
62+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
63+
return tableData[section].count
64+
}
65+
66+
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
67+
let title = sectionTitles[section]
68+
let headerView = InsetGroupedSectionHeader(title: title)
69+
return headerView
70+
}
71+
}

iOS/Views/Settings/Display/DisplayViewController.swift

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,39 @@
88

99
import UIKit
1010

11-
class DisplayViewController: UITableViewController {
12-
13-
let tableData = [
14-
[String.localized("APP_SIGNING_INPUT_VIEW_CONTROLLER_SECTION_TITLE_APPEARENCE")],
15-
["Collection View"],
16-
[],
17-
["Certificate Name"]
18-
]
19-
20-
var sectionTitles = [
21-
"",
22-
String.localized("DISPLAY_VIEW_CONTROLLER_SECTION_TITLE_TINT_COLOR"),
23-
String.localized("DISPLAY_VIEW_CONTROLLER_SECTION_TITLE_STORE"),
24-
String.localized("CERTIFICATES_VIEW_CONTROLLER_TITLE")
25-
]
11+
class DisplayViewController: FRSTableViewController {
2612

2713
let collectionData = ["Default", "Berry", "Mint", "Dr Pepper", "Cool Blue", "Fuchsia", "Purplish"]
2814
let collectionDataColors = ["848ef9", "ff7a83", "a6e3a1", "711f25", "4161F1", "FF00FF", "D7B4F3"]
2915

30-
init() { super.init(style: .insetGrouped) }
31-
32-
required init?(coder: NSCoder) {
33-
fatalError("init(coder:) has not been implemented")
34-
}
35-
3616
override func viewDidLoad() {
3717
super.viewDidLoad()
3818
title = String.localized("SETTINGS_VIEW_CONTROLLER_CELL_DISPLAY")
39-
self.navigationItem.largeTitleDisplayMode = .never
40-
self.tableView.delegate = self
41-
self.tableView.dataSource = self
19+
20+
tableData = [
21+
[String.localized("APP_SIGNING_INPUT_VIEW_CONTROLLER_SECTION_TITLE_APPEARENCE")],
22+
["Collection View"],
23+
[],
24+
["Certificate Name"]
25+
]
26+
27+
sectionTitles = [
28+
"",
29+
String.localized("DISPLAY_VIEW_CONTROLLER_SECTION_TITLE_TINT_COLOR"),
30+
String.localized("DISPLAY_VIEW_CONTROLLER_SECTION_TITLE_STORE"),
31+
String.localized("CERTIFICATES_VIEW_CONTROLLER_TITLE")
32+
]
33+
4234
self.tableView.register(CollectionTableViewCell.self, forCellReuseIdentifier: "CollectionCell")
4335
}
4436

45-
func updateAppearance(with style: UIUserInterfaceStyle) {
37+
private func updateAppearance(with style: UIUserInterfaceStyle) {
4638
view.window?.overrideUserInterfaceStyle = style
4739
Preferences.preferredInterfaceStyle = style.rawValue
4840
}
4941
}
5042

5143
extension DisplayViewController {
52-
override func numberOfSections(in tableView: UITableView) -> Int { return sectionTitles.count }
53-
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return sectionTitles[section] }
54-
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return sectionTitles[section].isEmpty ? 5 : 40 }
55-
5644
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
5745
if section == 2 {
5846
return 3
@@ -61,12 +49,6 @@ extension DisplayViewController {
6149
}
6250
}
6351

64-
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
65-
let title = sectionTitles[section]
66-
let headerView = InsetGroupedSectionHeader(title: title)
67-
return headerView
68-
}
69-
7052
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
7153
let reuseIdentifier = "Cell"
7254
var cell = UITableViewCell(style: .default, reuseIdentifier: reuseIdentifier)

0 commit comments

Comments
 (0)