From c6335b345d940fb3c49ab7ff4baccd3c243a1559 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Fri, 26 Jul 2024 11:56:33 +0100 Subject: [PATCH] feat: Refactor RunTest view to improve input and nettest status handling Signed-off-by: Norbel AMBANUMBEN --- ooniprobe.xcodeproj/project.pbxproj | 22 +- ooniprobe/OONIDescriptor.swift | 12 +- .../RunTest/Rows/InputTableViewCell.swift | 50 +++- .../View/RunTest/Rows/NettestStatus.swift | 19 +- .../RunTest/Rows/NettestTableViewCell.swift | 87 ++++++- ...TestOverviewViewController+TableView.swift | 237 ++++-------------- .../View/RunTest/TestOverviewViewController.h | 2 +- .../View/RunTest/TestOverviewViewController.m | 21 +- 8 files changed, 215 insertions(+), 235 deletions(-) diff --git a/ooniprobe.xcodeproj/project.pbxproj b/ooniprobe.xcodeproj/project.pbxproj index fe883dc4..3ee01452 100644 --- a/ooniprobe.xcodeproj/project.pbxproj +++ b/ooniprobe.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 46; objects = { /* Begin PBXBuildFile section */ @@ -19,6 +19,9 @@ 7940AA9228117E9000C0EB5D /* share.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7940AA8828117E9000C0EB5D /* share.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 7945903D2C21BFB1008116BF /* OONIDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7945903C2C21BFB1008116BF /* OONIDescriptor.swift */; }; 79780FCF27E9F18E002A38B1 /* Languages.plist in Resources */ = {isa = PBXBuildFile; fileRef = 79780FCE27E9F18E002A38B1 /* Languages.plist */; }; + 79BC192B2C53AD890017B7EC /* InputTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79BC192A2C53AD890017B7EC /* InputTableViewCell.swift */; }; + 79BC192D2C53ADC20017B7EC /* NettestTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79BC192C2C53ADC20017B7EC /* NettestTableViewCell.swift */; }; + 79BC192F2C53B3D10017B7EC /* NettestStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79BC192E2C53B3D10017B7EC /* NettestStatus.swift */; }; 79DB62342C2D8F020076FA0C /* TestOverviewViewController+TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 79DB62332C2D8F020076FA0C /* TestOverviewViewController+TableView.swift */; }; 7AED19812A6EC9A2003B265A /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7AED19802A6EC9A2003B265A /* libresolv.tbd */; }; 7AED19832A6EC9C7003B265A /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 7AED19822A6EC9C7003B265A /* libresolv.tbd */; }; @@ -234,6 +237,9 @@ 79780FCE27E9F18E002A38B1 /* Languages.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Languages.plist; sourceTree = ""; }; 79AA093C2A86E44400C23E27 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = ""; }; 79AA093D2A86E47600C23E27 /* my */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = my; path = my.lproj/Localizable.strings; sourceTree = ""; }; + 79BC192A2C53AD890017B7EC /* InputTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputTableViewCell.swift; sourceTree = ""; }; + 79BC192C2C53ADC20017B7EC /* NettestTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NettestTableViewCell.swift; sourceTree = ""; }; + 79BC192E2C53B3D10017B7EC /* NettestStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NettestStatus.swift; sourceTree = ""; }; 79DB62332C2D8F020076FA0C /* TestOverviewViewController+TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TestOverviewViewController+TableView.swift"; sourceTree = ""; }; 7A8CB0932ADDDAC1005AB2BC /* libcrypto.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libcrypto.xcframework; path = Pods/libcrypto/libcrypto.xcframework; sourceTree = ""; }; 7A8CB0942ADDDAC1005AB2BC /* libevent.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libevent.xcframework; path = Pods/libevent/libevent.xcframework; sourceTree = ""; }; @@ -608,6 +614,16 @@ path = share; sourceTree = ""; }; + 79BC19292C53AD470017B7EC /* Rows */ = { + isa = PBXGroup; + children = ( + 79BC192A2C53AD890017B7EC /* InputTableViewCell.swift */, + 79BC192C2C53ADC20017B7EC /* NettestTableViewCell.swift */, + 79BC192E2C53B3D10017B7EC /* NettestStatus.swift */, + ); + path = Rows; + sourceTree = ""; + }; A226141514CB239FFA382514 /* Pods */ = { isa = PBXGroup; children = ( @@ -716,6 +732,7 @@ ED0D8D6D201866D8003DDF23 /* RunTest */ = { isa = PBXGroup; children = ( + 79BC19292C53AD470017B7EC /* Rows */, ED1CC80020159D970041089A /* TestRunningViewController.h */, ED1CC80120159D970041089A /* TestRunningViewController.m */, ED0D8D6E20186742003DDF23 /* TestOverviewViewController.h */, @@ -1615,11 +1632,13 @@ ED41D8B82089E9C500543191 /* WebsitesDetailsViewController.m in Sources */, ED3AE9F020341C8600DAAF36 /* ResultsHeaderViewController.m in Sources */, EDDB0B761FFF6C8B00EFD9C8 /* Onboarding3ViewController.m in Sources */, + 79BC192F2C53B3D10017B7EC /* NettestStatus.swift in Sources */, EDF4ED20248A8B50001A5406 /* EventResult.m in Sources */, ED4D1E60246315EF0087B36D /* BasicTableViewCell.m in Sources */, EDF4ED31248FBFEC001A5406 /* CircumventionDetailsViewController.m in Sources */, EDB3D64926203DC000724ECF /* ExperimentalSuite.m in Sources */, EDB33B7E21838824002CEC34 /* CustomURLViewController.m in Sources */, + 79BC192B2C53AD890017B7EC /* InputTableViewCell.swift in Sources */, ED14B2342465411E009AA906 /* Psiphon.m in Sources */, ED2E067121D4867B00E9B9EE /* NdtTest.m in Sources */, ED9CCEF7252B3298004F8420 /* OONISessionConfig.m in Sources */, @@ -1640,6 +1659,7 @@ ED2E066F21D4867B00E9B9EE /* HttpInvalidRequestLine.m in Sources */, ED4DF7DA2609F0ED00521C5B /* BackgroundTask.m in Sources */, ED4A00B526494F140083C8F6 /* ProxyViewController.m in Sources */, + 79BC192D2C53ADC20017B7EC /* NettestTableViewCell.swift in Sources */, ED9CCEE8252B30D3004F8420 /* OONIContext.m in Sources */, ED21D092269C93B900BB09D8 /* ProgressViewController.m in Sources */, ED58CF7E1FEBBE2800E3C415 /* TestUtility.m in Sources */, diff --git a/ooniprobe/OONIDescriptor.swift b/ooniprobe/OONIDescriptor.swift index a96065cf..98d23a7d 100644 --- a/ooniprobe/OONIDescriptor.swift +++ b/ooniprobe/OONIDescriptor.swift @@ -192,7 +192,17 @@ public class OONIDescriptor: NSObject { name: "experimental", title: NSLocalizedString("Test.Experimental.Fullname", comment: ""), shortDescription: NSLocalizedString("Dashboard.Experimental.Card.Description", comment: ""), - longDescription: NSLocalizedString("Dashboard.Experimental.Overview.Paragraph", comment: ""), + longDescription: String.localizedStringWithFormat( + NSLocalizedString("Dashboard.Experimental.Overview.Paragraph", comment: ""), + """ + \n- [STUN Reachability](https://github.com/ooni/spec/blob/master/nettests/ts-025-stun-reachability.md) + \n- [DNS Check](https://github.com/ooni/spec/blob/master/nettests/ts-028-dnscheck.md) + \n- [RiseupVPN](https://ooni.org/nettest/riseupvpn/) + \n- [ECH Check](https://github.com/ooni/spec/blob/master/nettests/ts-039-echcheck.md) + \(String(format: "%@ (%@)", "\n- [Tor Snowflake](https://ooni.org/nettest/tor-snowflake/)", NSLocalizedString("Settings.TestOptions.LongRunningTest", comment: ""))) + \(String(format: "%@ (%@)", "\n- [Vanilla Tor](https://github.com/ooni/spec/blob/master/nettests/ts-016-vanilla-tor.md)", NSLocalizedString("Settings.TestOptions.LongRunningTest", comment: ""))) + """ + ) , icon: "experimental", color: UIColor(named: "color_indigo1")!, animation: "experimental", diff --git a/ooniprobe/View/RunTest/Rows/InputTableViewCell.swift b/ooniprobe/View/RunTest/Rows/InputTableViewCell.swift index 04e9cd02..828ace86 100644 --- a/ooniprobe/View/RunTest/Rows/InputTableViewCell.swift +++ b/ooniprobe/View/RunTest/Rows/InputTableViewCell.swift @@ -1,9 +1,43 @@ -// -// InputTableViewCell.swift -// ooniprobe -// -// Created by Norbel Ambanumben on 26/07/2024. -// Copyright © 2024 OONI. All rights reserved. -// +import SwiftUI -import Foundation +// MARK: - Input views and TableCell + +/// A SwiftUI view that represents an input in the table view. +struct InputTableView: View { + var item: String + + var body: some View { + HStack { + Text(item).font(.callout) + Spacer() + } + } +} + +/// A UITableViewCell subclass that displays an input in the table view. +class InputTableViewCell: UITableViewCell { + private var hostingController: UIHostingController? + + /// Configures the cell with the specified data. + /// - Parameter data: The input string. + func configure(with data: String) { + + let toggleCellView = InputTableView(item:data) + + if let hostingController = hostingController { + hostingController.rootView = toggleCellView + } else { + hostingController = UIHostingController(rootView: toggleCellView) + if let hostingView = hostingController?.view { + hostingView.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(hostingView) + NSLayoutConstraint.activate([ + hostingView.topAnchor.constraint(equalTo: contentView.topAnchor), + hostingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + hostingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + hostingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + ]) + } + } + } +} diff --git a/ooniprobe/View/RunTest/Rows/NettestStatus.swift b/ooniprobe/View/RunTest/Rows/NettestStatus.swift index 406010a1..865133ad 100644 --- a/ooniprobe/View/RunTest/Rows/NettestStatus.swift +++ b/ooniprobe/View/RunTest/Rows/NettestStatus.swift @@ -1,9 +1,12 @@ -// -// NettestStatus.swift -// ooniprobe -// -// Created by Norbel Ambanumben on 26/07/2024. -// Copyright © 2024 OONI. All rights reserved. -// +// MARK: - NettestStatus -import Foundation +/// A struct that represents the status of a Nettest. +class NettestStatus : ObservableObject { + var nettest: Nettest + @Published var isSelected: Bool = false + @Published var isExpanded: Bool = false + + init(nettest: Nettest) { + self.nettest = nettest + } +} diff --git a/ooniprobe/View/RunTest/Rows/NettestTableViewCell.swift b/ooniprobe/View/RunTest/Rows/NettestTableViewCell.swift index 0920b7c3..da6a7839 100644 --- a/ooniprobe/View/RunTest/Rows/NettestTableViewCell.swift +++ b/ooniprobe/View/RunTest/Rows/NettestTableViewCell.swift @@ -1,9 +1,78 @@ -// -// NettestTableViewCell.swift -// ooniprobe -// -// Created by Norbel Ambanumben on 26/07/2024. -// Copyright © 2024 OONI. All rights reserved. -// - -import Foundation +import SwiftUI + +/// A SwiftUI toggle style that uses a checkbox. +struct iOSCheckboxToggleStyle: ToggleStyle { + func makeBody(configuration: Configuration) -> some View { + Button(action: { + configuration.isOn.toggle() + }, label: { + HStack { + configuration.label + Spacer() + Image(systemName: configuration.isOn ? "checkmark.square" : "square") + .padding() + } + }).foregroundColor(.black) + } +} + +// MARK: - Nettests views and TableCell + +/// A SwiftUI view that represents a section in the table view. +struct NettestTableCell: View { + var item: NettestStatus + @Binding var isSelected: Bool + + var body: some View { + HStack { + Text(LocalizationUtility.getNameForTest(item.nettest.name)) + .font(.callout) + .lineLimit(1) + .layoutPriority(1) + if let inputs = item.nettest.inputs, !inputs.isEmpty { + Image(systemName: item.isExpanded ? "chevron.up" : "chevron.down") + } else { + Spacer() + } + Toggle(isOn: $isSelected) {}.toggleStyle(iOSCheckboxToggleStyle()) + } + } +} + +/// A UITableViewCell subclass that displays a section in the table view. +class NettestTableViewCell: UITableViewCell { + private var hostingController: UIHostingController? + + /// Configures the cell with the specified data. + /// - Parameters: + /// - data: The NettestStatus object. + /// - onToggleChange: A closure that is called when the toggle is changed. + func configure(with data: NettestStatus, onToggleChange: @escaping (Bool) -> Void) { + // Create a binding to pass the data to the SwiftUI view + let binding = Binding( + get: { data.isSelected }, + set: { newValue in + data.isSelected = newValue + onToggleChange(newValue) + } + ) + + let toggleCellView = NettestTableCell(item: data, isSelected: binding) + + if let hostingController = hostingController { + hostingController.rootView = toggleCellView + } else { + hostingController = UIHostingController(rootView: toggleCellView) + if let hostingView = hostingController?.view { + hostingView.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(hostingView) + NSLayoutConstraint.activate([ + hostingView.topAnchor.constraint(equalTo: contentView.topAnchor), + hostingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), + hostingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), + hostingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), + ]) + } + } + } +} diff --git a/ooniprobe/View/RunTest/TestOverviewViewController+TableView.swift b/ooniprobe/View/RunTest/TestOverviewViewController+TableView.swift index 960041d8..8296c400 100644 --- a/ooniprobe/View/RunTest/TestOverviewViewController+TableView.swift +++ b/ooniprobe/View/RunTest/TestOverviewViewController+TableView.swift @@ -1,60 +1,18 @@ import Foundation import SwiftUI -struct OverviewContentView: View { - let descriptor:OONIDescriptor - @State var runTestsAutomatically:Bool = false - - @State var installUpdatesAutomatically:Bool = false - - @State var nettests: [NettestStatus] - - var body: some View { - - let runTestsAutomaticallyBinding = Binding( - get: { self.runTestsAutomatically }, - set: { - runTestsAutomaticallyChanged($0) - } - ) - - HStack{ - VStack { - Text(descriptor.longDescription).font(.callout) - Text("Test Settings") - Toggle("Install updates automatically", isOn: $installUpdatesAutomatically) - Toggle("Run tests automatically", isOn: runTestsAutomaticallyBinding).toggleStyle(iOSCheckboxToggleStyle()) - UITableViewWrapper( - nettests: $nettests, - didSelectRow: { indexPath in - let allEnabled = nettests.allSatisfy({ nettest in - nettest.isSelected - }) - runTestsAutomatically = allEnabled - }) - .padding(.bottom) - .frame(height: 1000) - } - } - } - - func runTestsAutomaticallyChanged(_ newState: Bool) { - nettests.forEach({ nettest in - nettest.isSelected = newState - }) - //something async - self.runTestsAutomatically = newState - } -} extension TestOverviewViewController { - open override func viewDidAppear(_ animated: Bool) { + @objc private func setupDescriptorViews() { guard let descriptor = self.descriptor as? OONIDescriptor else { return } - let contentView = OverviewContentView(descriptor: descriptor,nettests: descriptor.nettest.map { nettest in NettestStatus(nettest: nettest) }) + let contentView = OverviewContentView( + descriptor: descriptor, + nettests: descriptor.nettest.map { nettest in NettestStatus(nettest: nettest) } + ) let hostingController = UIHostingController(rootView: contentView) @@ -73,31 +31,54 @@ extension TestOverviewViewController { } } -// MARK: - NettestStatus - -/// A struct that represents the status of a Nettest. -class NettestStatus : ObservableObject { - var nettest: Nettest - @Published var isSelected: Bool = false - @Published var isExpanded: Bool = false +struct OverviewContentView: View { + let descriptor:OONIDescriptor + @State var runTestsAutomatically:Bool = false - init(nettest: Nettest) { - self.nettest = nettest - } -} - -// MARK: - MarkdownLabel - -/// A SwiftUI view that displays a Markdown label. -struct MarkdownLabel: UIViewRepresentable { - var rect: CGRect + @State var installUpdatesAutomatically:Bool = false - func makeUIView(context: Context) -> RHMarkdownLabel { - return RHMarkdownLabel(frame: rect) + @State var nettests: [NettestStatus] + + var body: some View { + + let runTestsAutomaticallyBinding = Binding( + get: { self.runTestsAutomatically }, + set: { + runTestsAutomaticallyChanged($0) + } + ) + + VStack(alignment: .leading, spacing: 8) { + Text(LocalizedStringKey(descriptor.longDescription)) + .padding(.top) + .font(.custom("FiraSans-Regular", size: 14.0)) + .foregroundColor(Color("color_gray9")) + Text("Test Settings") + .bold() + .padding(.top) + .padding(.bottom) + Toggle("Install updates automatically", isOn: $installUpdatesAutomatically) + Toggle("Run tests automatically", isOn: runTestsAutomaticallyBinding).toggleStyle(iOSCheckboxToggleStyle()) + UITableViewWrapper( + nettests: $nettests, + didSelectRow: { indexPath in + let allEnabled = nettests.allSatisfy({ nettest in + nettest.isSelected + }) + runTestsAutomatically = allEnabled + }) + .padding(.bottom) + .frame(height: 1000) + } + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) } - func updateUIView(_ uiView: RHMarkdownLabel, context: Context) { - uiView.markdown = NSLocalizedString("Dashboard.InstantMessaging.Overview.Paragraph", comment: "") + func runTestsAutomaticallyChanged(_ newState: Bool) { + nettests.forEach({ nettest in + // TODO: save to database + nettest.isSelected = newState + }) + self.runTestsAutomatically = newState } } @@ -164,7 +145,6 @@ struct UITableViewWrapper: UIViewRepresentable { //TODO: Save preference change to database // Update the isSelected property of the NettestStatus object for the current section to the new value of the toggle. self?.parent.nettests[indexPath.section].isSelected = newValue - //self?.parent.nettests = self?.parent.nettests ?? [] // Invoke the didSelectRow closure with the selected indexPath self?.parent.didSelectRow(indexPath) tableView.reloadData() @@ -204,122 +184,3 @@ struct UITableViewWrapper: UIViewRepresentable { } } } - - -/// A SwiftUI toggle style that uses a checkbox. -struct iOSCheckboxToggleStyle: ToggleStyle { - func makeBody(configuration: Configuration) -> some View { - Button(action: { - configuration.isOn.toggle() - }, label: { - HStack { - configuration.label - Spacer() - Image(systemName: configuration.isOn ? "checkmark.square" : "square") - .padding() - } - }).foregroundColor(.black) - } -} - -// MARK: - Nettests views and TableCell - -/// A SwiftUI view that represents a section in the table view. -struct SectionTableCell: View { - var item: NettestStatus - @Binding var isOn: Bool - - var body: some View { - HStack { - Text(LocalizationUtility.getNameForTest(item.nettest.name)) - .font(.callout) - .lineLimit(1) - .layoutPriority(1) - if let inputs = item.nettest.inputs, !inputs.isEmpty { - Image(systemName: item.isExpanded ? "chevron.up" : "chevron.down") - } else { - Spacer() - } - Toggle(isOn: $isOn) {}.toggleStyle(iOSCheckboxToggleStyle()) - } - } -} - -/// A UITableViewCell subclass that displays a section in the table view. -class NettestTableViewCell: UITableViewCell { - private var hostingController: UIHostingController? - - /// Configures the cell with the specified data. - /// - Parameters: - /// - data: The NettestStatus object. - /// - onToggleChange: A closure that is called when the toggle is changed. - func configure(with data: NettestStatus, onToggleChange: @escaping (Bool) -> Void) { - // Create a binding to pass the data to the SwiftUI view - let binding = Binding( - get: { data.isSelected }, - set: { newValue in - onToggleChange(newValue) - } - ) - - let toggleCellView = SectionTableCell(item:data, isOn: binding) - - if let hostingController = hostingController { - hostingController.rootView = toggleCellView - } else { - hostingController = UIHostingController(rootView: toggleCellView) - if let hostingView = hostingController?.view { - hostingView.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(hostingView) - NSLayoutConstraint.activate([ - hostingView.topAnchor.constraint(equalTo: contentView.topAnchor), - hostingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), - hostingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - hostingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), - ]) - } - } - } -} - -// MARK: - Input views and TableCell - -/// A SwiftUI view that represents an input in the table view. -struct InputTableView: View { - var item: String - - var body: some View { - HStack { - Text(item).font(.callout) - Spacer() - } - } -} - -/// A UITableViewCell subclass that displays an input in the table view. -class InputTableViewCell: UITableViewCell { - private var hostingController: UIHostingController? - - /// Configures the cell with the specified data. - /// - Parameter data: The input string. - func configure(with data: String) { - - let toggleCellView = InputTableView(item:data) - - if let hostingController = hostingController { - hostingController.rootView = toggleCellView - } else { - hostingController = UIHostingController(rootView: toggleCellView) - if let hostingView = hostingController?.view { - hostingView.translatesAutoresizingMaskIntoConstraints = false - contentView.addSubview(hostingView) - NSLayoutConstraint.activate([ - hostingView.topAnchor.constraint(equalTo: contentView.topAnchor), - hostingView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor), - hostingView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor), - hostingView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor), - ]) - } - } - } -} diff --git a/ooniprobe/View/RunTest/TestOverviewViewController.h b/ooniprobe/View/RunTest/TestOverviewViewController.h index 301f113b..eb807219 100644 --- a/ooniprobe/View/RunTest/TestOverviewViewController.h +++ b/ooniprobe/View/RunTest/TestOverviewViewController.h @@ -12,7 +12,7 @@ UIColor *defaultColor; } -+ (void)loadSwiftUIViews; ++ (void)setupDescriptorViews; @property (nonatomic, strong) id descriptor; diff --git a/ooniprobe/View/RunTest/TestOverviewViewController.m b/ooniprobe/View/RunTest/TestOverviewViewController.m index 6fd80869..8db4546b 100644 --- a/ooniprobe/View/RunTest/TestOverviewViewController.m +++ b/ooniprobe/View/RunTest/TestOverviewViewController.m @@ -17,26 +17,9 @@ - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeConstraints) name:@"networkTestEndedUI" object:nil]; [self.testNameLabel setText:[LocalizationUtility getNameForTest:[descriptor performSelector:@selector(name)]]]; - NSString *testLongDesc = [LocalizationUtility getLongDescriptionForTest:[descriptor performSelector:@selector(name)]]; - [self.testDescriptionLabel setFont:[UIFont fontWithName:@"FiraSans-Regular" size:14]]; - [self.testDescriptionLabel setTextColor:[UIColor colorNamed:@"color_gray9"]]; NSMutableDictionary *linkAttributes = [NSMutableDictionary dictionary]; linkAttributes[(NSString *) kCTUnderlineStyleAttributeName] = @YES; linkAttributes[(NSString *) kCTForegroundColorAttributeName] = [UIColor colorNamed:@"color_base"]; - self.testDescriptionLabel.linkAttributes = [NSDictionary dictionaryWithDictionary:linkAttributes]; - [self.testDescriptionLabel setMarkdown:testLongDesc]; - if ([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) { - if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.view.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft) { - self.testDescriptionLabel.textAlignment = NSTextAlignmentRight; - } - } else { - if ([NSLocale characterDirectionForLanguage:[NSLocale preferredLanguages][0]] == NSLocaleLanguageDirectionRightToLeft) { - self.testDescriptionLabel.textAlignment = NSTextAlignmentRight; - } - } - [self.testDescriptionLabel setDidSelectLinkWithURLBlock:^(RHMarkdownLabel *label, NSURL *url) { - [[UIApplication sharedApplication] openURL:url]; - }]; [self.runButton setTitle:[NSString stringWithFormat:@"%@", NSLocalizedString(@"Dashboard.Overview.Run", nil)] forState:UIControlStateNormal]; if ([[descriptor performSelector:@selector(name)] isEqualToString:@"websites"]) [self.websitesButton setTitle:[NSString stringWithFormat:@"%@", NSLocalizedString(@"Dashboard.Overview.ChooseWebsites", nil)] forState:UIControlStateNormal]; @@ -51,10 +34,10 @@ - (void)viewDidLoad { [NavigationBarUtility setNavigationBar:self.navigationController.navigationBar color:defaultColor]; self.navigationController.navigationBar.topItem.title = @""; - [self loadSwiftUIViews]; + [self setupDescriptorViews]; } -- (void)loadSwiftUIViews{} +- (void)setupDescriptorViews{} -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated];