Removing Dead Code part 1 (#2234)

This commit is contained in:
Mauro
2023-12-13 09:51:57 +01:00
committed by GitHub
parent 09b276d94b
commit d99d26fcdc
88 changed files with 115 additions and 477 deletions
-4
View File
@@ -106,10 +106,6 @@ enum RoomAvatarSizeOnScreen {
}
extension AvatarSize {
var size: CGSize {
CGSize(width: value, height: value)
}
var scaledSize: CGSize {
CGSize(width: scaledValue, height: scaledValue)
}
@@ -130,12 +130,6 @@ private extension String {
self[index(startIndex, offsetBy: offset)]
}
subscript(bounds: CountableClosedRange<Int>) -> Substring {
let start = index(startIndex, offsetBy: bounds.lowerBound)
let end = index(startIndex, offsetBy: bounds.upperBound)
return self[start...end]
}
subscript(bounds: CountableRange<Int>) -> Substring {
let start = index(startIndex, offsetBy: bounds.lowerBound)
let end = index(startIndex, offsetBy: bounds.upperBound)
@@ -16,6 +16,7 @@
import Foundation
// periphery:ignore - property wrappers generate false positives
@propertyWrapper
struct CancellableTask<S: Sendable, F: Error> {
private var storedValue: Task<S, F>?
@@ -47,18 +47,18 @@ struct CollapsibleReactionLayout: Layout {
rows: collapsedRows,
collapseButton: subviewsByType.collapseButton,
addMoreButton: subviewsByType.addMoreButton)
let size = sizeThatFits(proposal: proposal, rows: collapsedRowsWithButtons)
let size = sizeThatFits(rows: collapsedRowsWithButtons)
return size
} else {
// Show all subviews with the button at the end
var rowsWithButtons = calculateRows(proposal: proposal, subviews: Array(subviews))
ensureCollapseAndAddMoreButtonsAreOnTheSameRow(&rowsWithButtons)
let size = sizeThatFits(proposal: proposal, rows: rowsWithButtons)
let size = sizeThatFits(rows: rowsWithButtons)
return size
}
} else {
// Otherwise we are just calculating the size of all items without the button
return sizeThatFits(proposal: proposal, rows: reactionsAndAddMore)
return sizeThatFits(rows: reactionsAndAddMore)
}
}
@@ -140,7 +140,7 @@ struct CollapsibleReactionLayout: Layout {
/// - proposal: The proposed size
/// - rows: The list of rows
/// - Returns: The size render the rows
private func sizeThatFits(proposal: ProposedViewSize, rows: [[FlowLayoutSubview]]) -> CGSize {
private func sizeThatFits(rows: [[FlowLayoutSubview]]) -> CGSize {
let sizes = rows.map { row in
row.map { subview in
subview.sizeThatFits(.unspecified)
@@ -31,6 +31,18 @@ extension View {
})
return alert(item.wrappedValue?.title ?? "", isPresented: binding, presenting: item.wrappedValue, actions: actions, message: message)
}
// periphery: ignore - not used yet but might be useful
func alert<Item, Actions>(item: Binding<Item?>, @ViewBuilder actions: (Item) -> Actions) -> some View where Item: AlertProtocol, Actions: View {
let binding = Binding<Bool>(get: {
item.wrappedValue != nil
}, set: { newValue in
if !newValue {
item.wrappedValue = nil
}
})
return alert(item.wrappedValue?.title ?? "", isPresented: binding, presenting: item.wrappedValue, actions: actions)
}
}
/// A type that describes an alert to be shown to the user.
@@ -73,13 +73,3 @@ extension Array where Element == RoomTimelineItemProtocol {
first { $0.id.timelineID == id.timelineID }
}
}
extension Array {
func appending(_ element: Element) -> [Element] {
self + [element]
}
func appending(_ elements: [Element]) -> [Element] {
self + elements
}
}
@@ -34,6 +34,7 @@ extension View {
return confirmationDialog(item.wrappedValue?.title ?? "", isPresented: binding, titleVisibility: titleVisibility, presenting: item.wrappedValue, actions: actions)
}
// periphery: ignore - not used yet but might be useful
func confirmationDialog<Item, Actions, Message>(item: Binding<Item?>,
titleVisibility: Visibility = .automatic,
@ViewBuilder actions: (Item) -> Actions,
@@ -21,9 +21,3 @@ extension MapTilerStyleBuilder {
self.init(baseURL: appSettings.mapTilerBaseURL, key: appSettings.mapTilerApiKey)
}
}
extension MapTilerGeoCodingService {
init(session: URLSession = .shared, appSettings: AppSettings) {
self.init(session: session, key: appSettings.mapTilerApiKey, geocodingURL: appSettings.geocodingURLFormatString)
}
}
@@ -22,7 +22,6 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
private let cacheKey: String
private let temporaryBlockquoteMarkingColor = UIColor.magenta
private let temporaryCodeBlockMarkingColor = UIColor.cyan
private let linkColor = UIColor.blue
private let permalinkBaseURL: URL
private let mentionBuilder: MentionBuilderProtocol
@@ -33,10 +32,6 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
caches.removeAll()
}
static func invalidateCache(for key: String = defaultKey) {
caches[key]?.removeAllValues()
}
init(cacheKey: String = defaultKey, permalinkBaseURL: URL, mentionBuilder: MentionBuilderProtocol) {
self.cacheKey = cacheKey
if Self.caches[cacheKey] == nil {
@@ -73,7 +68,7 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
// that could happen with the default HTML renderer of NSAttributedString which is a
// webview.
func fromHTML(_ htmlString: String?) -> AttributedString? {
guard var originalHTMLString = htmlString else {
guard let originalHTMLString = htmlString else {
return nil
}
@@ -18,27 +18,27 @@ import Foundation
enum BlockquoteAttribute: AttributedStringKey {
typealias Value = Bool
public static var name = "MXBlockquoteAttribute"
static var name = "MXBlockquoteAttribute"
}
enum UserIDAttribute: AttributedStringKey {
typealias Value = String
public static var name = "MXUserIDAttribute"
static var name = "MXUserIDAttribute"
}
enum RoomIDAttribute: AttributedStringKey {
typealias Value = String
public static var name = "MXRoomIDAttribute"
static var name = "MXRoomIDAttribute"
}
enum RoomAliasAttribute: AttributedStringKey {
typealias Value = String
public static var name = "MXRoomAliasAttribute"
static var name = "MXRoomAliasAttribute"
}
enum AllUsersMentionAttribute: AttributedStringKey {
typealias Value = Bool
public static var name = "MXAllUsersMentionAttribute"
static var name = "MXAllUsersMentionAttribute"
}
struct EventIDAttributeValue: Hashable {
@@ -48,9 +48,10 @@ struct EventIDAttributeValue: Hashable {
enum EventIDAttribute: AttributedStringKey {
typealias Value = EventIDAttributeValue
public static var name = "MXEventIDAttribute"
static var name = "MXEventIDAttribute"
}
// periphery: ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
extension AttributeScopes {
struct ElementXAttributes: AttributeScope {
let blockquote: BlockquoteAttribute
@@ -69,6 +70,7 @@ extension AttributeScopes {
var elementX: ElementXAttributes.Type { ElementXAttributes.self }
}
// periphery: ignore - required to make NSAttributedString to AttributedString conversion even if not used directly
extension AttributeDynamicLookup {
subscript<T: AttributedStringKey>(dynamicMember keyPath: KeyPath<AttributeScopes.ElementXAttributes, T>) -> T {
self[T.self]
@@ -1,72 +0,0 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import CoreLocation
import Foundation
struct MapTilerGeoCodingService: MapTilerGeoCodingServiceProtocol {
private let key: String
private let session: URLSession
private let geocodingURL: String
init(session: URLSession = .shared, key: String, geocodingURL: String) {
self.session = session
self.key = key
self.geocodingURL = geocodingURL
}
private struct GeocodedPlace: Decodable {
struct FeatureCollection: Decodable {
let placeName: String
}
let features: [FeatureCollection]
}
func reverseGeoCoding(for coordinate: CLLocationCoordinate2D) async -> Result<String, MapTilerGeocodingError> {
let latitude = coordinate.latitude
let longitude = coordinate.longitude
let path = String(format: geocodingURL, longitude, latitude)
guard var url = URL(string: path) else { return .failure(.wrongGeocodingURL) }
let authorization = MapTilerAuthorization(key: key)
url = authorization.authorizeURL(url)
url.append(queryItems: [.init(name: "limit", value: "1")])
var request = URLRequest(url: url)
request.httpMethod = "GET"
do {
let (data, response) = try await session.dataWithRetry(for: request)
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else {
let errorDescription = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "Unknown"
MXLog.error("Failed to get reverse geocoding: \(errorDescription)")
MXLog.error("Response: \(response)")
return .failure(.geocodingFailed)
}
// Parse the JSON data
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let decodedResponse = try decoder.decode(GeocodedPlace.self, from: data)
guard let placeName = decodedResponse.features.first?.placeName else { return .failure(.geocodingFailed) }
return .success(placeName)
} catch {
return .failure(.geocodingFailed)
}
}
}
@@ -45,6 +45,6 @@ public extension Animation {
/// - Parameters:
/// - animation: Animation
/// - body: operations to be animated
public func withElementAnimation<Result>(_ animation: Animation? = .default, _ body: () throws -> Result) rethrows -> Result {
func withElementAnimation<Result>(_ animation: Animation? = .default, _ body: () throws -> Result) rethrows -> Result {
try withAnimation(animation?.disabledDuringTests(), body)
}
@@ -79,11 +79,8 @@ struct ShimmerOverlay_Previews: PreviewProvider, TestablePreview {
static let viewModel = HomeScreenViewModel(userSession: MockUserSession(clientProxy: MockClientProxy(userID: ""),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock()),
attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: ServiceLocator.shared.settings.permalinkBaseURL,
mentionBuilder: MentionBuilder()),
selectedRoomPublisher: CurrentValueSubject<String?, Never>(nil).asCurrentValuePublisher(),
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
static var previews: some View {
@@ -27,7 +27,11 @@ struct CustomLayoutLabelStyle: LabelStyle {
let spacing: CGFloat
var alignment: VerticalAlignment
enum IconLayout { case leading, trailing }
enum IconLayout {
case leading
case trailing
}
var iconLayout: IconLayout
fileprivate init(spacing: CGFloat, alignment: VerticalAlignment, iconLayout: IconLayout) {
@@ -38,10 +42,11 @@ struct CustomLayoutLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(alignment: alignment, spacing: spacing) {
if iconLayout == .leading {
switch iconLayout {
case .leading:
configuration.icon
configuration.title
} else {
case .trailing:
configuration.title
configuration.icon
}
@@ -26,11 +26,11 @@ struct AppActivityView: UIViewControllerRepresentable {
private var onCancel: (() -> Void)?
private var onComplete: CompletionType?
public init(activityItems: [Any],
applicationActivities: [UIActivity]? = nil,
excludedActivityTypes: [UIActivity.ActivityType] = [],
onCancel: (() -> Void)? = nil,
onComplete: CompletionType? = nil) {
init(activityItems: [Any],
applicationActivities: [UIActivity]? = nil,
excludedActivityTypes: [UIActivity.ActivityType] = [],
onCancel: (() -> Void)? = nil,
onComplete: CompletionType? = nil) {
self.activityItems = activityItems
self.applicationActivities = applicationActivities
self.excludedActivityTypes = excludedActivityTypes
@@ -38,7 +38,7 @@ struct AppActivityView: UIViewControllerRepresentable {
self.onComplete = onComplete
}
public func makeUIViewController(context: Context) -> UIViewControllerType {
func makeUIViewController(context: Context) -> UIViewControllerType {
let viewController = UIViewControllerType(activityItems: activityItems, applicationActivities: applicationActivities)
viewController.excludedActivityTypes = excludedActivityTypes
@@ -57,9 +57,9 @@ struct AppActivityView: UIViewControllerRepresentable {
return viewController
}
public func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { }
public static func dismantleUIViewController(_ uiViewController: UIViewControllerType, coordinator: Coordinator) {
static func dismantleUIViewController(_ uiViewController: UIViewControllerType, coordinator: Coordinator) {
uiViewController.completionWithItemsHandler = nil
}
}
@@ -1,30 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import SwiftUI
/// A toggle style that uses a button, with a checked/unchecked image like a checkbox.
struct ElementToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
Button { configuration.isOn.toggle() } label: {
Image(systemName: configuration.isOn ? "checkmark.square.fill" : "square")
.font(.title3.weight(.regular))
.imageScale(.large)
.foregroundColor(.compound.textActionPrimary)
}
.buttonStyle(.plain)
}
}
@@ -57,7 +57,6 @@ struct EstimatedWaveformView: View {
var lineWidth: CGFloat = 2
var linePadding: CGFloat = 2
var waveform: EstimatedWaveform
private let minimumGraphAmplitude: CGFloat = 1
var progress: CGFloat = 0.0
@State private var normalizedWaveformData: [Float] = []