From 5e22ba56773a07b1d08671d207ca3447f29e1f08 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 8 Dec 2023 01:47:26 -0700 Subject: [PATCH] Remove most imports of UIKit --- Mlem/App Constants.swift | 3 +-- Mlem/AppDelegate.swift | 1 - Mlem/Extensions/Color.swift | 2 -- Mlem/MlemApp.swift | 1 - .../Notifications/NotificationDisplayer.swift | 3 +-- Mlem/Temp Image Viewer/ImageSaver.swift | 19 +++++++++++-------- .../Temp Image Viewer/ZoomableContainer.swift | 1 - .../QuickLookPreviewController.swift | 1 - Mlem/Views/Tabs/Search/SearchView.swift | 1 - 9 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Mlem/App Constants.swift b/Mlem/App Constants.swift index 8dd7bc364..d849bf529 100644 --- a/Mlem/App Constants.swift +++ b/Mlem/App Constants.swift @@ -7,9 +7,8 @@ import Foundation import KeychainAccess -import UIKit -struct AppConstants { +enum AppConstants { static let cacheSize = 500_000_000 // 500MB in bytes static let urlCache: URLCache = .init(memoryCapacity: cacheSize, diskCapacity: cacheSize) static let imageSizeCache: NSCache = .init() diff --git a/Mlem/AppDelegate.swift b/Mlem/AppDelegate.swift index a677bde4e..e7ba1e339 100644 --- a/Mlem/AppDelegate.swift +++ b/Mlem/AppDelegate.swift @@ -7,7 +7,6 @@ import Foundation import SwiftUI -import UIKit // TODO: we need to do a bit of work to ensure we also switch tab when responding to these // as currently it launches you into the app, but if the app was already running you're left diff --git a/Mlem/Extensions/Color.swift b/Mlem/Extensions/Color.swift index 8facc23f6..2c2bd6e62 100644 --- a/Mlem/Extensions/Color.swift +++ b/Mlem/Extensions/Color.swift @@ -5,9 +5,7 @@ // Created by David Bureš on 26.03.2022. // -import Foundation import SwiftUI -import UIKit extension Color { // This is here to give me dynamic light/dark system colors for view backgrounds diff --git a/Mlem/MlemApp.swift b/Mlem/MlemApp.swift index e5a616f3c..fce3d4a03 100644 --- a/Mlem/MlemApp.swift +++ b/Mlem/MlemApp.swift @@ -8,7 +8,6 @@ import Dependencies import Nuke import SwiftUI -import UIKit import XCTestDynamicOverlay @main diff --git a/Mlem/Notifications/NotificationDisplayer.swift b/Mlem/Notifications/NotificationDisplayer.swift index 08ef57b05..64595b604 100644 --- a/Mlem/Notifications/NotificationDisplayer.swift +++ b/Mlem/Notifications/NotificationDisplayer.swift @@ -7,10 +7,9 @@ // import SwiftUI -import UIKit /// A class responsible for displaying important notifications to the user -class NotificationDisplayer { +enum NotificationDisplayer { // MARK: - Public methods /// A method that displays a `Notifiable` object to the user diff --git a/Mlem/Temp Image Viewer/ImageSaver.swift b/Mlem/Temp Image Viewer/ImageSaver.swift index db974bad8..05b5a09c7 100644 --- a/Mlem/Temp Image Viewer/ImageSaver.swift +++ b/Mlem/Temp Image Viewer/ImageSaver.swift @@ -7,16 +7,19 @@ // import Foundation -import UIKit +import Photos class ImageSaver: NSObject { func writeToPhotoAlbum(imageData: Data) { - if let image = UIImage(data: imageData) { - UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveCompleted), nil) - } - } - - @objc func saveCompleted(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) { - print("Save finished!") + PHPhotoLibrary.shared().performChanges({ + let creationRequest = PHAssetCreationRequest.forAsset() + creationRequest.addResource(with: .photo, data: imageData, options: nil) + }, completionHandler: { success, error in + if success { + print("Save finished!") + } else { + print("Error saving photo: \(String(describing: error?.localizedDescription))") + } + }) } } diff --git a/Mlem/Temp Image Viewer/ZoomableContainer.swift b/Mlem/Temp Image Viewer/ZoomableContainer.swift index fe383ed22..7fbc75250 100644 --- a/Mlem/Temp Image Viewer/ZoomableContainer.swift +++ b/Mlem/Temp Image Viewer/ZoomableContainer.swift @@ -7,7 +7,6 @@ // import SwiftUI -import UIKit // ref: https://stackoverflow.com/questions/74238414/is-there-an-easy-way-to-pinch-to-zoom-and-drag-any-view-in-swiftui diff --git a/Mlem/Views/Shared/Quick Look/QuickLookPreviewController.swift b/Mlem/Views/Shared/Quick Look/QuickLookPreviewController.swift index 62008ada5..fe9da97aa 100644 --- a/Mlem/Views/Shared/Quick Look/QuickLookPreviewController.swift +++ b/Mlem/Views/Shared/Quick Look/QuickLookPreviewController.swift @@ -6,7 +6,6 @@ // import QuickLook -import UIKit /// QuickLookPreviewController allows us to use UIKit's Quick Look view inside SwiftUI with interactive dismiss gesture, and a transparent background. final class QuickLookPreviewController: UIViewController, QLPreviewControllerDataSource, QLPreviewControllerDelegate { diff --git a/Mlem/Views/Tabs/Search/SearchView.swift b/Mlem/Views/Tabs/Search/SearchView.swift index 71ebc9e8e..39fd45d0b 100644 --- a/Mlem/Views/Tabs/Search/SearchView.swift +++ b/Mlem/Views/Tabs/Search/SearchView.swift @@ -9,7 +9,6 @@ import Combine import Dependencies import Foundation import SwiftUI -import UIKit private struct ViewOffsetKey: PreferenceKey { typealias Value = CGFloat