Skip to content

Commit

Permalink
feat: Refactor RunTest view to improve input and nettest status handling
Browse files Browse the repository at this point in the history
Signed-off-by: Norbel AMBANUMBEN <[email protected]>
  • Loading branch information
aanorbel committed Jul 26, 2024
1 parent 42db697 commit c6335b3
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 235 deletions.
22 changes: 21 additions & 1 deletion ooniprobe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -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 */; };
Expand Down Expand Up @@ -234,6 +237,9 @@
79780FCE27E9F18E002A38B1 /* Languages.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Languages.plist; sourceTree = "<group>"; };
79AA093C2A86E44400C23E27 /* vi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = vi; path = vi.lproj/Localizable.strings; sourceTree = "<group>"; };
79AA093D2A86E47600C23E27 /* my */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = my; path = my.lproj/Localizable.strings; sourceTree = "<group>"; };
79BC192A2C53AD890017B7EC /* InputTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputTableViewCell.swift; sourceTree = "<group>"; };
79BC192C2C53ADC20017B7EC /* NettestTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NettestTableViewCell.swift; sourceTree = "<group>"; };
79BC192E2C53B3D10017B7EC /* NettestStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NettestStatus.swift; sourceTree = "<group>"; };
79DB62332C2D8F020076FA0C /* TestOverviewViewController+TableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TestOverviewViewController+TableView.swift"; sourceTree = "<group>"; };
7A8CB0932ADDDAC1005AB2BC /* libcrypto.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libcrypto.xcframework; path = Pods/libcrypto/libcrypto.xcframework; sourceTree = "<group>"; };
7A8CB0942ADDDAC1005AB2BC /* libevent.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libevent.xcframework; path = Pods/libevent/libevent.xcframework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -608,6 +614,16 @@
path = share;
sourceTree = "<group>";
};
79BC19292C53AD470017B7EC /* Rows */ = {
isa = PBXGroup;
children = (
79BC192A2C53AD890017B7EC /* InputTableViewCell.swift */,
79BC192C2C53ADC20017B7EC /* NettestTableViewCell.swift */,
79BC192E2C53B3D10017B7EC /* NettestStatus.swift */,
);
path = Rows;
sourceTree = "<group>";
};
A226141514CB239FFA382514 /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -716,6 +732,7 @@
ED0D8D6D201866D8003DDF23 /* RunTest */ = {
isa = PBXGroup;
children = (
79BC19292C53AD470017B7EC /* Rows */,
ED1CC80020159D970041089A /* TestRunningViewController.h */,
ED1CC80120159D970041089A /* TestRunningViewController.m */,
ED0D8D6E20186742003DDF23 /* TestOverviewViewController.h */,
Expand Down Expand Up @@ -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 */,
Expand All @@ -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 */,
Expand Down
12 changes: 11 additions & 1 deletion ooniprobe/OONIDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
50 changes: 42 additions & 8 deletions ooniprobe/View/RunTest/Rows/InputTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -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<InputTableView>?

/// 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),
])
}
}
}
}
19 changes: 11 additions & 8 deletions ooniprobe/View/RunTest/Rows/NettestStatus.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
87 changes: 78 additions & 9 deletions ooniprobe/View/RunTest/Rows/NettestTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -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<NettestTableCell>?

/// 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<Bool>(
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),
])
}
}
}
}
Loading

0 comments on commit c6335b3

Please sign in to comment.